-
Notifications
You must be signed in to change notification settings - Fork 13.3k
const-stabilize HashMap/HashSet::with_hasher (+ required compiller changes) #118427
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
Closed
aDotInTheVoid
wants to merge
4
commits into
rust-lang:master
from
aDotInTheVoid:most-normal-stabilization
Closed
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ec12fea
const_eval: Allow std to stabley call const fns from deps.
aDotInTheVoid 9318d0a
const-stabilize HashMap/HashSet::with_hasher
aDotInTheVoid f4136eb
`any` -> `any_unmarked` for `rustc_allow_const_fn_unstable`
aDotInTheVoid ec8f6af
Add test for calling const-unstable function with `-Zforce-unstable-i…
aDotInTheVoid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// compile-flags: -Zforce-unstable-if-unmarked | ||
|
||
// This emulates a dep-of-std (eg hashbrown), that has const functions it | ||
// cannot mark as stable, and is build with force-unstable-if-unmarked. | ||
|
||
pub const fn do_something_else() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// aux-build:normal-const-fn.rs | ||
// check-pass | ||
#![crate_type = "lib"] | ||
#![feature(staged_api)] | ||
#![feature(rustc_attrs)] | ||
#![feature(rustc_private)] | ||
#![allow(internal_features)] | ||
#![feature(rustc_allow_const_fn_unstable)] | ||
#![stable(feature = "stable_feature", since = "1.0.0")] | ||
|
||
extern crate normal_const_fn; | ||
|
||
// This ensures std can call const functions in it's deps that don't have | ||
// access to rustc_const_stable annotations (and hense don't have a feature) | ||
// gate. | ||
|
||
#[rustc_const_stable(feature = "stable_feature", since = "1.0.0")] | ||
#[stable(feature = "stable_feature", since = "1.0.0")] | ||
#[rustc_allow_const_fn_unstable(any)] | ||
pub const fn do_something() { | ||
normal_const_fn::do_something_else() | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
So this would allow this function to call any unstable function? That's not great, we specifically want to keep an eye on what is (recursively) exposed to
const
on stable, and with such an "any" handling that's not really possible.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.
In fact this calls into hashbrown, doesn't it? We'd want to ensure that hashbrown only uses const-stable features then. const nightly features are much more prone to making things fail-to-build when they get changed, which is why we have a more strict stability check than for regular non-const functions.
Ideally we'd be able to, and be required to, mark functions as
rustc_const_stable
in hashbrown itself; together with an agreement with the hashbrown maintainers that wg-const-eval will be consulted before making use ofrustc_allow_const_fn_unstable
. That requires a rework of the const stability stuff though I think since currently it is tied up with the regular stability stuff (but there's no need for that, having an unstable function be const-stable makes perfect sense).I'm not sure what is the best way to do that. This might have to wait until Oli is back from vacation, it's a pretty fundamental change to our const stabilization policy.
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.
No, only unmarked unstable functions. I should add a test for this (and change the name as well)
This already happens because hashbrown's functions are
const
on stable (so only have access to things that have been const-stabilized).However, because deps-of-std are build with
-Zforce-unstable-if-unmarked
, the compiler believes them to be unstably-const.This could be accomplished with a load of
but it would require a load of ugly changes to hashbrown, as this would also require them to mark all public functions as stable (because currently stability and const-stability are under the same
#![feature(staged_api)]
. Spliting that up would be a lot of work for very little benefit.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.
I see a lot of
feature
flags in hashbrown, in particular core_intrinsics which is potentially problematic. We surely don't want it to const-use any intrinsic we haven't exposed stably yet. How can we be sure that the hashbrown built for the standard library still only uses stable const features?What are "unmarked" unstable functions?
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.
I supose hashbrown could change to
#[cfg_attr(feature="rustc_dep_of_std"), feature(const_super_unstable_and_broken)]
, and we wouldn't mechanicly know. I think the best way would be to ask them not to do that. Given that hashbrown needs to be able to provide a const-stable implementation of new, I'm not concerned about being backed into a corner where there's no way to implement new with stable const 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.
core_intrinsics
seems to only be used forCan we move those under a different feature so that hashbrown can use them but not accidentally use anything else?
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.
See
rust/compiler/rustc_const_eval/src/transform/check_consts/check.rs
Lines 984 to 989 in b10cfcd
When a function is unstable, but not either const-stable or const-unstable. This is true for hashbrown, despite it not having any stability attributes, as it is built with
-Zforce-unstable-if-unmarked
such that it isn't availibe to normal crates, despite being available in the sysrootrust/compiler/rustc_passes/src/stability.rs
Lines 635 to 651 in b10cfcd
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.
Don't see why not. Although it looks like the pattern with intrinsic is to add wrappers that don't live in intrinsic, and put them on a separate feature and maybe stabilize them.
#![feature(core_intrinsics)]
doesn't allow using them in const-contexts, that's on a seperate feature. While it's not impossible, it'd be much more likely (ha) to be flagged in review.https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=43a21473dbd0af03612e0805e2a847f2
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.
Okay I see. I also see this comment
@ecstatic-morse I wonder what you meant by "fixing" this, what would be the more correct behavior?
IMO these should be treated like those with explicit
rustc_const_unstable
except they have no feature gate.Yes. But those will often not be const at all, or they are const unstable and hashbrown shouldn't use that feature ideally.
Hm... we could raise an error when an "unmarked" const function calls a const-unstable function? That should guarantee that when we allow
rustc_allow_const_fn_unstable(unmarked)
this can never call a function explicitly marked as const-unstable, not even transitively?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.
We already do this! I've added a test for this.
Also, I've renamed the attribute to
#[rustc_allow_const_fn_unstable(any_unmarked)]
, so it's clearer that you can't call arbitrary unstableley-const fns.