@@ -836,44 +836,117 @@ def f(val: bool) -> bool:
836836 return not val
837837
838838def test() -> None:
839- a = tuple((i, x) for i, (_, x) in zip(map(str, range(5)), enumerate(sorted(reversed("abc")))))
839+ # this tuple is created from a very complex genexp but we can still compute the length and preallocate the tuple
840+ a = tuple(
841+ x
842+ for x
843+ in zip(
844+ map(str, range(5)),
845+ enumerate(sorted(reversed(tuple("abcdefg"))))
846+ )
847+ )
840848[out]
841849def f(val):
842850 val, r0 :: bool
843851L0:
844852 r0 = val ^ 1
845853 return r0
846- def test(source):
847- source :: tuple
848- r0 :: native_int
849- r1 :: tuple
850- r2 :: native_int
851- r3 :: bit
852- r4 :: object
853- r5, x, r6 :: bool
854- r7 :: object
855- r8 :: native_int
856- a :: tuple
854+ def test():
855+ r0 :: list
856+ r1, r2, r3 :: object
857+ r4 :: object[1]
858+ r5 :: object_ptr
859+ r6 :: object
860+ r7 :: range
861+ r8 :: object
862+ r9 :: str
863+ r10 :: object
864+ r11 :: object[2]
865+ r12 :: object_ptr
866+ r13 :: object
867+ r14 :: str
868+ r15 :: tuple
869+ r16 :: object
870+ r17 :: str
871+ r18 :: object
872+ r19 :: object[1]
873+ r20 :: object_ptr
874+ r21 :: object
875+ r22 :: list
876+ r23 :: object
877+ r24 :: str
878+ r25 :: object
879+ r26 :: object[1]
880+ r27 :: object_ptr
881+ r28, r29 :: object
882+ r30 :: str
883+ r31 :: object
884+ r32 :: object[2]
885+ r33 :: object_ptr
886+ r34, r35, r36 :: object
887+ r37, x :: tuple[str, tuple[int, str]]
888+ r38 :: object
889+ r39 :: i32
890+ r40, r41 :: bit
891+ r42, a :: tuple
857892L0:
858- r0 = var_object_size source
859- r1 = PyTuple_New(r0)
860- r2 = 0
893+ r0 = PyList_New(0)
894+ r1 = load_address PyUnicode_Type
895+ r2 = load_address PyRange_Type
896+ r3 = object 5
897+ r4 = [r3]
898+ r5 = load_address r4
899+ r6 = PyObject_Vectorcall(r2, r5, 1, 0)
900+ keep_alive r3
901+ r7 = cast(range, r6)
902+ r8 = builtins :: module
903+ r9 = 'map'
904+ r10 = CPyObject_GetAttr(r8, r9)
905+ r11 = [r1, r7]
906+ r12 = load_address r11
907+ r13 = PyObject_Vectorcall(r10, r12, 2, 0)
908+ keep_alive r1, r7
909+ r14 = 'abcdefg'
910+ r15 = PySequence_Tuple(r14)
911+ r16 = builtins :: module
912+ r17 = 'reversed'
913+ r18 = CPyObject_GetAttr(r16, r17)
914+ r19 = [r15]
915+ r20 = load_address r19
916+ r21 = PyObject_Vectorcall(r18, r20, 1, 0)
917+ keep_alive r15
918+ r22 = CPySequence_Sort(r21)
919+ r23 = builtins :: module
920+ r24 = 'enumerate'
921+ r25 = CPyObject_GetAttr(r23, r24)
922+ r26 = [r22]
923+ r27 = load_address r26
924+ r28 = PyObject_Vectorcall(r25, r27, 1, 0)
925+ keep_alive r22
926+ r29 = builtins :: module
927+ r30 = 'zip'
928+ r31 = CPyObject_GetAttr(r29, r30)
929+ r32 = [r13, r28]
930+ r33 = load_address r32
931+ r34 = PyObject_Vectorcall(r31, r33, 2, 0)
932+ keep_alive r13, r28
933+ r35 = PyObject_GetIter(r34)
861934L1:
862- r3 = r2 < r0 :: signed
863- if r3 goto L2 else goto L4 :: bool
935+ r36 = PyIter_Next(r35)
936+ if is_error(r36) goto L4 else goto L2
864937L2:
865- r4 = CPySequenceTuple_GetItemUnsafe(source, r2)
866- r5 = unbox(bool, r4)
867- x = r5
868- r6 = f(x)
869- r7 = box(bool, r6)
870- CPySequenceTuple_SetItemUnsafe(r1, r2, r7)
938+ r37 = unbox(tuple[str, tuple[int, str]], r36)
939+ x = r37
940+ r38 = box(tuple[str, tuple[int, str]], x)
941+ r39 = PyList_Append(r0, r38)
942+ r40 = r39 >= 0 :: signed
871943L3:
872- r8 = r2 + 1
873- r2 = r8
874944 goto L1
875945L4:
876- a = r1
946+ r41 = CPy_NoErrOccurred()
947+ L5:
948+ r42 = PyList_AsTuple(r0)
949+ a = r42
877950 return 1
878951
879952[case testTupleBuiltFromStars]
0 commit comments