Skip to content

Commit 3a62e89

Browse files
committed
Remove the anon query modifier
We still have some anon-task machinery for `DepKind::TraitSelect` tasks, but there are no longer any queries that use the `anon` modifier.
1 parent 0dfce4d commit 3a62e89

9 files changed

Lines changed: 11 additions & 62 deletions

File tree

compiler/rustc_macros/src/query.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ struct CacheOnDiskIf {
140140
/// See `rustc_middle::query::modifiers` for documentation of each query modifier.
141141
struct QueryModifiers {
142142
// tidy-alphabetical-start
143-
anon: Option<Ident>,
144143
arena_cache: Option<Ident>,
145144
cache_on_disk_if: Option<CacheOnDiskIf>,
146145
depth_limit: Option<Ident>,
@@ -159,7 +158,6 @@ fn parse_query_modifiers(input: ParseStream<'_>) -> Result<QueryModifiers> {
159158
let mut desc = None;
160159
let mut no_force = None;
161160
let mut no_hash = None;
162-
let mut anon = None;
163161
let mut eval_always = None;
164162
let mut depth_limit = None;
165163
let mut separate_provide_extern = None;
@@ -195,8 +193,6 @@ fn parse_query_modifiers(input: ParseStream<'_>) -> Result<QueryModifiers> {
195193
try_insert!(no_force = modifier);
196194
} else if modifier == "no_hash" {
197195
try_insert!(no_hash = modifier);
198-
} else if modifier == "anon" {
199-
try_insert!(anon = modifier);
200196
} else if modifier == "eval_always" {
201197
try_insert!(eval_always = modifier);
202198
} else if modifier == "depth_limit" {
@@ -218,7 +214,6 @@ fn parse_query_modifiers(input: ParseStream<'_>) -> Result<QueryModifiers> {
218214
desc,
219215
no_force,
220216
no_hash,
221-
anon,
222217
eval_always,
223218
depth_limit,
224219
separate_provide_extern,
@@ -248,7 +243,6 @@ fn returns_error_guaranteed(ret_ty: &ReturnType) -> bool {
248243
fn make_modifiers_stream(query: &Query) -> proc_macro2::TokenStream {
249244
let QueryModifiers {
250245
// tidy-alphabetical-start
251-
anon,
252246
arena_cache,
253247
cache_on_disk_if,
254248
depth_limit,
@@ -261,7 +255,6 @@ fn make_modifiers_stream(query: &Query) -> proc_macro2::TokenStream {
261255
// tidy-alphabetical-end
262256
} = &query.modifiers;
263257

264-
let anon = anon.is_some();
265258
let arena_cache = arena_cache.is_some();
266259
let cache_on_disk = cache_on_disk_if.is_some();
267260
let depth_limit = depth_limit.is_some();
@@ -280,7 +273,6 @@ fn make_modifiers_stream(query: &Query) -> proc_macro2::TokenStream {
280273
query_name_span =>
281274
// Search for (QMODLIST) to find all occurrences of this query modifier list.
282275
// tidy-alphabetical-start
283-
anon: #anon,
284276
arena_cache: #arena_cache,
285277
cache_on_disk: #cache_on_disk,
286278
depth_limit: #depth_limit,
@@ -396,7 +388,6 @@ fn add_to_analyzer_stream(query: &Query, analyzer_stream: &mut proc_macro2::Toke
396388

397389
doc_link!(
398390
// tidy-alphabetical-start
399-
anon,
400391
arena_cache,
401392
depth_limit,
402393
eval_always,
@@ -487,11 +478,6 @@ pub(super) fn rustc_queries(input: TokenStream) -> TokenStream {
487478
});
488479

489480
if let Some(feedable) = &modifiers.feedable {
490-
assert!(
491-
modifiers.anon.is_none(),
492-
feedable.span(),
493-
"Query {name} cannot be both `feedable` and `anon`."
494-
);
495481
assert!(
496482
modifiers.eval_always.is_none(),
497483
feedable.span(),

compiler/rustc_middle/src/dep_graph/dep_node.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,14 @@ impl DepKind {
9494
pub struct DepNode {
9595
pub kind: DepKind,
9696

97-
/// This is _typically_ a hash of the query key, but sometimes not.
97+
/// If `kind` is a query method, then its "key fingerprint" is always a
98+
/// stable hash of the query key.
9899
///
99-
/// For example, `anon` nodes have a fingerprint that is derived from their
100-
/// dependencies instead of a key.
100+
/// For non-query nodes, the content of this field varies:
101+
/// - Some dep kinds always use a dummy `ZERO` fingerprint.
102+
/// - Some dep kinds use the stable hash of some relevant key-like value.
103+
/// - Some dep kinds use the `with_anon_task` mechanism, and set their key
104+
/// fingerprint to a hash derived from the task's dependencies.
101105
///
102106
/// In some cases the key value can be reconstructed from this fingerprint;
103107
/// see [`KeyFingerprintStyle`].

compiler/rustc_middle/src/dep_graph/graph.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,8 @@ impl DepGraphData {
375375
/// incorrectly marked green.
376376
///
377377
/// FIXME: This could perhaps return a `WithDepNode` to ensure that the
378-
/// user of this function actually performs the read; we'll have to see
379-
/// how to make that work with `anon` in `execute_job_incr`, though.
380-
pub fn with_anon_task_inner<'tcx, OP, R>(
378+
/// user of this function actually performs the read.
379+
fn with_anon_task_inner<'tcx, OP, R>(
381380
&self,
382381
tcx: TyCtxt<'tcx>,
383382
dep_kind: DepKind,

compiler/rustc_middle/src/query/modifiers.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@
77

88
// tidy-alphabetical-start
99
//
10-
/// # `anon` query modifier
11-
///
12-
/// Generate a dep node based not on the query key, but on the query's dependencies.
13-
pub(crate) struct anon;
14-
1510
/// # `arena_cache` query modifier
1611
///
1712
/// Query return values must impl `Copy` and be small, but some queries must return values that

compiler/rustc_middle/src/query/plumbing.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ pub enum EnsureMode {
7777
pub struct QueryVTable<'tcx, C: QueryCache> {
7878
pub name: &'static str,
7979

80-
/// True if this query has the `anon` modifier.
81-
pub anon: bool,
8280
/// True if this query has the `eval_always` modifier.
8381
pub eval_always: bool,
8482
/// True if this query has the `depth_limit` modifier.
@@ -283,7 +281,6 @@ macro_rules! define_callbacks {
283281
fn $name:ident($($K:tt)*) -> $V:ty
284282
{
285283
// Search for (QMODLIST) to find all occurrences of this query modifier list.
286-
anon: $anon:literal,
287284
arena_cache: $arena_cache:literal,
288285
cache_on_disk: $cache_on_disk:literal,
289286
depth_limit: $depth_limit:literal,

compiler/rustc_query_impl/src/dep_kind_vtables.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,26 +96,17 @@ mod non_query {
9696
/// Shared implementation of the [`DepKindVTable`] constructor for queries.
9797
/// Called from macro-generated code for each query.
9898
pub(crate) fn make_dep_kind_vtable_for_query<'tcx, Q>(
99-
is_anon: bool,
10099
is_cache_on_disk: bool,
101100
is_eval_always: bool,
102101
is_no_force: bool,
103102
) -> DepKindVTable<'tcx>
104103
where
105104
Q: GetQueryVTable<'tcx>,
106105
{
107-
let key_fingerprint_style = if is_anon {
108-
KeyFingerprintStyle::Opaque
109-
} else {
110-
<Q::Cache as QueryCache>::Key::key_fingerprint_style()
111-
};
112-
113106
// A query dep-node can only be forced or promoted if it can recover a key
114107
// from its key fingerprint.
108+
let key_fingerprint_style = <Q::Cache as QueryCache>::Key::key_fingerprint_style();
115109
let can_recover = key_fingerprint_style.is_maybe_recoverable();
116-
if is_anon {
117-
assert!(!can_recover);
118-
}
119110

120111
DepKindVTable {
121112
is_eval_always,
@@ -135,7 +126,6 @@ macro_rules! define_dep_kind_vtables {
135126
fn $name:ident($K:ty) -> $V:ty
136127
{
137128
// Search for (QMODLIST) to find all occurrences of this query modifier list.
138-
anon: $anon:literal,
139129
arena_cache: $arena_cache:literal,
140130
cache_on_disk: $cache_on_disk:literal,
141131
depth_limit: $depth_limit:literal,
@@ -168,7 +158,6 @@ macro_rules! define_dep_kind_vtables {
168158
$crate::dep_kind_vtables::make_dep_kind_vtable_for_query::<
169159
$crate::query_impl::$name::VTableGetter,
170160
>(
171-
$anon,
172161
$cache_on_disk,
173162
$eval_always,
174163
$no_force,

compiler/rustc_query_impl/src/execution.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ fn execute_job_incr<'tcx, C: QueryCache>(
424424
let dep_graph_data =
425425
tcx.dep_graph.data().expect("should always be present in incremental mode");
426426

427-
if !query.anon && !query.eval_always {
427+
if !query.eval_always {
428428
// `to_dep_node` is expensive for some `DepKind`s.
429429
let dep_node =
430430
dep_node_opt.get_or_insert_with(|| DepNode::construct(tcx, query.dep_kind, &key));
@@ -451,13 +451,6 @@ fn execute_job_incr<'tcx, C: QueryCache>(
451451
let prof_timer = tcx.prof.query_provider();
452452

453453
let (result, dep_node_index) = start_query(job_id, query.depth_limit, || {
454-
if query.anon {
455-
// Call the query provider inside an anon task.
456-
return dep_graph_data.with_anon_task_inner(tcx, query.dep_kind, || {
457-
(query.invoke_provider_fn)(tcx, key)
458-
});
459-
}
460-
461454
// `to_dep_node` is expensive for some `DepKind`s.
462455
let dep_node =
463456
dep_node_opt.unwrap_or_else(|| DepNode::construct(tcx, query.dep_kind, &key));
@@ -601,9 +594,6 @@ fn check_if_ensure_can_skip_execution<'tcx, C: QueryCache>(
601594
return EnsureCanSkip { skip_execution: false, dep_node: None };
602595
}
603596

604-
// Ensuring an anonymous query makes no sense
605-
assert!(!query.anon);
606-
607597
let dep_node = DepNode::construct(tcx, query.dep_kind, &key);
608598

609599
let serialized_dep_node_index = match tcx.dep_graph.try_mark_green(tcx, &dep_node) {
@@ -703,8 +693,6 @@ pub(crate) fn force_query<'tcx, C: QueryCache>(
703693
return;
704694
}
705695

706-
debug_assert!(!query.anon);
707-
708696
ensure_sufficient_stack(|| {
709697
try_execute_query::<C, true>(query, tcx, DUMMY_SP, key, Some(dep_node))
710698
});

compiler/rustc_query_impl/src/query_impl.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ macro_rules! define_queries {
1616
fn $name:ident($K:ty) -> $V:ty
1717
{
1818
// Search for (QMODLIST) to find all occurrences of this query modifier list.
19-
anon: $anon:literal,
2019
arena_cache: $arena_cache:literal,
2120
cache_on_disk: $cache_on_disk:literal,
2221
depth_limit: $depth_limit:literal,
@@ -133,7 +132,6 @@ macro_rules! define_queries {
133132

134133
QueryVTable {
135134
name: stringify!($name),
136-
anon: $anon,
137135
eval_always: $eval_always,
138136
depth_limit: $depth_limit,
139137
feedable: $feedable,

src/doc/rustc-dev-guide/src/queries/incremental-compilation-in-detail.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -485,13 +485,6 @@ respect to incremental compilation:
485485
For example, it makes no sense to store values from upstream
486486
crates in the cache because they are already available in the upstream crate's metadata.
487487

488-
- `anon` - This attribute makes the system use "anonymous" dep-nodes for the given query.
489-
An anonymous dep-node is not identified by the corresponding query key.
490-
Instead, its ID is computed from the IDs of its dependencies.
491-
This allows the red-green system to do its change detection even if there is no
492-
query key available for a given dep-node -- something which is needed for
493-
handling trait selection because it is not based on queries.
494-
495488
[mod]: ../query.html#adding-a-new-kind-of-query
496489

497490

0 commit comments

Comments
 (0)