@@ -53,6 +53,23 @@ public func assert(
53
53
}
54
54
}
55
55
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
+
56
73
/// Checks a necessary condition for making forward progress.
57
74
///
58
75
/// Use this function to detect conditions that must prevent the program from
@@ -100,6 +117,27 @@ public func precondition(
100
117
}
101
118
}
102
119
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
+
103
141
/// Indicates that an internal sanity check failed.
104
142
///
105
143
/// This function's effect varies depending on the build flag used:
@@ -137,6 +175,23 @@ public func assertionFailure(
137
175
}
138
176
}
139
177
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
+
140
195
/// Indicates that a precondition was violated.
141
196
///
142
197
/// Use this function to stop the program when control flow can only reach the
@@ -164,7 +219,6 @@ public func assertionFailure(
164
219
/// where `preconditionFailure(_:file:line:)` is called.
165
220
/// - line: The line number to print along with `message`. The default is the
166
221
/// line number where `preconditionFailure(_:file:line:)` is called.
167
- #if !$Embedded
168
222
@_transparent
169
223
@_unavailableInEmbedded
170
224
public func preconditionFailure(
@@ -181,7 +235,8 @@ public func preconditionFailure(
181
235
}
182
236
_conditionallyUnreachable ( )
183
237
}
184
- #else
238
+
239
+ #if $Embedded
185
240
@_transparent
186
241
public func preconditionFailure(
187
242
_ message: @autoclosure ( ) -> StaticString = StaticString ( ) ,
@@ -207,7 +262,6 @@ public func preconditionFailure(
207
262
/// where `fatalError(_:file:line:)` is called.
208
263
/// - line: The line number to print along with `message`. The default is the
209
264
/// line number where `fatalError(_:file:line:)` is called.
210
- #if !$Embedded
211
265
@_transparent
212
266
@_unavailableInEmbedded
213
267
public func fatalError(
@@ -217,7 +271,8 @@ public func fatalError(
217
271
_assertionFailure ( " Fatal error " , message ( ) , file: file, line: line,
218
272
flags: _fatalErrorFlags ( ) )
219
273
}
220
- #else
274
+
275
+ #if $Embedded
221
276
@_transparent
222
277
public func fatalError(
223
278
_ message: @autoclosure ( ) -> StaticString = StaticString ( ) ,
0 commit comments