Description
From #85122 (comment) and #85122 (comment).
After #120594 (1.78), unsafe precondition checks always apply under -Cdebug-assertions=y
, but there is currently no way to disable particular cases in debug builds:
They will make things too slow for somebody sooner or later -- it is not uncommon in projects to have a "fast debug" build where a few checks need to be explicitly bypassed in hot paths. And it is not just the branch/call itself, it can also break other optimizations like vectorization: https://godbolt.org/z/MMTordabn.
I really like the unsafe precondition checks, but I would like to make sure there is an escape hatch for
-Cdebug-assertions=y
builds. Perhaps we need acore::hint::unreachable_unchecked_even_in_debug
-like (even if it does not solve the "there is no checked API" case, but I don't know if that is an issue). For me,core::hint::unreachable_unchecked
was that in the past, and things likeunwrap_unchecked()
were the "checked in debug" ones.I also just noticed that using the intrinsic for slice indexing is not enough to remove the check in a debug build and get vectorization back (included in the link).