-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Less unsafe in dangling
/without_provenance
#135344
Conversation
r? @ibraheemdev rustbot has assigned @ibraheemdev. Use |
bb3: { | ||
StorageLive(_10); | ||
_10 = const {0x1 as *mut ()}; | ||
_9 = NonNull::<T>::new_unchecked::precondition_check(const {0x1 as *mut ()}) -> [return: bb4, unwind unreachable]; |
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.
annot: it was always impossible to trigger this UbCheck
-- there's no user value passed to Box<[_]>::default()
-- so having it here was just making rustc do more work for no reason.
(Similarly for <&[_]>::default()
and friends as well.)
0c7c016
to
c0d5988
Compare
This looks very good, great idea! @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Less unsafe in `dangling`/`without_provenance` This PR was inspired by the new `NonNull::without_provenance` (cc rust-lang#135243 (comment)) since it made me realize that we could write `NonNull::dangling` in completely-safe code using other existing things. Then doing that led me to a few more places that could be simplified, like now that GVN will optimize Transmute-then-PtrToPtr, we can just implement `ptr::without_provenance` by calling `ptr::without_provenance_mut` since the shipped rlib of `core` ends up with the same single statement as the implementation (thanks to GVN merging the steps) and thus there's no need to duplicate the `transmute` -- and more importantly, no need to repeat a long safety comment. There did end up being a couple of other changes needed to avoid exploding certain bits of MIR, though -- like `<Box<[i32]>>::default()`'s MIR originally got way worse as certain things didn't inline, or had a bunch of extraneous UbChecks -- so there's a couple of other changes to solve that.
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (f97ac68): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Instruction countThis is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.
Max RSS (memory usage)Results (primary 0.7%, secondary 2.4%)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.
CyclesResults (primary 1.6%, secondary -2.6%)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.
Binary sizeResults (primary 0.0%, secondary -1.1%)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.
Bootstrap: 763.089s -> 764.045s (0.13%) |
The perf change here looks like inlining churn to me, more than any substantial move one way or the other. Some losses, some wins on icounts, but not a ton of them. Both wins and losses for binary size in both debug and opt. The one primary regression has a very different codegen schedule: @bors r=joboet |
Less unsafe in `dangling`/`without_provenance` This PR was inspired by the new `NonNull::without_provenance` (cc rust-lang#135243 (comment)) since it made me realize that we could write `NonNull::dangling` in completely-safe code using other existing things. Then doing that led me to a few more places that could be simplified, like now that GVN will optimize Transmute-then-PtrToPtr, we can just implement `ptr::without_provenance` by calling `ptr::without_provenance_mut` since the shipped rlib of `core` ends up with the same single statement as the implementation (thanks to GVN merging the steps) and thus there's no need to duplicate the `transmute` -- and more importantly, no need to repeat a long safety comment. There did end up being a couple of other changes needed to avoid exploding certain bits of MIR, though -- like `<Box<[i32]>>::default()`'s MIR originally got way worse as certain things didn't inline, or had a bunch of extraneous UbChecks -- so there's a couple of other changes to solve that.
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
c0d5988
to
27be78c
Compare
This comment has been minimized.
This comment has been minimized.
Oops, CI failed |
This comment has been minimized.
This comment has been minimized.
27be78c
to
c18718c
Compare
Didn't change anything in the rebase but CI's passing now 🤷 @bors r=joboet |
⌛ Testing commit c18718c with merge d8a64098c9d0fb25699f657c6efff0bb418f7e18... |
☀️ Test successful - checks-actions |
Finished benchmarking commit (d8a6409): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowOur benchmarks found a performance regression caused by this PR. Next Steps:
@rustbot label: +perf-regression Instruction countThis is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.
Max RSS (memory usage)Results (primary 0.3%, secondary 1.2%)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.
CyclesResults (primary -0.0%, secondary -2.9%)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.
Binary sizeResults (primary -0.1%, secondary -1.1%)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.
Bootstrap: 764.032s -> 762.749s (-0.17%) |
} | ||
} | ||
scope 17 (inlined <Enumerate<std::slice::Iter<'_, T>> as IntoIterator>::into_iter) { | ||
scope 18 (inlined <Enumerate<std::slice::Iter<'_, T>> as IntoIterator>::into_iter) { |
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.
annot: note that there's no changes to the actual MIR blocks (statements/terminators) in any of these pre-codegen tests, just changes to which things ended up inlined along the way.
This PR was inspired by the new
NonNull::without_provenance
(cc #135243 (comment)) since it made me realize that we could writeNonNull::dangling
in completely-safe code using other existing things.Then doing that led me to a few more places that could be simplified, like now that GVN will optimize Transmute-then-PtrToPtr, we can just implement
ptr::without_provenance
by callingptr::without_provenance_mut
since the shipped rlib ofcore
ends up with the same single statement as the implementation (thanks to GVN merging the steps) and thus there's no need to duplicate thetransmute
-- and more importantly, no need to repeat a long safety comment.There did end up being a couple of other changes needed to avoid exploding certain bits of MIR, though -- like
<Box<[i32]>>::default()
's MIR originally got way worse as certain things didn't inline, or had a bunch of extraneous UbChecks -- so there's a couple of other changes to solve that.