Skip to content

Remove QueryCtxt and trait HasDepContext#152704

Open
Zalathar wants to merge 3 commits intorust-lang:mainfrom
Zalathar:query-ctxt
Open

Remove QueryCtxt and trait HasDepContext#152704
Zalathar wants to merge 3 commits intorust-lang:mainfrom
Zalathar:query-ctxt

Conversation

@Zalathar
Copy link
Member


With the QueryContext trait removed, wrapper struct QueryCtxt no longer serves a purpose and can be replaced with TyCtxt everywhere.

After that, the only obstacle to removing trait HasDepContext is DepGraph::with_task, which uses the trait to allow passing both a TyCtxt and a query vtable through the context argument. But we can achieve the same result by passing the vtable through the other argument instead, in a tuple alongside the query key.

r? nnethercote

@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. labels Feb 16, 2026
self.assert_dep_node_not_yet_allocated_in_current_session(tcx.sess, &dep_node, || {
format!(
"forcing query with already existing `DepNode`\n\
- query-key: {task_arg:?}\n\
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't just print the query key now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will print a tuple of (query_name, key), which seems fine.

// Delegate to another function to actually execute the query job.
let (result, dep_node_index) = if INCR {
execute_job_incr(query, qcx, qcx.tcx.dep_graph.data().unwrap(), key, dep_node, id)
execute_job_incr(query, tcx, tcx.dep_graph.data().unwrap(), key, dep_node, id)
Copy link
Contributor

@nnethercote nnethercote Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could now just pass in tcx and get the dep graph data later (in try_load_from_disk_and_cache_in_memory).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That duplicates the unwrap(), so DepGraphData is passed around to indicate incremental is enabled.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have pushed the call to tcx.dep_graph.data().unwrap() down into execute_job_incr, and incorporated that change into the commit that removes QueryCtxt, because it touches the affected lines anyway.

Pushing the call down any further is not obviously better to me, so I stopped there for now.

@nnethercote
Copy link
Contributor

r=me with the nits addressed, and merging should wait for #152703.

@nnethercote nnethercote added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 16, 2026
@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@Zalathar
Copy link
Member Author

@rustbot blocked

@rustbot rustbot added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 17, 2026
This struct was only wrapping `TyCtxt` in order to implement traits that
were removed by RUST-152636.

This commit also slightly simplifies the signature of `execute_job_incr`, by
having it call `tcx.dep_graph.data()` internally.
The need for a `HasDepContext` impl on tuples can be avoided by passing the
query vtable as part of an argument tuple instead.
@rustbot
Copy link
Collaborator

rustbot commented Feb 17, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@Zalathar
Copy link
Member Author

Nits addressed, and #152703 has merged.

@rustbot ready
@bors r=nnethercote

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 17, 2026

📋 This PR cannot be approved because it currently has the following label: S-blocked.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels Feb 17, 2026
@Zalathar
Copy link
Member Author

@bors r=nnethercote

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 17, 2026

📌 Commit 25d5cd2 has been approved by nnethercote

It is now in the queue for this repository.

@rust-bors rust-bors bot 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 17, 2026
jdonszelmann added a commit to jdonszelmann/rust that referenced this pull request Feb 17, 2026
Remove `QueryCtxt` and trait `HasDepContext`

- Follow-up to rust-lang#152636.
- Potentially waiting on rust-lang#152703 to reduce conflicts.
---

With the `QueryContext` trait removed, wrapper struct `QueryCtxt` no longer serves a purpose and can be replaced with `TyCtxt` everywhere.

After that, the only obstacle to removing trait `HasDepContext` is `DepGraph::with_task`, which uses the trait to allow passing both a `TyCtxt` and a query vtable through the context argument. But we can achieve the same result by passing the vtable through the other argument instead, in a tuple alongside the query key.

r? nnethercote
jdonszelmann added a commit to jdonszelmann/rust that referenced this pull request Feb 17, 2026
Remove `QueryCtxt` and trait `HasDepContext`

- Follow-up to rust-lang#152636.
- Potentially waiting on rust-lang#152703 to reduce conflicts.
---

With the `QueryContext` trait removed, wrapper struct `QueryCtxt` no longer serves a purpose and can be replaced with `TyCtxt` everywhere.

After that, the only obstacle to removing trait `HasDepContext` is `DepGraph::with_task`, which uses the trait to allow passing both a `TyCtxt` and a query vtable through the context argument. But we can achieve the same result by passing the vtable through the other argument instead, in a tuple alongside the query key.

r? nnethercote
rust-bors bot pushed a commit that referenced this pull request Feb 17, 2026
Rollup of 6 pull requests

Successful merges:

 - #152609 (Install LLVM DLL in the right place on Windows)
 - #149904 (`-Znext-solver` Remove the forced ambiguity hack from search graph)
 - #152704 (Remove `QueryCtxt` and trait `HasDepContext`)
 - #152746 (remove `#![allow(stable_features)]` from most tests)
 - #152675 (Improve `VaList` stdlib docs)
 - #152748 (Update `sysinfo` version to `0.38.2`)
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants