[stdlib] refactor precondition() for consistency #64169
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The following simple function currently compiles differently in
-Ononemode than in-Oor-Osize:Compilation succeeds in
-Onone, and fails otherwise (with a missing return value error.)This is due to the implementation of
precondition()being@_transparent, and having two completely different implementations depending on whether it takes the_isDebugAssertConfiguration()branch or the_isReleaseAssertConfiguration()branch. The version ofprecondition()that is analyzed by the compiler after the mandatory inlining is simply different whether it occurs in debug mode or in release mode.In debug mode, the precondition's condition is explicitly used for flow control, and
_assertionFailureis called conditionally. In release mode, the precondition's condition result is saved in a variable, thenBuiltin.condfail_messageis called unconditionally. In the particular case show above, whereprecondition()is called with a constantfalseargument, this difference in approaches causes a compilation error in release mode that doesn't occur in debug mode.The solution is to use the condition for flow control before deciding on the specific way to trap.
Resolves rdar://106320129