Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue for `mem::unreachable` #43751
Comments
tbu-
referenced this issue
Aug 8, 2017
Merged
Put `intrinsics::unreachable` on a possible path to stabilization #43750
sfackler
added
B-unstable
T-libs
labels
Aug 8, 2017
This comment has been minimized.
This comment has been minimized.
|
Bikeshed: I find it surprising that safe |
This comment has been minimized.
This comment has been minimized.
|
Another possible name/location for discussion: |
This comment has been minimized.
This comment has been minimized.
|
This does not belong in Why not just call it |
This comment has been minimized.
This comment has been minimized.
|
There's a suggestion calling it |
This comment has been minimized.
This comment has been minimized.
|
I like @notriddle's suggestion. Does what it says on the tin. |
Mark-Simulacrum
added
the
C-tracking-issue
label
Aug 10, 2017
This comment has been minimized.
This comment has been minimized.
|
(Sorry, couldn't help myself) |
This comment has been minimized.
This comment has been minimized.
Except that, in most cases, it won't consume your clothes. Your computer probably doesn't even have the necessary hardware to do anything to your laundry. Undefined behaviour may eat your laundry, because it may do anything; the specification places no constraints on what the result of invoking this intrinsic is. A name like Unlike |
This comment has been minimized.
This comment has been minimized.
|
@notriddle Yep, I agree that (Context for those who came to this community after Rust 1.0: Before 1.0 there was a disclaimer on Rust's homepage saying something like it wasn't production ready yet, and could in theory do anything, including eating your laundry. I don't remember the exact wording.) |
This comment has been minimized.
This comment has been minimized.
earthengine
commented
Aug 18, 2017
|
I would say |
This comment has been minimized.
This comment has been minimized.
|
@earthengine |
This comment has been minimized.
This comment has been minimized.
earthengine
commented
Aug 18, 2017
|
Then make it inside |
This comment has been minimized.
This comment has been minimized.
|
Consider that another intrinsic, |
This comment has been minimized.
This comment has been minimized.
|
I propose that we simply stabilise the This would need some thinking on how to deal with the currently stable intrinsics in there:
|
This comment has been minimized.
This comment has been minimized.
|
Would (I thought about calling it |
This comment has been minimized.
This comment has been minimized.
|
For the currently-stable things in |
This comment has been minimized.
This comment has been minimized.
|
Although they are "stable" they cannot be used as such because importing
the intrinsics module trips the instability check – so a deprecation
doesn't seem necessary to me. At least some of them were made stable as an
implementation detail.
…On Aug 27, 2017 1:15 AM, "scottmcm" ***@***.***> wrote:
For the currently-stable things in intrinsics: Since they're all exported
elsewhere with (nearly?) identical signatures, just deprecate them with a
message suggesting the ptr or mem ones instead?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#43751 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AApc0mwJl8q9HWNO03KHl1ymOItRg7FDks5scJj1gaJpZM4OxZfV>
.
|
This comment has been minimized.
This comment has been minimized.
|
It doesn't actually trip the stability check, you can import them from intrinsics if you want even though they are re-exported elsewhere. So we could avoid creating another module. |
This comment has been minimized.
This comment has been minimized.
|
Do likely/unlikely also belong in the same category, that category that doesn't have a home in a current submodule? likely/unlikely: #26179 |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
( |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
I agree. Especially since their impact for being used incorrectly is simply UB. |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
Or that means |
This comment has been minimized.
This comment has been minimized.
|
I'm actually kinda okay with |
This comment has been minimized.
This comment has been minimized.
|
After some discussion on IRC and re-reading the earlier discussion, I actually don't see any reason to not stabilize |
This comment has been minimized.
This comment has been minimized.
I think it is the opposite, right? If one uses |
This comment has been minimized.
This comment has been minimized.
|
I think that something that has |
This comment has been minimized.
This comment has been minimized.
|
@SimonSapin I feel like that would make me never use |
This comment has been minimized.
This comment has been minimized.
|
You are welcome to use or not use whatever APIs you want. |
This comment has been minimized.
This comment has been minimized.
|
I mean, it's supposed to have a deterrent effect, as it should only be used
in really provably unreachable code, so... yeah.
…On Wed, Apr 18, 2018 at 12:35 PM, Steven Fackler ***@***.***> wrote:
You are welcome to use or not use whatever APIs you want.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#43751 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAC3n0dKOv8TqshD52G17jRIeP_OEzz4ks5tp2tQgaJpZM4OxZfV>
.
|
This comment has been minimized.
This comment has been minimized.
|
@mark-i-m Double negation is hard and I can’t tell what your "that" refers to. |
This comment has been minimized.
This comment has been minimized.
|
To clarify, what I mean is this: I generally prefer to leave asserts on in production, but there are a few asserts that I like to turn off in production. For those few asserts, I still want them on when I'm debugging. I consider While I'm debugging, if I don't want to risk UB. When I deploy, I'm confident enough that I'm willing to not have the assert. If I can't make that distinction cleanly, I'm unlike to ever use |
This comment has been minimized.
This comment has been minimized.
|
It sounds like you want to use https://crates.io/crates/debug_unreachable, and maybe there’s a case to be made to include it in the standard library but it shouldn’t be under the name |
This comment has been minimized.
This comment has been minimized.
|
… however just copying that code into libstd or libcore probably won’t work since the standard library is always compiled in release mode. |
This comment has been minimized.
This comment has been minimized.
|
@SimonSapin That's fair. Thanks :) |
This comment has been minimized.
This comment has been minimized.
|
I think @mark-i-m has raised a great point and we need to be more clear about what use cases we envision for
I sympathize with this and I struggle to think of reasonable use cases where I would prefer the current unconditionally unchecked unreachable over something like debug_unreachable. @SimonSapin or @sfackler do you have such a use case in mind? |
This comment has been minimized.
This comment has been minimized.
|
How would that be implemented? |
This comment has been minimized.
This comment has been minimized.
|
Possibly the same way |
This comment has been minimized.
This comment has been minimized.
|
We can do literally anything we want when undefined behavior happens so that's not a thing we need to explicitly guarantee. #45920 causes a trap to be generated from unreachable anyway, so you're already going to abort if an unreachable_unchecked is reached. |
This comment has been minimized.
This comment has been minimized.
|
Then it's just a difference between "unconditionally unchecked is the correct behavior for a function with this name, and if we want a debug checked version later we call it something else or recommend a thirdparty crate" vs "we wish we could check in debug mode but the standard library is not set up to be able to do that -- maybe later." You and Simon seem to have been supporting the former but maybe mark-i-m and I would prefer the latter. Is the trap as easily debuggable as a panic with stacktrace? |
This comment has been minimized.
This comment has been minimized.
|
Abort doesn't print a stack trace but I believe you can catch it in a
debugger.
…On Wed, Apr 18, 2018 at 4:14 PM, David Tolnay ***@***.***> wrote:
Then it's just a difference between "unconditionally unchecked is the
correct behavior for a function with this name, and if we want a debug
checked version later we call it something else or recommend a thirdparty
crate" vs "we wish we could check in debug mode but the standard library is
not set up to be able to do that -- maybe later." You and Simon seem to
have been supporting the former but maybe mark-i-m and I would prefer the
latter.
Is the trap as easily debuggable as a panic with stacktrace?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#43751 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAC3n_tCywRhtTIgSv7qKr2b20Z3_YIAks5tp56RgaJpZM4OxZfV>
.
|
This comment has been minimized.
This comment has been minimized.
|
Note that #45920 only kicks in at codegen time, optimizations based on the UB can still cause arbitrarily bad or confusing consequences. You might not even ever hit the unreachable -- if it is conditional, for example, the branch with the "unreachable" in it might be eliminated entirely. |
This comment has been minimized.
This comment has been minimized.
|
One reason for not panicking specifically is that it unwinds the stack, and the surrounding unsafe code might not be equipped to handle that. What if it immediately aborted and printed a stack trace in debug mode? |
This comment has been minimized.
This comment has been minimized.
It's not quite as nice. A trap will cause the program to be killed on a standard Linux setup. If you are running in GDB, then GDB will pause and you can use
I think I would be ok with pretty much anything, as long as the program halts and some debugging info is printed. |
This comment has been minimized.
This comment has been minimized.
|
Well if it's defined to trap it's not undefined, is it? And those "clever
UB optimizations" shouldn't happen in debug mode.
…On Wed, Apr 18, 2018 at 4:25 PM, Robin Kruppe ***@***.***> wrote:
Note that #45920 <#45920> only
kicks in at codegen time, optimizations based on the UB can still cause
arbitrarily bad or confusing consequences. You might not even ever hit the
unreachable -- if it is conditional, for example, the branch with the
"unreachable" in it might be eliminated entirely.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#43751 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAC3n89B_KPoilfOw6CqLzu442ctFS97ks5tp6EjgaJpZM4OxZfV>
.
|
This comment has been minimized.
This comment has been minimized.
|
I think that I was wrong, and that However I think that for the past three years the crate also hasn’t been doing what everyone thinks it’s doing, since it uses |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
It's undefined, period, codegen can just be configured is slightly mitigating the impact of any |
This comment has been minimized.
This comment has been minimized.
Yes but the call site is in libcore, which has already been compiled, so it won't do what you expect. That's why there are |
This comment has been minimized.
This comment has been minimized.
Undefined doesn't necessarily have to mean unpredictable. Technically, |
This comment has been minimized.
This comment has been minimized.
This is not true anymore if you factor compilers into the equation. Actual real-world programs don't segfault reliably when the programmer might think that it'd reliably execute the |
tbu- commentedAug 8, 2017
No description provided.