-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SE-0276] Support multiple patterns in catch clauses #27776
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
Conversation
Updated to fix code completion tests, this now passes the test suite |
I'm a little uncomfortable with making Also, instead of using |
I'm not sure what benefit we'd get from having CatchStmt and CaseStmt continue to be different classes. They do exactly the same thing, just with different expectations about the incoming type. |
@jrose-apple There are a few cases where we need to check the @rintaro I agree that the |
7d0940a
to
6a6bc71
Compare
ad9a6d3
to
29a40d5
Compare
@swift-ci please test |
4267fb3
to
da8e73c
Compare
18449b8
to
b1aa6b8
Compare
@swift-ci please smoke test |
@swift-ci please test source compatibility |
@swift-ci build toolchain |
@DougGregor I guess I forgot to link them on this PR, swiftlang/llvm-project#538 and swiftlang/swift-syntax#190 are also required to build this. Sorry about that! |
swiftlang/llvm-project#538 @swift-ci please build toolchain |
swiftlang/llvm-project#538 @swift-ci please test source compatibility |
Thanks @theblixguy ! |
Linux Toolchain (Ubuntu 16.04) Install command |
Build failed |
For reference, the update above picks up changes from recent updates to function builders and the indentation implementation |
Build failed |
swiftlang/llvm-project#538 @swift-ci please test macOS |
Build failed |
swiftlang/llvm-project#538 @swift-ci please test macOS |
Build failed |
Looks like something in swift-syntax has fallen out of date. I’ll take a closer look tommorrow |
testing w/ updated swift-syntax PR swiftlang/llvm-project#538 @swift-ci please test |
Build failed |
swiftlang/llvm-project#538 @swift-ci please test macOS |
@rjmccall do you mind helping review the type checker and SILGen changes here as the original author of do-catch? |
Build failed |
My lldb patch seems to be out of date again, looking now |
Build failed |
On further investigation, the failures above may have just been infra issues. trying again: swiftlang/llvm-project#538 @swift-ci please test |
Like switch cases, a catch clause may now include a comma- separated list of patterns. The body will be executed if any one of those patterns is matched. This patch replaces `CatchStmt` with `CaseStmt` as the children of `DoCatchStmt` in the AST. This necessitates a number of changes throughout the compiler, including: - Parser & libsyntax support for the new syntax and AST structure - Typechecking of multi-pattern catches, including those which contain bindings. - SILGen support - Code completion updates - Profiler updates - Name lookup changes
f1f15ea
to
43e2d10
Compare
fixing profiler merge conflicts swiftlang/llvm-project#538 @swift-ci please test |
Build failed |
Build failed |
macOS failure looks like flakiness:
Windows failure is expected since it doesn't support cross-repo PR testing swiftlang/llvm-project#538 @swift-ci please test macOS platform |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really good! I have one comment where it looks like we have a lot of code duplication in the type checker between switch
and do-catch
, but we can clean that up in a follow-up PR.
|
||
auto clauses = S->getCatches(); | ||
CaseStmt *previousBlock = nullptr; | ||
for (auto i = clauses.begin(), e = clauses.end(); i != e; ++i) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code looks nearly identical to what's in visitSwitchStmt
. Can they be unified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think they can be if I refactor fallthrough handling a little. I'll look into that asap
@swift-ci please test source compatibility |
swiftlang/llvm-project#538 @swift-ci please test source compatibility |
// Since we know that we only have one case label item, grab its pattern | ||
// vars and use that to update expected with the right SILValue. | ||
// | ||
// TODO: Do we need a copy here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gottesmm Any thoughts on this TODO?
@owenv Also, can you update the ChangeLog in a follow-up PR? |
e.g.
do { ... } catch MyErr.a(let code), MyErr.b(let code) { ... }
The approach I took here was to get rid of
CatchStmt
entirely and reuseCaseStmt
inDoCatchStmt
. If anyone has time to take a look, I'd appreciate feedback on whether this seems like a good approach before I pitch this on the forums. Initially I tried keepingCatchStmt
around and just modifying it to holdCaseLabelItems
, but it resulted in a lot of code duplication in Sema and SILGen. This approach is cleaner overall, but there are still some rough edges (in the profiling code, for instance).Requires the following PRs for testing:
swiftlang/llvm-project#538
swiftlang/swift-syntax#190