-
Notifications
You must be signed in to change notification settings - Fork 441
Add keypath method and initializer syntax under an experimental feature flag keypathWithMethodMembers
#2950
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
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.
The implementation looks good to me. I have a few small comments inline.
Child( | ||
name: "leftParen", | ||
kind: .token(choices: [.token(.leftParen)]), | ||
isOptional: true | ||
), |
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.
Why is the left parenthesis optional? Wouldn’t we just have a normal member component if we don’t have parentheses?
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 modeled this after .funcCallExpr
but you're right and I will make this non optional. @ahoppen I also have 2 related questions:
.keyPathPropertyComponent
has a .genericArgumentClause
but I don't see any examples of it being used in the tests. Do you happen to know when that is used? It seems like a generic on the root (eg: \Box<Int>.item
) is already being handled by KeyPathExpr
.
Is there a way to make .labeledExprList
optional? I forgot to account for this - partially applied methods parse their method name and arg list into DeclReferenceExpr
and do not have a LabeledExprList
. I'm inclined to create a second node to handle this (eg: .keyPathPartiallyAppliedComponent
).
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.
.keyPathPropertyComponent
has a.genericArgumentClause
but I don't see any examples of it being used in the tests. Do you happen to know when that is used? It seems like a generic on the root (eg:\Box<Int>.item
) is already being handled byKeyPathExpr
.
I don’t think a generic clause is actually valid in key path properties and maybe we should remove it. @rintaro Can you think of a reason why KeyPathPropertyComponentSyntax
should have a generic arguments clause?
Is there a way to make
.labeledExprList
optional? I forgot to account for this - partially applied methods parse their method name and arg list intoDeclReferenceExpr
and do not have aLabeledExprList
. I'm inclined to create a second node to handle this (eg:.keyPathPartiallyAppliedComponent
).
I’m not sure I understand. If there are no parentheses, we should be able to parse the component as a KeyPathPropertyComponentSyntax
. If there are parentheses and no arguments, arguments
can just be an empty list. And if there are arguments … then it doesn’t need to be optional.
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’m not sure I understand. If there are no parentheses, we should be able to parse the component as a KeyPathPropertyComponentSyntax. If there are parentheses and no arguments, arguments can just be an empty list. And if there are arguments … then it doesn’t need to be optional.
Should partial arguments should also be KeyPathPropertyComponentSyntax? method(_:)
and method(arg:)
for unapplied keypath methods are being parsed as DeclReferenceExpr
with DeclNameArgumentListSyntax
arguments instead of LabeledExprList
. I have pushed changes that reflect this, unsure if there are any ramifications of doing it this way, but the Swift and c++ parser outputs match.
e0c6ccb
to
7762c01
Compare
dfa57bf
to
dd259f6
Compare
Added additional tests to ensure Swift and c++ parsers match. |
6cf481b
to
6790783
Compare
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.
That looks great and is much simpler as well. Just two minor comments, everything else is great.
6790783
to
fa3596e
Compare
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 to me 🚀
@swift-ci Please test |
Not sure why this test is failing - is it due to my imports in |
Oh, I just didn’t test it with your PR in the compiler repo. Let’s try again. @swift-ci Please test |
Looks like you need to rebase this PR + re-generate the sources to adjust it for #2926. |
fa3596e
to
5c3310a
Compare
Rebased and regenerated, but running into this failure locally:
|
Could you try if deleting |
@swift-ci Please test |
1 similar comment
@swift-ci Please test |
Yes, deleting Examples/.build fixed the issue locally. |
swiftlang/swift-foundation#1179 @swift-ci Please test windows platform. |
swiftlang/swift-foundation#1179 @swift-ci please test windows platform |
@ahoppen Unsure why the Windows platform test keeps failing. |
Because the tests that you added to the |
Are you able to share any failure output? I only see "Build finished. No test results found." and nothing is failing for me locally. |
The failing job was https://ci-external.swift.org/job/swift-syntax-PR-windows/4074/ with two test failures:
Seems like the difference is the lack of
That one is less obvious to me though - I don't see a |
646b14f
to
8b5df29
Compare
Thank you. The above tests should now pass, but I have a new test in the compiler that is failing due to this swift-syntax PR. Is there a way to suppress Parser diagnostics for all keypath methods and initializers so that invalid expressions are only caught and diagnosed in semantic analysis? This test preserving current diagnostics in the compiler fails as it forces me to add Parser diagnostics and expects the following instead:
I would like only the first semantic diagnostic. This test is missing the compiler experimental flag that is related to this feature. Can I add the swift-syntax changes in this PR without the swift-syntax experimental flag to prevent these diagnostics? @ahoppen @bnbarham |
You can add |
@bnbarham Would it be |
Yeah, that should definitely work 🤔. Locally I see eg.
And then:
|
Still getting errors. I also tried the expanded version. Could the experimental flags be causing issues here?
|
What are the errors you’re seeing now? It might be easiest if you could push your latest revisions. |
My mistake: I have no idea what I was doing before but this test now passes! Running CI now... |
@swift-ci Please test. |
Unsure if I'm looking at the correct part of the failure output for the Windows test, but I don't see any failed tests. I see this:
but I'm unsure how to fix this. Do I need to rebase llvm or clang? @ahoppen |
That’s an unrelated test failure which was fixed by swiftlang/llvm-project#10189. Let’s try again @swift-ci Please test Windows |
Do update-checkout errors need a rebase? I'm now seeing:
|
No, seems to be some infrastructure issue. Let’s try again. And sorry for those unrelated CI failures. @swift-ci Please test Windows |
Oh, we forgot to link the compiler PR. @swift-ci Please test Windows. |
@swift-ci Please test Windows. |
1 similar comment
@swift-ci Please test Windows. |
This accompanies the swift-foundation and compiler implementation for Method and Initializer Keypaths which extends keypath usage to include references to methods and initializers: