Skip to content
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

Add a macro for "unreachable" whose meaning differs in debug and release builds #18152

Closed
kmcallister opened this Issue Oct 19, 2014 · 5 comments

Comments

Projects
None yet
4 participants
@kmcallister
Copy link
Contributor

kmcallister commented Oct 19, 2014

In debug builds it means "I think we can't get here, please fail!() if we do", i.e. the same as the current unreachable!().

In release builds it means "I promise we can't get here, LLVM, you are free to do absolutely anything if we can", i.e. intrinsics::unreachable().

Improper use can totally break memory safety in release builds, so we should make it unsafe-only even in debug builds. For the same reason I don't think the current unreachable!() should change meaning to this. I don't have a great alternative name, which I think is the main obstacle with this ticket!

E-easy E-bikeshed :)

@vojtechkral

This comment has been minimized.

Copy link
Contributor

vojtechkral commented Nov 20, 2014

OTOH, if unreachable!() were made unsafe, existing code using it (potentialy incorrectly) would not compile, right? The meaning could be changed and for the "original" purpose an assert could be created, eg. assert_unreachable!() ... which admitedly wouldn't be much different from assert!(false, "..."), but conveys the intent much more clearly.

@smaudet

This comment has been minimized.

Copy link

smaudet commented Jan 8, 2015

Anyone mind if I take a look at this?

@kmcallister

This comment has been minimized.

Copy link
Contributor Author

kmcallister commented Jan 8, 2015

Perhaps it should be debug_unreachable!() by analogy with debug_assert!() and the like. It has the same meaning of "unchecked in release builds".

@vojtechkral

This comment has been minimized.

Copy link
Contributor

vojtechkral commented Jan 11, 2015

This doesn't require an RFC? @kmcallister

edit: @smaudet I'm having a look at it if that's alright by you??? 😁

vojtechkral added a commit to vojtechkral/rust that referenced this issue Jan 12, 2015

Add a macro named optimize_unreachable!()
that combines std::unreachable!() and std::intrinsics::unreachable()
In a debug build, it forwards to std::unreachable!(), panics when reached.
In an ndebug build, evaluates to std::intrinsics::unreachable()
to enable optimizations. Unsafe in both cases.

Fixes rust-lang#18152
@steveklabnik

This comment has been minimized.

Copy link
Member

steveklabnik commented Jan 21, 2015

I'm pulling a massive triage effort to get us ready for 1.0. As part of this, I'm moving stuff that's wishlist-like to the RFCs repo, as that's where major new things should get discussed/prioritized.

This issue has been moved to the RFCs repo: rust-lang/rfcs#698

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.