Squash the Foundation and swift_willThrow backtraces together if we have both.#1537
Open
Squash the Foundation and swift_willThrow backtraces together if we have both.#1537
swift_willThrow backtraces together if we have both.#1537Conversation
… 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.
briancroom
reviewed
Feb 10, 2026
| } | ||
|
|
||
| #if !hasFeature(Embedded) && SWT_TARGET_OS_APPLE && !SWT_NO_DYNAMIC_LINKING | ||
| private static var _markerAddressBetweenSwiftWillThrowAndFoundation: Address { |
Contributor
Author
There was a problem hiding this comment.
Yeah I ended up not needing it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR does something a little weird: on Darwin, for
NSErrorinstances that are created (and thus have a backtrace captured by Foundation) and later thrown through Swift (and thus have one captured byswift_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:
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 theswift_willThrowbacktrace 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: