Skip to content

Commit

Permalink
Auto merge of rust-lang#118348 - Mark-Simulacrum:feature-code-size, r…
Browse files Browse the repository at this point in the history
…=compiler-errors

Cut code size for feature hashing

This locally cuts ~32 kB of .text instructions.

This isn't really a clear win in terms of readability. IMO the code size benefits are worth it (even if they're not necessarily present in the x86_64 hyperoptimized build, I expect them to translate similarly to other platforms). Ultimately there's lots of "small ish" low hanging fruit like this that I'm seeing that seems worth tackling to me, and could translate into larger wins in aggregate.
  • Loading branch information
bors committed Nov 29, 2023
2 parents b1e56de + 1487bd6 commit f440b5f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 10 additions & 2 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_query_system/src/ich/impls_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

0 comments on commit f440b5f

Please sign in to comment.