Skip to content

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

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

paldepind wants to merge 4 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 dynamic 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)

@paldepind
paldepind requested a review from a team as a code owner November 13, 2026 13:38
@paldepind
paldepind requested a dynamic review from Copilot November 13, 2026 13:48

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.

🔵 Needs a closer look

The new wrappers propagate value flow but not operand types, causing unannotated declarations to lose inferred receiver types and breaking subsequent member or method resolution.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Propagate operand types through all four copy operators

unified/​ql/​lib/​codeql/​unified/​internal/​dataflow/​DataFlowPluginSwift.qll:75

Value flow now passes through these wrappers, but neither TypeInferencePluginSwift.qll::inferType nor TypeInference.qll::stepLanguageSpecific propagates their operand types. Consequently, an unannotated declaration such as let copied = copy original loses the inferred receiver type needed to resolve subsequent instance member accesses or method calls. Propagate operand types, including generic type paths, through all four operators and add type-inference/member-resolution regression tests.

1 resolved since last review

Review effort: Balanced (dynamic)

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