Skip to content

Commit f8325ad

Browse files
committed
stdlib: let _precondition include the file+line info in debug builds.
For using the improved condfail messages in the stdlib, we need a function, like precondition(), just taking a StaticString instead of a String for the message. The existing (underscored) _precondition is a perfect fit for this, except that it's not printing the location info in debug builds. This change makes _precondition() equivalent to precondition, just taking a StaticString as argument. The other alternative would be to add another variant of precondition, just taking a StaticString. But we already have so many failure functions in Assert.swift, so adapting an existing one seems to be a better solution. This effectively undos a change from 5 years ago which intentionally removed the location info from _precondition (rdar://problem/16958193). But this was at a time where swift was not open source yet. So I think today it's okay to always add location information, even if it's from inside the stdlib. It can be even very useful for expert users for looking up the location the stdlib source.
1 parent e915300 commit f8325ad

File tree

1 file changed

+1
-29
lines changed

1 file changed

+1
-29
lines changed

stdlib/public/core/AssertCommon.swift

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -172,35 +172,7 @@ internal func _fatalErrorMessage(
172172
file: StaticString, line: UInt,
173173
flags: UInt32
174174
) -> Never {
175-
#if INTERNAL_CHECKS_ENABLED
176-
prefix.withUTF8Buffer() {
177-
(prefix) in
178-
message.withUTF8Buffer() {
179-
(message) in
180-
file.withUTF8Buffer() {
181-
(file) in
182-
_swift_stdlib_reportFatalErrorInFile(
183-
prefix.baseAddress!, CInt(prefix.count),
184-
message.baseAddress!, CInt(message.count),
185-
file.baseAddress!, CInt(file.count), UInt32(line),
186-
flags)
187-
}
188-
}
189-
}
190-
#else
191-
prefix.withUTF8Buffer() {
192-
(prefix) in
193-
message.withUTF8Buffer() {
194-
(message) in
195-
_swift_stdlib_reportFatalError(
196-
prefix.baseAddress!, CInt(prefix.count),
197-
message.baseAddress!, CInt(message.count),
198-
flags)
199-
}
200-
}
201-
#endif
202-
203-
Builtin.int_trap()
175+
_assertionFailure(prefix, message, file: file, line: line, flags: flags)
204176
}
205177

206178
/// Prints a fatal error message when an unimplemented initializer gets

0 commit comments

Comments
 (0)