-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Typed throws] Support overrides that are contravariant in the thrown error #69839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
Adopt typed throws for the `map` operation to propagate thrown error types through the `map` API. This is done in a manner that is backward compatible for almost all cases: * The new typed-throws entrypoint is `@_alwaysEmitIntoClient` so it can back-deploy all the way back. * The old `rethrows` entrypoint is left in place, using `@usableFromInline` with `internal` so it is part of the ABI but not the public interface, and `@_disfavoredOverload` so the type checker avoids it while building the standard library itself. The old entrypoint is implemented in terms of the new one. Note that the implementation details for the existential collection "box" classes rely on method overriding of `_map` operations, and the types are frozen, so we don't get to change their signatures. However, these are only implementations, not API: the actual API `map` functions can be upgraded to typed throws. Note that this code makes use of a known hole in `rethrows` checking to allow calling between `rethrows` and typed throws. We'll need to do something about this for source-compatibility reasons, but I'll follow up with that separately.
Replace the hackish use of `@_disfavoredOverload` with the more principled use of `@_silgen_name` for the entrypoint we are maintaining, then rename these functions in source to `__rethrows_map` to indicate what they're for. While here, make them `throws` instead of `rethrows`. The ABI is the same, and `throws` allows us do avoid to do/catch tricks with rethrows functions.
…rows These class methods are internal, but because they are overridden and are part of a `@usableFromInline`, `@_fixed_layout` class, we they can't be moved over to typed throws without breaking ABI. However, they are only ever called from typed-throws functions, which already need a do...catch dance to downcast the error itself. Make them `throws` instead, which is ABI-compatible, but eliminates the need for do...catch hackery in the function itself.
When substitution into a function type with `throws(E)` produces either `throws(any Error)` or `throws(Never)`, adjust the resulting function type to the equivalent `throws` or non-throwing.
SIL opaque values do not yet support typed throws, so avoid the API that uses them.
@swift-ci please smoke test |
467e6d2
to
225360b
Compare
@swift-ci please smoke test |
225360b
to
07b26e2
Compare
@swift-ci please smoke test |
1 similar comment
@swift-ci please smoke test |
@swift-ci please smoke test Linux |
Whoops. I landed way more than I wanted to here, so I've reverted this PR and opened another with the intended functionality |
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.
No description provided.