Skip to content

Commit

Permalink
Use a field for has_params.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Jan 8, 2021
1 parent d8c87ac commit 5027f1c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 25 deletions.
37 changes: 14 additions & 23 deletions compiler/rustc_middle/src/dep_graph/dep_node.rs
Expand Up @@ -76,6 +76,9 @@ pub use rustc_query_system::dep_graph::{DepContext, DepNodeParams};
/// of the `DepKind`. Overall, this allows to implement `DepContext` using this manual
/// jump table instead of large matches.
pub struct DepKindStruct {
/// Whether the DepNode has parameters (query keys).
pub(super) has_params: bool,

/// Anonymous queries cannot be replayed from one compiler invocation to the next.
/// When their result is needed, it is recomputed. They are useful for fine-grained
/// dependency tracking, and caching within one compiler invocation.
Expand Down Expand Up @@ -132,26 +135,31 @@ pub mod dep_kind {
use super::*;

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

// Represents metadata from an extern crate.
pub const CrateMetadata: DepKindStruct = DepKindStruct { is_anon: false, is_eval_always: true };
pub const CrateMetadata: DepKindStruct =
DepKindStruct { has_params: true, is_anon: false, is_eval_always: true };

pub const TraitSelect: DepKindStruct = DepKindStruct { is_anon: true, is_eval_always: false };
pub const TraitSelect: DepKindStruct =
DepKindStruct { has_params: false, is_anon: true, is_eval_always: false };

pub const CompileCodegenUnit: DepKindStruct =
DepKindStruct { is_anon: false, is_eval_always: false };
DepKindStruct { has_params: true, is_anon: false, is_eval_always: false };

macro_rules! define_query_dep_kinds {
($(
[$($attrs:tt)*]
$variant:ident $(( $tuple_arg_ty:ty $(,)? ))*
,)*) => (
$(pub const $variant: DepKindStruct = {
const has_params: bool = $({ erase!($tuple_arg_ty); true } |)* false;
const is_anon: bool = contains_anon_attr!($($attrs)*);
const is_eval_always: bool = contains_eval_always_attr!($($attrs)*);

DepKindStruct {
has_params,
is_anon,
is_eval_always,
}
Expand Down Expand Up @@ -199,23 +207,6 @@ macro_rules! define_dep_nodes {
)*
}
}

#[allow(unreachable_code)]
pub fn has_params(&self) -> bool {
match *self {
$(
DepKind :: $variant => {
// tuple args
$({
erase!($tuple_arg_ty);
return true;
})*

false
}
)*
}
}
}

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

Expand Down Expand Up @@ -341,7 +332,7 @@ impl DepNodeExt for DepNode {
return Err(());
}

if kind.has_params() {
if kind.has_params {
Ok(DepNode::from_def_path_hash(def_path_hash, kind))
} else {
Ok(DepNode::new_no_params(kind))
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_middle/src/dep_graph/mod.rs
Expand Up @@ -31,14 +31,15 @@ impl rustc_query_system::dep_graph::DepKind for DepKind {
self.is_eval_always
}

#[inline(always)]
fn has_params(&self) -> bool {
DepKind::has_params(self)
self.has_params
}

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

if !node.kind.has_params() && !node.kind.is_anon {
if !node.kind.has_params && !node.kind.is_anon {
return Ok(());
}

Expand Down

0 comments on commit 5027f1c

Please sign in to comment.