diff options
| author | Mark Rousskov <mark.simulacrum@gmail.com> | 2023-11-26 22:32:41 -0500 |
|---|---|---|
| committer | Mark Rousskov <mark.simulacrum@gmail.com> | 2023-11-26 22:34:17 -0500 |
| commit | 1487bd6a174f813967ffff6b3334b4fe296f1f30 (patch) | |
| tree | 799c4cbf66e0b395bec5d64f1259dd5cd612992b /compiler | |
| parent | 1bcbb7c93b96828092e83e52d592faa046183d6c (diff) | |
| download | rust-1487bd6a174f813967ffff6b3334b4fe296f1f30.tar.gz rust-1487bd6a174f813967ffff6b3334b4fe296f1f30.zip | |
Cut code size for feature hashing
This locally cuts ~32 kB of .text instructions.
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_feature/src/unstable.rs | 12 | ||||
| -rw-r--r-- | compiler/rustc_query_system/src/ich/impls_syntax.rs | 8 |
2 files changed, 14 insertions, 6 deletions
diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index e34661d5fc6..f73a286e6af 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -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. #[derive(Clone, Default, Debug)] pub struct Features { @@ -82,8 +84,14 @@ macro_rules! declare_features { self.declared_features.insert(symbol); } - pub fn walk_feature_fields(&self, mut f: impl FnMut(&str, bool)) { - $(f(stringify!($feature), self.$feature);)+ + /// This is intended for hashing the set of active features. + /// + /// 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 diff --git a/compiler/rustc_query_system/src/ich/impls_syntax.rs b/compiler/rustc_query_system/src/ich/impls_syntax.rs index 81a7eb604f5..f2387017c82 100644 --- a/compiler/rustc_query_system/src/ich/impls_syntax.rs +++ b/compiler/rustc_query_system/src/ich/impls_syntax.rs @@ -117,9 +117,9 @@ impl<'tcx> HashStable<StableHashingContext<'tcx>> for rustc_feature::Features { self.declared_lang_features.hash_stable(hcx, hasher); self.declared_lib_features.hash_stable(hcx, hasher); - self.walk_feature_fields(|feature_name, value| { - feature_name.hash_stable(hcx, hasher); - value.hash_stable(hcx, hasher); - }); + self.all_features()[..].hash_stable(hcx, hasher); + for feature in rustc_feature::UNSTABLE_FEATURES.iter() { + feature.feature.name.hash_stable(hcx, hasher); + } } } |
