From cab940e848d0645619a31ae068b5ccbbf47f9cb8 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 28 Mar 2021 18:30:25 +0200 Subject: [PATCH 01/14] Merge two consecutive tcx.analysis() calls --- compiler/rustc_driver/src/lib.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index c8891734ccec8..6d193ae2730fc 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -411,11 +411,10 @@ fn run_compiler( return early_exit(); } - if sess.opts.debugging_opts.save_analysis { - let crate_name = queries.crate_name()?.peek().clone(); - queries.global_ctxt()?.peek_mut().enter(|tcx| { - let result = tcx.analysis(LOCAL_CRATE); - + let crate_name = queries.crate_name()?.peek().clone(); + queries.global_ctxt()?.peek_mut().enter(|tcx| { + let result = tcx.analysis(LOCAL_CRATE); + if sess.opts.debugging_opts.save_analysis { sess.time("save_analysis", || { save::process_crate( tcx, @@ -428,12 +427,9 @@ fn run_compiler( ), ) }); - - result - })?; - } - - queries.global_ctxt()?.peek_mut().enter(|tcx| tcx.analysis(LOCAL_CRATE))?; + } + result + })?; if callbacks.after_analysis(compiler, queries) == Compilation::Stop { return early_exit(); From b5e049de0850edd90b60753cf8c0df62b9e159a1 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 28 Mar 2021 18:36:53 +0200 Subject: [PATCH 02/14] Remove dummy_config --- compiler/rustc_driver/src/lib.rs | 102 ++++++++++---------------- compiler/rustc_session/src/session.rs | 6 +- 2 files changed, 43 insertions(+), 65 deletions(-) diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index 6d193ae2730fc..6dd29e7959325 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -35,7 +35,7 @@ use rustc_session::config::{ErrorOutputType, Input, OutputType, PrintRequest, Tr use rustc_session::getopts; use rustc_session::lint::{Lint, LintId}; use rustc_session::{config, DiagnosticOutput, Session}; -use rustc_session::{early_error, early_warn}; +use rustc_session::{early_error, early_error_no_abort, early_warn}; use rustc_span::source_map::{FileLoader, FileName}; use rustc_span::symbol::sym; @@ -199,46 +199,49 @@ fn run_compiler( }; let sopts = config::build_session_options(&matches); - let cfg = interface::parse_cfgspecs(matches.opt_strs("cfg")); - - // We wrap `make_codegen_backend` in another `Option` such that `dummy_config` can take - // ownership of it when necessary, while also allowing the non-dummy config to take ownership - // when `dummy_config` is not used. - let mut make_codegen_backend = Some(make_codegen_backend); - - let mut dummy_config = |sopts, cfg, diagnostic_output| { - let mut config = interface::Config { - opts: sopts, - crate_cfg: cfg, - input: Input::File(PathBuf::new()), - input_path: None, - output_file: None, - output_dir: None, - file_loader: None, - diagnostic_output, - stderr: None, - lint_caps: Default::default(), - parse_sess_created: None, - register_lints: None, - override_queries: None, - make_codegen_backend: make_codegen_backend.take().unwrap(), - registry: diagnostics_registry(), - }; - callbacks.config(&mut config); - config - }; if let Some(ref code) = matches.opt_str("explain") { handle_explain(diagnostics_registry(), code, sopts.error_format); return Ok(()); } + let cfg = interface::parse_cfgspecs(matches.opt_strs("cfg")); let (odir, ofile) = make_output(&matches); - let (input, input_file_path, input_err) = match make_input(&matches.free) { - Some(v) => v, + let mut config = interface::Config { + opts: sopts, + crate_cfg: cfg, + input: Input::File(PathBuf::new()), + input_path: None, + output_file: ofile, + output_dir: odir, + file_loader, + diagnostic_output, + stderr: None, + lint_caps: Default::default(), + parse_sess_created: None, + register_lints: None, + override_queries: None, + make_codegen_backend, + registry: diagnostics_registry(), + }; + + match make_input(&matches.free) { + Some((input, input_file_path, input_err)) => { + if let Some(err) = input_err { + // Immediately stop compilation if there was an issue reading + // the input (for example if the input stream is not UTF-8). + early_error_no_abort(config.opts.error_format, &err.to_string()); + return Err(ErrorReported); + } + + config.input = input; + config.input_path = input_file_path; + + callbacks.config(&mut config); + } None => match matches.free.len() { 0 => { - let config = dummy_config(sopts, cfg, diagnostic_output); + callbacks.config(&mut config); interface::run_compiler(config, |compiler| { let sopts = &compiler.session().opts; if sopts.describe_lints { @@ -260,8 +263,8 @@ fn run_compiler( &***compiler.codegen_backend(), compiler.session(), None, - &odir, - &ofile, + &compiler.output_dir(), + &compiler.output_file(), ); if should_stop == Compilation::Stop { @@ -273,7 +276,7 @@ fn run_compiler( } 1 => panic!("make_input should have provided valid inputs"), _ => early_error( - sopts.error_format, + config.opts.error_format, &format!( "multiple input filenames provided (first two filenames are `{}` and `{}`)", matches.free[0], matches.free[1], @@ -282,35 +285,6 @@ fn run_compiler( }, }; - if let Some(err) = input_err { - // Immediately stop compilation if there was an issue reading - // the input (for example if the input stream is not UTF-8). - interface::run_compiler(dummy_config(sopts, cfg, diagnostic_output), |compiler| { - compiler.session().err(&err.to_string()); - }); - return Err(ErrorReported); - } - - let mut config = interface::Config { - opts: sopts, - crate_cfg: cfg, - input, - input_path: input_file_path, - output_file: ofile, - output_dir: odir, - file_loader, - diagnostic_output, - stderr: None, - lint_caps: Default::default(), - parse_sess_created: None, - register_lints: None, - override_queries: None, - make_codegen_backend: make_codegen_backend.unwrap(), - registry: diagnostics_registry(), - }; - - callbacks.config(&mut config); - interface::run_compiler(config, |compiler| { let sess = compiler.session(); let should_stop = RustcDefaultCalls::print_crate_info( diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 693f427d7afcc..43e0ac875bc34 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -1591,7 +1591,7 @@ pub enum IncrCompSession { InvalidBecauseOfErrors { session_directory: PathBuf }, } -pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! { +pub fn early_error_no_abort(output: config::ErrorOutputType, msg: &str) { let emitter: Box = match output { config::ErrorOutputType::HumanReadable(kind) => { let (short, color_config) = kind.unzip(); @@ -1603,6 +1603,10 @@ pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! { }; let handler = rustc_errors::Handler::with_emitter(true, None, emitter); handler.struct_fatal(msg).emit(); +} + +pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! { + early_error_no_abort(output, msg); rustc_errors::FatalError.raise(); } From 2fa71752935c3f43be549e58d5ac91309932385f Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 28 Mar 2021 18:48:52 +0200 Subject: [PATCH 03/14] Document a few things --- compiler/rustc_driver/src/lib.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index 6dd29e7959325..94d962a437380 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -133,6 +133,7 @@ pub fn diagnostics_registry() -> Registry { Registry::new(&rustc_error_codes::DIAGNOSTICS) } +/// This is the primary entry point for rustc. pub struct RunCompiler<'a, 'b> { at_args: &'a [String], callbacks: &'b mut (dyn Callbacks + Send), @@ -146,6 +147,9 @@ impl<'a, 'b> RunCompiler<'a, 'b> { pub fn new(at_args: &'a [String], callbacks: &'b mut (dyn Callbacks + Send)) -> Self { Self { at_args, callbacks, file_loader: None, emitter: None, make_codegen_backend: None } } + + /// Set a custom codegen backend. + /// /// Used by cg_clif. pub fn set_make_codegen_backend( &mut self, @@ -156,11 +160,17 @@ impl<'a, 'b> RunCompiler<'a, 'b> { self.make_codegen_backend = make_codegen_backend; self } + + /// Emit diagnostics to the specified location. + /// /// Used by RLS. pub fn set_emitter(&mut self, emitter: Option>) -> &mut Self { self.emitter = emitter; self } + + /// Load files from sources other than the file system. + /// /// Used by RLS. pub fn set_file_loader( &mut self, @@ -169,6 +179,8 @@ impl<'a, 'b> RunCompiler<'a, 'b> { self.file_loader = file_loader; self } + + /// Parse args and run the compiler. pub fn run(self) -> interface::Result<()> { run_compiler( self.at_args, @@ -179,8 +191,6 @@ impl<'a, 'b> RunCompiler<'a, 'b> { ) } } -// Parse args and run the compiler. This is the primary entry point for rustc. -// The FileLoader provides a way to load files from sources other than the file system. fn run_compiler( at_args: &[String], callbacks: &mut (dyn Callbacks + Send), From 2acdc877006d7812dc32d1a08d560b7c8edfc34c Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 28 Mar 2021 19:00:49 +0200 Subject: [PATCH 04/14] Inline process_rlink into try_process_rlink --- compiler/rustc_driver/src/lib.rs | 37 +++++++++++++++----------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index 94d962a437380..2ca0e73c74d99 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -599,28 +599,25 @@ fn show_content_with_pager(content: &str) { } impl RustcDefaultCalls { - fn process_rlink(sess: &Session, compiler: &interface::Compiler) -> Result<(), ErrorReported> { - if let Input::File(file) = compiler.input() { - // FIXME: #![crate_type] and #![crate_name] support not implemented yet - let attrs = vec![]; - sess.init_crate_types(collect_crate_types(sess, &attrs)); - let outputs = compiler.build_output_filenames(&sess, &attrs); - let rlink_data = fs::read_to_string(file).unwrap_or_else(|err| { - sess.fatal(&format!("failed to read rlink file: {}", err)); - }); - let codegen_results: CodegenResults = json::decode(&rlink_data).unwrap_or_else(|err| { - sess.fatal(&format!("failed to decode rlink: {}", err)); - }); - compiler.codegen_backend().link(&sess, codegen_results, &outputs) - } else { - sess.fatal("rlink must be a file") - } - } - pub fn try_process_rlink(sess: &Session, compiler: &interface::Compiler) -> Compilation { if sess.opts.debugging_opts.link_only { - let result = RustcDefaultCalls::process_rlink(sess, compiler); - abort_on_err(result, sess); + if let Input::File(file) = compiler.input() { + // FIXME: #![crate_type] and #![crate_name] support not implemented yet + let attrs = vec![]; + sess.init_crate_types(collect_crate_types(sess, &attrs)); + let outputs = compiler.build_output_filenames(&sess, &attrs); + let rlink_data = fs::read_to_string(file).unwrap_or_else(|err| { + sess.fatal(&format!("failed to read rlink file: {}", err)); + }); + let codegen_results: CodegenResults = + json::decode(&rlink_data).unwrap_or_else(|err| { + sess.fatal(&format!("failed to decode rlink: {}", err)); + }); + let result = compiler.codegen_backend().link(&sess, codegen_results, &outputs); + abort_on_err(result, sess); + } else { + sess.fatal("rlink must be a file") + } Compilation::Stop } else { Compilation::Continue From c752ee53ae52dcb552f964e30cf57aa5f48a62f8 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 28 Mar 2021 19:18:44 +0200 Subject: [PATCH 05/14] Tiny cleanup --- compiler/rustc_driver/src/lib.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index 2ca0e73c74d99..198589a1090c4 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -603,9 +603,8 @@ impl RustcDefaultCalls { if sess.opts.debugging_opts.link_only { if let Input::File(file) = compiler.input() { // FIXME: #![crate_type] and #![crate_name] support not implemented yet - let attrs = vec![]; - sess.init_crate_types(collect_crate_types(sess, &attrs)); - let outputs = compiler.build_output_filenames(&sess, &attrs); + sess.init_crate_types(collect_crate_types(sess, &[])); + let outputs = compiler.build_output_filenames(&sess, &[]); let rlink_data = fs::read_to_string(file).unwrap_or_else(|err| { sess.fatal(&format!("failed to read rlink file: {}", err)); }); From 673c1b6e496432e68bca148fcfdae647ad21befb Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 28 Mar 2021 19:23:21 +0200 Subject: [PATCH 06/14] Remove unnecessary argument --- compiler/rustc_driver/src/lib.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index 198589a1090c4..97ba1aad0f328 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -308,7 +308,6 @@ fn run_compiler( RustcDefaultCalls::list_metadata( sess, &*compiler.codegen_backend().metadata_loader(), - &matches, compiler.input(), ) }) @@ -626,11 +625,9 @@ impl RustcDefaultCalls { pub fn list_metadata( sess: &Session, metadata_loader: &dyn MetadataLoader, - matches: &getopts::Matches, input: &Input, ) -> Compilation { - let r = matches.opt_strs("Z"); - if r.iter().any(|s| *s == "ls") { + if sess.opts.debugging_opts.ls { match *input { Input::File(ref ifile) => { let path = &(*ifile); From 808090eb073d8b2d56479045b6ef0fe67872a077 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 28 Mar 2021 22:14:09 +0200 Subject: [PATCH 07/14] Pass target_cpu to LinkerInfo::new instead of link_binary This is one step towards separating the linking code from codegen backends --- .../rustc_codegen_cranelift/src/driver/aot.rs | 2 +- compiler/rustc_codegen_cranelift/src/lib.rs | 2 - compiler/rustc_codegen_llvm/src/lib.rs | 3 +- compiler/rustc_codegen_ssa/src/back/link.rs | 7 +-- compiler/rustc_codegen_ssa/src/back/linker.rs | 43 ++++++++----------- compiler/rustc_codegen_ssa/src/back/write.rs | 3 +- compiler/rustc_codegen_ssa/src/base.rs | 6 ++- 7 files changed, 26 insertions(+), 40 deletions(-) diff --git a/compiler/rustc_codegen_cranelift/src/driver/aot.rs b/compiler/rustc_codegen_cranelift/src/driver/aot.rs index ed3bdedddced5..c7121b9386125 100644 --- a/compiler/rustc_codegen_cranelift/src/driver/aot.rs +++ b/compiler/rustc_codegen_cranelift/src/driver/aot.rs @@ -295,7 +295,7 @@ pub(super) fn run_aot( metadata_module, metadata, windows_subsystem, - linker_info: LinkerInfo::new(tcx), + linker_info: LinkerInfo::new(tcx, crate::target_triple(tcx.sess).to_string()), crate_info: CrateInfo::new(tcx), }, work_products, diff --git a/compiler/rustc_codegen_cranelift/src/lib.rs b/compiler/rustc_codegen_cranelift/src/lib.rs index 720d2a1253445..75b7b9bbeb567 100644 --- a/compiler/rustc_codegen_cranelift/src/lib.rs +++ b/compiler/rustc_codegen_cranelift/src/lib.rs @@ -267,13 +267,11 @@ impl CodegenBackend for CraneliftCodegenBackend { ) -> Result<(), ErrorReported> { use rustc_codegen_ssa::back::link::link_binary; - let target_cpu = crate::target_triple(sess).to_string(); link_binary::>( sess, &codegen_results, outputs, &codegen_results.crate_name.as_str(), - &target_cpu, ); Ok(()) diff --git a/compiler/rustc_codegen_llvm/src/lib.rs b/compiler/rustc_codegen_llvm/src/lib.rs index 5ca4b226c38fb..4707d17f18e47 100644 --- a/compiler/rustc_codegen_llvm/src/lib.rs +++ b/compiler/rustc_codegen_llvm/src/lib.rs @@ -270,6 +270,7 @@ impl CodegenBackend for LlvmCodegenBackend { Box::new(rustc_codegen_ssa::base::codegen_crate( LlvmCodegenBackend(()), tcx, + crate::llvm_util::target_cpu(tcx.sess).to_string(), metadata, need_metadata_module, )) @@ -305,13 +306,11 @@ impl CodegenBackend for LlvmCodegenBackend { // Run the linker on any artifacts that resulted from the LLVM run. // This should produce either a finished executable or library. - let target_cpu = crate::llvm_util::target_cpu(sess); link_binary::>( sess, &codegen_results, outputs, &codegen_results.crate_name.as_str(), - target_cpu, ); Ok(()) diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 686ebc13ea3fc..857088fe5661f 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -50,7 +50,6 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>( codegen_results: &CodegenResults, outputs: &OutputFilenames, crate_name: &str, - target_cpu: &str, ) { let _timer = sess.timer("link_binary"); let output_metadata = sess.opts.output_types.contains_key(&OutputType::Metadata); @@ -100,7 +99,6 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>( &out_filename, codegen_results, path.as_ref(), - target_cpu, ); } } @@ -531,7 +529,6 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>( out_filename: &Path, codegen_results: &CodegenResults, tmpdir: &Path, - target_cpu: &str, ) { info!("preparing {:?} to {:?}", crate_type, out_filename); let (linker_path, flavor) = linker_and_flavor(sess); @@ -543,7 +540,6 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>( tmpdir, out_filename, codegen_results, - target_cpu, ); linker::disable_localization(&mut cmd); @@ -1617,14 +1613,13 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>( tmpdir: &Path, out_filename: &Path, codegen_results: &CodegenResults, - target_cpu: &str, ) -> Command { let crt_objects_fallback = crt_objects_fallback(sess, crate_type); let base_cmd = get_linker(sess, path, flavor, crt_objects_fallback); // FIXME: Move `/LIBPATH` addition for uwp targets from the linker construction // to the linker args construction. assert!(base_cmd.get_args().is_empty() || sess.target.vendor == "uwp"); - let cmd = &mut *codegen_results.linker_info.to_linker(base_cmd, &sess, flavor, target_cpu); + let cmd = &mut *codegen_results.linker_info.to_linker(base_cmd, &sess, flavor); let link_output_kind = link_output_kind(sess, crate_type); // NO-OPT-OUT, OBJECT-FILES-MAYBE, CUSTOMIZATION-POINT diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index e19274e579b95..4d16ae3b0127b 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -37,12 +37,14 @@ pub fn disable_localization(linker: &mut Command) { /// need out of the shared crate context before we get rid of it. #[derive(Encodable, Decodable)] pub struct LinkerInfo { + target_cpu: String, exports: FxHashMap>, } impl LinkerInfo { - pub fn new(tcx: TyCtxt<'_>) -> LinkerInfo { + pub fn new(tcx: TyCtxt<'_>, target_cpu: String) -> LinkerInfo { LinkerInfo { + target_cpu, exports: tcx .sess .crate_types() @@ -57,38 +59,31 @@ impl LinkerInfo { cmd: Command, sess: &'a Session, flavor: LinkerFlavor, - target_cpu: &'a str, ) -> Box { match flavor { LinkerFlavor::Lld(LldFlavor::Link) | LinkerFlavor::Msvc => { Box::new(MsvcLinker { cmd, sess, info: self }) as Box } LinkerFlavor::Em => Box::new(EmLinker { cmd, sess, info: self }) as Box, - LinkerFlavor::Gcc => Box::new(GccLinker { - cmd, - sess, - info: self, - hinted_static: false, - is_ld: false, - target_cpu, - }) as Box, + LinkerFlavor::Gcc => { + Box::new(GccLinker { cmd, sess, info: self, hinted_static: false, is_ld: false }) + as Box + } LinkerFlavor::Lld(LldFlavor::Ld) | LinkerFlavor::Lld(LldFlavor::Ld64) - | LinkerFlavor::Ld => Box::new(GccLinker { - cmd, - sess, - info: self, - hinted_static: false, - is_ld: true, - target_cpu, - }) as Box, + | LinkerFlavor::Ld => { + Box::new(GccLinker { cmd, sess, info: self, hinted_static: false, is_ld: true }) + as Box + } LinkerFlavor::Lld(LldFlavor::Wasm) => { Box::new(WasmLd::new(cmd, sess, self)) as Box } - LinkerFlavor::PtxLinker => Box::new(PtxLinker { cmd, sess }) as Box, + LinkerFlavor::PtxLinker => { + Box::new(PtxLinker { cmd, sess, info: self }) as Box + } } } } @@ -156,7 +151,6 @@ pub struct GccLinker<'a> { hinted_static: bool, // Keeps track of the current hinting mode. // Link as ld is_ld: bool, - target_cpu: &'a str, } impl<'a> GccLinker<'a> { @@ -228,8 +222,7 @@ impl<'a> GccLinker<'a> { }; self.linker_arg(&format!("-plugin-opt={}", opt_level)); - let target_cpu = self.target_cpu; - self.linker_arg(&format!("-plugin-opt=mcpu={}", target_cpu)); + self.linker_arg(&format!("-plugin-opt=mcpu={}", self.info.target_cpu)); } fn build_dylib(&mut self, out_filename: &Path) { @@ -1276,6 +1269,7 @@ fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec { pub struct PtxLinker<'a> { cmd: Command, sess: &'a Session, + info: &'a LinkerInfo, } impl<'a> Linker for PtxLinker<'a> { @@ -1321,10 +1315,7 @@ impl<'a> Linker for PtxLinker<'a> { fn finalize(&mut self) { // Provide the linker with fallback to internal `target-cpu`. - self.cmd.arg("--fallback-arch").arg(match self.sess.opts.cg.target_cpu { - Some(ref s) => s, - None => &self.sess.target.cpu, - }); + self.cmd.arg("--fallback-arch").arg(&self.info.target_cpu); } fn link_dylib(&mut self, _lib: Symbol) { diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index 7a8d8fb13043b..cc9c6c2c2d658 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -426,6 +426,7 @@ fn need_pre_lto_bitcode_for_incr_comp(sess: &Session) -> bool { pub fn start_async_codegen( backend: B, tcx: TyCtxt<'_>, + target_cpu: String, metadata: EncodedMetadata, total_cgus: usize, ) -> OngoingCodegen { @@ -448,7 +449,7 @@ pub fn start_async_codegen( subsystem.to_string() }); - let linker_info = LinkerInfo::new(tcx); + let linker_info = LinkerInfo::new(tcx, target_cpu); let crate_info = CrateInfo::new(tcx); let regular_config = diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index 08e31c3b37f34..247c26d8b2213 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -461,12 +461,13 @@ fn get_argc_argv<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( pub fn codegen_crate( backend: B, tcx: TyCtxt<'tcx>, + target_cpu: String, metadata: EncodedMetadata, need_metadata_module: bool, ) -> OngoingCodegen { // Skip crate items and just output metadata in -Z no-codegen mode. if tcx.sess.opts.debugging_opts.no_codegen || !tcx.sess.opts.output_types.should_codegen() { - let ongoing_codegen = start_async_codegen(backend, tcx, metadata, 1); + let ongoing_codegen = start_async_codegen(backend, tcx, target_cpu, metadata, 1); ongoing_codegen.codegen_finished(tcx); @@ -492,7 +493,8 @@ pub fn codegen_crate( } } - let ongoing_codegen = start_async_codegen(backend.clone(), tcx, metadata, codegen_units.len()); + let ongoing_codegen = + start_async_codegen(backend.clone(), tcx, target_cpu, metadata, codegen_units.len()); let ongoing_codegen = AbortCodegenOnDrop::(Some(ongoing_codegen)); // Codegen an allocator shim, if necessary. From c47eeac61290cd3ef7994e0d68e754eb36d15001 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Mon, 29 Mar 2021 10:13:50 +0200 Subject: [PATCH 08/14] Move wasm_import_module_map provider to cg_ssa --- compiler/rustc_codegen_llvm/src/attributes.rs | 31 ------------------- compiler/rustc_codegen_llvm/src/lib.rs | 9 ++---- .../src/back/symbol_export.rs | 29 +++++++++++++++++ 3 files changed, 31 insertions(+), 38 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/attributes.rs b/compiler/rustc_codegen_llvm/src/attributes.rs index 64ebe585dd837..aed61e3764697 100644 --- a/compiler/rustc_codegen_llvm/src/attributes.rs +++ b/compiler/rustc_codegen_llvm/src/attributes.rs @@ -4,12 +4,10 @@ use std::ffi::CString; use cstr::cstr; use rustc_codegen_ssa::traits::*; -use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::small_c_str::SmallCStr; use rustc_hir::def_id::DefId; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::ty::layout::HasTyCtxt; -use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, TyCtxt}; use rustc_session::config::{OptLevel, SanitizerSet}; use rustc_session::Session; @@ -339,35 +337,6 @@ pub fn from_fn_attrs(cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value, instance: ty:: } } -pub fn provide_both(providers: &mut Providers) { - providers.wasm_import_module_map = |tcx, cnum| { - // Build up a map from DefId to a `NativeLib` structure, where - // `NativeLib` internally contains information about - // `#[link(wasm_import_module = "...")]` for example. - let native_libs = tcx.native_libraries(cnum); - - let def_id_to_native_lib = native_libs - .iter() - .filter_map(|lib| lib.foreign_module.map(|id| (id, lib))) - .collect::>(); - - let mut ret = FxHashMap::default(); - for (def_id, lib) in tcx.foreign_modules(cnum).iter() { - let module = def_id_to_native_lib.get(&def_id).and_then(|s| s.wasm_import_module); - let module = match module { - Some(s) => s, - None => continue, - }; - ret.extend(lib.foreign_items.iter().map(|id| { - assert_eq!(id.krate, cnum); - (*id, module.to_string()) - })); - } - - ret - }; -} - fn wasm_import_module(tcx: TyCtxt<'_>, id: DefId) -> Option { tcx.wasm_import_module_map(id.krate).get(&id).map(|s| CString::new(&s[..]).unwrap()) } diff --git a/compiler/rustc_codegen_llvm/src/lib.rs b/compiler/rustc_codegen_llvm/src/lib.rs index 4707d17f18e47..6ce11a9dfcf45 100644 --- a/compiler/rustc_codegen_llvm/src/lib.rs +++ b/compiler/rustc_codegen_llvm/src/lib.rs @@ -253,13 +253,8 @@ impl CodegenBackend for LlvmCodegenBackend { Box::new(metadata::LlvmMetadataLoader) } - fn provide(&self, providers: &mut ty::query::Providers) { - attributes::provide_both(providers); - } - - fn provide_extern(&self, providers: &mut ty::query::Providers) { - attributes::provide_both(providers); - } + fn provide(&self, _providers: &mut ty::query::Providers) {} + fn provide_extern(&self, _providers: &mut ty::query::Providers) {} fn codegen_crate<'tcx>( &self, diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index abad8281d3a69..3d7a2d2b1dd8d 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -369,11 +369,13 @@ pub fn provide(providers: &mut Providers) { providers.upstream_monomorphizations = upstream_monomorphizations_provider; providers.is_unreachable_local_definition = is_unreachable_local_definition_provider; providers.upstream_drop_glue_for = upstream_drop_glue_for_provider; + providers.wasm_import_module_map = wasm_import_module_map; } pub fn provide_extern(providers: &mut Providers) { providers.is_reachable_non_generic = is_reachable_non_generic_provider_extern; providers.upstream_monomorphizations_for = upstream_monomorphizations_for_provider; + providers.wasm_import_module_map = wasm_import_module_map; } fn symbol_export_level(tcx: TyCtxt<'_>, sym_def_id: DefId) -> SymbolExportLevel { @@ -441,3 +443,30 @@ pub fn symbol_name_for_instance_in_crate<'tcx>( ExportedSymbol::NoDefId(symbol_name) => symbol_name.to_string(), } } + +fn wasm_import_module_map(tcx: TyCtxt<'_>, cnum: CrateNum) -> FxHashMap { + // Build up a map from DefId to a `NativeLib` structure, where + // `NativeLib` internally contains information about + // `#[link(wasm_import_module = "...")]` for example. + let native_libs = tcx.native_libraries(cnum); + + let def_id_to_native_lib = native_libs + .iter() + .filter_map(|lib| lib.foreign_module.map(|id| (id, lib))) + .collect::>(); + + let mut ret = FxHashMap::default(); + for (def_id, lib) in tcx.foreign_modules(cnum).iter() { + let module = def_id_to_native_lib.get(&def_id).and_then(|s| s.wasm_import_module); + let module = match module { + Some(s) => s, + None => continue, + }; + ret.extend(lib.foreign_items.iter().map(|id| { + assert_eq!(id.krate, cnum); + (*id, module.to_string()) + })); + } + + ret +} From 18d1b3f3ebb8a5c5fb9a58122f6eaab63d09ec4e Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 30 Mar 2021 12:54:42 +0200 Subject: [PATCH 09/14] Fix hotplug codegen backend test --- .../run-make-fulldeps/hotplug_codegen_backend/the_backend.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/run-make-fulldeps/hotplug_codegen_backend/the_backend.rs b/src/test/run-make-fulldeps/hotplug_codegen_backend/the_backend.rs index 0e1bef6f68d53..684e9760cc663 100644 --- a/src/test/run-make-fulldeps/hotplug_codegen_backend/the_backend.rs +++ b/src/test/run-make-fulldeps/hotplug_codegen_backend/the_backend.rs @@ -65,7 +65,7 @@ impl CodegenBackend for TheBackend { metadata_module: None, metadata, windows_subsystem: None, - linker_info: LinkerInfo::new(tcx), + linker_info: LinkerInfo::new(tcx, "fake_target_cpu".to_string()), crate_info: CrateInfo::new(tcx), }) } From 0447f91e10d4f95ef2ff35b253e1964ed7c5f9fc Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 30 Mar 2021 18:17:14 +0200 Subject: [PATCH 10/14] Let load_query_result_cache take a &DefPathTable This allows removing a confusing mem::replace in create_global_ctxt --- .../rustc_incremental/src/persist/load.rs | 6 +++--- compiler/rustc_interface/src/passes.rs | 14 +++++-------- compiler/rustc_middle/src/ty/context.rs | 3 +-- .../src/ty/query/on_disk_cache.rs | 20 +++++++------------ 4 files changed, 16 insertions(+), 27 deletions(-) diff --git a/compiler/rustc_incremental/src/persist/load.rs b/compiler/rustc_incremental/src/persist/load.rs index 2b5649bb0594f..74e6e844bd35e 100644 --- a/compiler/rustc_incremental/src/persist/load.rs +++ b/compiler/rustc_incremental/src/persist/load.rs @@ -1,7 +1,7 @@ //! Code to save/load the dep-graph from files. use rustc_data_structures::fx::FxHashMap; -use rustc_hir::definitions::Definitions; +use rustc_hir::definitions::DefPathTable; use rustc_middle::dep_graph::{PreviousDepGraph, SerializedDepGraph, WorkProduct, WorkProductId}; use rustc_middle::ty::query::OnDiskCache; use rustc_serialize::opaque::Decoder; @@ -198,7 +198,7 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture { /// creating an empty cache if it could not be loaded. pub fn load_query_result_cache<'a>( sess: &'a Session, - definitions: &Definitions, + def_path_table: &DefPathTable, ) -> Option> { if sess.opts.incremental.is_none() { return None; @@ -212,7 +212,7 @@ pub fn load_query_result_cache<'a>( sess.is_nightly_build(), ) { LoadResult::Ok { data: (bytes, start_pos) } => { - Some(OnDiskCache::new(sess, bytes, start_pos, definitions)) + Some(OnDiskCache::new(sess, bytes, start_pos, def_path_table)) } _ => Some(OnDiskCache::new_empty(sess.source_map())), } diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 94be7a03a932b..94864256be2b5 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -13,7 +13,6 @@ use rustc_data_structures::{box_region_allow_access, declare_box_region_type, pa use rustc_errors::{ErrorReported, PResult}; use rustc_expand::base::ExtCtxt; use rustc_hir::def_id::{CrateNum, LOCAL_CRATE}; -use rustc_hir::definitions::Definitions; use rustc_hir::Crate; use rustc_index::vec::IndexVec; use rustc_lint::LintStore; @@ -51,7 +50,7 @@ use std::io::{self, BufWriter, Write}; use std::lazy::SyncLazy; use std::path::PathBuf; use std::rc::Rc; -use std::{env, fs, iter, mem}; +use std::{env, fs, iter}; pub fn parse<'a>(sess: &'a Session, input: &Input) -> PResult<'a, ast::Crate> { let krate = sess.time("parse_crate", || match input { @@ -761,7 +760,7 @@ pub fn create_global_ctxt<'tcx>( lint_store: Lrc, krate: &'tcx Crate<'tcx>, dep_graph: DepGraph, - mut resolver_outputs: ResolverOutputs, + resolver_outputs: ResolverOutputs, outputs: OutputFilenames, crate_name: &str, queries: &'tcx OnceCell>, @@ -769,12 +768,10 @@ pub fn create_global_ctxt<'tcx>( arena: &'tcx WorkerLocal>, ) -> QueryContext<'tcx> { let sess = &compiler.session(); - let defs: &'tcx Definitions = arena.alloc(mem::replace( - &mut resolver_outputs.definitions, - Definitions::new(crate_name, sess.local_crate_disambiguator()), - )); - let query_result_on_disk_cache = rustc_incremental::load_query_result_cache(sess, defs); + let def_path_table = resolver_outputs.definitions.def_path_table(); + let query_result_on_disk_cache = + rustc_incremental::load_query_result_cache(sess, def_path_table); let codegen_backend = compiler.codegen_backend(); let mut local_providers = *DEFAULT_QUERY_PROVIDERS; @@ -804,7 +801,6 @@ pub fn create_global_ctxt<'tcx>( arena, resolver_outputs, krate, - defs, dep_graph, query_result_on_disk_cache, queries.as_dyn(), diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 94c1758b25c21..9e90dadfff950 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -1122,7 +1122,6 @@ impl<'tcx> TyCtxt<'tcx> { arena: &'tcx WorkerLocal>, resolutions: ty::ResolverOutputs, krate: &'tcx hir::Crate<'tcx>, - definitions: &'tcx Definitions, dep_graph: DepGraph, on_disk_cache: Option>, queries: &'tcx dyn query::QueryEngine<'tcx>, @@ -1164,7 +1163,7 @@ impl<'tcx> TyCtxt<'tcx> { glob_map: resolutions.glob_map, extern_prelude: resolutions.extern_prelude, untracked_crate: krate, - definitions, + definitions: arena.alloc(resolutions.definitions), on_disk_cache, queries, query_caches: query::QueryCaches::default(), diff --git a/compiler/rustc_middle/src/ty/query/on_disk_cache.rs b/compiler/rustc_middle/src/ty/query/on_disk_cache.rs index 416199b384000..e78faa7079aa1 100644 --- a/compiler/rustc_middle/src/ty/query/on_disk_cache.rs +++ b/compiler/rustc_middle/src/ty/query/on_disk_cache.rs @@ -10,8 +10,7 @@ use rustc_data_structures::thin_vec::ThinVec; use rustc_data_structures::unhash::UnhashMap; use rustc_errors::Diagnostic; use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, LOCAL_CRATE}; -use rustc_hir::definitions::DefPathHash; -use rustc_hir::definitions::Definitions; +use rustc_hir::definitions::{DefPathHash, DefPathTable}; use rustc_index::vec::{Idx, IndexVec}; use rustc_query_system::dep_graph::DepContext; use rustc_query_system::query::QueryContext; @@ -167,22 +166,13 @@ crate struct RawDefId { pub index: u32, } -fn make_local_def_path_hash_map(definitions: &Definitions) -> UnhashMap { - UnhashMap::from_iter( - definitions - .def_path_table() - .all_def_path_hashes_and_def_ids(LOCAL_CRATE) - .map(|(hash, def_id)| (hash, def_id.as_local().unwrap())), - ) -} - impl<'sess> OnDiskCache<'sess> { /// Creates a new `OnDiskCache` instance from the serialized data in `data`. pub fn new( sess: &'sess Session, data: Vec, start_pos: usize, - definitions: &Definitions, + def_path_table: &DefPathTable, ) -> Self { debug_assert!(sess.opts.incremental.is_some()); @@ -220,7 +210,11 @@ impl<'sess> OnDiskCache<'sess> { hygiene_context: Default::default(), foreign_def_path_hashes: footer.foreign_def_path_hashes, latest_foreign_def_path_hashes: Default::default(), - local_def_path_hash_to_def_id: make_local_def_path_hash_map(definitions), + local_def_path_hash_to_def_id: UnhashMap::from_iter( + def_path_table + .all_def_path_hashes_and_def_ids(LOCAL_CRATE) + .map(|(hash, def_id)| (hash, def_id.as_local().unwrap())), + ), def_path_hash_to_def_id_cache: Default::default(), } } From 4a6cfc6788800d0ba26d2295dfa1eb460e5ab887 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 2 May 2021 17:49:32 +0200 Subject: [PATCH 11/14] Don't arena allocate Definitions --- compiler/rustc_middle/src/ty/context.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 9e90dadfff950..c9510f2deb431 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -967,7 +967,7 @@ pub struct GlobalCtxt<'tcx> { export_map: ExportMap, pub(crate) untracked_crate: &'tcx hir::Crate<'tcx>, - pub(crate) definitions: &'tcx Definitions, + pub(crate) definitions: Definitions, /// This provides access to the incremental compilation on-disk cache for query results. /// Do not access this directly. It is only meant to be used by @@ -1163,7 +1163,7 @@ impl<'tcx> TyCtxt<'tcx> { glob_map: resolutions.glob_map, extern_prelude: resolutions.extern_prelude, untracked_crate: krate, - definitions: arena.alloc(resolutions.definitions), + definitions: resolutions.definitions, on_disk_cache, queries, query_caches: query::QueryCaches::default(), @@ -1319,14 +1319,14 @@ impl<'tcx> TyCtxt<'tcx> { pub fn create_stable_hashing_context(self) -> StableHashingContext<'tcx> { let krate = self.gcx.untracked_crate; - StableHashingContext::new(self.sess, krate, self.definitions, &*self.cstore) + StableHashingContext::new(self.sess, krate, &self.definitions, &*self.cstore) } #[inline(always)] pub fn create_no_span_stable_hashing_context(self) -> StableHashingContext<'tcx> { let krate = self.gcx.untracked_crate; - StableHashingContext::ignore_spans(self.sess, krate, self.definitions, &*self.cstore) + StableHashingContext::ignore_spans(self.sess, krate, &self.definitions, &*self.cstore) } pub fn serialize_query_result_cache(self, encoder: &mut FileEncoder) -> FileEncodeResult { From b25292473a339869dc818768d45ec06ab59e8767 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 2 May 2021 17:57:04 +0200 Subject: [PATCH 12/14] Simplify make_input --- compiler/rustc_driver/src/lib.rs | 43 ++++++++++++++++---------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index 97ba1aad0f328..2b8c69a13079f 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -235,21 +235,15 @@ fn run_compiler( registry: diagnostics_registry(), }; - match make_input(&matches.free) { - Some((input, input_file_path, input_err)) => { - if let Some(err) = input_err { - // Immediately stop compilation if there was an issue reading - // the input (for example if the input stream is not UTF-8). - early_error_no_abort(config.opts.error_format, &err.to_string()); - return Err(ErrorReported); - } - + match make_input(config.opts.error_format, &matches.free) { + Err(ErrorReported) => return Err(ErrorReported), + Ok(Some((input, input_file_path))) => { config.input = input; config.input_path = input_file_path; callbacks.config(&mut config); } - None => match matches.free.len() { + Ok(None) => match matches.free.len() { 0 => { callbacks.config(&mut config); interface::run_compiler(config, |compiler| { @@ -469,19 +463,23 @@ fn make_output(matches: &getopts::Matches) -> (Option, Option) } // Extract input (string or file and optional path) from matches. -fn make_input(free_matches: &[String]) -> Option<(Input, Option, Option)> { +fn make_input( + error_format: ErrorOutputType, + free_matches: &[String], +) -> Result)>, ErrorReported> { if free_matches.len() == 1 { let ifile = &free_matches[0]; if ifile == "-" { let mut src = String::new(); - let err = if io::stdin().read_to_string(&mut src).is_err() { - Some(io::Error::new( - io::ErrorKind::InvalidData, + if io::stdin().read_to_string(&mut src).is_err() { + // Immediately stop compilation if there was an issue reading + // the input (for example if the input stream is not UTF-8). + early_error_no_abort( + error_format, "couldn't read from stdin, as it did not contain valid UTF-8", - )) - } else { - None - }; + ); + return Err(ErrorReported); + } if let Ok(path) = env::var("UNSTABLE_RUSTDOC_TEST_PATH") { let line = env::var("UNSTABLE_RUSTDOC_TEST_LINE").expect( "when UNSTABLE_RUSTDOC_TEST_PATH is set \ @@ -490,14 +488,15 @@ fn make_input(free_matches: &[String]) -> Option<(Input, Option, Option let line = isize::from_str_radix(&line, 10) .expect("UNSTABLE_RUSTDOC_TEST_LINE needs to be an number"); let file_name = FileName::doc_test_source_code(PathBuf::from(path), line); - return Some((Input::Str { name: file_name, input: src }, None, err)); + Ok(Some((Input::Str { name: file_name, input: src }, None))) + } else { + Ok(Some((Input::Str { name: FileName::anon_source_code(&src), input: src }, None))) } - Some((Input::Str { name: FileName::anon_source_code(&src), input: src }, None, err)) } else { - Some((Input::File(PathBuf::from(ifile)), Some(PathBuf::from(ifile)), None)) + Ok(Some((Input::File(PathBuf::from(ifile)), Some(PathBuf::from(ifile))))) } } else { - None + Ok(None) } } From b71cd56e48efce342357617f5206b1cc77ea8902 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 2 May 2021 17:57:30 +0200 Subject: [PATCH 13/14] Move queries.crate_name() --- compiler/rustc_driver/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index 2b8c69a13079f..bdb75fc6928ff 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -388,10 +388,10 @@ fn run_compiler( return early_exit(); } - let crate_name = queries.crate_name()?.peek().clone(); queries.global_ctxt()?.peek_mut().enter(|tcx| { - let result = tcx.analysis(LOCAL_CRATE); + tcx.analysis(LOCAL_CRATE)?; if sess.opts.debugging_opts.save_analysis { + let crate_name = queries.crate_name()?.peek().clone(); sess.time("save_analysis", || { save::process_crate( tcx, @@ -405,7 +405,7 @@ fn run_compiler( ) }); } - result + Ok(()) })?; if callbacks.after_analysis(compiler, queries) == Compilation::Stop { From 163b4801e72a11803a6dcfece2099b11e5a9be76 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Mon, 3 May 2021 13:44:13 +0200 Subject: [PATCH 14/14] Run save_analysis even when analysis returned an error --- compiler/rustc_driver/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index bdb75fc6928ff..bd96d22585585 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -389,7 +389,7 @@ fn run_compiler( } queries.global_ctxt()?.peek_mut().enter(|tcx| { - tcx.analysis(LOCAL_CRATE)?; + let result = tcx.analysis(LOCAL_CRATE); if sess.opts.debugging_opts.save_analysis { let crate_name = queries.crate_name()?.peek().clone(); sess.time("save_analysis", || { @@ -405,7 +405,7 @@ fn run_compiler( ) }); } - Ok(()) + result })?; if callbacks.after_analysis(compiler, queries) == Compilation::Stop {