Skip to content

Commit 01ed700

Browse files
committed
Auto merge of #33450 - SiegeLord:dep_info_no_analysis, r=nrc
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 #33231.
2 parents 4ec5ce5 + 215b260 commit 01ed700

File tree

6 files changed

+97
-45
lines changed

6 files changed

+97
-45
lines changed

src/librustc_driver/driver.rs

+50-21
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,19 @@ 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+
141154
let expanded_crate = assign_node_ids(sess, expanded_crate);
142155
let dep_graph = DepGraph::new(sess.opts.build_dep_graph());
143156

@@ -173,25 +186,22 @@ pub fn compile_input(sess: &Session,
173186
"indexing hir",
174187
move || hir_map::map_crate(hir_forest, defs));
175188

176-
177-
write_out_deps(sess, &outputs, &id);
178-
179189
{
180190
let _ignore = hir_map.dep_graph.in_ignore();
181-
controller_entry_point!(after_write_deps,
191+
controller_entry_point!(after_hir_lowering,
182192
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),
193+
CompileState::state_after_hir_lowering(input,
194+
sess,
195+
outdir,
196+
output,
197+
&arenas,
198+
&cstore,
199+
&hir_map,
200+
&analysis,
201+
&resolutions,
202+
&expanded_crate,
203+
&hir_map.krate(),
204+
&id),
195205
Ok(()));
196206
}
197207

@@ -311,6 +321,7 @@ pub struct CompileController<'a> {
311321
pub after_parse: PhaseController<'a>,
312322
pub after_expand: PhaseController<'a>,
313323
pub after_write_deps: PhaseController<'a>,
324+
pub after_hir_lowering: PhaseController<'a>,
314325
pub after_analysis: PhaseController<'a>,
315326
pub after_llvm: PhaseController<'a>,
316327

@@ -323,6 +334,7 @@ impl<'a> CompileController<'a> {
323334
after_parse: PhaseController::basic(),
324335
after_expand: PhaseController::basic(),
325336
after_write_deps: PhaseController::basic(),
337+
after_hir_lowering: PhaseController::basic(),
326338
after_analysis: PhaseController::basic(),
327339
after_llvm: PhaseController::basic(),
328340
make_glob_map: resolve::MakeGlobMap::No,
@@ -433,15 +445,32 @@ impl<'a, 'b, 'ast, 'tcx> CompileState<'a, 'b, 'ast, 'tcx> {
433445
session: &'ast Session,
434446
out_dir: &'a Option<PathBuf>,
435447
out_file: &'a Option<PathBuf>,
436-
arenas: &'ast ty::CtxtArenas<'ast>,
437448
cstore: &'a CStore,
438-
hir_map: &'a hir_map::Map<'ast>,
439-
analysis: &'a ty::CrateAnalysis,
440-
resolutions: &'a Resolutions,
441449
krate: &'a ast::Crate,
442-
hir_crate: &'a hir::Crate,
443450
crate_name: &'a str)
444451
-> CompileState<'a, 'b, 'ast, 'tcx> {
452+
CompileState {
453+
crate_name: Some(crate_name),
454+
cstore: Some(cstore),
455+
expanded_crate: Some(krate),
456+
out_file: out_file.as_ref().map(|s| &**s),
457+
..CompileState::empty(input, session, out_dir)
458+
}
459+
}
460+
461+
fn state_after_hir_lowering(input: &'a Input,
462+
session: &'ast Session,
463+
out_dir: &'a Option<PathBuf>,
464+
out_file: &'a Option<PathBuf>,
465+
arenas: &'ast ty::CtxtArenas<'ast>,
466+
cstore: &'a CStore,
467+
hir_map: &'a hir_map::Map<'ast>,
468+
analysis: &'a ty::CrateAnalysis,
469+
resolutions: &'a Resolutions,
470+
krate: &'a ast::Crate,
471+
hir_crate: &'a hir::Crate,
472+
crate_name: &'a str)
473+
-> CompileState<'a, 'b, 'ast, 'tcx> {
445474
CompileState {
446475
crate_name: Some(crate_name),
447476
arenas: Some(arenas),

src/librustc_driver/lib.rs

+13-13
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_hir_lowering.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_hir_lowering.callback = box move |state| {
470+
pretty::print_after_hir_lowering(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

+11-11
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_hir_lowering<'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

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'.bak' 's/^.*input.dd/input.dd/g' $(TMPDIR)/input.dd
6+
diff -u $(TMPDIR)/input.dd input.dd
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
input.dd: input.rs
2+
3+
input.rs:
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)