@@ -572,3 +572,332 @@ def sort_iterable(a):
572572L0:
573573 r0 = CPySequence_Sort(a)
574574 return 1
575+
576+ [case testListBuiltFromStr]
577+ def f2(val: str) -> str:
578+ return val + "f2"
579+
580+ def test() -> None:
581+ source = "abc"
582+ a = [f2(x) for x in source]
583+ [out]
584+ def f2(val):
585+ val, r0, r1 :: str
586+ L0:
587+ r0 = 'f2'
588+ r1 = PyUnicode_Concat(val, r0)
589+ return r1
590+ def test():
591+ r0, source :: str
592+ r1 :: native_int
593+ r2 :: bit
594+ r3 :: list
595+ r4 :: native_int
596+ r5 :: bit
597+ r6, x, r7 :: str
598+ r8 :: native_int
599+ a :: list
600+ L0:
601+ r0 = 'abc'
602+ source = r0
603+ r1 = CPyStr_Size_size_t(source)
604+ r2 = r1 >= 0 :: signed
605+ r3 = PyList_New(r1)
606+ r4 = 0
607+ L1:
608+ r5 = r4 < r1 :: signed
609+ if r5 goto L2 else goto L4 :: bool
610+ L2:
611+ r6 = CPyStr_GetItemUnsafe(source, r4)
612+ x = r6
613+ r7 = f2(x)
614+ CPyList_SetItemUnsafe(r3, r4, r7)
615+ L3:
616+ r8 = r4 + 1
617+ r4 = r8
618+ goto L1
619+ L4:
620+ a = r3
621+ return 1
622+
623+ [case testListBuiltFromStrExpr]
624+ def f2(val: str) -> str:
625+ return val + "f2"
626+
627+ def test() -> None:
628+ a = [f2(x) for x in "abc"]
629+ [out]
630+ def f2(val):
631+ val, r0, r1 :: str
632+ L0:
633+ r0 = 'f2'
634+ r1 = PyUnicode_Concat(val, r0)
635+ return r1
636+ def test():
637+ r0 :: str
638+ r1 :: list
639+ r2 :: native_int
640+ r3 :: bit
641+ r4, x, r5 :: str
642+ r6 :: native_int
643+ a :: list
644+ L0:
645+ r0 = 'abc'
646+ r1 = PyList_New(3)
647+ r2 = 0
648+ L1:
649+ r3 = r2 < 3 :: signed
650+ if r3 goto L2 else goto L4 :: bool
651+ L2:
652+ r4 = CPyStr_GetItemUnsafe(r0, r2)
653+ x = r4
654+ r5 = f2(x)
655+ CPyList_SetItemUnsafe(r1, r2, r5)
656+ L3:
657+ r6 = r2 + 1
658+ r2 = r6
659+ goto L1
660+ L4:
661+ a = r1
662+ return 1
663+
664+ [case testListBuiltFromFinalStr]
665+ from typing import Final
666+
667+ source: Final = "abc"
668+
669+ def f2(val: str) -> str:
670+ return val + "f2"
671+
672+ def test() -> None:
673+ a = [f2(x) for x in source]
674+ [out]
675+ def f2(val):
676+ val, r0, r1 :: str
677+ L0:
678+ r0 = 'f2'
679+ r1 = PyUnicode_Concat(val, r0)
680+ return r1
681+ def test():
682+ r0 :: str
683+ r1 :: list
684+ r2 :: native_int
685+ r3 :: bit
686+ r4, x, r5 :: str
687+ r6 :: native_int
688+ a :: list
689+ L0:
690+ r0 = 'abc'
691+ r1 = PyList_New(3)
692+ r2 = 0
693+ L1:
694+ r3 = r2 < 3 :: signed
695+ if r3 goto L2 else goto L4 :: bool
696+ L2:
697+ r4 = CPyStr_GetItemUnsafe(r0, r2)
698+ x = r4
699+ r5 = f2(x)
700+ CPyList_SetItemUnsafe(r1, r2, r5)
701+ L3:
702+ r6 = r2 + 1
703+ r2 = r6
704+ goto L1
705+ L4:
706+ a = r1
707+ return 1
708+
709+ [case testListBuiltFromBytes_64bit]
710+ def f2(val: int) -> int:
711+ return val + 2
712+
713+ def test() -> None:
714+ source = b"abc"
715+ a = [f2(x) for x in source]
716+
717+ [out]
718+ def f2(val):
719+ val, r0 :: int
720+ L0:
721+ r0 = CPyTagged_Add(val, 4)
722+ return r0
723+ def test():
724+ r0, source :: bytes
725+ r1 :: native_int
726+ r2 :: list
727+ r3 :: native_int
728+ r4, r5, r6 :: bit
729+ r7, r8, r9, r10 :: int
730+ r11 :: object
731+ r12, x, r13 :: int
732+ r14 :: object
733+ r15 :: native_int
734+ a :: list
735+ L0:
736+ r0 = b'abc'
737+ source = r0
738+ r1 = var_object_size source
739+ r2 = PyList_New(r1)
740+ r3 = 0
741+ L1:
742+ r4 = r3 < r1 :: signed
743+ if r4 goto L2 else goto L8 :: bool
744+ L2:
745+ r5 = r3 <= 4611686018427387903 :: signed
746+ if r5 goto L3 else goto L4 :: bool
747+ L3:
748+ r6 = r3 >= -4611686018427387904 :: signed
749+ if r6 goto L5 else goto L4 :: bool
750+ L4:
751+ r7 = CPyTagged_FromInt64(r3)
752+ r8 = r7
753+ goto L6
754+ L5:
755+ r9 = r3 << 1
756+ r8 = r9
757+ L6:
758+ r10 = CPyBytes_GetItem(source, r8)
759+ r11 = box(int, r10)
760+ r12 = unbox(int, r11)
761+ x = r12
762+ r13 = f2(x)
763+ r14 = box(int, r13)
764+ CPyList_SetItemUnsafe(r2, r3, r14)
765+ L7:
766+ r15 = r3 + 1
767+ r3 = r15
768+ goto L1
769+ L8:
770+ a = r2
771+ return 1
772+
773+ [case testListBuiltFromBytesExpr_64bit]
774+ def f2(val: int) -> int:
775+ return val + 2
776+
777+ def test() -> None:
778+ a = [f2(x) for x in b"abc"]
779+
780+ [out]
781+ def f2(val):
782+ val, r0 :: int
783+ L0:
784+ r0 = CPyTagged_Add(val, 4)
785+ return r0
786+ def test():
787+ r0 :: bytes
788+ r1 :: list
789+ r2 :: native_int
790+ r3, r4, r5 :: bit
791+ r6, r7, r8, r9 :: int
792+ r10 :: object
793+ r11, x, r12 :: int
794+ r13 :: object
795+ r14 :: native_int
796+ a :: list
797+ L0:
798+ r0 = b'abc'
799+ r1 = PyList_New(3)
800+ r2 = 0
801+ L1:
802+ r3 = r2 < 3 :: signed
803+ if r3 goto L2 else goto L8 :: bool
804+ L2:
805+ r4 = r2 <= 4611686018427387903 :: signed
806+ if r4 goto L3 else goto L4 :: bool
807+ L3:
808+ r5 = r2 >= -4611686018427387904 :: signed
809+ if r5 goto L5 else goto L4 :: bool
810+ L4:
811+ r6 = CPyTagged_FromInt64(r2)
812+ r7 = r6
813+ goto L6
814+ L5:
815+ r8 = r2 << 1
816+ r7 = r8
817+ L6:
818+ r9 = CPyBytes_GetItem(r0, r7)
819+ r10 = box(int, r9)
820+ r11 = unbox(int, r10)
821+ x = r11
822+ r12 = f2(x)
823+ r13 = box(int, r12)
824+ CPyList_SetItemUnsafe(r1, r2, r13)
825+ L7:
826+ r14 = r2 + 1
827+ r2 = r14
828+ goto L1
829+ L8:
830+ a = r1
831+ return 1
832+
833+ [case testListBuiltFromFinalBytes_64bit]
834+ from typing import Final
835+
836+ source: Final = b"abc"
837+
838+ def f2(val: int) -> int:
839+ return val + 2
840+
841+ def test() -> None:
842+ a = [f2(x) for x in source]
843+
844+ [out]
845+ def f2(val):
846+ val, r0 :: int
847+ L0:
848+ r0 = CPyTagged_Add(val, 4)
849+ return r0
850+ def test():
851+ r0 :: bytes
852+ r1 :: bool
853+ r2 :: native_int
854+ r3 :: list
855+ r4 :: native_int
856+ r5, r6, r7 :: bit
857+ r8, r9, r10, r11 :: int
858+ r12 :: object
859+ r13, x, r14 :: int
860+ r15 :: object
861+ r16 :: native_int
862+ a :: list
863+ L0:
864+ r0 = __main__.source :: static
865+ if is_error(r0) goto L1 else goto L2
866+ L1:
867+ r1 = raise NameError('value for final name "source" was not set')
868+ unreachable
869+ L2:
870+ r2 = var_object_size r0
871+ r3 = PyList_New(r2)
872+ r4 = 0
873+ L3:
874+ r5 = r4 < r2 :: signed
875+ if r5 goto L4 else goto L10 :: bool
876+ L4:
877+ r6 = r4 <= 4611686018427387903 :: signed
878+ if r6 goto L5 else goto L6 :: bool
879+ L5:
880+ r7 = r4 >= -4611686018427387904 :: signed
881+ if r7 goto L7 else goto L6 :: bool
882+ L6:
883+ r8 = CPyTagged_FromInt64(r4)
884+ r9 = r8
885+ goto L8
886+ L7:
887+ r10 = r4 << 1
888+ r9 = r10
889+ L8:
890+ r11 = CPyBytes_GetItem(r0, r9)
891+ r12 = box(int, r11)
892+ r13 = unbox(int, r12)
893+ x = r13
894+ r14 = f2(x)
895+ r15 = box(int, r14)
896+ CPyList_SetItemUnsafe(r3, r4, r15)
897+ L9:
898+ r16 = r4 + 1
899+ r4 = r16
900+ goto L3
901+ L10:
902+ a = r3
903+ return 1
0 commit comments