-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
assert_unsafe_precondition!
: assume()
the expression
#106220
Conversation
r? @m-ou-se (rustbot has picked a reviewer for you, use r? to override) |
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
40dc027
to
5074f33
Compare
This may help the compiler to get some facts about the code and thus optimize it better. It may however have an effect on compile times
5074f33
to
ac83eee
Compare
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
⌛ Trying commit ac83eee with merge e67894d5ec350dea8f428c3445622a197639cdd1... |
FWIW I tried this already: https://rust-lang.zulipchat.com/#narrow/stream/187780-t-compiler.2Fwg-llvm/topic/.E2.9C.94.20codegen.20regression.20from.20intrinsics.3A.3Aunreachable.2Fllvm.2Eas.2E.2E.2E But that was with a previous LLVM and a different implementation of Not to open another can of worms, but if this PR regresses compile time, consider adding this change: #105435 |
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (e67894d5ec350dea8f428c3445622a197639cdd1): comparison URL. Overall result: ❌ regressions - ACTION NEEDEDBenchmarking 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 a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis 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.
CyclesResultsThis 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.
|
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.
Other than the suggestion I've made on the code itself, could you also update the macro's documentation to reflect this change? It currently states (in multiple places) that it only has an effect if debug_assertions
are on, whereas now the compiler may assume that the precondition holds even if debug_assertions
are off (and indeed it is now immediate UB if the precondition does not hold, whereas before the safety issue was due to the more subtle differences between compile-time and run-time evaluations).
} | ||
} else { | ||
// SAFETY: the caller must ensure this | ||
unsafe { $crate::intrinsics::assume($e) }; |
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.
The macro should only be invoked from unsafe
contexts, so this explicit unsafe
block is superfluous (and indeed potentially harmful, as it could introduce UB if the macro is accidentally invoked from a safe context).
unsafe { $crate::intrinsics::assume($e) }; | |
$crate::intrinsics::assume($e); |
Based on the perf run, I'm not sure we have any evidence this is helpful. The few improvements are in externs which might just be noise, and the rest are in CTFE and the breakdown for those is all over the place. Can you come up with a demonstration of some code that is optimized better with this change? |
Closing this as there seems to be no gain or interest in this. |
This may help the compiler to get some facts about the code and thus optimize it better.
It may however have an effect on compile times