-
Notifications
You must be signed in to change notification settings - Fork 1
Introduce DFA-based Uniqueness Checking #53
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
paganma
wants to merge
91
commits into
main
Choose a base branch
from
marco/uniqueness-dataflow-analysis
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.
+1,771
−638
Open
Changes from all commits
Commits
Show all changes
91 commits
Select commit
Hold shift + click to select a range
1ed9f3d
Simplify names
paganma efcd263
Implement basic facility for dataflow analysis
paganma 0d9023a
Decouple UniquenessResolver from UniquenessChecker
paganma bc0b5e5
Remove visitor
paganma 53c10b0
fixup! Decouple UniquenessResolver from UniquenessChecker
paganma bf1f192
Rename UniqueDeclarationChecker.kt to UniquenessDeclarationChecker.kt
paganma 8cb9195
Implement precise UniquenessType lattice
paganma 009d7e9
Extract enums from UniquenessType
paganma 55a3608
Declare initial and bottom as values
paganma f211f03
Skeleton for UniquenessGraphChecker and UniquenessAnalyzer implementa…
paganma d97cbc5
fixup! Skeleton for UniquenessGraphChecker and UniquenessAnalyzer imp…
paganma 89673c5
fixup! Skeleton for UniquenessGraphChecker and UniquenessAnalyzer imp…
paganma 56e7f18
fixup! Skeleton for UniquenessGraphChecker and UniquenessAnalyzer imp…
paganma 017b7a9
Implement local_assignments test
paganma 0a2b365
Evaluate uniqueness types at local assignments
paganma ce89876
Handle method calls in analysis
paganma b316636
Extract TypeAssigner
paganma d754de9
Extract Path from FirProperty
paganma c9a1592
Branching example
paganma 34fb4df
Looping example
paganma 211036d
Fix format
paganma ca89175
Check simple locals
paganma ccc3d4f
Reimplement basic UniquenessTrie structure and methods
paganma d0f938e
Switch from Map to UniquenessTrie for the flow object
paganma f1b8165
Add more local_assignments tests
paganma af69ad9
Integrate UniquenessTrie with UniquenessResolver
paganma 4e042e7
Implement hashCode() function for UniquenessTrie
paganma aa35df1
Add support for composed paths
paganma bb56809
Move the right operand of a unique assignment
paganma ef1ba2e
Rename Free to Captured
paganma 6029629
Rename Captured to Consumed
paganma 713843a
Reimplement original uniqueness-checking semantics
paganma 7ba24c1
Remove unused abstract type
paganma 12d662e
Simplify names, add documentation
paganma b4f1d2a
Disallow leaking of borrowed values
paganma a06131b
Test field support
paganma c5b4e2d
Check all partially-moved and partially-shared arguments
paganma e144824
Reorganize and add tests
paganma 819f7be
Reorganize and add tests
paganma 857d8c3
Fix test assertions
paganma 67fe2ac
Add tests for borrowing locals
paganma 698c13f
Add tests for borrowing locals
paganma b7910f6
Merge remote-tracking branch 'origin/marco/uniqueness-dataflow-analys…
paganma 3570a70
Fix formatting
paganma 917dee7
Rename graph local
paganma ec61489
Test local argument passing
paganma 03a3668
Reorder imports
paganma 3ab86a2
Improve handling of interdependent arguments
paganma 29e93bc
Remove unused import
paganma 8e32760
Correctly check return and throw expressions
paganma fe5ad43
Remove unused import
paganma 273165d
fixup! Correctly check return and throw expressions
paganma e06666e
fixup! Correctly check return and throw expressions
paganma f4bb698
Use different path extraction strategies for receivers and values.
paganma 28167e6
Fix formatting, add documentation
paganma aac41e9
Only move unique value paths on the right-hand side of the definition
paganma ba4a281
Improve local names
paganma 166e0c4
Add comments
paganma bef5c19
Correct tests names
paganma 52de67b
Clarify documentation
paganma 0140083
Use `valuePaths` property instead of directly using the visitor
paganma 1a2aff3
Improve locals names
paganma f660bd8
Rename local `out` to `errorCollector`
paganma 9fb9935
Update formver.compiler-plugin/plugin/src/org/jetbrains/kotlin/formve…
paganma e175d7e
Put `resolver` and `initial` local declaration inside try-catch
paganma 62cb786
Split declaration of `callableDeclaration` from `callableSymbol`
paganma fe29663
Update formver.compiler-plugin/uniqueness/src/org/jetbrains/kotlin/fo…
paganma b9ec09c
Check casts
paganma d254b58
Merge remote-tracking branch 'origin/marco/uniqueness-dataflow-analys…
paganma 2dbb020
Use when expressions to simplify checks
paganma c2b9caf
Use `computeIfAbsent` to fetch `child`
paganma 0822c03
Rename `BorrowLevel`s to `Global` and `Local`
paganma 0856eed
fixup! Rename `BorrowLevel`s to `Global` and `Local`
paganma bd8f6fe
Avoid using abstract classes in tests
paganma aeb85b8
Move the individual `valuePaths` based on their individual types.
paganma 1c7657e
Update formver.compiler-plugin/uniqueness/src/org/jetbrains/kotlin/fo…
paganma 9a02a0b
Use smart casts through `when`
paganma d6c3328
Merge remote-tracking branch 'origin/marco/uniqueness-dataflow-analys…
paganma 664238a
Refactor out logic for checking leaked values
paganma b450b19
Use helper function for checking leaked values; improve diagnostics p…
paganma adbc3fd
Refactor out value usage checking
paganma 339b02b
Move `graph` and `errorCollector` declarations inside try-catch
paganma ac48ffc
Remove all the extra newlines around the body of class declarations
paganma 0c48c5a
Rename `handleDefinition` to `evaluateDefinition`
paganma 036180a
Rename `handleDefinition` to `evaluateDefinition`
paganma 6f3d4c0
Enable `@Unique` and `@Borrowed` to annotate local variables
paganma c157a4d
Pretty-print uniqueness types
paganma f6d7ec1
Refactor out common checking logic, use callbacks for reporting errors
paganma 8404956
Set uniqueness after the assignment based on receiver's default
paganma 83dc416
Update tests for new checking logic and diagnostics reporting
paganma 6e477cc
Reorder `visit` methods
paganma 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
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
10 changes: 6 additions & 4 deletions
10
formver.compiler-plugin/testData/diagnostics/uniqueness_checker/annotations.kt
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 |
|---|---|---|
| @@ -1,11 +1,13 @@ | ||
| // UNIQUE_CHECK_ONLY | ||
|
|
||
| import org.jetbrains.kotlin.formver.plugin.Unique | ||
| import org.jetbrains.kotlin.formver.plugin.Borrowed | ||
| import org.jetbrains.kotlin.formver.plugin.Unique | ||
|
|
||
| class Box(@Unique val a: Any) | ||
|
|
||
| fun f_unique(@Unique box: Box) {} | ||
| fun f_borrowed(@Borrowed box: Box) {} | ||
| fun f_unique_borrowed(@Unique @Borrowed box: Box) {} | ||
| fun `unique parameter`(@Unique box: Box) {} | ||
|
|
||
| fun `borrowed parameter`(@Borrowed box: Box) {} | ||
|
|
||
| fun `unique borrowed parameter`(@Unique @Borrowed box: Box) {} | ||
|
|
25 changes: 25 additions & 0 deletions
25
formver.compiler-plugin/testData/diagnostics/uniqueness_checker/assign_local.fir.diag.txt
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,25 @@ | ||
| /assign_local.kt:(290,291): error: Argument uniqueness mismatch: expected 'unique global', actual 'shared global'. | ||
|
|
||
| /assign_local.kt:(387,388): error: Argument uniqueness mismatch: expected 'unique global', actual 'shared local'. | ||
|
|
||
| /assign_local.kt:(598,599): error: Argument uniqueness mismatch: expected 'unique global', actual 'unique local'. | ||
|
|
||
| /assign_local.kt:(697,698): error: Argument uniqueness mismatch: expected 'unique global', actual 'shared global'. | ||
|
|
||
| /assign_local.kt:(797,798): error: Argument uniqueness mismatch: expected 'unique global', actual 'shared local'. | ||
|
|
||
| /assign_local.kt:(991,992): error: Argument uniqueness mismatch: expected 'unique global', actual 'shared global'. | ||
|
|
||
| /assign_local.kt:(1115,1116): error: Argument uniqueness mismatch: expected 'unique global', actual 'shared local'. | ||
|
|
||
| /assign_local.kt:(1254,1255): error: Argument uniqueness mismatch: expected 'unique global', actual 'unique local'. | ||
|
|
||
| /assign_local.kt:(1389,1390): error: Argument uniqueness mismatch: expected 'unique global', actual 'shared global'. | ||
|
|
||
| /assign_local.kt:(1532,1533): error: Argument uniqueness mismatch: expected 'unique global', actual 'shared local'. | ||
|
|
||
| /assign_local.kt:(1841,1842): error: Argument uniqueness mismatch: expected 'unique global', actual 'unique local'. | ||
|
|
||
| /assign_local.kt:(2028,2029): error: Argument uniqueness mismatch: expected 'unique global', actual 'shared global'. | ||
|
|
||
| /assign_local.kt:(2194,2195): error: Assignment uniqueness mismatch: expected 'unique global', actual 'moved'. |
150 changes: 150 additions & 0 deletions
150
formver.compiler-plugin/testData/diagnostics/uniqueness_checker/assign_local.kt
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,150 @@ | ||
| // UNIQUE_CHECK_ONLY | ||
|
|
||
| import org.jetbrains.kotlin.formver.plugin.Borrowed | ||
| import org.jetbrains.kotlin.formver.plugin.Unique | ||
|
|
||
| fun nondet(): Boolean { | ||
| return false | ||
| } | ||
|
|
||
| fun consume(@Unique x: Any) {} | ||
|
|
||
| // Var assignments | ||
|
|
||
| fun `assign shared`(x: Any) { | ||
| var y: Any | ||
|
|
||
| y = x | ||
|
|
||
| consume(<!UNIQUENESS_VIOLATION!>y<!>) | ||
| } | ||
|
|
||
| fun `assign borrowed`(@Borrowed x: Any) { | ||
| @Borrowed var y: Any | ||
|
|
||
| y = x | ||
|
|
||
| consume(<!UNIQUENESS_VIOLATION!>y<!>) | ||
| } | ||
|
|
||
| fun `assign unique`(@Unique x: Any) { | ||
| @Unique var y: Any | ||
|
|
||
| y = x | ||
|
|
||
| consume(y) | ||
| } | ||
|
|
||
| fun `assign unique-borrowed`(@Unique @Borrowed x: Any) { | ||
| @Unique @Borrowed var y: Any | ||
|
|
||
| y = x | ||
|
|
||
| consume(<!UNIQUENESS_VIOLATION!>y<!>) | ||
| } | ||
|
|
||
| // Var declarations | ||
|
|
||
| fun `assign shared in declaration`(x: Any) { | ||
| var y = x | ||
|
|
||
| consume(<!UNIQUENESS_VIOLATION!>y<!>) | ||
| } | ||
|
|
||
| fun `assign borrowed in declaration`(@Borrowed x: Any) { | ||
| @Borrowed var y = x | ||
|
|
||
| consume(<!UNIQUENESS_VIOLATION!>y<!>) | ||
| } | ||
|
|
||
| fun `assign unique in unique declaration`(@Unique x: Any) { | ||
| @Unique var y = x | ||
|
|
||
| consume(y) | ||
| } | ||
|
|
||
| fun `assign unique in shared declaration`(@Unique x: Any) { | ||
| var y = x | ||
|
|
||
| consume(<!UNIQUENESS_VIOLATION!>y<!>) | ||
| } | ||
|
|
||
| fun `assign unique-borrowed in borrowed declaration`(@Unique @Borrowed x: Any) { | ||
| @Borrowed var y = x | ||
|
|
||
| consume(<!UNIQUENESS_VIOLATION!>y<!>) | ||
| } | ||
|
|
||
| fun `assign unique-borrowed in unique-borrowed declaration`(@Unique @Borrowed x: Any) { | ||
| @Unique @Borrowed var y = x | ||
|
|
||
| consume(<!UNIQUENESS_VIOLATION!>y<!>) | ||
| } | ||
|
|
||
| // Assignment chaining | ||
|
|
||
| fun `chain shared assignments`(x: Any) { | ||
| var y: Any | ||
| var z: Any | ||
|
|
||
| y = x | ||
| z = y | ||
|
|
||
| consume(<!UNIQUENESS_VIOLATION!>z<!>) | ||
| } | ||
|
|
||
| fun `chain borrowed assignments`(@Borrowed x: Any) { | ||
| @Borrowed var y: Any | ||
| @Borrowed var z: Any | ||
|
|
||
| y = x | ||
| z = y | ||
|
|
||
| consume(<!UNIQUENESS_VIOLATION!>z<!>) | ||
| } | ||
|
|
||
| fun `chain unique assignments`(@Unique x: Any) { | ||
| @Unique var y: Any | ||
| @Unique var z: Any | ||
|
|
||
| y = x | ||
| z = y | ||
|
|
||
| consume(z) | ||
| } | ||
|
|
||
| fun `chain unique-borrowed assignments`(@Unique @Borrowed x: Any) { | ||
| @Unique @Borrowed var y: Any | ||
| @Unique @Borrowed var z: Any | ||
|
|
||
| y = x | ||
| z = y | ||
|
|
||
| consume(<!UNIQUENESS_VIOLATION!>z<!>) | ||
| } | ||
|
|
||
| // Conditional assignments | ||
|
|
||
| fun `assign unique or shared`(@Unique x: Any, y: Any) { | ||
| var z: Any; | ||
|
|
||
| if (nondet()) { | ||
| z = x | ||
| } else { | ||
| z = y | ||
| } | ||
|
|
||
| consume(<!UNIQUENESS_VIOLATION!>z<!>) | ||
| } | ||
|
|
||
| // Looping assignments | ||
|
|
||
| fun `assign unique to shared in loop`(@Unique x: Any, @Unique y: Any) { | ||
| @Unique var z: Any = y; | ||
|
|
||
| while (nondet()) { | ||
| z = <!UNIQUENESS_VIOLATION!>x<!> | ||
| } | ||
|
|
||
| consume(z) | ||
| } | ||
5 changes: 5 additions & 0 deletions
5
formver.compiler-plugin/testData/diagnostics/uniqueness_checker/assign_property.fir.diag.txt
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,5 @@ | ||
| /assign_property.kt:(409,410): error: Assignment uniqueness mismatch: expected 'unique global', actual 'shared global'. | ||
|
|
||
| /assign_property.kt:(506,507): error: Assignment uniqueness mismatch: expected 'unique global', actual 'shared local'. | ||
|
|
||
| /assign_property.kt:(727,728): error: Assignment uniqueness mismatch: expected 'unique global', actual 'unique local'. |
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.