Skip to content

Commit

Permalink
Unrolled build for rust-lang#115730
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#115730 - bjorn3:some_driver_refactors, r=compiler-errors

Some more small driver refactors

To improve clarity and simplify some code.
  • Loading branch information
rust-timer committed Sep 11, 2023
2 parents e2b3676 + 2eca717 commit 9cecb98
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
10 changes: 5 additions & 5 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ pub fn abort_on_err<T>(result: Result<T, ErrorGuaranteed>, 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>,
Expand All @@ -184,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 {
Expand Down Expand Up @@ -407,7 +407,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();
}

Expand Down Expand Up @@ -445,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();
}

Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_interface/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,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<QueryResult<'_, (ast::Crate, ast::AttrVec)>> {
self.pre_configure.compute(|| {
let mut krate = self.parse()?.steal();
Expand Down Expand Up @@ -171,6 +172,7 @@ impl<'tcx> Queries<'tcx> {
pub fn global_ctxt(&'tcx self) -> Result<QueryResult<'_, &'tcx GlobalCtxt<'tcx>>> {
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.
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_smir/src/rustc_internal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<R>(mut f: impl FnMut(&mut Tables<'_>) -> R) -> R {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/tools/miri/src/bin/miri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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");
}
Expand Down
3 changes: 1 addition & 2 deletions tests/run-make-fulldeps/obtain-borrowck/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 9cecb98

Please sign in to comment.