From 0ed291453da7b7233f1b6f6535a2d7e80610d568 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 10 Sep 2023 09:31:10 +0000 Subject: [PATCH 1/3] Rename after_parsing callback to after_crate_root_parsing To avoid confusion if it is called after all parsing is done or not. --- compiler/rustc_driver_impl/src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index e56347ab38e9b..0fe5a96619990 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -162,9 +162,10 @@ pub fn abort_on_err(result: Result, sess: &Session) -> T pub trait Callbacks { /// Called before creating the compiler instance fn config(&mut self, _config: &mut interface::Config) {} - /// Called after parsing. Return value instructs the compiler whether to + /// Called after parsing the crate root. Submodules are not yet parsed when + /// this callback is called. Return value instructs the compiler whether to /// continue the compilation afterwards (defaults to `Compilation::Continue`) - fn after_parsing<'tcx>( + fn after_crate_root_parsing<'tcx>( &mut self, _compiler: &interface::Compiler, _queries: &'tcx Queries<'tcx>, @@ -407,7 +408,7 @@ fn run_compiler( return early_exit(); } - if callbacks.after_parsing(compiler, queries) == Compilation::Stop { + if callbacks.after_crate_root_parsing(compiler, queries) == Compilation::Stop { return early_exit(); } From 90e9053189da16be1f1ee00836e692edb9bf8154 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 10 Sep 2023 09:32:38 +0000 Subject: [PATCH 2/3] Deprecate the pre_configure query Only deprecating it rather than making it private to just in case someone has a use case for it. --- compiler/rustc_interface/src/queries.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler/rustc_interface/src/queries.rs b/compiler/rustc_interface/src/queries.rs index e0d9998d919b1..f3a026f71a2bb 100644 --- a/compiler/rustc_interface/src/queries.rs +++ b/compiler/rustc_interface/src/queries.rs @@ -116,6 +116,7 @@ impl<'tcx> Queries<'tcx> { .compute(|| passes::parse(self.session()).map_err(|mut parse_error| parse_error.emit())) } + #[deprecated = "pre_configure may be made private in the future. If you need it please open an issue with your use case."] pub fn pre_configure(&self) -> Result> { self.pre_configure.compute(|| { let mut krate = self.parse()?.steal(); @@ -173,6 +174,7 @@ impl<'tcx> Queries<'tcx> { pub fn global_ctxt(&'tcx self) -> Result>> { self.gcx.compute(|| { let sess = self.session(); + #[allow(deprecated)] let (krate, pre_configured_attrs) = self.pre_configure()?.steal(); // parse `#[crate_name]` even if `--crate-name` was passed, to make sure it matches. From 2eca717a240a37e4e996d727b6506d2f2e990b74 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 10 Sep 2023 09:44:03 +0000 Subject: [PATCH 3/3] Remove EarlyErrorHandler argument from after_analysis callback It is only used by miri which can create a new one using the Session. --- compiler/rustc_driver_impl/src/lib.rs | 3 +-- compiler/rustc_smir/src/rustc_internal/mod.rs | 2 -- src/tools/miri/src/bin/miri.rs | 4 ++-- tests/run-make-fulldeps/obtain-borrowck/driver.rs | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index 0fe5a96619990..f38adefa7c0b8 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -185,7 +185,6 @@ pub trait Callbacks { /// continue the compilation afterwards (defaults to `Compilation::Continue`) fn after_analysis<'tcx>( &mut self, - _handler: &EarlyErrorHandler, _compiler: &interface::Compiler, _queries: &'tcx Queries<'tcx>, ) -> Compilation { @@ -446,7 +445,7 @@ fn run_compiler( queries.global_ctxt()?.enter(|tcx| tcx.analysis(()))?; - if callbacks.after_analysis(&handler, compiler, queries) == Compilation::Stop { + if callbacks.after_analysis(compiler, queries) == Compilation::Stop { return early_exit(); } diff --git a/compiler/rustc_smir/src/rustc_internal/mod.rs b/compiler/rustc_smir/src/rustc_internal/mod.rs index 73b8e060dd830..4203990ab0560 100644 --- a/compiler/rustc_smir/src/rustc_internal/mod.rs +++ b/compiler/rustc_smir/src/rustc_internal/mod.rs @@ -16,7 +16,6 @@ use rustc_driver::{Callbacks, Compilation, RunCompiler}; use rustc_interface::{interface, Queries}; use rustc_middle::mir::interpret::AllocId; use rustc_middle::ty::TyCtxt; -use rustc_session::EarlyErrorHandler; pub use rustc_span::def_id::{CrateNum, DefId}; fn with_tables(mut f: impl FnMut(&mut Tables<'_>) -> R) -> R { @@ -233,7 +232,6 @@ where /// continue the compilation afterwards (defaults to `Compilation::Continue`) fn after_analysis<'tcx>( &mut self, - _handler: &EarlyErrorHandler, _compiler: &interface::Compiler, queries: &'tcx Queries<'tcx>, ) -> Compilation { diff --git a/src/tools/miri/src/bin/miri.rs b/src/tools/miri/src/bin/miri.rs index 97718f1f4a9f7..1e9219d4bb23a 100644 --- a/src/tools/miri/src/bin/miri.rs +++ b/src/tools/miri/src/bin/miri.rs @@ -59,7 +59,6 @@ impl rustc_driver::Callbacks for MiriCompilerCalls { fn after_analysis<'tcx>( &mut self, - handler: &EarlyErrorHandler, _: &rustc_interface::interface::Compiler, queries: &'tcx rustc_interface::Queries<'tcx>, ) -> Compilation { @@ -68,7 +67,8 @@ impl rustc_driver::Callbacks for MiriCompilerCalls { tcx.sess.fatal("miri cannot be run on programs that fail compilation"); } - init_late_loggers(handler, tcx); + let handler = EarlyErrorHandler::new(tcx.sess.opts.error_format); + init_late_loggers(&handler, tcx); if !tcx.crate_types().contains(&CrateType::Executable) { tcx.sess.fatal("miri only makes sense on bin crates"); } diff --git a/tests/run-make-fulldeps/obtain-borrowck/driver.rs b/tests/run-make-fulldeps/obtain-borrowck/driver.rs index 04c551cf4bb6c..b59a65a713f95 100644 --- a/tests/run-make-fulldeps/obtain-borrowck/driver.rs +++ b/tests/run-make-fulldeps/obtain-borrowck/driver.rs @@ -27,7 +27,7 @@ use rustc_interface::{Config, Queries}; use rustc_middle::query::queries::mir_borrowck::ProvidedValue; use rustc_middle::query::{ExternProviders, Providers}; use rustc_middle::ty::TyCtxt; -use rustc_session::{Session, EarlyErrorHandler}; +use rustc_session::Session; use std::cell::RefCell; use std::collections::HashMap; use std::thread_local; @@ -58,7 +58,6 @@ impl rustc_driver::Callbacks for CompilerCalls { // the result. fn after_analysis<'tcx>( &mut self, - _handler: &EarlyErrorHandler, compiler: &Compiler, queries: &'tcx Queries<'tcx>, ) -> Compilation {