-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
[Parser] Cleans up parsing of function parameter attributes #1812
Conversation
@swift-ci Please smoke test |
@lattner can you review this change? |
Yes, I'll review it, hopefully tomorrow. |
@lattner or @tkremenek can you please run the tests again? I fixed all the ones that were failing and squashed to a single commit. |
@swift-ci please test |
|
||
// ('inout' | 'let')? | ||
bool hasSpecifier = false; | ||
while (Tok.isAny(tok::kw_inout, tok::kw_let, tok::kw_var)) { |
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 why you changed the comment here, given that kw_var is still accepted.
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.
We check for kw_var to give the warning but the code would be invalid if var was still there. I'm not sure whether the comment is supposed to reflect what's valid or what's checked for.
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'd prefer to have the in-function comments correlate to the code. It makes sense to keep the comments at the top of the function aligned with the formal grammar.
I made a few comments above, the test failures seem spurious. |
@lattner I changed it so that the 'var' detection now happens in sema, and provides a nifty fixit to place a shadow copy. I tried to make it so that indentation would work too, but tbh I'm not completely sure that's the right way. I also fixed the comments, and the test case with the let/var diff, I moved it to another test case because the diagnostic was not getting a chance to run because of all the other errors in the file. |
@swift-ci please test |
ERROR(parameter_let_as_attr,none, | ||
"'let' before a parameter type is not allowed, place it before the parameter name instead", ()) | ||
ERROR(parameter_var_as_attr,none, | ||
"'var' as a parameter attribute is not allowed, consider creating a shadow copy in the function body or using 'inout' for pass-by-reference", ()) |
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.
Please indent the "'var... line to match the placement of the "(parameter_var_as_attr" on the previous line. Similarly, please de-indent the "'let' before ... " line a few lines above.
Detailed comments in the patch. This is looking great, thank you for working on this! |
To confirm, SE-0053 is accepted. |
I think we should warn/error on them with migration away from the syntax where possible. That said, we shouldn't bother with this if they occur after the colon, since that is not syntax we have ever accepted. |
@swift-ci please test |
The test failure is a win: you fixed a crasher :-) |
Unfortunately, it still crashes with the inout moved to the right location. |
Yep, please, and remove the --crash from the run line. Thanks! |
Ok, reviewing the patch now. |
"parameter may not have multiple 'inout', 'var', or 'let' specifiers", | ||
()) | ||
ERROR(parameter_let_as_attr,none, | ||
"'let' as a parameter attribute is not allowed", (bool)) | ||
|
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 (bool) parameter is not used and is always false. You can drop it. I was thinking that you can do something like:
"'%select{let|var}0' as a parameter attribute is not allowed"
Where the bool is "isVar()"
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.
But given your logic, I can see how that doesn't make sense anymore! So I think you should just drop the bool.
And... that's all I've got, some of them are super picky :-) Thank you again for working on this, the fixits & migration that you're providing are really top notch! |
e69267c
to
fc3b63c
Compare
@lattner fixed everything, I think. Thank you so much for your peer reviews, its been really awesome to have the legendary Chris Lattner review my code :) |
Ah, you're right, thanks! |
@swift-ci Please test |
The revised patch looks great. Once testing is done, I'll merge it. In a follow-on PR, please update the changelog to mention the changes to formerly valid code (e.g. that inout/var/let before the colon) are now errors. Also, please add some a test to show that the invalid code is being rejected with the new diagnostics. Thanks again! |
It looks like your refactor introduced some crashes: swift: /home/buildnode/jenkins/workspace/swift-PR-Linux/swift/lib/AST/DiagnosticEngine.cpp:188: swift::InFlightDiagnostic &swift::InFlightDiagnostic::fixItReplaceChars(swift::SourceLoc, swift::SourceLoc, llvm::StringRef): Assertion `IsActive && "Cannot modify an inactive diagnostic"' failed. |
…3. Fixes SR-979, SR-1020 and cleans up implementation of SE-0003. Provides better fix-its and diagnostics for misplaced 'inout' and prohibits 'var' and 'let' from parameter attributes
@lattner Should be fixed now. For the follow up PR do you want me to add tests to a separate file because this one already modifies and adds some tests that check for invalid |
Ah, if these are already covered, then we're good, thanks! |
@swift-ci please test |
@swift-ci Please test |
@lattner it looks like the linux build timed out. Is there anything I need to fix or will running it again fix it? |
It should be fine, I'll run some local tests. Thanks again for implementing this! Please close out the SR's, and send a PR for the changelog. -Chris |
Pull from the `main` upstream branch
What's in this pull request?
This pull request cleans up parsing of parameter attributes by parsing the inout, let and var tokens better. It cleans up the implementation to work better with SE-0003 by giving better fix-its and diagnostics for var as parameter attributes. It implements SE-0053 to disallow
let
as an attribute. It provides better fixits forinout
that are either duplicated or misplaced to better implement SE-0031.Resolved bug number:
Before merging this pull request to apple/swift repository:
Triggering Swift CI
The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:
Smoke Testing
Validation Testing
Note: Only members of the Apple organization can trigger swift-ci.