-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Stabilize hint::assert_unchecked
#123588
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
Stabilize hint::assert_unchecked
#123588
Conversation
|
I don't think there is much purpose in keeping a separate r? libs-api |
This comment has been minimized.
This comment has been minimized.
7599168 to
29683ac
Compare
It doesn't? I think it always works, except that the person writing the post has to be an org member to ping org teams. (You can tell because the team doesn't get highlighted and linked if a non-org-member writes |
| /// /// `p` must be nonnull and valid | ||
| /// pub unsafe fn next_value(p: *const i32) -> i32 { | ||
| /// // SAFETY: caller invariants guarantee that `p` is not null | ||
| /// unsafe { hint::assert_unchecked(!p.is_null()) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like a pretty weird example. Do we not have something better? We even have to defend the example later in the documentation as being not real world.
One example that feels more illustrative is guaranteeing that the returned integer is in-bounds for some slice. For example, binary search tells LLVM that the indexes it returns are in-bounds of the length. Replicating binary search here probably is too much, but replicating a simpler algorithm (e.g., &[(u32, usize)] where you search for a particular needle and every usize is guaranteed to be an index in the array -- so before returning it you want to tell LLVM that) feels like a better example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't think there was much purpose in showing a real example of how it may be used in practice since we say elsewhere that you should only use this after benchmarking, and that a smarter optimizer may be able to figure it out at some point. So rather than showing an real usecase that might go away, I figured a dummy example of how it can actually affect codegen may be more useful.
But I am happy to change here as needed, maybe I can rework this example to make its intent more obvious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this example. It's not necessarily real world, but I do think it is effective at demonstrating the principle here in a pretty small and easily digestible code snippet.
Ah, I remember a couple of times when |
29683ac to
4f77927
Compare
|
☔ The latest upstream changes (presumably #104087) made this pull request unmergeable. Please resolve the merge conflicts. |
|
ping @BurntSushi Was your concern resolved by the documentation presented in this PR? |
| /// /// `p` must be nonnull and valid | ||
| /// pub unsafe fn next_value(p: *const i32) -> i32 { | ||
| /// // SAFETY: caller invariants guarantee that `p` is not null | ||
| /// unsafe { hint::assert_unchecked(!p.is_null()) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this example. It's not necessarily real world, but I do think it is effective at demonstrating the principle here in a pretty small and easily digestible code snippet.
|
@c410-f3r Yes, I'd be happy to resolve my concern once this is merged. |
|
Thanks @BurntSushi |
|
@BurntSushi Given that FCP is blocked on docs and this PR is open to both stabilize and resolve the concern, what would you prefer? Should the PR be split up such that docs can be merged, the concern resolved, and FCP started, or should the concern be lifted on the basis that it will be resolved at the same time as stabilization? I'd prefer the latter for simplicity. |
|
Ah this slipped my mind but is waiting on me, I’ll incorporate the feedback tomorrow. I think burntsushi said somehow that this PR is suitable to resolve the docs concern. @rustbot author |
|
Yeah I see the conflict here. I think when I was reviewing this, I thought this was just a doc update. Yes, in the future, I think that should be de-coupled from stabilization itself, otherwise we have a chicken & egg problem. Generally speaking, I'd like to see doc updates merged before resolving my concern. But I've resolved the concern in #119131. |
4f77927 to
75e0985
Compare
This comment has been minimized.
This comment has been minimized.
75e0985 to
3ec924c
Compare
Rearrange the sections and add an example to `core::hint::assert_unchecked`.
Make both `hint_assert_unchecked` and `const_hint_assert_unchecked` stable as `hint_assert_unchecked`.
3ec924c to
5745c22
Compare
|
I updated the docs based on the feedback. Since you have been pretty involved here, |
|
Oh whoops, forgot the important labels @rustbot ready |
dtolnay
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
|
@bors r+ |
Make the following API stable, including const:
This PR also reworks some of the documentation and adds an example.
Tracking issue: #119131
FCP: #119131 (comment). The docs update should resolve the remaining concern.