Skip to content

Commit 1487bd6

Browse files
Cut code size for feature hashing
This locally cuts ~32 kB of .text instructions.
1 parent 1bcbb7c commit 1487bd6

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

Diff for: compiler/rustc_feature/src/unstable.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ macro_rules! declare_features {
5050
}),+
5151
];
5252

53+
const NUM_FEATURES: usize = UNSTABLE_FEATURES.len();
54+
5355
/// A set of features to be used by later passes.
5456
#[derive(Clone, Default, Debug)]
5557
pub struct Features {
@@ -82,8 +84,14 @@ macro_rules! declare_features {
8284
self.declared_features.insert(symbol);
8385
}
8486

85-
pub fn walk_feature_fields(&self, mut f: impl FnMut(&str, bool)) {
86-
$(f(stringify!($feature), self.$feature);)+
87+
/// This is intended for hashing the set of active features.
88+
///
89+
/// The expectation is that this produces much smaller code than other alternatives.
90+
///
91+
/// Note that the total feature count is pretty small, so this is not a huge array.
92+
#[inline]
93+
pub fn all_features(&self) -> [u8; NUM_FEATURES] {
94+
[$(self.$feature as u8),+]
8795
}
8896

8997
/// Is the given feature explicitly declared, i.e. named in a

Diff for: compiler/rustc_query_system/src/ich/impls_syntax.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ impl<'tcx> HashStable<StableHashingContext<'tcx>> for rustc_feature::Features {
117117
self.declared_lang_features.hash_stable(hcx, hasher);
118118
self.declared_lib_features.hash_stable(hcx, hasher);
119119

120-
self.walk_feature_fields(|feature_name, value| {
121-
feature_name.hash_stable(hcx, hasher);
122-
value.hash_stable(hcx, hasher);
123-
});
120+
self.all_features()[..].hash_stable(hcx, hasher);
121+
for feature in rustc_feature::UNSTABLE_FEATURES.iter() {
122+
feature.feature.name.hash_stable(hcx, hasher);
123+
}
124124
}
125125
}

0 commit comments

Comments
 (0)