Skip to content

Commit bbdbe99

Browse files
authored
Auto merge of #34480 - jseyfried:remove_entry_points, r=nrc
Remove redundant `CompileController` entry points Remove the `after_expand` and `after_write_deps` `CompileController` entry points. The only things that separate these entry points from `after_hir_lowering` are dep-info generation and HIR map construction, neither of which is computationally intensive or has the potential to error. r? @nrc
2 parents 696b703 + d1e3d62 commit bbdbe99

File tree

8 files changed

+57
-81
lines changed

8 files changed

+57
-81
lines changed

src/librustc_driver/driver.rs

Lines changed: 36 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -116,34 +116,20 @@ 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

123-
controller_entry_point!(after_expand,
124-
sess,
125-
CompileState::state_after_expand(input,
126-
sess,
127-
outdir,
128-
output,
129-
&cstore,
130-
&expanded_crate,
131-
&id),
132-
Ok(()));
133-
134131
write_out_deps(sess, &outputs, &id);
135132

136-
controller_entry_point!(after_write_deps,
137-
sess,
138-
CompileState::state_after_write_deps(input,
139-
sess,
140-
outdir,
141-
output,
142-
&cstore,
143-
&expanded_crate,
144-
&id),
145-
Ok(()));
146-
147133
let arenas = ty::CtxtArenas::new();
148134

149135
// Construct the HIR map
@@ -285,7 +271,6 @@ pub fn source_name(input: &Input) -> String {
285271
pub struct CompileController<'a> {
286272
pub after_parse: PhaseController<'a>,
287273
pub after_expand: PhaseController<'a>,
288-
pub after_write_deps: PhaseController<'a>,
289274
pub after_hir_lowering: PhaseController<'a>,
290275
pub after_analysis: PhaseController<'a>,
291276
pub after_llvm: PhaseController<'a>,
@@ -298,7 +283,6 @@ impl<'a> CompileController<'a> {
298283
CompileController {
299284
after_parse: PhaseController::basic(),
300285
after_expand: PhaseController::basic(),
301-
after_write_deps: PhaseController::basic(),
302286
after_hir_lowering: PhaseController::basic(),
303287
after_analysis: PhaseController::basic(),
304288
after_llvm: PhaseController::basic(),
@@ -406,23 +390,6 @@ impl<'a, 'b, 'ast, 'tcx> CompileState<'a, 'b, 'ast, 'tcx> {
406390
}
407391
}
408392

409-
fn state_after_write_deps(input: &'a Input,
410-
session: &'ast Session,
411-
out_dir: &'a Option<PathBuf>,
412-
out_file: &'a Option<PathBuf>,
413-
cstore: &'a CStore,
414-
krate: &'a ast::Crate,
415-
crate_name: &'a str)
416-
-> CompileState<'a, 'b, 'ast, 'tcx> {
417-
CompileState {
418-
crate_name: Some(crate_name),
419-
cstore: Some(cstore),
420-
expanded_crate: Some(krate),
421-
out_file: out_file.as_ref().map(|s| &**s),
422-
..CompileState::empty(input, session, out_dir)
423-
}
424-
}
425-
426393
fn state_after_hir_lowering(input: &'a Input,
427394
session: &'ast Session,
428395
out_dir: &'a Option<PathBuf>,
@@ -556,13 +523,16 @@ pub struct ExpansionResult<'a> {
556523
/// standard library and prelude, and name resolution.
557524
///
558525
/// Returns `None` if we're aborting after handling -W help.
559-
pub fn phase_2_configure_and_expand<'a>(sess: &Session,
560-
cstore: &CStore,
561-
mut krate: ast::Crate,
562-
crate_name: &'a str,
563-
addl_plugins: Option<Vec<String>>,
564-
make_glob_map: MakeGlobMap)
565-
-> 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+
{
566536
let time_passes = sess.time_passes();
567537

568538
// strip before anything else because crate metadata may use #[cfg_attr]
@@ -745,9 +715,23 @@ pub fn phase_2_configure_and_expand<'a>(sess: &Session,
745715
"AST validation",
746716
|| ast_validation::check_crate(sess, &krate));
747717

748-
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+
749732
resolver.resolve_crate(&krate);
750-
});
733+
Ok(())
734+
})?;
751735

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

src/librustc_driver/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
511511
}
512512

513513
if sess.opts.no_analysis || sess.opts.debugging_opts.ast_json {
514-
control.after_write_deps.stop = Compilation::Stop;
514+
control.after_hir_lowering.stop = Compilation::Stop;
515515
}
516516

517517
if !sess.opts.output_types.keys().any(|&i| i == OutputType::Exe) {

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)