-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Typed throws #68629
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
Typed throws #68629
Conversation
a7187cf
to
b352be8
Compare
@swift-ci please smoke test |
Parse typed throw specifiers as `throws(X)` in every place where there are effects specified, and record the resulting thrown error type in the AST except the type system. This includes: * `FunctionTypeRepr`, for the parsed representation of types * `AbstractFunctionDecl`, for various function-like declarations * `ClosureExpr`, for closures * `ArrowExpr`, for parsing of types within expression context This also introduces some serialization logic for the thrown error type of function-like declarations, along with an API to extract the thrown interface type from one of those declarations, although right now it will either be `Error` or empty.
Add the thrown type into the AST representation of function types, mapping from function type representations and declarations into the appropriate thrown type. Add tests for serialization, printing, and basic equivalence of function types that have thrown errors.
… type Rather than always type-check the expression in a `throw` statement for conformance to `Error`, check that it converts to the thrown error type.
Enable typed throws on explicit closures, either due to contextual type information or due to explicit specification.
Lower the thrown error type into the SIL function type. This requires very little code because the thrown error type was already modeled as a SILResultInfo, which carries type information. Note that this lowering does not yet account for error types that need to passed indirectly, but we will need to do so for (e.g.) using resilient error types. Teach a few places in SIL generation not to assume that thrown types are always the existential error type, which primarily comes down to ensuring that rethrow epilogues have the thrown type of the corresponding function or closure. Teach throw emission to implicitly box concrete thrown errors in the error existential when needed to satisfy the throw destination. This is a temporary solution that helps translate typed throws into untyped throws, but it should be replaced by a better modeling within the AST of the points at which thrown errors are converted.
b352be8
to
1d976a3
Compare
@swift-ci please smoke test |
@swift-ci please smoke test |
@swift-ci please build toolchain |
Note: I'm looking to get this building cleanly and then merging it, since everything is behind an experimental flag and the next part is a major refactoring of the effects checker. |
(Note: toolchain builds aren't useful at this point, and were kicked off with the wrong settings because I meant to do that in a different PR. Those failures are meaningless) |
Witness checking and associated type inference was implemented in #69087 |
Subtyping implemented via #68995 |
Basic IR generation is in #68833 |
Improving effects checking in #69198 |
Infer |
Introduce upcoming feature |
Name mangling is coming in via #69471 |
SIL generation for generic thrown errors is coming in via #69430 |
Name mangling and runtime type metadata are in #69493 |
SIL generation for generic typed throws is working now, with #69767 being the last of the series of PRs. |
Fun in the standard library: #69771 |
Yet more SILGen thunking fun: #69791 |
Overrides: #69839 |
Silly me, overrides are going to land as #69922, but the code is done |
Start implementing typed throw specifiers with the syntax
throws(X)
. There are a large number of tasks involved in such a feature; this pull request covers the parsing and type checking aspects.throws(X)
as an effect specifier everywhere it is needed (functions, initializers, accessors, closures, function types, expressions that can become function types)throws
statements against the specified thrown type of functions/initializers/accessorsasync let
with typed throws