-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Query refactoring #107831
Query refactoring #107831
Conversation
These are in places where a `tcx` is easily obtained.
There is a type `QueryCtxt`, which impls the trait `QueryContext`. Confusingly, there is another type `QueryContext`. The latter is (like `TyCtxt`) just a pointer to a `GlobalContext`. It's not used much, e.g. its `impl` block has a single method. This commit removes `QueryContext`, replacing its use with direct `GlobalCtxt` use.
@bors r+ rollup |
impl<'tcx> GlobalCtxt<'tcx> { | ||
/// Installs `self` in a `TyCtxt` and `ImplicitCtxt` for the duration of | ||
/// `f`. | ||
pub fn enter<'a: 'tcx, F, R>(&'a self, f: F) -> R |
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.
This shouldn't be available outside rustc_interface
as it cannot be accidentally called.
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.
Even before this PR, it's used in several other places: rustdoc, miri, etc. This grep
output gives an idea:
compiler/rustc_driver_impl/src/lib.rs: queries.global_ctxt()?.enter(|tcx| {
compiler/rustc_driver_impl/src/lib.rs: queries.global_ctxt()?.enter(|tcx| tcx.output_filenames(()));
compiler/rustc_driver_impl/src/lib.rs: queries.global_ctxt()?.enter(|tcx| {
compiler/rustc_interface/src/queries.rs: self.global_ctxt()?.enter(|tcx| {
compiler/rustc_interface/src/queries.rs: let (crate_hash, prepare_outputs, dep_graph) = self.global_ctxt()?.enter(|tcx| {
src/librustdoc/doctest.rs: let collector = queries.global_ctxt()?.enter(|tcx| {
src/tools/miri/src/bin/miri.rs: queries.global_ctxt().unwrap().enter(|tcx| {
tests/run-make-fulldeps/obtain-borrowck/driver.rs: queries.global_ctxt().unwrap().enter(|tcx| {
compiler/rustc_interface/src/queries.rs: gcx.enter(|tcx| {
compiler/rustc_interface/src/queries.rs: gcx.enter(rustc_query_impl::alloc_self_profile_query_strings);
compiler/rustc_interface/src/queries.rs: .time("serialize_dep_graph", || gcx.enter(rustc_incremental::save_dep_graph));
src/librustdoc/lib.rs: gcx.enter(|tcx| {
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 meant to say the upstream compiler crates cannot call it. The downstream crates however must call it to initialize the GlobalCtxt
pointer in the TLS state, before getting access to TyCtxt
. The QueryContext
structure ensures they do so.
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#107043 (Support `true` and `false` as boolean flag params) - rust-lang#107831 (Query refactoring) - rust-lang#107841 (Handled snap curl issue inside Rust) - rust-lang#107852 (rustdoc: remove unused fn parameter `tab`) - rust-lang#107861 (Sync release notes for 1.67.1) - rust-lang#107863 (Allow multiple candidates with same response in new solver) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Just some cleanups I found when learning about the query system.
Best reviewed one commit at a time.
r? @oli-obk