Debian Codegraph @

mypyc/test-data/irbuild-i64.test

raw
1 [case testI64Basics]
2 from mypy_extensions import i64
3
4 def f() -> i64:
5 x: i64 = 5
6 y = x
7 return y
8 [out]
9 def f():
10 x, y :: i64
11 L0:
12 x = 5
13 y = x
14 return y
15
16 [case testI64Compare]
17 from mypy_extensions import i64
18
19 def min(x: i64, y: i64) -> i64:
20 if x < y:
21 return x
22 else:
23 return y
24
25 def all_comparisons(x: i64) -> int:
26 if x == 2:
27 y = 10
28 elif 3 != x:
29 y = 11
30 elif x > 4:
31 y = 12
32 elif 6 >= x:
33 y = 13
34 elif x < 5:
35 y = 14
36 elif 6 <= x:
37 y = 15
38 else:
39 y = 16
40 return y
41 [out]
42 def min(x, y):
43 x, y :: i64
44 r0 :: bit
45 L0:
46 r0 = x < y :: signed
47 if r0 goto L1 else goto L2 :: bool
48 L1:
49 return x
50 L2:
51 return y
52 L3:
53 unreachable
54 def all_comparisons(x):
55 x :: i64
56 r0 :: bit
57 y :: int
58 r1, r2, r3, r4, r5 :: bit
59 L0:
60 r0 = x == 2
61 if r0 goto L1 else goto L2 :: bool
62 L1:
63 y = 20
64 goto L18
65 L2:
66 r1 = 3 != x
67 if r1 goto L3 else goto L4 :: bool
68 L3:
69 y = 22
70 goto L17
71 L4:
72 r2 = x > 4 :: signed
73 if r2 goto L5 else goto L6 :: bool
74 L5:
75 y = 24
76 goto L16
77 L6:
78 r3 = 6 >= x :: signed
79 if r3 goto L7 else goto L8 :: bool
80 L7:
81 y = 26
82 goto L15
83 L8:
84 r4 = x < 5 :: signed
85 if r4 goto L9 else goto L10 :: bool
86 L9:
87 y = 28
88 goto L14
89 L10:
90 r5 = 6 <= x :: signed
91 if r5 goto L11 else goto L12 :: bool
92 L11:
93 y = 30
94 goto L13
95 L12:
96 y = 32
97 L13:
98 L14:
99 L15:
100 L16:
101 L17:
102 L18:
103 return y
104
105 [case testI64Arithmetic]
106 from mypy_extensions import i64
107
108 def f(x: i64, y: i64) -> i64:
109 z = x + y
110 return y - z
111 [out]
112 def f(x, y):
113 x, y, r0, z, r1 :: i64
114 L0:
115 r0 = x + y
116 z = r0
117 r1 = y - z
118 return r1
119
120 [case testI64Negation]
121 from mypy_extensions import i64
122
123 def f() -> i64:
124 i: i64 = -3
125 return -i
126 [out]
127 def f():
128 i, r0 :: i64
129 L0:
130 i = -3
131 r0 = 0 - i
132 return r0
133
134 [case testI64MoreUnaryOps]
135 from mypy_extensions import i64
136
137 def unary(x: i64) -> i64:
138 y = ~x
139 x = +y
140 return x
141 [out]
142 def unary(x):
143 x, r0, y :: i64
144 L0:
145 r0 = x ^ -1
146 y = r0
147 x = y
148 return x
149
150 [case testI64BoxingAndUnboxing]
151 from typing import Any
152 from mypy_extensions import i64
153
154 def f(a: Any) -> None:
155 b: i64 = a
156 a = b
157 [out]
158 def f(a):
159 a :: object
160 r0, b :: i64
161 r1 :: object
162 L0:
163 r0 = unbox(i64, a)
164 b = r0
165 r1 = box(i64, b)
166 a = r1
167 return 1
168
169 [case testI64ListGetSetItem]
170 from typing import List
171 from mypy_extensions import i64
172
173 def get(a: List[i64], i: i64) -> i64:
174 return a[i]
175 def set(a: List[i64], i: i64, x: i64) -> None:
176 a[i] = x
177 [out]
178 def get(a, i):
179 a :: list
180 i :: i64
181 r0 :: object
182 r1 :: i64
183 L0:
184 r0 = CPyList_GetItemInt64(a, i)
185 r1 = unbox(i64, r0)
186 return r1
187 def set(a, i, x):
188 a :: list
189 i, x :: i64
190 r0 :: object
191 r1 :: bit
192 L0:
193 r0 = box(i64, x)
194 r1 = CPyList_SetItemInt64(a, i, r0)
195 return 1
196
197 [case testI64MixedArithmetic]
198 from mypy_extensions import i64
199
200 def f() -> i64:
201 a: i64 = 1
202 b = a + 2
203 return 3 - b
204 [out]
205 def f():
206 a, r0, b, r1 :: i64
207 L0:
208 a = 1
209 r0 = a + 2
210 b = r0
211 r1 = 3 - b
212 return r1
213
214 [case testI64MixedComparison]
215 from mypy_extensions import i64
216
217 def f(a: i64) -> i64:
218 if a < 3:
219 return 1
220 elif 3 < a:
221 return 2
222 return 3
223 [out]
224 def f(a):
225 a :: i64
226 r0, r1 :: bit
227 L0:
228 r0 = a < 3 :: signed
229 if r0 goto L1 else goto L2 :: bool
230 L1:
231 return 1
232 L2:
233 r1 = 3 < a :: signed
234 if r1 goto L3 else goto L4 :: bool
235 L3:
236 return 2
237 L4:
238 L5:
239 return 3
240
241 [case testI64InplaceOperations]
242 from mypy_extensions import i64
243
244 def add(a: i64) -> i64:
245 b = a
246 b += 1
247 a += b
248 return a
249 def others(a: i64, b: i64) -> i64:
250 a -= b
251 a *= b
252 a &= b
253 a |= b
254 a ^= b
255 a <<= b
256 a >>= b
257 return a
258 [out]
259 def add(a):
260 a, b, r0, r1 :: i64
261 L0:
262 b = a
263 r0 = b + 1
264 b = r0
265 r1 = a + b
266 a = r1
267 return a
268 def others(a, b):
269 a, b, r0, r1, r2, r3, r4, r5, r6 :: i64
270 L0:
271 r0 = a - b
272 a = r0
273 r1 = a * b
274 a = r1
275 r2 = a & b
276 a = r2
277 r3 = a | b
278 a = r3
279 r4 = a ^ b
280 a = r4
281 r5 = a << b
282 a = r5
283 r6 = a >> b
284 a = r6
285 return a
286
287 [case testI64BitwiseOps]
288 from mypy_extensions import i64
289
290 def forward(a: i64, b: i64) -> i64:
291 b = a & 1
292 a = b | 2
293 b = a ^ 3
294 a = b << 4
295 b = a >> 5
296 return b
297
298 def reverse(a: i64, b: i64) -> i64:
299 b = 1 & a
300 a = 2 | b
301 b = 3 ^ a
302 a = 4 << b
303 b = 5 >> a
304 return b
305
306 def unary(a: i64) -> i64:
307 return ~a
308 [out]
309 def forward(a, b):
310 a, b, r0, r1, r2, r3, r4 :: i64
311 L0:
312 r0 = a & 1
313 b = r0
314 r1 = b | 2
315 a = r1
316 r2 = a ^ 3
317 b = r2
318 r3 = b << 4
319 a = r3
320 r4 = a >> 5
321 b = r4
322 return b
323 def reverse(a, b):
324 a, b, r0, r1, r2, r3, r4 :: i64
325 L0:
326 r0 = 1 & a
327 b = r0
328 r1 = 2 | b
329 a = r1
330 r2 = 3 ^ a
331 b = r2
332 r3 = 4 << b
333 a = r3
334 r4 = 5 >> a
335 b = r4
336 return b
337 def unary(a):
338 a, r0 :: i64
339 L0:
340 r0 = a ^ -1
341 return r0
342
343 [case testI64Division]
344 from mypy_extensions import i64
345
346 def constant_divisor(x: i64) -> i64:
347 return x // 7
348 def variable_divisor(x: i64, y: i64) -> i64:
349 return x // y
350 def constant_lhs(x: i64) -> i64:
351 return 27 // x
352 def divide_by_neg_one(x: i64) -> i64:
353 return x // -1
354 def divide_by_zero(x: i64) -> i64:
355 return x // 0
356 [out]
357 def constant_divisor(x):
358 x, r0, r1 :: i64
359 r2, r3, r4 :: bit
360 r5 :: i64
361 r6 :: bit
362 r7 :: i64
363 L0:
364 r0 = x / 7
365 r1 = r0
366 r2 = x < 0 :: signed
367 r3 = 7 < 0 :: signed
368 r4 = r2 == r3
369 if r4 goto L3 else goto L1 :: bool
370 L1:
371 r5 = r1 * 7
372 r6 = r5 == x
373 if r6 goto L3 else goto L2 :: bool
374 L2:
375 r7 = r1 - 1
376 r1 = r7
377 L3:
378 return r1
379 def variable_divisor(x, y):
380 x, y, r0 :: i64
381 L0:
382 r0 = CPyInt64_Divide(x, y)
383 return r0
384 def constant_lhs(x):
385 x, r0 :: i64
386 L0:
387 r0 = CPyInt64_Divide(27, x)
388 return r0
389 def divide_by_neg_one(x):
390 x, r0 :: i64
391 L0:
392 r0 = CPyInt64_Divide(x, -1)
393 return r0
394 def divide_by_zero(x):
395 x, r0 :: i64
396 L0:
397 r0 = CPyInt64_Divide(x, 0)
398 return r0
399
400 [case testI64Mod]
401 from mypy_extensions import i64
402
403 def constant_divisor(x: i64) -> i64:
404 return x % 7
405 def variable_divisor(x: i64, y: i64) -> i64:
406 return x % y
407 def constant_lhs(x: i64) -> i64:
408 return 27 % x
409 def mod_by_zero(x: i64) -> i64:
410 return x % 0
411 [out]
412 def constant_divisor(x):
413 x, r0, r1 :: i64
414 r2, r3, r4, r5 :: bit
415 r6 :: i64
416 L0:
417 r0 = x % 7
418 r1 = r0
419 r2 = x < 0 :: signed
420 r3 = 7 < 0 :: signed
421 r4 = r2 == r3
422 if r4 goto L3 else goto L1 :: bool
423 L1:
424 r5 = r1 == 0
425 if r5 goto L3 else goto L2 :: bool
426 L2:
427 r6 = r1 + 7
428 r1 = r6
429 L3:
430 return r1
431 def variable_divisor(x, y):
432 x, y, r0 :: i64
433 L0:
434 r0 = CPyInt64_Remainder(x, y)
435 return r0
436 def constant_lhs(x):
437 x, r0 :: i64
438 L0:
439 r0 = CPyInt64_Remainder(27, x)
440 return r0
441 def mod_by_zero(x):
442 x, r0 :: i64
443 L0:
444 r0 = CPyInt64_Remainder(x, 0)
445 return r0
446
447 [case testI64InPlaceDiv]
448 from mypy_extensions import i64
449
450 def by_constant(x: i64) -> i64:
451 x //= 7
452 return x
453 def by_variable(x: i64, y: i64) -> i64:
454 x //= y
455 return x
456 [out]
457 def by_constant(x):
458 x, r0, r1 :: i64
459 r2, r3, r4 :: bit
460 r5 :: i64
461 r6 :: bit
462 r7 :: i64
463 L0:
464 r0 = x / 7
465 r1 = r0
466 r2 = x < 0 :: signed
467 r3 = 7 < 0 :: signed
468 r4 = r2 == r3
469 if r4 goto L3 else goto L1 :: bool
470 L1:
471 r5 = r1 * 7
472 r6 = r5 == x
473 if r6 goto L3 else goto L2 :: bool
474 L2:
475 r7 = r1 - 1
476 r1 = r7
477 L3:
478 x = r1
479 return x
480 def by_variable(x, y):
481 x, y, r0 :: i64
482 L0:
483 r0 = CPyInt64_Divide(x, y)
484 x = r0
485 return x
486
487 [case testI64InPlaceMod]
488 from mypy_extensions import i64
489
490 def by_constant(x: i64) -> i64:
491 x %= 7
492 return x
493 def by_variable(x: i64, y: i64) -> i64:
494 x %= y
495 return x
496 [out]
497 def by_constant(x):
498 x, r0, r1 :: i64
499 r2, r3, r4, r5 :: bit
500 r6 :: i64
501 L0:
502 r0 = x % 7
503 r1 = r0
504 r2 = x < 0 :: signed
505 r3 = 7 < 0 :: signed
506 r4 = r2 == r3
507 if r4 goto L3 else goto L1 :: bool
508 L1:
509 r5 = r1 == 0
510 if r5 goto L3 else goto L2 :: bool
511 L2:
512 r6 = r1 + 7
513 r1 = r6
514 L3:
515 x = r1
516 return x
517 def by_variable(x, y):
518 x, y, r0 :: i64
519 L0:
520 r0 = CPyInt64_Remainder(x, y)
521 x = r0
522 return x
523
524 [case testI64ForRange]
525 from mypy_extensions import i64
526
527 def g(a: i64) -> None: pass
528
529 def f(x: i64) -> None:
530 n: i64 # TODO: Infer the type
531 for n in range(x):
532 g(n)
533 [out]
534 def g(a):
535 a :: i64
536 L0:
537 return 1
538 def f(x):
539 x, r0, n :: i64
540 r1 :: bit
541 r2 :: None
542 r3 :: i64
543 L0:
544 r0 = 0
545 n = r0
546 L1:
547 r1 = r0 < x :: signed
548 if r1 goto L2 else goto L4 :: bool
549 L2:
550 n = r0
551 r2 = g(n)
552 L3:
553 r3 = r0 + 1
554 r0 = r3
555 goto L1
556 L4:
557 return 1
558
559 [case testI64ConvertFromInt_64bit]
560 from mypy_extensions import i64
561
562 def int_to_i64(a: int) -> i64:
563 return a
564 [out]
565 def int_to_i64(a):
566 a :: int
567 r0 :: native_int
568 r1 :: bit
569 r2, r3 :: i64
570 r4 :: ptr
571 r5 :: c_ptr
572 r6 :: i64
573 L0:
574 r0 = a & 1
575 r1 = r0 == 0
576 if r1 goto L1 else goto L2 :: bool
577 L1:
578 r2 = a >> 1
579 r3 = r2
580 goto L3
581 L2:
582 r4 = a ^ 1
583 r5 = r4
584 r6 = CPyLong_AsInt64(r5)
585 r3 = r6
586 keep_alive a
587 L3:
588 return r3
589
590 [case testI64ConvertToInt_64bit]
591 from mypy_extensions import i64
592
593 def i64_to_int(a: i64) -> int:
594 return a
595 [out]
596 def i64_to_int(a):
597 a :: i64
598 r0, r1 :: bit
599 r2, r3, r4 :: int
600 L0:
601 r0 = a <= 4611686018427387903 :: signed
602 if r0 goto L1 else goto L2 :: bool
603 L1:
604 r1 = a >= -4611686018427387904 :: signed
605 if r1 goto L3 else goto L2 :: bool
606 L2:
607 r2 = CPyTagged_FromInt64(a)
608 r3 = r2
609 goto L4
610 L3:
611 r4 = a << 1
612 r3 = r4
613 L4:
614 return r3
615
616 [case testI64ConvertToInt_32bit]
617 from mypy_extensions import i64
618
619 def i64_to_int(a: i64) -> int:
620 return a
621 [out]
622 def i64_to_int(a):
623 a :: i64
624 r0, r1 :: bit
625 r2, r3 :: int
626 r4 :: native_int
627 r5 :: int
628 L0:
629 r0 = a <= 1073741823 :: signed
630 if r0 goto L1 else goto L2 :: bool
631 L1:
632 r1 = a >= -1073741824 :: signed
633 if r1 goto L3 else goto L2 :: bool
634 L2:
635 r2 = CPyTagged_FromInt64(a)
636 r3 = r2
637 goto L4
638 L3:
639 r4 = truncate a: i64 to native_int
640 r5 = r4 << 1
641 r3 = r5
642 L4:
643 return r3
644
645 [case testI64Tuple]
646 from typing import Tuple
647 from mypy_extensions import i64
648
649 def f(x: i64, y: i64) -> Tuple[i64, i64]:
650 return x, y
651
652 def g() -> Tuple[i64, i64]:
653 return 1, 2
654
655 def h() -> i64:
656 x, y = g()
657 t = g()
658 return x + y + t[0]
659 [out]
660 def f(x, y):
661 x, y, r0, r1 :: i64
662 r2 :: tuple[i64, i64]
663 L0:
664 r0 = x
665 r1 = y
666 r2 = (r0, r1)
667 return r2
668 def g():
669 r0 :: tuple[int, int]
670 r1 :: tuple[i64, i64]
671 L0:
672 r0 = (2, 4)
673 r1 = (1, 2)
674 return r1
675 def h():
676 r0 :: tuple[i64, i64]
677 r1, x, r2, y :: i64
678 r3, t :: tuple[i64, i64]
679 r4, r5, r6 :: i64
680 L0:
681 r0 = g()
682 r1 = r0[0]
683 x = r1
684 r2 = r0[1]
685 y = r2
686 r3 = g()
687 t = r3
688 r4 = x + y
689 r5 = t[0]
690 r6 = r4 + r5
691 return r6
692
693 [case testI64MixWithTagged1_64bit]
694 from mypy_extensions import i64
695 def f(x: i64, y: int) -> i64:
696 return x + y
697 [out]
698 def f(x, y):
699 x :: i64
700 y :: int
701 r0 :: native_int
702 r1 :: bit
703 r2, r3 :: i64
704 r4 :: ptr
705 r5 :: c_ptr
706 r6, r7 :: i64
707 L0:
708 r0 = y & 1
709 r1 = r0 == 0
710 if r1 goto L1 else goto L2 :: bool
711 L1:
712 r2 = y >> 1
713 r3 = r2
714 goto L3
715 L2:
716 r4 = y ^ 1
717 r5 = r4
718 r6 = CPyLong_AsInt64(r5)
719 r3 = r6
720 keep_alive y
721 L3:
722 r7 = x + r3
723 return r7
724
725 [case testI64MixWithTagged2_64bit]
726 from mypy_extensions import i64
727 def f(x: int, y: i64) -> i64:
728 return x + y
729 [out]
730 def f(x, y):
731 x :: int
732 y :: i64
733 r0 :: native_int
734 r1 :: bit
735 r2, r3 :: i64
736 r4 :: ptr
737 r5 :: c_ptr
738 r6, r7 :: i64
739 L0:
740 r0 = x & 1
741 r1 = r0 == 0
742 if r1 goto L1 else goto L2 :: bool
743 L1:
744 r2 = x >> 1
745 r3 = r2
746 goto L3
747 L2:
748 r4 = x ^ 1
749 r5 = r4
750 r6 = CPyLong_AsInt64(r5)
751 r3 = r6
752 keep_alive x
753 L3:
754 r7 = r3 + y
755 return r7
756
757 [case testI64MixWithTaggedInPlace1_64bit]
758 from mypy_extensions import i64
759 def f(y: i64) -> int:
760 x = 0
761 x += y
762 return x
763 [out]
764 def f(y):
765 y :: i64
766 x :: int
767 r0 :: native_int
768 r1 :: bit
769 r2, r3 :: i64
770 r4 :: ptr
771 r5 :: c_ptr
772 r6, r7 :: i64
773 r8, r9 :: bit
774 r10, r11, r12 :: int
775 L0:
776 x = 0
777 r0 = x & 1
778 r1 = r0 == 0
779 if r1 goto L1 else goto L2 :: bool
780 L1:
781 r2 = x >> 1
782 r3 = r2
783 goto L3
784 L2:
785 r4 = x ^ 1
786 r5 = r4
787 r6 = CPyLong_AsInt64(r5)
788 r3 = r6
789 keep_alive x
790 L3:
791 r7 = r3 + y
792 r8 = r7 <= 4611686018427387903 :: signed
793 if r8 goto L4 else goto L5 :: bool
794 L4:
795 r9 = r7 >= -4611686018427387904 :: signed
796 if r9 goto L6 else goto L5 :: bool
797 L5:
798 r10 = CPyTagged_FromInt64(r7)
799 r11 = r10
800 goto L7
801 L6:
802 r12 = r7 << 1
803 r11 = r12
804 L7:
805 x = r11
806 return x
807
808 [case testI64MixWithTaggedInPlace2_64bit]
809 from mypy_extensions import i64
810 def f(y: int) -> i64:
811 x: i64 = 0
812 x += y
813 return x
814 [out]
815 def f(y):
816 y :: int
817 x :: i64
818 r0 :: native_int
819 r1 :: bit
820 r2, r3 :: i64
821 r4 :: ptr
822 r5 :: c_ptr
823 r6, r7 :: i64
824 L0:
825 x = 0
826 r0 = y & 1
827 r1 = r0 == 0
828 if r1 goto L1 else goto L2 :: bool
829 L1:
830 r2 = y >> 1
831 r3 = r2
832 goto L3
833 L2:
834 r4 = y ^ 1
835 r5 = r4
836 r6 = CPyLong_AsInt64(r5)
837 r3 = r6
838 keep_alive y
839 L3:
840 r7 = x + r3
841 x = r7
842 return x
843
844 [case testI64MixedCompare1_64bit]
845 from mypy_extensions import i64
846 def f(x: int, y: i64) -> bool:
847 return x == y
848 [out]
849 def f(x, y):
850 x :: int
851 y :: i64
852 r0 :: native_int
853 r1 :: bit
854 r2, r3 :: i64
855 r4 :: ptr
856 r5 :: c_ptr
857 r6 :: i64
858 r7 :: bit
859 L0:
860 r0 = x & 1
861 r1 = r0 == 0
862 if r1 goto L1 else goto L2 :: bool
863 L1:
864 r2 = x >> 1
865 r3 = r2
866 goto L3
867 L2:
868 r4 = x ^ 1
869 r5 = r4
870 r6 = CPyLong_AsInt64(r5)
871 r3 = r6
872 keep_alive x
873 L3:
874 r7 = r3 == y
875 return r7
876
877 [case testI64MixedCompare2_64bit]
878 from mypy_extensions import i64
879 def f(x: i64, y: int) -> bool:
880 return x == y
881 [out]
882 def f(x, y):
883 x :: i64
884 y :: int
885 r0 :: native_int
886 r1 :: bit
887 r2, r3 :: i64
888 r4 :: ptr
889 r5 :: c_ptr
890 r6 :: i64
891 r7 :: bit
892 L0:
893 r0 = y & 1
894 r1 = r0 == 0
895 if r1 goto L1 else goto L2 :: bool
896 L1:
897 r2 = y >> 1
898 r3 = r2
899 goto L3
900 L2:
901 r4 = y ^ 1
902 r5 = r4
903 r6 = CPyLong_AsInt64(r5)
904 r3 = r6
905 keep_alive y
906 L3:
907 r7 = x == r3
908 return r7
909
910 [case testI64MixedCompare_32bit]
911 from mypy_extensions import i64
912 def f(x: int, y: i64) -> bool:
913 return x == y
914 [out]
915 def f(x, y):
916 x :: int
917 y :: i64
918 r0 :: native_int
919 r1 :: bit
920 r2, r3, r4 :: i64
921 r5 :: ptr
922 r6 :: c_ptr
923 r7 :: i64
924 r8 :: bit
925 L0:
926 r0 = x & 1
927 r1 = r0 == 0
928 if r1 goto L1 else goto L2 :: bool
929 L1:
930 r2 = extend signed x: builtins.int to i64
931 r3 = r2 >> 1
932 r4 = r3
933 goto L3
934 L2:
935 r5 = x ^ 1
936 r6 = r5
937 r7 = CPyLong_AsInt64(r6)
938 r4 = r7
939 keep_alive x
940 L3:
941 r8 = r4 == y
942 return r8
943
944 [case testI64AsBool]
945 from mypy_extensions import i64
946 def f(x: i64) -> i64:
947 if x:
948 return 5
949 elif not x:
950 return 6
951 return 3
952 def unary_not(x: i64) -> bool:
953 return not x
954 [out]
955 def f(x):
956 x :: i64
957 r0, r1 :: bit
958 L0:
959 r0 = x != 0
960 if r0 goto L1 else goto L2 :: bool
961 L1:
962 return 5
963 L2:
964 r1 = x != 0
965 if r1 goto L4 else goto L3 :: bool
966 L3:
967 return 6
968 L4:
969 L5:
970 return 3
971 def unary_not(x):
972 x :: i64
973 r0 :: bit
974 L0:
975 r0 = x == 0
976 return r0
977
978 [case testI64AssignMixed_64bit]
979 from mypy_extensions import i64
980 def f(x: i64, y: int) -> i64:
981 x = y
982 return x
983 def g(x: i64, y: int) -> int:
984 y = x
985 return y
986 [out]
987 def f(x, y):
988 x :: i64
989 y :: int
990 r0 :: native_int
991 r1 :: bit
992 r2, r3 :: i64
993 r4 :: ptr
994 r5 :: c_ptr
995 r6 :: i64
996 L0:
997 r0 = y & 1
998 r1 = r0 == 0
999 if r1 goto L1 else goto L2 :: bool
1000 L1:
1001 r2 = y >> 1
1002 r3 = r2
1003 goto L3
1004 L2:
1005 r4 = y ^ 1
1006 r5 = r4
1007 r6 = CPyLong_AsInt64(r5)
1008 r3 = r6
1009 keep_alive y
1010 L3:
1011 x = r3
1012 return x
1013 def g(x, y):
1014 x :: i64
1015 y :: int
1016 r0, r1 :: bit
1017 r2, r3, r4 :: int
1018 L0:
1019 r0 = x <= 4611686018427387903 :: signed
1020 if r0 goto L1 else goto L2 :: bool
1021 L1:
1022 r1 = x >= -4611686018427387904 :: signed
1023 if r1 goto L3 else goto L2 :: bool
1024 L2:
1025 r2 = CPyTagged_FromInt64(x)
1026 r3 = r2
1027 goto L4
1028 L3:
1029 r4 = x << 1
1030 r3 = r4
1031 L4:
1032 y = r3
1033 return y
1034
1035 [case testBorrowOverI64Arithmetic_withgil]
1036 from mypy_extensions import i64
1037
1038 def add_simple(c: C) -> i64:
1039 return c.x + c.y
1040
1041 def inplace_add_simple(c: C) -> None:
1042 c.x += c.y
1043
1044 def add_borrow(d: D) -> i64:
1045 return d.c.x + d.c.y
1046
1047 class D:
1048 c: C
1049
1050 class C:
1051 x: i64
1052 y: i64
1053 [out]
1054 def add_simple(c):
1055 c :: __main__.C
1056 r0, r1, r2 :: i64
1057 L0:
1058 r0 = c.x
1059 r1 = c.y
1060 r2 = r0 + r1
1061 return r2
1062 def inplace_add_simple(c):
1063 c :: __main__.C
1064 r0, r1, r2 :: i64
1065 r3 :: bool
1066 L0:
1067 r0 = c.x
1068 r1 = c.y
1069 r2 = r0 + r1
1070 c.x = r2; r3 = is_error
1071 return 1
1072 def add_borrow(d):
1073 d :: __main__.D
1074 r0 :: __main__.C
1075 r1 :: i64
1076 r2 :: __main__.C
1077 r3, r4 :: i64
1078 L0:
1079 r0 = borrow d.c
1080 r1 = r0.x
1081 r2 = borrow d.c
1082 r3 = r2.y
1083 r4 = r1 + r3
1084 keep_alive d, d
1085 return r4
1086
1087 [case testBorrowOverI64Bitwise_withgil]
1088 from mypy_extensions import i64
1089
1090 def bitwise_simple(c: C) -> i64:
1091 return c.x | c.y
1092
1093 def inplace_bitwide_simple(c: C) -> None:
1094 c.x &= c.y
1095
1096 def bitwise_borrow(d: D) -> i64:
1097 return d.c.x ^ d.c.y
1098
1099 class D:
1100 c: C
1101
1102 class C:
1103 x: i64
1104 y: i64
1105 [out]
1106 def bitwise_simple(c):
1107 c :: __main__.C
1108 r0, r1, r2 :: i64
1109 L0:
1110 r0 = c.x
1111 r1 = c.y
1112 r2 = r0 | r1
1113 return r2
1114 def inplace_bitwide_simple(c):
1115 c :: __main__.C
1116 r0, r1, r2 :: i64
1117 r3 :: bool
1118 L0:
1119 r0 = c.x
1120 r1 = c.y
1121 r2 = r0 & r1
1122 c.x = r2; r3 = is_error
1123 return 1
1124 def bitwise_borrow(d):
1125 d :: __main__.D
1126 r0 :: __main__.C
1127 r1 :: i64
1128 r2 :: __main__.C
1129 r3, r4 :: i64
1130 L0:
1131 r0 = borrow d.c
1132 r1 = r0.x
1133 r2 = borrow d.c
1134 r3 = r2.y
1135 r4 = r1 ^ r3
1136 keep_alive d, d
1137 return r4
1138
1139 [case testBorrowOverI64ListGetItem1_withgil]
1140 from mypy_extensions import i64
1141
1142 def f(n: i64) -> str:
1143 a = [C()]
1144 return a[n].s
1145
1146 class C:
1147 s: str
1148 [out]
1149 def f(n):
1150 n :: i64
1151 r0 :: __main__.C
1152 r1 :: list
1153 r2 :: ptr
1154 a :: list
1155 r3 :: object
1156 r4 :: __main__.C
1157 r5 :: str
1158 L0:
1159 r0 = C()
1160 r1 = PyList_New(1)
1161 r2 = list_items r1
1162 buf_init_item r2, 0, r0
1163 keep_alive r1
1164 a = r1
1165 r3 = CPyList_GetItemInt64Borrow(a, n)
1166 r4 = borrow cast(__main__.C, r3)
1167 r5 = r4.s
1168 keep_alive a, n, r3
1169 return r5
1170
1171 [case testBorrowOverI64ListGetItem1_nogil]
1172 from mypy_extensions import i64
1173
1174 def f(n: i64) -> str:
1175 a = [C()]
1176 return a[n].s
1177
1178 class C:
1179 s: str
1180 [out]
1181 def f(n):
1182 n :: i64
1183 r0 :: __main__.C
1184 r1 :: list
1185 r2 :: ptr
1186 a :: list
1187 r3 :: object
1188 r4 :: __main__.C
1189 r5 :: str
1190 L0:
1191 r0 = C()
1192 r1 = PyList_New(1)
1193 r2 = list_items r1
1194 buf_init_item r2, 0, r0
1195 keep_alive r1
1196 a = r1
1197 r3 = CPyList_GetItemInt64(a, n)
1198 r4 = cast(__main__.C, r3)
1199 r5 = r4.s
1200 return r5
1201
1202 [case testBorrowOverI64ListGetItem2_withgil]
1203 from typing import List
1204 from mypy_extensions import i64
1205
1206 def f(a: List[i64], n: i64) -> bool:
1207 if a[n] == 0:
1208 return True
1209 return False
1210 [out]
1211 def f(a, n):
1212 a :: list
1213 n :: i64
1214 r0 :: object
1215 r1 :: i64
1216 r2 :: bit
1217 L0:
1218 r0 = CPyList_GetItemInt64Borrow(a, n)
1219 r1 = unbox(i64, r0)
1220 r2 = r1 == 0
1221 keep_alive a, n
1222 if r2 goto L1 else goto L2 :: bool
1223 L1:
1224 return 1
1225 L2:
1226 return 0
1227
1228 [case testBorrowOverI64ListGetItem2_nogil]
1229 from typing import List
1230 from mypy_extensions import i64
1231
1232 def f(a: List[i64], n: i64) -> bool:
1233 if a[n] == 0:
1234 return True
1235 return False
1236 [out]
1237 def f(a, n):
1238 a :: list
1239 n :: i64
1240 r0 :: object
1241 r1 :: i64
1242 r2 :: bit
1243 L0:
1244 r0 = CPyList_GetItemInt64(a, n)
1245 r1 = unbox(i64, r0)
1246 r2 = r1 == 0
1247 if r2 goto L1 else goto L2 :: bool
1248 L1:
1249 return 1
1250 L2:
1251 return 0
1252
1253 [case testCoerceShortIntToI64]
1254 from mypy_extensions import i64
1255 from typing import List
1256
1257 def f(a: List[i64], y: i64) -> bool:
1258 if len(a) < y:
1259 return True
1260 return False
1261
1262 def g(a: List[i64], y: i64) -> bool:
1263 if y < len(a):
1264 return True
1265 return False
1266 [out]
1267 def f(a, y):
1268 a :: list
1269 y :: i64
1270 r0 :: native_int
1271 r1 :: short_int
1272 r2 :: i64
1273 r3 :: bit
1274 L0:
1275 r0 = var_object_size a
1276 r1 = r0 << 1
1277 r2 = r1 >> 1
1278 r3 = r2 < y :: signed
1279 if r3 goto L1 else goto L2 :: bool
1280 L1:
1281 return 1
1282 L2:
1283 return 0
1284 def g(a, y):
1285 a :: list
1286 y :: i64
1287 r0 :: native_int
1288 r1 :: short_int
1289 r2 :: i64
1290 r3 :: bit
1291 L0:
1292 r0 = var_object_size a
1293 r1 = r0 << 1
1294 r2 = r1 >> 1
1295 r3 = y < r2 :: signed
1296 if r3 goto L1 else goto L2 :: bool
1297 L1:
1298 return 1
1299 L2:
1300 return 0
1301
1302 [case testMultiplyListByI64_64bit]
1303 from mypy_extensions import i64
1304 from typing import List
1305
1306 def f(n: i64) -> List[i64]:
1307 return [n] * n
1308 [out]
1309 def f(n):
1310 n :: i64
1311 r0 :: list
1312 r1 :: object
1313 r2 :: ptr
1314 r3, r4 :: bit
1315 r5, r6, r7 :: int
1316 r8 :: list
1317 L0:
1318 r0 = PyList_New(1)
1319 r1 = box(i64, n)
1320 r2 = list_items r0
1321 buf_init_item r2, 0, r1
1322 keep_alive r0
1323 r3 = n <= 4611686018427387903 :: signed
1324 if r3 goto L1 else goto L2 :: bool
1325 L1:
1326 r4 = n >= -4611686018427387904 :: signed
1327 if r4 goto L3 else goto L2 :: bool
1328 L2:
1329 r5 = CPyTagged_FromInt64(n)
1330 r6 = r5
1331 goto L4
1332 L3:
1333 r7 = n << 1
1334 r6 = r7
1335 L4:
1336 r8 = CPySequence_Multiply(r0, r6)
1337 return r8
1338
1339 [case testShortIntAndI64Op]
1340 from mypy_extensions import i64
1341 from typing import List
1342
1343 def add_i64(a: List[i64], n: i64) -> i64:
1344 return len(a) + n
1345 def add_i64_2(a: List[i64], n: i64) -> i64:
1346 return n + len(a)
1347 def eq_i64(a: List[i64], n: i64) -> bool:
1348 if len(a) == n:
1349 return True
1350 return False
1351 def lt_i64(a: List[i64], n: i64) -> bool:
1352 if n < len(a):
1353 return True
1354 return False
1355 [out]
1356 def add_i64(a, n):
1357 a :: list
1358 n :: i64
1359 r0 :: native_int
1360 r1 :: short_int
1361 r2, r3 :: i64
1362 L0:
1363 r0 = var_object_size a
1364 r1 = r0 << 1
1365 r2 = r1 >> 1
1366 r3 = r2 + n
1367 return r3
1368 def add_i64_2(a, n):
1369 a :: list
1370 n :: i64
1371 r0 :: native_int
1372 r1 :: short_int
1373 r2, r3 :: i64
1374 L0:
1375 r0 = var_object_size a
1376 r1 = r0 << 1
1377 r2 = r1 >> 1
1378 r3 = n + r2
1379 return r3
1380 def eq_i64(a, n):
1381 a :: list
1382 n :: i64
1383 r0 :: native_int
1384 r1 :: short_int
1385 r2 :: i64
1386 r3 :: bit
1387 L0:
1388 r0 = var_object_size a
1389 r1 = r0 << 1
1390 r2 = r1 >> 1
1391 r3 = r2 == n
1392 if r3 goto L1 else goto L2 :: bool
1393 L1:
1394 return 1
1395 L2:
1396 return 0
1397 def lt_i64(a, n):
1398 a :: list
1399 n :: i64
1400 r0 :: native_int
1401 r1 :: short_int
1402 r2 :: i64
1403 r3 :: bit
1404 L0:
1405 r0 = var_object_size a
1406 r1 = r0 << 1
1407 r2 = r1 >> 1
1408 r3 = n < r2 :: signed
1409 if r3 goto L1 else goto L2 :: bool
1410 L1:
1411 return 1
1412 L2:
1413 return 0
1414
1415 [case testOptionalI64_64bit]
1416 from typing import Optional
1417 from mypy_extensions import i64
1418
1419 def f(x: Optional[i64]) -> i64:
1420 if x is None:
1421 return 1
1422 return x
1423 [out]
1424 def f(x):
1425 x :: union[i64, None]
1426 r0 :: object
1427 r1 :: bit
1428 r2 :: i64
1429 L0:
1430 r0 = load_address _Py_NoneStruct
1431 r1 = x == r0
1432 if r1 goto L1 else goto L2 :: bool
1433 L1:
1434 return 1
1435 L2:
1436 r2 = unbox(i64, x)
1437 return r2
1438
1439 [case testI64DefaultValueSingle]
1440 from mypy_extensions import i64
1441
1442 def f(x: i64, y: i64 = 0) -> i64:
1443 return x + y
1444
1445 def g() -> i64:
1446 return f(7) + f(8, 9)
1447 [out]
1448 def f(x, y, __bitmap):
1449 x, y :: i64
1450 __bitmap, r0 :: u32
1451 r1 :: bit
1452 r2 :: i64
1453 L0:
1454 r0 = __bitmap & 1
1455 r1 = r0 == 0
1456 if r1 goto L1 else goto L2 :: bool
1457 L1:
1458 y = 0
1459 L2:
1460 r2 = x + y
1461 return r2
1462 def g():
1463 r0, r1, r2 :: i64
1464 L0:
1465 r0 = f(7, 0, 0)
1466 r1 = f(8, 9, 1)
1467 r2 = r0 + r1
1468 return r2
1469
1470 [case testI64DefaultValueWithMultipleArgs]
1471 from mypy_extensions import i64
1472
1473 def f(a: i64, b: i64 = 1, c: int = 2, d: i64 = 3) -> i64:
1474 return 0
1475
1476 def g() -> i64:
1477 return f(7) + f(8, 9) + f(1, 2, 3) + f(4, 5, 6, 7)
1478 [out]
1479 def f(a, b, c, d, __bitmap):
1480 a, b :: i64
1481 c :: int
1482 d :: i64
1483 __bitmap, r0 :: u32
1484 r1 :: bit
1485 r2 :: u32
1486 r3 :: bit
1487 L0:
1488 r0 = __bitmap & 1
1489 r1 = r0 == 0
1490 if r1 goto L1 else goto L2 :: bool
1491 L1:
1492 b = 1
1493 L2:
1494 if is_error(c) goto L3 else goto L4
1495 L3:
1496 c = 4
1497 L4:
1498 r2 = __bitmap & 2
1499 r3 = r2 == 0
1500 if r3 goto L5 else goto L6 :: bool
1501 L5:
1502 d = 3
1503 L6:
1504 return 0
1505 def g():
1506 r0 :: int
1507 r1 :: i64
1508 r2 :: int
1509 r3, r4, r5, r6, r7, r8 :: i64
1510 L0:
1511 r0 = <error> :: int
1512 r1 = f(7, 0, r0, 0, 0)
1513 r2 = <error> :: int
1514 r3 = f(8, 9, r2, 0, 1)
1515 r4 = r1 + r3
1516 r5 = f(1, 2, 6, 0, 1)
1517 r6 = r4 + r5
1518 r7 = f(4, 5, 12, 7, 3)
1519 r8 = r6 + r7
1520 return r8
1521
1522 [case testI64MethodDefaultValue]
1523 from mypy_extensions import i64
1524
1525 class C:
1526 def m(self, x: i64 = 5) -> None:
1527 pass
1528
1529 def f(c: C) -> None:
1530 c.m()
1531 c.m(6)
1532 [out]
1533 def C.m(self, x, __bitmap):
1534 self :: __main__.C
1535 x :: i64
1536 __bitmap, r0 :: u32
1537 r1 :: bit
1538 L0:
1539 r0 = __bitmap & 1
1540 r1 = r0 == 0
1541 if r1 goto L1 else goto L2 :: bool
1542 L1:
1543 x = 5
1544 L2:
1545 return 1
1546 def f(c):
1547 c :: __main__.C
1548 r0, r1 :: None
1549 L0:
1550 r0 = c.m(0, 0)
1551 r1 = c.m(6, 1)
1552 return 1
1553
1554 [case testI64ExplicitConversionFromNativeInt]
1555 from mypy_extensions import i64, i32, i16
1556
1557 def from_i16(x: i16) -> i64:
1558 return i64(x)
1559
1560 def from_i32(x: i32) -> i64:
1561 return i64(x)
1562
1563 def from_i64(x: i64) -> i64:
1564 return i64(x)
1565 [out]
1566 def from_i16(x):
1567 x :: i16
1568 r0 :: i64
1569 L0:
1570 r0 = extend signed x: i16 to i64
1571 return r0
1572 def from_i32(x):
1573 x :: i32
1574 r0 :: i64
1575 L0:
1576 r0 = extend signed x: i32 to i64
1577 return r0
1578 def from_i64(x):
1579 x :: i64
1580 L0:
1581 return x
1582
1583 [case testI64ExplicitConversionFromInt_64bit]
1584 from mypy_extensions import i64
1585
1586 def f(x: int) -> i64:
1587 return i64(x)
1588 [out]
1589 def f(x):
1590 x :: int
1591 r0 :: native_int
1592 r1 :: bit
1593 r2, r3 :: i64
1594 r4 :: ptr
1595 r5 :: c_ptr
1596 r6 :: i64
1597 L0:
1598 r0 = x & 1
1599 r1 = r0 == 0
1600 if r1 goto L1 else goto L2 :: bool
1601 L1:
1602 r2 = x >> 1
1603 r3 = r2
1604 goto L3
1605 L2:
1606 r4 = x ^ 1
1607 r5 = r4
1608 r6 = CPyLong_AsInt64(r5)
1609 r3 = r6
1610 keep_alive x
1611 L3:
1612 return r3
1613
1614 [case testI64ExplicitConversionToInt_64bit]
1615 from mypy_extensions import i64
1616
1617 def f(x: i64) -> int:
1618 return int(x)
1619 [out]
1620 def f(x):
1621 x :: i64
1622 r0, r1 :: bit
1623 r2, r3, r4 :: int
1624 L0:
1625 r0 = x <= 4611686018427387903 :: signed
1626 if r0 goto L1 else goto L2 :: bool
1627 L1:
1628 r1 = x >= -4611686018427387904 :: signed
1629 if r1 goto L3 else goto L2 :: bool
1630 L2:
1631 r2 = CPyTagged_FromInt64(x)
1632 r3 = r2
1633 goto L4
1634 L3:
1635 r4 = x << 1
1636 r3 = r4
1637 L4:
1638 return r3
1639
1640 [case testI64ExplicitConversionFromLiteral]
1641 from mypy_extensions import i64
1642
1643 def f() -> None:
1644 x = i64(0)
1645 y = i64(11)
1646 z = i64(-3)
1647 [out]
1648 def f():
1649 x, y, z :: i64
1650 L0:
1651 x = 0
1652 y = 11
1653 z = -3
1654 return 1
1655
1656 [case testI64ForLoopOverRange]
1657 from mypy_extensions import i64
1658
1659 def f() -> None:
1660 for x in range(i64(4)):
1661 y = x
1662 [out]
1663 def f():
1664 r0, x :: i64
1665 r1 :: bit
1666 y, r2 :: i64
1667 L0:
1668 r0 = 0
1669 x = r0
1670 L1:
1671 r1 = r0 < 4 :: signed
1672 if r1 goto L2 else goto L4 :: bool
1673 L2:
1674 x = r0
1675 y = x
1676 L3:
1677 r2 = r0 + 1
1678 r0 = r2
1679 goto L1
1680 L4:
1681 return 1
1682
1683 [case testI64ForLoopOverRange2]
1684 from mypy_extensions import i64
1685
1686 def f() -> None:
1687 for x in range(0, i64(4)):
1688 y = x
1689 [out]
1690 def f():
1691 r0, x :: i64
1692 r1 :: bit
1693 y, r2 :: i64
1694 L0:
1695 r0 = 0
1696 x = r0
1697 L1:
1698 r1 = r0 < 4 :: signed
1699 if r1 goto L2 else goto L4 :: bool
1700 L2:
1701 x = r0
1702 y = x
1703 L3:
1704 r2 = r0 + 1
1705 r0 = r2
1706 goto L1
1707 L4:
1708 return 1
1709
1710 [case testI64MethodDefaultValueOverride]
1711 from mypy_extensions import i64
1712
1713 class C:
1714 def f(self, x: i64 = 11) -> None: pass
1715 class D(C):
1716 def f(self, x: i64 = 12) -> None: pass
1717 [out]
1718 def C.f(self, x, __bitmap):
1719 self :: __main__.C
1720 x :: i64
1721 __bitmap, r0 :: u32
1722 r1 :: bit
1723 L0:
1724 r0 = __bitmap & 1
1725 r1 = r0 == 0
1726 if r1 goto L1 else goto L2 :: bool
1727 L1:
1728 x = 11
1729 L2:
1730 return 1
1731 def D.f(self, x, __bitmap):
1732 self :: __main__.D
1733 x :: i64
1734 __bitmap, r0 :: u32
1735 r1 :: bit
1736 L0:
1737 r0 = __bitmap & 1
1738 r1 = r0 == 0
1739 if r1 goto L1 else goto L2 :: bool
1740 L1:
1741 x = 12
1742 L2:
1743 return 1
1744
1745 [case testI64FinalConstants]
1746 from typing import Final
1747 from mypy_extensions import i64
1748
1749 A: Final = -1
1750 B: Final = -(1 + 3*2)
1751 C: Final = 0
1752 D: Final = A - B
1753 E: Final[i64] = 1 + 3
1754
1755 def f1() -> i64:
1756 return A
1757
1758 def f2() -> i64:
1759 return A + B
1760
1761 def f3() -> i64:
1762 return C
1763
1764 def f4() -> i64:
1765 return D
1766
1767 def f5() -> i64:
1768 return E
1769 [out]
1770 def f1():
1771 L0:
1772 return -1
1773 def f2():
1774 L0:
1775 return -8
1776 def f3():
1777 L0:
1778 return 0
1779 def f4():
1780 L0:
1781 return 6
1782 def f5():
1783 L0:
1784 return 4
1785
1786 [case testI64OperationsWithBools]
1787 from mypy_extensions import i64
1788
1789 # TODO: Other mixed operations
1790
1791 def add_bool_to_int(n: i64, b: bool) -> i64:
1792 return n + b
1793
1794 def compare_bool_to_i64(n: i64, b: bool) -> bool:
1795 if n == b:
1796 return b != n
1797 return True
1798 [out]
1799 def add_bool_to_int(n, b):
1800 n :: i64
1801 b :: bool
1802 r0, r1 :: i64
1803 L0:
1804 r0 = extend b: builtins.bool to i64
1805 r1 = n + r0
1806 return r1
1807 def compare_bool_to_i64(n, b):
1808 n :: i64
1809 b :: bool
1810 r0 :: i64
1811 r1 :: bit
1812 r2 :: i64
1813 r3 :: bit
1814 L0:
1815 r0 = extend b: builtins.bool to i64
1816 r1 = n == r0
1817 if r1 goto L1 else goto L2 :: bool
1818 L1:
1819 r2 = extend b: builtins.bool to i64
1820 r3 = r2 != n
1821 return r3
1822 L2:
1823 return 1
1824
1825 [case testI64Cast_64bit]
1826 from typing import cast
1827 from mypy_extensions import i64
1828
1829 def cast_object(o: object) -> i64:
1830 return cast(i64, o)
1831
1832 def cast_int(x: int) -> i64:
1833 return cast(i64, x)
1834 [out]
1835 def cast_object(o):
1836 o :: object
1837 r0 :: i64
1838 L0:
1839 r0 = unbox(i64, o)
1840 return r0
1841 def cast_int(x):
1842 x :: int
1843 r0 :: native_int
1844 r1 :: bit
1845 r2, r3 :: i64
1846 r4 :: ptr
1847 r5 :: c_ptr
1848 r6 :: i64
1849 L0:
1850 r0 = x & 1
1851 r1 = r0 == 0
1852 if r1 goto L1 else goto L2 :: bool
1853 L1:
1854 r2 = x >> 1
1855 r3 = r2
1856 goto L3
1857 L2:
1858 r4 = x ^ 1
1859 r5 = r4
1860 r6 = CPyLong_AsInt64(r5)
1861 r3 = r6
1862 keep_alive x
1863 L3:
1864 return r3
1865
1866 [case testI64Cast_32bit]
1867 from typing import cast
1868 from mypy_extensions import i64
1869
1870 def cast_int(x: int) -> i64:
1871 return cast(i64, x)
1872 [out]
1873 def cast_int(x):
1874 x :: int
1875 r0 :: native_int
1876 r1 :: bit
1877 r2, r3, r4 :: i64
1878 r5 :: ptr
1879 r6 :: c_ptr
1880 r7 :: i64
1881 L0:
1882 r0 = x & 1
1883 r1 = r0 == 0
1884 if r1 goto L1 else goto L2 :: bool
1885 L1:
1886 r2 = extend signed x: builtins.int to i64
1887 r3 = r2 >> 1
1888 r4 = r3
1889 goto L3
1890 L2:
1891 r5 = x ^ 1
1892 r6 = r5
1893 r7 = CPyLong_AsInt64(r6)
1894 r4 = r7
1895 keep_alive x
1896 L3:
1897 return r4
1898
1899 [case testI64ExplicitConversionFromVariousTypes_64bit]
1900 from mypy_extensions import i64
1901
1902 def bool_to_i64(b: bool) -> i64:
1903 return i64(b)
1904
1905 def str_to_i64(s: str) -> i64:
1906 return i64(s)
1907
1908 def str_to_i64_with_base(s: str) -> i64:
1909 return i64(s, 2)
1910
1911 class C:
1912 def __int__(self) -> i64:
1913 return 5
1914
1915 def instance_to_i64(c: C) -> i64:
1916 return i64(c)
1917
1918 def float_to_i64(x: float) -> i64:
1919 return i64(x)
1920 [out]
1921 def bool_to_i64(b):
1922 b :: bool
1923 r0 :: i64
1924 L0:
1925 r0 = extend b: builtins.bool to i64
1926 return r0
1927 def str_to_i64(s):
1928 s :: str
1929 r0 :: object
1930 r1 :: i64
1931 L0:
1932 r0 = CPyLong_FromStr(s)
1933 r1 = unbox(i64, r0)
1934 return r1
1935 def str_to_i64_with_base(s):
1936 s :: str
1937 r0 :: object
1938 r1 :: i64
1939 L0:
1940 r0 = CPyLong_FromStrWithBase(s, 4)
1941 r1 = unbox(i64, r0)
1942 return r1
1943 def C.__int__(self):
1944 self :: __main__.C
1945 L0:
1946 return 5
1947 def instance_to_i64(c):
1948 c :: __main__.C
1949 r0 :: i64
1950 L0:
1951 r0 = c.__int__()
1952 return r0
1953 def float_to_i64(x):
1954 x :: float
1955 r0 :: int
1956 r1 :: native_int
1957 r2 :: bit
1958 r3, r4 :: i64
1959 r5 :: ptr
1960 r6 :: c_ptr
1961 r7 :: i64
1962 L0:
1963 r0 = CPyTagged_FromFloat(x)
1964 r1 = r0 & 1
1965 r2 = r1 == 0
1966 if r2 goto L1 else goto L2 :: bool
1967 L1:
1968 r3 = r0 >> 1
1969 r4 = r3
1970 goto L3
1971 L2:
1972 r5 = r0 ^ 1
1973 r6 = r5
1974 r7 = CPyLong_AsInt64(r6)
1975 r4 = r7
1976 keep_alive r0
1977 L3:
1978 return r4
1979
1980 [case testI64ExplicitConversionFromFloat_32bit]
1981 from mypy_extensions import i64
1982
1983 def float_to_i64(x: float) -> i64:
1984 return i64(x)
1985 [out]
1986 def float_to_i64(x):
1987 x :: float
1988 r0 :: int
1989 r1 :: native_int
1990 r2 :: bit
1991 r3, r4, r5 :: i64
1992 r6 :: ptr
1993 r7 :: c_ptr
1994 r8 :: i64
1995 L0:
1996 r0 = CPyTagged_FromFloat(x)
1997 r1 = r0 & 1
1998 r2 = r1 == 0
1999 if r2 goto L1 else goto L2 :: bool
2000 L1:
2001 r3 = extend signed r0: builtins.int to i64
2002 r4 = r3 >> 1
2003 r5 = r4
2004 goto L3
2005 L2:
2006 r6 = r0 ^ 1
2007 r7 = r6
2008 r8 = CPyLong_AsInt64(r7)
2009 r5 = r8
2010 keep_alive r0
2011 L3:
2012 return r5
2013
2014 [case testI64ConvertToFloat_64bit]
2015 from mypy_extensions import i64
2016
2017 def i64_to_float(x: i64) -> float:
2018 return float(x)
2019 [out]
2020 def i64_to_float(x):
2021 x :: i64
2022 r0, r1 :: bit
2023 r2, r3, r4 :: int
2024 r5 :: float
2025 L0:
2026 r0 = x <= 4611686018427387903 :: signed
2027 if r0 goto L1 else goto L2 :: bool
2028 L1:
2029 r1 = x >= -4611686018427387904 :: signed
2030 if r1 goto L3 else goto L2 :: bool
2031 L2:
2032 r2 = CPyTagged_FromInt64(x)
2033 r3 = r2
2034 goto L4
2035 L3:
2036 r4 = x << 1
2037 r3 = r4
2038 L4:
2039 r5 = CPyFloat_FromTagged(r3)
2040 return r5
2041
2042 [case testI64ConvertToFloat_32bit]
2043 from mypy_extensions import i64
2044
2045 def i64_to_float(x: i64) -> float:
2046 return float(x)
2047 [out]
2048 def i64_to_float(x):
2049 x :: i64
2050 r0, r1 :: bit
2051 r2, r3 :: int
2052 r4 :: native_int
2053 r5 :: int
2054 r6 :: float
2055 L0:
2056 r0 = x <= 1073741823 :: signed
2057 if r0 goto L1 else goto L2 :: bool
2058 L1:
2059 r1 = x >= -1073741824 :: signed
2060 if r1 goto L3 else goto L2 :: bool
2061 L2:
2062 r2 = CPyTagged_FromInt64(x)
2063 r3 = r2
2064 goto L4
2065 L3:
2066 r4 = truncate x: i64 to native_int
2067 r5 = r4 << 1
2068 r3 = r5
2069 L4:
2070 r6 = CPyFloat_FromTagged(r3)
2071 return r6
2072
2073 [case testI64IsinstanceNarrowing_withgil]
2074 from typing import Union
2075 from mypy_extensions import i64
2076
2077 class C:
2078 a: i64
2079
2080 def narrow1(x: Union[C, i64]) -> i64:
2081 if isinstance(x, i64):
2082 return x
2083 return x.a
2084
2085 def narrow2(x: Union[C, i64]) -> i64:
2086 if isinstance(x, int):
2087 return x
2088 return x.a
2089 [out]
2090 def narrow1(x):
2091 x :: union[__main__.C, i64]
2092 r0 :: object
2093 r1 :: i32
2094 r2 :: bit
2095 r3 :: bool
2096 r4 :: i64
2097 r5 :: __main__.C
2098 r6 :: i64
2099 L0:
2100 r0 = load_address PyLong_Type
2101 r1 = PyObject_IsInstance(x, r0)
2102 r2 = r1 >= 0 :: signed
2103 r3 = truncate r1: i32 to builtins.bool
2104 if r3 goto L1 else goto L2 :: bool
2105 L1:
2106 r4 = unbox(i64, x)
2107 return r4
2108 L2:
2109 r5 = borrow cast(__main__.C, x)
2110 r6 = r5.a
2111 keep_alive x
2112 return r6
2113 def narrow2(x):
2114 x :: union[__main__.C, i64]
2115 r0 :: bit
2116 r1 :: i64
2117 r2 :: __main__.C
2118 r3 :: i64
2119 L0:
2120 r0 = PyLong_Check(x)
2121 if r0 goto L1 else goto L2 :: bool
2122 L1:
2123 r1 = unbox(i64, x)
2124 return r1
2125 L2:
2126 r2 = borrow cast(__main__.C, x)
2127 r3 = r2.a
2128 keep_alive x
2129 return r3
2130
2131 [case testI64ConvertBetweenTuples_64bit]
2132 from __future__ import annotations
2133 from mypy_extensions import i64
2134
2135 def f(t: tuple[int, i64, int]) -> None:
2136 tt: tuple[int, i64, i64] = t
2137
2138 def g(n: int) -> None:
2139 t: tuple[i64, i64] = (1, n)
2140 [out]
2141 def f(t):
2142 t :: tuple[int, i64, int]
2143 r0 :: int
2144 r1 :: i64
2145 r2 :: int
2146 r3 :: native_int
2147 r4 :: bit
2148 r5, r6 :: i64
2149 r7 :: ptr
2150 r8 :: c_ptr
2151 r9 :: i64
2152 r10, tt :: tuple[int, i64, i64]
2153 L0:
2154 r0 = t[0]
2155 r1 = t[1]
2156 r2 = t[2]
2157 r3 = r2 & 1
2158 r4 = r3 == 0
2159 if r4 goto L1 else goto L2 :: bool
2160 L1:
2161 r5 = r2 >> 1
2162 r6 = r5
2163 goto L3
2164 L2:
2165 r7 = r2 ^ 1
2166 r8 = r7
2167 r9 = CPyLong_AsInt64(r8)
2168 r6 = r9
2169 keep_alive r2
2170 L3:
2171 r10 = (r0, r1, r6)
2172 tt = r10
2173 return 1
2174 def g(n):
2175 n, r0 :: int
2176 r1 :: tuple[int, int]
2177 r2 :: int
2178 r3 :: native_int
2179 r4 :: bit
2180 r5, r6 :: i64
2181 r7 :: ptr
2182 r8 :: c_ptr
2183 r9 :: i64
2184 r10, t :: tuple[i64, i64]
2185 L0:
2186 r0 = n
2187 r1 = (2, r0)
2188 r2 = r1[1]
2189 r3 = r2 & 1
2190 r4 = r3 == 0
2191 if r4 goto L1 else goto L2 :: bool
2192 L1:
2193 r5 = r2 >> 1
2194 r6 = r5
2195 goto L3
2196 L2:
2197 r7 = r2 ^ 1
2198 r8 = r7
2199 r9 = CPyLong_AsInt64(r8)
2200 r6 = r9
2201 keep_alive r2
2202 L3:
2203 r10 = (1, r6)
2204 t = r10
2205 return 1