Skip to content

Unified: Support Swift borrow, consume, copy, and unsafe expressions - #23104

Open
paldepind wants to merge 2 commits into
mainfrom
unified/modified-expr
Open

paldepind wants to merge 2 commits into
mainfrom
unified/modified-expr

Conversation

@paldepind

@paldepind paldepind commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Just like how await and try are mapped to unary_expr this PR does the same for borrow, consume, copy, and unsafe expressions.

paldepind and others added 2 commits November 11, 2026 15:30
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8dd55540-3d6b-43a8-873a-7d22380d548f
@paldepind
paldepind force-pushed the unified/modified-expr branch from eca683d to 7862a67 Compare November 11, 2026 14:31
@paldepind paldepind changed the title Unified: Support Swift borrow, consume, copy, and unsafe expressions Unified: Support Swift borrow, consume, copy, and unsafe expressions Nov 11, 2026
@paldepind
paldepind marked this pull request as ready for review November 12, 2026 08:59
@paldepind
paldepind requested a review from a team as a code owner November 12, 2026 08:59
Copilot AI auto review requested due to automatic review settings November 12, 2026 08:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new Swift unary operators lack operand value propagation in unified data flow, causing flows through borrow, consume, copy, and unsafe to stop at the wrapper and leaving a gap in security analyses.

1 open issue
What changed in this PR

Adds unified Swift extraction support for borrow, consume, copy, and unsafe, representing them as unary expressions like await and try.

Changes:

  • Adds translation rules that preserve each keyword as a prefix operator and translate its operand.
  • Removes the corresponding unsupported-node mappings.
  • Adds a borrow fixture and updates expected output for all four expressions.
File Description
unified/​extractor/​tests/​corpus/​swift/​expressions/​unsafe-expression.output Expects a unary expression wrapping the call.
unified/​extractor/​tests/​corpus/​swift/​expressions/​copy-expression.output Expects a copy unary expression.
unified/​extractor/​tests/​corpus/​swift/​expressions/​consume-expression.output Expects a consume unary expression.
unified/​extractor/​tests/​corpus/​swift/​expressions/​borrow-expression.swift Adds a basic borrow-expression fixture.
unified/​extractor/​tests/​corpus/​swift/​expressions/​borrow-expression.output Records the borrow fixture’s expected syntax trees.
unified/​extractor/​src/​languages/​swift/​swift.rs Adds the four unary-expression translation rules.

Review effort: Balanced (auto)

rule!((awaitExpr awaitKeyword: @@keyword expression: @val) => (unary_expr
operator: (prefix_operator "await" location: {keyword})
operand: {val})),
rule!((borrowExpr borrowKeyword: @@keyword expression: @val) => (unary_expr

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think that's outside the scope of this PR but I'd like to take a look at that afterwards once we've agreed that this is how we'll map these construct to the common AST.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The UnaryExpr representation is the way to go 👍

It would be great if you could update type inference and data flow in this PR.

In general I'd like a chunk of work to own an entire language feature across all layers, unless it's impractical for some reason. (In Q1 we worked layer-by-layer for a fixed subset of features in order to bootstrap, but I want to move away from that).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants