-
Notifications
You must be signed in to change notification settings - Fork 171
[ASR/LLVM]: Implement Tuple/List Compare #1342
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
15 commits
Select commit
Hold shift + click to select a range
f3ee92a
Add TupleCompare Node in ASR
Smit-create 907758a
Implement TupleCompare in AST->ASR
Smit-create a5928ac
Implement ListCompare in ASR
Smit-create 597672e
Add tests
Smit-create 21bd466
Update tests
Smit-create 08a0920
Implement Compare Pass for TupleCompare
Smit-create f5f09d3
Support NotEq cmpop in TupleCompare pass
Smit-create 3029ff6
Implement missing Tuple type
Smit-create 8592df1
Add integration tests
Smit-create 8c24fc6
Add list compare pass
Smit-create 971005b
Add tests for list compare
Smit-create 3b760dc
Add docs
Smit-create d2cbcff
Fix errors after ASR changes in variable
Smit-create 380d9dd
Update reference tests
Smit-create 5e10562
Fix the return variable intent type
Smit-create 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from ltypes import i32 | ||
|
||
|
||
def f(): | ||
a11: tuple[i32, i32] | ||
b11: tuple[i32, i32] | ||
a11 = (1, 2) | ||
b11 = (1, 2) | ||
assert a11 == b11 | ||
c11: tuple[i32, i32] | ||
c11 = (1, 3) | ||
assert a11 != c11 and c11 != b11 | ||
a: tuple[tuple[i32, i32], str, bool] | ||
b: tuple[tuple[i32, i32], str, bool] | ||
a = (a11, 'ok', True) | ||
b = (b11, 'ok', True) | ||
assert a == b | ||
b = (b11, 'notok', True) | ||
assert a != b | ||
|
||
|
||
def g(): | ||
a11: list[i32] | ||
b11: list[i32] | ||
a11 = [1, 2, 3, 4] | ||
b11 = [1, 2, 3, 4] | ||
assert a11 == b11 | ||
a11.append(5) | ||
assert a11 != b11 | ||
c11: list[i32] = [] | ||
assert a11 != c11 | ||
|
||
d11: list[str] = ['a', 'b', '^', '*'] | ||
e11: list[str] = ['a', 'b', '^'] | ||
assert d11 != e11 | ||
e11.append('*') | ||
assert d11 == e11 | ||
|
||
f11: list[tuple[i32, i32]] = [] | ||
x: tuple[i32, i32] | ||
i: i32 | ||
for i in range(10): | ||
x = (i, i+2) | ||
f11.append(x) | ||
|
||
g11: list[tuple[i32, i32]] = [] | ||
for i in range(9): | ||
x = (i, i+2) | ||
g11.append(x) | ||
assert g11 != f11 | ||
x = (9, 11) | ||
g11.append(x) | ||
assert g11 == f11 | ||
|
||
|
||
def check(): | ||
f() | ||
g() | ||
|
||
|
||
check() |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test for nested tuples as well with mixed types like,
tuple[i32, tuple[i64, f32], str]
.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case (see #1342 (comment)) is not yet covered in the tests. Please test for this first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I avoided using
f32
because of precision issues in comparison. I added a test for the mixed types: