Skip to content

[5.3][AST] Restore getSourceRange() on DefaultArgumentExpr #31873

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

Conversation

nathawes
Copy link
Contributor

@nathawes nathawes commented May 18, 2020

Cherry-pick of #31861

  • Explanation:
    This restores getSourceRange() on DefaultArgumentExpr after it was removed in
    [Sema] Maintain the implicitness of call argument tuple/parens in coerceCallArguments #31184. While source tooling and diagnostics don't care about default arg expression locations (nothing can reference them and any issues in them should be diagnosed on the callee rather than caller side), their locations are output in the debug info, so their removal resulted in a debug info regression (rdar://problem/63195504).

    It was originally removed to solve the issues it was causing when computing the source range of TupleExprs containing defaulted arguments after a trailing closure. The implementation assumes its argument expressions with valid source locations appear in source order, which default argument expressions violate (they point to the start of their parent tuple expression). This change works around that issue with a more targeted fix instead by updating TupleExpr::getSourceRange() to simply ignore DefaultArgExprs.

  • Scope of issue: This results in having no debug info for frames corresponding to default argument expressions.

  • Origination: This regressed due to a part of the fix to stop tuple expressions being incorrectly flagged as implicit when they contained defaulted arguments: [Sema] Maintain the implicitness of call argument tuple/parens in coerceCallArguments #31184 (rdar 62118957)

  • Risk: Low. This restores the previous functionality and adds a more targeted fix for the original issue it was resolving.

  • Testing: Added a regression test to catch the debug info regression in future. All regression tests pass.

  • Reviewer: @xedin (on the master PR)

Resolves rdar://problem/63195504

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 nathawes added the r5.3 label May 18, 2020
@nathawes
Copy link
Contributor Author

@swift-ci please test

@nathawes nathawes changed the title [WIP][5.3][AST] Restore getSourceRange() on DefaultArgumentExpr [5.3][AST] Restore getSourceRange() on DefaultArgumentExpr May 19, 2020
@nathawes nathawes marked this pull request as ready for review May 19, 2020 16:49
@nathawes nathawes requested a review from a team as a code owner May 19, 2020 16:49
@nathawes
Copy link
Contributor Author

@swift-ci please nominate

@tkremenek tkremenek merged commit 43a607c into swiftlang:release/5.3 May 19, 2020
@AnthonyLatsis AnthonyLatsis added swift 5.3 🍒 release cherry pick Flag: Release branch cherry picks labels Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks swift 5.3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants