Skip to content

[AST] [Sema] [IDE] Fix places where we set bare arguments #17987

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

Merged
merged 4 commits into from
Jul 25, 2018
Merged

[AST] [Sema] [IDE] Fix places where we set bare arguments #17987

merged 4 commits into from
Jul 25, 2018

Conversation

beccadax
Copy link
Contributor

@beccadax beccadax commented Jul 16, 2018

This change adds an assertion that, except on SelfApplyExprs, Arg must always be a ParenExpr, TupleExpr, TupleShuffleExpr, CodeCompletionExpr, or ErrorExpr. It then fixes all failures caught by build-script -t or -T on macOS. I'm opening this PR now so I can let CI have a crack at it.

Along the way, I may have fixed rdar://41416911, but I'll need someone at Apple to confirm that for me.

I'm not sure if we should keep the assertions in the compiler or revert them and just merge the fixes, but I'm not at that stage yet anyway.

@CodaFi @slavapestov Probably relevant to your interests.

@beccadax
Copy link
Contributor Author

@swift-ci Please test

@beccadax beccadax changed the title [WIP] Fix places where we set arbitrary arguments [WIP] Fix places where we set bare arguments Jul 16, 2018
@beccadax
Copy link
Contributor Author

I'm a bit surprised by the lack of CodeCompletionExprs and ErrorExprs, but maybe it's true…

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 83b8c6f8f2215a9b5395a06d94bed5197dcd1c75

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 83b8c6f8f2215a9b5395a06d94bed5197dcd1c75

@beccadax
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - a4a76464d5112778fb82cf161f42f2f906d703ce

@beccadax
Copy link
Contributor Author

That one failure looks like it was from the then-current master; rebasing and trying again.

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - a4a76464d5112778fb82cf161f42f2f906d703ce

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - a4a76464d5112778fb82cf161f42f2f906d703ce

@beccadax
Copy link
Contributor Author

🤷‍♂️

@swift-ci Please test

@CodaFi
Copy link
Contributor

CodaFi commented Jul 18, 2018

@rintaro also had some work on this in #17696

@CodaFi CodaFi requested a review from rintaro July 18, 2018 19:16
@beccadax beccadax changed the title [WIP] Fix places where we set bare arguments [AST] [Sema] [IDE] Fix places where we set bare arguments Jul 18, 2018
@beccadax
Copy link
Contributor Author

beccadax commented Jul 18, 2018

@CodaFi Yes, we seem to have implemented similar fixes. Looks like the difference is that I effectively && the CallArgs test with the inner if, while @rintaro effectively &&s it with the outer if. I suspect he has it right and I have it wrong, but he might disagree.

If #17696 gets merged, I can back out that particular change, and I think the rest of this will slot right in.

@slavapestov
Copy link
Contributor

This looks like a great idea. Eventually we want ApplyExpr to directly store call arguments and encode which ones are packed into variadics and defaulted, etc. Normalizing the AST in this manner is a good first step and also makes sense on its own.

@beccadax
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - a1420cb46ec1043e5aa6fbfe595dd5576bf2efb6

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - a1420cb46ec1043e5aa6fbfe595dd5576bf2efb6

@beccadax
Copy link
Contributor Author

🙄

@swift-ci please test

beccadax added 4 commits July 22, 2018 19:29
Most ApplyExpr subclasses will now require a ParenExpr, TupleExpr, or TupleShuffleExpr around their argument lists. The exceptions are BinaryExpr, which requires a TupleExpr, and SelfApplyExpr and its subclasses, which allow anything (and only ever have one argument).

This change doesn’t fix any of the places where we actually generate these.
PreCheckExpression was not treating the implicit call parens on unary or binary operator applications like the explicit parens on CallExpr applications. Now it will. This prevents various forms of mischief, like having them subsumed into a TypeExpr.
@CodaFi
Copy link
Contributor

CodaFi commented Jul 23, 2018

@swift-ci please smoke test

else if (isa<BinaryExpr>(this))
return isa<TupleExpr>(e);
else
return isa<ParenExpr>(e) || isa<TupleExpr>(e) || isa<TupleShuffleExpr>(e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth to add PrefixUnaryExpr/PostfixUnaryExpr -> ParenExpr check here? cc: @xedin

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since arguments of such expressions are now implicitly wrapped into parens it shouldn't be required.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's why I thought we can add the check for it.

Copy link
Contributor Author

@beccadax beccadax Jul 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think we should. To be honest, I’d like to drop the BinaryExpr -> TupleExpr check too, because I want to support operator functions with extra defaulted parameters (for #line and friends), which will require TupleShuffleExpr args on BinaryExpr. But that will require other changes to the compiler, and I’d rather do one thing at a time.

@beccadax
Copy link
Contributor Author

@swift-ci please smoke test and merge

@rintaro
Copy link
Member

rintaro commented Jul 25, 2018

It seems bot didn't responded.
@swift-ci please smoke test and merge

@swift-ci swift-ci merged commit e9cb62d into swiftlang:master Jul 25, 2018
@beccadax beccadax deleted the youll-get-no-argument branch July 25, 2018 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants