@@ -116,8 +116,16 @@ pub fn compile_input(sess: &Session,
116
116
let outputs = build_output_filenames ( input, outdir, output, & krate. attrs , sess) ;
117
117
let id = link:: find_crate_name ( Some ( sess) , & krate. attrs , input) ;
118
118
let ExpansionResult { expanded_crate, defs, analysis, resolutions, mut hir_forest } = {
119
- let make_glob_map = control. make_glob_map ;
120
- phase_2_configure_and_expand ( sess, & cstore, krate, & id, addl_plugins, make_glob_map) ?
119
+ phase_2_configure_and_expand (
120
+ sess, & cstore, krate, & id, addl_plugins, control. make_glob_map ,
121
+ |expanded_crate| {
122
+ let mut state = CompileState :: state_after_expand (
123
+ input, sess, outdir, output, & cstore, expanded_crate, & id,
124
+ ) ;
125
+ controller_entry_point ! ( after_expand, sess, state, Ok ( ( ) ) ) ;
126
+ Ok ( ( ) )
127
+ }
128
+ ) ?
121
129
} ;
122
130
123
131
write_out_deps ( sess, & outputs, & id) ;
@@ -262,6 +270,7 @@ pub fn source_name(input: &Input) -> String {
262
270
/// Expect more entry points to be added in the future.
263
271
pub struct CompileController < ' a > {
264
272
pub after_parse : PhaseController < ' a > ,
273
+ pub after_expand : PhaseController < ' a > ,
265
274
pub after_hir_lowering : PhaseController < ' a > ,
266
275
pub after_analysis : PhaseController < ' a > ,
267
276
pub after_llvm : PhaseController < ' a > ,
@@ -273,6 +282,7 @@ impl<'a> CompileController<'a> {
273
282
pub fn basic ( ) -> CompileController < ' a > {
274
283
CompileController {
275
284
after_parse : PhaseController :: basic ( ) ,
285
+ after_expand : PhaseController :: basic ( ) ,
276
286
after_hir_lowering : PhaseController :: basic ( ) ,
277
287
after_analysis : PhaseController :: basic ( ) ,
278
288
after_llvm : PhaseController :: basic ( ) ,
@@ -363,6 +373,23 @@ impl<'a, 'b, 'ast, 'tcx> CompileState<'a, 'b, 'ast, 'tcx> {
363
373
}
364
374
}
365
375
376
+ fn state_after_expand ( input : & ' a Input ,
377
+ session : & ' ast Session ,
378
+ out_dir : & ' a Option < PathBuf > ,
379
+ out_file : & ' a Option < PathBuf > ,
380
+ cstore : & ' a CStore ,
381
+ expanded_crate : & ' a ast:: Crate ,
382
+ crate_name : & ' a str )
383
+ -> CompileState < ' a , ' b , ' ast , ' tcx > {
384
+ CompileState {
385
+ crate_name : Some ( crate_name) ,
386
+ cstore : Some ( cstore) ,
387
+ expanded_crate : Some ( expanded_crate) ,
388
+ out_file : out_file. as_ref ( ) . map ( |s| & * * s) ,
389
+ ..CompileState :: empty ( input, session, out_dir)
390
+ }
391
+ }
392
+
366
393
fn state_after_hir_lowering ( input : & ' a Input ,
367
394
session : & ' ast Session ,
368
395
out_dir : & ' a Option < PathBuf > ,
@@ -496,13 +523,16 @@ pub struct ExpansionResult<'a> {
496
523
/// standard library and prelude, and name resolution.
497
524
///
498
525
/// Returns `None` if we're aborting after handling -W help.
499
- pub fn phase_2_configure_and_expand < ' a > ( sess : & Session ,
500
- cstore : & CStore ,
501
- mut krate : ast:: Crate ,
502
- crate_name : & ' a str ,
503
- addl_plugins : Option < Vec < String > > ,
504
- make_glob_map : MakeGlobMap )
505
- -> Result < ExpansionResult < ' a > , usize > {
526
+ pub fn phase_2_configure_and_expand < ' a , F > ( sess : & Session ,
527
+ cstore : & CStore ,
528
+ mut krate : ast:: Crate ,
529
+ crate_name : & ' a str ,
530
+ addl_plugins : Option < Vec < String > > ,
531
+ make_glob_map : MakeGlobMap ,
532
+ after_expand : F )
533
+ -> Result < ExpansionResult < ' a > , usize >
534
+ where F : FnOnce ( & ast:: Crate ) -> CompileResult ,
535
+ {
506
536
let time_passes = sess. time_passes ( ) ;
507
537
508
538
// strip before anything else because crate metadata may use #[cfg_attr]
@@ -685,9 +715,23 @@ pub fn phase_2_configure_and_expand<'a>(sess: &Session,
685
715
"AST validation" ,
686
716
|| ast_validation:: check_crate ( sess, & krate) ) ;
687
717
688
- time ( sess. time_passes ( ) , "name resolution" , || {
718
+ time ( sess. time_passes ( ) , "name resolution" , || -> CompileResult {
719
+ // Currently, we ignore the name resolution data structures for the purposes of dependency
720
+ // tracking. Instead we will run name resolution and include its output in the hash of each
721
+ // item, much like we do for macro expansion. In other words, the hash reflects not just
722
+ // its contents but the results of name resolution on those contents. Hopefully we'll push
723
+ // this back at some point.
724
+ let _ignore = sess. dep_graph . in_ignore ( ) ;
725
+ resolver. build_reduced_graph ( & krate) ;
726
+ resolver. resolve_imports ( ) ;
727
+
728
+ // Since import resolution will eventually happen in expansion,
729
+ // don't perform `after_expand` until after import resolution.
730
+ after_expand ( & krate) ?;
731
+
689
732
resolver. resolve_crate ( & krate) ;
690
- } ) ;
733
+ Ok ( ( ) )
734
+ } ) ?;
691
735
692
736
// Lower ast -> hir.
693
737
let hir_forest = time ( sess. time_passes ( ) , "lowering ast -> hir" , || {
0 commit comments