Rollup merge of #115730 - bjorn3:some_driver_refactors, r=compiler-errors
Some more small driver refactors To improve clarity and simplify some code.
This commit is contained in:
commit
c943ec2fba
5 changed files with 10 additions and 11 deletions
|
@ -162,9 +162,10 @@ pub fn abort_on_err<T>(result: Result<T, ErrorGuaranteed>, sess: &Session) -> T
|
||||||
pub trait Callbacks {
|
pub trait Callbacks {
|
||||||
/// Called before creating the compiler instance
|
/// Called before creating the compiler instance
|
||||||
fn config(&mut self, _config: &mut interface::Config) {}
|
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`)
|
/// continue the compilation afterwards (defaults to `Compilation::Continue`)
|
||||||
fn after_parsing<'tcx>(
|
fn after_crate_root_parsing<'tcx>(
|
||||||
&mut self,
|
&mut self,
|
||||||
_compiler: &interface::Compiler,
|
_compiler: &interface::Compiler,
|
||||||
_queries: &'tcx Queries<'tcx>,
|
_queries: &'tcx Queries<'tcx>,
|
||||||
|
@ -184,7 +185,6 @@ pub trait Callbacks {
|
||||||
/// continue the compilation afterwards (defaults to `Compilation::Continue`)
|
/// continue the compilation afterwards (defaults to `Compilation::Continue`)
|
||||||
fn after_analysis<'tcx>(
|
fn after_analysis<'tcx>(
|
||||||
&mut self,
|
&mut self,
|
||||||
_handler: &EarlyErrorHandler,
|
|
||||||
_compiler: &interface::Compiler,
|
_compiler: &interface::Compiler,
|
||||||
_queries: &'tcx Queries<'tcx>,
|
_queries: &'tcx Queries<'tcx>,
|
||||||
) -> Compilation {
|
) -> Compilation {
|
||||||
|
@ -407,7 +407,7 @@ fn run_compiler(
|
||||||
return early_exit();
|
return early_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
if callbacks.after_parsing(compiler, queries) == Compilation::Stop {
|
if callbacks.after_crate_root_parsing(compiler, queries) == Compilation::Stop {
|
||||||
return early_exit();
|
return early_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -445,7 +445,7 @@ fn run_compiler(
|
||||||
|
|
||||||
queries.global_ctxt()?.enter(|tcx| tcx.analysis(()))?;
|
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();
|
return early_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -114,6 +114,7 @@ impl<'tcx> Queries<'tcx> {
|
||||||
.compute(|| passes::parse(self.session()).map_err(|mut parse_error| parse_error.emit()))
|
.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)>> {
|
pub fn pre_configure(&self) -> Result<QueryResult<'_, (ast::Crate, ast::AttrVec)>> {
|
||||||
self.pre_configure.compute(|| {
|
self.pre_configure.compute(|| {
|
||||||
let mut krate = self.parse()?.steal();
|
let mut krate = self.parse()?.steal();
|
||||||
|
@ -171,6 +172,7 @@ impl<'tcx> Queries<'tcx> {
|
||||||
pub fn global_ctxt(&'tcx self) -> Result<QueryResult<'_, &'tcx GlobalCtxt<'tcx>>> {
|
pub fn global_ctxt(&'tcx self) -> Result<QueryResult<'_, &'tcx GlobalCtxt<'tcx>>> {
|
||||||
self.gcx.compute(|| {
|
self.gcx.compute(|| {
|
||||||
let sess = self.session();
|
let sess = self.session();
|
||||||
|
#[allow(deprecated)]
|
||||||
let (krate, pre_configured_attrs) = self.pre_configure()?.steal();
|
let (krate, pre_configured_attrs) = self.pre_configure()?.steal();
|
||||||
|
|
||||||
// parse `#[crate_name]` even if `--crate-name` was passed, to make sure it matches.
|
// parse `#[crate_name]` even if `--crate-name` was passed, to make sure it matches.
|
||||||
|
|
|
@ -16,7 +16,6 @@ use rustc_driver::{Callbacks, Compilation, RunCompiler};
|
||||||
use rustc_interface::{interface, Queries};
|
use rustc_interface::{interface, Queries};
|
||||||
use rustc_middle::mir::interpret::AllocId;
|
use rustc_middle::mir::interpret::AllocId;
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
use rustc_session::EarlyErrorHandler;
|
|
||||||
pub use rustc_span::def_id::{CrateNum, DefId};
|
pub use rustc_span::def_id::{CrateNum, DefId};
|
||||||
|
|
||||||
fn with_tables<R>(mut f: impl FnMut(&mut Tables<'_>) -> R) -> R {
|
fn with_tables<R>(mut f: impl FnMut(&mut Tables<'_>) -> R) -> R {
|
||||||
|
@ -233,7 +232,6 @@ where
|
||||||
/// continue the compilation afterwards (defaults to `Compilation::Continue`)
|
/// continue the compilation afterwards (defaults to `Compilation::Continue`)
|
||||||
fn after_analysis<'tcx>(
|
fn after_analysis<'tcx>(
|
||||||
&mut self,
|
&mut self,
|
||||||
_handler: &EarlyErrorHandler,
|
|
||||||
_compiler: &interface::Compiler,
|
_compiler: &interface::Compiler,
|
||||||
queries: &'tcx Queries<'tcx>,
|
queries: &'tcx Queries<'tcx>,
|
||||||
) -> Compilation {
|
) -> Compilation {
|
||||||
|
|
|
@ -59,7 +59,6 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
|
||||||
|
|
||||||
fn after_analysis<'tcx>(
|
fn after_analysis<'tcx>(
|
||||||
&mut self,
|
&mut self,
|
||||||
handler: &EarlyErrorHandler,
|
|
||||||
_: &rustc_interface::interface::Compiler,
|
_: &rustc_interface::interface::Compiler,
|
||||||
queries: &'tcx rustc_interface::Queries<'tcx>,
|
queries: &'tcx rustc_interface::Queries<'tcx>,
|
||||||
) -> Compilation {
|
) -> Compilation {
|
||||||
|
@ -68,7 +67,8 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
|
||||||
tcx.sess.fatal("miri cannot be run on programs that fail compilation");
|
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) {
|
if !tcx.crate_types().contains(&CrateType::Executable) {
|
||||||
tcx.sess.fatal("miri only makes sense on bin crates");
|
tcx.sess.fatal("miri only makes sense on bin crates");
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ use rustc_interface::{Config, Queries};
|
||||||
use rustc_middle::query::queries::mir_borrowck::ProvidedValue;
|
use rustc_middle::query::queries::mir_borrowck::ProvidedValue;
|
||||||
use rustc_middle::query::{ExternProviders, Providers};
|
use rustc_middle::query::{ExternProviders, Providers};
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
use rustc_session::{Session, EarlyErrorHandler};
|
use rustc_session::Session;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::thread_local;
|
use std::thread_local;
|
||||||
|
@ -58,7 +58,6 @@ impl rustc_driver::Callbacks for CompilerCalls {
|
||||||
// the result.
|
// the result.
|
||||||
fn after_analysis<'tcx>(
|
fn after_analysis<'tcx>(
|
||||||
&mut self,
|
&mut self,
|
||||||
_handler: &EarlyErrorHandler,
|
|
||||||
compiler: &Compiler,
|
compiler: &Compiler,
|
||||||
queries: &'tcx Queries<'tcx>,
|
queries: &'tcx Queries<'tcx>,
|
||||||
) -> Compilation {
|
) -> Compilation {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue