Skip to content
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

Merged
merged 4 commits into from
Feb 10, 2023
Merged

Query refactoring #107831

merged 4 commits into from
Feb 10, 2023

Conversation

nnethercote
Copy link
Contributor

Just some cleanups I found when learning about the query system.

Best reviewed one commit at a time.

r? @oli-obk

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.
@rustbot rustbot added A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Feb 9, 2023
@oli-obk
Copy link
Contributor

oli-obk commented Feb 9, 2023

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Feb 9, 2023

📌 Commit 243944c has been approved by oli-obk

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 9, 2023
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
Copy link
Contributor

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.

Copy link
Contributor Author

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| {

Copy link
Contributor

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.

bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 10, 2023
…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
@bors bors merged commit 11e1280 into rust-lang:master Feb 10, 2023
@rustbot rustbot added this to the 1.69.0 milestone Feb 10, 2023
@nnethercote nnethercote deleted the query-refactoring branch February 12, 2023 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants