Repository navigation
Unified: Support Swift borrow, consume, copy, and unsafe expressions
#23104
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
Open
paldepind
wants to merge
4
commits into
main
Choose a base branch
from
unified/modified-expr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0fbe6e5
Unified: Add borrow expression corpus test
paldepind 7862a67
Unified: Support Swift `borrow`, `consume`, `copy`, and `unsafe` expr…
paldepind 4a8c7cc
Unified: Add tests for `borrow`, `consume`, `copy`, and `unsafe`
paldepind 6f9cdeb
Unified: Add data flow throug `borrow`, `consume`, `copy`, and `unsafe`
paldepind File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
unified/extractor/tests/corpus/swift/expressions/borrow-expression.output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| let original = [1, 2, 3] | ||
| let borrowed = borrow original | ||
|
|
||
| --- | ||
|
|
||
| sourceFile | ||
| endOfFileToken: endOfFile | ||
| statements: | ||
| codeBlockItem | ||
| item: | ||
| variableDecl | ||
| attributes: | ||
| modifiers: | ||
| bindingSpecifier: let | ||
| bindings: | ||
| patternBinding | ||
| initializer: | ||
| initializerClause | ||
| equal: = | ||
| value: | ||
| arrayExpr | ||
| elements: | ||
| arrayElement | ||
| expression: | ||
| integerLiteralExpr | ||
| literal: integerLiteral "1" | ||
| trailingComma: , | ||
| arrayElement | ||
| expression: | ||
| integerLiteralExpr | ||
| literal: integerLiteral "2" | ||
| trailingComma: , | ||
| arrayElement | ||
| expression: | ||
| integerLiteralExpr | ||
| literal: integerLiteral "3" | ||
| leftSquare: [ | ||
| rightSquare: ] | ||
| pattern: | ||
| identifierPattern | ||
| identifier: identifier "original" | ||
| codeBlockItem | ||
| item: | ||
| variableDecl | ||
| attributes: | ||
| modifiers: | ||
| bindingSpecifier: let | ||
| bindings: | ||
| patternBinding | ||
| initializer: | ||
| initializerClause | ||
| equal: = | ||
| value: | ||
| borrowExpr | ||
| expression: | ||
| declReferenceExpr | ||
| baseName: identifier "original" | ||
| borrowKeyword: borrow | ||
| pattern: | ||
| identifierPattern | ||
| identifier: identifier "borrowed" | ||
|
|
||
| --- | ||
|
|
||
| top_level source="⟨body⟩" | ||
| body: | ||
| block source="⟨stmt⟩\n⟨stmt⟩" | ||
| stmt: | ||
| variable_declaration source="⟨modifier⟩ ⟨pattern⟩ = ⟨value⟩" | ||
| modifier: modifier "let" source="let" | ||
| pattern: identifier "original" source="original" | ||
| value: | ||
| array_literal source="[⟨element⟩, ⟨element⟩, ⟨element⟩]" | ||
| element: | ||
| int_literal "1" source="1" | ||
| int_literal "2" source="2" | ||
| int_literal "3" source="3" | ||
| variable_declaration source="⟨modifier⟩ ⟨pattern⟩ = ⟨value⟩" | ||
| modifier: modifier "let" source="let" | ||
| pattern: identifier "borrowed" source="borrowed" | ||
| value: | ||
| unary_expr source="⟨operator⟩ ⟨operand⟩" | ||
| operand: identifier "original" source="original" | ||
| operator: prefix_operator "borrow" source="borrow" |
2 changes: 2 additions & 0 deletions
2
unified/extractor/tests/corpus/swift/expressions/borrow-expression.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| let original = [1, 2, 3] | ||
| let borrowed = borrow original |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
unified/ql/test/library-tests/dataflow/modified-expressions.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| func testBorrow() { | ||
| let original = source("borrow") | ||
| let borrowed = borrow original | ||
| sink(borrowed) // $ hasValueFlow=borrow | ||
| } | ||
|
|
||
| func testConsume() { | ||
| let original = source("consume") | ||
| let consumed = consume original | ||
| sink(consumed) // $ hasValueFlow=consume | ||
| } | ||
|
|
||
| func testCopy() { | ||
| let original = source("copy") | ||
| let copied = copy original | ||
| sink(copied) // $ hasValueFlow=copy | ||
| } | ||
|
|
||
| func testUnsafe() { | ||
| let original = source("unsafe") | ||
| let unchecked = unsafe original | ||
| sink(unchecked) // $ hasValueFlow=unsafe | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.