Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3k
Commitdb67888
authored
[mypyc] Use native integers for some sequence indexing operations (#19426)
For example, when iterating over a list, now we use a native integerfor the index (which is not exposed to the user). Previously we usedtagged integers, but in these use cases they provide no real benefit.This simplifies the IR and should slightly improve performance, as fewertagged int to native int conversions are needed.Multiple ops have to be migrated in one go, as these interact witheach other, and by only changing a subset of them would actuallygenerate more verbose IR, as a bunch of extra coercions would beneeded.List of impacted statements: * For loop over sequence * Assignment like `x, y = a` for tuple/list rvalue * Dict iteration * List comprehensionFor example, consider this example:```def foo(a: list[int]) -> None: for x in a: pass```Old generated IR was like this:```def foo(a): a :: list r0 :: short_int r1 :: ptr r2 :: native_int r3 :: short_int r4 :: bit r5 :: native_int r6, r7 :: ptr r8 :: native_int r9 :: ptr r10 :: object r11 :: int r12 :: short_int r13 :: NoneL0: r0 = 0L1: r1 = get_element_ptr a ob_size :: PyVarObject r2 = load_mem r1 :: native_int* r3 = r2 << 1 r4 = r0 < r3 :: signed if r4 goto L2 else goto L5 :: boolL2: r5 = r0 >> 1 r6 = get_element_ptr a ob_item :: PyListObject r7 = load_mem r6 :: ptr* r8 = r5 * 8 r9 = r7 + r8 r10 = load_mem r9 :: builtins.object* inc_ref r10 r11 = unbox(int, r10) dec_ref r10 if is_error(r11) goto L6 (error at foo:2) else goto L3L3: dec_ref r11 :: intL4: r12 = r0 + 2 r0 = r12 goto L1L5: return 1L6: r13 = <error> :: None return r13```Now the generated IR is simpler:```def foo(a): a :: list r0 :: native_int r1 :: ptr r2 :: native_int r3 :: bit r4, r5 :: ptr r6 :: native_int r7 :: ptr r8 :: object r9 :: int r10 :: native_int r11 :: NoneL0: r0 = 0L1: r1 = get_element_ptr a ob_size :: PyVarObject r2 = load_mem r1 :: native_int* r3 = r0 < r2 :: signed if r3 goto L2 else goto L5 :: boolL2: r4 = get_element_ptr a ob_item :: PyListObject r5 = load_mem r4 :: ptr* r6 = r0 * 8 r7 = r5 + r6 r8 = load_mem r7 :: builtins.object* inc_ref r8 r9 = unbox(int, r8) dec_ref r8 if is_error(r9) goto L6 (error at foo:2) else goto L3L3: dec_ref r9 :: intL4: r10 = r0 + 1 r0 = r10 goto L1L5: return 1L6: r11 = <error> :: None return r11```1 parent2f7ba4e commitdb67888
File tree
17 files changed
+1128
-1217
lines changed- mypyc
- irbuild
- lib-rt
- primitives
- test-data
17 files changed
+1128
-1217
lines changedLines changed: 7 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
129 | 129 |
| |
130 | 130 |
| |
131 | 131 |
| |
| 132 | + | |
132 | 133 |
| |
133 | 134 |
| |
134 | 135 |
| |
| |||
772 | 773 |
| |
773 | 774 |
| |
774 | 775 |
| |
775 |
| - | |
| 776 | + | |
776 | 777 |
| |
| 778 | + | |
777 | 779 |
| |
| 780 | + | |
| 781 | + | |
| 782 | + | |
778 | 783 |
| |
| 784 | + | |
779 | 785 |
| |
780 | 786 |
| |
781 | 787 |
| |
|
Lines changed: 10 additions & 12 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
44 | 44 |
| |
45 | 45 |
| |
46 | 46 |
| |
| 47 | + | |
47 | 48 |
| |
48 | 49 |
| |
49 | 50 |
| |
| |||
75 | 76 |
| |
76 | 77 |
| |
77 | 78 |
| |
| 79 | + | |
78 | 80 |
| |
79 | 81 |
| |
80 | 82 |
| |
| |||
586 | 588 |
| |
587 | 589 |
| |
588 | 590 |
| |
589 |
| - | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
590 | 594 |
| |
591 | 595 |
| |
592 | 596 |
| |
| |||
766 | 770 |
| |
767 | 771 |
| |
768 | 772 |
| |
| 773 | + | |
| 774 | + | |
769 | 775 |
| |
770 | 776 |
| |
771 | 777 |
| |
| |||
784 | 790 |
| |
785 | 791 |
| |
786 | 792 |
| |
787 |
| - | |
| 793 | + | |
788 | 794 |
| |
789 |
| - | |
790 |
| - | |
791 |
| - | |
| 795 | + | |
792 | 796 |
| |
793 | 797 |
| |
794 | 798 |
| |
| |||
838 | 842 |
| |
839 | 843 |
| |
840 | 844 |
| |
841 |
| - | |
842 |
| - | |
843 |
| - | |
844 |
| - | |
845 |
| - | |
846 |
| - | |
847 |
| - | |
| 845 | + | |
848 | 846 |
| |
849 | 847 |
| |
850 | 848 |
| |
|
Lines changed: 5 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
652 | 652 |
| |
653 | 653 |
| |
654 | 654 |
| |
655 |
| - | |
| 655 | + | |
656 | 656 |
| |
657 | 657 |
| |
658 | 658 |
| |
| |||
703 | 703 |
| |
704 | 704 |
| |
705 | 705 |
| |
706 |
| - | |
| 706 | + | |
707 | 707 |
| |
708 | 708 |
| |
709 | 709 |
| |
710 | 710 |
| |
711 |
| - | |
712 | 711 |
| |
713 |
| - | |
| 712 | + | |
714 | 713 |
| |
715 | 714 |
| |
716 | 715 |
| |
| |||
783 | 782 |
| |
784 | 783 |
| |
785 | 784 |
| |
786 |
| - | |
| 785 | + | |
| 786 | + | |
787 | 787 |
| |
788 | 788 |
| |
789 | 789 |
| |
|
Lines changed: 2 additions & 9 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
231 | 231 |
| |
232 | 232 |
| |
233 | 233 |
| |
234 |
| - | |
235 |
| - | |
236 |
| - | |
237 |
| - | |
238 |
| - | |
239 |
| - | |
240 |
| - | |
241 |
| - | |
242 |
| - | |
| 234 | + | |
| 235 | + | |
243 | 236 |
| |
244 | 237 |
| |
245 | 238 |
| |
|
Lines changed: 10 additions & 9 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
46 | 46 |
| |
47 | 47 |
| |
48 | 48 |
| |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
49 | 57 |
| |
50 | 58 |
| |
51 |
| - | |
| 59 | + | |
52 | 60 |
| |
53 |
| - | |
54 |
| - | |
55 |
| - | |
56 |
| - | |
57 |
| - | |
58 |
| - | |
59 |
| - | |
60 |
| - | |
| 61 | + | |
61 | 62 |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
289 | 289 |
| |
290 | 290 |
| |
291 | 291 |
| |
292 |
| - | |
| 292 | + | |
293 | 293 |
| |
294 | 294 |
| |
295 | 295 |
| |
|
Lines changed: 5 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
13 | 13 |
| |
14 | 14 |
| |
15 | 15 |
| |
| 16 | + | |
16 | 17 |
| |
17 | 18 |
| |
18 | 19 |
| |
| |||
154 | 155 |
| |
155 | 156 |
| |
156 | 157 |
| |
157 |
| - | |
| 158 | + | |
158 | 159 |
| |
159 | 160 |
| |
160 | 161 |
| |
| |||
183 | 184 |
| |
184 | 185 |
| |
185 | 186 |
| |
186 |
| - | |
187 |
| - | |
| 187 | + | |
| 188 | + | |
188 | 189 |
| |
189 |
| - | |
| 190 | + | |
190 | 191 |
| |
191 | 192 |
| |
192 | 193 |
| |
|
Lines changed: 14 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
6 | 6 |
| |
7 | 7 |
| |
8 | 8 |
| |
9 |
| - | |
| 9 | + | |
10 | 10 |
| |
11 |
| - | |
12 | 11 |
| |
13 | 12 |
| |
14 | 13 |
| |
15 | 14 |
| |
16 | 15 |
| |
| 16 | + | |
17 | 17 |
| |
18 | 18 |
| |
19 | 19 |
| |
| |||
29 | 29 |
| |
30 | 30 |
| |
31 | 31 |
| |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
32 | 41 |
| |
33 | 42 |
| |
34 | 43 |
| |
| |||
48 | 57 |
| |
49 | 58 |
| |
50 | 59 |
| |
51 |
| - | |
52 |
| - | |
| 60 | + | |
| 61 | + | |
53 | 62 |
| |
54 |
| - | |
| 63 | + | |
55 | 64 |
| |
56 | 65 |
| |
57 | 66 |
| |
|
0 commit comments
Comments
(0)