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

const fn stability checking: also check declared language features #129659

Merged
merged 1 commit into from
Aug 31, 2024

Conversation

RalfJung
Copy link
Member

Fixes #129656

@oli-obk I assume it is just an oversight that this didn't use features().declared()? Or is there a deep reason that this must only check declared_lib_features?

@rustbot
Copy link
Collaborator

rustbot commented Aug 27, 2024

r? @fee1-dead

rustbot has assigned @fee1-dead.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added 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. labels Aug 27, 2024
@fee1-dead
Copy link
Member

fee1-dead commented Aug 29, 2024

The only reason I could think of is that we might allow rustc_const_unstable under a lang feature, but the lang feature is already accepted. So when someone tries to call that const function in const contexts, it would suggest them to enable the feature, but when they enable the feature they'd see a warning that it is already stable?

oli is on leave, so maybe we can get more eyes on this from someone else who is familiar with stability checking

@RalfJung
Copy link
Member Author

The only reason I could think of is that we might allow rustc_const_unstable under a lang feature, but the lang feature is already accepted. So when someone tries to call that const function in const contexts, it would suggest them to enable the feature, but when they enable the feature they'd see a warning that it is already stable?

That would equally apply to regular stability, not just const stability, right?
We might want to reject unstable/rustc_const_unstable with an already-stable (or removed) language feature. But that's a separate question.

@RalfJung
Copy link
Member Author

The status quo is that the example in #129656 suggests to enable the f128 feature gate which is already enabled. So that's clearly worse than what you describe. ;)

Copy link
Contributor

@oli-obk oli-obk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't make any statements about the current or expected behavior around (const) stability without putting more thought and time into it than I am currently able to

@@ -0,0 +1,19 @@
//! Ensure that we can use a language feature with a `const fn` and things behave as expected.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explain what "expected" means in detail.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it should work like all feature gates work -- if you enable the feature gate it is actually considered enabled...

@RalfJung
Copy link
Member Author

To me this looks like a fairly simple oversight -- the code does tcx.features().declared_lib_features.iter().any(...) to check whether a feature gate is enabled, but everywhere else in the compiler we use tcx.features().declared(...) to do that check.

@fee1-dead
Copy link
Member

We might want to reject unstable/rustc_const_unstable with an already-stable (or removed) language feature. But that's a separate question.

Let's add that as a test. If this isn't rejected, we should open an issue to track fixing it for both unstable and rustc_const_unstable. If the case for unstable is already fixed but not rustc_const_unstable, I'd want this PR to have that fixed also.

The status quo is that the example in #129656 suggests to enable the f128 feature gate which is already enabled. So that's clearly worse than what you describe. ;)

Well, that requires someone who enables the staged_api feature to specify a lang feature with rustc_const_unstable. It's bad, but I think there's not a lot urgency for making it possible.. Even if the PR using f128_const lands first, we can also just rename the feature afterwards.

@RalfJung
Copy link
Member Author

RalfJung commented Aug 31, 2024

I think there's not a lot urgency

I didn't say that this fix is more urgent than a regular PR. It's just a normal bugfix. :)

Let's add that as a test. If this isn't rejected, we should open an issue to track fixing it for both unstable and rustc_const_unstable. If the case for unstable is already fixed but not rustc_const_unstable, I'd want this PR to have that fixed also.

This is completely orthogonal to the issue this PR is concerned with. Please don't ask the PR to be extended in scope to fix unrelated issues.

This PR is about making rustc_const_unstable consistent with unstable.

I created an issue to track the concern around already-stable lang features: #129814.

@fee1-dead
Copy link
Member

Let's add that as a test. If this isn't rejected, we should open an issue to track fixing it for both unstable and rustc_const_unstable. If the case for unstable is already fixed but not rustc_const_unstable, I'd want this PR to have that fixed also.

This is completely orthogonal to the issue this PR is concerned with. Please don't ask the PR to be extended in scope to fix unrelated issues.

Maybe I should be the person opening that issue.. I shouldn't be asking for more work when it isn't necessary. Sorry if that nudge was annoying!

On another look, I think there is no deep reason - probably an oversight as you said, so let's merge it.

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Aug 31, 2024

📌 Commit c298417 has been approved by fee1-dead

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 31, 2024
@fee1-dead
Copy link
Member

fee1-dead commented Aug 31, 2024

The actual reason that this used declared_lib_features instead of .declared is probably that we just didn't consider the potential use for specifying a lang feature in rustc_const_unstable. I guess I was trying too hard to find any deep reasons for this.

bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 31, 2024
…iaskrgr

Rollup of 12 pull requests

Successful merges:

 - rust-lang#129659 (const fn stability checking: also check declared language features)
 - rust-lang#129711 (Expand NLL MIR dumps)
 - rust-lang#129730 (f32 docs: define 'arithmetic' operations)
 - rust-lang#129733 (Subtree update of `rust-analyzer`)
 - rust-lang#129749 (llvm-wrapper: adapt for LLVM API changes)
 - rust-lang#129757 (Add a test for trait solver overflow in MIR inliner cycle detection)
 - rust-lang#129760 (Make the "detect-old-time" UI test more representative)
 - rust-lang#129767 (Remove `#[macro_use] extern crate tracing`, round 4)
 - rust-lang#129774 (Remove `#[macro_use] extern crate tracing` from rustdoc and rustfmt)
 - rust-lang#129785 (Miri subtree update)
 - rust-lang#129791 (mark joboet as on vacation)
 - rust-lang#129812 (interpret, codegen: tweak some comments and checks regarding Box with custom allocator)

Failed merges:

 - rust-lang#129777 (Add `unreachable_pub`, round 4)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 31, 2024
…iaskrgr

Rollup of 12 pull requests

Successful merges:

 - rust-lang#129659 (const fn stability checking: also check declared language features)
 - rust-lang#129711 (Expand NLL MIR dumps)
 - rust-lang#129730 (f32 docs: define 'arithmetic' operations)
 - rust-lang#129733 (Subtree update of `rust-analyzer`)
 - rust-lang#129749 (llvm-wrapper: adapt for LLVM API changes)
 - rust-lang#129757 (Add a test for trait solver overflow in MIR inliner cycle detection)
 - rust-lang#129760 (Make the "detect-old-time" UI test more representative)
 - rust-lang#129767 (Remove `#[macro_use] extern crate tracing`, round 4)
 - rust-lang#129774 (Remove `#[macro_use] extern crate tracing` from rustdoc and rustfmt)
 - rust-lang#129785 (Miri subtree update)
 - rust-lang#129791 (mark joboet as on vacation)
 - rust-lang#129812 (interpret, codegen: tweak some comments and checks regarding Box with custom allocator)

Failed merges:

 - rust-lang#129777 (Add `unreachable_pub`, round 4)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit ea5bb99 into rust-lang:master Aug 31, 2024
6 checks passed
@rustbot rustbot added this to the 1.82.0 milestone Aug 31, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Aug 31, 2024
Rollup merge of rust-lang#129659 - RalfJung:const-fn-lang-feat, r=fee1-dead

const fn stability checking: also check declared language features

Fixes rust-lang#129656

`@oli-obk` I assume it is just an oversight that this didn't use `features().declared()`? Or is there a deep reason that this must only check `declared_lib_features`?
@RalfJung RalfJung deleted the const-fn-lang-feat branch August 31, 2024 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A const-unstable function cannot call other const-unstable functions gated under a language feature gate
5 participants