From 9532c3ce9f6c95e7cbf25b51da42cdf850cda56e Mon Sep 17 00:00:00 2001 From: 97littleleaf11 <97littleleaf11@gmail.com> Date: Sun, 11 Apr 2021 18:16:35 +0800 Subject: [PATCH 1/7] Add range primitive type --- mypyc/codegen/emit.py | 12 +++++++----- mypyc/ir/rtypes.py | 8 ++++++++ mypyc/irbuild/mapper.py | 4 +++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/mypyc/codegen/emit.py b/mypyc/codegen/emit.py index e8b3c77be9d6..f51f56b523ad 100644 --- a/mypyc/codegen/emit.py +++ b/mypyc/codegen/emit.py @@ -15,7 +15,7 @@ is_list_rprimitive, is_dict_rprimitive, is_set_rprimitive, is_tuple_rprimitive, is_none_rprimitive, is_object_rprimitive, object_rprimitive, is_str_rprimitive, int_rprimitive, is_optional_type, optional_value_type, is_int32_rprimitive, - is_int64_rprimitive, is_bit_rprimitive + is_int64_rprimitive, is_bit_rprimitive, is_range_rprimitive ) from mypyc.ir.func_ir import FuncDecl from mypyc.ir.class_ir import ClassIR, all_concrete_classes @@ -410,8 +410,8 @@ def emit_cast(self, src: str, dest: str, typ: RType, declare_dest: bool = False, # TODO: Verify refcount handling. if (is_list_rprimitive(typ) or is_dict_rprimitive(typ) or is_set_rprimitive(typ) - or is_float_rprimitive(typ) or is_str_rprimitive(typ) or is_int_rprimitive(typ) - or is_bool_rprimitive(typ)): + or is_str_rprimitive(typ) or is_range_rprimitive(typ) or is_float_rprimitive(typ) + or is_int_rprimitive(typ) or is_bool_rprimitive(typ)): if declare_dest: self.emit_line('PyObject *{};'.format(dest)) if is_list_rprimitive(typ): @@ -420,10 +420,12 @@ def emit_cast(self, src: str, dest: str, typ: RType, declare_dest: bool = False, prefix = 'PyDict' elif is_set_rprimitive(typ): prefix = 'PySet' - elif is_float_rprimitive(typ): - prefix = 'CPyFloat' elif is_str_rprimitive(typ): prefix = 'PyUnicode' + elif is_range_rprimitive(typ): + prefix = 'PyRange' + elif is_float_rprimitive(typ): + prefix = 'CPyFloat' elif is_int_rprimitive(typ): prefix = 'PyLong' elif is_bool_rprimitive(typ) or is_bit_rprimitive(typ): diff --git a/mypyc/ir/rtypes.py b/mypyc/ir/rtypes.py index 2490da6fe51f..de8e7d6b60f2 100644 --- a/mypyc/ir/rtypes.py +++ b/mypyc/ir/rtypes.py @@ -324,6 +324,10 @@ def __hash__(self) -> int: tuple_rprimitive = RPrimitive('builtins.tuple', is_unboxed=False, is_refcounted=True) # type: Final +# Python range object. +range_rprimitive = RPrimitive('builtins.range', is_unboxed=False, + is_refcounted=True) # type: Final + def is_tagged(rtype: RType) -> bool: return rtype is int_rprimitive or rtype is short_int_rprimitive @@ -401,6 +405,10 @@ def is_tuple_rprimitive(rtype: RType) -> bool: return isinstance(rtype, RPrimitive) and rtype.name == 'builtins.tuple' +def is_range_rprimitive(rtype: RType) -> bool: + return isinstance(rtype, RPrimitive) and rtype.name == 'builtins.range' + + def is_sequence_rprimitive(rtype: RType) -> bool: return isinstance(rtype, RPrimitive) and ( is_list_rprimitive(rtype) or is_tuple_rprimitive(rtype) or is_str_rprimitive(rtype) diff --git a/mypyc/irbuild/mapper.py b/mypyc/irbuild/mapper.py index 5b2521d2e76c..8e9dd8a9c578 100644 --- a/mypyc/irbuild/mapper.py +++ b/mypyc/irbuild/mapper.py @@ -12,7 +12,7 @@ from mypyc.ir.rtypes import ( RType, RUnion, RTuple, RInstance, object_rprimitive, dict_rprimitive, tuple_rprimitive, none_rprimitive, int_rprimitive, float_rprimitive, str_rprimitive, bool_rprimitive, - list_rprimitive, set_rprimitive + list_rprimitive, set_rprimitive, range_rprimitive ) from mypyc.ir.func_ir import FuncSignature, FuncDecl, RuntimeArg from mypyc.ir.class_ir import ClassIR @@ -58,6 +58,8 @@ def type_to_rtype(self, typ: Optional[Type]) -> RType: return set_rprimitive elif typ.type.fullname == 'builtins.tuple': return tuple_rprimitive # Varying-length tuple + elif typ.type.fullname == 'builtins.range': + return range_rprimitive elif typ.type in self.type_to_ir: inst = RInstance(self.type_to_ir[typ.type]) # Treat protocols as Union[protocol, object], so that we can do fast From c45edb66f8c40f5e9a27679aaede46cac12bd10e Mon Sep 17 00:00:00 2001 From: 97littleleaf11 <97littleleaf11@gmail.com> Date: Fri, 23 Apr 2021 23:12:36 +0800 Subject: [PATCH 2/7] Load range type and add some tests --- mypyc/primitives/misc_ops.py | 6 +++ mypyc/test-data/irbuild-basic.test | 66 ++++++++++++++++++++++++++++++ mypyc/test-data/run-dicts.test | 2 +- mypyc/test-data/run-floats.test | 2 + mypyc/test-data/run-loops.test | 18 +++++++- 5 files changed, 92 insertions(+), 2 deletions(-) diff --git a/mypyc/primitives/misc_ops.py b/mypyc/primitives/misc_ops.py index 4f3a49c14a9f..3c8f8e4fa9dd 100644 --- a/mypyc/primitives/misc_ops.py +++ b/mypyc/primitives/misc_ops.py @@ -15,6 +15,12 @@ type=object_rprimitive, src='PyBool_Type') +# Get the 'range' type object. +load_address_op( + name='builtins.range', + type=object_rprimitive, + src='PyRange_Type') + # Get the boxed Python 'None' object none_object_op = load_address_op( name='Py_None', diff --git a/mypyc/test-data/irbuild-basic.test b/mypyc/test-data/irbuild-basic.test index 9b7eaeb8e58b..7fab79027af4 100644 --- a/mypyc/test-data/irbuild-basic.test +++ b/mypyc/test-data/irbuild-basic.test @@ -3646,3 +3646,69 @@ L0: r2 = r1 >= 0 :: signed r3 = truncate r1: int32 to builtins.bool return r3 + +[case testRangeObject] +def range_object() -> None: + r = range(4, 12, 2) + sum = 0 + for i in r: + sum += i + +def range_in_loop() -> None: + sum = 0 + for i in range(4, 12, 2): + sum += i +[out] +def range_object(): + r0, r1, r2, r3, r4, r :: object + sum :: int + r5, r6 :: object + r7, i, r8 :: int + r9 :: bit +L0: + r0 = load_address PyRange_Type + r1 = box(short_int, 8) + r2 = box(short_int, 24) + r3 = box(short_int, 4) + r4 = PyObject_CallFunctionObjArgs(r0, r1, r2, r3, 0) + r = r4 + sum = 0 + r5 = PyObject_GetIter(r) +L1: + r6 = PyIter_Next(r5) + if is_error(r6) goto L4 else goto L2 +L2: + r7 = unbox(int, r6) + i = r7 + r8 = CPyTagged_Add(sum, i) + sum = r8 +L3: + goto L1 +L4: + r9 = CPy_NoErrOccured() +L5: + return 1 +def range_in_loop(): + sum :: int + r0 :: short_int + i :: int + r1 :: bit + r2 :: int + r3 :: short_int +L0: + sum = 0 + r0 = 8 + i = r0 +L1: + r1 = r0 < 24 :: signed + if r1 goto L2 else goto L4 :: bool +L2: + r2 = CPyTagged_Add(sum, i) + sum = r2 +L3: + r3 = r0 + 4 + r0 = r3 + i = r3 + goto L1 +L4: + return 1 diff --git a/mypyc/test-data/run-dicts.test b/mypyc/test-data/run-dicts.test index 329d186874f4..86e098f4529b 100644 --- a/mypyc/test-data/run-dicts.test +++ b/mypyc/test-data/run-dicts.test @@ -1,4 +1,4 @@ -# Dict test cases (compile and run) +# Test cases for dicts (compile and run) [case testDictStuff] from typing import Dict, Any, List, Set, Tuple diff --git a/mypyc/test-data/run-floats.test b/mypyc/test-data/run-floats.test index e716949d69c4..1b40a598bf39 100644 --- a/mypyc/test-data/run-floats.test +++ b/mypyc/test-data/run-floats.test @@ -1,3 +1,5 @@ +# Test cases for floats (compile and run) + [case testStrToFloat] def str_to_float(x: str) -> float: return float(x) diff --git a/mypyc/test-data/run-loops.test b/mypyc/test-data/run-loops.test index b83853bc6d16..468f37a4148a 100644 --- a/mypyc/test-data/run-loops.test +++ b/mypyc/test-data/run-loops.test @@ -1,4 +1,4 @@ -# Test cases for "for" and "while" loops (compile and run) +# Test cases for "range" objects, "for" and "while" loops (compile and run) [case testFor] from typing import List, Tuple @@ -452,3 +452,19 @@ def bar(x: Optional[str]) -> None: [file driver.py] from native import bar bar(None) + +[case testRangeObject] +r1 = range(4, 12, 2) +for i in r1: + print(i) +try: + r2 = range(4, 12, 0) +except ValueError as e: + assert 'range() arg 3 must not be zero' in str(e) +else: + assert False +[out] +4 +6 +8 +10 From 8c959f121236b57d1b553c4f812373472bd25853 Mon Sep 17 00:00:00 2001 From: 97littleleaf11 <97littleleaf11@gmail.com> Date: Mon, 26 Apr 2021 21:56:54 +0800 Subject: [PATCH 3/7] Wrong attemp --- mypyc/ir/rtypes.py | 9 +++++- mypyc/irbuild/for_helpers.py | 55 ++++++++++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/mypyc/ir/rtypes.py b/mypyc/ir/rtypes.py index de8e7d6b60f2..3e5b167f8043 100644 --- a/mypyc/ir/rtypes.py +++ b/mypyc/ir/rtypes.py @@ -809,5 +809,12 @@ def deserialize(cls, data: JsonDict, ctx: 'DeserMaps') -> 'RArray': PyListObject = RStruct( name='PyListObject', names=['ob_base', 'ob_item', 'allocated'], - types=[PyObject, pointer_rprimitive, c_pyssize_t_rprimitive] + types=[PyVarObject, pointer_rprimitive, c_pyssize_t_rprimitive] +) + +PyRangeObject = RStruct( + name='rangeobject', + names=['ob_base', 'start', 'stop', 'step', 'length'], + types=[PyObject, pointer_rprimitive, pointer_rprimitive, pointer_rprimitive, + pointer_rprimitive] ) diff --git a/mypyc/irbuild/for_helpers.py b/mypyc/irbuild/for_helpers.py index 73c6ece3d708..11dd5983dbd4 100644 --- a/mypyc/irbuild/for_helpers.py +++ b/mypyc/irbuild/for_helpers.py @@ -12,11 +12,13 @@ Lvalue, Expression, TupleExpr, CallExpr, RefExpr, GeneratorExpr, ARG_POS, MemberExpr, TypeAlias ) from mypyc.ir.ops import ( - Value, BasicBlock, Integer, Branch, Register, TupleGet, TupleSet, IntOp + Value, BasicBlock, Integer, Branch, Register, TupleGet, TupleSet, IntOp, GetElementPtr, + LoadMem ) from mypyc.ir.rtypes import ( RType, is_short_int_rprimitive, is_list_rprimitive, is_sequence_rprimitive, - RTuple, is_dict_rprimitive, short_int_rprimitive, int_rprimitive + RTuple, is_dict_rprimitive, short_int_rprimitive, int_rprimitive, + PyRangeObject, is_range_rprimitive ) from mypyc.primitives.registry import CFunctionDescription from mypyc.primitives.dict_ops import ( @@ -249,6 +251,20 @@ def make_for_loop_generator(builder: IRBuilder, for_dict.init(expr_reg, target_type) return for_dict + if is_range_rprimitive(rtyp): + # Special case "for k in ". + range_reg = builder.accept(expr) + elem_address = builder.add(GetElementPtr(range_reg, PyRangeObject, 'start')) + start_reg = builder.add(LoadMem(int_rprimitive, elem_address)) + elem_address = builder.add(GetElementPtr(range_reg, PyRangeObject, 'stop')) + stop_reg = builder.add(LoadMem(int_rprimitive, elem_address)) + elem_address = builder.add(GetElementPtr(range_reg, PyRangeObject, 'step')) + step_reg = builder.add(LoadMem(int_rprimitive, elem_address)) + + for_range = ForRangeType(builder, index, body_block, loop_exit, line, nested) + for_range.init(start_reg, stop_reg, step_reg) + return for_range + if (isinstance(expr, CallExpr) and isinstance(expr.callee, RefExpr)): if (is_range_ref(expr.callee) @@ -707,6 +723,41 @@ def gen_step(self) -> None: builder.assign(self.index_target, new_val, line) +class ForRangeType(ForRange): + """Generate optimized IR for a for loop over an integer range.""" + + def init(self, start_reg: Value, end_reg: Value, step_reg: Value) -> None: + super().init(start_reg, end_reg, 0) + self.step_reg = step_reg + + def gen_condition(self) -> None: + builder = self.builder + line = self.line + # Add loop condition check. + # cmp = '<' if self.step > 0 else '>' + comparison = builder.binary_op(builder.read(self.index_reg, line), + builder.read(self.end_target, line), '<', line) + builder.add_bool_branch(comparison, self.body_block, self.loop_exit) + + def gen_step(self) -> None: + builder = self.builder + line = self.line + + # Increment index register. If the range is known to fit in short ints, use + # short ints. + if (is_short_int_rprimitive(self.start_reg.type) + and is_short_int_rprimitive(self.end_reg.type)): + new_val = builder.int_op(short_int_rprimitive, + builder.read(self.index_reg, line), + self.step_reg, IntOp.ADD, line) + + else: + new_val = builder.binary_op( + builder.read(self.index_reg, line), self.step_reg, '+', line) + builder.assign(self.index_reg, new_val, line) + builder.assign(self.index_target, new_val, line) + + class ForInfiniteCounter(ForGenerator): """Generate optimized IR for a for loop counting from 0 to infinity.""" From 08616b83d9afe12c40831636fc34716b14bdcc67 Mon Sep 17 00:00:00 2001 From: 97littleleaf11 <97littleleaf11@gmail.com> Date: Thu, 6 May 2021 15:47:16 +0800 Subject: [PATCH 4/7] Change range from function to class --- mypyc/ir/rtypes.py | 7 ----- mypyc/irbuild/for_helpers.py | 15 ----------- mypyc/test-data/fixtures/ir.py | 6 ++++- mypyc/test-data/irbuild-basic.test | 28 ++++++++++--------- mypyc/test-data/run-loops.test | 43 ++++++++++++++++++++---------- 5 files changed, 49 insertions(+), 50 deletions(-) diff --git a/mypyc/ir/rtypes.py b/mypyc/ir/rtypes.py index 3e5b167f8043..c5880031d423 100644 --- a/mypyc/ir/rtypes.py +++ b/mypyc/ir/rtypes.py @@ -811,10 +811,3 @@ def deserialize(cls, data: JsonDict, ctx: 'DeserMaps') -> 'RArray': names=['ob_base', 'ob_item', 'allocated'], types=[PyVarObject, pointer_rprimitive, c_pyssize_t_rprimitive] ) - -PyRangeObject = RStruct( - name='rangeobject', - names=['ob_base', 'start', 'stop', 'step', 'length'], - types=[PyObject, pointer_rprimitive, pointer_rprimitive, pointer_rprimitive, - pointer_rprimitive] -) diff --git a/mypyc/irbuild/for_helpers.py b/mypyc/irbuild/for_helpers.py index 11dd5983dbd4..8fb06541a13a 100644 --- a/mypyc/irbuild/for_helpers.py +++ b/mypyc/irbuild/for_helpers.py @@ -18,7 +18,6 @@ from mypyc.ir.rtypes import ( RType, is_short_int_rprimitive, is_list_rprimitive, is_sequence_rprimitive, RTuple, is_dict_rprimitive, short_int_rprimitive, int_rprimitive, - PyRangeObject, is_range_rprimitive ) from mypyc.primitives.registry import CFunctionDescription from mypyc.primitives.dict_ops import ( @@ -251,20 +250,6 @@ def make_for_loop_generator(builder: IRBuilder, for_dict.init(expr_reg, target_type) return for_dict - if is_range_rprimitive(rtyp): - # Special case "for k in ". - range_reg = builder.accept(expr) - elem_address = builder.add(GetElementPtr(range_reg, PyRangeObject, 'start')) - start_reg = builder.add(LoadMem(int_rprimitive, elem_address)) - elem_address = builder.add(GetElementPtr(range_reg, PyRangeObject, 'stop')) - stop_reg = builder.add(LoadMem(int_rprimitive, elem_address)) - elem_address = builder.add(GetElementPtr(range_reg, PyRangeObject, 'step')) - step_reg = builder.add(LoadMem(int_rprimitive, elem_address)) - - for_range = ForRangeType(builder, index, body_block, loop_exit, line, nested) - for_range.init(start_reg, stop_reg, step_reg) - return for_range - if (isinstance(expr, CallExpr) and isinstance(expr.callee, RefExpr)): if (is_range_ref(expr.callee) diff --git a/mypyc/test-data/fixtures/ir.py b/mypyc/test-data/fixtures/ir.py index 70ecd9d9ab2e..4d9246bb64ad 100644 --- a/mypyc/test-data/fixtures/ir.py +++ b/mypyc/test-data/fixtures/ir.py @@ -191,6 +191,11 @@ def __or__(self, s: Set[S]) -> Set[Union[T, S]]: ... class slice: pass +class range(Sequence[int], Iterable[int]): + def __init__(self, x: int, y: int = ..., z: int = ...) -> None: pass + def __iter__(self) -> Iterator[int]: pass + def __len__(self) -> int: pass + class property: def __init__(self, fget: Optional[Callable[[Any], Any]] = ..., fset: Optional[Callable[[Any, Any], None]] = ..., @@ -243,7 +248,6 @@ def id(o: object) -> int: pass # This type is obviously wrong but the test stubs don't have Sized anymore def len(o: object) -> int: pass def print(*object) -> None: pass -def range(x: int, y: int = ..., z: int = ...) -> Iterator[int]: pass def isinstance(x: object, t: object) -> bool: pass def iter(i: Iterable[T]) -> Iterator[T]: pass @overload diff --git a/mypyc/test-data/irbuild-basic.test b/mypyc/test-data/irbuild-basic.test index 7fab79027af4..240dc1829fdc 100644 --- a/mypyc/test-data/irbuild-basic.test +++ b/mypyc/test-data/irbuild-basic.test @@ -3660,32 +3660,34 @@ def range_in_loop() -> None: sum += i [out] def range_object(): - r0, r1, r2, r3, r4, r :: object + r0, r1, r2, r3, r4 :: object + r5, r :: range sum :: int - r5, r6 :: object - r7, i, r8 :: int - r9 :: bit + r6, r7 :: object + r8, i, r9 :: int + r10 :: bit L0: r0 = load_address PyRange_Type r1 = box(short_int, 8) r2 = box(short_int, 24) r3 = box(short_int, 4) r4 = PyObject_CallFunctionObjArgs(r0, r1, r2, r3, 0) - r = r4 + r5 = cast(range, r4) + r = r5 sum = 0 - r5 = PyObject_GetIter(r) + r6 = PyObject_GetIter(r) L1: - r6 = PyIter_Next(r5) - if is_error(r6) goto L4 else goto L2 + r7 = PyIter_Next(r6) + if is_error(r7) goto L4 else goto L2 L2: - r7 = unbox(int, r6) - i = r7 - r8 = CPyTagged_Add(sum, i) - sum = r8 + r8 = unbox(int, r7) + i = r8 + r9 = CPyTagged_Add(sum, i) + sum = r9 L3: goto L1 L4: - r9 = CPy_NoErrOccured() + r10 = CPy_NoErrOccured() L5: return 1 def range_in_loop(): diff --git a/mypyc/test-data/run-loops.test b/mypyc/test-data/run-loops.test index 468f37a4148a..994b30b42347 100644 --- a/mypyc/test-data/run-loops.test +++ b/mypyc/test-data/run-loops.test @@ -454,17 +454,32 @@ from native import bar bar(None) [case testRangeObject] -r1 = range(4, 12, 2) -for i in r1: - print(i) -try: - r2 = range(4, 12, 0) -except ValueError as e: - assert 'range() arg 3 must not be zero' in str(e) -else: - assert False -[out] -4 -6 -8 -10 +from typing import Any + +def f(x: range) -> int: + sum = 0 + for i in x: + sum += i + return sum + +def test_range_object() -> None: + r1 = range(4, 12, 2) + tmp_list = [x for x in r1] + assert tmp_list == [4, 6, 8, 10] + assert f(r1) == 28 + r2: Any = range(10) + assert f(r2) == 45 + r3: Any = 'x' + try: + f(r3) + except TypeError as e: + assert "range object expected; got str" in str(e) + try: + ff: Any = f + ff(r3) + except TypeError as e: + assert "range object expected; got str" in str(e) + try: + r4 = range(4, 12, 0) + except ValueError as e: + assert "range() arg 3 must not be zero" in str(e) From 70376d9dbad2576668cf2203f6b7151afbba14ab Mon Sep 17 00:00:00 2001 From: 97littleleaf11 <97littleleaf11@gmail.com> Date: Thu, 6 May 2021 16:28:27 +0800 Subject: [PATCH 5/7] Fix range ir --- mypyc/test-data/fixtures/ir.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mypyc/test-data/fixtures/ir.py b/mypyc/test-data/fixtures/ir.py index a3359fad433e..b3f25c11dcd5 100644 --- a/mypyc/test-data/fixtures/ir.py +++ b/mypyc/test-data/fixtures/ir.py @@ -192,10 +192,11 @@ def __or__(self, s: Set[S]) -> Set[Union[T, S]]: ... class slice: pass -class range(Sequence[int], Iterable[int]): +class range(Iterable[int]): def __init__(self, x: int, y: int = ..., z: int = ...) -> None: pass def __iter__(self) -> Iterator[int]: pass def __len__(self) -> int: pass + def __next__(self) -> int: pass class property: def __init__(self, fget: Optional[Callable[[Any], Any]] = ..., From 94399bd46e3932023545a9938ddb046a7b16dcab Mon Sep 17 00:00:00 2001 From: 97littleleaf11 <97littleleaf11@gmail.com> Date: Thu, 6 May 2021 16:28:42 +0800 Subject: [PATCH 6/7] Revert --- mypyc/irbuild/for_helpers.py | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/mypyc/irbuild/for_helpers.py b/mypyc/irbuild/for_helpers.py index df4875547a88..5fa2b4f05d96 100644 --- a/mypyc/irbuild/for_helpers.py +++ b/mypyc/irbuild/for_helpers.py @@ -764,41 +764,6 @@ def gen_step(self) -> None: builder.assign(self.index_target, new_val, line) -class ForRangeType(ForRange): - """Generate optimized IR for a for loop over an integer range.""" - - def init(self, start_reg: Value, end_reg: Value, step_reg: Value) -> None: - super().init(start_reg, end_reg, 0) - self.step_reg = step_reg - - def gen_condition(self) -> None: - builder = self.builder - line = self.line - # Add loop condition check. - # cmp = '<' if self.step > 0 else '>' - comparison = builder.binary_op(builder.read(self.index_reg, line), - builder.read(self.end_target, line), '<', line) - builder.add_bool_branch(comparison, self.body_block, self.loop_exit) - - def gen_step(self) -> None: - builder = self.builder - line = self.line - - # Increment index register. If the range is known to fit in short ints, use - # short ints. - if (is_short_int_rprimitive(self.start_reg.type) - and is_short_int_rprimitive(self.end_reg.type)): - new_val = builder.int_op(short_int_rprimitive, - builder.read(self.index_reg, line), - self.step_reg, IntOp.ADD, line) - - else: - new_val = builder.binary_op( - builder.read(self.index_reg, line), self.step_reg, '+', line) - builder.assign(self.index_reg, new_val, line) - builder.assign(self.index_target, new_val, line) - - class ForInfiniteCounter(ForGenerator): """Generate optimized IR for a for loop counting from 0 to infinity.""" From 017711ef1034ad9c85715086f6fd03eceef213be Mon Sep 17 00:00:00 2001 From: 97littleleaf11 <97littleleaf11@gmail.com> Date: Thu, 6 May 2021 16:57:37 +0800 Subject: [PATCH 7/7] Remove unused imports --- mypyc/irbuild/for_helpers.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mypyc/irbuild/for_helpers.py b/mypyc/irbuild/for_helpers.py index 5fa2b4f05d96..8097b453b117 100644 --- a/mypyc/irbuild/for_helpers.py +++ b/mypyc/irbuild/for_helpers.py @@ -12,8 +12,7 @@ Lvalue, Expression, TupleExpr, CallExpr, RefExpr, GeneratorExpr, ARG_POS, MemberExpr, TypeAlias ) from mypyc.ir.ops import ( - Value, BasicBlock, Integer, Branch, Register, TupleGet, TupleSet, IntOp, GetElementPtr, - LoadMem + Value, BasicBlock, Integer, Branch, Register, TupleGet, TupleSet, IntOp ) from mypyc.ir.rtypes import ( RType, is_short_int_rprimitive, is_list_rprimitive, is_sequence_rprimitive,