-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
rename debug_assert_nounwind → debug_assert_ubcheck #121583
Conversation
Now it's not necessarily outlined, it can be inlined by LLVM (and really, I see no reason for these two macros to have different behavior in that regard). So now the distinctive feature is whether it's executed by CTFE (which, even with the const_eval_select semantics nonsense sorted out, is probably still useful for CTFE performance). I'm not sure what to best name that though. |
Both are in an |
That would mean such checks would always fail in const eval, so doesn't that introduce an implicit reliance on not actually using those functions in const eval? I'd prefer to reduce the amount of manual coordination required in here if possible, and I think this proposal would increase it, right? I'm happy to approve a rename, because the current name is Quite Bad. I should have renamed this when I changed the implementation. I've been thinking about what the right design is but I'm not sure of a solution yet so you're just getting my mental notes. Maybe you want to do something with them, if not I'll do something later. I think the structure with The odd syntax used by There are two variants of checks here; we have checks that should be enabled in CTFE/Miri and at runtime, and checks which should only be enabled at runtime. Adding a second intrinsic for this would duplicate a lot of work elsewhere in the compiler. Maybe we can just add a boolean argument to the intrinsic? Or a two-variant enum? Then one version of the checks is: if intrinsics::debug_asertions(Always) {
precondition_check($($arg,)*); and the other is if intrinsics::debug_assertions(OnlyRuntime) {
const_eval_select(($(arg,)*), comptime, precondition_check);
} |
Eh, sorry, I meant always return
So that's
Yes that makes sense. To propose a different color for our bikeshed though, I'd name the enum after the goal, not the mechanism, otherwise people are not going to know what they are supposed to do. So e.g., That also makes me wonder whether |
Yes. |
Okay in that case this PR is moot I guess, since the macro it renames is going to disappear. I'm happy to close it and let you take care of unifying the two macros. :) |
…=<try> Distinguish between library and lang UB in assert_unsafe_precondition As described in rust-lang#121583 (comment), `assert_unsafe_precondition` now explicitly distinguishes between language UB (conditions we explicitly optimize on) and library UB (things we document you shouldn't do, and maybe some library internals assume you don't do). `debug_assert_nounwind` was originally added to avoid the "only at runtime" aspect of `assert_unsafe_precondition`. Since then the difference between the macros has gotten muddied. This totally revamps the situation. Now _all_ preconditions shall be checked with `assert_unsafe_precondition`. If you have a precondition that's only checkable at runtime, do a `const_eval_select` hack, as done in this PR. r? RalfJung
Closing in favor of #121662. |
…=RalfJung Distinguish between library and lang UB in assert_unsafe_precondition As described in rust-lang#121583 (comment), `assert_unsafe_precondition` now explicitly distinguishes between language UB (conditions we explicitly optimize on) and library UB (things we document you shouldn't do, and maybe some library internals assume you don't do). `debug_assert_nounwind` was originally added to avoid the "only at runtime" aspect of `assert_unsafe_precondition`. Since then the difference between the macros has gotten muddied. This totally revamps the situation. Now _all_ preconditions shall be checked with `assert_unsafe_precondition`. If you have a precondition that's only checkable at runtime, do a `const_eval_select` hack, as done in this PR. r? RalfJung
…=RalfJung Distinguish between library and lang UB in assert_unsafe_precondition As described in rust-lang#121583 (comment), `assert_unsafe_precondition` now explicitly distinguishes between language UB (conditions we explicitly optimize on) and library UB (things we document you shouldn't do, and maybe some library internals assume you don't do). `debug_assert_nounwind` was originally added to avoid the "only at runtime" aspect of `assert_unsafe_precondition`. Since then the difference between the macros has gotten muddied. This totally revamps the situation. Now _all_ preconditions shall be checked with `assert_unsafe_precondition`. If you have a precondition that's only checkable at runtime, do a `const_eval_select` hack, as done in this PR. r? RalfJung
Distinguish between library and lang UB in assert_unsafe_precondition As described in rust-lang/rust#121583 (comment), `assert_unsafe_precondition` now explicitly distinguishes between language UB (conditions we explicitly optimize on) and library UB (things we document you shouldn't do, and maybe some library internals assume you don't do). `debug_assert_nounwind` was originally added to avoid the "only at runtime" aspect of `assert_unsafe_precondition`. Since then the difference between the macros has gotten muddied. This totally revamps the situation. Now _all_ preconditions shall be checked with `assert_unsafe_precondition`. If you have a precondition that's only checkable at runtime, do a `const_eval_select` hack, as done in this PR. r? RalfJung
Distinguish between library and lang UB in assert_unsafe_precondition As described in rust-lang/rust#121583 (comment), `assert_unsafe_precondition` now explicitly distinguishes between language UB (conditions we explicitly optimize on) and library UB (things we document you shouldn't do, and maybe some library internals assume you don't do). `debug_assert_nounwind` was originally added to avoid the "only at runtime" aspect of `assert_unsafe_precondition`. Since then the difference between the macros has gotten muddied. This totally revamps the situation. Now _all_ preconditions shall be checked with `assert_unsafe_precondition`. If you have a precondition that's only checkable at runtime, do a `const_eval_select` hack, as done in this PR. r? RalfJung
Distinguish between library and lang UB in assert_unsafe_precondition As described in rust-lang/rust#121583 (comment), `assert_unsafe_precondition` now explicitly distinguishes between language UB (conditions we explicitly optimize on) and library UB (things we document you shouldn't do, and maybe some library internals assume you don't do). `debug_assert_nounwind` was originally added to avoid the "only at runtime" aspect of `assert_unsafe_precondition`. Since then the difference between the macros has gotten muddied. This totally revamps the situation. Now _all_ preconditions shall be checked with `assert_unsafe_precondition`. If you have a precondition that's only checkable at runtime, do a `const_eval_select` hack, as done in this PR. r? RalfJung
This captures its changed meaning since #120863 a bit better.
However, the naming of
debug_assert_ubcheck
vsassert_unsafe_precondition
is still unclear. Both are guarded byintrinsics::debug_assertions
, the main difference is whether the check needs to be const-compatible and whether it is being outlined. So maybeassert_unsafe_precondition
should be renamed todebug_assert_ubcheck_outline
? Is the outlining even desirable? If we can makeis_aligned_and_not_null
andis_nonoverlapping
const-compatible (e.g. by using const_eval_select inside them and making them always returnfalse
true
), then we could usedebug_assert_ubcheck
everywhere.r? @saethlin