Skip to content

Commit f16eac9

Browse files
SiegeLordExSiegeLord
authored andcommitted
Make --emit dep-info work correctly with -Z no-analysis again.
Previously, it would attempt to resolve some external crates that weren't necessary for dep-info output. Fixes rust-lang#33231.
1 parent d658809 commit f16eac9

File tree

6 files changed

+93
-40
lines changed

6 files changed

+93
-40
lines changed

src/librustc_driver/driver.rs

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,20 @@ pub fn compile_input(sess: &Session,
138138
&id),
139139
Ok(()));
140140

141+
write_out_deps(sess, &outputs, &id);
142+
143+
{ controller_entry_point!(after_write_deps,
144+
sess,
145+
CompileState::state_after_write_deps(input,
146+
sess,
147+
outdir,
148+
output,
149+
&cstore,
150+
&expanded_crate,
151+
&id),
152+
Ok(()));
153+
}
154+
141155
let expanded_crate = assign_node_ids(sess, expanded_crate);
142156
let dep_graph = DepGraph::new(sess.opts.build_dep_graph());
143157

@@ -173,25 +187,22 @@ pub fn compile_input(sess: &Session,
173187
"indexing hir",
174188
move || hir_map::map_crate(hir_forest, defs));
175189

176-
177-
write_out_deps(sess, &outputs, &id);
178-
179190
{
180191
let _ignore = hir_map.dep_graph.in_ignore();
181-
controller_entry_point!(after_write_deps,
192+
controller_entry_point!(after_ast,
182193
sess,
183-
CompileState::state_after_write_deps(input,
184-
sess,
185-
outdir,
186-
output,
187-
&arenas,
188-
&cstore,
189-
&hir_map,
190-
&analysis,
191-
&resolutions,
192-
&expanded_crate,
193-
&hir_map.krate(),
194-
&id),
194+
CompileState::state_after_ast(input,
195+
sess,
196+
outdir,
197+
output,
198+
&arenas,
199+
&cstore,
200+
&hir_map,
201+
&analysis,
202+
&resolutions,
203+
&expanded_crate,
204+
&hir_map.krate(),
205+
&id),
195206
Ok(()));
196207
}
197208

@@ -311,6 +322,7 @@ pub struct CompileController<'a> {
311322
pub after_parse: PhaseController<'a>,
312323
pub after_expand: PhaseController<'a>,
313324
pub after_write_deps: PhaseController<'a>,
325+
pub after_ast: PhaseController<'a>,
314326
pub after_analysis: PhaseController<'a>,
315327
pub after_llvm: PhaseController<'a>,
316328

@@ -323,6 +335,7 @@ impl<'a> CompileController<'a> {
323335
after_parse: PhaseController::basic(),
324336
after_expand: PhaseController::basic(),
325337
after_write_deps: PhaseController::basic(),
338+
after_ast: PhaseController::basic(),
326339
after_analysis: PhaseController::basic(),
327340
after_llvm: PhaseController::basic(),
328341
make_glob_map: resolve::MakeGlobMap::No,
@@ -430,6 +443,23 @@ impl<'a, 'b, 'ast, 'tcx> CompileState<'a, 'b, 'ast, 'tcx> {
430443
}
431444

432445
fn state_after_write_deps(input: &'a Input,
446+
session: &'ast Session,
447+
out_dir: &'a Option<PathBuf>,
448+
out_file: &'a Option<PathBuf>,
449+
cstore: &'a CStore,
450+
krate: &'a ast::Crate,
451+
crate_name: &'a str)
452+
-> CompileState<'a, 'b, 'ast, 'tcx> {
453+
CompileState {
454+
crate_name: Some(crate_name),
455+
cstore: Some(cstore),
456+
expanded_crate: Some(krate),
457+
out_file: out_file.as_ref().map(|s| &**s),
458+
..CompileState::empty(input, session, out_dir)
459+
}
460+
}
461+
462+
fn state_after_ast(input: &'a Input,
433463
session: &'ast Session,
434464
out_dir: &'a Option<PathBuf>,
435465
out_file: &'a Option<PathBuf>,

src/librustc_driver/lib.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -461,23 +461,23 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
461461

462462
if let Some((ppm, opt_uii)) = parse_pretty(sess, matches) {
463463
if ppm.needs_ast_map(&opt_uii) {
464-
control.after_write_deps.stop = Compilation::Stop;
464+
control.after_ast.stop = Compilation::Stop;
465465

466466
control.after_parse.callback = box move |state| {
467467
state.krate = Some(pretty::fold_crate(state.krate.take().unwrap(), ppm));
468468
};
469-
control.after_write_deps.callback = box move |state| {
470-
pretty::print_after_write_deps(state.session,
471-
state.ast_map.unwrap(),
472-
state.analysis.unwrap(),
473-
state.resolutions.unwrap(),
474-
state.input,
475-
&state.expanded_crate.take().unwrap(),
476-
state.crate_name.unwrap(),
477-
ppm,
478-
state.arenas.unwrap(),
479-
opt_uii.clone(),
480-
state.out_file);
469+
control.after_ast.callback = box move |state| {
470+
pretty::print_after_ast(state.session,
471+
state.ast_map.unwrap(),
472+
state.analysis.unwrap(),
473+
state.resolutions.unwrap(),
474+
state.input,
475+
&state.expanded_crate.take().unwrap(),
476+
state.crate_name.unwrap(),
477+
ppm,
478+
state.arenas.unwrap(),
479+
opt_uii.clone(),
480+
state.out_file);
481481
};
482482
} else {
483483
control.after_parse.stop = Compilation::Stop;

src/librustc_driver/pretty.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -812,17 +812,17 @@ pub fn print_after_parsing(sess: &Session,
812812
write_output(out, ofile);
813813
}
814814

815-
pub fn print_after_write_deps<'tcx, 'a: 'tcx>(sess: &'a Session,
816-
ast_map: &hir_map::Map<'tcx>,
817-
analysis: &ty::CrateAnalysis,
818-
resolutions: &Resolutions,
819-
input: &Input,
820-
krate: &ast::Crate,
821-
crate_name: &str,
822-
ppm: PpMode,
823-
arenas: &'tcx ty::CtxtArenas<'tcx>,
824-
opt_uii: Option<UserIdentifiedItem>,
825-
ofile: Option<&Path>) {
815+
pub fn print_after_ast<'tcx, 'a: 'tcx>(sess: &'a Session,
816+
ast_map: &hir_map::Map<'tcx>,
817+
analysis: &ty::CrateAnalysis,
818+
resolutions: &Resolutions,
819+
input: &Input,
820+
krate: &ast::Crate,
821+
crate_name: &str,
822+
ppm: PpMode,
823+
arenas: &'tcx ty::CtxtArenas<'tcx>,
824+
opt_uii: Option<UserIdentifiedItem>,
825+
ofile: Option<&Path>) {
826826
let dep_graph = DepGraph::new(false);
827827
let _ignore = dep_graph.in_ignore();
828828

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-include ../tools.mk
2+
3+
all:
4+
$(RUSTC) -o $(TMPDIR)/input.dd -Z no-analysis --emit dep-info input.rs
5+
sed -i "s@$(TMPDIR)/@@g" $(TMPDIR)/input.dd
6+
diff -u $(TMPDIR)/input.dd input.dd
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
input.dd: input.rs
2+
3+
input.rs:
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Tests that dep info can be emitted without resolving external crates.
12+
extern crate not_there;
13+
14+
fn main() {}

0 commit comments

Comments
 (0)