Unwrap parenthesized expressions in unified Swift extraction - #22552
Unwrap parenthesized expressions in unified Swift extraction#22552aschackmull with Copilot wants to merge 6 commits into
Conversation
Co-authored-by: aschackmull <28296824+aschackmull@users.noreply.github.com>
Co-authored-by: aschackmull <28296824+aschackmull@users.noreply.github.com>
Co-authored-by: aschackmull <28296824+aschackmull@users.noreply.github.com>
Co-authored-by: aschackmull <28296824+aschackmull@users.noreply.github.com>
Co-authored-by: aschackmull <28296824+aschackmull@users.noreply.github.com>
| elements: (labeledExpr label: _? @label expression: @e) | ||
| elements: _* @rest) |
There was a problem hiding this comment.
Quick question on the recursive translation and semantics of sequential rule-macro evaluation: As far as I've understood, the single-@ on label and rest mean "do recursive translation". Is this work wasted if the where clause fails and we proceed to the next tupleExpr rule below (which also specifies recursive translation), or is the recursive translation guaranteed to only be done once? To put it differently, would this pair of rules be more efficient if they used @@ for label and rest?
There was a problem hiding this comment.
For the purposes of the guard, all @-captures behave as if they are @@-captures. That is, guard evaluation happens before any automatic translation takes place.
(This makes the syntax a bit awkward, but the alternative would be to force the user to explicitly translate things that could have been auto-translated, and this seemed like the worse option to me.)
There was a problem hiding this comment.
🟡 Changes recommended
The unwrapping guard incorrectly matches trailing-comma tuples such as (x,).
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR updates Swift extraction to unwrap parenthesized grouping expressions while preserving tuple structure.
Changes:
- Adds single-element tuple-expression unwrapping.
- Preserves multi-element tuple mappings.
- Updates Swift extraction corpus expectations.
File summaries
| File | Description |
|---|---|
unified/extractor/tests/corpus/swift/operators/parenthesised-expression.output |
Updates grouped expression extraction. |
unified/extractor/tests/corpus/swift/control-flow/switch-expression-pattern.output |
Verifies structured tuple patterns. |
unified/extractor/tests/corpus/swift/collections/tuple-literal.output |
Verifies tuple literal extraction. |
unified/extractor/src/languages/swift/swift.rs |
Implements tuple-expression mapping and unwrapping. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Parenthesized Swift conditions such as
while (x > 0)were extracted as opaque tuple expressions, omitting the contained comparison.tupleExprnodes as grouping expressions.now extracts the condition as the
x > 0binary expression.