Skip to content

Commit d1e3d62

Browse files
committed
Add the after_expand entry point between import resolution and the rest of name resolution
1 parent 9eec738 commit d1e3d62

File tree

7 files changed

+75
-39
lines changed

7 files changed

+75
-39
lines changed

src/librustc_driver/driver.rs

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,16 @@ pub fn compile_input(sess: &Session,
116116
let outputs = build_output_filenames(input, outdir, output, &krate.attrs, sess);
117117
let id = link::find_crate_name(Some(sess), &krate.attrs, input);
118118
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+
)?
121129
};
122130

123131
write_out_deps(sess, &outputs, &id);
@@ -262,6 +270,7 @@ pub fn source_name(input: &Input) -> String {
262270
/// Expect more entry points to be added in the future.
263271
pub struct CompileController<'a> {
264272
pub after_parse: PhaseController<'a>,
273+
pub after_expand: PhaseController<'a>,
265274
pub after_hir_lowering: PhaseController<'a>,
266275
pub after_analysis: PhaseController<'a>,
267276
pub after_llvm: PhaseController<'a>,
@@ -273,6 +282,7 @@ impl<'a> CompileController<'a> {
273282
pub fn basic() -> CompileController<'a> {
274283
CompileController {
275284
after_parse: PhaseController::basic(),
285+
after_expand: PhaseController::basic(),
276286
after_hir_lowering: PhaseController::basic(),
277287
after_analysis: PhaseController::basic(),
278288
after_llvm: PhaseController::basic(),
@@ -363,6 +373,23 @@ impl<'a, 'b, 'ast, 'tcx> CompileState<'a, 'b, 'ast, 'tcx> {
363373
}
364374
}
365375

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+
366393
fn state_after_hir_lowering(input: &'a Input,
367394
session: &'ast Session,
368395
out_dir: &'a Option<PathBuf>,
@@ -496,13 +523,16 @@ pub struct ExpansionResult<'a> {
496523
/// standard library and prelude, and name resolution.
497524
///
498525
/// 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+
{
506536
let time_passes = sess.time_passes();
507537

508538
// 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,
685715
"AST validation",
686716
|| ast_validation::check_crate(sess, &krate));
687717

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+
689732
resolver.resolve_crate(&krate);
690-
});
733+
Ok(())
734+
})?;
691735

692736
// Lower ast -> hir.
693737
let hir_forest = time(sess.time_passes(), "lowering ast -> hir", || {

src/librustc_driver/test.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,11 @@ fn test_env<F>(source_string: &str,
116116
input: source_string.to_string(),
117117
};
118118
let krate = driver::phase_1_parse_input(&sess, krate_config, &input).unwrap();
119-
let driver::ExpansionResult { defs, resolutions, mut hir_forest, .. } =
120-
driver::phase_2_configure_and_expand(&sess, &cstore, krate, "test", None, MakeGlobMap::No)
121-
.expect("phase 2 aborted");
119+
let driver::ExpansionResult { defs, resolutions, mut hir_forest, .. } = {
120+
driver::phase_2_configure_and_expand(
121+
&sess, &cstore, krate, "test", None, MakeGlobMap::No, |_| Ok(()),
122+
).expect("phase 2 aborted")
123+
};
122124
let _ignore = dep_graph.in_ignore();
123125

124126
let arenas = ty::CtxtArenas::new();

src/librustc_resolve/lib.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,18 +1167,6 @@ impl<'a> Resolver<'a> {
11671167

11681168
/// Entry point to crate resolution.
11691169
pub fn resolve_crate(&mut self, krate: &Crate) {
1170-
// Currently, we ignore the name resolution data structures for
1171-
// the purposes of dependency tracking. Instead we will run name
1172-
// resolution and include its output in the hash of each item,
1173-
// much like we do for macro expansion. In other words, the hash
1174-
// reflects not just its contents but the results of name
1175-
// resolution on those contents. Hopefully we'll push this back at
1176-
// some point.
1177-
let _ignore = self.session.dep_graph.in_ignore();
1178-
1179-
self.build_reduced_graph(krate);
1180-
resolve_imports::resolve_imports(self);
1181-
11821170
self.current_module = self.graph_root;
11831171
visit::walk_crate(self, krate);
11841172

src/librustc_resolve/resolve_imports.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ use syntax_pos::{Span, DUMMY_SP};
3030

3131
use std::cell::{Cell, RefCell};
3232

33+
impl<'a> Resolver<'a> {
34+
pub fn resolve_imports(&mut self) {
35+
ImportResolver { resolver: self }.resolve_imports();
36+
}
37+
}
38+
3339
/// Contains data for specific types of import directives.
3440
#[derive(Clone, Debug)]
3541
pub enum ImportDirectiveSubclass {
@@ -722,8 +728,3 @@ fn import_directive_subclass_to_string(subclass: &ImportDirectiveSubclass) -> St
722728
GlobImport { .. } => "*".to_string(),
723729
}
724730
}
725-
726-
pub fn resolve_imports(resolver: &mut Resolver) {
727-
let mut import_resolver = ImportResolver { resolver: resolver };
728-
import_resolver.resolve_imports();
729-
}

src/librustdoc/core.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ pub fn run_core(search_paths: SearchPaths,
149149
let name = link::find_crate_name(Some(&sess), &krate.attrs, &input);
150150

151151
let driver::ExpansionResult { defs, analysis, resolutions, mut hir_forest, .. } = {
152-
let make_glob_map = resolve::MakeGlobMap::No;
153-
driver::phase_2_configure_and_expand(&sess, &cstore, krate, &name, None, make_glob_map)
154-
.expect("phase_2_configure_and_expand aborted in rustdoc!")
152+
driver::phase_2_configure_and_expand(
153+
&sess, &cstore, krate, &name, None, resolve::MakeGlobMap::No, |_| Ok(()),
154+
).expect("phase_2_configure_and_expand aborted in rustdoc!")
155155
};
156156

157157
let arenas = ty::CtxtArenas::new();

src/librustdoc/test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ pub fn run(input: &str,
9595
cfg.extend(config::parse_cfgspecs(cfgs.clone()));
9696
let krate = panictry!(driver::phase_1_parse_input(&sess, cfg, &input));
9797
let driver::ExpansionResult { defs, mut hir_forest, .. } = {
98-
let make_glob_map = MakeGlobMap::No;
99-
phase_2_configure_and_expand(&sess, &cstore, krate, "rustdoc-test", None, make_glob_map)
100-
.expect("phase_2_configure_and_expand aborted in rustdoc!")
98+
phase_2_configure_and_expand(
99+
&sess, &cstore, krate, "rustdoc-test", None, MakeGlobMap::No, |_| Ok(())
100+
).expect("phase_2_configure_and_expand aborted in rustdoc!")
101101
};
102102

103103
let dep_graph = DepGraph::new(false);

src/test/run-make/execution-engine/test.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,9 @@ fn compile_program(input: &str, sysroot: PathBuf)
241241
let krate = panictry!(driver::phase_1_parse_input(&sess, cfg, &input));
242242

243243
let driver::ExpansionResult { defs, analysis, resolutions, mut hir_forest, .. } = {
244-
driver::phase_2_configure_and_expand(&sess, &cstore, krate, &id, None, MakeGlobMap::No)
245-
.expect("phase_2 returned `None`")
244+
driver::phase_2_configure_and_expand(
245+
&sess, &cstore, krate, &id, None, MakeGlobMap::No, |_| Ok(()),
246+
).expect("phase_2 returned `None`")
246247
};
247248

248249
let arenas = ty::CtxtArenas::new();

0 commit comments

Comments
 (0)