Cut code size for feature hashing
This locally cuts ~32 kB of .text instructions.
This commit is contained in:
parent
1bcbb7c93b
commit
1487bd6a17
@ -50,6 +50,8 @@ macro_rules! declare_features {
|
|||||||
}),+
|
}),+
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const NUM_FEATURES: usize = UNSTABLE_FEATURES.len();
|
||||||
|
|
||||||
/// A set of features to be used by later passes.
|
/// A set of features to be used by later passes.
|
||||||
#[derive(Clone, Default, Debug)]
|
#[derive(Clone, Default, Debug)]
|
||||||
pub struct Features {
|
pub struct Features {
|
||||||
@ -82,8 +84,14 @@ macro_rules! declare_features {
|
|||||||
self.declared_features.insert(symbol);
|
self.declared_features.insert(symbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_feature_fields(&self, mut f: impl FnMut(&str, bool)) {
|
/// This is intended for hashing the set of active features.
|
||||||
$(f(stringify!($feature), self.$feature);)+
|
///
|
||||||
|
/// The expectation is that this produces much smaller code than other alternatives.
|
||||||
|
///
|
||||||
|
/// Note that the total feature count is pretty small, so this is not a huge array.
|
||||||
|
#[inline]
|
||||||
|
pub fn all_features(&self) -> [u8; NUM_FEATURES] {
|
||||||
|
[$(self.$feature as u8),+]
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Is the given feature explicitly declared, i.e. named in a
|
/// Is the given feature explicitly declared, i.e. named in a
|
||||||
|
@ -117,9 +117,9 @@ impl<'tcx> HashStable<StableHashingContext<'tcx>> for rustc_feature::Features {
|
|||||||
self.declared_lang_features.hash_stable(hcx, hasher);
|
self.declared_lang_features.hash_stable(hcx, hasher);
|
||||||
self.declared_lib_features.hash_stable(hcx, hasher);
|
self.declared_lib_features.hash_stable(hcx, hasher);
|
||||||
|
|
||||||
self.walk_feature_fields(|feature_name, value| {
|
self.all_features()[..].hash_stable(hcx, hasher);
|
||||||
feature_name.hash_stable(hcx, hasher);
|
for feature in rustc_feature::UNSTABLE_FEATURES.iter() {
|
||||||
value.hash_stable(hcx, hasher);
|
feature.feature.name.hash_stable(hcx, hasher);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user