Skip to content

Commit ce85ac2

Browse files
committed
Encode DepNodeKind in the lowest bit of DepNodeKind
1 parent 62ca540 commit ce85ac2

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,23 @@ macro_rules! define_dep_nodes {
106106
$({ $($struct_arg_name:ident : $struct_arg_ty:ty),* })*
107107
,)*
108108
) => (
109+
// Used to get an unique integer per dep kind
110+
enum DepKindCounter {
111+
$($variant),*
112+
}
113+
114+
/// Encodes `eval_always` in the lowest bit of the discriminant
115+
const fn dep_kind_discriminant(kind: DepKindCounter, eval_always: bool) -> isize {
116+
(((kind as u16) << 1) | (eval_always as u16)) as isize
117+
}
118+
109119
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash,
110120
RustcEncodable, RustcDecodable)]
111121
pub enum DepKind {
112-
$($variant),*
122+
$($variant = dep_kind_discriminant(
123+
DepKindCounter::$variant,
124+
contains_eval_always_attr!($($attr),*),
125+
)),*
113126
}
114127

115128
impl DepKind {
@@ -155,11 +168,8 @@ macro_rules! define_dep_nodes {
155168

156169
#[inline(always)]
157170
pub fn is_eval_always(&self) -> bool {
158-
match *self {
159-
$(
160-
DepKind :: $variant => { contains_eval_always_attr!($($attr), *) }
161-
)*
162-
}
171+
// `eval_always` is encoded in the lowest bit of DepNodeKind
172+
*self as u16 & 1 == 1
163173
}
164174

165175
#[allow(unreachable_code)]

0 commit comments

Comments
 (0)