-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[ast]/[silgen] If a case stmt is a fallthrough source, tail allocate a pointer in the case stmt to the fallthrough case. #23284
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
[ast]/[silgen] If a case stmt is a fallthrough source, tail allocate a pointer in the case stmt to the fallthrough case. #23284
Conversation
…il allocated pointer field. rdar://47467128
I am mainly asking for review of the first commit. |
@swift-ci smoke test |
@@ -920,6 +922,45 @@ class CaseLabelItem { | |||
} | |||
}; | |||
|
|||
/// FallthroughStmt - The keyword "fallthrough". | |||
class FallthroughStmt : public Stmt { |
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.
There are no changes here to FallthroughStmt. I just ran into issues with my uses for it in CaseStmt and then discovered that I couldn't just use a forward declaration of it = /.
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.
*So I moved it above CaseStmt.
Since I based the logic on identifying fallthroughs on the logic in SILGenPattern, the actual output from SILGenPattern should be not changed at all so test updates were not needed. |
private llvm::TrailingObjects<CaseStmt, CaseLabelItem> { | ||
class CaseStmt final | ||
: public Stmt, | ||
private llvm::TrailingObjects<CaseStmt, FallthroughStmt *, |
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 decided to store the entire FallthroughStmt * rather than a pointer to the CaseStmt* returned from FallthroughStmt::getFallthroughDest(). This seems more flexible. That being said, I did not want to add it to the API surface, so I did not expose it directly.
@@ -943,24 +986,47 @@ class CaseStmt final : public Stmt, | |||
|
|||
llvm::PointerIntPair<Stmt *, 1, bool> BodyAndHasBoundDecls; | |||
|
|||
/// Set to true if we have a fallthrough. | |||
/// | |||
/// TODO: Once we have CaseBodyVarDecls, use the bit in BodyAndHasBoundDecls |
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.
To be clear here: HasBoundDecls is true iff we have CaseBodyVarDecls to my commit adding those will fix that. I just did not want to create a field called BodyAndHasBoundDeclsAndHasFallthrough
...
One last comment. I checked for other places that were using CaseStmt::create. This is the only call site AFAIKT that can have a fallthrough. This can be seen since FallthroughStmt are only created in the parser, never in sema. |
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.
Looks good apart from some nitpick and clarifying question.
…est() instead of computing this itself. rdar://47467128
91c34cc
to
7b27b4b
Compare
@swift-ci smoke test |
1 similar comment
@swift-ci smoke test |
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.
LGTM!
@swift-ci smoke test and merge |
I killed the two non smoke test and merge jobs that I triggered. |
The linux case failed b/c of 12:19:01 SwiftXCTestFunctionalTests :: Asynchronous/Expectations/main.swift I need to get around to fixing that. |
@swift-ci smoke test linux platform |
The second commit uses this in SILGenPattern in a trivial way to show that everything works.