-
Notifications
You must be signed in to change notification settings - Fork 20
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::assume
#315
Comments
I prefer the name |
The |
So, |
I guess that works. I was so used to assume that I didn't even consider it. But we could slap an alias on it for anyone looking for assume. |
We discussed this in today's @rust-lang/libs-api meeting. We had consensus that we want this method, and ended up bikeshedding over the name. We also had consensus that we wanted |
If it's going to have Having I'll send a PR; we can always bikeshed in nightly. EDIT: Tracking issue rust-lang/rust#119131 |
Add `hint::assert_unchecked` 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: rust-lang#119131
Add `hint::assert_unchecked` 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: rust-lang/rust#119131
Can this ACP be closed since the feature was added? |
Add `hint::assert_unchecked` 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: rust-lang/rust#119131
Add `hint::assert_unchecked` 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: rust-lang/rust#119131
Proposal
Now that
hint::unreachable_unchecked()
is stable, people say things likewhen intentionally adding UB in certain paths.
We should just have
hint::assume(cond)
rather than making those people write outif !cond { hint::unreachable_unchecked() }
.assume
has its own gotchas, certainly, like how adding it can actually make things slower. But that's even more so the case for writing out the condition yourself, so I don't think that's a reason to not have a canonical way to write it.The canonical way could also expose implement it with https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/syntax/enum.NonDivergingIntrinsic.html#variant.Assume -- because that's what the
assume
intrinsic does already -- which is nicer in MIR than theif
phrasing since it doesn't split basic blocks.Solution sketch
Alternatives
unreachable_unchecked
.assume_unchecked
orassert_unchecked
. Butassume
is a long-standing name for this, so it's what I proposed. I'm fine to use whatever name libs-api would like best.unreachable_unchecked
and libs-api feels positive about things likeu32::unchecked_add
, I think having this fits with modern precedent .What happens now?
This issue contains an API change proposal (or ACP) and is part of the libs-api team feature lifecycle. Once this issue is filed, the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.
Possible responses
The libs team may respond in various different ways. First, the team will consider the problem (this doesn't require any concrete solution or alternatives to have been proposed):
Second, if there's a concrete solution:
The text was updated successfully, but these errors were encountered: