Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Oct 22, 2024

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, 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

@rustbot rustbot added A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Oct 22, 2024
@rustbot
Copy link
Collaborator

rustbot commented Oct 22, 2024

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 const_evaluatable.rs

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.
(See the Target Tier Policy.)

Some changes occurred in match checking

cc @Nadrieril

changes to the core type system

cc @compiler-errors, @lcnr

Some changes occurred in match lowering

cc @Nadrieril

Some changes occurred in rustc_ty_utils::consts.rs

cc @BoxyUwU

Copy link
Contributor

@nnethercote nnethercote left a 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?
Copy link
Contributor

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
Copy link
Contributor

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 {
Copy link
Contributor

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.
Copy link
Contributor

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 {
Copy link
Contributor

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(),
Copy link
Contributor

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?

@nnethercote
Copy link
Contributor

Let's do another perf run, just to be sure:

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 22, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 22, 2024
…=<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`
@bors
Copy link
Contributor

bors commented Oct 22, 2024

⌛ Trying commit dd8850b with merge 740f801...

@bors
Copy link
Contributor

bors commented Oct 22, 2024

☀️ Try build successful - checks-actions
Build commit: 740f801 (740f801072bbece1059248b3173d1ea8d7da6435)

@rust-timer
Copy link
Collaborator

Queued 740f801 with parent 86d69c7, future comparison URL.
There is currently 1 preceding artifact in the queue.
It will probably take at least ~2.5 hours until the benchmark run finishes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-perf Status: Waiting on a perf run to be completed. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants