-
Notifications
You must be signed in to change notification settings - Fork 12.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle GlobalCtxt directly from librustc_interface query system #66791
Changes from 13 commits
266ede1
5098ba6
27513a2
becfe5c
18bb912
ea1b803
7d01b6c
8ffc944
9d5f721
68b1ac9
144d1c2
58a9c73
b99513b
7b71e9a
7e72b36
79e2324
e5ed101
77a4c85
e321ba9
1e12f39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ use rustc_codegen_ssa::back::link::emit_metadata; | |
use rustc_codegen_utils::codegen_backend::CodegenBackend; | ||
use rustc_codegen_utils::link::filename_for_metadata; | ||
use rustc_data_structures::{box_region_allow_access, declare_box_region_type, parallel}; | ||
use rustc_data_structures::sync::{Lrc, ParallelIterator, par_iter}; | ||
use rustc_data_structures::sync::{Lrc, Once, ParallelIterator, par_iter}; | ||
use rustc_errors::PResult; | ||
use rustc_incremental; | ||
use rustc_metadata::cstore; | ||
|
@@ -740,44 +740,41 @@ pub fn default_provide_extern(providers: &mut ty::query::Providers<'_>) { | |
rustc_codegen_ssa::provide_extern(providers); | ||
} | ||
|
||
declare_box_region_type!( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this macro now be removed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it's still used for the resolver. |
||
pub BoxedGlobalCtxt, | ||
for('tcx), | ||
(&'tcx GlobalCtxt<'tcx>) -> ((), ()) | ||
); | ||
pub struct BoxedGlobalCtxt<'tcx>(&'tcx GlobalCtxt<'tcx>); | ||
Zoxc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
impl BoxedGlobalCtxt { | ||
impl<'gcx> BoxedGlobalCtxt<'gcx> { | ||
Zoxc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pub fn enter<F, R>(&mut self, f: F) -> R | ||
where | ||
F: for<'tcx> FnOnce(TyCtxt<'tcx>) -> R, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this could just be |
||
{ | ||
self.access(|gcx| ty::tls::enter_global(gcx, |tcx| f(tcx))) | ||
ty::tls::enter_global(self.0, |tcx| f(tcx)) | ||
} | ||
|
||
pub fn print_stats(&self) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd just remove this function and let its caller call |
||
self.0.queries.print_stats() | ||
} | ||
} | ||
|
||
pub fn create_global_ctxt( | ||
compiler: &Compiler, | ||
pub fn create_global_ctxt<'gcx>( | ||
Zoxc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
compiler: &'gcx Compiler, | ||
lint_store: Lrc<lint::LintStore>, | ||
mut hir_forest: hir::map::Forest, | ||
hir_forest: &'gcx hir::map::Forest, | ||
mut resolver_outputs: ResolverOutputs, | ||
outputs: OutputFilenames, | ||
crate_name: &str, | ||
) -> BoxedGlobalCtxt { | ||
let sess = compiler.session().clone(); | ||
global_ctxt: &'gcx Once<GlobalCtxt<'gcx>>, | ||
arenas: &'gcx Once<AllArenas>, | ||
) -> BoxedGlobalCtxt<'gcx> { | ||
let sess = &compiler.session(); | ||
let codegen_backend = compiler.codegen_backend().clone(); | ||
let crate_name = crate_name.to_string(); | ||
let defs = mem::take(&mut resolver_outputs.definitions); | ||
let override_queries = compiler.override_queries; | ||
|
||
let ((), result) = BoxedGlobalCtxt::new(static move || { | ||
let sess = &*sess; | ||
|
||
let global_ctxt: Option<GlobalCtxt<'_>>; | ||
let arenas = AllArenas::new(); | ||
let arenas = arenas.init_locking(|| AllArenas::new()); | ||
Zoxc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Construct the HIR map. | ||
let hir_map = time(sess, "indexing HIR", || { | ||
hir::map::map_crate(sess, &*resolver_outputs.cstore, &mut hir_forest, &defs) | ||
hir::map::map_crate(sess, &*resolver_outputs.cstore, &hir_forest, defs) | ||
}); | ||
|
||
let query_result_on_disk_cache = time(sess, "load query result cache", || { | ||
|
@@ -796,7 +793,7 @@ pub fn create_global_ctxt( | |
callback(sess, &mut local_providers, &mut extern_providers); | ||
} | ||
|
||
let gcx = TyCtxt::create_global_ctxt( | ||
let gcx = global_ctxt.init_locking(move || TyCtxt::create_global_ctxt( | ||
sess, | ||
lint_store, | ||
local_providers, | ||
|
@@ -807,26 +804,15 @@ pub fn create_global_ctxt( | |
query_result_on_disk_cache, | ||
&crate_name, | ||
&outputs | ||
); | ||
)); | ||
|
||
global_ctxt = Some(gcx); | ||
let gcx = global_ctxt.as_ref().unwrap(); | ||
|
||
ty::tls::enter_global(gcx, |tcx| { | ||
ty::tls::enter_global(&gcx, |tcx| { | ||
// Do some initialization of the DepGraph that can only be done with the | ||
// tcx available. | ||
time(tcx.sess, "dep graph tcx init", || rustc_incremental::dep_graph_tcx_init(tcx)); | ||
}); | ||
|
||
yield BoxedGlobalCtxt::initial_yield(()); | ||
box_region_allow_access!(for('tcx), (&'tcx GlobalCtxt<'tcx>), (gcx)); | ||
|
||
if sess.opts.debugging_opts.query_stats { | ||
gcx.queries.print_stats(); | ||
} | ||
}); | ||
|
||
result | ||
BoxedGlobalCtxt(gcx) | ||
} | ||
|
||
/// Runs the resolution, type-checking, region checking and other | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it maybe a problem that now,
after_analysis
is called insidecompiler.enter
, so that if the callback needs access to the ctx and callscompiler.enter
itself, we end up with nestedcompiler.enter
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is indeed the problem. The
Callbacks
are supposed to take&'tcx Queries<'tcx>
now to avoid that. So that has to be fixed before Miri can work again. Do you or @cjgillot want to fix that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should probably be an assertion to avoid calling
enter
twice too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prepared a PR at #66896 (and tested that this indeed is sufficient to fix Miri).
I didn't do that as I wouldn't know how.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay. Do you still need me to do something?