-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
[mypyc] Add 'range' primitive type #10307
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9532c3c
Add range primitive type
97littleleaf11 c45edb6
Load range type and add some tests
97littleleaf11 8c959f1
Wrong attemp
97littleleaf11 08616b8
Change range from function to class
97littleleaf11 bc76b92
Merge branch 'master' into add-range
97littleleaf11 70376d9
Fix range ir
97littleleaf11 94399bd
Revert
97littleleaf11 017711e
Remove unused imports
97littleleaf11 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -3649,3 +3649,71 @@ L0: | |
r2 = r1 >= 0 :: signed | ||
r3 = truncate r1: int32 to builtins.bool | ||
return r3 | ||
|
||
[case testRangeObject] | ||
def range_object() -> None: | ||
r = range(4, 12, 2) | ||
sum = 0 | ||
for i in r: | ||
sum += i | ||
|
||
def range_in_loop() -> None: | ||
sum = 0 | ||
for i in range(4, 12, 2): | ||
sum += i | ||
[out] | ||
def range_object(): | ||
r0, r1, r2, r3, r4 :: object | ||
r5, r :: range | ||
sum :: int | ||
r6, r7 :: object | ||
r8, i, r9 :: int | ||
r10 :: bit | ||
L0: | ||
r0 = load_address PyRange_Type | ||
r1 = box(short_int, 8) | ||
r2 = box(short_int, 24) | ||
r3 = box(short_int, 4) | ||
r4 = PyObject_CallFunctionObjArgs(r0, r1, r2, r3, 0) | ||
r5 = cast(range, r4) | ||
r = r5 | ||
sum = 0 | ||
r6 = PyObject_GetIter(r) | ||
L1: | ||
r7 = PyIter_Next(r6) | ||
if is_error(r7) goto L4 else goto L2 | ||
L2: | ||
r8 = unbox(int, r7) | ||
i = r8 | ||
r9 = CPyTagged_Add(sum, i) | ||
sum = r9 | ||
L3: | ||
goto L1 | ||
L4: | ||
r10 = CPy_NoErrOccured() | ||
L5: | ||
return 1 | ||
def range_in_loop(): | ||
sum :: int | ||
r0 :: short_int | ||
i :: int | ||
r1 :: bit | ||
r2 :: int | ||
r3 :: short_int | ||
L0: | ||
sum = 0 | ||
r0 = 8 | ||
i = r0 | ||
L1: | ||
r1 = r0 < 24 :: signed | ||
if r1 goto L2 else goto L4 :: bool | ||
L2: | ||
r2 = CPyTagged_Add(sum, i) | ||
sum = r2 | ||
L3: | ||
r3 = r0 + 4 | ||
r0 = r3 | ||
i = r3 | ||
goto L1 | ||
L4: | ||
return 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two cases seem to work correctly. |
This file contains 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 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 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
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.
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.
There probably is an existing test case for range in a for loop, so this can be removed.
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 cannot find the irbuild case and I'll keep this.