@@ -140,13 +140,6 @@ pub fn compile_input(trans: Box<TransCrate>,
140140 let crate_name =
141141 :: rustc_trans_utils:: link:: find_crate_name ( Some ( sess) , & krate. attrs , input) ;
142142
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 ( ) ;
150143 let ExpansionResult { expanded_crate, defs, analysis, resolutions, mut hir_forest } = {
151144 phase_2_configure_and_expand (
152145 sess,
@@ -156,8 +149,6 @@ pub fn compile_input(trans: Box<TransCrate>,
156149 & crate_name,
157150 addl_plugins,
158151 control. make_glob_map ,
159- & resolver_arenas,
160- & mut crate_loader,
161152 |expanded_crate| {
162153 let mut state = CompileState :: state_after_expand (
163154 input, sess, outdir, output, & cstore, expanded_crate, & crate_name,
@@ -572,6 +563,12 @@ pub struct ExpansionResult {
572563 pub hir_forest : hir_map:: Forest ,
573564}
574565
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+
575572/// Run the "early phases" of the compiler: initial `cfg` processing,
576573/// loading compiler plugins (including those from `addl_plugins`),
577574/// syntax expansion, secondary `cfg` expansion, synthesis of a test
@@ -580,6 +577,52 @@ pub struct ExpansionResult {
580577///
581578/// Returns `None` if we're aborting after handling -W help.
582579pub 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 ,
583626 cstore : & ' a CStore ,
584627 krate : ast:: Crate ,
585628 registry : Option < Registry > ,
@@ -589,7 +632,7 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &'a Session,
589632 resolver_arenas : & ' a ResolverArenas < ' a > ,
590633 crate_loader : & ' a mut CrateLoader ,
591634 after_expand : F )
592- -> Result < ExpansionResult , CompileIncomplete >
635+ -> Result < InnerExpansionResult < ' a > , CompileIncomplete >
593636 where F : FnOnce ( & ast:: Crate ) -> CompileResult ,
594637{
595638 let time_passes = sess. time_passes ( ) ;
@@ -860,21 +903,9 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &'a Session,
860903 syntax:: ext:: hygiene:: clear_markings ( ) ;
861904 }
862905
863- Ok ( ExpansionResult {
906+ Ok ( InnerExpansionResult {
864907 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,
878909 hir_forest,
879910 } )
880911}
0 commit comments