Repository navigation
Stabilize funnel_shifts (including const) - #161015
Conversation
|
Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr
cc @rust-lang/wg-const-eval
cc @rust-lang/wg-const-eval
cc @rust-lang/miri
cc @Amanieu, @folkertdev, @sayantn |
| #[rustc_intrinsic_const_stable_indirect] | ||
| #[rustc_intrinsic] | ||
| #[rustc_nounwind] | ||
| #[rustc_const_unstable(feature = "funnel_shifts", issue = "145686")] | ||
| #[unstable(feature = "funnel_shifts", issue = "145686")] | ||
| #[track_caller] | ||
| #[rustc_allow_const_fn_unstable(const_trait_impl, core_intrinsics_fallbacks)] | ||
| #[miri::intrinsic_fallback_is_spec] | ||
| pub const unsafe fn unchecked_funnel_shl<T: [const] fallback::FunnelShift>( |
There was a problem hiding this comment.
Note that const_trait_impl is only needed for the fallback. We could implement a version without it if needed.
The fallback traits are gated behind core_intrinsics_fallbacks, I'm not sure whether there's a cleaner way to do this.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment has been minimized.
This comment has been minimized.
cf9c57e to
11cd98d
Compare
This comment has been minimized.
This comment has been minimized.
11cd98d to
c21507f
Compare
There was a problem hiding this comment.
This should be "right half", right?
|
@traviscross has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
|
Zero lang concerns; this is a value operation with fallback MIR showing it can be implemented with existing rust. @rfcbot reviewed |
|
A concern for the libs(-api) part: Is this actually guaranteed to panic for out-of-range shifts? It feels inconsistent with other things. I'd expect that And it's a bit weird to not have the |
|
Wrapping by default was the original proposal but was decided against, see rust-lang/libs-team#642 (comment). The |
|
We’ll implement the wrapping versions, independently of this PR. EDIT: Done in #161119. |
…r=nia-e
Stabilize `funnel_shifts` (including `const`)
`funnel_shl` and `funnel_shr` have been around for close to a year, the unchecked versions for a number of months. These are reasonably small and uncontroversial, and it can be tricky to get similar performance with a fallback; stabilize them here.
Newly stable API:
```rust
impl {u8, u16, u32, u64, u128, usize} {
pub const fn funnel_shl(self, right: Self, shift: u32) -> Self;
pub const fn funnel_shr(self, right: Self, shift: u32) -> Self;
pub const unsafe fn unchecked_funnel_shl(self, right: Self, shift: u32) -> Self;
pub const unsafe fn unchecked_funnel_shr(self, right: Self, shift: u32) -> Self;
}
```
The tracking issue also mentions a `wrapping_` version but it has not been implemented.
Closes: rust-lang#145686 (tracking issue, wrapping versions will need a new issue)
…r=nia-e
Stabilize `funnel_shifts` (including `const`)
`funnel_shl` and `funnel_shr` have been around for close to a year, the unchecked versions for a number of months. These are reasonably small and uncontroversial, and it can be tricky to get similar performance with a fallback; stabilize them here.
Newly stable API:
```rust
impl {u8, u16, u32, u64, u128, usize} {
pub const fn funnel_shl(self, right: Self, shift: u32) -> Self;
pub const fn funnel_shr(self, right: Self, shift: u32) -> Self;
pub const unsafe fn unchecked_funnel_shl(self, right: Self, shift: u32) -> Self;
pub const unsafe fn unchecked_funnel_shr(self, right: Self, shift: u32) -> Self;
}
```
The tracking issue also mentions a `wrapping_` version but it has not been implemented.
Closes: rust-lang#145686 (tracking issue, wrapping versions will need a new issue)
…uwer Rollup of 15 pull requests Successful merges: - #158936 (Add `std::fs::{Home|Media}Dirs`) - #129036 (Additional NonZero conversions) - #158997 (Avoid recording unnameable `extern crate` aliases in diagnostic metadata) - #161015 (Stabilize `funnel_shifts` (including `const`)) - #161712 (Stabilize `Result::into_{ok,err}`) - #162493 (Add support for -Zsanitizer-cfi-minimal-runtime) - #162655 (next solver: prefer to select impl candidates over global where-clause candidates) - #162862 (Fix intra doc link resolution when a doc comment is composed of both inner and outer doc comment) - #163200 (make `RustaceansAreAwesome` satisfy trait bounds) - #163331 (Move `Arc` and `Rc` into `rcs` mod) - #163427 (implement #![feature(gca_adts)]) - #163428 (do not complain about unstable target features on nightly) - #163444 (Add `stable_rustc` helper in `run-make-support`) - #163447 (Allow using different index types when reading and writing to tables) - #163450 (Force the correct type variable to never for method resolution on an adjusted never type)
|
⌛ Testing commit f7548dd with merge e666839... Workflow: https://github.com/rust-lang/rust/actions/runs/36521046367 |
Stabilize `funnel_shifts` (including `const`)
`funnel_shl` and `funnel_shr` have been around for close to a year, the unchecked versions for a number of months. These are reasonably small and uncontroversial, and it can be tricky to get similar performance with a fallback; stabilize them here.
Newly stable API:
```rust
impl {u8, u16, u32, u64, u128, usize} {
pub const fn funnel_shl(self, right: Self, shift: u32) -> Self;
pub const fn funnel_shr(self, right: Self, shift: u32) -> Self;
pub const unsafe fn unchecked_funnel_shl(self, right: Self, shift: u32) -> Self;
pub const unsafe fn unchecked_funnel_shr(self, right: Self, shift: u32) -> Self;
}
```
The tracking issue also mentions a `wrapping_` version but it has not been implemented.
Closes: #145686 (tracking issue, wrapping versions will need a new issue)
…r=nia-e
Stabilize `funnel_shifts` (including `const`)
`funnel_shl` and `funnel_shr` have been around for close to a year, the unchecked versions for a number of months. These are reasonably small and uncontroversial, and it can be tricky to get similar performance with a fallback; stabilize them here.
Newly stable API:
```rust
impl {u8, u16, u32, u64, u128, usize} {
pub const fn funnel_shl(self, right: Self, shift: u32) -> Self;
pub const fn funnel_shr(self, right: Self, shift: u32) -> Self;
pub const unsafe fn unchecked_funnel_shl(self, right: Self, shift: u32) -> Self;
pub const unsafe fn unchecked_funnel_shr(self, right: Self, shift: u32) -> Self;
}
```
The tracking issue also mentions a `wrapping_` version but it has not been implemented.
Closes: rust-lang#145686 (tracking issue, wrapping versions will need a new issue)
|
@bors retry yield to rollup |
|
❗ You can only retry pull requests that are approved and have a previously failed auto build. Hint: There is currently a pending auto build on this PR. To cancel it, run |
|
@bors yield ...? |
|
Auto build was cancelled. Cancelled workflows: The next pull request likely to be tested is #161015. |
|
⌛ Testing commit f7548dd with merge 5aeecdc... Workflow: https://github.com/rust-lang/rust/actions/runs/36521366415 |
Stabilize `funnel_shifts` (including `const`)
`funnel_shl` and `funnel_shr` have been around for close to a year, the unchecked versions for a number of months. These are reasonably small and uncontroversial, and it can be tricky to get similar performance with a fallback; stabilize them here.
Newly stable API:
```rust
impl {u8, u16, u32, u64, u128, usize} {
pub const fn funnel_shl(self, right: Self, shift: u32) -> Self;
pub const fn funnel_shr(self, right: Self, shift: u32) -> Self;
pub const unsafe fn unchecked_funnel_shl(self, right: Self, shift: u32) -> Self;
pub const unsafe fn unchecked_funnel_shr(self, right: Self, shift: u32) -> Self;
}
```
The tracking issue also mentions a `wrapping_` version but it has not been implemented.
Closes: #145686 (tracking issue, wrapping versions will need a new issue)
|
@bors yield to rollup |
|
Auto build was cancelled. Cancelled workflows: The next pull request likely to be tested is #163465. |
Rollup of 9 pull requests Successful merges: - #161015 (Stabilize `funnel_shifts` (including `const`)) - #161712 (Stabilize `Result::into_{ok,err}`) - #162493 (Add support for -Zsanitizer-cfi-minimal-runtime) - #163427 (implement #![feature(gca_adts)]) - #163390 (add `automatically_derived` attribute documentation) - #163428 (do not complain about unstable target features on nightly) - #163444 (Add `stable_rustc` helper in `run-make-support`) - #163447 (Allow using different index types when reading and writing to tables) - #163459 (Stabilize vec_try_remove)
Rollup of 9 pull requests Successful merges: - rust-lang/rust#161015 (Stabilize `funnel_shifts` (including `const`)) - rust-lang/rust#161712 (Stabilize `Result::into_{ok,err}`) - rust-lang/rust#162493 (Add support for -Zsanitizer-cfi-minimal-runtime) - rust-lang/rust#163427 (implement #![feature(gca_adts)]) - rust-lang/rust#163390 (add `automatically_derived` attribute documentation) - rust-lang/rust#163428 (do not complain about unstable target features on nightly) - rust-lang/rust#163444 (Add `stable_rustc` helper in `run-make-support`) - rust-lang/rust#163447 (Allow using different index types when reading and writing to tables) - rust-lang/rust#163459 (Stabilize vec_try_remove)
Rollup of 9 pull requests Successful merges: - rust-lang/rust#161015 (Stabilize `funnel_shifts` (including `const`)) - rust-lang/rust#161712 (Stabilize `Result::into_{ok,err}`) - rust-lang/rust#162493 (Add support for -Zsanitizer-cfi-minimal-runtime) - rust-lang/rust#163427 (implement #![feature(gca_adts)]) - rust-lang/rust#163390 (add `automatically_derived` attribute documentation) - rust-lang/rust#163428 (do not complain about unstable target features on nightly) - rust-lang/rust#163444 (Add `stable_rustc` helper in `run-make-support`) - rust-lang/rust#163447 (Allow using different index types when reading and writing to tables) - rust-lang/rust#163459 (Stabilize vec_try_remove)
Rollup of 9 pull requests Successful merges: - rust-lang/rust#161015 (Stabilize `funnel_shifts` (including `const`)) - rust-lang/rust#161712 (Stabilize `Result::into_{ok,err}`) - rust-lang/rust#162493 (Add support for -Zsanitizer-cfi-minimal-runtime) - rust-lang/rust#163427 (implement #![feature(gca_adts)]) - rust-lang/rust#163390 (add `automatically_derived` attribute documentation) - rust-lang/rust#163428 (do not complain about unstable target features on nightly) - rust-lang/rust#163444 (Add `stable_rustc` helper in `run-make-support`) - rust-lang/rust#163447 (Allow using different index types when reading and writing to tables) - rust-lang/rust#163459 (Stabilize vec_try_remove)
| #[rustc_const_unstable(feature = "funnel_shifts", issue = "145686")] | ||
| #[unstable(feature = "funnel_shifts", issue = "145686")] | ||
| #[track_caller] | ||
| #[rustc_allow_const_fn_unstable(const_trait_impl, core_intrinsics_fallbacks)] |
There was a problem hiding this comment.
I just realized that we should not have landed this. This allows core_intrinsics_fallbacks to use arbitrary unstable const things that will then be exposed on stable.
rustc_allow_const_fn_unstable should only be used for lang features, never for library features.
There was a problem hiding this comment.
There's still plenty of time to change/revert before it lands on stable on December 24.
There was a problem hiding this comment.
What's supposed to happen with core_intrinsics_fallbacks? It looks like this is the first case to use one of those traits.
There was a problem hiding this comment.
For non-trait fallbacks, what's supposed to happen is that all functions that can be called from stable are tagged #[rustc_const_stable_indirect]. That way we enforce recursive const stability through them.
#[rustc_const_stable_indirect] does not yet support traits. That will have to be fixed. It's not trivial because with traits we cannot in general know which function actually gets called. So we'll have to tag the trait method itself and then have to ensure that all impls are recursively const-checked.
There was a problem hiding this comment.
Were things working correctly before? Rotate has been const stable and it was using #[rustc_allow_const_fn_unstable(const_trait_impl, funnel_shifts)] prior to this PR. Maybe we could get away with something similar by moving the traits to core_intrinsics_funnel_shift_fallback to at least limit potential issues.
There was a problem hiding this comment.
(Note: the branch would be 12 November.)
There was a problem hiding this comment.
If anything we could revert the const stabilization. But I don't think this PR caused the issue, so reverting it wouldn't fix it anyway—we still need rustc_allow_const_fn_unstable(some_library_feature) to support the long-existing const stability of rotate_*, unless we effectively revert bc809be and reimplement in the compiler again.
But I don't think that's worth it if there's a reasonable policy to be reached here.
There was a problem hiding this comment.
Yeah I don't think we need to revert the stabilization, worst-case we add a native implementation.
There was a problem hiding this comment.
Zulip discussion: #t-compiler/const-eval > Const stability for intrinsic fallback bodies?
View all comments
funnel_shlandfunnel_shrhave been around for close to a year, the unchecked versions for a number of months. These are reasonably small and uncontroversial, and it can be tricky to get similar performance with a fallback; stabilize them here.Newly stable API:
The tracking issue also mentions a
wrapping_version but it has not been implemented.Closes: #145686 (tracking issue, wrapping versions will need a new issue)
This involves an intrinsic stabilization so needs FCP from both @rust-lang/lang and @rust-lang/libs-api.
@rustbot label +I-lang-nominated +I-libs-api-nominated
Cc others who have been involved: @RalfJung, @folkertdev, @sayantn
r? libs