-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nightly feature tracking: get rid of the per-feature bool fields #132027
base: master
Are you sure you want to change the base?
Conversation
Some changes occurred in src/tools/clippy cc @rust-lang/clippy Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri HIR ty lowering was modified cc @fmease Some changes occurred in exhaustiveness checking cc @Nadrieril Some changes occurred in cc @BoxyUwU Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt Some changes occurred in src/librustdoc/clean/types.rs cc @camelid These commits modify compiler targets. Some changes occurred in match checking cc @Nadrieril changes to the core type system Some changes occurred in match lowering cc @Nadrieril Some changes occurred in cc @BoxyUwU |
16e611f
to
dd8850b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A nice simplification. Just a few minor comments.
@@ -115,7 +115,7 @@ impl<'tcx> HashStable<StableHashingContext<'tcx>> for rustc_feature::Features { | |||
self.enabled_lang_features().hash_stable(hcx, hasher); | |||
self.enabled_lib_features().hash_stable(hcx, hasher); | |||
|
|||
self.all_lang_features()[..].hash_stable(hcx, hasher); | |||
// FIXME: why do we hash something that is a compile-time constant? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good question. But I suggest undoing this change and then redoing it in a follow-up PR. That way if any problems occur they will bisect back to a small and distinct PR.
@@ -14,7 +14,7 @@ type GateFn = fn(&Features) -> bool; | |||
|
|||
macro_rules! cfg_fn { | |||
($field: ident) => { | |||
(|features| features.$field) as GateFn | |||
Features::$field as GateFn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the as GateFn
still needed? If not, it might be worth removing this macro and writing Features::foo
directly in all the relevant places.
@@ -8,7 +8,6 @@ use super::{Feature, to_nonzero}; | |||
|
|||
pub struct UnstableFeature { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This struct is now a trivial wrapper around Feature
. Maybe remove it in a second commit?
@@ -30,6 +29,46 @@ macro_rules! status_to_enum { | |||
}; | |||
} | |||
|
|||
/// A set of features to be used by later passes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A comment like this would be useful here:
There are two ways to check if a feature `foo` is enabled.
- Directly with the `foo` method, e.g. `if tcx.features().foo() { ... }`.
- With the `enabled` method, e.g. `if tcx.features.enabled(sym::foo) { ... }`.
The former is preferred. `enabled` should only be used when the feature symbol is not a constant, e.g. a parameter.
enabled_features: FxHashSet<Symbol>, | ||
} | ||
|
||
impl Features { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This impl
block is much nicer now 👍
Some(sym::x86_amx_intrinsics) => rust_features.x86_amx_intrinsics, | ||
Some(sym::xop_target_feature) => rust_features.xop_target_feature, | ||
Some(sym::s390x_target_feature) => rust_features.s390x_target_feature, | ||
Some(sym::arm_target_feature) => rust_features.arm_target_feature(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be changed to:
Some(sym) => {
match sym {
sym::arm_target_feature
| sym::hexagon_target_feature
| ... // all the other possibilities
=> rust_features.enabled(sym)
}
}
It has more indentation, but would avoid the feature name being repeated on every line, and make it easier to add new lines in the future. What do you think?
Let's do another perf run, just to be sure: @bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
…=<try> nightly feature tracking: get rid of the per-feature bool fields The `struct Features` that tracks which features are enabled has a ton of public `bool`-typed fields that are basically caching the result of looking up the corresponding feature in `enabled_lang_features`. Having public fields with an invariant is not great, so at least they should be made private. However, it turns out caching these lookups is actually [not worth it](rust-lang#131321 (comment)), so this PR just entirely gets rid of these fields. (The alternative would be to make them private and have a method for each of them to expose them in a read-only way. Most of the diff of this PR would be the same in that case.) r? `@nnethercote`
☀️ Try build successful - checks-actions |
Queued 740f801 with parent 86d69c7, future comparison URL. |
The
struct Features
that tracks which features are enabled has a ton of publicbool
-typed fields that are basically caching the result of looking up the corresponding feature inenabled_lang_features
. Having public fields with an invariant is not great, so at least they should be made private. However, it turns out caching these lookups is actually not worth it, so this PR just entirely gets rid of these fields. (The alternative would be to make them private and have a method for each of them to expose them in a read-only way. Most of the diff of this PR would be the same in that case.)r? @nnethercote