Skip to content

Add contracts and autoharness for the unsigned funnel shifts - #822

Open
bardiharborow wants to merge 1 commit into
model-checking:mainfrom
bardiharborow:funnel-shift-contracts
Open

bardiharborow wants to merge 1 commit into
model-checking:mainfrom
bardiharborow:funnel-shift-contracts

Conversation

@bardiharborow

Copy link
Copy Markdown

unchecked_funnel_shl and unchecked_funnel_shr are public, stable (since 1.101.0) unsafe methods in core::num that had no contract and no proof. Add #[requires(n < <$ActualT>::BITS)] to both. This is the condition their assert_unsafe_precondition! checks and the one their documentation states, and unchecked_shl uses the same contract.

Verify both with autoharness for u8, u16, u32, u64, u128 and usize, over all inputs that satisfy the contract. The signed integer types do not have funnel shifts.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

`unchecked_funnel_shl` and `unchecked_funnel_shr` are public, stable
(since 1.101.0) unsafe methods in `core::num` that had no contract and
no proof. Add `#[requires(n < <$ActualT>::BITS)]` to both. This is the
condition their `assert_unsafe_precondition!` checks and the one their
documentation states, and `unchecked_shl` uses the same contract.

Verify both with autoharness for `u8`, `u16`, `u32`, `u64`, `u128` and
`usize`, over all inputs that satisfy the contract. The signed integer
types do not have funnel shifts.
@bardiharborow
bardiharborow requested a review from a team as a code owner December 4, 2026 18:48

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant