@@ -140,13 +140,6 @@ pub fn compile_input(trans: Box<TransCrate>,
140
140
let crate_name =
141
141
:: rustc_trans_utils:: link:: find_crate_name ( Some ( sess) , & krate. attrs , input) ;
142
142
143
- // Currently, we ignore the name resolution data structures for the purposes of dependency
144
- // tracking. Instead we will run name resolution and include its output in the hash of each
145
- // item, much like we do for macro expansion. In other words, the hash reflects not just
146
- // its contents but the results of name resolution on those contents. Hopefully we'll push
147
- // this back at some point.
148
- let mut crate_loader = CrateLoader :: new ( sess, & cstore, & crate_name) ;
149
- let resolver_arenas = Resolver :: arenas ( ) ;
150
143
let ExpansionResult { expanded_crate, defs, analysis, resolutions, mut hir_forest } = {
151
144
phase_2_configure_and_expand (
152
145
sess,
@@ -156,8 +149,6 @@ pub fn compile_input(trans: Box<TransCrate>,
156
149
& crate_name,
157
150
addl_plugins,
158
151
control. make_glob_map ,
159
- & resolver_arenas,
160
- & mut crate_loader,
161
152
|expanded_crate| {
162
153
let mut state = CompileState :: state_after_expand (
163
154
input, sess, outdir, output, & cstore, expanded_crate, & crate_name,
@@ -572,6 +563,12 @@ pub struct ExpansionResult {
572
563
pub hir_forest : hir_map:: Forest ,
573
564
}
574
565
566
+ pub struct InnerExpansionResult < ' a > {
567
+ pub expanded_crate : ast:: Crate ,
568
+ pub resolver : Resolver < ' a > ,
569
+ pub hir_forest : hir_map:: Forest ,
570
+ }
571
+
575
572
/// Run the "early phases" of the compiler: initial `cfg` processing,
576
573
/// loading compiler plugins (including those from `addl_plugins`),
577
574
/// syntax expansion, secondary `cfg` expansion, synthesis of a test
@@ -580,6 +577,52 @@ pub struct ExpansionResult {
580
577
///
581
578
/// Returns `None` if we're aborting after handling -W help.
582
579
pub fn phase_2_configure_and_expand < ' a , F > ( sess : & ' a Session ,
580
+ cstore : & ' a CStore ,
581
+ krate : ast:: Crate ,
582
+ registry : Option < Registry > ,
583
+ crate_name : & str ,
584
+ addl_plugins : Option < Vec < String > > ,
585
+ make_glob_map : MakeGlobMap ,
586
+ after_expand : F )
587
+ -> Result < ExpansionResult , CompileIncomplete >
588
+ where F : FnOnce ( & ast:: Crate ) -> CompileResult {
589
+ // Currently, we ignore the name resolution data structures for the purposes of dependency
590
+ // tracking. Instead we will run name resolution and include its output in the hash of each
591
+ // item, much like we do for macro expansion. In other words, the hash reflects not just
592
+ // its contents but the results of name resolution on those contents. Hopefully we'll push
593
+ // this back at some point.
594
+ let mut crate_loader = CrateLoader :: new ( sess, & cstore, & crate_name) ;
595
+ let resolver_arenas = Resolver :: arenas ( ) ;
596
+ let result = phase_2_configure_and_expand_inner ( sess, cstore, krate, registry, crate_name, addl_plugins,
597
+ make_glob_map, & resolver_arenas, & mut crate_loader, after_expand) ;
598
+ match result {
599
+ Ok ( InnerExpansionResult { expanded_crate, resolver, hir_forest} ) => {
600
+ Ok ( ExpansionResult {
601
+ expanded_crate,
602
+ defs : resolver. definitions ,
603
+ hir_forest,
604
+ resolutions : Resolutions {
605
+ freevars : resolver. freevars ,
606
+ export_map : resolver. export_map ,
607
+ trait_map : resolver. trait_map ,
608
+ maybe_unused_trait_imports : resolver. maybe_unused_trait_imports ,
609
+ maybe_unused_extern_crates : resolver. maybe_unused_extern_crates ,
610
+ } ,
611
+
612
+ analysis : ty:: CrateAnalysis {
613
+ access_levels : Rc :: new ( AccessLevels :: default ( ) ) ,
614
+ name : crate_name. to_string ( ) ,
615
+ glob_map : if resolver. make_glob_map { Some ( resolver. glob_map ) } else { None } ,
616
+ } ,
617
+ } )
618
+ }
619
+ Err ( x) => Err ( x)
620
+ }
621
+ }
622
+
623
+ /// Same as phase_2_configure_and_expand, but doesn't let you keep the resolver
624
+ /// around
625
+ pub fn phase_2_configure_and_expand_inner < ' a , F > ( sess : & ' a Session ,
583
626
cstore : & ' a CStore ,
584
627
krate : ast:: Crate ,
585
628
registry : Option < Registry > ,
@@ -589,7 +632,7 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &'a Session,
589
632
resolver_arenas : & ' a ResolverArenas < ' a > ,
590
633
crate_loader : & ' a mut CrateLoader ,
591
634
after_expand : F )
592
- -> Result < ExpansionResult , CompileIncomplete >
635
+ -> Result < InnerExpansionResult < ' a > , CompileIncomplete >
593
636
where F : FnOnce ( & ast:: Crate ) -> CompileResult ,
594
637
{
595
638
let time_passes = sess. time_passes ( ) ;
@@ -860,21 +903,9 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &'a Session,
860
903
syntax:: ext:: hygiene:: clear_markings ( ) ;
861
904
}
862
905
863
- Ok ( ExpansionResult {
906
+ Ok ( InnerExpansionResult {
864
907
expanded_crate : krate,
865
- defs : resolver. definitions ,
866
- analysis : ty:: CrateAnalysis {
867
- access_levels : Rc :: new ( AccessLevels :: default ( ) ) ,
868
- name : crate_name. to_string ( ) ,
869
- glob_map : if resolver. make_glob_map { Some ( resolver. glob_map ) } else { None } ,
870
- } ,
871
- resolutions : Resolutions {
872
- freevars : resolver. freevars ,
873
- export_map : resolver. export_map ,
874
- trait_map : resolver. trait_map ,
875
- maybe_unused_trait_imports : resolver. maybe_unused_trait_imports ,
876
- maybe_unused_extern_crates : resolver. maybe_unused_extern_crates ,
877
- } ,
908
+ resolver,
878
909
hir_forest,
879
910
} )
880
911
}
0 commit comments