Skip to content

Commit a8b1888

Browse files
committed
Encode DepNodeKind in the lowest bit of DepNodeKind
1 parent b1cf4d0 commit a8b1888

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
@@ -105,10 +105,23 @@ macro_rules! define_dep_nodes {
105105
$({ $($struct_arg_name:ident : $struct_arg_ty:ty),* })*
106106
,)*
107107
) => (
108+
// Used to get an unique integer per dep kind
109+
enum DepKindCounter {
110+
$($variant),*
111+
}
112+
113+
/// Encodes `eval_always` in the lowest bit of the discriminant
114+
const fn dep_kind_discriminant(kind: DepKindCounter, eval_always: bool) -> isize {
115+
(((kind as u16) << 1) | (eval_always as u16)) as isize
116+
}
117+
108118
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash,
109119
RustcEncodable, RustcDecodable)]
110120
pub enum DepKind {
111-
$($variant),*
121+
$($variant = dep_kind_discriminant(
122+
DepKindCounter::$variant,
123+
contains_eval_always_attr!($($attr),*),
124+
)),*
112125
}
113126

114127
impl DepKind {
@@ -154,11 +167,8 @@ macro_rules! define_dep_nodes {
154167

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

164174
#[allow(unreachable_code)]

0 commit comments

Comments
 (0)