Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 11 additions & 31 deletions stdlib/public/core/Assert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public func assert(
/// execution in a debuggable state after printing `message`.
///
/// * In `-O` builds (the default for Xcode's Release configuration): If
/// `condition` evaluates to `false`, stop program execution.
/// `condition` evaluates to `false`, stop program execution after printing `message`.
///
/// * In `-Ounchecked` builds, `condition` is not evaluated, but the optimizer
/// may assume that it *always* evaluates to `true`. Failure to satisfy that
Expand All @@ -108,16 +108,9 @@ public func precondition(
_ message: @autoclosure () -> String = String(),
file: StaticString = #file, line: UInt = #line
) {
// Only check in debug and release mode. In release mode just trap.
if _isDebugAssertConfiguration() {
if !_fastPath(condition()) {
_assertionFailure("Precondition failed", message(), file: file, line: line,
flags: _fatalErrorFlags())
}
} else if _isReleaseAssertConfiguration() {
let error = !condition()
Builtin.condfail_message(error._value,
StaticString("precondition failure").unsafeRawPointer)
if !_fastPath(condition()) {
_assertionFailure("Precondition failed", message(), file: file, line: line,
flags: _fatalErrorFlags())
}
}

Expand Down Expand Up @@ -212,7 +205,7 @@ public func assertionFailure(
/// printing `message`.
///
/// * In `-O` builds (the default for Xcode's Release configuration), stops
/// program execution.
/// program execution after printing `message`.
///
/// * In `-Ounchecked` builds, the optimizer may assume that this function is
/// never called. Failure to satisfy that assumption is a serious
Expand All @@ -233,14 +226,8 @@ public func preconditionFailure(
_ message: @autoclosure () -> String = String(),
file: StaticString = #file, line: UInt = #line
) -> Never {
// Only check in debug and release mode. In release mode just trap.
if _isDebugAssertConfiguration() {
_assertionFailure("Fatal error", message(), file: file, line: line,
flags: _fatalErrorFlags())
} else if _isReleaseAssertConfiguration() {
Builtin.condfail_message(true._value,
StaticString("precondition failure").unsafeRawPointer)
}
_assertionFailure("Fatal error", message(), file: file, line: line,
flags: _fatalErrorFlags())
_conditionallyUnreachable()
}

Expand Down Expand Up @@ -313,23 +300,16 @@ public func fatalError(
/// Library precondition checks.
///
/// Library precondition checks are enabled in debug mode and release mode. When
/// building in fast mode they are disabled. In release mode they don't print
/// an error message but just trap. In debug mode they print an error message
/// building in fast mode they are disabled. They print an error message
/// and abort.
@usableFromInline @_transparent
internal func _precondition(
_ condition: @autoclosure () -> Bool, _ message: StaticString = StaticString(),
file: StaticString = #file, line: UInt = #line
) {
// Only check in debug and release mode. In release mode just trap.
if _isDebugAssertConfiguration() {
if !_fastPath(condition()) {
_assertionFailure("Fatal error", message, file: file, line: line,
flags: _fatalErrorFlags())
}
} else if _isReleaseAssertConfiguration() {
let error = !condition()
Builtin.condfail_message(error._value, message.unsafeRawPointer)
if !_fastPath(condition()) {
_assertionFailure("Fatal error", message, file: file, line: line,
flags: _fatalErrorFlags())
}
}

Expand Down