From f16eac928a7feec28825db36acd259aca2382381 Mon Sep 17 00:00:00 2001 From: Pavel Sountsov Date: Thu, 5 May 2016 21:48:44 -0700 Subject: [PATCH 1/6] 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. --- src/librustc_driver/driver.rs | 62 ++++++++++++++----- src/librustc_driver/lib.rs | 26 ++++---- src/librustc_driver/pretty.rs | 22 +++---- .../run-make/dep-info-no-analysis/Makefile | 6 ++ .../run-make/dep-info-no-analysis/input.dd | 3 + .../run-make/dep-info-no-analysis/input.rs | 14 +++++ 6 files changed, 93 insertions(+), 40 deletions(-) create mode 100644 src/test/run-make/dep-info-no-analysis/Makefile create mode 100644 src/test/run-make/dep-info-no-analysis/input.dd create mode 100644 src/test/run-make/dep-info-no-analysis/input.rs diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index e72204e5e22de..0d5ecc53a7900 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -138,6 +138,20 @@ pub fn compile_input(sess: &Session, &id), Ok(())); + write_out_deps(sess, &outputs, &id); + + { controller_entry_point!(after_write_deps, + sess, + CompileState::state_after_write_deps(input, + sess, + outdir, + output, + &cstore, + &expanded_crate, + &id), + Ok(())); + } + let expanded_crate = assign_node_ids(sess, expanded_crate); let dep_graph = DepGraph::new(sess.opts.build_dep_graph()); @@ -173,25 +187,22 @@ pub fn compile_input(sess: &Session, "indexing hir", move || hir_map::map_crate(hir_forest, defs)); - - write_out_deps(sess, &outputs, &id); - { let _ignore = hir_map.dep_graph.in_ignore(); - controller_entry_point!(after_write_deps, + controller_entry_point!(after_ast, sess, - CompileState::state_after_write_deps(input, - sess, - outdir, - output, - &arenas, - &cstore, - &hir_map, - &analysis, - &resolutions, - &expanded_crate, - &hir_map.krate(), - &id), + CompileState::state_after_ast(input, + sess, + outdir, + output, + &arenas, + &cstore, + &hir_map, + &analysis, + &resolutions, + &expanded_crate, + &hir_map.krate(), + &id), Ok(())); } @@ -311,6 +322,7 @@ pub struct CompileController<'a> { pub after_parse: PhaseController<'a>, pub after_expand: PhaseController<'a>, pub after_write_deps: PhaseController<'a>, + pub after_ast: PhaseController<'a>, pub after_analysis: PhaseController<'a>, pub after_llvm: PhaseController<'a>, @@ -323,6 +335,7 @@ impl<'a> CompileController<'a> { after_parse: PhaseController::basic(), after_expand: PhaseController::basic(), after_write_deps: PhaseController::basic(), + after_ast: PhaseController::basic(), after_analysis: PhaseController::basic(), after_llvm: PhaseController::basic(), make_glob_map: resolve::MakeGlobMap::No, @@ -430,6 +443,23 @@ impl<'a, 'b, 'ast, 'tcx> CompileState<'a, 'b, 'ast, 'tcx> { } fn state_after_write_deps(input: &'a Input, + session: &'ast Session, + out_dir: &'a Option, + out_file: &'a Option, + cstore: &'a CStore, + krate: &'a ast::Crate, + crate_name: &'a str) + -> CompileState<'a, 'b, 'ast, 'tcx> { + CompileState { + crate_name: Some(crate_name), + cstore: Some(cstore), + expanded_crate: Some(krate), + out_file: out_file.as_ref().map(|s| &**s), + ..CompileState::empty(input, session, out_dir) + } + } + + fn state_after_ast(input: &'a Input, session: &'ast Session, out_dir: &'a Option, out_file: &'a Option, diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 4da36be94e009..483ba044add62 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -461,23 +461,23 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls { if let Some((ppm, opt_uii)) = parse_pretty(sess, matches) { if ppm.needs_ast_map(&opt_uii) { - control.after_write_deps.stop = Compilation::Stop; + control.after_ast.stop = Compilation::Stop; control.after_parse.callback = box move |state| { state.krate = Some(pretty::fold_crate(state.krate.take().unwrap(), ppm)); }; - control.after_write_deps.callback = box move |state| { - pretty::print_after_write_deps(state.session, - state.ast_map.unwrap(), - state.analysis.unwrap(), - state.resolutions.unwrap(), - state.input, - &state.expanded_crate.take().unwrap(), - state.crate_name.unwrap(), - ppm, - state.arenas.unwrap(), - opt_uii.clone(), - state.out_file); + control.after_ast.callback = box move |state| { + pretty::print_after_ast(state.session, + state.ast_map.unwrap(), + state.analysis.unwrap(), + state.resolutions.unwrap(), + state.input, + &state.expanded_crate.take().unwrap(), + state.crate_name.unwrap(), + ppm, + state.arenas.unwrap(), + opt_uii.clone(), + state.out_file); }; } else { control.after_parse.stop = Compilation::Stop; diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index 8d8984000c7e4..2fd015bf5b80e 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -812,17 +812,17 @@ pub fn print_after_parsing(sess: &Session, write_output(out, ofile); } -pub fn print_after_write_deps<'tcx, 'a: 'tcx>(sess: &'a Session, - ast_map: &hir_map::Map<'tcx>, - analysis: &ty::CrateAnalysis, - resolutions: &Resolutions, - input: &Input, - krate: &ast::Crate, - crate_name: &str, - ppm: PpMode, - arenas: &'tcx ty::CtxtArenas<'tcx>, - opt_uii: Option, - ofile: Option<&Path>) { +pub fn print_after_ast<'tcx, 'a: 'tcx>(sess: &'a Session, + ast_map: &hir_map::Map<'tcx>, + analysis: &ty::CrateAnalysis, + resolutions: &Resolutions, + input: &Input, + krate: &ast::Crate, + crate_name: &str, + ppm: PpMode, + arenas: &'tcx ty::CtxtArenas<'tcx>, + opt_uii: Option, + ofile: Option<&Path>) { let dep_graph = DepGraph::new(false); let _ignore = dep_graph.in_ignore(); diff --git a/src/test/run-make/dep-info-no-analysis/Makefile b/src/test/run-make/dep-info-no-analysis/Makefile new file mode 100644 index 0000000000000..8d31de3781c2d --- /dev/null +++ b/src/test/run-make/dep-info-no-analysis/Makefile @@ -0,0 +1,6 @@ +-include ../tools.mk + +all: + $(RUSTC) -o $(TMPDIR)/input.dd -Z no-analysis --emit dep-info input.rs + sed -i "s@$(TMPDIR)/@@g" $(TMPDIR)/input.dd + diff -u $(TMPDIR)/input.dd input.dd diff --git a/src/test/run-make/dep-info-no-analysis/input.dd b/src/test/run-make/dep-info-no-analysis/input.dd new file mode 100644 index 0000000000000..f2c8676515b8a --- /dev/null +++ b/src/test/run-make/dep-info-no-analysis/input.dd @@ -0,0 +1,3 @@ +input.dd: input.rs + +input.rs: diff --git a/src/test/run-make/dep-info-no-analysis/input.rs b/src/test/run-make/dep-info-no-analysis/input.rs new file mode 100644 index 0000000000000..523b0f0670ce4 --- /dev/null +++ b/src/test/run-make/dep-info-no-analysis/input.rs @@ -0,0 +1,14 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Tests that dep info can be emitted without resolving external crates. +extern crate not_there; + +fn main() {} From 105aa8c30fc97fc7bfadc23bbf35eee412e164cb Mon Sep 17 00:00:00 2001 From: Pavel Sountsov Date: Thu, 5 May 2016 22:06:56 -0700 Subject: [PATCH 2/6] Fix funky formatting. --- src/librustc_driver/driver.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 0d5ecc53a7900..731283abc10a2 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -140,17 +140,16 @@ pub fn compile_input(sess: &Session, write_out_deps(sess, &outputs, &id); - { controller_entry_point!(after_write_deps, - sess, - CompileState::state_after_write_deps(input, - sess, - outdir, - output, - &cstore, - &expanded_crate, - &id), - Ok(())); - } + controller_entry_point!(after_write_deps, + sess, + CompileState::state_after_write_deps(input, + sess, + outdir, + output, + &cstore, + &expanded_crate, + &id), + Ok(())); let expanded_crate = assign_node_ids(sess, expanded_crate); let dep_graph = DepGraph::new(sess.opts.build_dep_graph()); From 64cca3ab2dfa7643fe6d67505001c43f7e8e2868 Mon Sep 17 00:00:00 2001 From: Pavel Sountsov Date: Sun, 8 May 2016 10:08:09 -0700 Subject: [PATCH 3/6] Rename after_ast to after_hir_lowering. --- src/librustc_driver/driver.rs | 34 +++++++++++++++++----------------- src/librustc_driver/lib.rs | 4 ++-- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 731283abc10a2..96aa0bb5de579 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -188,9 +188,9 @@ pub fn compile_input(sess: &Session, { let _ignore = hir_map.dep_graph.in_ignore(); - controller_entry_point!(after_ast, + controller_entry_point!(after_hir_lowering, sess, - CompileState::state_after_ast(input, + CompileState::state_after_hir_lowering(input, sess, outdir, output, @@ -321,7 +321,7 @@ pub struct CompileController<'a> { pub after_parse: PhaseController<'a>, pub after_expand: PhaseController<'a>, pub after_write_deps: PhaseController<'a>, - pub after_ast: PhaseController<'a>, + pub after_hir_lowering: PhaseController<'a>, pub after_analysis: PhaseController<'a>, pub after_llvm: PhaseController<'a>, @@ -334,7 +334,7 @@ impl<'a> CompileController<'a> { after_parse: PhaseController::basic(), after_expand: PhaseController::basic(), after_write_deps: PhaseController::basic(), - after_ast: PhaseController::basic(), + after_hir_lowering: PhaseController::basic(), after_analysis: PhaseController::basic(), after_llvm: PhaseController::basic(), make_glob_map: resolve::MakeGlobMap::No, @@ -458,19 +458,19 @@ impl<'a, 'b, 'ast, 'tcx> CompileState<'a, 'b, 'ast, 'tcx> { } } - fn state_after_ast(input: &'a Input, - session: &'ast Session, - out_dir: &'a Option, - out_file: &'a Option, - arenas: &'ast ty::CtxtArenas<'ast>, - cstore: &'a CStore, - hir_map: &'a hir_map::Map<'ast>, - analysis: &'a ty::CrateAnalysis, - resolutions: &'a Resolutions, - krate: &'a ast::Crate, - hir_crate: &'a hir::Crate, - crate_name: &'a str) - -> CompileState<'a, 'b, 'ast, 'tcx> { + fn state_after_hir_lowering(input: &'a Input, + session: &'ast Session, + out_dir: &'a Option, + out_file: &'a Option, + arenas: &'ast ty::CtxtArenas<'ast>, + cstore: &'a CStore, + hir_map: &'a hir_map::Map<'ast>, + analysis: &'a ty::CrateAnalysis, + resolutions: &'a Resolutions, + krate: &'a ast::Crate, + hir_crate: &'a hir::Crate, + crate_name: &'a str) + -> CompileState<'a, 'b, 'ast, 'tcx> { CompileState { crate_name: Some(crate_name), arenas: Some(arenas), diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 483ba044add62..796cf82c77511 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -461,12 +461,12 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls { if let Some((ppm, opt_uii)) = parse_pretty(sess, matches) { if ppm.needs_ast_map(&opt_uii) { - control.after_ast.stop = Compilation::Stop; + control.after_hir_lowering.stop = Compilation::Stop; control.after_parse.callback = box move |state| { state.krate = Some(pretty::fold_crate(state.krate.take().unwrap(), ppm)); }; - control.after_ast.callback = box move |state| { + control.after_hir_lowering.callback = box move |state| { pretty::print_after_ast(state.session, state.ast_map.unwrap(), state.analysis.unwrap(), From a75fc0d23cd46157166b162ae0b1f15ba086a6f7 Mon Sep 17 00:00:00 2001 From: Pavel Sountsov Date: Mon, 9 May 2016 08:31:43 -0700 Subject: [PATCH 4/6] Make the dep-info-no-analysis regex more robust on Windows. --- src/test/run-make/dep-info-no-analysis/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/run-make/dep-info-no-analysis/Makefile b/src/test/run-make/dep-info-no-analysis/Makefile index 8d31de3781c2d..66bb37d8bf33e 100644 --- a/src/test/run-make/dep-info-no-analysis/Makefile +++ b/src/test/run-make/dep-info-no-analysis/Makefile @@ -2,5 +2,5 @@ all: $(RUSTC) -o $(TMPDIR)/input.dd -Z no-analysis --emit dep-info input.rs - sed -i "s@$(TMPDIR)/@@g" $(TMPDIR)/input.dd + sed -i "s/^.*input.dd/input.dd/g" $(TMPDIR)/input.dd diff -u $(TMPDIR)/input.dd input.dd From ba04a52b9677b8c472196a9c280808a63a69bf28 Mon Sep 17 00:00:00 2001 From: Pavel Sountsov Date: Tue, 10 May 2016 19:21:44 -0700 Subject: [PATCH 5/6] Also rename the print_from_ast. --- src/librustc_driver/lib.rs | 22 +++++++++++----------- src/librustc_driver/pretty.rs | 22 +++++++++++----------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 796cf82c77511..2a4b30e016f28 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -467,17 +467,17 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls { state.krate = Some(pretty::fold_crate(state.krate.take().unwrap(), ppm)); }; control.after_hir_lowering.callback = box move |state| { - pretty::print_after_ast(state.session, - state.ast_map.unwrap(), - state.analysis.unwrap(), - state.resolutions.unwrap(), - state.input, - &state.expanded_crate.take().unwrap(), - state.crate_name.unwrap(), - ppm, - state.arenas.unwrap(), - opt_uii.clone(), - state.out_file); + pretty::print_after_hir_lowering(state.session, + state.ast_map.unwrap(), + state.analysis.unwrap(), + state.resolutions.unwrap(), + state.input, + &state.expanded_crate.take().unwrap(), + state.crate_name.unwrap(), + ppm, + state.arenas.unwrap(), + opt_uii.clone(), + state.out_file); }; } else { control.after_parse.stop = Compilation::Stop; diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index 2fd015bf5b80e..d3716af205396 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -812,17 +812,17 @@ pub fn print_after_parsing(sess: &Session, write_output(out, ofile); } -pub fn print_after_ast<'tcx, 'a: 'tcx>(sess: &'a Session, - ast_map: &hir_map::Map<'tcx>, - analysis: &ty::CrateAnalysis, - resolutions: &Resolutions, - input: &Input, - krate: &ast::Crate, - crate_name: &str, - ppm: PpMode, - arenas: &'tcx ty::CtxtArenas<'tcx>, - opt_uii: Option, - ofile: Option<&Path>) { +pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session, + ast_map: &hir_map::Map<'tcx>, + analysis: &ty::CrateAnalysis, + resolutions: &Resolutions, + input: &Input, + krate: &ast::Crate, + crate_name: &str, + ppm: PpMode, + arenas: &'tcx ty::CtxtArenas<'tcx>, + opt_uii: Option, + ofile: Option<&Path>) { let dep_graph = DepGraph::new(false); let _ignore = dep_graph.in_ignore(); From 215b2603f1a4a1f82e8a454addf36f104742b147 Mon Sep 17 00:00:00 2001 From: Pavel Sountsov Date: Thu, 12 May 2016 09:32:17 -0700 Subject: [PATCH 6/6] Fix the sed invocation to also work with BSD sed. --- src/test/run-make/dep-info-no-analysis/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/run-make/dep-info-no-analysis/Makefile b/src/test/run-make/dep-info-no-analysis/Makefile index 66bb37d8bf33e..5d2cfadfd020a 100644 --- a/src/test/run-make/dep-info-no-analysis/Makefile +++ b/src/test/run-make/dep-info-no-analysis/Makefile @@ -2,5 +2,5 @@ all: $(RUSTC) -o $(TMPDIR)/input.dd -Z no-analysis --emit dep-info input.rs - sed -i "s/^.*input.dd/input.dd/g" $(TMPDIR)/input.dd + sed -i'.bak' 's/^.*input.dd/input.dd/g' $(TMPDIR)/input.dd diff -u $(TMPDIR)/input.dd input.dd