Rollup merge of #132410 - bjorn3:yet_another_driver_refactor_round, r=cjgillot
Some more refactorings towards removing driver queries Follow up to https://github.com/rust-lang/rust/pull/127184 ## Custom driver breaking change The `after_analysis` callback is changed to accept `TyCtxt` instead of `Queries`. The only safe query in `Queries` to call at this point is `global_ctxt()` which allows you to enter the `TyCtxt` either way. To fix your custom driver, replace the `queries: &'tcx Queries<'tcx>` argument with `tcx: TyCtxt<'tcx>` and remove your `queries.global_ctxt().unwrap().enter(|tcx| { ... })` call and only keep the contents of the closure. ## Custom driver deprecation The `after_crate_root_parsing` callback is now deprecated. Several custom drivers are incorrectly calling `queries.global_ctxt()` from inside of it, which causes some driver code to be skipped. As such I would like to either remove it in the future or if custom drivers still need it, change it to accept an `&rustc_ast::Crate` instead.
This commit is contained in:
commit
af1ca153d4
33 changed files with 223 additions and 191 deletions
|
@ -313,6 +313,7 @@ macro_rules! optional {
|
|||
macro_rules! run_driver {
|
||||
($args:expr, $callback:expr $(, $with_tcx:ident)?) => {{
|
||||
use rustc_driver::{Callbacks, Compilation, RunCompiler};
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_interface::{interface, Queries};
|
||||
use stable_mir::CompilerError;
|
||||
use std::ops::ControlFlow;
|
||||
|
@ -373,23 +374,21 @@ macro_rules! run_driver {
|
|||
fn after_analysis<'tcx>(
|
||||
&mut self,
|
||||
_compiler: &interface::Compiler,
|
||||
queries: &'tcx Queries<'tcx>,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
) -> Compilation {
|
||||
queries.global_ctxt().unwrap().enter(|tcx| {
|
||||
if let Some(callback) = self.callback.take() {
|
||||
rustc_internal::run(tcx, || {
|
||||
self.result = Some(callback($(optional!($with_tcx tcx))?));
|
||||
})
|
||||
.unwrap();
|
||||
if self.result.as_ref().is_some_and(|val| val.is_continue()) {
|
||||
Compilation::Continue
|
||||
} else {
|
||||
Compilation::Stop
|
||||
}
|
||||
} else {
|
||||
if let Some(callback) = self.callback.take() {
|
||||
rustc_internal::run(tcx, || {
|
||||
self.result = Some(callback($(optional!($with_tcx tcx))?));
|
||||
})
|
||||
.unwrap();
|
||||
if self.result.as_ref().is_some_and(|val| val.is_continue()) {
|
||||
Compilation::Continue
|
||||
} else {
|
||||
Compilation::Stop
|
||||
}
|
||||
})
|
||||
} else {
|
||||
Compilation::Continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue