rustc_queries simplifications#152958
Merged
rust-bors[bot] merged 3 commits intorust-lang:mainfrom Feb 22, 2026
Merged
Conversation
Due to a bug, you can currently use `key` within the `desc` block and it'll just work regardless of what actual key name you specified. A subsequent commit will fix this, so let's correct the affected queries first.
Due to a bug they aren't actually necessary! (A few queries already take advantage of this, probably unintentionally.) And the next commit will remove support for explicit `tcx` bindings in favour of implicit.
Contributor
Author
|
If you want to understand the two bugs in the The A simple fix is to remove the |
Contributor
Author
This comment has been minimized.
This comment has been minimized.
As currently written, these have big problems. - `desc` and `cache_on_disk_if` modifiers use different syntaxes to introduce `tcx`. - `desc` is mis-implemented such that the explicit binding isn't even necessary and the key name can be botched, as the previous two commits showed. (It's the `let (#tcx, #key) = (tcx, key);` line that messes things up.) It's simpler and less error-prone to simply not require explicit `tcx` bindings, and instead just make it implicitly available to these code snippets.
b39375a to
ecb778f
Compare
oli-obk
approved these changes
Feb 22, 2026
Contributor
Contributor
Contributor
Heh I noticed this before but didn't investigate |
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Feb 22, 2026
…=oli-obk
`rustc_queries` simplifications
Queries have two ways of specifying code snippets, in `desc` and `cache_on_disk_if` blocks. An example:
```rust
query check_liveness(key: LocalDefId) -> &'tcx rustc_index::bit_set::DenseBitSet<abi::FieldIdx> {
arena_cache
desc { |tcx| "checking liveness of variables in `{}`", tcx.def_path_str(key.to_def_id()) }
cache_on_disk_if(tcx) { tcx.is_typeck_child(key.to_def_id()) }
}
```
If you need to use `tcx` in the snippet, you can use an explicit binding. But there are multiple problems with this.
- The syntax used is different in the two snippets: `|tcx|` within the block vs. `(tcx)` outside the block. (!!)
- Bug 1: In `desc` snippets you can leave out the `|tcx|` and still use `tcx`. Several existing queries do this.
- Bug 2: In `desc` snippets you can always use `key` in the snippet to refer to the key, even if that's not the identifier used in the query head.
- Finally, you can bind `tcx` and not use it, without a warning. Several existing queries do this.
I think explicit `tcx` binding is silly. Many queries need `tcx` and this macro is already super-magical, so just making `tcx` implicitly available seems fine, rather than making the query writer jump through a little syntactic hoop. This makes both the query definitions and the proc macro simpler.
r? @petrochenkov
rust-bors bot
pushed a commit
that referenced
this pull request
Feb 22, 2026
…uwer Rollup of 5 pull requests Successful merges: - #149366 (GVN: consider constants of primitive types as deterministic) - #152779 (Clarify aspects of query macros) - #152958 (`rustc_queries` simplifications) - #149783 (stabilize `cfg_select!`) - #152708 (Build: Add `stdenv.cc.cc.lib` to Nix dependencies)
rust-bors bot
pushed a commit
that referenced
this pull request
Feb 22, 2026
…uwer Rollup of 5 pull requests Successful merges: - #149366 (GVN: consider constants of primitive types as deterministic) - #152779 (Clarify aspects of query macros) - #152958 (`rustc_queries` simplifications) - #149783 (stabilize `cfg_select!`) - #152708 (Build: Add `stdenv.cc.cc.lib` to Nix dependencies)
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Feb 22, 2026
…=oli-obk
`rustc_queries` simplifications
Queries have two ways of specifying code snippets, in `desc` and `cache_on_disk_if` blocks. An example:
```rust
query check_liveness(key: LocalDefId) -> &'tcx rustc_index::bit_set::DenseBitSet<abi::FieldIdx> {
arena_cache
desc { |tcx| "checking liveness of variables in `{}`", tcx.def_path_str(key.to_def_id()) }
cache_on_disk_if(tcx) { tcx.is_typeck_child(key.to_def_id()) }
}
```
If you need to use `tcx` in the snippet, you can use an explicit binding. But there are multiple problems with this.
- The syntax used is different in the two snippets: `|tcx|` within the block vs. `(tcx)` outside the block. (!!)
- Bug 1: In `desc` snippets you can leave out the `|tcx|` and still use `tcx`. Several existing queries do this.
- Bug 2: In `desc` snippets you can always use `key` in the snippet to refer to the key, even if that's not the identifier used in the query head.
- Finally, you can bind `tcx` and not use it, without a warning. Several existing queries do this.
I think explicit `tcx` binding is silly. Many queries need `tcx` and this macro is already super-magical, so just making `tcx` implicitly available seems fine, rather than making the query writer jump through a little syntactic hoop. This makes both the query definitions and the proc macro simpler.
r? @petrochenkov
rust-bors bot
pushed a commit
that referenced
this pull request
Feb 22, 2026
…uwer Rollup of 8 pull requests Successful merges: - #149366 (GVN: consider constants of primitive types as deterministic) - #152779 (Clarify aspects of query macros) - #152958 (`rustc_queries` simplifications) - #152385 (Feature gate for defaulted associated type_consts with associated_type_defaults ) - #152708 (Build: Add `stdenv.cc.cc.lib` to Nix dependencies) - #152921 (Add build.rustdoc option to bootstrap config) - #152926 (Fix ICE when an associated type is wrongly marked as `final`) - #152927 (Index expressions rendered the index: subexpression as the id, instea…)
rust-bors bot
pushed a commit
that referenced
this pull request
Feb 22, 2026
…uwer Rollup of 7 pull requests Successful merges: - #152779 (Clarify aspects of query macros) - #152958 (`rustc_queries` simplifications) - #152385 (Feature gate for defaulted associated type_consts with associated_type_defaults ) - #152708 (Build: Add `stdenv.cc.cc.lib` to Nix dependencies) - #152921 (Add build.rustdoc option to bootstrap config) - #152926 (Fix ICE when an associated type is wrongly marked as `final`) - #152927 (Index expressions rendered the index: subexpression as the id, instea…)
rust-timer
added a commit
that referenced
this pull request
Feb 22, 2026
Rollup merge of #152958 - nnethercote:rustc_queries-fixes, r=oli-obk `rustc_queries` simplifications Queries have two ways of specifying code snippets, in `desc` and `cache_on_disk_if` blocks. An example: ```rust query check_liveness(key: LocalDefId) -> &'tcx rustc_index::bit_set::DenseBitSet<abi::FieldIdx> { arena_cache desc { |tcx| "checking liveness of variables in `{}`", tcx.def_path_str(key.to_def_id()) } cache_on_disk_if(tcx) { tcx.is_typeck_child(key.to_def_id()) } } ``` If you need to use `tcx` in the snippet, you can use an explicit binding. But there are multiple problems with this. - The syntax used is different in the two snippets: `|tcx|` within the block vs. `(tcx)` outside the block. (!!) - Bug 1: In `desc` snippets you can leave out the `|tcx|` and still use `tcx`. Several existing queries do this. - Bug 2: In `desc` snippets you can always use `key` in the snippet to refer to the key, even if that's not the identifier used in the query head. - Finally, you can bind `tcx` and not use it, without a warning. Several existing queries do this. I think explicit `tcx` binding is silly. Many queries need `tcx` and this macro is already super-magical, so just making `tcx` implicitly available seems fine, rather than making the query writer jump through a little syntactic hoop. This makes both the query definitions and the proc macro simpler. r? @petrochenkov
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Queries have two ways of specifying code snippets, in
descandcache_on_disk_ifblocks. An example:If you need to use
tcxin the snippet, you can use an explicit binding. But there are multiple problems with this.|tcx|within the block vs.(tcx)outside the block. (!!)descsnippets you can leave out the|tcx|and still usetcx. Several existing queries do this.descsnippets you can always usekeyin the snippet to refer to the key, even if that's not the identifier used in the query head.tcxand not use it, without a warning. Several existing queries do this.I think explicit
tcxbinding is silly. Many queries needtcxand this macro is already super-magical, so just makingtcximplicitly available seems fine, rather than making the query writer jump through a little syntactic hoop. This makes both the query definitions and the proc macro simpler.r? @petrochenkov