Skip to content

Squash the Foundation and swift_willThrow backtraces together if we have both.#1537

Open
grynspan wants to merge 1 commit intomainfrom
jgrynspan/170069880-splort-backtraces
Open

Squash the Foundation and swift_willThrow backtraces together if we have both.#1537
grynspan wants to merge 1 commit intomainfrom
jgrynspan/170069880-splort-backtraces

Conversation

@grynspan
Copy link
Contributor

@grynspan grynspan commented Feb 10, 2026

This PR does something a little weird: on Darwin, for NSError instances that are created (and thus have a backtrace captured by Foundation) and later thrown through Swift (and thus have one captured by swift_willThrow), squash them together to produce a combined franketrace.

We have no way to know at our layer which backtrace is more salient. In some cases, test authors want to see in Swift where an error originated, while in other cases that backtrace is heavily truncated and the source location down in Foundation is more useful.

So provide both?

If the two backtraces have a common suffix (likely if they occur in a synchronous call), we deduplicate it so that you end up with a backtrace that looks like:

SWIFT_WILLTHROW_BASED
SWIFT_WILLTHROW_BASED
SWIFT_WILLTHROW_BASED
FOUNDATION_BASED
FOUNDATION_BASED
COMMON
COMMON
COMMON
...

This actually makes sense when you see it, because you see a backtrace that shows the error being created and then being thrown.

If the two operations occur asynchronously in a way that doesn't use Swift concurrency (e.g. using a dispatch queue or good ol' NSThread), the backtraces likely won't have a common prefix of more than a few Mach-level symbols, so you end up with, chronologically, the Foundation backtrace followed by the swift_willThrow backtrace in a single array.

And finally, if only one backtrace or the other is available, you end up with that backtrace verbatim.

Resolves rdar://170081869.

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

… have both.

This PR does something a little weird: on Darwin, for `NSError` instances that
are created (and thus have a backtrace captured by Foundation) and later thrown
through Swift (and thus have one captured by `swift_willThrow`), squash them
together to produce a combined franketrace.

We have no way to know at our layer which backtrace is more salient. In some
cases, test authors want to see in Swift where an error originated, while in
other cases that backtrace is heavily truncated and the source location down in
Foundation is more useful.

So provide both?

If the two backtraces have a common suffix (likely if they occur in a
synchronous call), we deduplicate it so that you end up with a backtrace that
looks like:

```
SWIFT_WILLTHROW_BASED
SWIFT_WILLTHROW_BASED
SWIFT_WILLTHROW_BASED
FOUNDATION_BASED
FOUNDATION_BASED
COMMON
COMMON
COMMON
...
```

This actually makes sense when you see it, because you see a backtrace that
shows the error being created and then being thrown.

If the two operations occur asynchronously in a way that doesn't use Swift
concurrency (e.g. using a dispatch queue or good ol' `NSThread`), the backtraces
likely won't have a common prefix of more than a few Mach-level symbols, so you
end up with, chronologically, the Foundation backtrace followed by the
`swift_willThrow` backtrace in a single array.

And finally, if only one backtrace or the other is available, you end up with
that backtrace verbatim.

Resolves rdar://170069880.
@grynspan grynspan added this to the Swift 6.4.0 (main) milestone Feb 10, 2026
@grynspan grynspan self-assigned this Feb 10, 2026
@grynspan grynspan added the bug 🪲 Something isn't working label Feb 10, 2026
@grynspan grynspan added darwin 🍎 macOS, iOS, watchOS, tvOS, and visionOS support issue-handling Related to Issue handling within the testing library labels Feb 10, 2026
}

#if !hasFeature(Embedded) && SWT_TARGET_OS_APPLE && !SWT_NO_DYNAMIC_LINKING
private static var _markerAddressBetweenSwiftWillThrowAndFoundation: Address {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I ended up not needing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🪲 Something isn't working darwin 🍎 macOS, iOS, watchOS, tvOS, and visionOS support issue-handling Related to Issue handling within the testing library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants