Skip to content

[Sema] Maintain the implicitness of call argument tuple/parens in coerceCallArguments #31184

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 1 commit into from
Apr 24, 2020

Conversation

nathawes
Copy link
Contributor

If any arguments were defaulted the tuple/paren was made implicit, even though the original tuple/paren was present in the source.

This prevented some sourcekit ASTWalkers from considering them, making refactorings, documentation info, jump-to-definition and other features unavailable when queried via their argument labels.

Resolves rdar://problem/62118957

@nathawes nathawes requested a review from xedin April 21, 2020 18:55
@nathawes
Copy link
Contributor Author

@swift-ci please test

lib/AST/Expr.cpp Outdated
@@ -1231,6 +1231,9 @@ SourceRange TupleExpr::getSourceRange() const {
} else {
// Scan forward for the first valid source loc.
for (Expr *expr : getElements()) {
// Skip default arguments - they inherit the location of their parent.
if (isa<DefaultArgumentExpr>(expr))
Copy link
Contributor

@xedin xedin Apr 21, 2020

Choose a reason for hiding this comment

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

I see that in coerceCallArguments when we create DefaultArgumentExpr we give it arg->getStartLoc() which is supposed to be a location of "argument list". I think DefaultArgumentExpr should implement getStartLoc/getEndLoc and return {} from it to indicate that it has to source location. This way we wouldn't need to touch TupleExpr, WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not even sure why would it implement getSourceRange with a single location, maybe we should just remove Loc from DefaultArgumentExpr?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, makes sense – thanks!

arg = new (ctx)
ParenExpr(lParenLoc, newArgs[0], rParenLoc, hasTrailingClosure);
arg->setImplicit();
if (isImplicit)
arg->setImplicit();
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI Expr::setImplicit accepts an argument so I believe arg->setImplicit(isImplicit); should work.

@nathawes nathawes force-pushed the defaulted-arg-list-implicitness branch from 29cf3d8 to 3a5460a Compare April 21, 2020 19:42
@nathawes
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 29cf3d8631a27a93216796aeb4e3e327e220a763

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 29cf3d8631a27a93216796aeb4e3e327e220a763

…rceCallArguments

If any arguments were defaulted the tuple/paren was made implicit, even though
the original tuple/paren was present in the source.

This prevented some sourcekit ASTWalkers from considering them, making
refactorings, documentation info, jump-to-definition and other features
unavailable when queried via their argument labels.

Resolves rdar://problem/62118957
@nathawes nathawes force-pushed the defaulted-arg-list-implicitness branch from 3a5460a to 7c0a178 Compare April 24, 2020 01:55
@nathawes
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 3a5460afe764d358a3b7b6c57a8afd11f63ec2c6

@@ -788,7 +788,8 @@ Expr *CallerSideDefaultArgExprRequest::evaluate(
auto paramTy = defaultExpr->getType();

// Re-create the default argument using the location info of the call site.
auto *initExpr = synthesizeCallerSideDefault(param, defaultExpr->getLoc());
auto *initExpr =
synthesizeCallerSideDefault(param, defaultExpr->getArgumentListLoc());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@xedin this is the bit I was missing that caused the test failures previously. getLoc() was based on getSourceRange().

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 3a5460afe764d358a3b7b6c57a8afd11f63ec2c6

@nathawes nathawes merged commit b297ea6 into swiftlang:master Apr 24, 2020
@nathawes nathawes deleted the defaulted-arg-list-implicitness branch April 24, 2020 20:25
nathawes pushed a commit to nathawes/swift that referenced this pull request May 18, 2020
This restores getSourceRange() on DefaultArgumentExpr after it was removed in
swiftlang#31184.

It was originally removed to solve the issues it was causing when computing the
source range of its parent TupleExpr. To account for trailing closures we walk
back through the tuple's arguments until one with a valid location is found,
which we use as the end location. If the last argument was a DefaultArgumentExpr
though that meant the end loc would end up being the tuple's start location, so
none of the tuple's other arguments were contained in its range, triggering an
ASTVerifier assertion. Source tooling and diagnostics don't care about default
arg expression locations as nothing can reference them, but their locations are
output in the debug info. Added a regression test to catch that in future, and
updated TupleExpr::getSourceRange() to ignore them when computing the end loc.

Resolves rdar://problem/63195504.
nathawes pushed a commit to nathawes/swift that referenced this pull request May 18, 2020
This restores getSourceRange() on DefaultArgumentExpr after it was removed in
swiftlang#31184.

It was originally removed to solve the issues it was causing when computing the
source range of its parent TupleExpr. To account for trailing closures we walk
back through the tuple's arguments until one with a valid location is found,
which we use as the end location. If the last argument was a DefaultArgumentExpr
though that meant the end loc would end up being the tuple's start location, so
none of the tuple's other arguments were contained in its range, triggering an
ASTVerifier assertion. Source tooling and diagnostics don't care about default
arg expression locations as nothing can reference them, but their locations are
output in the debug info. Added a regression test to catch that in future, and
updated TupleExpr::getSourceRange() to ignore them when computing the end loc.

Resolves rdar://problem/63195504.
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.

3 participants