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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 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 56c8ce0
Unified: Test type inference through modified expressions
paldepind 276428f
Unified: Infer types through modified expressions
paldepind 412c6e6
Unified: Move Swift type inference steps into the plugin
paldepind 16f6306
Merge main into unified/modified-expr
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
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
31 changes: 31 additions & 0 deletions
31
unified/ql/test/library-tests/type-inference/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,31 @@ | ||
| func testBorrowTypeInference() { | ||
| let value = 42 | ||
| let borrowed = borrow value // $ type=borrowed:Int | ||
| let original = Generic(v: "borrow") // $ target=Generic.init | ||
| let generic = borrow original // $ type=generic@Generic<T>:String | ||
| let result = generic.getValue() // $ type=result:String target=Generic.getValue | ||
| } | ||
|
|
||
| func testConsumeTypeInference() { | ||
| let value = 42 | ||
| let consumed = consume value // $ type=consumed:Int | ||
| let original = Generic(v: "consume") // $ target=Generic.init | ||
| let generic = consume original // $ type=generic@Generic<T>:String | ||
| let result = generic.getValue() // $ type=result:String target=Generic.getValue | ||
| } | ||
|
|
||
| func testCopyTypeInference() { | ||
| let value = 42 | ||
| let copied = copy value // $ type=copied:Int | ||
| let original = Generic(v: "copy") // $ target=Generic.init | ||
| let generic = copy original // $ type=generic@Generic<T>:String | ||
| let result = generic.getValue() // $ type=result:String target=Generic.getValue | ||
| } | ||
|
|
||
| func testUnsafeTypeInference() { | ||
| let value = 42 | ||
| let unchecked = unsafe value // $ type=unchecked:Int | ||
| let original = Generic(v: "unsafe") // $ target=Generic.init | ||
| let generic = unsafe original // $ type=generic@Generic<T>:String | ||
| let result = generic.getValue() // $ type=result:String target=Generic.getValue | ||
| } |
Oops, something went wrong.
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.