@@ -53,6 +53,23 @@ public func assert(
5353 }
5454}
5555
56+ #if $Embedded
57+ @_transparent
58+ public func assert(
59+ _ condition: @autoclosure ( ) -> Bool ,
60+ _ message: @autoclosure ( ) -> StaticString = StaticString ( ) ,
61+ file: StaticString = #file, line: UInt = #line
62+ ) {
63+ // Only assert in debug mode.
64+ if _isDebugAssertConfiguration ( ) {
65+ if !_fastPath( condition ( ) ) {
66+ _assertionFailure ( " Assertion failed " , message ( ) , file: file, line: line,
67+ flags: _fatalErrorFlags ( ) )
68+ }
69+ }
70+ }
71+ #endif
72+
5673/// Checks a necessary condition for making forward progress.
5774///
5875/// Use this function to detect conditions that must prevent the program from
@@ -100,6 +117,27 @@ public func precondition(
100117 }
101118}
102119
120+ #if $Embedded
121+ @_transparent
122+ public func precondition(
123+ _ condition: @autoclosure ( ) -> Bool ,
124+ _ message: @autoclosure ( ) -> StaticString = StaticString ( ) ,
125+ file: StaticString = #file, line: UInt = #line
126+ ) {
127+ // Only check in debug and release mode. In release mode just trap.
128+ if _isDebugAssertConfiguration ( ) {
129+ if !_fastPath( condition ( ) ) {
130+ _assertionFailure ( " Precondition failed " , message ( ) , file: file, line: line,
131+ flags: _fatalErrorFlags ( ) )
132+ }
133+ } else if _isReleaseAssertConfiguration ( ) {
134+ let error = !condition( )
135+ Builtin . condfail_message ( error. _value,
136+ StaticString ( " precondition failure " ) . unsafeRawPointer)
137+ }
138+ }
139+ #endif
140+
103141/// Indicates that an internal sanity check failed.
104142///
105143/// This function's effect varies depending on the build flag used:
@@ -137,6 +175,23 @@ public func assertionFailure(
137175 }
138176}
139177
178+ #if $Embedded
179+ @inlinable
180+ @inline ( __always)
181+ public func assertionFailure(
182+ _ message: @autoclosure ( ) -> StaticString = StaticString ( ) ,
183+ file: StaticString = #file, line: UInt = #line
184+ ) {
185+ if _isDebugAssertConfiguration ( ) {
186+ _assertionFailure ( " Fatal error " , message ( ) , file: file, line: line,
187+ flags: _fatalErrorFlags ( ) )
188+ }
189+ else if _isFastAssertConfiguration ( ) {
190+ _conditionallyUnreachable ( )
191+ }
192+ }
193+ #endif
194+
140195/// Indicates that a precondition was violated.
141196///
142197/// Use this function to stop the program when control flow can only reach the
@@ -164,7 +219,6 @@ public func assertionFailure(
164219/// where `preconditionFailure(_:file:line:)` is called.
165220/// - line: The line number to print along with `message`. The default is the
166221/// line number where `preconditionFailure(_:file:line:)` is called.
167- #if !$Embedded
168222@_transparent
169223@_unavailableInEmbedded
170224public func preconditionFailure(
@@ -181,7 +235,8 @@ public func preconditionFailure(
181235 }
182236 _conditionallyUnreachable ( )
183237}
184- #else
238+
239+ #if $Embedded
185240@_transparent
186241public func preconditionFailure(
187242 _ message: @autoclosure ( ) -> StaticString = StaticString ( ) ,
@@ -207,7 +262,6 @@ public func preconditionFailure(
207262/// where `fatalError(_:file:line:)` is called.
208263/// - line: The line number to print along with `message`. The default is the
209264/// line number where `fatalError(_:file:line:)` is called.
210- #if !$Embedded
211265@_transparent
212266@_unavailableInEmbedded
213267public func fatalError(
@@ -217,7 +271,8 @@ public func fatalError(
217271 _assertionFailure ( " Fatal error " , message ( ) , file: file, line: line,
218272 flags: _fatalErrorFlags ( ) )
219273}
220- #else
274+
275+ #if $Embedded
221276@_transparent
222277public func fatalError(
223278 _ message: @autoclosure ( ) -> StaticString = StaticString ( ) ,
0 commit comments