Skip to content

Commit bb35146

Browse files
Update irbuild-tuple.test
1 parent 8580c7f commit bb35146

File tree

1 file changed

+41
-6
lines changed

1 file changed

+41
-6
lines changed

mypyc/test-data/irbuild-tuple.test

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -748,13 +748,16 @@ def varint() -> int:
748748
# this helper lets us break constant folding for this test
749749
return 2
750750

751-
source: Final = (1, varint(), 3)
751+
source_final: Final = (1, varint(), 3)
752+
source_var = (1, varint(), 3)
752753

753754
def f(val: int) -> bool:
754755
return val % 2 == 0
755756

756-
def test() -> None:
757-
a = tuple(f(x) for x in source)
757+
def test_final_can_fold() -> None:
758+
a = tuple(f(x) for x in source_final)
759+
def test_var_can_not_fold() -> None:
760+
a = tuple(f(x) for x in source_var)
758761
[out]
759762
def varint():
760763
L0:
@@ -766,7 +769,7 @@ L0:
766769
r0 = CPyTagged_Remainder(val, 4)
767770
r1 = int_eq r0, 0
768771
return r1
769-
def test():
772+
def test_final_can_fold():
770773
r0 :: tuple[int, int, int]
771774
r1 :: bool
772775
r2 :: object
@@ -785,10 +788,10 @@ def test():
785788
r17 :: native_int
786789
a :: tuple
787790
L0:
788-
r0 = __main__.source :: static
791+
r0 = __main__.source_final :: static
789792
if is_error(r0) goto L1 else goto L2
790793
L1:
791-
r1 = raise NameError('value for final name "source" was not set')
794+
r1 = raise NameError('value for final name "source_final" was not set')
792795
unreachable
793796
L2:
794797
r2 = box(tuple[int, int, int], r0)
@@ -818,6 +821,38 @@ L5:
818821
L6:
819822
a = r10
820823
return 1
824+
def test_var_can_not_fold():
825+
source :: tuple
826+
r0 :: native_int
827+
r1 :: tuple
828+
r2 :: native_int
829+
r3 :: bit
830+
r4 :: object
831+
r5, x, r6 :: bool
832+
r7 :: object
833+
r8 :: native_int
834+
a :: tuple
835+
L0:
836+
r0 = var_object_size source
837+
r1 = PyTuple_New(r0)
838+
r2 = 0
839+
L1:
840+
r3 = r2 < r0 :: signed
841+
if r3 goto L2 else goto L4 :: bool
842+
L2:
843+
r4 = CPySequenceTuple_GetItemUnsafe(source, r2)
844+
r5 = unbox(bool, r4)
845+
x = r5
846+
r6 = f(x)
847+
r7 = box(bool, r6)
848+
CPySequenceTuple_SetItemUnsafe(r1, r2, r7)
849+
L3:
850+
r8 = r2 + 1
851+
r2 = r8
852+
goto L1
853+
L4:
854+
a = r1
855+
return 1
821856

822857
[case testTupleBuiltFromVariableLengthTuple]
823858
from typing import Tuple

0 commit comments

Comments
 (0)