Skip to content

Swift: clean up VarDecl, NamedPattern and SwitchStmt interactions #14567

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 8 commits into from
Oct 30, 2023

Conversation

redsun82
Copy link
Contributor

@redsun82 redsun82 commented Oct 23, 2023

  • variables under CaseStmt are now AST children, which solves orphan VarDecls in that case
  • reordered CaseStmt AST children to be labels > variables > body (was body > labels)
  • made NamedPattern::getVarDecl an extracted property instead of getName

The above was introducing several VarDecl duplications, as CaseStmt::getCaseBodyVariables, NamedPattern::getVarDecl and DeclRefExpr::getDecl were all actually returning distinct VarDecl instances. It turns out, VarDecl has a getCanonicalVarDecl() to get the true unique variable declaration 🤷 This is now applied at a fundamental level in the the dispatcher, so that any fetching of a variable declaration done anywhere in any translator will pass through this.

@github-actions github-actions bot added the Swift label Oct 23, 2023
* `variables` under `CaseStmt` are now AST children, which solves
  orphan `VarDecl`s in that case
* reordered `CaseStmt` AST children to be `labels > variables > body`
  (was `body > labels`)
* made `NamedPattern::getVarDecl` an extracted property instead of
  `getName`
* The above led to duplicate DB entities because of a quirk in the
  Swift compiler code. This is solved by tweaking the extraction of
  `variables` under `CaseStmt` to not use `getCaseBodyVariables`.
@@ -1,3 +1,4 @@
| var_decls.swift:2:7:2:7 | i | var_decls.swift:2:7:2:7 | i |
Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's actually weird that this was missing! This is the for loop i variable, which is distinct from the i variable introduced after the loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, wait, this is a parent pattern thing, I don't fully know what to make of this 😆

@MathiasVP MathiasVP force-pushed the redsun82/swift-case-variables branch from 90516d9 to 6538a76 Compare October 27, 2023 14:55
@MathiasVP MathiasVP marked this pull request as ready for review October 30, 2023 09:39
@MathiasVP MathiasVP requested a review from a team as a code owner October 30, 2023 09:39
@MathiasVP MathiasVP added the no-change-note-required This PR does not need a change note label Oct 30, 2023
Copy link
Contributor Author

@redsun82 redsun82 left a comment

Choose a reason for hiding this comment

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

@MathiasVP the DB scripts look good to me!

@MathiasVP
Copy link
Contributor

Awesome. In that case I'll approve the merge so that we can merge it 🎉 (because the code changes LGTM as well!)

@MathiasVP MathiasVP merged commit 3a9ffe1 into main Oct 30, 2023
@MathiasVP MathiasVP deleted the redsun82/swift-case-variables branch October 30, 2023 11:23
# 85| [ConcreteVarDecl] b
# 85| Type = Int
# 88| [ConcreteVarDecl] a
# 88| Type = Int
# 92| [ConcreteVarDecl] x
# 92| Type = (Int)
# 95| [ConcreteVarDecl] x
# 95| Type = Int
Copy link
Contributor Author

Choose a reason for hiding this comment

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

still quite a number of orphaned (or maybe duplicate?) var decls here, eh?

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like it, yeah

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-change-note-required This PR does not need a change note Swift
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants