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

Add hint::assert_unchecked #119133

Merged
merged 1 commit into from Dec 26, 2023
Merged

Add hint::assert_unchecked #119133

merged 1 commit into from Dec 26, 2023

Conversation

scottmcm
Copy link
Member

Libs-API expressed interest, modulo bikeshedding, in rust-lang/libs-team#315 (comment)

I think that means this is good for nightly, since we can always rename it before stabilization.

Tracking issue: #119131

@rustbot
Copy link
Collaborator

rustbot commented Dec 19, 2023

r? @thomcc

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 19, 2023
@rust-log-analyzer

This comment has been minimized.

#[unstable(feature = "hint_assert_unchecked", issue = "119131")]
pub const unsafe fn assert_unchecked(cond: bool) {
// SAFETY: The caller promised this is true.
unsafe { crate::intrinsics::assume(cond) }
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to use assert_unsafe_precondition here like in other unchecked fns like unreachable_unchecked?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I suppose it should. Done.

@the8472
Copy link
Member

the8472 commented Dec 19, 2023

This could also point to unreachable_unchecked and recommend when to use which.

@scottmcm
Copy link
Member Author

@the8472 Sure
image

(The reciprocal mention will have to wait for stabilization.)

/// benefit to `let n = u32::count_ones(x); assert_unchecked(n <= u32::BITS);`.
///
/// If ever you're tempted to write `assert_unchecked(false)`, then you're
/// actually looking for [`unreachable_unchecked()`].
Copy link
Member

Choose a reason for hiding this comment

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

Is it worth mentioning that this is logically entirely equivalent to if !cond { unreachable_unchecked(); }?

@thomcc
Copy link
Member

thomcc commented Dec 26, 2023

I'm going to take the comment here as an implicit ACP+. It's unstable anyway, so if this was premature, no real damage done.

@bors r+

@bors
Copy link
Contributor

bors commented Dec 26, 2023

📌 Commit 7556d6f has been approved by thomcc

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 Dec 26, 2023
@bors
Copy link
Contributor

bors commented Dec 26, 2023

⌛ Testing commit 7556d6f with merge e1fadb2...

@bors
Copy link
Contributor

bors commented Dec 26, 2023

☀️ Test successful - checks-actions
Approved by: thomcc
Pushing e1fadb2 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 26, 2023
@bors bors merged commit e1fadb2 into rust-lang:master Dec 26, 2023
12 checks passed
@rustbot rustbot added this to the 1.77.0 milestone Dec 26, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (e1fadb2): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.4% [-3.7%, -3.1%] 2
All ❌✅ (primary) - - 0

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.3% [1.1%, 1.4%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.7% [-1.7%, -1.7%] 1
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 670.004s -> 670.607s (0.09%)
Artifact size: 312.52 MiB -> 312.44 MiB (-0.03%)

@scottmcm scottmcm deleted the assert-unchecked branch December 26, 2023 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants