Skip to content

Commit e100413

Browse files
committed
Disable backtrace capturing in Embedded Swift.
This PR disables the bulk of the backtrace-capturing-on-error logic when building for Embedded Swift. At least for the moment, we can't deal with error existentials in Embedded Swift, so this code won't function correctly even if it successfully compiles.
1 parent ee0ba8c commit e100413

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Sources/Testing/SourceAttribution/Backtrace.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ extension Backtrace: Codable {
119119
// MARK: - Backtraces for thrown errors
120120

121121
extension Backtrace {
122+
#if !hasFeature(Embedded)
122123
// MARK: - Error cache keys
123124

124125
/// A type used as a cache key that uniquely identifies error existential
@@ -321,6 +322,7 @@ extension Backtrace {
321322
}
322323
forward(errorType)
323324
}
325+
#endif
324326

325327
/// Whether or not Foundation provides a function that triggers the capture of
326328
/// backtaces when instances of `NSError` or `CFError` are created.
@@ -336,7 +338,7 @@ extension Backtrace {
336338
/// - Note: The underlying Foundation function is called (if present) the
337339
/// first time the value of this property is read.
338340
static let isFoundationCaptureEnabled = {
339-
#if _runtime(_ObjC) && !SWT_NO_DYNAMIC_LINKING
341+
#if !hasFeature(Embedded) && _runtime(_ObjC) && !SWT_NO_DYNAMIC_LINKING
340342
if Environment.flag(named: "SWT_FOUNDATION_ERROR_BACKTRACING_ENABLED") == true {
341343
let _CFErrorSetCallStackCaptureEnabled = symbol(named: "_CFErrorSetCallStackCaptureEnabled").map {
342344
castCFunction(at: $0, to: (@convention(c) (DarwinBoolean) -> DarwinBoolean).self)
@@ -348,6 +350,7 @@ extension Backtrace {
348350
return false
349351
}()
350352

353+
#if !hasFeature(Embedded)
351354
/// The implementation of ``Backtrace/startCachingForThrownErrors()``, run
352355
/// only once.
353356
///
@@ -373,6 +376,7 @@ extension Backtrace {
373376
}
374377
}
375378
}()
379+
#endif
376380

377381
/// Configure the Swift runtime to allow capturing backtraces when errors are
378382
/// thrown.
@@ -381,17 +385,21 @@ extension Backtrace {
381385
/// developer-supplied code to ensure that thrown errors' backtraces are
382386
/// always captured.
383387
static func startCachingForThrownErrors() {
388+
#if !hasFeature(Embedded)
384389
__SWIFT_TESTING_IS_CAPTURING_A_BACKTRACE_FOR_A_THROWN_ERROR__
390+
#endif
385391
}
386392

387393
/// Flush stale entries from the error-mapping cache.
388394
///
389395
/// Call this function periodically to ensure that errors do not continue to
390396
/// take up space in the cache after they have been deinitialized.
391397
static func flushThrownErrorCache() {
398+
#if !hasFeature(Embedded)
392399
_errorMappingCache.withLock { cache in
393400
cache = cache.filter { $0.value.errorObject != nil }
394401
}
402+
#endif
395403
}
396404

397405
/// Initialize an instance of this type with the previously-cached backtrace
@@ -411,6 +419,7 @@ extension Backtrace {
411419
/// initializer cannot be made an instance method or property of `Error`
412420
/// because doing so will cause Swift-native errors to be unboxed into
413421
/// existential containers with different addresses.
422+
#if !hasFeature(Embedded)
414423
@inline(never)
415424
init?(forFirstThrowOf error: any Error, checkFoundation: Bool = true) {
416425
if checkFoundation && Self.isFoundationCaptureEnabled,
@@ -430,4 +439,9 @@ extension Backtrace {
430439
return nil
431440
}
432441
}
442+
#else
443+
init?(forFirstThrowOf error: some Error, checkFoundation: Bool = true) {
444+
return nil
445+
}
446+
#endif
433447
}

0 commit comments

Comments
 (0)