Skip to content

Add support for capturing backtraces from typed throws. #642

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Sep 4, 2024

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented Aug 26, 2024

Swift 6 introduces the typed throws feature to replace rethrows and to support error handling in Embedded Swift. This feature uses an ABI that differs from the one used by untyped (traditional) throws and as such, our hook into the runtime (_swift_willThrow) is insufficient to provide backtrace information for errors thrown this way.

This PR adds support for capturing said backtraces if and only if the thrown error is of reference type. Such errors have stable addresses that we can track over time, whereas errors of value type will be copied when used with typed throws.

I'm also taking the opportunity to implement some performance enhancements to Backtrace. It shouldn't get called very frequently, but it also should be fast! This PR is dependent on #647.

Checklist:

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

@grynspan
Copy link
Contributor Author

@swift-ci please test

@grynspan
Copy link
Contributor Author

@swift-ci test

3 similar comments
@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan
Copy link
Contributor Author

Checking up on the status of swiftlang/swift#62985.

@grynspan
Copy link
Contributor Author

Yup. Windows is still cranky about weak referencing existential boxes.

@grynspan
Copy link
Contributor Author

@swift-ci test

1 similar comment
@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan grynspan added the performance Performance issues label Aug 28, 2024
@grynspan grynspan force-pushed the jgrynspan/typed-throws branch from d7a25a7 to 8133bd7 Compare August 28, 2024 15:08
@grynspan grynspan removed the performance Performance issues label Aug 28, 2024
@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan grynspan force-pushed the jgrynspan/typed-throws branch from 8133bd7 to c8cbbf0 Compare September 3, 2024 16:56
Swift 6 introduces the typed throws feature to replace `rethrows` and to support
error handling in Embedded Swift. This feature uses an ABI that differs from the
one used by untyped (traditional) `throws` and as such, our hook into the
runtime (`_swift_willThrows`) is insufficient to provide backtrace information
for errors thrown this way.

This PR adds support for capturing said backtraces _if and only if_ the thrown
error is of reference type. Such errors have stable addresses that we can track
over time, whereas errors of value type will be copied when used with typed
throws.
@grynspan grynspan force-pushed the jgrynspan/typed-throws branch from c8cbbf0 to 15ce720 Compare September 4, 2024 19:20
@grynspan
Copy link
Contributor Author

grynspan commented Sep 4, 2024

@swift-ci test

@grynspan grynspan merged commit 0ca9774 into main Sep 4, 2024
3 checks passed
@grynspan grynspan deleted the jgrynspan/typed-throws branch September 4, 2024 19:55
@grynspan grynspan added this to the Swift 6.1 milestone Sep 10, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants