Skip to content

Commit 5027f1c

Browse files
committed
Use a field for has_params.
1 parent d8c87ac commit 5027f1c

File tree

2 files changed

+17
-25
lines changed

2 files changed

+17
-25
lines changed

compiler/rustc_middle/src/dep_graph/dep_node.rs

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ pub use rustc_query_system::dep_graph::{DepContext, DepNodeParams};
7676
/// of the `DepKind`. Overall, this allows to implement `DepContext` using this manual
7777
/// jump table instead of large matches.
7878
pub struct DepKindStruct {
79+
/// Whether the DepNode has parameters (query keys).
80+
pub(super) has_params: bool,
81+
7982
/// Anonymous queries cannot be replayed from one compiler invocation to the next.
8083
/// When their result is needed, it is recomputed. They are useful for fine-grained
8184
/// dependency tracking, and caching within one compiler invocation.
@@ -132,26 +135,31 @@ pub mod dep_kind {
132135
use super::*;
133136

134137
// We use this for most things when incr. comp. is turned off.
135-
pub const Null: DepKindStruct = DepKindStruct { is_anon: false, is_eval_always: false };
138+
pub const Null: DepKindStruct =
139+
DepKindStruct { has_params: false, is_anon: false, is_eval_always: false };
136140

137141
// Represents metadata from an extern crate.
138-
pub const CrateMetadata: DepKindStruct = DepKindStruct { is_anon: false, is_eval_always: true };
142+
pub const CrateMetadata: DepKindStruct =
143+
DepKindStruct { has_params: true, is_anon: false, is_eval_always: true };
139144

140-
pub const TraitSelect: DepKindStruct = DepKindStruct { is_anon: true, is_eval_always: false };
145+
pub const TraitSelect: DepKindStruct =
146+
DepKindStruct { has_params: false, is_anon: true, is_eval_always: false };
141147

142148
pub const CompileCodegenUnit: DepKindStruct =
143-
DepKindStruct { is_anon: false, is_eval_always: false };
149+
DepKindStruct { has_params: true, is_anon: false, is_eval_always: false };
144150

145151
macro_rules! define_query_dep_kinds {
146152
($(
147153
[$($attrs:tt)*]
148154
$variant:ident $(( $tuple_arg_ty:ty $(,)? ))*
149155
,)*) => (
150156
$(pub const $variant: DepKindStruct = {
157+
const has_params: bool = $({ erase!($tuple_arg_ty); true } |)* false;
151158
const is_anon: bool = contains_anon_attr!($($attrs)*);
152159
const is_eval_always: bool = contains_eval_always_attr!($($attrs)*);
153160

154161
DepKindStruct {
162+
has_params,
155163
is_anon,
156164
is_eval_always,
157165
}
@@ -199,23 +207,6 @@ macro_rules! define_dep_nodes {
199207
)*
200208
}
201209
}
202-
203-
#[allow(unreachable_code)]
204-
pub fn has_params(&self) -> bool {
205-
match *self {
206-
$(
207-
DepKind :: $variant => {
208-
// tuple args
209-
$({
210-
erase!($tuple_arg_ty);
211-
return true;
212-
})*
213-
214-
false
215-
}
216-
)*
217-
}
218-
}
219210
}
220211

221212
pub struct DepConstructor;
@@ -308,7 +299,7 @@ impl DepNodeExt for DepNode {
308299
/// method will assert that the given DepKind actually requires a
309300
/// single DefId/DefPathHash parameter.
310301
fn from_def_path_hash(def_path_hash: DefPathHash, kind: DepKind) -> DepNode {
311-
debug_assert!(kind.can_reconstruct_query_key() && kind.has_params());
302+
debug_assert!(kind.can_reconstruct_query_key() && kind.has_params);
312303
DepNode { kind, hash: def_path_hash.0.into() }
313304
}
314305

@@ -341,7 +332,7 @@ impl DepNodeExt for DepNode {
341332
return Err(());
342333
}
343334

344-
if kind.has_params() {
335+
if kind.has_params {
345336
Ok(DepNode::from_def_path_hash(def_path_hash, kind))
346337
} else {
347338
Ok(DepNode::new_no_params(kind))

compiler/rustc_middle/src/dep_graph/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@ impl rustc_query_system::dep_graph::DepKind for DepKind {
3131
self.is_eval_always
3232
}
3333

34+
#[inline(always)]
3435
fn has_params(&self) -> bool {
35-
DepKind::has_params(self)
36+
self.has_params
3637
}
3738

3839
fn debug_node(node: &DepNode, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3940
write!(f, "{:?}", node.kind)?;
4041

41-
if !node.kind.has_params() && !node.kind.is_anon {
42+
if !node.kind.has_params && !node.kind.is_anon {
4243
return Ok(());
4344
}
4445

0 commit comments

Comments
 (0)