From fe0c10019d7ee96909cc42cc265ef999a6b5dd70 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Mon, 25 Dec 2017 13:55:21 +0530 Subject: [PATCH] Split out creation of the resolver arena in phase_2_configure_and_expand --- src/librustc_driver/driver.rs | 79 ++++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 24 deletions(-) diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 90ab8a1951f12..31e7b3617990f 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -140,13 +140,6 @@ pub fn compile_input(trans: Box, let crate_name = ::rustc_trans_utils::link::find_crate_name(Some(sess), &krate.attrs, input); - // Currently, we ignore the name resolution data structures for the purposes of dependency - // tracking. Instead we will run name resolution and include its output in the hash of each - // item, much like we do for macro expansion. In other words, the hash reflects not just - // its contents but the results of name resolution on those contents. Hopefully we'll push - // this back at some point. - let mut crate_loader = CrateLoader::new(sess, &cstore, &crate_name); - let resolver_arenas = Resolver::arenas(); let ExpansionResult { expanded_crate, defs, analysis, resolutions, mut hir_forest } = { phase_2_configure_and_expand( sess, @@ -156,8 +149,6 @@ pub fn compile_input(trans: Box, &crate_name, addl_plugins, control.make_glob_map, - &resolver_arenas, - &mut crate_loader, |expanded_crate| { let mut state = CompileState::state_after_expand( input, sess, outdir, output, &cstore, expanded_crate, &crate_name, @@ -572,6 +563,12 @@ pub struct ExpansionResult { pub hir_forest: hir_map::Forest, } +pub struct InnerExpansionResult<'a> { + pub expanded_crate: ast::Crate, + pub resolver: Resolver<'a>, + pub hir_forest: hir_map::Forest, +} + /// Run the "early phases" of the compiler: initial `cfg` processing, /// loading compiler plugins (including those from `addl_plugins`), /// syntax expansion, secondary `cfg` expansion, synthesis of a test @@ -580,6 +577,52 @@ pub struct ExpansionResult { /// /// Returns `None` if we're aborting after handling -W help. pub fn phase_2_configure_and_expand<'a, F>(sess: &'a Session, + cstore: &'a CStore, + krate: ast::Crate, + registry: Option, + crate_name: &str, + addl_plugins: Option>, + make_glob_map: MakeGlobMap, + after_expand: F) + -> Result + where F: FnOnce(&ast::Crate) -> CompileResult { + // Currently, we ignore the name resolution data structures for the purposes of dependency + // tracking. Instead we will run name resolution and include its output in the hash of each + // item, much like we do for macro expansion. In other words, the hash reflects not just + // its contents but the results of name resolution on those contents. Hopefully we'll push + // this back at some point. + let mut crate_loader = CrateLoader::new(sess, &cstore, &crate_name); + let resolver_arenas = Resolver::arenas(); + let result = phase_2_configure_and_expand_inner(sess, cstore, krate, registry, crate_name, addl_plugins, + make_glob_map, &resolver_arenas, &mut crate_loader, after_expand); + match result { + Ok(InnerExpansionResult {expanded_crate, resolver, hir_forest}) => { + Ok(ExpansionResult { + expanded_crate, + defs: resolver.definitions, + hir_forest, + resolutions: Resolutions { + freevars: resolver.freevars, + export_map: resolver.export_map, + trait_map: resolver.trait_map, + maybe_unused_trait_imports: resolver.maybe_unused_trait_imports, + maybe_unused_extern_crates: resolver.maybe_unused_extern_crates, + }, + + analysis: ty::CrateAnalysis { + access_levels: Rc::new(AccessLevels::default()), + name: crate_name.to_string(), + glob_map: if resolver.make_glob_map { Some(resolver.glob_map) } else { None }, + }, + }) + } + Err(x) => Err(x) + } +} + +/// Same as phase_2_configure_and_expand, but doesn't let you keep the resolver +/// around +pub fn phase_2_configure_and_expand_inner<'a, F>(sess: &'a Session, cstore: &'a CStore, krate: ast::Crate, registry: Option, @@ -589,7 +632,7 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &'a Session, resolver_arenas: &'a ResolverArenas<'a>, crate_loader: &'a mut CrateLoader, after_expand: F) - -> Result + -> Result, CompileIncomplete> where F: FnOnce(&ast::Crate) -> CompileResult, { let time_passes = sess.time_passes(); @@ -860,21 +903,9 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &'a Session, syntax::ext::hygiene::clear_markings(); } - Ok(ExpansionResult { + Ok(InnerExpansionResult { expanded_crate: krate, - defs: resolver.definitions, - analysis: ty::CrateAnalysis { - access_levels: Rc::new(AccessLevels::default()), - name: crate_name.to_string(), - glob_map: if resolver.make_glob_map { Some(resolver.glob_map) } else { None }, - }, - resolutions: Resolutions { - freevars: resolver.freevars, - export_map: resolver.export_map, - trait_map: resolver.trait_map, - maybe_unused_trait_imports: resolver.maybe_unused_trait_imports, - maybe_unused_extern_crates: resolver.maybe_unused_extern_crates, - }, + resolver, hir_forest, }) }