Repository navigation
Closed
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Milestone
Description
Feature gate: #![feature(unbounded_shifts)]
This is a tracking issue for ACP 428.
This adds shifts functions to the integer types that ignore type bounds when shifting, with out of range values for the rhs yielding the result of shifting the entire value out (0 for left shifts, and unsigned right shifts, and either 0 or -1 for signed right shifts).
Public API
impl uN{
pub const fn unbounded_shl(self, rhs: u32) -> Self;
pub const fn unbounded_shr(self, rhs: u32) -> Self;
}
impl iN{
pub const fn unbounded_shl(self, rhs: u32) -> Self;
pub const fn unbounded_shr(self, rhs: u32) -> Self;
}Steps / History
- Implementation: Add implementations for
unbounded_shl/unbounded_shr#129377 - Final comment period (FCP)1
- Stabilization PR Stabilize
unbounded_shifts#137393
Unresolved Questions
- None yet.
Footnotes
Reacted by Trevor Gross and Stepan Koltsov
Reacted by rodrimati1992, Alisa Sireneva, Matty Weatherley, Waterdragen, teor and José Luis Cruz
Metadata
Metadata
Assignees
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Activity
Rollup merge of rust-lang#129377 - chorman0773:unbounded-shifts-impl,…
Unrolled build for rust-lang#129377
joshtriplett commentedon Nov 12, 2024
This seems ready to stabilize.
@rfcbot merge
rfcbot commentedon Nov 12, 2024
Team member @joshtriplett 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!
See this document for info about what commands tagged team members can give me.
chorman0773 commentedon Nov 12, 2024
I was going to do a stabilization report.
Just to be clear, my intention was to stabilize it both as a function and as a
const fnin one shot, so team should keep that in mind during the pFCP.chorman0773 commentedon Dec 5, 2024
Stabilization Report
(Retroactive to pFCP)
Implementation History
unbounded_shl/unbounded_shr#129377Api Summary
unbounded_shlandunbounded_shrshiftsselfleft or right byrhsas though with unbounded range. Ifrhsexceeds the bounds of the type, the result is:unbounded_shl,0alwaysunbounded_shr,0for unsigned integers and either0or-1(depending on the sign bit)Experience Report
The Clever-ISA Project Emulator uses the nightly version of these functions to implement same-named functions in a primitive type wrapper. The wrapper functions (particularily
unbounded_shr) are then used throughout the emulator to compute a number of different bitmasks.scottmcm commentedon Jan 7, 2025
Big fan of stabilizing a canonical way to write "shift that actually works" 👍
(These are the only shifts where shifting by one N times is the same as shifting by N one time.)
rfcbot commentedon Feb 11, 2025
🔔 This is now entering its final comment period, as per the review above. 🔔
1 remaining item
rfcbot commentedon Feb 21, 2025
The final comment period, with a disposition to merge, as per the review above, is now complete.
As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.
This will be merged soon.
Rollup merge of rust-lang#137393 - chorman0773:unbounded-shifts-stabi…
Rollup merge of rust-lang#137393 - chorman0773:unbounded-shifts-stabi…
Unrolled build for rust-lang#137393
Rollup merge of rust-lang#137393 - chorman0773:unbounded-shifts-stabi…
Rollup merge of rust-lang#137393 - chorman0773:unbounded-shifts-stabi…
frozolotl commentedon May 15, 2025
This issue can be closed, no?
build(deps): update rust to v1.87.0
rust187: add a package for rust 1.87.0.
kupiakos commentedon Jul 11, 2025
I didn't see
saturating_shl/saturating_shrconsidered among the names. When one writeslhs.saturating_add(rhs), therhsisunboundedin the same manner - if the result of the operation would be an error, the value ofrhsis reduced to its largest value such that an error does not occur. The fullysaturatedresult ofshl/shris0/!0, like how it'sMIN/MAXfor overflow. I think it's at least as appropriate a name aswrapping_shl/wrapping_shr.saturating_shl/saturating_shrmethods to integers? It'd quickly deprecateunbounded_, which wouldn't be great.Shl<usize>/Shr<usize>be implemented onSaturating<T>that is backed byunbounded_shl/unbounded_shr, to mirrorimpl Shl<usize>/Shr<usize> for Wrapping<T>which forwards towrapping_?chorman0773 commentedon Jul 11, 2025
saturating_sh{l,r}were considered offline (also ACP 230 discusses them, but wasn't related to the original ACP). The reason the name wasn't initially proposed is because it's unclear whether it refers to the result or the input. A reasonable behaviour for1u32.saturating_shl(32)is to yield the value!0(which is what ACP 230 proposed, incidentally). Sayingunboundedis more clear, IMO. One thing that also stands out forunbounded_sh{l,r}is that a valid impl is:This is not the case for
saturating_addet. al.Edit; Also looks like 230 was accepted with the behaviour as specified, so there would be both behaviours available, I guess.