diff --git a/mypyc/codegen/emitfunc.py b/mypyc/codegen/emitfunc.py index 76d5cbd09b5d..52a1ac2f3f90 100644 --- a/mypyc/codegen/emitfunc.py +++ b/mypyc/codegen/emitfunc.py @@ -19,7 +19,7 @@ ) from mypyc.ir.func_ir import FuncIR, FuncDecl, FUNC_STATICMETHOD, FUNC_CLASSMETHOD from mypyc.ir.class_ir import ClassIR -from mypyc.analysis.const_int import find_constant_integer_registers +from mypyc.ir.const_int import find_constant_integer_registers # Whether to insert debug asserts for all error handling, to quickly # catch errors propagating without exceptions set. diff --git a/mypyc/analysis/const_int.py b/mypyc/ir/const_int.py similarity index 100% rename from mypyc/analysis/const_int.py rename to mypyc/ir/const_int.py diff --git a/mypyc/ir/func_ir.py b/mypyc/ir/func_ir.py index 4c6d51ea564b..70dd53b8ac34 100644 --- a/mypyc/ir/func_ir.py +++ b/mypyc/ir/func_ir.py @@ -1,4 +1,5 @@ """Intermediate representation of functions.""" +import re from typing import List, Optional, Sequence, Dict from typing_extensions import Final @@ -10,6 +11,7 @@ DeserMaps, Goto, Branch, Return, Unreachable, BasicBlock, Environment ) from mypyc.ir.rtypes import RType, deserialize_type +from mypyc.ir.const_int import find_constant_integer_registers from mypyc.namegen import NameGenerator @@ -218,7 +220,9 @@ def deserialize(cls, data: JsonDict, ctx: DeserMaps) -> 'FuncIR': INVALID_FUNC_DEF = FuncDef('', [], Block([])) # type: Final -def format_blocks(blocks: List[BasicBlock], env: Environment) -> List[str]: +def format_blocks(blocks: List[BasicBlock], + env: Environment, + const_regs: Dict[str, int]) -> List[str]: """Format a list of IR basic blocks into a human-readable form.""" # First label all of the blocks for i, block in enumerate(blocks): @@ -244,9 +248,14 @@ def format_blocks(blocks: List[BasicBlock], env: Environment) -> List[str]: and ops[-1].label == blocks[i + 1]): # Hide the last goto if it just goes to the next basic block. ops = ops[:-1] + # load int registers start with 'i' + regex = re.compile(r'\bi[0-9]+\b') for op in ops: - line = ' ' + op.to_str(env) - lines.append(line) + if op.name not in const_regs: + line = ' ' + op.to_str(env) + line = regex.sub(lambda i: str(const_regs[i.group()]) if i.group() in const_regs + else i.group(), line) + lines.append(line) if not isinstance(block.ops[-1], (Goto, Branch, Return, Unreachable)): # Each basic block needs to exit somewhere. @@ -259,8 +268,10 @@ def format_func(fn: FuncIR) -> List[str]: cls_prefix = fn.class_name + '.' if fn.class_name else '' lines.append('def {}{}({}):'.format(cls_prefix, fn.name, ', '.join(arg.name for arg in fn.args))) - for line in fn.env.to_lines(): + # compute constants + const_regs = find_constant_integer_registers(fn.blocks) + for line in fn.env.to_lines(const_regs): lines.append(' ' + line) - code = format_blocks(fn.blocks, fn.env) + code = format_blocks(fn.blocks, fn.env, const_regs) lines.extend(code) return lines diff --git a/mypyc/ir/ops.py b/mypyc/ir/ops.py index f0f77d9b8a66..e4eeeba0a2bb 100644 --- a/mypyc/ir/ops.py +++ b/mypyc/ir/ops.py @@ -138,6 +138,7 @@ def __init__(self, name: Optional[str] = None) -> None: self.indexes = OrderedDict() # type: Dict[Value, int] self.symtable = OrderedDict() # type: OrderedDict[SymbolNode, AssignmentTarget] self.temp_index = 0 + self.temp_load_int_idx = 0 # All names genereted; value is the number of duplicates seen. self.names = {} # type: Dict[str, int] self.vars_needing_init = set() # type: Set[Value] @@ -198,6 +199,10 @@ def add_op(self, reg: 'RegisterOp') -> None: """Record the value of an operation.""" if reg.is_void: return + if isinstance(reg, LoadInt): + self.add(reg, "i%d" % self.temp_load_int_idx) + self.temp_load_int_idx += 1 + return self.add(reg, 'r%d' % self.temp_index) self.temp_index += 1 @@ -232,17 +237,24 @@ def format(self, fmt: str, *args: Any) -> str: i = n return ''.join(result) - def to_lines(self) -> List[str]: + def to_lines(self, const_regs: Optional[Dict[str, int]] = None) -> List[str]: result = [] i = 0 regs = list(self.regs()) - + if const_regs is None: + const_regs = {} while i < len(regs): i0 = i - group = [regs[i0].name] + if regs[i0].name not in const_regs: + group = [regs[i0].name] + else: + group = [] + i += 1 + continue while i + 1 < len(regs) and regs[i + 1].type == regs[i0].type: i += 1 - group.append(regs[i].name) + if regs[i].name not in const_regs: + group.append(regs[i].name) i += 1 result.append('%s :: %s' % (', '.join(group), regs[i0].type)) return result diff --git a/mypyc/test-data/analysis.test b/mypyc/test-data/analysis.test index 2d81e5157425..53dadee6dfd4 100644 --- a/mypyc/test-data/analysis.test +++ b/mypyc/test-data/analysis.test @@ -10,43 +10,35 @@ def f(a: int) -> None: [out] def f(a): a :: int - r0 :: short_int x :: int - r1 :: bool - r2, r3, r4 :: native_int - r5, r6, r7 :: bool - r8 :: short_int + r0 :: bool + r1 :: native_int + r2, r3, r4 :: bool y :: int - r9 :: short_int z :: int - r10 :: None + r5 :: None L0: - r0 = 2 - x = r0 - r2 = 1 - r3 = x & r2 - r4 = 0 - r5 = r3 == r4 - if r5 goto L1 else goto L2 :: bool + x = 2 + r1 = x & 1 + r2 = r1 == 0 + if r2 goto L1 else goto L2 :: bool L1: - r6 = x == a - r1 = r6 + r3 = x == a + r0 = r3 goto L3 L2: - r7 = CPyTagged_IsEq_(x, a) - r1 = r7 + r4 = CPyTagged_IsEq_(x, a) + r0 = r4 L3: - if r1 goto L4 else goto L5 :: bool + if r0 goto L4 else goto L5 :: bool L4: - r8 = 2 - y = r8 + y = 2 goto L6 L5: - r9 = 2 - z = r9 + z = 2 L6: - r10 = None - return r10 + r5 = None + return r5 (0, 0) {a} {a} (0, 1) {a} {a, x} (0, 2) {a, x} {a, x} @@ -55,20 +47,20 @@ L6: (0, 5) {a, x} {a, x} (0, 6) {a, x} {a, x} (1, 0) {a, x} {a, x} -(1, 1) {a, x} {a, r1, x} -(1, 2) {a, r1, x} {a, r1, x} +(1, 1) {a, x} {a, r0, x} +(1, 2) {a, r0, x} {a, r0, x} (2, 0) {a, x} {a, x} -(2, 1) {a, x} {a, r1, x} -(2, 2) {a, r1, x} {a, r1, x} -(3, 0) {a, r1, x} {a, r1, x} -(4, 0) {a, r1, x} {a, r1, x} -(4, 1) {a, r1, x} {a, r1, x, y} -(4, 2) {a, r1, x, y} {a, r1, x, y} -(5, 0) {a, r1, x} {a, r1, x} -(5, 1) {a, r1, x} {a, r1, x, z} -(5, 2) {a, r1, x, z} {a, r1, x, z} -(6, 0) {a, r1, x, y, z} {a, r1, x, y, z} -(6, 1) {a, r1, x, y, z} {a, r1, x, y, z} +(2, 1) {a, x} {a, r0, x} +(2, 2) {a, r0, x} {a, r0, x} +(3, 0) {a, r0, x} {a, r0, x} +(4, 0) {a, r0, x} {a, r0, x} +(4, 1) {a, r0, x} {a, r0, x, y} +(4, 2) {a, r0, x, y} {a, r0, x, y} +(5, 0) {a, r0, x} {a, r0, x} +(5, 1) {a, r0, x} {a, r0, x, z} +(5, 2) {a, r0, x, z} {a, r0, x, z} +(6, 0) {a, r0, x, y, z} {a, r0, x, y, z} +(6, 1) {a, r0, x, y, z} {a, r0, x, y, z} [case testSimple_Liveness] def f(a: int) -> int: @@ -80,27 +72,23 @@ def f(a: int) -> int: [out] def f(a): a :: int - r0 :: short_int x :: int - r1 :: short_int - r2 :: bool + r0 :: bool L0: - r0 = 2 - x = r0 - r1 = 2 - r2 = CPyTagged_IsEq(x, r1) - if r2 goto L1 else goto L2 :: bool + x = 2 + r0 = CPyTagged_IsEq(x, 2) + if r0 goto L1 else goto L2 :: bool L1: return a L2: return x L3: unreachable -(0, 0) {a} {a, r0} -(0, 1) {a, r0} {a, x} -(0, 2) {a, x} {a, r1, x} -(0, 3) {a, r1, x} {a, r2, x} -(0, 4) {a, r2, x} {a, x} +(0, 0) {a} {a, i0} +(0, 1) {a, i0} {a, x} +(0, 2) {a, x} {a, i1, x} +(0, 3) {a, i1, x} {a, r0, x} +(0, 4) {a, r0, x} {a, x} (1, 0) {a} {} (2, 0) {x} {} (3, 0) {} {} @@ -113,25 +101,19 @@ def f() -> int: return x [out] def f(): - r0 :: short_int x :: int - r1 :: short_int y :: int - r2 :: short_int L0: - r0 = 2 - x = r0 - r1 = 2 - y = r1 - r2 = 4 - x = r2 + x = 2 + y = 2 + x = 4 return x -(0, 0) {} {r0} -(0, 1) {r0} {} -(0, 2) {} {r1} -(0, 3) {r1} {} -(0, 4) {} {r2} -(0, 5) {r2} {x} +(0, 0) {} {i0} +(0, 1) {i0} {} +(0, 2) {} {i1} +(0, 3) {i1} {} +(0, 4) {} {i2} +(0, 5) {i2} {x} (0, 6) {x} {} [case testSpecial2_Liveness] @@ -143,21 +125,17 @@ def f(a: int) -> int: [out] def f(a): a :: int - r0, r1, r2 :: short_int L0: - r0 = 2 - a = r0 - r1 = 4 - a = r1 - r2 = 6 - a = r2 + a = 2 + a = 4 + a = 6 return a -(0, 0) {} {r0} -(0, 1) {r0} {} -(0, 2) {} {r1} -(0, 3) {r1} {} -(0, 4) {} {r2} -(0, 5) {r2} {a} +(0, 0) {} {i0} +(0, 1) {i0} {} +(0, 2) {} {i1} +(0, 3) {i1} {} +(0, 4) {} {i2} +(0, 5) {i2} {a} (0, 6) {a} {} [case testSimple_MustDefined] @@ -170,30 +148,22 @@ def f(a: int) -> None: [out] def f(a): a :: int - r0 :: short_int - r1 :: bool - r2 :: short_int + r0 :: bool y :: int - r3 :: short_int x :: int - r4 :: short_int - r5 :: None + r1 :: None L0: - r0 = 2 - r1 = CPyTagged_IsEq(a, r0) - if r1 goto L1 else goto L2 :: bool + r0 = CPyTagged_IsEq(a, 2) + if r0 goto L1 else goto L2 :: bool L1: - r2 = 2 - y = r2 - r3 = 4 - x = r3 + y = 2 + x = 4 goto L3 L2: - r4 = 4 - x = r4 + x = 4 L3: - r5 = None - return r5 + r1 = None + return r1 (0, 0) {a} {a} (0, 1) {a} {a} (0, 2) {a} {a} @@ -226,25 +196,21 @@ def f(n: int) -> None: [out] def f(n): n :: int - r0 :: short_int - r1 :: bool - r2 :: short_int - r3, m :: int - r4 :: None + r0 :: bool + r1, m :: int + r2 :: None L0: L1: - r0 = 10 - r1 = CPyTagged_IsLt(n, r0) - if r1 goto L2 else goto L3 :: bool + r0 = CPyTagged_IsLt(n, 10) + if r0 goto L2 else goto L3 :: bool L2: - r2 = 2 - r3 = CPyTagged_Add(n, r2) - n = r3 + r1 = CPyTagged_Add(n, 2) + n = r1 m = n goto L1 L3: - r4 = None - return r4 + r2 = None + return r2 (0, 0) {n} {n} (1, 0) {n} {n} (1, 1) {n} {n} @@ -269,61 +235,51 @@ def f(n: int) -> None: [out] def f(n): n :: int - r0 :: short_int x :: int - r1 :: short_int y :: int - r2 :: short_int - r3 :: bool - r4 :: short_int - r5 :: bool - r6 :: short_int - r7 :: None + r0 :: bool + r1 :: bool + r2 :: None L0: - r0 = 2 - x = r0 - r1 = 2 - y = r1 + x = 2 + y = 2 L1: - r2 = 2 - r3 = CPyTagged_IsLt(n, r2) - if r3 goto L2 else goto L6 :: bool + r0 = CPyTagged_IsLt(n, 2) + if r0 goto L2 else goto L6 :: bool L2: n = y L3: - r4 = 4 - r5 = CPyTagged_IsLt(n, r4) - if r5 goto L4 else goto L5 :: bool + r1 = CPyTagged_IsLt(n, 4) + if r1 goto L4 else goto L5 :: bool L4: - r6 = 2 - n = r6 + n = 2 n = x goto L3 L5: goto L1 L6: - r7 = None - return r7 -(0, 0) {n} {n, r0} -(0, 1) {n, r0} {n, x} -(0, 2) {n, x} {n, r1, x} -(0, 3) {n, r1, x} {n, x, y} + r2 = None + return r2 +(0, 0) {n} {i0, n} +(0, 1) {i0, n} {n, x} +(0, 2) {n, x} {i1, n, x} +(0, 3) {i1, n, x} {n, x, y} (0, 4) {n, x, y} {n, x, y} -(1, 0) {n, x, y} {n, r2, x, y} -(1, 1) {n, r2, x, y} {r3, x, y} -(1, 2) {r3, x, y} {x, y} +(1, 0) {n, x, y} {i2, n, x, y} +(1, 1) {i2, n, x, y} {r0, x, y} +(1, 2) {r0, x, y} {x, y} (2, 0) {x, y} {n, x, y} (2, 1) {n, x, y} {n, x, y} -(3, 0) {n, x, y} {n, r4, x, y} -(3, 1) {n, r4, x, y} {n, r5, x, y} -(3, 2) {n, r5, x, y} {n, x, y} -(4, 0) {x, y} {r6, x, y} -(4, 1) {r6, x, y} {x, y} +(3, 0) {n, x, y} {i3, n, x, y} +(3, 1) {i3, n, x, y} {n, r1, x, y} +(3, 2) {n, r1, x, y} {n, x, y} +(4, 0) {x, y} {i4, x, y} +(4, 1) {i4, x, y} {x, y} (4, 2) {x, y} {n, x, y} (4, 3) {n, x, y} {n, x, y} (5, 0) {n, x, y} {n, x, y} -(6, 0) {} {r7} -(6, 1) {r7} {} +(6, 0) {} {r2} +(6, 1) {r2} {} [case testCall_Liveness] def f(x: int) -> int: @@ -332,32 +288,30 @@ def f(x: int) -> int: [out] def f(x): x :: int - r0 :: short_int - r1, a, r2, r3, r4 :: int + r0, a, r1, r2, r3 :: int L0: - r0 = 2 - r1 = f(r0) - if is_error(r1) goto L3 (error at f:2) else goto L1 + r0 = f(2) + if is_error(r0) goto L3 (error at f:2) else goto L1 L1: - a = r1 - r2 = f(a) - if is_error(r2) goto L3 (error at f:3) else goto L2 + a = r0 + r1 = f(a) + if is_error(r1) goto L3 (error at f:3) else goto L2 L2: - r3 = CPyTagged_Add(r2, a) - return r3 + r2 = CPyTagged_Add(r1, a) + return r2 L3: - r4 = :: int - return r4 -(0, 0) {} {r0} -(0, 1) {r0} {r1} -(0, 2) {r1} {r1} -(1, 0) {r1} {a} -(1, 1) {a} {a, r2} -(1, 2) {a, r2} {a, r2} -(2, 0) {a, r2} {r3} -(2, 1) {r3} {} -(3, 0) {} {r4} -(3, 1) {r4} {} + r3 = :: int + return r3 +(0, 0) {} {i0} +(0, 1) {i0} {r0} +(0, 2) {r0} {r0} +(1, 0) {r0} {a} +(1, 1) {a} {a, r1} +(1, 2) {a, r1} {a, r1} +(2, 0) {a, r1} {r2} +(2, 1) {r2} {} +(3, 0) {} {r3} +(3, 1) {r3} {} [case testLoop_MaybeDefined] def f(a: int) -> None: @@ -369,58 +323,50 @@ def f(a: int) -> None: def f(a): a :: int r0 :: bool - r1, r2, r3 :: native_int - r4 :: bool - r5, r6, r7 :: native_int - r8, r9, r10, r11, r12 :: bool - r13, r14, r15 :: native_int - r16 :: bool - r17, r18, r19 :: native_int - r20, r21, r22, r23 :: bool + r1 :: native_int + r2 :: bool + r3 :: native_int + r4, r5, r6, r7, r8 :: bool + r9 :: native_int + r10 :: bool + r11 :: native_int + r12, r13, r14, r15 :: bool y, x :: int - r24 :: None + r16 :: None L0: L1: - r1 = 1 - r2 = a & r1 - r3 = 0 - r4 = r2 == r3 - r5 = 1 - r6 = a & r5 - r7 = 0 - r8 = r6 == r7 - r9 = r4 & r8 - if r9 goto L2 else goto L3 :: bool + r1 = a & 1 + r2 = r1 == 0 + r3 = a & 1 + r4 = r3 == 0 + r5 = r2 & r4 + if r5 goto L2 else goto L3 :: bool L2: - r10 = a < a :: signed - r0 = r10 + r6 = a < a :: signed + r0 = r6 goto L4 L3: - r11 = CPyTagged_IsLt_(a, a) - r0 = r11 + r7 = CPyTagged_IsLt_(a, a) + r0 = r7 L4: if r0 goto L5 else goto L12 :: bool L5: L6: - r13 = 1 - r14 = a & r13 - r15 = 0 - r16 = r14 == r15 - r17 = 1 - r18 = a & r17 - r19 = 0 - r20 = r18 == r19 - r21 = r16 & r20 - if r21 goto L7 else goto L8 :: bool + r9 = a & 1 + r10 = r9 == 0 + r11 = a & 1 + r12 = r11 == 0 + r13 = r10 & r12 + if r13 goto L7 else goto L8 :: bool L7: - r22 = a < a :: signed - r12 = r22 + r14 = a < a :: signed + r8 = r14 goto L9 L8: - r23 = CPyTagged_IsLt_(a, a) - r12 = r23 + r15 = CPyTagged_IsLt_(a, a) + r8 = r15 L9: - if r12 goto L10 else goto L11 :: bool + if r8 goto L10 else goto L11 :: bool L10: y = a goto L6 @@ -428,50 +374,50 @@ L11: x = a goto L1 L12: - r24 = None - return r24 + r16 = None + return r16 (0, 0) {a} {a} -(1, 0) {a, r0, r12, x, y} {a, r0, r12, x, y} -(1, 1) {a, r0, r12, x, y} {a, r0, r12, x, y} -(1, 2) {a, r0, r12, x, y} {a, r0, r12, x, y} -(1, 3) {a, r0, r12, x, y} {a, r0, r12, x, y} -(1, 4) {a, r0, r12, x, y} {a, r0, r12, x, y} -(1, 5) {a, r0, r12, x, y} {a, r0, r12, x, y} -(1, 6) {a, r0, r12, x, y} {a, r0, r12, x, y} -(1, 7) {a, r0, r12, x, y} {a, r0, r12, x, y} -(1, 8) {a, r0, r12, x, y} {a, r0, r12, x, y} -(1, 9) {a, r0, r12, x, y} {a, r0, r12, x, y} -(2, 0) {a, r0, r12, x, y} {a, r0, r12, x, y} -(2, 1) {a, r0, r12, x, y} {a, r0, r12, x, y} -(2, 2) {a, r0, r12, x, y} {a, r0, r12, x, y} -(3, 0) {a, r0, r12, x, y} {a, r0, r12, x, y} -(3, 1) {a, r0, r12, x, y} {a, r0, r12, x, y} -(3, 2) {a, r0, r12, x, y} {a, r0, r12, x, y} -(4, 0) {a, r0, r12, x, y} {a, r0, r12, x, y} -(5, 0) {a, r0, r12, x, y} {a, r0, r12, x, y} -(6, 0) {a, r0, r12, x, y} {a, r0, r12, x, y} -(6, 1) {a, r0, r12, x, y} {a, r0, r12, x, y} -(6, 2) {a, r0, r12, x, y} {a, r0, r12, x, y} -(6, 3) {a, r0, r12, x, y} {a, r0, r12, x, y} -(6, 4) {a, r0, r12, x, y} {a, r0, r12, x, y} -(6, 5) {a, r0, r12, x, y} {a, r0, r12, x, y} -(6, 6) {a, r0, r12, x, y} {a, r0, r12, x, y} -(6, 7) {a, r0, r12, x, y} {a, r0, r12, x, y} -(6, 8) {a, r0, r12, x, y} {a, r0, r12, x, y} -(6, 9) {a, r0, r12, x, y} {a, r0, r12, x, y} -(7, 0) {a, r0, r12, x, y} {a, r0, r12, x, y} -(7, 1) {a, r0, r12, x, y} {a, r0, r12, x, y} -(7, 2) {a, r0, r12, x, y} {a, r0, r12, x, y} -(8, 0) {a, r0, r12, x, y} {a, r0, r12, x, y} -(8, 1) {a, r0, r12, x, y} {a, r0, r12, x, y} -(8, 2) {a, r0, r12, x, y} {a, r0, r12, x, y} -(9, 0) {a, r0, r12, x, y} {a, r0, r12, x, y} -(10, 0) {a, r0, r12, x, y} {a, r0, r12, x, y} -(10, 1) {a, r0, r12, x, y} {a, r0, r12, x, y} -(11, 0) {a, r0, r12, x, y} {a, r0, r12, x, y} -(11, 1) {a, r0, r12, x, y} {a, r0, r12, x, y} -(12, 0) {a, r0, r12, x, y} {a, r0, r12, x, y} -(12, 1) {a, r0, r12, x, y} {a, r0, r12, x, y} +(1, 0) {a, r0, r8, x, y} {a, r0, r8, x, y} +(1, 1) {a, r0, r8, x, y} {a, r0, r8, x, y} +(1, 2) {a, r0, r8, x, y} {a, r0, r8, x, y} +(1, 3) {a, r0, r8, x, y} {a, r0, r8, x, y} +(1, 4) {a, r0, r8, x, y} {a, r0, r8, x, y} +(1, 5) {a, r0, r8, x, y} {a, r0, r8, x, y} +(1, 6) {a, r0, r8, x, y} {a, r0, r8, x, y} +(1, 7) {a, r0, r8, x, y} {a, r0, r8, x, y} +(1, 8) {a, r0, r8, x, y} {a, r0, r8, x, y} +(1, 9) {a, r0, r8, x, y} {a, r0, r8, x, y} +(2, 0) {a, r0, r8, x, y} {a, r0, r8, x, y} +(2, 1) {a, r0, r8, x, y} {a, r0, r8, x, y} +(2, 2) {a, r0, r8, x, y} {a, r0, r8, x, y} +(3, 0) {a, r0, r8, x, y} {a, r0, r8, x, y} +(3, 1) {a, r0, r8, x, y} {a, r0, r8, x, y} +(3, 2) {a, r0, r8, x, y} {a, r0, r8, x, y} +(4, 0) {a, r0, r8, x, y} {a, r0, r8, x, y} +(5, 0) {a, r0, r8, x, y} {a, r0, r8, x, y} +(6, 0) {a, r0, r8, x, y} {a, r0, r8, x, y} +(6, 1) {a, r0, r8, x, y} {a, r0, r8, x, y} +(6, 2) {a, r0, r8, x, y} {a, r0, r8, x, y} +(6, 3) {a, r0, r8, x, y} {a, r0, r8, x, y} +(6, 4) {a, r0, r8, x, y} {a, r0, r8, x, y} +(6, 5) {a, r0, r8, x, y} {a, r0, r8, x, y} +(6, 6) {a, r0, r8, x, y} {a, r0, r8, x, y} +(6, 7) {a, r0, r8, x, y} {a, r0, r8, x, y} +(6, 8) {a, r0, r8, x, y} {a, r0, r8, x, y} +(6, 9) {a, r0, r8, x, y} {a, r0, r8, x, y} +(7, 0) {a, r0, r8, x, y} {a, r0, r8, x, y} +(7, 1) {a, r0, r8, x, y} {a, r0, r8, x, y} +(7, 2) {a, r0, r8, x, y} {a, r0, r8, x, y} +(8, 0) {a, r0, r8, x, y} {a, r0, r8, x, y} +(8, 1) {a, r0, r8, x, y} {a, r0, r8, x, y} +(8, 2) {a, r0, r8, x, y} {a, r0, r8, x, y} +(9, 0) {a, r0, r8, x, y} {a, r0, r8, x, y} +(10, 0) {a, r0, r8, x, y} {a, r0, r8, x, y} +(10, 1) {a, r0, r8, x, y} {a, r0, r8, x, y} +(11, 0) {a, r0, r8, x, y} {a, r0, r8, x, y} +(11, 1) {a, r0, r8, x, y} {a, r0, r8, x, y} +(12, 0) {a, r0, r8, x, y} {a, r0, r8, x, y} +(12, 1) {a, r0, r8, x, y} {a, r0, r8, x, y} [case testTrivial_BorrowedArgument] def f(a: int, b: int) -> int: @@ -491,11 +437,9 @@ def f(a: int) -> int: [out] def f(a): a, b :: int - r0 :: short_int L0: b = a - r0 = 2 - a = r0 + a = 2 return a (0, 0) {a} {a} (0, 1) {a} {a} @@ -514,35 +458,28 @@ def f(a: int) -> int: def f(a): a :: int r0 :: bool - r1, r2, r3 :: native_int - r4, r5, r6 :: bool - r7 :: short_int + r1 :: native_int + r2, r3, r4 :: bool x :: int - r8, r9 :: short_int L0: - r1 = 1 - r2 = a & r1 - r3 = 0 - r4 = r2 == r3 - if r4 goto L1 else goto L2 :: bool + r1 = a & 1 + r2 = r1 == 0 + if r2 goto L1 else goto L2 :: bool L1: - r5 = a == a - r0 = r5 + r3 = a == a + r0 = r3 goto L3 L2: - r6 = CPyTagged_IsEq_(a, a) - r0 = r6 + r4 = CPyTagged_IsEq_(a, a) + r0 = r4 L3: if r0 goto L4 else goto L5 :: bool L4: - r7 = 4 - x = r7 - r8 = 2 - a = r8 + x = 4 + a = 2 goto L6 L5: - r9 = 2 - x = r9 + x = 2 L6: return x (0, 0) {a} {a} @@ -578,28 +515,22 @@ def f(a: int) -> int: [out] def f(a): a :: int - r0 :: short_int sum :: int - r1 :: short_int i :: int - r2 :: bool - r3 :: int - r4 :: short_int - r5 :: int + r0 :: bool + r1 :: int + r2 :: int L0: - r0 = 0 - sum = r0 - r1 = 0 - i = r1 + sum = 0 + i = 0 L1: - r2 = CPyTagged_IsLe(i, a) - if r2 goto L2 else goto L3 :: bool + r0 = CPyTagged_IsLe(i, a) + if r0 goto L2 else goto L3 :: bool L2: - r3 = CPyTagged_Add(sum, i) - sum = r3 - r4 = 2 - r5 = CPyTagged_Add(i, r4) - i = r5 + r1 = CPyTagged_Add(sum, i) + sum = r1 + r2 = CPyTagged_Add(i, 2) + i = r2 goto L1 L3: return sum @@ -638,12 +569,9 @@ def lol(x): r3 :: str r4 :: object r5 :: bool - r6 :: short_int - r7 :: int - r8 :: bool - r9 :: short_int - r10, r11 :: int - r12 :: bool + r6 :: int + r7 :: bool + r8, r9 :: int L0: L1: r0 = CPyTagged_Id(x) @@ -659,14 +587,12 @@ L3: r5 = CPy_ExceptionMatches(r4) if r5 goto L4 else goto L5 :: bool L4: - r6 = 2 - r7 = CPyTagged_Negate(r6) + r6 = CPyTagged_Negate(2) CPy_RestoreExcInfo(r1) - return r7 + return r6 L5: CPy_Reraise() - r12 = 0 - if not r12 goto L8 else goto L6 :: bool + if not 0 goto L8 else goto L6 :: bool L6: unreachable L7: @@ -674,17 +600,16 @@ L7: goto L10 L8: CPy_RestoreExcInfo(r1) - r8 = keep_propagating - if not r8 goto L11 else goto L9 :: bool + r7 = keep_propagating + if not r7 goto L11 else goto L9 :: bool L9: unreachable L10: - r9 = 2 - r10 = CPyTagged_Add(st, r9) - return r10 + r8 = CPyTagged_Add(st, 2) + return r8 L11: - r11 = :: int - return r11 + r9 = :: int + return r9 (0, 0) {x} {x} (1, 0) {x} {r0} (1, 1) {r0} {st} @@ -696,23 +621,23 @@ L11: (2, 4) {r1, r4} {r1, r4} (3, 0) {r1, r4} {r1, r5} (3, 1) {r1, r5} {r1} -(4, 0) {r1} {r1, r6} -(4, 1) {r1, r6} {r1, r7} -(4, 2) {r1, r7} {r7} -(4, 3) {r7} {} +(4, 0) {r1} {i0, r1} +(4, 1) {i0, r1} {r1, r6} +(4, 2) {r1, r6} {r6} +(4, 3) {r6} {} (5, 0) {r1} {r1} -(5, 1) {r1} {r1, r12} -(5, 2) {r1, r12} {r1} +(5, 1) {r1} {i2, r1} +(5, 2) {i2, r1} {r1} (6, 0) {} {} (7, 0) {r1, st} {st} (7, 1) {st} {st} (8, 0) {r1} {} -(8, 1) {} {r8} -(8, 2) {r8} {} +(8, 1) {} {r7} +(8, 2) {r7} {} (9, 0) {} {} -(10, 0) {st} {r9, st} -(10, 1) {r9, st} {r10} -(10, 2) {r10} {} -(11, 0) {} {r11} -(11, 1) {r11} {} +(10, 0) {st} {i1, st} +(10, 1) {i1, st} {r8} +(10, 2) {r8} {} +(11, 0) {} {r9} +(11, 1) {r9} {} diff --git a/mypyc/test-data/exceptions.test b/mypyc/test-data/exceptions.test index 9e720e7abe4c..4b39cb2978b2 100644 --- a/mypyc/test-data/exceptions.test +++ b/mypyc/test-data/exceptions.test @@ -9,22 +9,20 @@ def f(x: List[int]) -> int: [out] def f(x): x :: list - r0 :: short_int - r1 :: object - r2, r3 :: int + r0 :: object + r1, r2 :: int L0: - r0 = 0 - r1 = CPyList_GetItemShort(x, r0) - if is_error(r1) goto L3 (error at f:3) else goto L1 + r0 = CPyList_GetItemShort(x, 0) + if is_error(r0) goto L3 (error at f:3) else goto L1 L1: - r2 = unbox(int, r1) - dec_ref r1 - if is_error(r2) goto L3 (error at f:3) else goto L2 + r1 = unbox(int, r0) + dec_ref r0 + if is_error(r1) goto L3 (error at f:3) else goto L2 L2: - return r2 + return r1 L3: - r3 = :: int - return r3 + r2 = :: int + return r2 [case testListAppendAndSetItemError] from typing import List @@ -77,41 +75,36 @@ def f(x): r0 :: None r1 :: object r2 :: bool - r3 :: short_int - r4 :: __main__.A - r5 :: None - r6 :: object - r7, r8 :: bool - r9, r10 :: short_int - r11 :: int + r3 :: __main__.A + r4 :: None + r5 :: object + r6, r7 :: bool + r8 :: int L0: r0 = None r1 = box(None, r0) r2 = x is r1 if r2 goto L1 else goto L2 :: bool L1: - r3 = 2 - return r3 + return 2 L2: inc_ref x - r4 = cast(__main__.A, x) - if is_error(r4) goto L6 (error at f:8) else goto L3 + r3 = cast(__main__.A, x) + if is_error(r3) goto L6 (error at f:8) else goto L3 L3: - r5 = None - r6 = box(None, r5) - r7 = r4 is r6 - dec_ref r4 - r8 = !r7 - if r8 goto L4 else goto L5 :: bool + r4 = None + r5 = box(None, r4) + r6 = r3 is r5 + dec_ref r3 + r7 = !r6 + if r7 goto L4 else goto L5 :: bool L4: - r9 = 4 - return r9 + return 4 L5: - r10 = 6 - return r10 + return 6 L6: - r11 = :: int - return r11 + r8 = :: int + return r8 [case testListSum] from typing import List @@ -126,66 +119,56 @@ def sum(a: List[int], l: int) -> int: def sum(a, l): a :: list l :: int - r0 :: short_int sum :: int - r1 :: short_int i :: int + r0 :: bool + r1 :: native_int r2 :: bool - r3, r4, r5 :: native_int - r6 :: bool - r7, r8, r9 :: native_int - r10, r11, r12, r13 :: bool - r14 :: object - r15, r16 :: int - r17 :: short_int - r18, r19 :: int + r3 :: native_int + r4, r5, r6, r7 :: bool + r8 :: object + r9, r10 :: int + r11, r12 :: int L0: - r0 = 0 - sum = r0 - r1 = 0 - i = r1 + sum = 0 + i = 0 L1: - r3 = 1 - r4 = i & r3 - r5 = 0 - r6 = r4 == r5 - r7 = 1 - r8 = l & r7 - r9 = 0 - r10 = r8 == r9 - r11 = r6 & r10 - if r11 goto L2 else goto L3 :: bool + r1 = i & 1 + r2 = r1 == 0 + r3 = l & 1 + r4 = r3 == 0 + r5 = r2 & r4 + if r5 goto L2 else goto L3 :: bool L2: - r12 = i < l :: signed - r2 = r12 + r6 = i < l :: signed + r0 = r6 goto L4 L3: - r13 = CPyTagged_IsLt_(i, l) - r2 = r13 + r7 = CPyTagged_IsLt_(i, l) + r0 = r7 L4: - if r2 goto L5 else goto L10 :: bool + if r0 goto L5 else goto L10 :: bool L5: - r14 = CPyList_GetItem(a, i) - if is_error(r14) goto L11 (error at sum:6) else goto L6 + r8 = CPyList_GetItem(a, i) + if is_error(r8) goto L11 (error at sum:6) else goto L6 L6: - r15 = unbox(int, r14) - dec_ref r14 - if is_error(r15) goto L11 (error at sum:6) else goto L7 + r9 = unbox(int, r8) + dec_ref r8 + if is_error(r9) goto L11 (error at sum:6) else goto L7 L7: - r16 = CPyTagged_Add(sum, r15) + r10 = CPyTagged_Add(sum, r9) dec_ref sum :: int - dec_ref r15 :: int - sum = r16 - r17 = 2 - r18 = CPyTagged_Add(i, r17) + dec_ref r9 :: int + sum = r10 + r11 = CPyTagged_Add(i, 2) dec_ref i :: int - i = r18 + i = r11 goto L1 L8: return sum L9: - r19 = :: int - return r19 + r12 = :: int + return r12 L10: dec_ref i :: int goto L8 @@ -281,7 +264,6 @@ def a(): r14, r15 :: object r16 :: bool r17 :: str - r18 :: bool L0: L1: r0 = builtins :: module @@ -319,8 +301,7 @@ L8: if is_error(r6) goto L11 else goto L9 L9: CPy_Reraise() - r18 = 0 - if not r18 goto L13 else goto L22 :: bool + if not 0 goto L13 else goto L22 :: bool L10: unreachable L11: diff --git a/mypyc/test-data/irbuild-basic.test b/mypyc/test-data/irbuild-basic.test index b586371bb2d2..65a4b66dcabb 100644 --- a/mypyc/test-data/irbuild-basic.test +++ b/mypyc/test-data/irbuild-basic.test @@ -3,11 +3,8 @@ def f() -> int: return 1 [out] def f(): - r0 :: short_int L0: - r0 = 2 - return r0 - + return 2 [case testFunctionArgument] def f(x: int) -> int: return x @@ -17,6 +14,7 @@ def f(x): L0: return x + [case testExplicitNoneReturn] def f() -> None: return @@ -44,11 +42,9 @@ def f() -> int: return y [out] def f(): - r0 :: short_int x, y :: int L0: - r0 = 2 - x = r0 + x = 2 y = x return y @@ -60,15 +56,13 @@ def f(x: int) -> None: [out] def f(x): x :: int - r0 :: short_int y :: int - r1 :: None + r0 :: None L0: - r0 = 2 - y = r0 + y = 2 y = x - r1 = None - return r1 + r0 = None + return r0 [case testIntArithmetic] def f(x: int, y: int) -> int: @@ -76,13 +70,11 @@ def f(x: int, y: int) -> int: [out] def f(x, y): x, y :: int - r0 :: short_int - r1, r2 :: int + r0, r1 :: int L0: - r0 = 2 - r1 = CPyTagged_Add(y, r0) - r2 = CPyTagged_Multiply(x, r1) - return r2 + r0 = CPyTagged_Add(y, 2) + r1 = CPyTagged_Multiply(x, r0) + return r1 [case testIf] def f(x: int, y: int) -> int: @@ -93,34 +85,28 @@ def f(x: int, y: int) -> int: def f(x, y): x, y :: int r0 :: bool - r1, r2, r3 :: native_int - r4 :: bool - r5, r6, r7 :: native_int - r8, r9, r10, r11 :: bool - r12 :: short_int -L0: - r1 = 1 - r2 = x & r1 - r3 = 0 - r4 = r2 == r3 - r5 = 1 - r6 = y & r5 - r7 = 0 - r8 = r6 == r7 - r9 = r4 & r8 - if r9 goto L1 else goto L2 :: bool + r1 :: native_int + r2 :: bool + r3 :: native_int + r4, r5, r6, r7 :: bool +L0: + r1 = x & 1 + r2 = r1 == 0 + r3 = y & 1 + r4 = r3 == 0 + r5 = r2 & r4 + if r5 goto L1 else goto L2 :: bool L1: - r10 = x < y :: signed - r0 = r10 + r6 = x < y :: signed + r0 = r6 goto L3 L2: - r11 = CPyTagged_IsLt_(x, y) - r0 = r11 + r7 = CPyTagged_IsLt_(x, y) + r0 = r7 L3: if r0 goto L4 else goto L5 :: bool L4: - r12 = 2 - x = r12 + x = 2 L5: return x @@ -135,38 +121,31 @@ def f(x: int, y: int) -> int: def f(x, y): x, y :: int r0 :: bool - r1, r2, r3 :: native_int - r4 :: bool - r5, r6, r7 :: native_int - r8, r9, r10, r11 :: bool - r12, r13 :: short_int -L0: - r1 = 1 - r2 = x & r1 - r3 = 0 - r4 = r2 == r3 - r5 = 1 - r6 = y & r5 - r7 = 0 - r8 = r6 == r7 - r9 = r4 & r8 - if r9 goto L1 else goto L2 :: bool + r1 :: native_int + r2 :: bool + r3 :: native_int + r4, r5, r6, r7 :: bool +L0: + r1 = x & 1 + r2 = r1 == 0 + r3 = y & 1 + r4 = r3 == 0 + r5 = r2 & r4 + if r5 goto L1 else goto L2 :: bool L1: - r10 = x < y :: signed - r0 = r10 + r6 = x < y :: signed + r0 = r6 goto L3 L2: - r11 = CPyTagged_IsLt_(x, y) - r0 = r11 + r7 = CPyTagged_IsLt_(x, y) + r0 = r7 L3: if r0 goto L4 else goto L5 :: bool L4: - r12 = 2 - x = r12 + x = 2 goto L6 L5: - r13 = 4 - x = r13 + x = 4 L6: return x @@ -181,41 +160,34 @@ def f(x: int, y: int) -> int: def f(x, y): x, y :: int r0 :: bool - r1, r2, r3 :: native_int - r4 :: bool - r5, r6, r7 :: native_int - r8, r9, r10, r11, r12 :: bool - r13, r14 :: short_int -L0: - r1 = 1 - r2 = x & r1 - r3 = 0 - r4 = r2 == r3 - r5 = 1 - r6 = y & r5 - r7 = 0 - r8 = r6 == r7 - r9 = r4 & r8 - if r9 goto L1 else goto L2 :: bool + r1 :: native_int + r2 :: bool + r3 :: native_int + r4, r5, r6, r7, r8 :: bool +L0: + r1 = x & 1 + r2 = r1 == 0 + r3 = y & 1 + r4 = r3 == 0 + r5 = r2 & r4 + if r5 goto L1 else goto L2 :: bool L1: - r10 = x < y :: signed - r0 = r10 + r6 = x < y :: signed + r0 = r6 goto L3 L2: - r11 = CPyTagged_IsLt_(x, y) - r0 = r11 + r7 = CPyTagged_IsLt_(x, y) + r0 = r7 L3: if r0 goto L4 else goto L6 :: bool L4: - r12 = CPyTagged_IsGt(x, y) - if r12 goto L5 else goto L6 :: bool + r8 = CPyTagged_IsGt(x, y) + if r8 goto L5 else goto L6 :: bool L5: - r13 = 2 - x = r13 + x = 2 goto L7 L6: - r14 = 4 - x = r14 + x = 4 L7: return x @@ -252,41 +224,34 @@ def f(x: int, y: int) -> int: def f(x, y): x, y :: int r0 :: bool - r1, r2, r3 :: native_int - r4 :: bool - r5, r6, r7 :: native_int - r8, r9, r10, r11, r12 :: bool - r13, r14 :: short_int -L0: - r1 = 1 - r2 = x & r1 - r3 = 0 - r4 = r2 == r3 - r5 = 1 - r6 = y & r5 - r7 = 0 - r8 = r6 == r7 - r9 = r4 & r8 - if r9 goto L1 else goto L2 :: bool + r1 :: native_int + r2 :: bool + r3 :: native_int + r4, r5, r6, r7, r8 :: bool +L0: + r1 = x & 1 + r2 = r1 == 0 + r3 = y & 1 + r4 = r3 == 0 + r5 = r2 & r4 + if r5 goto L1 else goto L2 :: bool L1: - r10 = x < y :: signed - r0 = r10 + r6 = x < y :: signed + r0 = r6 goto L3 L2: - r11 = CPyTagged_IsLt_(x, y) - r0 = r11 + r7 = CPyTagged_IsLt_(x, y) + r0 = r7 L3: if r0 goto L5 else goto L4 :: bool L4: - r12 = CPyTagged_IsGt(x, y) - if r12 goto L5 else goto L6 :: bool + r8 = CPyTagged_IsGt(x, y) + if r8 goto L5 else goto L6 :: bool L5: - r13 = 2 - x = r13 + x = 2 goto L7 L6: - r14 = 4 - x = r14 + x = 4 L7: return x @@ -321,34 +286,28 @@ def f(x: int, y: int) -> int: def f(x, y): x, y :: int r0 :: bool - r1, r2, r3 :: native_int - r4 :: bool - r5, r6, r7 :: native_int - r8, r9, r10, r11 :: bool - r12 :: short_int -L0: - r1 = 1 - r2 = x & r1 - r3 = 0 - r4 = r2 == r3 - r5 = 1 - r6 = y & r5 - r7 = 0 - r8 = r6 == r7 - r9 = r4 & r8 - if r9 goto L1 else goto L2 :: bool + r1 :: native_int + r2 :: bool + r3 :: native_int + r4, r5, r6, r7 :: bool +L0: + r1 = x & 1 + r2 = r1 == 0 + r3 = y & 1 + r4 = r3 == 0 + r5 = r2 & r4 + if r5 goto L1 else goto L2 :: bool L1: - r10 = x < y :: signed - r0 = r10 + r6 = x < y :: signed + r0 = r6 goto L3 L2: - r11 = CPyTagged_IsLt_(x, y) - r0 = r11 + r7 = CPyTagged_IsLt_(x, y) + r0 = r7 L3: if r0 goto L5 else goto L4 :: bool L4: - r12 = 2 - x = r12 + x = 2 L5: return x @@ -361,37 +320,31 @@ def f(x: int, y: int) -> int: def f(x, y): x, y :: int r0 :: bool - r1, r2, r3 :: native_int - r4 :: bool - r5, r6, r7 :: native_int - r8, r9, r10, r11, r12 :: bool - r13 :: short_int -L0: - r1 = 1 - r2 = x & r1 - r3 = 0 - r4 = r2 == r3 - r5 = 1 - r6 = y & r5 - r7 = 0 - r8 = r6 == r7 - r9 = r4 & r8 - if r9 goto L1 else goto L2 :: bool + r1 :: native_int + r2 :: bool + r3 :: native_int + r4, r5, r6, r7, r8 :: bool +L0: + r1 = x & 1 + r2 = r1 == 0 + r3 = y & 1 + r4 = r3 == 0 + r5 = r2 & r4 + if r5 goto L1 else goto L2 :: bool L1: - r10 = x < y :: signed - r0 = r10 + r6 = x < y :: signed + r0 = r6 goto L3 L2: - r11 = CPyTagged_IsLt_(x, y) - r0 = r11 + r7 = CPyTagged_IsLt_(x, y) + r0 = r7 L3: if r0 goto L4 else goto L5 :: bool L4: - r12 = CPyTagged_IsGt(x, y) - if r12 goto L6 else goto L5 :: bool + r8 = CPyTagged_IsGt(x, y) + if r8 goto L6 else goto L5 :: bool L5: - r13 = 2 - x = r13 + x = 2 L6: return x @@ -425,18 +378,16 @@ def f(x: int, y: int) -> int: [out] def f(x, y): x, y :: int - r0 :: short_int - r1 :: bool - r2 :: int + r0 :: bool + r1 :: int L0: - r0 = 2 - x = r0 + x = 2 L1: - r1 = CPyTagged_IsGt(x, y) - if r1 goto L2 else goto L3 :: bool + r0 = CPyTagged_IsGt(x, y) + if r0 goto L2 else goto L3 :: bool L2: - r2 = CPyTagged_Subtract(x, y) - x = r2 + r1 = CPyTagged_Subtract(x, y) + x = r1 goto L1 L3: return x @@ -456,14 +407,12 @@ def f() -> None: x = 1 [out] def f(): - r0 :: short_int x :: int - r1 :: None + r0 :: None L0: - r0 = 2 - x = r0 - r1 = None - return r1 + x = 2 + r0 = None + return r0 [case testImplicitNoneReturnAndIf] def f(x: int, y: int) -> None: @@ -475,42 +424,35 @@ def f(x: int, y: int) -> None: def f(x, y): x, y :: int r0 :: bool - r1, r2, r3 :: native_int - r4 :: bool - r5, r6, r7 :: native_int - r8, r9, r10, r11 :: bool - r12, r13 :: short_int - r14 :: None + r1 :: native_int + r2 :: bool + r3 :: native_int + r4, r5, r6, r7 :: bool + r8 :: None L0: - r1 = 1 - r2 = x & r1 - r3 = 0 - r4 = r2 == r3 - r5 = 1 - r6 = y & r5 - r7 = 0 - r8 = r6 == r7 - r9 = r4 & r8 - if r9 goto L1 else goto L2 :: bool + r1 = x & 1 + r2 = r1 == 0 + r3 = y & 1 + r4 = r3 == 0 + r5 = r2 & r4 + if r5 goto L1 else goto L2 :: bool L1: - r10 = x < y :: signed - r0 = r10 + r6 = x < y :: signed + r0 = r6 goto L3 L2: - r11 = CPyTagged_IsLt_(x, y) - r0 = r11 + r7 = CPyTagged_IsLt_(x, y) + r0 = r7 L3: if r0 goto L4 else goto L5 :: bool L4: - r12 = 2 - x = r12 + x = 2 goto L6 L5: - r13 = 4 - y = r13 + y = 4 L6: - r14 = None - return r14 + r8 = None + return r8 [case testRecursion] def f(n: int) -> int: @@ -521,28 +463,21 @@ def f(n: int) -> int: [out] def f(n): n :: int - r0 :: short_int - r1 :: bool - r2, r3 :: short_int - r4, r5 :: int - r6 :: short_int - r7, r8, r9 :: int + r0 :: bool + r1, r2 :: int + r3, r4, r5 :: int L0: - r0 = 2 - r1 = CPyTagged_IsLe(n, r0) - if r1 goto L1 else goto L2 :: bool + r0 = CPyTagged_IsLe(n, 2) + if r0 goto L1 else goto L2 :: bool L1: - r2 = 2 - return r2 + return 2 L2: - r3 = 2 - r4 = CPyTagged_Subtract(n, r3) - r5 = f(r4) - r6 = 4 - r7 = CPyTagged_Subtract(n, r6) - r8 = f(r7) - r9 = CPyTagged_Add(r5, r8) - return r9 + r1 = CPyTagged_Subtract(n, 2) + r2 = f(r1) + r3 = CPyTagged_Subtract(n, 4) + r4 = f(r3) + r5 = CPyTagged_Add(r2, r4) + return r5 L3: unreachable @@ -570,32 +505,23 @@ def f(n: int) -> int: [out] def f(n): n :: int - r0 :: short_int - r1 :: bool - r2 :: short_int + r0 :: bool x :: int - r3 :: short_int - r4 :: bool - r5, r6 :: short_int + r1 :: bool L0: - r0 = 0 - r1 = CPyTagged_IsLt(n, r0) - if r1 goto L1 else goto L2 :: bool + r0 = CPyTagged_IsLt(n, 0) + if r0 goto L1 else goto L2 :: bool L1: - r2 = 2 - x = r2 + x = 2 goto L6 L2: - r3 = 0 - r4 = CPyTagged_IsEq(n, r3) - if r4 goto L3 else goto L4 :: bool + r1 = CPyTagged_IsEq(n, 0) + if r1 goto L3 else goto L4 :: bool L3: - r5 = 2 - x = r5 + x = 2 goto L5 L4: - r6 = 4 - x = r6 + x = 4 L5: L6: return x @@ -606,12 +532,10 @@ def f(n: int) -> int: [out] def f(n): n :: int - r0 :: short_int - r1 :: int + r0 :: int L0: - r0 = 2 - r1 = CPyTagged_Negate(r0) - return r1 + r0 = CPyTagged_Negate(2) + return r0 [case testConditionalExpr] def f(n: int) -> int: @@ -619,23 +543,18 @@ def f(n: int) -> int: [out] def f(n): n :: int - r0 :: short_int - r1 :: bool - r2 :: int - r3, r4 :: short_int + r0 :: bool + r1 :: int L0: - r0 = 0 - r1 = CPyTagged_IsEq(n, r0) - if r1 goto L1 else goto L2 :: bool + r0 = CPyTagged_IsEq(n, 0) + if r0 goto L1 else goto L2 :: bool L1: - r3 = 0 - r2 = r3 + r1 = 0 goto L3 L2: - r4 = 2 - r2 = r4 + r1 = 2 L3: - return r2 + return r1 [case testOperatorAssignment] def f() -> int: @@ -644,16 +563,12 @@ def f() -> int: return x [out] def f(): - r0 :: short_int x :: int - r1 :: short_int - r2 :: int + r0 :: int L0: - r0 = 0 + x = 0 + r0 = CPyTagged_Add(x, 2) x = r0 - r1 = 2 - r2 = CPyTagged_Add(x, r1) - x = r2 return x [case testTrue] @@ -757,18 +672,16 @@ def f(x): r0 :: object r1 :: str r2 :: object - r3 :: short_int - r4, r5 :: object - r6 :: None + r3, r4 :: object + r5 :: None L0: r0 = builtins :: module r1 = unicode_1 :: static ('print') r2 = getattr r0, r1 - r3 = 10 - r4 = box(short_int, r3) - r5 = py_call(r2, r4) - r6 = None - return r6 + r3 = box(short_int, 10) + r4 = py_call(r2, r3) + r5 = None + return r5 [case testPrint] import builtins @@ -777,20 +690,18 @@ def f(x: int) -> None: [out] def f(x): x :: int - r0 :: short_int - r1 :: object - r2 :: str - r3, r4, r5 :: object - r6 :: None -L0: - r0 = 10 - r1 = builtins :: module - r2 = unicode_1 :: static ('print') - r3 = getattr r1, r2 - r4 = box(short_int, r0) - r5 = py_call(r3, r4) - r6 = None - return r6 + r0 :: object + r1 :: str + r2, r3, r4 :: object + r5 :: None +L0: + r0 = builtins :: module + r1 = unicode_1 :: static ('print') + r2 = getattr r0, r1 + r3 = box(short_int, 10) + r4 = py_call(r2, r3) + r5 = None + return r5 [case testUnicodeLiteral] def f() -> str: @@ -851,23 +762,21 @@ def g(y: object) -> None: def g(y): y :: object r0 :: None - r1 :: short_int - r2 :: object - r3 :: list - r4, r5 :: None - r6 :: object - r7, r8 :: None + r1 :: object + r2 :: list + r3, r4 :: None + r5 :: object + r6, r7 :: None L0: r0 = g(y) - r1 = 2 - r2 = box(short_int, r1) - r3 = [r2] - r4 = g(r3) - r5 = None - r6 = box(None, r5) - r7 = g(r6) - r8 = None - return r8 + r1 = box(short_int, 2) + r2 = [r1] + r3 = g(r2) + r4 = None + r5 = box(None, r4) + r6 = g(r5) + r7 = None + return r7 [case testCoerceToObject1] def g(y: object) -> object: @@ -879,35 +788,26 @@ def g(y: object) -> object: [out] def g(y): y :: object - r0 :: short_int - r1, r2 :: object - r3, a :: list - r4, r5 :: short_int - r6 :: tuple[int, int] - r7 :: short_int + r0, r1 :: object + r2, a :: list + r3 :: tuple[int, int] + r4 :: object + r5, r6 :: bool + r7 :: object r8 :: object - r9, r10 :: bool - r11 :: object - r12 :: short_int - r13 :: object L0: - r0 = 2 - r1 = box(short_int, r0) - r2 = g(r1) - r3 = [y] - a = r3 - r4 = 2 - r5 = 4 - r6 = (r4, r5) - r7 = 0 - r8 = box(tuple[int, int], r6) - r9 = CPyList_SetItem(a, r7, r8) - r10 = True - r11 = box(bool, r10) - y = r11 - r12 = 6 - r13 = box(short_int, r12) - return r13 + r0 = box(short_int, 2) + r1 = g(r0) + r2 = [y] + a = r2 + r3 = (2, 4) + r4 = box(tuple[int, int], r3) + r5 = CPyList_SetItem(a, 0, r4) + r6 = True + r7 = box(bool, r6) + y = r7 + r8 = box(short_int, 6) + return r8 [case testCoerceToObject2] class A: @@ -920,21 +820,19 @@ def f(a: A, o: object) -> None: def f(a, o): a :: __main__.A o :: object - r0 :: short_int - r1 :: object - r2 :: bool - r3 :: int - r4 :: object - r5 :: None + r0 :: object + r1 :: bool + r2 :: int + r3 :: object + r4 :: None L0: - r0 = 2 - r1 = box(short_int, r0) - a.x = r1; r2 = is_error - r3 = a.n - r4 = box(int, r3) - o = r4 - r5 = None - return r5 + r0 = box(short_int, 2) + a.x = r0; r1 = is_error + r2 = a.n + r3 = box(int, r2) + o = r3 + r4 = None + return r4 [case testDownCast] from typing import cast, List, Tuple @@ -1117,9 +1015,8 @@ def big_int() -> None: [out] def big_int(): r0, a_62_bit, r1, max_62_bit, r2, b_63_bit, r3, c_63_bit, r4, max_63_bit, r5, d_64_bit, r6, max_32_bit :: int - r7 :: short_int max_31_bit :: int - r8 :: None + r7 :: None L0: r0 = int_1 :: static (4611686018427387902) a_62_bit = r0 @@ -1135,10 +1032,9 @@ L0: d_64_bit = r5 r6 = int_7 :: static (2147483647) max_32_bit = r6 - r7 = 2147483646 - max_31_bit = r7 - r8 = None - return r8 + max_31_bit = 2147483646 + r7 = None + return r7 [case testCallableTypes] from typing import Callable @@ -1163,21 +1059,19 @@ def call_callable_type() -> float: [out] def absolute_value(x): x :: int - r0 :: short_int - r1 :: bool - r2, r3 :: int + r0 :: bool + r1, r2 :: int L0: - r0 = 0 - r1 = CPyTagged_IsGt(x, r0) - if r1 goto L1 else goto L2 :: bool + r0 = CPyTagged_IsGt(x, 0) + if r0 goto L1 else goto L2 :: bool L1: - r2 = x + r1 = x goto L3 L2: - r3 = CPyTagged_Negate(x) - r2 = r3 + r2 = CPyTagged_Negate(x) + r1 = r2 L3: - return r2 + return r1 def call_native_function(x): x, r0 :: int L0: @@ -1231,70 +1125,58 @@ def call_python_method_with_keyword_args(xs: List[int], first: int, second: int) [out] def call_python_function_with_keyword_arg(x): x :: str - r0 :: short_int - r1 :: object - r2 :: str - r3 :: tuple - r4 :: native_int + r0 :: object + r1 :: str + r2 :: tuple + r3 :: object + r4 :: dict r5 :: object - r6 :: dict - r7 :: object - r8 :: int -L0: - r0 = 4 - r1 = int - r2 = unicode_3 :: static ('base') - r3 = (x) :: tuple - r4 = 1 - r5 = box(short_int, r0) - r6 = CPyDict_Build(r4, r2, r5) - r7 = py_call_with_kwargs(r1, r3, r6) - r8 = unbox(int, r7) - return r8 + r6 :: int +L0: + r0 = int + r1 = unicode_3 :: static ('base') + r2 = (x) :: tuple + r3 = box(short_int, 4) + r4 = CPyDict_Build(1, r1, r3) + r5 = py_call_with_kwargs(r0, r2, r4) + r6 = unbox(int, r5) + return r6 def call_python_method_with_keyword_args(xs, first, second): xs :: list first, second :: int - r0 :: short_int - r1 :: str - r2 :: object - r3 :: str - r4 :: object - r5 :: tuple - r6 :: native_int + r0 :: str + r1 :: object + r2 :: str + r3 :: object + r4 :: tuple + r5 :: object + r6 :: dict r7 :: object - r8 :: dict + r8 :: str r9 :: object - r10 :: short_int - r11 :: str - r12 :: object - r13, r14 :: str - r15 :: tuple - r16 :: native_int - r17, r18 :: object - r19 :: dict - r20 :: object + r10, r11 :: str + r12 :: tuple + r13, r14 :: object + r15 :: dict + r16 :: object L0: - r0 = 0 - r1 = unicode_4 :: static ('insert') - r2 = getattr xs, r1 - r3 = unicode_5 :: static ('x') - r4 = box(short_int, r0) - r5 = (r4) :: tuple - r6 = 1 - r7 = box(int, first) - r8 = CPyDict_Build(r6, r3, r7) - r9 = py_call_with_kwargs(r2, r5, r8) - r10 = 2 - r11 = unicode_4 :: static ('insert') - r12 = getattr xs, r11 - r13 = unicode_5 :: static ('x') - r14 = unicode_6 :: static ('i') - r15 = () :: tuple - r16 = 2 - r17 = box(int, second) - r18 = box(short_int, r10) - r19 = CPyDict_Build(r16, r13, r17, r14, r18) - r20 = py_call_with_kwargs(r12, r15, r19) + r0 = unicode_4 :: static ('insert') + r1 = getattr xs, r0 + r2 = unicode_5 :: static ('x') + r3 = box(short_int, 0) + r4 = (r3) :: tuple + r5 = box(int, first) + r6 = CPyDict_Build(1, r2, r5) + r7 = py_call_with_kwargs(r1, r4, r6) + r8 = unicode_4 :: static ('insert') + r9 = getattr xs, r8 + r10 = unicode_5 :: static ('x') + r11 = unicode_6 :: static ('i') + r12 = () :: tuple + r13 = box(int, second) + r14 = box(short_int, 2) + r15 = CPyDict_Build(2, r10, r13, r11, r14) + r16 = py_call_with_kwargs(r9, r12, r15) return xs [case testObjectAsBoolean] @@ -1321,51 +1203,39 @@ def lst(x: List[int]) -> int: def obj(x): x :: object r0 :: bool - r1, r2 :: short_int L0: r0 = bool x :: object if r0 goto L1 else goto L2 :: bool L1: - r1 = 2 - return r1 + return 2 L2: - r2 = 0 - return r2 + return 0 L3: unreachable def num(x): x :: int - r0 :: short_int - r1 :: bool - r2, r3 :: short_int + r0 :: bool L0: - r0 = 0 - r1 = CPyTagged_IsNe(x, r0) - if r1 goto L1 else goto L2 :: bool + r0 = CPyTagged_IsNe(x, 0) + if r0 goto L1 else goto L2 :: bool L1: - r2 = 2 - return r2 + return 2 L2: - r3 = 0 - return r3 + return 0 L3: unreachable def lst(x): x :: list - r0, r1 :: short_int - r2 :: bool - r3, r4 :: short_int + r0 :: short_int + r1 :: bool L0: r0 = len x :: list - r1 = 0 - r2 = r0 != r1 - if r2 goto L1 else goto L2 :: bool + r1 = r0 != 0 + if r1 goto L1 else goto L2 :: bool L1: - r3 = 2 - return r3 + return 2 L2: - r4 = 0 - return r4 + return 0 L3: unreachable @@ -1397,41 +1267,33 @@ def opt_int(x): r0 :: object r1 :: bool r2 :: int - r3 :: short_int - r4 :: bool - r5, r6 :: short_int + r3 :: bool L0: r0 = builtins.None :: object r1 = x is not r0 if r1 goto L1 else goto L3 :: bool L1: r2 = unbox(int, x) - r3 = 0 - r4 = CPyTagged_IsNe(r2, r3) - if r4 goto L2 else goto L3 :: bool + r3 = CPyTagged_IsNe(r2, 0) + if r3 goto L2 else goto L3 :: bool L2: - r5 = 2 - return r5 + return 2 L3: - r6 = 0 - return r6 + return 0 L4: unreachable def opt_a(x): x :: union[__main__.A, None] r0 :: object r1 :: bool - r2, r3 :: short_int L0: r0 = builtins.None :: object r1 = x is not r0 if r1 goto L1 else goto L2 :: bool L1: - r2 = 2 - return r2 + return 2 L2: - r3 = 0 - return r3 + return 0 L3: unreachable def opt_o(x): @@ -1440,7 +1302,6 @@ def opt_o(x): r1 :: bool r2 :: object r3 :: bool - r4, r5 :: short_int L0: r0 = builtins.None :: object r1 = x is not r0 @@ -1450,11 +1311,9 @@ L1: r3 = bool r2 :: object if r3 goto L2 else goto L3 :: bool L2: - r4 = 2 - return r4 + return 2 L3: - r5 = 0 - return r5 + return 0 L4: unreachable @@ -1520,19 +1379,18 @@ def __top_level__(): r2 :: bool r3 :: str r4 :: object - r5 :: short_int - r6 :: dict - r7 :: str - r8 :: object - r9 :: int32 - r10 :: dict - r11 :: str - r12 :: object - r13 :: int - r14 :: object - r15 :: str - r16, r17, r18 :: object - r19 :: None + r5 :: dict + r6 :: str + r7 :: object + r8 :: int32 + r9 :: dict + r10 :: str + r11 :: object + r12 :: int + r13 :: object + r14 :: str + r15, r16, r17 :: object + r18 :: None L0: r0 = builtins :: module r1 = builtins.None :: object @@ -1543,22 +1401,21 @@ L1: r4 = import r3 :: str builtins = r4 :: module L2: - r5 = 2 - r6 = __main__.globals :: static - r7 = unicode_1 :: static ('x') - r8 = box(short_int, r5) - r9 = CPyDict_SetItem(r6, r7, r8) - r10 = __main__.globals :: static - r11 = unicode_1 :: static ('x') - r12 = CPyDict_GetItem(r10, r11) - r13 = unbox(int, r12) - r14 = builtins :: module - r15 = unicode_2 :: static ('print') - r16 = getattr r14, r15 - r17 = box(int, r13) - r18 = py_call(r16, r17) - r19 = None - return r19 + r5 = __main__.globals :: static + r6 = unicode_1 :: static ('x') + r7 = box(short_int, 2) + r8 = CPyDict_SetItem(r5, r6, r7) + r9 = __main__.globals :: static + r10 = unicode_1 :: static ('x') + r11 = CPyDict_GetItem(r9, r10) + r12 = unbox(int, r11) + r13 = builtins :: module + r14 = unicode_2 :: static ('print') + r15 = getattr r13, r14 + r16 = box(int, r12) + r17 = py_call(r15, r16) + r18 = None + return r18 [case testCallOverloaded] import m @@ -1575,18 +1432,16 @@ def f(): r0 :: object r1 :: str r2 :: object - r3 :: short_int - r4, r5 :: object - r6 :: str + r3, r4 :: object + r5 :: str L0: r0 = m :: module r1 = unicode_2 :: static ('f') r2 = getattr r0, r1 - r3 = 2 - r4 = box(short_int, r3) - r5 = py_call(r2, r4) - r6 = cast(str, r5) - return r6 + r3 = box(short_int, 2) + r4 = py_call(r2, r3) + r5 = cast(str, r4) + return r5 [case testCallOverloadedNative] from typing import overload, Union @@ -1608,19 +1463,17 @@ def foo(x): L0: return x def main(): - r0 :: short_int - r1 :: object - r2 :: union[int, str] - r3, x :: int - r4 :: None + r0 :: object + r1 :: union[int, str] + r2, x :: int + r3 :: None L0: - r0 = 0 - r1 = box(short_int, r0) - r2 = foo(r1) - r3 = unbox(int, r2) - x = r3 - r4 = None - return r4 + r0 = box(short_int, 0) + r1 = foo(r0) + r2 = unbox(int, r1) + x = r2 + r3 = None + return r3 [case testCallOverloadedNativeSubclass] from typing import overload, Union @@ -1663,19 +1516,17 @@ L2: r4 = A() return r4 def main(): - r0 :: short_int - r1 :: object - r2 :: __main__.A - r3, x :: __main__.B - r4 :: None + r0 :: object + r1 :: __main__.A + r2, x :: __main__.B + r3 :: None L0: - r0 = 0 - r1 = box(short_int, r0) - r2 = foo(r1) - r3 = cast(__main__.B, r2) - x = r3 - r4 = None - return r4 + r0 = box(short_int, 0) + r1 = foo(r0) + r2 = cast(__main__.B, r1) + x = r2 + r3 = None + return r3 [case testFunctionCallWithKeywordArgs] def f(x: int, y: str) -> None: pass @@ -1693,20 +1544,16 @@ L0: return r0 def g(): r0 :: str - r1 :: short_int - r2 :: None - r3 :: short_int - r4 :: str - r5, r6 :: None + r1 :: None + r2 :: str + r3, r4 :: None L0: r0 = unicode_1 :: static ('a') - r1 = 0 - r2 = f(r1, r0) - r3 = 2 - r4 = unicode_2 :: static ('b') - r5 = f(r3, r4) - r6 = None - return r6 + r1 = f(0, r0) + r2 = unicode_2 :: static ('b') + r3 = f(2, r2) + r4 = None + return r4 [case testMethodCallWithKeywordArgs] class A: @@ -1727,20 +1574,16 @@ L0: def g(a): a :: __main__.A r0 :: str - r1 :: short_int - r2 :: None - r3 :: short_int - r4 :: str - r5, r6 :: None + r1 :: None + r2 :: str + r3, r4 :: None L0: r0 = unicode_4 :: static ('a') - r1 = 0 - r2 = a.f(r1, r0) - r3 = 2 - r4 = unicode_5 :: static ('b') - r5 = a.f(r3, r4) - r6 = None - return r6 + r1 = a.f(0, r0) + r2 = unicode_5 :: static ('b') + r3 = a.f(2, r2) + r4 = None + return r4 [case testStarArgs] from typing import Tuple @@ -1758,62 +1601,54 @@ L0: r0 = (a, b, c) return r0 def g(): - r0, r1, r2 :: short_int - r3 :: tuple[int, int, int] - r4 :: dict - r5 :: str - r6 :: object - r7 :: list - r8, r9 :: object - r10 :: tuple - r11 :: dict - r12 :: object - r13 :: tuple[int, int, int] -L0: - r0 = 2 - r1 = 4 - r2 = 6 - r3 = (r0, r1, r2) - r4 = __main__.globals :: static - r5 = unicode_3 :: static ('f') - r6 = CPyDict_GetItem(r4, r5) - r7 = [] - r8 = box(tuple[int, int, int], r3) - r9 = CPyList_Extend(r7, r8) - r10 = PyList_AsTuple(r7) - r11 = PyDict_New() - r12 = py_call_with_kwargs(r6, r10, r11) - r13 = unbox(tuple[int, int, int], r12) - return r13 + r0 :: tuple[int, int, int] + r1 :: dict + r2 :: str + r3 :: object + r4 :: list + r5, r6 :: object + r7 :: tuple + r8 :: dict + r9 :: object + r10 :: tuple[int, int, int] +L0: + r0 = (2, 4, 6) + r1 = __main__.globals :: static + r2 = unicode_3 :: static ('f') + r3 = CPyDict_GetItem(r1, r2) + r4 = [] + r5 = box(tuple[int, int, int], r0) + r6 = CPyList_Extend(r4, r5) + r7 = PyList_AsTuple(r4) + r8 = PyDict_New() + r9 = py_call_with_kwargs(r3, r7, r8) + r10 = unbox(tuple[int, int, int], r9) + return r10 def h(): - r0, r1, r2 :: short_int - r3 :: tuple[int, int] - r4 :: dict - r5 :: str + r0 :: tuple[int, int] + r1 :: dict + r2 :: str + r3, r4 :: object + r5 :: list r6, r7 :: object - r8 :: list - r9, r10 :: object - r11 :: tuple - r12 :: dict - r13 :: object - r14 :: tuple[int, int, int] -L0: - r0 = 2 - r1 = 4 - r2 = 6 - r3 = (r1, r2) - r4 = __main__.globals :: static - r5 = unicode_3 :: static ('f') - r6 = CPyDict_GetItem(r4, r5) - r7 = box(short_int, r0) - r8 = [r7] - r9 = box(tuple[int, int], r3) - r10 = CPyList_Extend(r8, r9) - r11 = PyList_AsTuple(r8) - r12 = PyDict_New() - r13 = py_call_with_kwargs(r6, r11, r12) - r14 = unbox(tuple[int, int, int], r13) - return r14 + r8 :: tuple + r9 :: dict + r10 :: object + r11 :: tuple[int, int, int] +L0: + r0 = (4, 6) + r1 = __main__.globals :: static + r2 = unicode_3 :: static ('f') + r3 = CPyDict_GetItem(r1, r2) + r4 = box(short_int, 2) + r5 = [r4] + r6 = box(tuple[int, int], r0) + r7 = CPyList_Extend(r5, r6) + r8 = PyList_AsTuple(r5) + r9 = PyDict_New() + r10 = py_call_with_kwargs(r3, r8, r9) + r11 = unbox(tuple[int, int, int], r10) + return r11 [case testStar2Args] from typing import Tuple @@ -1832,78 +1667,62 @@ L0: return r0 def g(): r0 :: str - r1 :: short_int + r1 :: str r2 :: str - r3 :: short_int - r4 :: str - r5 :: short_int - r6 :: native_int - r7, r8, r9 :: object - r10, r11 :: dict - r12 :: str + r3, r4, r5 :: object + r6, r7 :: dict + r8 :: str + r9 :: object + r10 :: tuple + r11 :: dict + r12 :: int32 r13 :: object - r14 :: tuple - r15 :: dict - r16 :: int32 - r17 :: object - r18 :: tuple[int, int, int] + r14 :: tuple[int, int, int] L0: r0 = unicode_3 :: static ('a') - r1 = 2 - r2 = unicode_4 :: static ('b') - r3 = 4 - r4 = unicode_5 :: static ('c') - r5 = 6 - r6 = 3 - r7 = box(short_int, r1) - r8 = box(short_int, r3) - r9 = box(short_int, r5) - r10 = CPyDict_Build(r6, r0, r7, r2, r8, r4, r9) - r11 = __main__.globals :: static - r12 = unicode_6 :: static ('f') - r13 = CPyDict_GetItem(r11, r12) - r14 = () :: tuple - r15 = PyDict_New() - r16 = CPyDict_UpdateInDisplay(r15, r10) - r17 = py_call_with_kwargs(r13, r14, r15) - r18 = unbox(tuple[int, int, int], r17) - return r18 + r1 = unicode_4 :: static ('b') + r2 = unicode_5 :: static ('c') + r3 = box(short_int, 2) + r4 = box(short_int, 4) + r5 = box(short_int, 6) + r6 = CPyDict_Build(3, r0, r3, r1, r4, r2, r5) + r7 = __main__.globals :: static + r8 = unicode_6 :: static ('f') + r9 = CPyDict_GetItem(r7, r8) + r10 = () :: tuple + r11 = PyDict_New() + r12 = CPyDict_UpdateInDisplay(r11, r6) + r13 = py_call_with_kwargs(r9, r10, r11) + r14 = unbox(tuple[int, int, int], r13) + return r14 def h(): - r0 :: short_int + r0 :: str r1 :: str - r2 :: short_int - r3 :: str - r4 :: short_int - r5 :: native_int - r6, r7 :: object - r8, r9 :: dict - r10 :: str - r11, r12 :: object - r13 :: tuple - r14 :: dict - r15 :: int32 - r16 :: object - r17 :: tuple[int, int, int] + r2, r3 :: object + r4, r5 :: dict + r6 :: str + r7, r8 :: object + r9 :: tuple + r10 :: dict + r11 :: int32 + r12 :: object + r13 :: tuple[int, int, int] L0: - r0 = 2 - r1 = unicode_4 :: static ('b') - r2 = 4 - r3 = unicode_5 :: static ('c') - r4 = 6 - r5 = 2 - r6 = box(short_int, r2) - r7 = box(short_int, r4) - r8 = CPyDict_Build(r5, r1, r6, r3, r7) - r9 = __main__.globals :: static - r10 = unicode_6 :: static ('f') - r11 = CPyDict_GetItem(r9, r10) - r12 = box(short_int, r0) - r13 = (r12) :: tuple - r14 = PyDict_New() - r15 = CPyDict_UpdateInDisplay(r14, r8) - r16 = py_call_with_kwargs(r11, r13, r14) - r17 = unbox(tuple[int, int, int], r16) - return r17 + r0 = unicode_4 :: static ('b') + r1 = unicode_5 :: static ('c') + r2 = box(short_int, 4) + r3 = box(short_int, 6) + r4 = CPyDict_Build(2, r0, r2, r1, r3) + r5 = __main__.globals :: static + r6 = unicode_6 :: static ('f') + r7 = CPyDict_GetItem(r5, r6) + r8 = box(short_int, 2) + r9 = (r8) :: tuple + r10 = PyDict_New() + r11 = CPyDict_UpdateInDisplay(r10, r4) + r12 = py_call_with_kwargs(r7, r9, r10) + r13 = unbox(tuple[int, int, int], r12) + return r13 [case testFunctionCallWithDefaultArgs] def f(x: int, y: int = 3, z: str = "test") -> None: @@ -1916,41 +1735,34 @@ def g() -> None: def f(x, y, z): x, y :: int z :: str - r0 :: short_int - r1 :: str - r2 :: None + r0 :: str + r1 :: None L0: if is_error(y) goto L1 else goto L2 L1: - r0 = 6 - y = r0 + y = 6 L2: if is_error(z) goto L3 else goto L4 L3: - r1 = unicode_1 :: static ('test') - z = r1 + r0 = unicode_1 :: static ('test') + z = r0 L4: - r2 = None - return r2 + r1 = None + return r1 def g(): - r0 :: short_int - r1 :: int - r2 :: str - r3 :: None - r4, r5 :: short_int - r6 :: str - r7, r8 :: None + r0 :: int + r1 :: str + r2 :: None + r3 :: str + r4, r5 :: None L0: - r0 = 4 - r1 = :: int - r2 = :: str - r3 = f(r0, r1, r2) - r4 = 6 - r5 = 12 - r6 = :: str - r7 = f(r5, r4, r6) - r8 = None - return r8 + r0 = :: int + r1 = :: str + r2 = f(4, r0, r1) + r3 = :: str + r4 = f(12, 6, r3) + r5 = None + return r5 [case testMethodCallWithDefaultArgs] class A: @@ -1966,44 +1778,37 @@ def A.f(self, x, y, z): self :: __main__.A x, y :: int z :: str - r0 :: short_int - r1 :: str - r2 :: None + r0 :: str + r1 :: None L0: if is_error(y) goto L1 else goto L2 L1: - r0 = 6 - y = r0 + y = 6 L2: if is_error(z) goto L3 else goto L4 L3: - r1 = unicode_4 :: static ('test') - z = r1 + r0 = unicode_4 :: static ('test') + z = r0 L4: - r2 = None - return r2 + r1 = None + return r1 def g(): r0, a :: __main__.A - r1 :: short_int - r2 :: int - r3 :: str - r4 :: None - r5, r6 :: short_int - r7 :: str - r8, r9 :: None + r1 :: int + r2 :: str + r3 :: None + r4 :: str + r5, r6 :: None L0: r0 = A() a = r0 - r1 = 4 - r2 = :: int - r3 = :: str - r4 = a.f(r1, r2, r3) - r5 = 6 - r6 = 12 - r7 = :: str - r8 = a.f(r6, r5, r7) - r9 = None - return r9 + r1 = :: int + r2 = :: str + r3 = a.f(4, r1, r2) + r4 = :: str + r5 = a.f(12, 6, r4) + r6 = None + return r6 [case testListComprehension] from typing import List @@ -2013,59 +1818,49 @@ def f() -> List[int]: [out] def f(): r0 :: list - r1, r2, r3 :: short_int - r4, r5, r6 :: object - r7 :: list - r8, r9, r10 :: short_int + r1, r2, r3 :: object + r4 :: list + r5, r6 :: short_int + r7 :: bool + r8 :: object + x, r9 :: int + r10 :: bool r11 :: bool - r12 :: object - x, r13 :: int - r14 :: short_int - r15 :: bool - r16 :: short_int - r17 :: bool - r18 :: int - r19 :: object - r20 :: int32 - r21, r22 :: short_int + r12 :: int + r13 :: object + r14 :: int32 + r15 :: short_int L0: r0 = [] - r1 = 2 - r2 = 4 - r3 = 6 - r4 = box(short_int, r1) - r5 = box(short_int, r2) - r6 = box(short_int, r3) - r7 = [r4, r5, r6] - r8 = 0 - r9 = r8 + r1 = box(short_int, 2) + r2 = box(short_int, 4) + r3 = box(short_int, 6) + r4 = [r1, r2, r3] + r5 = 0 L1: - r10 = len r7 :: list - r11 = r9 < r10 :: signed - if r11 goto L2 else goto L8 :: bool + r6 = len r4 :: list + r7 = r5 < r6 :: signed + if r7 goto L2 else goto L8 :: bool L2: - r12 = r7[r9] :: unsafe list - r13 = unbox(int, r12) - x = r13 - r14 = 4 - r15 = CPyTagged_IsNe(x, r14) - if r15 goto L4 else goto L3 :: bool + r8 = r4[r5] :: unsafe list + r9 = unbox(int, r8) + x = r9 + r10 = CPyTagged_IsNe(x, 4) + if r10 goto L4 else goto L3 :: bool L3: goto L7 L4: - r16 = 6 - r17 = CPyTagged_IsNe(x, r16) - if r17 goto L6 else goto L5 :: bool + r11 = CPyTagged_IsNe(x, 6) + if r11 goto L6 else goto L5 :: bool L5: goto L7 L6: - r18 = CPyTagged_Multiply(x, x) - r19 = box(int, r18) - r20 = PyList_Append(r0, r19) + r12 = CPyTagged_Multiply(x, x) + r13 = box(int, r12) + r14 = PyList_Append(r0, r13) L7: - r21 = 2 - r22 = r9 + r21 - r9 = r22 + r15 = r5 + 2 + r5 = r15 goto L1 L8: return r0 @@ -2077,60 +1872,50 @@ def f() -> Dict[int, int]: [out] def f(): r0 :: dict - r1, r2, r3 :: short_int - r4, r5, r6 :: object - r7 :: list - r8, r9, r10 :: short_int + r1, r2, r3 :: object + r4 :: list + r5, r6 :: short_int + r7 :: bool + r8 :: object + x, r9 :: int + r10 :: bool r11 :: bool - r12 :: object - x, r13 :: int - r14 :: short_int - r15 :: bool + r12 :: int + r13, r14 :: object + r15 :: int32 r16 :: short_int - r17 :: bool - r18 :: int - r19, r20 :: object - r21 :: int32 - r22, r23 :: short_int L0: r0 = PyDict_New() - r1 = 2 - r2 = 4 - r3 = 6 - r4 = box(short_int, r1) - r5 = box(short_int, r2) - r6 = box(short_int, r3) - r7 = [r4, r5, r6] - r8 = 0 - r9 = r8 + r1 = box(short_int, 2) + r2 = box(short_int, 4) + r3 = box(short_int, 6) + r4 = [r1, r2, r3] + r5 = 0 L1: - r10 = len r7 :: list - r11 = r9 < r10 :: signed - if r11 goto L2 else goto L8 :: bool + r6 = len r4 :: list + r7 = r5 < r6 :: signed + if r7 goto L2 else goto L8 :: bool L2: - r12 = r7[r9] :: unsafe list - r13 = unbox(int, r12) - x = r13 - r14 = 4 - r15 = CPyTagged_IsNe(x, r14) - if r15 goto L4 else goto L3 :: bool + r8 = r4[r5] :: unsafe list + r9 = unbox(int, r8) + x = r9 + r10 = CPyTagged_IsNe(x, 4) + if r10 goto L4 else goto L3 :: bool L3: goto L7 L4: - r16 = 6 - r17 = CPyTagged_IsNe(x, r16) - if r17 goto L6 else goto L5 :: bool + r11 = CPyTagged_IsNe(x, 6) + if r11 goto L6 else goto L5 :: bool L5: goto L7 L6: - r18 = CPyTagged_Multiply(x, x) - r19 = box(int, x) - r20 = box(int, r18) - r21 = CPyDict_SetItem(r0, r19, r20) + r12 = CPyTagged_Multiply(x, x) + r13 = box(int, x) + r14 = box(int, r12) + r15 = CPyDict_SetItem(r0, r13, r14) L7: - r22 = 2 - r23 = r9 + r22 - r9 = r23 + r16 = r5 + 2 + r5 = r16 goto L1 L8: return r0 @@ -2144,72 +1929,68 @@ def f(l: List[Tuple[int, int, int]]) -> List[int]: [out] def f(l): l :: list - r0, r1, r2 :: short_int - r3 :: bool - r4 :: object + r0, r1 :: short_int + r2 :: bool + r3 :: object x, y, z :: int - r5 :: tuple[int, int, int] - r6, r7, r8 :: int - r9, r10 :: short_int - r11 :: list - r12, r13, r14 :: short_int - r15 :: bool - r16 :: object + r4 :: tuple[int, int, int] + r5, r6, r7 :: int + r8 :: short_int + r9 :: list + r10, r11 :: short_int + r12 :: bool + r13 :: object x0, y0, z0 :: int - r17 :: tuple[int, int, int] - r18, r19, r20, r21, r22 :: int - r23 :: object - r24 :: int32 - r25, r26 :: short_int + r14 :: tuple[int, int, int] + r15, r16, r17, r18, r19 :: int + r20 :: object + r21 :: int32 + r22 :: short_int L0: r0 = 0 - r1 = r0 L1: - r2 = len l :: list - r3 = r1 < r2 :: signed - if r3 goto L2 else goto L4 :: bool + r1 = len l :: list + r2 = r0 < r1 :: signed + if r2 goto L2 else goto L4 :: bool L2: - r4 = l[r1] :: unsafe list - r5 = unbox(tuple[int, int, int], r4) - r6 = r5[0] - x = r6 - r7 = r5[1] - y = r7 - r8 = r5[2] - z = r8 + r3 = l[r0] :: unsafe list + r4 = unbox(tuple[int, int, int], r3) + r5 = r4[0] + x = r5 + r6 = r4[1] + y = r6 + r7 = r4[2] + z = r7 L3: - r9 = 2 - r10 = r1 + r9 - r1 = r10 + r8 = r0 + 2 + r0 = r8 goto L1 L4: - r11 = [] - r12 = 0 - r13 = r12 + r9 = [] + r10 = 0 L5: - r14 = len l :: list - r15 = r13 < r14 :: signed - if r15 goto L6 else goto L8 :: bool + r11 = len l :: list + r12 = r10 < r11 :: signed + if r12 goto L6 else goto L8 :: bool L6: - r16 = l[r13] :: unsafe list - r17 = unbox(tuple[int, int, int], r16) - r18 = r17[0] - x0 = r18 - r19 = r17[1] - y0 = r19 - r20 = r17[2] - z0 = r20 - r21 = CPyTagged_Add(x0, y0) - r22 = CPyTagged_Add(r21, z0) - r23 = box(int, r22) - r24 = PyList_Append(r11, r23) + r13 = l[r10] :: unsafe list + r14 = unbox(tuple[int, int, int], r13) + r15 = r14[0] + x0 = r15 + r16 = r14[1] + y0 = r16 + r17 = r14[2] + z0 = r17 + r18 = CPyTagged_Add(x0, y0) + r19 = CPyTagged_Add(r18, z0) + r20 = box(int, r19) + r21 = PyList_Append(r9, r20) L7: - r25 = 2 - r26 = r13 + r25 - r13 = r26 + r22 = r10 + 2 + r10 = r22 goto L5 L8: - return r11 + return r9 [case testProperty] class PropertyHolder: @@ -2256,13 +2037,11 @@ L0: return r3 def PropertyHolder.twice_value(self): self :: __main__.PropertyHolder - r0 :: short_int - r1, r2 :: int + r0, r1 :: int L0: - r0 = 4 - r1 = self.value - r2 = CPyTagged_Multiply(r0, r1) - return r2 + r0 = self.value + r1 = CPyTagged_Multiply(4, r0) + return r1 [case testPropertyDerivedGen] from typing import Callable @@ -2328,15 +2107,13 @@ L0: def BaseProperty.next(self): self :: __main__.BaseProperty r0 :: int - r1 :: short_int - r2 :: int - r3 :: __main__.BaseProperty + r1 :: int + r2 :: __main__.BaseProperty L0: r0 = self._incrementer - r1 = 2 - r2 = CPyTagged_Add(r0, r1) - r3 = BaseProperty(r2) - return r3 + r1 = CPyTagged_Add(r0, 2) + r2 = BaseProperty(r1) + return r2 def BaseProperty.__init__(self, value): self :: __main__.BaseProperty value :: int @@ -2483,12 +2260,10 @@ L0: return self def SubclassedTrait.boxed(self): self :: __main__.SubclassedTrait - r0 :: short_int - r1 :: object + r0 :: object L0: - r0 = 6 - r1 = box(short_int, r0) - return r1 + r0 = box(short_int, 6) + return r0 def DerivingObject.this(self): self :: __main__.DerivingObject L0: @@ -2500,10 +2275,8 @@ L0: return r0 def DerivingObject.boxed(self): self :: __main__.DerivingObject - r0 :: short_int L0: - r0 = 10 - return r0 + return 10 def DerivingObject.boxed__SubclassedTrait_glue(__mypyc_self__): __mypyc_self__ :: __main__.DerivingObject r0 :: int @@ -2584,41 +2357,39 @@ def __top_level__(): r39 :: dict r40 :: str r41 :: int32 - r42 :: short_int - r43 :: str - r44 :: dict - r45 :: str - r46, r47, r48 :: object - r49 :: tuple - r50 :: dict - r51 :: str - r52 :: int32 - r53 :: dict - r54 :: str - r55, r56, r57 :: object - r58 :: dict - r59 :: str - r60 :: int32 - r61 :: str - r62 :: dict - r63 :: str - r64 :: object - r65 :: dict - r66 :: str - r67, r68 :: object - r69 :: dict - r70 :: str - r71 :: int32 - r72, r73, r74 :: short_int - r75, r76, r77 :: object - r78 :: list + r42 :: str + r43 :: dict + r44 :: str + r45, r46, r47 :: object + r48 :: tuple + r49 :: dict + r50 :: str + r51 :: int32 + r52 :: dict + r53 :: str + r54, r55, r56 :: object + r57 :: dict + r58 :: str + r59 :: int32 + r60 :: str + r61 :: dict + r62 :: str + r63 :: object + r64 :: dict + r65 :: str + r66, r67 :: object + r68 :: dict + r69 :: str + r70 :: int32 + r71, r72, r73 :: object + r74 :: list + r75 :: dict + r76 :: str + r77, r78 :: object r79 :: dict r80 :: str - r81, r82 :: object - r83 :: dict - r84 :: str - r85 :: int32 - r86 :: None + r81 :: int32 + r82 :: None L0: r0 = builtins :: module r1 = builtins.None :: object @@ -2670,52 +2441,48 @@ L4: r39 = __main__.globals :: static r40 = unicode_5 :: static ('Lol') r41 = CPyDict_SetItem(r39, r40, r38) - r42 = 2 - r43 = unicode_8 :: static - r44 = __main__.globals :: static - r45 = unicode_5 :: static ('Lol') - r46 = CPyDict_GetItem(r44, r45) - r47 = box(short_int, r42) - r48 = py_call(r46, r47, r43) - r49 = cast(tuple, r48) - r50 = __main__.globals :: static - r51 = unicode_9 :: static ('x') - r52 = CPyDict_SetItem(r50, r51, r49) - r53 = __main__.globals :: static - r54 = unicode_2 :: static ('List') - r55 = CPyDict_GetItem(r53, r54) - r56 = int - r57 = r55[r56] :: object - r58 = __main__.globals :: static - r59 = unicode_10 :: static ('Foo') - r60 = CPyDict_SetItem(r58, r59, r57) - r61 = unicode_11 :: static ('Bar') - r62 = __main__.globals :: static - r63 = unicode_10 :: static ('Foo') - r64 = CPyDict_GetItem(r62, r63) - r65 = __main__.globals :: static - r66 = unicode_3 :: static ('NewType') - r67 = CPyDict_GetItem(r65, r66) - r68 = py_call(r67, r61, r64) - r69 = __main__.globals :: static - r70 = unicode_11 :: static ('Bar') - r71 = CPyDict_SetItem(r69, r70, r68) - r72 = 2 - r73 = 4 - r74 = 6 - r75 = box(short_int, r72) - r76 = box(short_int, r73) - r77 = box(short_int, r74) - r78 = [r75, r76, r77] + r42 = unicode_8 :: static + r43 = __main__.globals :: static + r44 = unicode_5 :: static ('Lol') + r45 = CPyDict_GetItem(r43, r44) + r46 = box(short_int, 2) + r47 = py_call(r45, r46, r42) + r48 = cast(tuple, r47) + r49 = __main__.globals :: static + r50 = unicode_9 :: static ('x') + r51 = CPyDict_SetItem(r49, r50, r48) + r52 = __main__.globals :: static + r53 = unicode_2 :: static ('List') + r54 = CPyDict_GetItem(r52, r53) + r55 = int + r56 = r54[r55] :: object + r57 = __main__.globals :: static + r58 = unicode_10 :: static ('Foo') + r59 = CPyDict_SetItem(r57, r58, r56) + r60 = unicode_11 :: static ('Bar') + r61 = __main__.globals :: static + r62 = unicode_10 :: static ('Foo') + r63 = CPyDict_GetItem(r61, r62) + r64 = __main__.globals :: static + r65 = unicode_3 :: static ('NewType') + r66 = CPyDict_GetItem(r64, r65) + r67 = py_call(r66, r60, r63) + r68 = __main__.globals :: static + r69 = unicode_11 :: static ('Bar') + r70 = CPyDict_SetItem(r68, r69, r67) + r71 = box(short_int, 2) + r72 = box(short_int, 4) + r73 = box(short_int, 6) + r74 = [r71, r72, r73] + r75 = __main__.globals :: static + r76 = unicode_11 :: static ('Bar') + r77 = CPyDict_GetItem(r75, r76) + r78 = py_call(r77, r74) r79 = __main__.globals :: static - r80 = unicode_11 :: static ('Bar') - r81 = CPyDict_GetItem(r79, r80) - r82 = py_call(r81, r78) - r83 = __main__.globals :: static - r84 = unicode_12 :: static ('y') - r85 = CPyDict_SetItem(r83, r84, r82) - r86 = None - return r86 + r80 = unicode_12 :: static ('y') + r81 = CPyDict_SetItem(r79, r80, r78) + r82 = None + return r82 [case testChainedConditional] def g(x: int) -> int: @@ -2730,41 +2497,37 @@ L0: def f(x, y, z): x, y, z, r0, r1 :: int r2, r3 :: bool - r4, r5, r6 :: native_int - r7 :: bool - r8, r9, r10 :: native_int - r11, r12, r13, r14 :: bool - r15 :: int - r16 :: bool + r4 :: native_int + r5 :: bool + r6 :: native_int + r7, r8, r9, r10 :: bool + r11 :: int + r12 :: bool L0: r0 = g(x) r1 = g(y) - r4 = 1 - r5 = r0 & r4 - r6 = 0 - r7 = r5 == r6 - r8 = 1 - r9 = r1 & r8 - r10 = 0 - r11 = r9 == r10 - r12 = r7 & r11 - if r12 goto L1 else goto L2 :: bool + r4 = r0 & 1 + r5 = r4 == 0 + r6 = r1 & 1 + r7 = r6 == 0 + r8 = r5 & r7 + if r8 goto L1 else goto L2 :: bool L1: - r13 = r0 < r1 :: signed - r3 = r13 + r9 = r0 < r1 :: signed + r3 = r9 goto L3 L2: - r14 = CPyTagged_IsLt_(r0, r1) - r3 = r14 + r10 = CPyTagged_IsLt_(r0, r1) + r3 = r10 L3: if r3 goto L5 else goto L4 :: bool L4: r2 = r3 goto L6 L5: - r15 = g(z) - r16 = CPyTagged_IsGt(r1, r15) - r2 = r16 + r11 = g(z) + r12 = CPyTagged_IsGt(r1, r11) + r2 = r12 L6: return r2 @@ -3208,8 +2971,7 @@ def call_any(l): r0, r1 :: bool r2, r3 :: object r4, i :: int - r5 :: short_int - r6, r7, r8 :: bool + r5, r6, r7 :: bool L0: r1 = False r0 = r1 @@ -3220,18 +2982,17 @@ L1: L2: r4 = unbox(int, r3) i = r4 - r5 = 0 - r6 = CPyTagged_IsEq(i, r5) - if r6 goto L3 else goto L4 :: bool + r5 = CPyTagged_IsEq(i, 0) + if r5 goto L3 else goto L4 :: bool L3: - r7 = True - r0 = r7 + r6 = True + r0 = r6 goto L8 L4: L5: goto L1 L6: - r8 = CPy_NoErrOccured() + r7 = CPy_NoErrOccured() L7: L8: return r0 @@ -3240,8 +3001,7 @@ def call_all(l): r0, r1 :: bool r2, r3 :: object r4, i :: int - r5 :: short_int - r6, r7, r8, r9 :: bool + r5, r6, r7, r8 :: bool L0: r1 = True r0 = r1 @@ -3252,19 +3012,18 @@ L1: L2: r4 = unbox(int, r3) i = r4 - r5 = 0 - r6 = CPyTagged_IsEq(i, r5) - r7 = !r6 - if r7 goto L3 else goto L4 :: bool + r5 = CPyTagged_IsEq(i, 0) + r6 = !r5 + if r6 goto L3 else goto L4 :: bool L3: - r8 = False - r0 = r8 + r7 = False + r0 = r7 goto L8 L4: L5: goto L1 L6: - r9 = CPy_NoErrOccured() + r8 = CPy_NoErrOccured() L7: L8: return r0 @@ -3304,15 +3063,12 @@ def f(a: bool) -> int: [out] def f(a): a :: bool - r0, r1 :: short_int L0: if a goto L1 else goto L2 :: bool L1: - r0 = 2 - return r0 + return 2 L2: - r1 = 4 - return r1 + return 4 L3: unreachable @@ -3382,28 +3138,21 @@ def f(a: bool) -> int: [out] def C.__mypyc_defaults_setup(__mypyc_self__): __mypyc_self__ :: __main__.C - r0 :: short_int - r1 :: bool - r2 :: short_int - r3, r4 :: bool + r0 :: bool + r1, r2 :: bool L0: - r0 = 2 - __mypyc_self__.x = r0; r1 = is_error - r2 = 4 - __mypyc_self__.y = r2; r3 = is_error - r4 = True - return r4 + __mypyc_self__.x = 2; r0 = is_error + __mypyc_self__.y = 4; r1 = is_error + r2 = True + return r2 def f(a): a :: bool - r0, r1 :: short_int L0: if a goto L1 else goto L2 :: bool L1: - r0 = 2 - return r0 + return 2 L2: - r1 = 4 - return r1 + return 4 L3: unreachable @@ -3418,9 +3167,8 @@ def f() -> int: def f(): r0 :: list r1 :: bool - r2 :: short_int - r3 :: object - r4 :: int + r2 :: object + r3 :: int L0: r0 = __main__.x :: static if is_error(r0) goto L1 else goto L2 @@ -3428,10 +3176,9 @@ L1: raise NameError('value for final name "x" was not set') unreachable L2: - r2 = 0 - r3 = CPyList_GetItemShort(r0, r2) - r4 = unbox(int, r3) - return r4 + r2 = CPyList_GetItemShort(r0, 0) + r3 = unbox(int, r2) + return r3 [case testFinalStaticTuple] from typing import Final @@ -3466,8 +3213,7 @@ def f() -> int: def f(): r0 :: int r1 :: bool - r2 :: short_int - r3 :: int + r2 :: int L0: r0 = __main__.x :: static if is_error(r0) goto L1 else goto L2 @@ -3475,9 +3221,8 @@ L1: raise NameError('value for final name "x" was not set') unreachable L2: - r2 = 2 - r3 = CPyTagged_Subtract(r0, r2) - return r3 + r2 = CPyTagged_Subtract(r0, 2) + return r2 [case testFinalRestrictedTypeVar] from typing import TypeVar @@ -3492,12 +3237,10 @@ def foo(z: Targ) -> None: [out] def foo(z): z :: object - r0 :: short_int - r1 :: None + r0 :: None L0: - r0 = 20 - r1 = None - return r1 + r0 = None + return r0 [case testDirectlyCall__bool__] class A: @@ -3529,16 +3272,13 @@ L0: def lol(x): x :: __main__.A r0 :: bool - r1, r2 :: short_int L0: r0 = x.__bool__() if r0 goto L1 else goto L2 :: bool L1: - r1 = 2 - return r1 + return 2 L2: - r2 = 0 - return r2 + return 0 L3: unreachable diff --git a/mypyc/test-data/irbuild-classes.test b/mypyc/test-data/irbuild-classes.test index 42d0e361fb9c..50a079955c7a 100644 --- a/mypyc/test-data/irbuild-classes.test +++ b/mypyc/test-data/irbuild-classes.test @@ -21,14 +21,12 @@ def f(a: A) -> None: [out] def f(a): a :: __main__.A - r0 :: short_int - r1 :: bool - r2 :: None + r0 :: bool + r1 :: None L0: - r0 = 2 - a.x = r0; r1 = is_error - r2 = None - return r2 + a.x = 2; r0 = is_error + r1 = None + return r1 [case testUserClassInList] class C: @@ -43,30 +41,24 @@ def f() -> int: [out] def f(): r0, c :: __main__.C - r1 :: short_int - r2 :: bool - r3, a :: list - r4 :: short_int - r5 :: object - r6, d :: __main__.C - r7 :: int - r8 :: short_int - r9 :: int + r1 :: bool + r2, a :: list + r3 :: object + r4, d :: __main__.C + r5 :: int + r6 :: int L0: r0 = C() c = r0 - r1 = 10 - c.x = r1; r2 = is_error - r3 = [c] - a = r3 - r4 = 0 - r5 = CPyList_GetItemShort(a, r4) - r6 = cast(__main__.C, r5) - d = r6 - r7 = d.x - r8 = 2 - r9 = CPyTagged_Add(r7, r8) - return r9 + c.x = 10; r1 = is_error + r2 = [c] + a = r2 + r3 = CPyList_GetItemShort(a, 0) + r4 = cast(__main__.C, r3) + d = r4 + r5 = d.x + r6 = CPyTagged_Add(r5, 2) + return r6 [case testMethodCall] class A: @@ -80,24 +72,20 @@ def A.f(self, x, y): self :: __main__.A x :: int y :: str - r0 :: short_int - r1 :: int + r0 :: int L0: - r0 = 20 - r1 = CPyTagged_Add(x, r0) - return r1 + r0 = CPyTagged_Add(x, 20) + return r0 def g(a): a :: __main__.A - r0 :: short_int - r1 :: str - r2 :: int - r3 :: None + r0 :: str + r1 :: int + r2 :: None L0: - r0 = 2 - r1 = unicode_4 :: static ('hi') - r2 = a.f(r0, r1) - r3 = None - return r3 + r0 = unicode_4 :: static ('hi') + r1 = a.f(2, r0) + r2 = None + return r2 [case testForwardUse] def g(a: A) -> int: @@ -129,11 +117,9 @@ def Node.length(self): r1 :: None r2 :: object r3, r4 :: bool - r5 :: short_int - r6 :: union[__main__.Node, None] - r7 :: __main__.Node - r8, r9 :: int - r10 :: short_int + r5 :: union[__main__.Node, None] + r6 :: __main__.Node + r7, r8 :: int L0: r0 = self.next r1 = None @@ -142,15 +128,13 @@ L0: r4 = !r3 if r4 goto L1 else goto L2 :: bool L1: - r5 = 2 - r6 = self.next - r7 = cast(__main__.Node, r6) - r8 = r7.length() - r9 = CPyTagged_Add(r5, r8) - return r9 + r5 = self.next + r6 = cast(__main__.Node, r5) + r7 = r6.length() + r8 = CPyTagged_Add(2, r7) + return r8 L2: - r10 = 2 - return r10 + return 2 [case testSubclass] class A: @@ -163,28 +147,22 @@ class B(A): [out] def A.__init__(self): self :: __main__.A - r0 :: short_int - r1 :: bool - r2 :: None + r0 :: bool + r1 :: None L0: - r0 = 20 - self.x = r0; r1 = is_error - r2 = None - return r2 + self.x = 20; r0 = is_error + r1 = None + return r1 def B.__init__(self): self :: __main__.B - r0 :: short_int + r0 :: bool r1 :: bool - r2 :: short_int - r3 :: bool - r4 :: None + r2 :: None L0: - r0 = 40 - self.x = r0; r1 = is_error - r2 = 60 - self.y = r2; r3 = is_error - r4 = None - return r4 + self.x = 40; r0 = is_error + self.y = 60; r1 = is_error + r2 = None + return r2 [case testAttrLvalue] class O(object): @@ -197,25 +175,21 @@ def increment(o: O) -> O: [out] def O.__init__(self): self :: __main__.O - r0 :: short_int - r1 :: bool - r2 :: None + r0 :: bool + r1 :: None L0: - r0 = 2 - self.x = r0; r1 = is_error - r2 = None - return r2 + self.x = 2; r0 = is_error + r1 = None + return r1 def increment(o): o :: __main__.O r0 :: int - r1 :: short_int - r2 :: int - r3 :: bool + r1 :: int + r2 :: bool L0: r0 = o.x - r1 = 2 - r2 = CPyTagged_Add(r0, r1) - o.x = r2; r3 = is_error + r1 = CPyTagged_Add(r0, 2) + o.x = r1; r2 = is_error return o [case testSubclassSpecialize2] @@ -701,35 +675,27 @@ def lol() -> int: [out] def C.foo(x): x :: int - r0 :: short_int - r1 :: int + r0 :: int L0: - r0 = 20 - r1 = CPyTagged_Add(r0, x) - return r1 + r0 = CPyTagged_Add(20, x) + return r0 def C.bar(cls, x): cls :: object x :: int - r0 :: short_int - r1 :: int + r0 :: int L0: - r0 = 20 - r1 = CPyTagged_Add(r0, x) - return r1 + r0 = CPyTagged_Add(20, x) + return r0 def lol(): - r0 :: short_int - r1 :: int - r2 :: object - r3 :: short_int - r4, r5 :: int + r0 :: int + r1 :: object + r2, r3 :: int L0: - r0 = 2 - r1 = C.foo(r0) - r2 = __main__.C :: type - r3 = 4 - r4 = C.bar(r2, r3) - r5 = CPyTagged_Add(r1, r4) - return r5 + r0 = C.foo(2) + r1 = __main__.C :: type + r2 = C.bar(r1, 4) + r3 = CPyTagged_Add(r0, r2) + return r3 [case testSuper1] class A: @@ -1013,50 +979,44 @@ class B(A): [out] def A.lol(self): self :: __main__.A - r0 :: short_int - r1 :: bool - r2 :: None + r0 :: bool + r1 :: None L0: - r0 = 200 - self.x = r0; r1 = is_error - r2 = None - return r2 + self.x = 200; r0 = is_error + r1 = None + return r1 def A.__mypyc_defaults_setup(__mypyc_self__): __mypyc_self__ :: __main__.A - r0 :: short_int - r1, r2 :: bool + r0, r1 :: bool L0: - r0 = 20 - __mypyc_self__.x = r0; r1 = is_error - r2 = True - return r2 + __mypyc_self__.x = 20; r0 = is_error + r1 = True + return r1 def B.__mypyc_defaults_setup(__mypyc_self__): __mypyc_self__ :: __main__.B - r0 :: short_int - r1 :: bool - r2 :: dict - r3 :: str - r4 :: object - r5 :: str - r6 :: bool - r7 :: None - r8 :: object - r9, r10, r11, r12 :: bool + r0 :: bool + r1 :: dict + r2 :: str + r3 :: object + r4 :: str + r5 :: bool + r6 :: None + r7 :: object + r8, r9, r10, r11 :: bool L0: - r0 = 20 - __mypyc_self__.x = r0; r1 = is_error - r2 = __main__.globals :: static - r3 = unicode_9 :: static ('LOL') - r4 = CPyDict_GetItem(r2, r3) - r5 = cast(str, r4) - __mypyc_self__.y = r5; r6 = is_error - r7 = None - r8 = box(None, r7) - __mypyc_self__.z = r8; r9 = is_error - r10 = True - __mypyc_self__.b = r10; r11 = is_error - r12 = True - return r12 + __mypyc_self__.x = 20; r0 = is_error + r1 = __main__.globals :: static + r2 = unicode_9 :: static ('LOL') + r3 = CPyDict_GetItem(r1, r2) + r4 = cast(str, r3) + __mypyc_self__.y = r4; r5 = is_error + r6 = None + r7 = box(None, r6) + __mypyc_self__.z = r7; r8 = is_error + r9 = True + __mypyc_self__.b = r9; r10 = is_error + r11 = True + return r11 [case testSubclassDictSpecalized] from typing import Dict diff --git a/mypyc/test-data/irbuild-dict.test b/mypyc/test-data/irbuild-dict.test index 1b62a8188a03..85f23058126d 100644 --- a/mypyc/test-data/irbuild-dict.test +++ b/mypyc/test-data/irbuild-dict.test @@ -5,15 +5,13 @@ def f(d: Dict[int, bool]) -> bool: [out] def f(d): d :: dict - r0 :: short_int - r1, r2 :: object - r3 :: bool + r0, r1 :: object + r2 :: bool L0: - r0 = 0 - r1 = box(short_int, r0) - r2 = CPyDict_GetItem(d, r1) - r3 = unbox(bool, r2) - return r3 + r0 = box(short_int, 0) + r1 = CPyDict_GetItem(d, r0) + r2 = unbox(bool, r1) + return r2 [case testDictSet] from typing import Dict @@ -23,18 +21,16 @@ def f(d: Dict[int, bool]) -> None: def f(d): d :: dict r0 :: bool - r1 :: short_int - r2, r3 :: object - r4 :: int32 - r5 :: None + r1, r2 :: object + r3 :: int32 + r4 :: None L0: r0 = False - r1 = 0 - r2 = box(short_int, r1) - r3 = box(bool, r0) - r4 = CPyDict_SetItem(d, r2, r3) - r5 = None - return r5 + r1 = box(short_int, 0) + r2 = box(bool, r0) + r3 = CPyDict_SetItem(d, r1, r2) + r4 = None + return r4 [case testNewEmptyDict] from typing import Dict @@ -56,23 +52,18 @@ def f(x: object) -> None: [out] def f(x): x :: object - r0, r1 :: short_int - r2 :: str - r3 :: native_int - r4, r5 :: object - r6, d :: dict - r7 :: None + r0 :: str + r1, r2 :: object + r3, d :: dict + r4 :: None L0: - r0 = 2 - r1 = 4 - r2 = unicode_1 :: static - r3 = 2 - r4 = box(short_int, r0) - r5 = box(short_int, r1) - r6 = CPyDict_Build(r3, r4, r5, r2, x) - d = r6 - r7 = None - return r7 + r0 = unicode_1 :: static + r1 = box(short_int, 2) + r2 = box(short_int, 4) + r3 = CPyDict_Build(2, r1, r2, r0, x) + d = r3 + r4 = None + return r4 [case testInDict] from typing import Dict @@ -84,22 +75,20 @@ def f(d: Dict[int, int]) -> bool: [out] def f(d): d :: dict - r0 :: short_int - r1 :: object - r2 :: int32 - r3, r4, r5 :: bool + r0 :: object + r1 :: int32 + r2, r3, r4 :: bool L0: - r0 = 8 - r1 = box(short_int, r0) - r2 = PyDict_Contains(d, r1) - r3 = truncate r2: int32 to builtins.bool - if r3 goto L1 else goto L2 :: bool + r0 = box(short_int, 8) + r1 = PyDict_Contains(d, r0) + r2 = truncate r1: int32 to builtins.bool + if r2 goto L1 else goto L2 :: bool L1: - r4 = True - return r4 + r3 = True + return r3 L2: - r5 = False - return r5 + r4 = False + return r4 L3: unreachable @@ -113,23 +102,21 @@ def f(d: Dict[int, int]) -> bool: [out] def f(d): d :: dict - r0 :: short_int - r1 :: object - r2 :: int32 - r3, r4, r5, r6 :: bool + r0 :: object + r1 :: int32 + r2, r3, r4, r5 :: bool L0: - r0 = 8 - r1 = box(short_int, r0) - r2 = PyDict_Contains(d, r1) - r3 = truncate r2: int32 to builtins.bool - r4 = !r3 - if r4 goto L1 else goto L2 :: bool + r0 = box(short_int, 8) + r1 = PyDict_Contains(d, r0) + r2 = truncate r1: int32 to builtins.bool + r3 = !r2 + if r3 goto L1 else goto L2 :: bool L1: - r5 = True - return r5 + r4 = True + return r4 L2: - r6 = False - return r6 + r5 = False + return r5 L3: unreachable @@ -157,44 +144,41 @@ def increment(d: Dict[str, int]) -> Dict[str, int]: [out] def increment(d): d :: dict - r0, r1 :: short_int - r2 :: int - r3 :: object - r4 :: tuple[bool, int, object] - r5 :: int - r6 :: bool - r7 :: object - k, r8 :: str - r9 :: object - r10 :: short_int - r11, r12 :: object - r13 :: int32 - r14, r15 :: bool + r0 :: short_int + r1 :: int + r2 :: object + r3 :: tuple[bool, int, object] + r4 :: int + r5 :: bool + r6 :: object + k, r7 :: str + r8 :: object + r9, r10 :: object + r11 :: int32 + r12, r13 :: bool L0: r0 = 0 - r1 = r0 - r2 = len d :: dict - r3 = CPyDict_GetKeysIter(d) + r1 = len d :: dict + r2 = CPyDict_GetKeysIter(d) L1: - r4 = CPyDict_NextKey(r3, r1) - r5 = r4[1] - r1 = r5 - r6 = r4[0] - if r6 goto L2 else goto L4 :: bool + r3 = CPyDict_NextKey(r2, r0) + r4 = r3[1] + r0 = r4 + r5 = r3[0] + if r5 goto L2 else goto L4 :: bool L2: - r7 = r4[2] - r8 = cast(str, r7) - k = r8 - r9 = CPyDict_GetItem(d, k) - r10 = 2 - r11 = box(short_int, r10) - r12 = r9 += r11 - r13 = CPyDict_SetItem(d, k, r12) + r6 = r3[2] + r7 = cast(str, r6) + k = r7 + r8 = CPyDict_GetItem(d, k) + r9 = box(short_int, 2) + r10 = r8 += r9 + r11 = CPyDict_SetItem(d, k, r10) L3: - r14 = CPyDict_CheckSize(d, r2) + r12 = CPyDict_CheckSize(d, r1) goto L1 L4: - r15 = CPy_NoErrOccured() + r13 = CPy_NoErrOccured() L5: return d @@ -206,26 +190,20 @@ def f(x: str, y: Dict[str, int]) -> Dict[str, int]: def f(x, y): x :: str y :: dict - r0 :: short_int - r1 :: str - r2 :: short_int - r3 :: native_int + r0 :: str + r1 :: object + r2 :: dict + r3 :: int32 r4 :: object - r5 :: dict - r6 :: int32 - r7 :: object - r8 :: int32 + r5 :: int32 L0: - r0 = 4 - r1 = unicode_3 :: static ('z') - r2 = 6 - r3 = 1 - r4 = box(short_int, r0) - r5 = CPyDict_Build(r3, x, r4) - r6 = CPyDict_UpdateInDisplay(r5, y) - r7 = box(short_int, r2) - r8 = CPyDict_SetItem(r5, r1, r7) - return r5 + r0 = unicode_3 :: static ('z') + r1 = box(short_int, 4) + r2 = CPyDict_Build(1, x, r1) + r3 = CPyDict_UpdateInDisplay(r2, y) + r4 = box(short_int, 6) + r5 = CPyDict_SetItem(r2, r0, r4) + return r2 [case testDictIterationMethods] from typing import Dict @@ -238,89 +216,87 @@ def print_dict_methods(d1: Dict[int, int], d2: Dict[int, int]) -> None: [out] def print_dict_methods(d1, d2): d1, d2 :: dict - r0, r1 :: short_int - r2 :: int - r3 :: object - r4 :: tuple[bool, int, object] - r5 :: int - r6 :: bool - r7 :: object - v, r8 :: int - r9 :: object - r10 :: int32 - r11 :: bool - r12 :: None - r13, r14 :: bool - r15, r16 :: short_int - r17 :: int - r18 :: object - r19 :: tuple[bool, int, object, object] - r20 :: int - r21 :: bool - r22, r23 :: object - r24, r25, k :: int - r26, r27, r28, r29, r30 :: object - r31 :: int32 - r32, r33 :: bool - r34 :: None + r0 :: short_int + r1 :: int + r2 :: object + r3 :: tuple[bool, int, object] + r4 :: int + r5 :: bool + r6 :: object + v, r7 :: int + r8 :: object + r9 :: int32 + r10 :: bool + r11 :: None + r12, r13 :: bool + r14 :: short_int + r15 :: int + r16 :: object + r17 :: tuple[bool, int, object, object] + r18 :: int + r19 :: bool + r20, r21 :: object + r22, r23, k :: int + r24, r25, r26, r27, r28 :: object + r29 :: int32 + r30, r31 :: bool + r32 :: None L0: r0 = 0 - r1 = r0 - r2 = len d1 :: dict - r3 = CPyDict_GetValuesIter(d1) + r1 = len d1 :: dict + r2 = CPyDict_GetValuesIter(d1) L1: - r4 = CPyDict_NextValue(r3, r1) - r5 = r4[1] - r1 = r5 - r6 = r4[0] - if r6 goto L2 else goto L6 :: bool + r3 = CPyDict_NextValue(r2, r0) + r4 = r3[1] + r0 = r4 + r5 = r3[0] + if r5 goto L2 else goto L6 :: bool L2: - r7 = r4[2] - r8 = unbox(int, r7) - v = r8 - r9 = box(int, v) - r10 = PyDict_Contains(d2, r9) - r11 = truncate r10: int32 to builtins.bool - if r11 goto L3 else goto L4 :: bool + r6 = r3[2] + r7 = unbox(int, r6) + v = r7 + r8 = box(int, v) + r9 = PyDict_Contains(d2, r8) + r10 = truncate r9: int32 to builtins.bool + if r10 goto L3 else goto L4 :: bool L3: - r12 = None - return r12 + r11 = None + return r11 L4: L5: - r13 = CPyDict_CheckSize(d1, r2) + r12 = CPyDict_CheckSize(d1, r1) goto L1 L6: - r14 = CPy_NoErrOccured() + r13 = CPy_NoErrOccured() L7: - r15 = 0 - r16 = r15 - r17 = len d2 :: dict - r18 = CPyDict_GetItemsIter(d2) + r14 = 0 + r15 = len d2 :: dict + r16 = CPyDict_GetItemsIter(d2) L8: - r19 = CPyDict_NextItem(r18, r16) - r20 = r19[1] - r16 = r20 - r21 = r19[0] - if r21 goto L9 else goto L11 :: bool + r17 = CPyDict_NextItem(r16, r14) + r18 = r17[1] + r14 = r18 + r19 = r17[0] + if r19 goto L9 else goto L11 :: bool L9: - r22 = r19[2] - r23 = r19[3] - r24 = unbox(int, r22) - r25 = unbox(int, r23) - k = r24 - v = r25 - r26 = box(int, k) - r27 = CPyDict_GetItem(d2, r26) - r28 = box(int, v) - r29 = r27 += r28 - r30 = box(int, k) - r31 = CPyDict_SetItem(d2, r30, r29) + r20 = r17[2] + r21 = r17[3] + r22 = unbox(int, r20) + r23 = unbox(int, r21) + k = r22 + v = r23 + r24 = box(int, k) + r25 = CPyDict_GetItem(d2, r24) + r26 = box(int, v) + r27 = r25 += r26 + r28 = box(int, k) + r29 = CPyDict_SetItem(d2, r28, r27) L10: - r32 = CPyDict_CheckSize(d2, r17) + r30 = CPyDict_CheckSize(d2, r15) goto L8 L11: - r33 = CPy_NoErrOccured() + r31 = CPy_NoErrOccured() L12: - r34 = None - return r34 + r32 = None + return r32 diff --git a/mypyc/test-data/irbuild-generics.test b/mypyc/test-data/irbuild-generics.test index eae3b058b708..069c33f303e9 100644 --- a/mypyc/test-data/irbuild-generics.test +++ b/mypyc/test-data/irbuild-generics.test @@ -15,14 +15,12 @@ L0: return x def g(x): x :: list - r0 :: short_int - r1 :: object - r2 :: list + r0 :: object + r1 :: list L0: - r0 = 0 - r1 = CPyList_GetItemShort(x, r0) - r2 = [r1] - return r2 + r0 = CPyList_GetItemShort(x, 0) + r1 = [r0] + return r1 def h(x, y): x :: int y :: list @@ -52,25 +50,21 @@ def f() -> None: [out] def f(): r0, c :: __main__.C - r1 :: short_int - r2 :: object - r3 :: bool - r4 :: short_int - r5 :: object - r6, r7 :: int - r8 :: None + r1 :: object + r2 :: bool + r3 :: object + r4, r5 :: int + r6 :: None L0: r0 = C() c = r0 - r1 = 2 - r2 = box(short_int, r1) - c.x = r2; r3 = is_error - r4 = 4 - r5 = c.x - r6 = unbox(int, r5) - r7 = CPyTagged_Add(r4, r6) - r8 = None - return r8 + r1 = box(short_int, 2) + c.x = r1; r2 = is_error + r3 = c.x + r4 = unbox(int, r3) + r5 = CPyTagged_Add(4, r4) + r6 = None + return r6 [case testGenericMethod] from typing import TypeVar, Generic @@ -116,26 +110,22 @@ def f(x): x :: __main__.C r0 :: object r1, y :: int - r2 :: short_int - r3 :: int - r4 :: object - r5 :: None - r6 :: short_int - r7 :: object - r8 :: __main__.C - r9 :: None + r2 :: int + r3 :: object + r4 :: None + r5 :: object + r6 :: __main__.C + r7 :: None L0: r0 = x.get() r1 = unbox(int, r0) y = r1 - r2 = 2 - r3 = CPyTagged_Add(y, r2) - r4 = box(int, r3) - r5 = x.set(r4) - r6 = 4 - r7 = box(short_int, r6) - r8 = C(r7) - x = r8 - r9 = None - return r9 + r2 = CPyTagged_Add(y, 2) + r3 = box(int, r2) + r4 = x.set(r3) + r5 = box(short_int, 4) + r6 = C(r5) + x = r6 + r7 = None + return r7 diff --git a/mypyc/test-data/irbuild-int.test b/mypyc/test-data/irbuild-int.test index 74d5861713f4..9c4ca8e17a0e 100644 --- a/mypyc/test-data/irbuild-int.test +++ b/mypyc/test-data/irbuild-int.test @@ -5,21 +5,20 @@ def f(x: int, y: int) -> bool: def f(x, y): x, y :: int r0 :: bool - r1, r2, r3 :: native_int - r4, r5, r6, r7 :: bool + r1 :: native_int + r2, r3, r4, r5 :: bool L0: - r1 = 1 - r2 = x & r1 - r3 = 0 - r4 = r2 == r3 - if r4 goto L1 else goto L2 :: bool + r1 = x & 1 + r2 = r1 == 0 + if r2 goto L1 else goto L2 :: bool L1: - r5 = x != y - r0 = r5 + r3 = x != y + r0 = r3 goto L3 L2: - r6 = CPyTagged_IsEq_(x, y) - r7 = !r6 - r0 = r7 + r4 = CPyTagged_IsEq_(x, y) + r5 = !r4 + r0 = r5 L3: return r0 + diff --git a/mypyc/test-data/irbuild-lists.test b/mypyc/test-data/irbuild-lists.test index 454bea233fc7..b07e5c40b118 100644 --- a/mypyc/test-data/irbuild-lists.test +++ b/mypyc/test-data/irbuild-lists.test @@ -5,14 +5,12 @@ def f(x: List[int]) -> int: [out] def f(x): x :: list - r0 :: short_int - r1 :: object - r2 :: int + r0 :: object + r1 :: int L0: - r0 = 0 - r1 = CPyList_GetItemShort(x, r0) - r2 = unbox(int, r1) - return r2 + r0 = CPyList_GetItemShort(x, 0) + r1 = unbox(int, r0) + return r1 [case testListOfListGet] from typing import List @@ -21,14 +19,12 @@ def f(x: List[List[int]]) -> List[int]: [out] def f(x): x :: list - r0 :: short_int - r1 :: object - r2 :: list + r0 :: object + r1 :: list L0: - r0 = 0 - r1 = CPyList_GetItemShort(x, r0) - r2 = cast(list, r1) - return r2 + r0 = CPyList_GetItemShort(x, 0) + r1 = cast(list, r0) + return r1 [case testListOfListGet2] from typing import List @@ -37,20 +33,16 @@ def f(x: List[List[int]]) -> int: [out] def f(x): x :: list - r0 :: short_int - r1 :: object - r2 :: list - r3 :: short_int - r4 :: object - r5 :: int + r0 :: object + r1 :: list + r2 :: object + r3 :: int L0: - r0 = 0 - r1 = CPyList_GetItemShort(x, r0) - r2 = cast(list, r1) - r3 = 2 - r4 = CPyList_GetItemShort(r2, r3) - r5 = unbox(int, r4) - return r5 + r0 = CPyList_GetItemShort(x, 0) + r1 = cast(list, r0) + r2 = CPyList_GetItemShort(r1, 2) + r3 = unbox(int, r2) + return r3 [case testListSet] from typing import List @@ -59,17 +51,14 @@ def f(x: List[int]) -> None: [out] def f(x): x :: list - r0, r1 :: short_int - r2 :: object - r3 :: bool - r4 :: None + r0 :: object + r1 :: bool + r2 :: None L0: - r0 = 2 - r1 = 0 - r2 = box(short_int, r0) - r3 = CPyList_SetItem(x, r1, r2) - r4 = None - return r4 + r0 = box(short_int, 2) + r1 = CPyList_SetItem(x, 0, r0) + r2 = None + return r2 [case testNewListEmpty] from typing import List @@ -91,19 +80,16 @@ def f() -> None: x: List[int] = [1, 2] [out] def f(): - r0, r1 :: short_int - r2, r3 :: object - r4, x :: list - r5 :: None + r0, r1 :: object + r2, x :: list + r3 :: None L0: - r0 = 2 - r1 = 4 - r2 = box(short_int, r0) - r3 = box(short_int, r1) - r4 = [r2, r3] - x = r4 - r5 = None - return r5 + r0 = box(short_int, 2) + r1 = box(short_int, 4) + r2 = [r0, r1] + x = r2 + r3 = None + return r3 [case testListMultiply] from typing import List @@ -113,24 +99,19 @@ def f(a: List[int]) -> None: [out] def f(a): a :: list - r0 :: short_int - r1, b :: list - r2, r3 :: short_int - r4 :: object - r5, r6 :: list - r7 :: None + r0, b :: list + r1 :: object + r2, r3 :: list + r4 :: None L0: - r0 = 4 - r1 = CPySequence_Multiply(a, r0) - b = r1 - r2 = 6 - r3 = 8 - r4 = box(short_int, r3) - r5 = [r4] - r6 = CPySequence_RMultiply(r2, r5) - b = r6 - r7 = None - return r7 + r0 = CPySequence_Multiply(a, 4) + b = r0 + r1 = box(short_int, 8) + r2 = [r1] + r3 = CPySequence_RMultiply(6, r2) + b = r3 + r4 = None + return r4 [case testListLen] from typing import List @@ -171,33 +152,29 @@ def increment(l: List[int]) -> List[int]: [out] def increment(l): l :: list - r0, r1, r2 :: short_int + r0, r1 :: short_int i :: int - r3 :: bool - r4 :: object - r5 :: short_int - r6, r7 :: object - r8 :: bool - r9, r10 :: short_int + r2 :: bool + r3 :: object + r4, r5 :: object + r6 :: bool + r7 :: short_int L0: - r0 = 0 - r1 = len l :: list - r2 = r0 - i = r2 + r0 = len l :: list + r1 = 0 + i = r1 L1: - r3 = r2 < r1 :: signed - if r3 goto L2 else goto L4 :: bool + r2 = r1 < r0 :: signed + if r2 goto L2 else goto L4 :: bool L2: - r4 = CPyList_GetItem(l, i) - r5 = 2 - r6 = box(short_int, r5) - r7 = r4 += r6 - r8 = CPyList_SetItem(l, i, r7) + r3 = CPyList_GetItem(l, i) + r4 = box(short_int, 2) + r5 = r3 += r4 + r6 = CPyList_SetItem(l, i, r5) L3: - r9 = 2 - r10 = r2 + r9 - r2 = r10 - i = r10 + r7 = r1 + 2 + r1 = r7 + i = r7 goto L1 L4: return l @@ -209,21 +186,17 @@ def f(x: List[int], y: List[int]) -> List[int]: [out] def f(x, y): x, y :: list - r0, r1, r2 :: short_int - r3, r4 :: object - r5 :: list - r6, r7, r8 :: object - r9 :: int32 + r0, r1 :: object + r2 :: list + r3, r4, r5 :: object + r6 :: int32 L0: - r0 = 2 - r1 = 4 - r2 = 6 - r3 = box(short_int, r0) - r4 = box(short_int, r1) - r5 = [r3, r4] - r6 = CPyList_Extend(r5, x) - r7 = CPyList_Extend(r5, y) - r8 = box(short_int, r2) - r9 = PyList_Append(r5, r8) - return r5 + r0 = box(short_int, 2) + r1 = box(short_int, 4) + r2 = [r0, r1] + r3 = CPyList_Extend(r2, x) + r4 = CPyList_Extend(r2, y) + r5 = box(short_int, 6) + r6 = PyList_Append(r2, r5) + return r2 diff --git a/mypyc/test-data/irbuild-nested.test b/mypyc/test-data/irbuild-nested.test index ae3ebe9bcf42..6419dc325da7 100644 --- a/mypyc/test-data/irbuild-nested.test +++ b/mypyc/test-data/irbuild-nested.test @@ -336,41 +336,35 @@ def inner_b_obj.__call__(__mypyc_self__): __mypyc_self__ :: __main__.inner_b_obj r0 :: __main__.b_env r1, inner :: object - r2 :: short_int - r3 :: bool - r4 :: short_int - foo, r5 :: int + r2 :: bool + foo, r3 :: int L0: r0 = __mypyc_self__.__mypyc_env__ r1 = r0.inner inner = r1 - r2 = 8 - r0.num = r2; r3 = is_error - r4 = 12 - foo = r4 - r5 = r0.num - return r5 + r0.num = 8; r2 = is_error + foo = 12 + r3 = r0.num + return r3 def b(): r0 :: __main__.b_env - r1 :: short_int - r2 :: bool - r3 :: __main__.inner_b_obj - r4, r5 :: bool - r6, r7 :: object - r8, r9, r10 :: int + r1 :: bool + r2 :: __main__.inner_b_obj + r3, r4 :: bool + r5, r6 :: object + r7, r8, r9 :: int L0: r0 = b_env() - r1 = 6 - r0.num = r1; r2 = is_error - r3 = inner_b_obj() - r3.__mypyc_env__ = r0; r4 = is_error - r0.inner = r3; r5 = is_error - r6 = r0.inner - r7 = py_call(r6) - r8 = unbox(int, r7) - r9 = r0.num - r10 = CPyTagged_Add(r8, r9) - return r10 + r0.num = 6; r1 = is_error + r2 = inner_b_obj() + r2.__mypyc_env__ = r0; r3 = is_error + r0.inner = r2; r4 = is_error + r5 = r0.inner + r6 = py_call(r5) + r7 = unbox(int, r6) + r8 = r0.num + r9 = CPyTagged_Add(r7, r8) + return r9 def inner_c_obj.__get__(__mypyc_self__, instance, owner): __mypyc_self__, instance, owner, r0 :: object r1 :: bool @@ -503,13 +497,12 @@ def b_a_obj.__call__(__mypyc_self__): r2 :: __main__.b_a_env r3 :: bool r4 :: int - r5 :: short_int - r6 :: int - r7 :: bool - r8 :: __main__.c_a_b_obj - r9, r10 :: bool - r11, r12 :: object - r13 :: int + r5 :: int + r6 :: bool + r7 :: __main__.c_a_b_obj + r8, r9 :: bool + r10, r11 :: object + r12 :: int L0: r0 = __mypyc_self__.__mypyc_env__ r1 = r0.b @@ -517,35 +510,32 @@ L0: r2 = b_a_env() r2.__mypyc_env__ = r0; r3 = is_error r4 = r0.x - r5 = 2 - r6 = CPyTagged_Add(r4, r5) - r0.x = r6; r7 = is_error - r8 = c_a_b_obj() - r8.__mypyc_env__ = r2; r9 = is_error - r2.c = r8; r10 = is_error - r11 = r2.c - r12 = py_call(r11) - r13 = unbox(int, r12) - return r13 + r5 = CPyTagged_Add(r4, 2) + r0.x = r5; r6 = is_error + r7 = c_a_b_obj() + r7.__mypyc_env__ = r2; r8 = is_error + r2.c = r7; r9 = is_error + r10 = r2.c + r11 = py_call(r10) + r12 = unbox(int, r11) + return r12 def a(): r0 :: __main__.a_env - r1 :: short_int - r2 :: bool - r3 :: __main__.b_a_obj - r4, r5 :: bool - r6, r7 :: object - r8 :: int + r1 :: bool + r2 :: __main__.b_a_obj + r3, r4 :: bool + r5, r6 :: object + r7 :: int L0: r0 = a_env() - r1 = 2 - r0.x = r1; r2 = is_error - r3 = b_a_obj() - r3.__mypyc_env__ = r0; r4 = is_error - r0.b = r3; r5 = is_error - r6 = r0.b - r7 = py_call(r6) - r8 = unbox(int, r7) - return r8 + r0.x = 2; r1 = is_error + r2 = b_a_obj() + r2.__mypyc_env__ = r0; r3 = is_error + r0.b = r2; r4 = is_error + r5 = r0.b + r6 = py_call(r5) + r7 = unbox(int, r6) + return r7 [case testNestedFunctionInsideStatements] def f(flag: bool) -> str: @@ -668,16 +658,14 @@ def foo_f_obj.__call__(__mypyc_self__): r0 :: __main__.f_env r1, foo :: object r2 :: int - r3 :: short_int - r4 :: int + r3 :: int L0: r0 = __mypyc_self__.__mypyc_env__ r1 = r0.foo foo = r1 r2 = r0.a - r3 = 2 - r4 = CPyTagged_Add(r2, r3) - return r4 + r3 = CPyTagged_Add(r2, 2) + return r3 def bar_f_obj.__get__(__mypyc_self__, instance, owner): __mypyc_self__, instance, owner, r0 :: object r1 :: bool @@ -722,30 +710,25 @@ def baz_f_obj.__call__(__mypyc_self__, n): n :: int r0 :: __main__.f_env r1, baz :: object - r2 :: short_int - r3 :: bool - r4, r5 :: short_int - r6 :: int - r7, r8 :: object - r9, r10 :: int + r2 :: bool + r3 :: int + r4, r5 :: object + r6, r7 :: int L0: r0 = __mypyc_self__.__mypyc_env__ r1 = r0.baz baz = r1 - r2 = 0 - r3 = CPyTagged_IsEq(n, r2) - if r3 goto L1 else goto L2 :: bool + r2 = CPyTagged_IsEq(n, 0) + if r2 goto L1 else goto L2 :: bool L1: - r4 = 0 - return r4 + return 0 L2: - r5 = 2 - r6 = CPyTagged_Subtract(n, r5) - r7 = box(int, r6) - r8 = py_call(baz, r7) - r9 = unbox(int, r8) - r10 = CPyTagged_Add(n, r9) - return r10 + r3 = CPyTagged_Subtract(n, 2) + r4 = box(int, r3) + r5 = py_call(baz, r4) + r6 = unbox(int, r5) + r7 = CPyTagged_Add(n, r6) + return r7 def f(a): a :: int r0 :: __main__.f_env @@ -869,20 +852,16 @@ def baz(n: int) -> int: [out] def baz(n): n :: int - r0 :: short_int - r1 :: bool - r2, r3 :: short_int - r4, r5, r6 :: int + r0 :: bool + r1, r2, r3 :: int L0: - r0 = 0 - r1 = CPyTagged_IsEq(n, r0) - if r1 goto L1 else goto L2 :: bool + r0 = CPyTagged_IsEq(n, 0) + if r0 goto L1 else goto L2 :: bool L1: - r2 = 0 - return r2 + return 0 L2: - r3 = 2 - r4 = CPyTagged_Subtract(n, r3) - r5 = baz(r4) - r6 = CPyTagged_Add(n, r5) - return r6 + r1 = CPyTagged_Subtract(n, 2) + r2 = baz(r1) + r3 = CPyTagged_Add(n, r2) + return r3 + diff --git a/mypyc/test-data/irbuild-optional.test b/mypyc/test-data/irbuild-optional.test index 7099fafc5698..de61c60cf1d1 100644 --- a/mypyc/test-data/irbuild-optional.test +++ b/mypyc/test-data/irbuild-optional.test @@ -13,18 +13,15 @@ def f(x): r0 :: None r1 :: object r2 :: bool - r3, r4 :: short_int L0: r0 = None r1 = box(None, r0) r2 = x is r1 if r2 goto L1 else goto L2 :: bool L1: - r3 = 2 - return r3 + return 2 L2: - r4 = 4 - return r4 + return 4 [case testIsNotNone] from typing import Optional @@ -41,7 +38,6 @@ def f(x): r0 :: None r1 :: object r2, r3 :: bool - r4, r5 :: short_int L0: r0 = None r1 = box(None, r0) @@ -49,11 +45,9 @@ L0: r3 = !r2 if r3 goto L1 else goto L2 :: bool L1: - r4 = 2 - return r4 + return 2 L2: - r5 = 4 - return r5 + return 4 [case testIsTruthy] from typing import Optional @@ -69,17 +63,14 @@ def f(x): x :: union[__main__.A, None] r0 :: object r1 :: bool - r2, r3 :: short_int L0: r0 = builtins.None :: object r1 = x is not r0 if r1 goto L1 else goto L2 :: bool L1: - r2 = 2 - return r2 + return 2 L2: - r3 = 4 - return r3 + return 4 [case testIsTruthyOverride] from typing import Optional @@ -108,7 +99,6 @@ def f(x): r1 :: bool r2 :: __main__.A r3 :: bool - r4, r5 :: short_int L0: r0 = builtins.None :: object r1 = x is not r0 @@ -118,11 +108,9 @@ L1: r3 = bool r2 :: object if r3 goto L2 else goto L3 :: bool L2: - r4 = 2 - return r4 + return 2 L3: - r5 = 4 - return r5 + return 4 [case testAssignToOptional] from typing import Optional @@ -145,16 +133,14 @@ def f(x, y, z): r0 :: None r1 :: object r2 :: __main__.A - r3 :: short_int - r4 :: object - r5, a :: __main__.A - r6 :: short_int - r7 :: object - r8 :: bool - r9 :: None - r10 :: object - r11 :: bool - r12 :: None + r3 :: object + r4, a :: __main__.A + r5 :: object + r6 :: bool + r7 :: None + r8 :: object + r9 :: bool + r10 :: None L0: r0 = None r1 = box(None, r0) @@ -162,19 +148,17 @@ L0: r2 = A() x = r2 x = y - r3 = 2 - r4 = box(short_int, r3) - z = r4 - r5 = A() - a = r5 - r6 = 2 - r7 = box(short_int, r6) - a.a = r7; r8 = is_error - r9 = None - r10 = box(None, r9) - a.a = r10; r11 = is_error - r12 = None - return r12 + r3 = box(short_int, 2) + z = r3 + r4 = A() + a = r4 + r5 = box(short_int, 2) + a.a = r5; r6 = is_error + r7 = None + r8 = box(None, r7) + a.a = r8; r9 = is_error + r10 = None + return r10 [case testBoxOptionalListItem] from typing import List, Optional @@ -185,25 +169,20 @@ def f(x: List[Optional[int]]) -> None: [out] def f(x): x :: list - r0, r1 :: short_int - r2 :: object - r3 :: bool - r4 :: None - r5 :: short_int - r6 :: object - r7 :: bool - r8 :: None + r0 :: object + r1 :: bool + r2 :: None + r3 :: object + r4 :: bool + r5 :: None L0: - r0 = 0 - r1 = 0 - r2 = box(short_int, r0) - r3 = CPyList_SetItem(x, r1, r2) - r4 = None - r5 = 2 - r6 = box(None, r4) - r7 = CPyList_SetItem(x, r5, r6) - r8 = None - return r8 + r0 = box(short_int, 0) + r1 = CPyList_SetItem(x, 0, r0) + r2 = None + r3 = box(None, r2) + r4 = CPyList_SetItem(x, 2, r3) + r5 = None + return r5 [case testNarrowDownFromOptional] from typing import Optional @@ -253,36 +232,34 @@ def f(y): r0 :: None x :: union[int, None] r1 :: object - r2 :: short_int - r3 :: bool - r4 :: object - r5 :: None - r6 :: object - r7, r8 :: bool - r9 :: int - r10 :: None + r2 :: bool + r3 :: object + r4 :: None + r5 :: object + r6, r7 :: bool + r8 :: int + r9 :: None L0: r0 = None r1 = box(None, r0) x = r1 - r2 = 2 - r3 = CPyTagged_IsEq(y, r2) - if r3 goto L1 else goto L2 :: bool + r2 = CPyTagged_IsEq(y, 2) + if r2 goto L1 else goto L2 :: bool L1: - r4 = box(int, y) - x = r4 + r3 = box(int, y) + x = r3 L2: - r5 = None - r6 = box(None, r5) - r7 = x is r6 - r8 = !r7 - if r8 goto L3 else goto L4 :: bool + r4 = None + r5 = box(None, r4) + r6 = x is r5 + r7 = !r6 + if r7 goto L3 else goto L4 :: bool L3: - r9 = unbox(int, x) - y = r9 + r8 = unbox(int, x) + y = r8 L4: - r10 = None - return r10 + r9 = None + return r9 [case testUnionType] from typing import Union @@ -302,10 +279,9 @@ def f(x): r1 :: int32 r2 :: bool r3 :: int - r4 :: short_int - r5 :: int - r6 :: __main__.A - r7 :: int + r4 :: int + r5 :: __main__.A + r6 :: int L0: r0 = int r1 = PyObject_IsInstance(x, r0) @@ -313,13 +289,12 @@ L0: if r2 goto L1 else goto L2 :: bool L1: r3 = unbox(int, x) - r4 = 2 - r5 = CPyTagged_Add(r3, r4) - return r5 + r4 = CPyTagged_Add(r3, 2) + return r4 L2: - r6 = cast(__main__.A, x) - r7 = r6.a - return r7 + r5 = cast(__main__.A, x) + r6 = r5.a + return r6 L3: unreachable @@ -331,14 +306,12 @@ def f(x: List[Union[int, str]]) -> object: [out] def f(x): x :: list - r0 :: short_int - r1 :: object - r2 :: union[int, str] + r0 :: object + r1 :: union[int, str] L0: - r0 = 0 - r1 = CPyList_GetItemShort(x, r0) - r2 = cast(union[int, str], r1) - return r2 + r0 = CPyList_GetItemShort(x, 0) + r1 = cast(union[int, str], r0) + return r1 [case testUnionAttributeAccess] from typing import Union @@ -419,57 +392,53 @@ L0: def C.f(self, x): self :: __main__.C x :: object - r0 :: short_int L0: - r0 = 0 - return r0 + return 0 def g(o): o :: union[__main__.A, __main__.B, __main__.C] - r0 :: short_int - r1, r2 :: object - r3 :: bool - r4 :: __main__.A - r5 :: int - r6, r7 :: object - r8 :: bool - r9 :: __main__.B - r10, r11 :: object - r12 :: __main__.C - r13 :: object - r14 :: int - r15, z :: object - r16 :: None + r0, r1 :: object + r2 :: bool + r3 :: __main__.A + r4 :: int + r5, r6 :: object + r7 :: bool + r8 :: __main__.B + r9, r10 :: object + r11 :: __main__.C + r12 :: object + r13 :: int + r14, z :: object + r15 :: None L0: - r0 = 2 - r2 = __main__.A :: type - r3 = type_is o, r2 - if r3 goto L1 else goto L2 :: bool + r1 = __main__.A :: type + r2 = type_is o, r1 + if r2 goto L1 else goto L2 :: bool L1: - r4 = cast(__main__.A, o) - r5 = r4.f(r0) - r6 = box(int, r5) - r1 = r6 + r3 = cast(__main__.A, o) + r4 = r3.f(2) + r5 = box(int, r4) + r0 = r5 goto L5 L2: - r7 = __main__.B :: type - r8 = type_is o, r7 - if r8 goto L3 else goto L4 :: bool + r6 = __main__.B :: type + r7 = type_is o, r6 + if r7 goto L3 else goto L4 :: bool L3: - r9 = cast(__main__.B, o) - r10 = box(short_int, r0) - r11 = r9.f(r10) - r1 = r11 + r8 = cast(__main__.B, o) + r9 = box(short_int, 2) + r10 = r8.f(r9) + r0 = r10 goto L5 L4: - r12 = cast(__main__.C, o) - r13 = box(short_int, r0) - r14 = r12.f(r13) - r15 = box(int, r14) - r1 = r15 + r11 = cast(__main__.C, o) + r12 = box(short_int, 2) + r13 = r11.f(r12) + r14 = box(int, r13) + r0 = r14 L5: - z = r1 - r16 = None - return r16 + z = r0 + r15 = None + return r15 [case testUnionWithNonNativeItem] from typing import Union diff --git a/mypyc/test-data/irbuild-set.test b/mypyc/test-data/irbuild-set.test index ccffc1af5351..02ec9f3b9a33 100644 --- a/mypyc/test-data/irbuild-set.test +++ b/mypyc/test-data/irbuild-set.test @@ -4,26 +4,22 @@ def f() -> Set[int]: return {1, 2, 3} [out] def f(): - r0, r1, r2 :: short_int - r3 :: set - r4 :: object - r5 :: int32 - r6 :: object - r7 :: int32 - r8 :: object - r9 :: int32 + r0 :: set + r1 :: object + r2 :: int32 + r3 :: object + r4 :: int32 + r5 :: object + r6 :: int32 L0: - r0 = 2 - r1 = 4 - r2 = 6 - r3 = set - r4 = box(short_int, r0) - r5 = PySet_Add(r3, r4) - r6 = box(short_int, r1) - r7 = PySet_Add(r3, r6) - r8 = box(short_int, r2) - r9 = PySet_Add(r3, r8) - return r3 + r0 = set + r1 = box(short_int, 2) + r2 = PySet_Add(r0, r1) + r3 = box(short_int, 4) + r4 = PySet_Add(r0, r3) + r5 = box(short_int, 6) + r6 = PySet_Add(r0, r5) + return r0 [case testNewEmptySet] from typing import Set @@ -54,28 +50,24 @@ def f() -> int: return len({1, 2, 3}) [out] def f(): - r0, r1, r2 :: short_int - r3 :: set - r4 :: object - r5 :: int32 - r6 :: object - r7 :: int32 - r8 :: object - r9 :: int32 - r10 :: int + r0 :: set + r1 :: object + r2 :: int32 + r3 :: object + r4 :: int32 + r5 :: object + r6 :: int32 + r7 :: int L0: - r0 = 2 - r1 = 4 - r2 = 6 - r3 = set - r4 = box(short_int, r0) - r5 = PySet_Add(r3, r4) - r6 = box(short_int, r1) - r7 = PySet_Add(r3, r6) - r8 = box(short_int, r2) - r9 = PySet_Add(r3, r8) - r10 = len r3 :: set - return r10 + r0 = set + r1 = box(short_int, 2) + r2 = PySet_Add(r0, r1) + r3 = box(short_int, 4) + r4 = PySet_Add(r0, r3) + r5 = box(short_int, 6) + r6 = PySet_Add(r0, r5) + r7 = len r0 :: set + return r7 [case testSetContains] from typing import Set @@ -84,31 +76,26 @@ def f() -> bool: return (5 in x) [out] def f(): - r0, r1 :: short_int - r2 :: set + r0 :: set + r1 :: object + r2 :: int32 r3 :: object r4 :: int32 + x :: set r5 :: object r6 :: int32 - x :: set - r7 :: short_int - r8 :: object - r9 :: int32 - r10 :: bool + r7 :: bool L0: - r0 = 6 - r1 = 8 - r2 = set - r3 = box(short_int, r0) - r4 = PySet_Add(r2, r3) - r5 = box(short_int, r1) - r6 = PySet_Add(r2, r5) - x = r2 - r7 = 10 - r8 = box(short_int, r7) - r9 = PySet_Contains(x, r8) - r10 = truncate r9: int32 to builtins.bool - return r10 + r0 = set + r1 = box(short_int, 6) + r2 = PySet_Add(r0, r1) + r3 = box(short_int, 8) + r4 = PySet_Add(r0, r3) + x = r0 + r5 = box(short_int, 10) + r6 = PySet_Contains(x, r5) + r7 = truncate r6: int32 to builtins.bool + return r7 [case testSetRemove] from typing import Set @@ -119,17 +106,15 @@ def f() -> Set[int]: [out] def f(): r0, x :: set - r1 :: short_int - r2 :: object - r3 :: bool - r4 :: None + r1 :: object + r2 :: bool + r3 :: None L0: r0 = set x = r0 - r1 = 2 - r2 = box(short_int, r1) - r3 = CPySet_Remove(x, r2) - r4 = None + r1 = box(short_int, 2) + r2 = CPySet_Remove(x, r1) + r3 = None return x [case testSetDiscard] @@ -141,17 +126,15 @@ def f() -> Set[int]: [out] def f(): r0, x :: set - r1 :: short_int - r2 :: object - r3 :: int32 - r4 :: None + r1 :: object + r2 :: int32 + r3 :: None L0: r0 = set x = r0 - r1 = 2 - r2 = box(short_int, r1) - r3 = PySet_Discard(x, r2) - r4 = None + r1 = box(short_int, 2) + r2 = PySet_Discard(x, r1) + r3 = None return x [case testSetAdd] @@ -163,17 +146,15 @@ def f() -> Set[int]: [out] def f(): r0, x :: set - r1 :: short_int - r2 :: object - r3 :: int32 - r4 :: None + r1 :: object + r2 :: int32 + r3 :: None L0: r0 = set x = r0 - r1 = 2 - r2 = box(short_int, r1) - r3 = PySet_Add(x, r2) - r4 = None + r1 = box(short_int, 2) + r2 = PySet_Add(x, r1) + r3 = None return x [case testSetClear] @@ -231,26 +212,22 @@ def f(x: Set[int], y: Set[int]) -> Set[int]: [out] def f(x, y): x, y :: set - r0, r1, r2 :: short_int - r3 :: set - r4 :: object - r5 :: int32 - r6 :: object - r7, r8, r9 :: int32 - r10 :: object - r11 :: int32 + r0 :: set + r1 :: object + r2 :: int32 + r3 :: object + r4, r5, r6 :: int32 + r7 :: object + r8 :: int32 L0: - r0 = 2 - r1 = 4 - r2 = 6 - r3 = set - r4 = box(short_int, r0) - r5 = PySet_Add(r3, r4) - r6 = box(short_int, r1) - r7 = PySet_Add(r3, r6) - r8 = _PySet_Update(r3, x) - r9 = _PySet_Update(r3, y) - r10 = box(short_int, r2) - r11 = PySet_Add(r3, r10) - return r3 + r0 = set + r1 = box(short_int, 2) + r2 = PySet_Add(r0, r1) + r3 = box(short_int, 4) + r4 = PySet_Add(r0, r3) + r5 = _PySet_Update(r0, x) + r6 = _PySet_Update(r0, y) + r7 = box(short_int, 6) + r8 = PySet_Add(r0, r7) + return r0 diff --git a/mypyc/test-data/irbuild-statements.test b/mypyc/test-data/irbuild-statements.test index 988751e9cdb9..ec681d0f1376 100644 --- a/mypyc/test-data/irbuild-statements.test +++ b/mypyc/test-data/irbuild-statements.test @@ -5,36 +5,31 @@ def f() -> None: x = x + i [out] def f(): - r0 :: short_int x :: int - r1, r2, r3 :: short_int + r0 :: short_int i :: int - r4 :: bool - r5 :: int - r6, r7 :: short_int - r8 :: None + r1 :: bool + r2 :: int + r3 :: short_int + r4 :: None L0: + x = 0 r0 = 0 - x = r0 - r1 = 0 - r2 = 10 - r3 = r1 - i = r3 + i = r0 L1: - r4 = r3 < r2 :: signed - if r4 goto L2 else goto L4 :: bool + r1 = r0 < 10 :: signed + if r1 goto L2 else goto L4 :: bool L2: - r5 = CPyTagged_Add(x, i) - x = r5 + r2 = CPyTagged_Add(x, i) + x = r2 L3: - r6 = 2 - r7 = r3 + r6 - r3 = r7 - i = r7 + r3 = r0 + 2 + r0 = r3 + i = r3 goto L1 L4: - r8 = None - return r8 + r4 = None + return r4 [case testForInNegativeRange] def f() -> None: @@ -42,29 +37,26 @@ def f() -> None: pass [out] def f(): - r0, r1, r2 :: short_int + r0 :: short_int i :: int - r3 :: bool - r4, r5 :: short_int - r6 :: None + r1 :: bool + r2 :: short_int + r3 :: None L0: r0 = 20 - r1 = 0 - r2 = r0 - i = r2 + i = r0 L1: - r3 = CPyTagged_IsGt(r2, r1) - if r3 goto L2 else goto L4 :: bool + r1 = CPyTagged_IsGt(r0, 0) + if r1 goto L2 else goto L4 :: bool L2: L3: - r4 = -2 - r5 = r2 + r4 - r2 = r5 - i = r5 + r2 = r0 + -2 + r0 = r2 + i = r2 goto L1 L4: - r6 = None - return r6 + r3 = None + return r3 [case testBreak] def f() -> None: @@ -73,22 +65,18 @@ def f() -> None: break [out] def f(): - r0 :: short_int n :: int - r1 :: short_int - r2 :: bool - r3 :: None + r0 :: bool + r1 :: None L0: - r0 = 0 - n = r0 + n = 0 L1: - r1 = 10 - r2 = CPyTagged_IsLt(n, r1) - if r2 goto L2 else goto L3 :: bool + r0 = CPyTagged_IsLt(n, 10) + if r0 goto L2 else goto L3 :: bool L2: L3: - r3 = None - return r3 + r1 = None + return r1 [case testBreakFor] def f() -> None: @@ -96,30 +84,27 @@ def f() -> None: break [out] def f(): - r0, r1, r2 :: short_int + r0 :: short_int n :: int - r3 :: bool - r4, r5 :: short_int - r6 :: None + r1 :: bool + r2 :: short_int + r3 :: None L0: r0 = 0 - r1 = 10 - r2 = r0 - n = r2 + n = r0 L1: - r3 = r2 < r1 :: signed - if r3 goto L2 else goto L4 :: bool + r1 = r0 < 10 :: signed + if r1 goto L2 else goto L4 :: bool L2: goto L4 L3: - r4 = 2 - r5 = r2 + r4 - r2 = r5 - n = r5 + r2 = r0 + 2 + r0 = r2 + n = r2 goto L1 L4: - r6 = None - return r6 + r3 = None + return r3 [case testBreakNested] def f() -> None: @@ -130,30 +115,24 @@ def f() -> None: break [out] def f(): - r0 :: short_int n :: int - r1 :: short_int - r2 :: bool - r3 :: short_int - r4 :: bool - r5 :: None + r0 :: bool + r1 :: bool + r2 :: None L0: - r0 = 0 - n = r0 + n = 0 L1: - r1 = 10 - r2 = CPyTagged_IsLt(n, r1) - if r2 goto L2 else goto L6 :: bool + r0 = CPyTagged_IsLt(n, 10) + if r0 goto L2 else goto L6 :: bool L2: L3: - r3 = 8 - r4 = CPyTagged_IsLt(n, r3) - if r4 goto L4 else goto L5 :: bool + r1 = CPyTagged_IsLt(n, 8) + if r1 goto L4 else goto L5 :: bool L4: L5: L6: - r5 = None - return r5 + r2 = None + return r2 [case testContinue] def f() -> None: @@ -162,23 +141,19 @@ def f() -> None: continue [out] def f(): - r0 :: short_int n :: int - r1 :: short_int - r2 :: bool - r3 :: None + r0 :: bool + r1 :: None L0: - r0 = 0 - n = r0 + n = 0 L1: - r1 = 10 - r2 = CPyTagged_IsLt(n, r1) - if r2 goto L2 else goto L3 :: bool + r0 = CPyTagged_IsLt(n, 10) + if r0 goto L2 else goto L3 :: bool L2: goto L1 L3: - r3 = None - return r3 + r1 = None + return r1 [case testContinueFor] def f() -> None: @@ -186,29 +161,26 @@ def f() -> None: continue [out] def f(): - r0, r1, r2 :: short_int + r0 :: short_int n :: int - r3 :: bool - r4, r5 :: short_int - r6 :: None + r1 :: bool + r2 :: short_int + r3 :: None L0: r0 = 0 - r1 = 10 - r2 = r0 - n = r2 + n = r0 L1: - r3 = r2 < r1 :: signed - if r3 goto L2 else goto L4 :: bool + r1 = r0 < 10 :: signed + if r1 goto L2 else goto L4 :: bool L2: L3: - r4 = 2 - r5 = r2 + r4 - r2 = r5 - n = r5 + r2 = r0 + 2 + r0 = r2 + n = r2 goto L1 L4: - r6 = None - return r6 + r3 = None + return r3 [case testContinueNested] def f() -> None: @@ -219,32 +191,26 @@ def f() -> None: continue [out] def f(): - r0 :: short_int n :: int - r1 :: short_int - r2 :: bool - r3 :: short_int - r4 :: bool - r5 :: None + r0 :: bool + r1 :: bool + r2 :: None L0: - r0 = 0 - n = r0 + n = 0 L1: - r1 = 10 - r2 = CPyTagged_IsLt(n, r1) - if r2 goto L2 else goto L6 :: bool + r0 = CPyTagged_IsLt(n, 10) + if r0 goto L2 else goto L6 :: bool L2: L3: - r3 = 8 - r4 = CPyTagged_IsLt(n, r3) - if r4 goto L4 else goto L5 :: bool + r1 = CPyTagged_IsLt(n, 8) + if r1 goto L4 else goto L5 :: bool L4: goto L3 L5: goto L1 L6: - r5 = None - return r5 + r2 = None + return r2 [case testForList] from typing import List @@ -257,32 +223,28 @@ def f(ls: List[int]) -> int: [out] def f(ls): ls :: list - r0 :: short_int y :: int - r1, r2, r3 :: short_int - r4 :: bool - r5 :: object - x, r6, r7 :: int - r8, r9 :: short_int + r0, r1 :: short_int + r2 :: bool + r3 :: object + x, r4, r5 :: int + r6 :: short_int L0: + y = 0 r0 = 0 - y = r0 - r1 = 0 - r2 = r1 L1: - r3 = len ls :: list - r4 = r2 < r3 :: signed - if r4 goto L2 else goto L4 :: bool + r1 = len ls :: list + r2 = r0 < r1 :: signed + if r2 goto L2 else goto L4 :: bool L2: - r5 = ls[r2] :: unsafe list - r6 = unbox(int, r5) - x = r6 - r7 = CPyTagged_Add(y, x) - y = r7 + r3 = ls[r0] :: unsafe list + r4 = unbox(int, r3) + x = r4 + r5 = CPyTagged_Add(y, x) + y = r5 L3: - r8 = 2 - r9 = r2 + r8 - r2 = r9 + r6 = r0 + 2 + r0 = r6 goto L1 L4: return y @@ -296,44 +258,43 @@ def f(d: Dict[int, int]) -> None: [out] def f(d): d :: dict - r0, r1 :: short_int - r2 :: int - r3 :: object - r4 :: tuple[bool, int, object] - r5 :: int - r6 :: bool - r7 :: object - key, r8 :: int - r9, r10 :: object - r11 :: int - r12, r13 :: bool - r14 :: None + r0 :: short_int + r1 :: int + r2 :: object + r3 :: tuple[bool, int, object] + r4 :: int + r5 :: bool + r6 :: object + key, r7 :: int + r8, r9 :: object + r10 :: int + r11, r12 :: bool + r13 :: None L0: r0 = 0 - r1 = r0 - r2 = len d :: dict - r3 = CPyDict_GetKeysIter(d) + r1 = len d :: dict + r2 = CPyDict_GetKeysIter(d) L1: - r4 = CPyDict_NextKey(r3, r1) - r5 = r4[1] - r1 = r5 - r6 = r4[0] - if r6 goto L2 else goto L4 :: bool + r3 = CPyDict_NextKey(r2, r0) + r4 = r3[1] + r0 = r4 + r5 = r3[0] + if r5 goto L2 else goto L4 :: bool L2: - r7 = r4[2] - r8 = unbox(int, r7) - key = r8 - r9 = box(int, key) - r10 = CPyDict_GetItem(d, r9) - r11 = unbox(int, r10) + r6 = r3[2] + r7 = unbox(int, r6) + key = r7 + r8 = box(int, key) + r9 = CPyDict_GetItem(d, r8) + r10 = unbox(int, r9) L3: - r12 = CPyDict_CheckSize(d, r2) + r11 = CPyDict_CheckSize(d, r1) goto L1 L4: - r13 = CPy_NoErrOccured() + r12 = CPy_NoErrOccured() L5: - r14 = None - return r14 + r13 = None + return r13 [case testForDictContinue] from typing import Dict @@ -348,63 +309,56 @@ def sum_over_even_values(d: Dict[int, int]) -> int: [out] def sum_over_even_values(d): d :: dict - r0 :: short_int s :: int - r1, r2 :: short_int - r3 :: int - r4 :: object - r5 :: tuple[bool, int, object] - r6 :: int - r7 :: bool - r8 :: object - key, r9 :: int - r10, r11 :: object - r12 :: int - r13 :: short_int - r14 :: int - r15 :: short_int - r16 :: bool - r17, r18 :: object - r19, r20 :: int - r21, r22 :: bool + r0 :: short_int + r1 :: int + r2 :: object + r3 :: tuple[bool, int, object] + r4 :: int + r5 :: bool + r6 :: object + key, r7 :: int + r8, r9 :: object + r10 :: int + r11 :: int + r12 :: bool + r13, r14 :: object + r15, r16 :: int + r17, r18 :: bool L0: + s = 0 r0 = 0 - s = r0 - r1 = 0 - r2 = r1 - r3 = len d :: dict - r4 = CPyDict_GetKeysIter(d) + r1 = len d :: dict + r2 = CPyDict_GetKeysIter(d) L1: - r5 = CPyDict_NextKey(r4, r2) - r6 = r5[1] - r2 = r6 - r7 = r5[0] - if r7 goto L2 else goto L6 :: bool + r3 = CPyDict_NextKey(r2, r0) + r4 = r3[1] + r0 = r4 + r5 = r3[0] + if r5 goto L2 else goto L6 :: bool L2: - r8 = r5[2] - r9 = unbox(int, r8) - key = r9 - r10 = box(int, key) - r11 = CPyDict_GetItem(d, r10) - r12 = unbox(int, r11) - r13 = 4 - r14 = CPyTagged_Remainder(r12, r13) - r15 = 0 - r16 = CPyTagged_IsNe(r14, r15) - if r16 goto L3 else goto L4 :: bool + r6 = r3[2] + r7 = unbox(int, r6) + key = r7 + r8 = box(int, key) + r9 = CPyDict_GetItem(d, r8) + r10 = unbox(int, r9) + r11 = CPyTagged_Remainder(r10, 4) + r12 = CPyTagged_IsNe(r11, 0) + if r12 goto L3 else goto L4 :: bool L3: goto L5 L4: - r17 = box(int, key) - r18 = CPyDict_GetItem(d, r17) - r19 = unbox(int, r18) - r20 = CPyTagged_Add(s, r19) - s = r20 + r13 = box(int, key) + r14 = CPyDict_GetItem(d, r13) + r15 = unbox(int, r14) + r16 = CPyTagged_Add(s, r15) + s = r16 L5: - r21 = CPyDict_CheckSize(d, r3) + r17 = CPyDict_CheckSize(d, r1) goto L1 L6: - r22 = CPy_NoErrOccured() + r18 = CPy_NoErrOccured() L7: return s @@ -544,27 +498,25 @@ def multi_assign(t, a, l): a :: __main__.A l :: list z :: int - r0 :: short_int - r1 :: int - r2 :: bool - r3 :: tuple[str, object] - r4 :: str - r5 :: bool - r6 :: object - r7 :: int - r8 :: None + r0 :: int + r1 :: bool + r2 :: tuple[str, object] + r3 :: str + r4 :: bool + r5 :: object + r6 :: int + r7 :: None L0: - r0 = 0 - r1 = t[0] - a.x = r1; r2 = is_error - r3 = t[1] - r4 = r3[0] - r5 = CPyList_SetItem(l, r0, r4) - r6 = r3[1] - r7 = unbox(int, r6) - z = r7 - r8 = None - return r8 + r0 = t[0] + a.x = r0; r1 = is_error + r2 = t[1] + r3 = r2[0] + r4 = CPyList_SetItem(l, 0, r3) + r5 = r2[1] + r6 = unbox(int, r5) + z = r6 + r7 = None + return r7 [case testAssert] from typing import Optional @@ -582,19 +534,16 @@ def complex_msg(x: Optional[str], s: str) -> None: [out] def no_msg(x): x, r0 :: bool - r1 :: short_int L0: if x goto L2 else goto L1 :: bool L1: raise AssertionError unreachable L2: - r1 = 2 - return r1 + return 2 def literal_msg(x): x :: object r0, r1 :: bool - r2 :: short_int L0: r0 = bool x :: object if r0 goto L2 else goto L1 :: bool @@ -602,8 +551,7 @@ L1: raise AssertionError('message') unreachable L2: - r2 = 4 - return r2 + return 4 def complex_msg(x, s): x :: union[str, None] s :: str @@ -643,65 +591,48 @@ def delListMultiple() -> None: del l[1], l[2], l[3] [out] def delList(): - r0, r1 :: short_int - r2, r3 :: object - r4, l :: list - r5 :: short_int - r6 :: object - r7 :: bool - r8 :: None + r0, r1 :: object + r2, l :: list + r3 :: object + r4 :: bool + r5 :: None L0: - r0 = 2 - r1 = 4 - r2 = box(short_int, r0) - r3 = box(short_int, r1) - r4 = [r2, r3] - l = r4 - r5 = 2 - r6 = box(short_int, r5) - r7 = l.__delitem__(r6) :: object - r8 = None - return r8 + r0 = box(short_int, 2) + r1 = box(short_int, 4) + r2 = [r0, r1] + l = r2 + r3 = box(short_int, 2) + r4 = l.__delitem__(r3) :: object + r5 = None + return r5 def delListMultiple(): - r0, r1, r2, r3, r4, r5, r6 :: short_int - r7, r8, r9, r10, r11, r12, r13 :: object - r14, l :: list - r15, r16, r17 :: short_int - r18 :: object - r19 :: bool - r20 :: object - r21 :: bool - r22 :: object - r23 :: bool - r24 :: None + r0, r1, r2, r3, r4, r5, r6 :: object + r7, l :: list + r8 :: object + r9 :: bool + r10 :: object + r11 :: bool + r12 :: object + r13 :: bool + r14 :: None L0: - r0 = 2 - r1 = 4 - r2 = 6 - r3 = 8 - r4 = 10 - r5 = 12 - r6 = 14 - r7 = box(short_int, r0) - r8 = box(short_int, r1) - r9 = box(short_int, r2) - r10 = box(short_int, r3) - r11 = box(short_int, r4) - r12 = box(short_int, r5) - r13 = box(short_int, r6) - r14 = [r7, r8, r9, r10, r11, r12, r13] - l = r14 - r15 = 2 - r16 = 4 - r17 = 6 - r18 = box(short_int, r15) - r19 = l.__delitem__(r18) :: object - r20 = box(short_int, r16) - r21 = l.__delitem__(r20) :: object - r22 = box(short_int, r17) - r23 = l.__delitem__(r22) :: object - r24 = None - return r24 + r0 = box(short_int, 2) + r1 = box(short_int, 4) + r2 = box(short_int, 6) + r3 = box(short_int, 8) + r4 = box(short_int, 10) + r5 = box(short_int, 12) + r6 = box(short_int, 14) + r7 = [r0, r1, r2, r3, r4, r5, r6] + l = r7 + r8 = box(short_int, 2) + r9 = l.__delitem__(r8) :: object + r10 = box(short_int, 4) + r11 = l.__delitem__(r10) :: object + r12 = box(short_int, 6) + r13 = l.__delitem__(r12) :: object + r14 = None + return r14 [case testDelDict] def delDict() -> None: @@ -713,66 +644,50 @@ def delDictMultiple() -> None: [out] def delDict(): r0 :: str - r1 :: short_int - r2 :: str - r3 :: short_int - r4 :: native_int - r5, r6 :: object - r7, d :: dict - r8 :: str - r9 :: bool - r10 :: None + r1 :: str + r2, r3 :: object + r4, d :: dict + r5 :: str + r6 :: bool + r7 :: None L0: r0 = unicode_1 :: static ('one') - r1 = 2 - r2 = unicode_2 :: static ('two') - r3 = 4 - r4 = 2 - r5 = box(short_int, r1) - r6 = box(short_int, r3) - r7 = CPyDict_Build(r4, r0, r5, r2, r6) - d = r7 - r8 = unicode_1 :: static ('one') - r9 = d.__delitem__(r8) :: object - r10 = None - return r10 + r1 = unicode_2 :: static ('two') + r2 = box(short_int, 2) + r3 = box(short_int, 4) + r4 = CPyDict_Build(2, r0, r2, r1, r3) + d = r4 + r5 = unicode_1 :: static ('one') + r6 = d.__delitem__(r5) :: object + r7 = None + return r7 def delDictMultiple(): r0 :: str - r1 :: short_int + r1 :: str r2 :: str - r3 :: short_int - r4 :: str - r5 :: short_int - r6 :: str - r7 :: short_int - r8 :: native_int - r9, r10, r11, r12 :: object - r13, d :: dict - r14, r15 :: str - r16, r17 :: bool - r18 :: None + r3 :: str + r4, r5, r6, r7 :: object + r8, d :: dict + r9, r10 :: str + r11, r12 :: bool + r13 :: None L0: r0 = unicode_1 :: static ('one') - r1 = 2 - r2 = unicode_2 :: static ('two') - r3 = 4 - r4 = unicode_3 :: static ('three') - r5 = 6 - r6 = unicode_4 :: static ('four') - r7 = 8 - r8 = 4 - r9 = box(short_int, r1) - r10 = box(short_int, r3) - r11 = box(short_int, r5) - r12 = box(short_int, r7) - r13 = CPyDict_Build(r8, r0, r9, r2, r10, r4, r11, r6, r12) - d = r13 - r14 = unicode_1 :: static ('one') - r15 = unicode_4 :: static ('four') - r16 = d.__delitem__(r14) :: object - r17 = d.__delitem__(r15) :: object - r18 = None - return r18 + r1 = unicode_2 :: static ('two') + r2 = unicode_3 :: static ('three') + r3 = unicode_4 :: static ('four') + r4 = box(short_int, 2) + r5 = box(short_int, 4) + r6 = box(short_int, 6) + r7 = box(short_int, 8) + r8 = CPyDict_Build(4, r0, r4, r1, r5, r2, r6, r3, r7) + d = r8 + r9 = unicode_1 :: static ('one') + r10 = unicode_4 :: static ('four') + r11 = d.__delitem__(r9) :: object + r12 = d.__delitem__(r10) :: object + r13 = None + return r13 [case testDelAttribute] class Dummy(): @@ -797,39 +712,33 @@ L0: r2 = None return r2 def delAttribute(): - r0, r1 :: short_int - r2, dummy :: __main__.Dummy + r0, dummy :: __main__.Dummy + r1 :: str + r2 :: bool + r3 :: None +L0: + r0 = Dummy(2, 4) + dummy = r0 + r1 = unicode_3 :: static ('x') + r2 = delattr dummy, r1 + r3 = None + return r3 +def delAttributeMultiple(): + r0, dummy :: __main__.Dummy + r1 :: str + r2 :: bool r3 :: str r4 :: bool r5 :: None L0: - r0 = 2 - r1 = 4 - r2 = Dummy(r0, r1) - dummy = r2 - r3 = unicode_3 :: static ('x') + r0 = Dummy(2, 4) + dummy = r0 + r1 = unicode_3 :: static ('x') + r2 = delattr dummy, r1 + r3 = unicode_4 :: static ('y') r4 = delattr dummy, r3 r5 = None return r5 -def delAttributeMultiple(): - r0, r1 :: short_int - r2, dummy :: __main__.Dummy - r3 :: str - r4 :: bool - r5 :: str - r6 :: bool - r7 :: None -L0: - r0 = 2 - r1 = 4 - r2 = Dummy(r0, r1) - dummy = r2 - r3 = unicode_3 :: static ('x') - r4 = delattr dummy, r3 - r5 = unicode_4 :: static ('y') - r6 = delattr dummy, r5 - r7 = None - return r7 [case testForEnumerate] from typing import List, Iterable @@ -843,73 +752,67 @@ def g(x: Iterable[int]) -> None: [out] def f(a): a :: list - r0, r1 :: short_int + r0 :: short_int i :: int - r2, r3, r4 :: short_int - r5 :: bool - r6 :: object - x, r7, r8 :: int - r9, r10, r11, r12 :: short_int - r13 :: None + r1, r2 :: short_int + r3 :: bool + r4 :: object + x, r5, r6 :: int + r7, r8 :: short_int + r9 :: None L0: r0 = 0 - r1 = r0 - i = r0 - r2 = 0 - r3 = r2 + i = 0 + r1 = 0 L1: - r4 = len a :: list - r5 = r3 < r4 :: signed - if r5 goto L2 else goto L4 :: bool + r2 = len a :: list + r3 = r1 < r2 :: signed + if r3 goto L2 else goto L4 :: bool L2: - r6 = a[r3] :: unsafe list - r7 = unbox(int, r6) - x = r7 - r8 = CPyTagged_Add(i, x) + r4 = a[r1] :: unsafe list + r5 = unbox(int, r4) + x = r5 + r6 = CPyTagged_Add(i, x) L3: - r9 = 2 - r10 = r1 + r9 - r1 = r10 - i = r10 - r11 = 2 - r12 = r3 + r11 - r3 = r12 + r7 = r0 + 2 + r0 = r7 + i = r7 + r8 = r1 + 2 + r1 = r8 goto L1 L4: L5: - r13 = None - return r13 + r9 = None + return r9 def g(x): x :: object - r0, r1 :: short_int + r0 :: short_int i :: int - r2, r3 :: object - r4, n :: int - r5, r6 :: short_int - r7 :: bool - r8 :: None + r1, r2 :: object + r3, n :: int + r4 :: short_int + r5 :: bool + r6 :: None L0: r0 = 0 - r1 = r0 - i = r0 - r2 = iter x :: object + i = 0 + r1 = iter x :: object L1: - r3 = next r2 :: object - if is_error(r3) goto L4 else goto L2 + r2 = next r1 :: object + if is_error(r2) goto L4 else goto L2 L2: - r4 = unbox(int, r3) - n = r4 + r3 = unbox(int, r2) + n = r3 L3: - r5 = 2 - r6 = r1 + r5 - r1 = r6 - i = r6 + r4 = r0 + 2 + r0 = r4 + i = r4 goto L1 L4: - r7 = CPy_NoErrOccured() + r5 = CPy_NoErrOccured() L5: - r8 = None - return r8 + r6 = None + return r6 [case testForZip] from typing import List, Iterable @@ -926,102 +829,94 @@ def g(a: Iterable[bool], b: List[int]) -> None: def f(a, b): a :: list b :: object - r0, r1 :: short_int - r2 :: object - r3 :: short_int - r4 :: bool - r5, r6 :: object - x, r7 :: int - r8, y, r9 :: bool - r10, r11, r12 :: short_int - r13 :: bool - r14 :: None + r0 :: short_int + r1 :: object + r2 :: short_int + r3 :: bool + r4, r5 :: object + x, r6 :: int + r7, y, r8 :: bool + r9 :: short_int + r10 :: bool + r11 :: None L0: r0 = 0 - r1 = r0 - r2 = iter b :: object + r1 = iter b :: object L1: - r3 = len a :: list - r4 = r1 < r3 :: signed - if r4 goto L2 else goto L7 :: bool + r2 = len a :: list + r3 = r0 < r2 :: signed + if r3 goto L2 else goto L7 :: bool L2: - r5 = next r2 :: object - if is_error(r5) goto L7 else goto L3 + r4 = next r1 :: object + if is_error(r4) goto L7 else goto L3 L3: - r6 = a[r1] :: unsafe list - r7 = unbox(int, r6) - x = r7 - r8 = unbox(bool, r5) - y = r8 - r9 = bool b :: object - if r9 goto L4 else goto L5 :: bool + r5 = a[r0] :: unsafe list + r6 = unbox(int, r5) + x = r6 + r7 = unbox(bool, r4) + y = r7 + r8 = bool b :: object + if r8 goto L4 else goto L5 :: bool L4: - r10 = 2 - x = r10 + x = 2 L5: L6: - r11 = 2 - r12 = r1 + r11 - r1 = r12 + r9 = r0 + 2 + r0 = r9 goto L1 L7: - r13 = CPy_NoErrOccured() + r10 = CPy_NoErrOccured() L8: - r14 = None - return r14 + r11 = None + return r11 def g(a, b): a :: object b :: list r0 :: object - r1, r2, r3, r4, r5 :: short_int + r1, r2 :: short_int z :: int - r6 :: object - r7 :: short_int - r8, r9, r10, x :: bool - r11 :: object - y, r12 :: int + r3 :: object + r4 :: short_int + r5, r6, r7, x :: bool + r8 :: object + y, r9 :: int + r10 :: bool + r11, r12 :: short_int r13 :: bool - r14, r15, r16, r17 :: short_int - r18 :: bool - r19 :: None + r14 :: None L0: r0 = iter a :: object r1 = 0 - r2 = r1 - r3 = 0 - r4 = 10 - r5 = r3 - z = r5 + r2 = 0 + z = r2 L1: - r6 = next r0 :: object - if is_error(r6) goto L6 else goto L2 + r3 = next r0 :: object + if is_error(r3) goto L6 else goto L2 L2: - r7 = len b :: list - r8 = r2 < r7 :: signed - if r8 goto L3 else goto L6 :: bool + r4 = len b :: list + r5 = r1 < r4 :: signed + if r5 goto L3 else goto L6 :: bool L3: - r9 = r5 < r4 :: signed - if r9 goto L4 else goto L6 :: bool + r6 = r2 < 10 :: signed + if r6 goto L4 else goto L6 :: bool L4: - r10 = unbox(bool, r6) + r7 = unbox(bool, r3) + x = r7 + r8 = b[r1] :: unsafe list + r9 = unbox(int, r8) + y = r9 + r10 = False x = r10 - r11 = b[r2] :: unsafe list - r12 = unbox(int, r11) - y = r12 - r13 = False - x = r13 L5: - r14 = 2 - r15 = r2 + r14 - r2 = r15 - r16 = 2 - r17 = r5 + r16 - r5 = r17 - z = r17 + r11 = r1 + 2 + r1 = r11 + r12 = r2 + 2 + r2 = r12 + z = r12 goto L1 L6: - r18 = CPy_NoErrOccured() + r13 = CPy_NoErrOccured() L7: - r19 = None - return r19 + r14 = None + return r14 diff --git a/mypyc/test-data/irbuild-strip-asserts.test b/mypyc/test-data/irbuild-strip-asserts.test index 8ee062a8c123..1ab6b4107b4d 100644 --- a/mypyc/test-data/irbuild-strip-asserts.test +++ b/mypyc/test-data/irbuild-strip-asserts.test @@ -5,14 +5,11 @@ def g(): return x [out] def g(): - r0, r1 :: short_int - r2 :: int - r3, x :: object + r0 :: int + r1, x :: object L0: - r0 = 2 - r1 = 4 - r2 = CPyTagged_Add(r0, r1) - r3 = box(int, r2) - x = r3 + r0 = CPyTagged_Add(2, 4) + r1 = box(int, r0) + x = r1 return x diff --git a/mypyc/test-data/irbuild-tuple.test b/mypyc/test-data/irbuild-tuple.test index f4d2b4d81ff0..d641827f37de 100644 --- a/mypyc/test-data/irbuild-tuple.test +++ b/mypyc/test-data/irbuild-tuple.test @@ -22,16 +22,14 @@ def f() -> int: [out] def f(): r0 :: bool - r1 :: short_int - r2, t :: tuple[bool, int] - r3 :: int + r1, t :: tuple[bool, int] + r2 :: int L0: r0 = True - r1 = 2 - r2 = (r0, r1) - t = r2 - r3 = t[1] - return r3 + r1 = (r0, 2) + t = r1 + r2 = t[1] + return r2 [case testTupleLen] from typing import Tuple @@ -40,10 +38,8 @@ def f(x: Tuple[bool, bool, int]) -> int: [out] def f(x): x :: tuple[bool, bool, int] - r0 :: short_int L0: - r0 = 6 - return r0 + return 6 [case testSequenceTuple] from typing import List @@ -53,15 +49,13 @@ def f(x: List[bool]) -> bool: def f(x): x :: list r0 :: tuple - r1 :: short_int - r2 :: object - r3 :: bool + r1 :: object + r2 :: bool L0: r0 = PyList_AsTuple(x) - r1 = 2 - r2 = CPySequenceTuple_GetItem(r0, r1) - r3 = unbox(bool, r2) - return r3 + r1 = CPySequenceTuple_GetItem(r0, 2) + r2 = unbox(bool, r1) + return r2 [case testSequenceTupleLen] from typing import Tuple @@ -82,23 +76,18 @@ def f() -> int: return t[1] [out] def f(): - r0, r1 :: short_int - r2 :: tuple[int, int] + r0 :: tuple[int, int] t :: tuple - r3 :: object - r4 :: short_int - r5 :: object - r6 :: int + r1 :: object + r2 :: object + r3 :: int L0: - r0 = 2 - r1 = 4 - r2 = (r0, r1) - r3 = box(tuple[int, int], r2) - t = r3 - r4 = 2 - r5 = CPySequenceTuple_GetItem(t, r4) - r6 = unbox(int, r5) - return r6 + r0 = (2, 4) + r1 = box(tuple[int, int], r0) + t = r1 + r2 = CPySequenceTuple_GetItem(t, 2) + r3 = unbox(int, r2) + return r3 [case testTupleDisplay] from typing import Sequence, Tuple @@ -107,25 +96,21 @@ def f(x: Sequence[int], y: Sequence[int]) -> Tuple[int, ...]: [out] def f(x, y): x, y :: object - r0, r1, r2 :: short_int - r3, r4 :: object - r5 :: list - r6, r7, r8 :: object - r9 :: int32 - r10 :: tuple + r0, r1 :: object + r2 :: list + r3, r4, r5 :: object + r6 :: int32 + r7 :: tuple L0: - r0 = 2 - r1 = 4 - r2 = 6 - r3 = box(short_int, r0) - r4 = box(short_int, r1) - r5 = [r3, r4] - r6 = CPyList_Extend(r5, x) - r7 = CPyList_Extend(r5, y) - r8 = box(short_int, r2) - r9 = PyList_Append(r5, r8) - r10 = PyList_AsTuple(r5) - return r10 + r0 = box(short_int, 2) + r1 = box(short_int, 4) + r2 = [r0, r1] + r3 = CPyList_Extend(r2, x) + r4 = CPyList_Extend(r2, y) + r5 = box(short_int, 6) + r6 = PyList_Append(r2, r5) + r7 = PyList_AsTuple(r2) + return r7 [case testTupleFor] from typing import Tuple, List @@ -135,32 +120,30 @@ def f(xs: Tuple[str, ...]) -> None: [out] def f(xs): xs :: tuple - r0, r1 :: short_int - r2 :: int - r3 :: bool - r4 :: object - x, r5 :: str - r6, r7 :: short_int - r8 :: None + r0 :: short_int + r1 :: int + r2 :: bool + r3 :: object + x, r4 :: str + r5 :: short_int + r6 :: None L0: r0 = 0 - r1 = r0 L1: - r2 = len xs :: tuple - r3 = CPyTagged_IsLt(r1, r2) - if r3 goto L2 else goto L4 :: bool + r1 = len xs :: tuple + r2 = CPyTagged_IsLt(r0, r1) + if r2 goto L2 else goto L4 :: bool L2: - r4 = CPySequenceTuple_GetItem(xs, r1) - r5 = cast(str, r4) - x = r5 + r3 = CPySequenceTuple_GetItem(xs, r0) + r4 = cast(str, r3) + x = r4 L3: - r6 = 2 - r7 = r1 + r6 - r1 = r7 + r5 = r0 + 2 + r0 = r5 goto L1 L4: - r8 = None - return r8 + r6 = None + return r6 [case testNamedTupleAttribute] from typing import NamedTuple @@ -175,21 +158,18 @@ def f(nt: NT, b: bool) -> int: def f(nt, b): nt :: tuple b :: bool - r0 :: short_int - r1 :: object - r2 :: int - r3 :: short_int - r4 :: object - r5 :: int + r0 :: object + r1 :: int + r2 :: object + r3 :: int L0: if b goto L1 else goto L2 :: bool L1: - r0 = 0 - r1 = CPySequenceTuple_GetItem(nt, r0) - r2 = unbox(int, r1) - return r2 + r0 = CPySequenceTuple_GetItem(nt, 0) + r1 = unbox(int, r0) + return r1 L2: - r3 = 2 - r4 = CPySequenceTuple_GetItem(nt, r3) - r5 = unbox(int, r4) - return r5 + r2 = CPySequenceTuple_GetItem(nt, 2) + r3 = unbox(int, r2) + return r3 + diff --git a/mypyc/test-data/refcount.test b/mypyc/test-data/refcount.test index fa957b876932..0e634145ae41 100644 --- a/mypyc/test-data/refcount.test +++ b/mypyc/test-data/refcount.test @@ -5,10 +5,8 @@ def f() -> int: return 1 [out] def f(): - r0 :: short_int L0: - r0 = 2 - return r0 + return 2 [case testReturnLocal] def f() -> int: @@ -16,11 +14,9 @@ def f() -> int: return x [out] def f(): - r0 :: short_int x :: int L0: - r0 = 2 - x = r0 + x = 2 return x [case testLocalVars] @@ -31,11 +27,9 @@ def f() -> int: return x [out] def f(): - r0 :: short_int x, y :: int L0: - r0 = 2 - x = r0 + x = 2 y = x x = y return x @@ -48,18 +42,16 @@ def f() -> int: return y + z [out] def f(): - r0 :: short_int - x, y, z, r1 :: int + x, y, z, r0 :: int L0: - r0 = 2 - x = r0 + x = 2 inc_ref x :: int y = x z = x - r1 = CPyTagged_Add(y, z) + r0 = CPyTagged_Add(y, z) dec_ref y :: int dec_ref z :: int - return r1 + return r0 [case testFreeAtReturn] def f() -> int: @@ -70,20 +62,14 @@ def f() -> int: return y [out] def f(): - r0 :: short_int x :: int - r1 :: short_int y :: int - r2 :: short_int - r3 :: bool + r0 :: bool L0: - r0 = 2 - x = r0 - r1 = 4 - y = r1 - r2 = 2 - r3 = CPyTagged_IsEq(x, r2) - if r3 goto L3 else goto L4 :: bool + x = 2 + y = 4 + r0 = CPyTagged_IsEq(x, 2) + if r0 goto L3 else goto L4 :: bool L1: return x L2: @@ -103,15 +89,13 @@ def f(a: int, b: int) -> int: [out] def f(a, b): a, b :: int - r0 :: short_int - r1, x, r2, y :: int + r0, x, r1, y :: int L0: - r0 = 2 - r1 = CPyTagged_Add(a, r0) - x = r1 - r2 = CPyTagged_Add(x, a) + r0 = CPyTagged_Add(a, 2) + x = r0 + r1 = CPyTagged_Add(x, a) dec_ref x :: int - y = r2 + y = r1 return y [case testArgumentsInAssign] @@ -123,20 +107,18 @@ def f(a: int) -> int: [out] def f(a): a, x, y :: int - r0 :: short_int - r1 :: int + r0 :: int L0: inc_ref a :: int x = a dec_ref x :: int inc_ref a :: int y = a - r0 = 2 - x = r0 - r1 = CPyTagged_Add(x, y) + x = 2 + r0 = CPyTagged_Add(x, y) dec_ref x :: int dec_ref y :: int - return r1 + return r0 [case testAssignToArgument1] def f(a: int) -> int: @@ -146,11 +128,9 @@ def f(a: int) -> int: [out] def f(a): a :: int - r0 :: short_int y :: int L0: - r0 = 2 - a = r0 + a = 2 y = a return y @@ -163,16 +143,12 @@ def f(a: int) -> int: [out] def f(a): a :: int - r0, r1, r2 :: short_int L0: - r0 = 2 - a = r0 + a = 2 dec_ref a :: int - r1 = 4 - a = r1 + a = 4 dec_ref a :: int - r2 = 6 - a = r2 + a = 6 return a [case testAssignToArgument3] @@ -184,11 +160,9 @@ def f(a: int) -> int: [out] def f(a): a :: int - r0 :: short_int x, y :: int L0: - r0 = 2 - x = r0 + x = 2 inc_ref x :: int a = x y = x @@ -217,41 +191,34 @@ def f(a: int) -> int: def f(a): a :: int r0 :: bool - r1, r2, r3 :: native_int - r4, r5, r6 :: bool - r7, r8 :: short_int + r1 :: native_int + r2, r3, r4 :: bool x :: int - r9 :: short_int - r10, y :: int -L0: - r1 = 1 - r2 = a & r1 - r3 = 0 - r4 = r2 == r3 - if r4 goto L1 else goto L2 :: bool + r5, y :: int +L0: + r1 = a & 1 + r2 = r1 == 0 + if r2 goto L1 else goto L2 :: bool L1: - r5 = a == a - r0 = r5 + r3 = a == a + r0 = r3 goto L3 L2: - r6 = CPyTagged_IsEq_(a, a) - r0 = r6 + r4 = CPyTagged_IsEq_(a, a) + r0 = r4 L3: if r0 goto L4 else goto L5 :: bool L4: - r7 = 2 - a = r7 + a = 2 goto L6 L5: - r8 = 4 - x = r8 + x = 4 dec_ref x :: int goto L7 L6: - r9 = 2 - r10 = CPyTagged_Add(a, r9) + r5 = CPyTagged_Add(a, 2) dec_ref a :: int - y = r10 + y = r5 return y L7: inc_ref a :: int @@ -269,40 +236,33 @@ def f(a: int) -> int: def f(a): a :: int r0 :: bool - r1, r2, r3 :: native_int - r4, r5, r6 :: bool - r7 :: short_int + r1 :: native_int + r2, r3, r4 :: bool x :: int - r8, r9 :: short_int - r10, y :: int -L0: - r1 = 1 - r2 = a & r1 - r3 = 0 - r4 = r2 == r3 - if r4 goto L1 else goto L2 :: bool + r5, y :: int +L0: + r1 = a & 1 + r2 = r1 == 0 + if r2 goto L1 else goto L2 :: bool L1: - r5 = a == a - r0 = r5 + r3 = a == a + r0 = r3 goto L3 L2: - r6 = CPyTagged_IsEq_(a, a) - r0 = r6 + r4 = CPyTagged_IsEq_(a, a) + r0 = r4 L3: if r0 goto L4 else goto L5 :: bool L4: - r7 = 4 - x = r7 + x = 4 dec_ref x :: int goto L7 L5: - r8 = 2 - a = r8 + a = 2 L6: - r9 = 2 - r10 = CPyTagged_Add(a, r9) + r5 = CPyTagged_Add(a, 2) dec_ref a :: int - y = r10 + y = r5 return y L7: inc_ref a :: int @@ -317,27 +277,23 @@ def f(a: int) -> int: def f(a): a :: int r0 :: bool - r1, r2, r3 :: native_int - r4, r5, r6 :: bool - r7 :: short_int -L0: - r1 = 1 - r2 = a & r1 - r3 = 0 - r4 = r2 == r3 - if r4 goto L1 else goto L2 :: bool + r1 :: native_int + r2, r3, r4 :: bool +L0: + r1 = a & 1 + r2 = r1 == 0 + if r2 goto L1 else goto L2 :: bool L1: - r5 = a == a - r0 = r5 + r3 = a == a + r0 = r3 goto L3 L2: - r6 = CPyTagged_IsEq_(a, a) - r0 = r6 + r4 = CPyTagged_IsEq_(a, a) + r0 = r4 L3: if r0 goto L4 else goto L6 :: bool L4: - r7 = 2 - a = r7 + a = 2 L5: return a L6: @@ -354,20 +310,18 @@ def f(a: int) -> int: [out] def f(a): a :: int - r0 :: short_int - x, r1 :: int + x, r0 :: int L0: inc_ref a :: int a = a - r0 = 2 - x = r0 + x = 2 inc_ref x :: int dec_ref x :: int x = x - r1 = CPyTagged_Add(x, a) + r0 = CPyTagged_Add(x, a) dec_ref x :: int dec_ref a :: int - return r1 + return r0 [case testIncrement1] def f(a: int) -> int: @@ -378,26 +332,20 @@ def f(a: int) -> int: [out] def f(a): a :: int - r0 :: short_int - r1 :: int - r2 :: short_int + r0 :: int x :: int - r3 :: short_int - r4, r5 :: int + r1, r2 :: int L0: - r0 = 2 - r1 = CPyTagged_Add(a, r0) - a = r1 - r2 = 2 - x = r2 - r3 = 2 - r4 = CPyTagged_Add(x, r3) + r0 = CPyTagged_Add(a, 2) + a = r0 + x = 2 + r1 = CPyTagged_Add(x, 2) dec_ref x :: int - x = r4 - r5 = CPyTagged_Add(a, x) + x = r1 + r2 = CPyTagged_Add(a, x) dec_ref a :: int dec_ref x :: int - return r5 + return r2 [case testIncrement2] def f() -> None: @@ -405,21 +353,17 @@ def f() -> None: x = x + 1 [out] def f(): - r0 :: short_int x :: int - r1 :: short_int - r2 :: int - r3 :: None + r0 :: int + r1 :: None L0: - r0 = 2 - x = r0 - r1 = 2 - r2 = CPyTagged_Add(x, r1) + x = 2 + r0 = CPyTagged_Add(x, 2) dec_ref x :: int - x = r2 + x = r0 dec_ref x :: int - r3 = None - return r3 + r1 = None + return r1 [case testAdd1] def f() -> None: @@ -427,21 +371,17 @@ def f() -> None: x = y + 1 [out] def f(): - r0 :: short_int y :: int - r1 :: short_int - r2, x :: int - r3 :: None + r0, x :: int + r1 :: None L0: - r0 = 2 - y = r0 - r1 = 2 - r2 = CPyTagged_Add(y, r1) + y = 2 + r0 = CPyTagged_Add(y, 2) dec_ref y :: int - x = r2 + x = r0 dec_ref x :: int - r3 = None - return r3 + r1 = None + return r1 [case testAdd2] def f(a: int) -> int: @@ -485,21 +425,19 @@ def f(a: int) -> None: [out] def f(a): a, r0, x :: int - r1 :: short_int - y, r2, z :: int - r3 :: None + y, r1, z :: int + r2 :: None L0: r0 = CPyTagged_Add(a, a) x = r0 dec_ref x :: int - r1 = 2 - y = r1 - r2 = CPyTagged_Add(y, y) + y = 2 + r1 = CPyTagged_Add(y, y) dec_ref y :: int - z = r2 + z = r1 dec_ref z :: int - r3 = None - return r3 + r2 = None + return r2 [case testAdd5] def f(a: int) -> None: @@ -509,21 +447,19 @@ def f(a: int) -> None: [out] def f(a): a, r0 :: int - r1 :: short_int - x, r2 :: int - r3 :: None + x, r1 :: int + r2 :: None L0: r0 = CPyTagged_Add(a, a) a = r0 dec_ref a :: int - r1 = 2 - x = r1 - r2 = CPyTagged_Add(x, x) + x = 2 + r1 = CPyTagged_Add(x, x) dec_ref x :: int - x = r2 + x = r1 dec_ref x :: int - r3 = None - return r3 + r2 = None + return r2 [case testReturnInMiddleOfFunction] def f() -> int: @@ -536,50 +472,40 @@ def f() -> int: return x + y - a [out] def f(): - r0 :: short_int x :: int - r1 :: short_int y :: int - r2 :: short_int z :: int - r3 :: bool - r4, r5, r6 :: native_int - r7, r8, r9 :: bool - r10 :: short_int - a, r11, r12 :: int -L0: - r0 = 2 - x = r0 - r1 = 4 - y = r1 - r2 = 6 - z = r2 - r4 = 1 - r5 = z & r4 - r6 = 0 - r7 = r5 == r6 - if r7 goto L1 else goto L2 :: bool + r0 :: bool + r1 :: native_int + r2, r3, r4 :: bool + a, r5, r6 :: int +L0: + x = 2 + y = 4 + z = 6 + r1 = z & 1 + r2 = r1 == 0 + if r2 goto L1 else goto L2 :: bool L1: - r8 = z == z - r3 = r8 + r3 = z == z + r0 = r3 goto L3 L2: - r9 = CPyTagged_IsEq_(z, z) - r3 = r9 + r4 = CPyTagged_IsEq_(z, z) + r0 = r4 L3: - if r3 goto L6 else goto L7 :: bool + if r0 goto L6 else goto L7 :: bool L4: return z L5: - r10 = 2 - a = r10 - r11 = CPyTagged_Add(x, y) + a = 2 + r5 = CPyTagged_Add(x, y) dec_ref x :: int dec_ref y :: int - r12 = CPyTagged_Subtract(r11, a) - dec_ref r11 :: int + r6 = CPyTagged_Subtract(r5, a) + dec_ref r5 :: int dec_ref a :: int - return r12 + return r6 L6: dec_ref x :: int dec_ref y :: int @@ -599,30 +525,24 @@ def f(a: int) -> int: [out] def f(a): a :: int - r0 :: short_int sum :: int - r1 :: short_int i :: int - r2 :: bool - r3 :: int - r4 :: short_int - r5 :: int + r0 :: bool + r1 :: int + r2 :: int L0: - r0 = 0 - sum = r0 - r1 = 0 - i = r1 + sum = 0 + i = 0 L1: - r2 = CPyTagged_IsLe(i, a) - if r2 goto L2 else goto L4 :: bool + r0 = CPyTagged_IsLe(i, a) + if r0 goto L2 else goto L4 :: bool L2: - r3 = CPyTagged_Add(sum, i) + r1 = CPyTagged_Add(sum, i) dec_ref sum :: int - sum = r3 - r4 = 2 - r5 = CPyTagged_Add(i, r4) + sum = r1 + r2 = CPyTagged_Add(i, 2) dec_ref i :: int - i = r5 + i = r2 goto L1 L3: return sum @@ -636,14 +556,12 @@ def f(a: int) -> int: [out] def f(a): a :: int - r0 :: short_int - r1, r2 :: int + r0, r1 :: int L0: - r0 = 2 - r1 = CPyTagged_Add(a, r0) - r2 = f(r1) - dec_ref r1 :: int - return r2 + r0 = CPyTagged_Add(a, 2) + r1 = f(r0) + dec_ref r0 :: int + return r1 [case testError] def f(x: List[int]) -> None: pass # E: Name 'List' is not defined \ @@ -655,20 +573,15 @@ def f() -> int: return 0 [out] def f(): - r0, r1 :: short_int - r2, r3 :: object - r4, a :: list - r5 :: short_int + r0, r1 :: object + r2, a :: list L0: - r0 = 0 - r1 = 2 - r2 = box(short_int, r0) - r3 = box(short_int, r1) - r4 = [r2, r3] - a = r4 + r0 = box(short_int, 0) + r1 = box(short_int, 2) + r2 = [r0, r1] + a = r2 dec_ref a - r5 = 0 - return r5 + return 0 [case testListSet] from typing import List @@ -677,23 +590,19 @@ def f(a: List[int], b: List[int]) -> None: [out] def f(a, b): a, b :: list - r0 :: short_int - r1 :: object - r2 :: int - r3 :: short_int - r4 :: object - r5 :: bool - r6 :: None + r0 :: object + r1 :: int + r2 :: object + r3 :: bool + r4 :: None L0: - r0 = 0 - r1 = CPyList_GetItemShort(b, r0) - r2 = unbox(int, r1) - dec_ref r1 - r3 = 0 - r4 = box(int, r2) - r5 = CPyList_SetItem(a, r3, r4) - r6 = None - return r6 + r0 = CPyList_GetItemShort(b, 0) + r1 = unbox(int, r0) + dec_ref r0 + r2 = box(int, r1) + r3 = CPyList_SetItem(a, 0, r2) + r4 = None + return r4 [case testTupleRefcount] from typing import Tuple @@ -740,22 +649,20 @@ def f() -> None: def f(): r0 :: __main__.C r1, a :: list - r2 :: short_int - r3 :: object - r4, d :: __main__.C - r5 :: None + r2 :: object + r3, d :: __main__.C + r4 :: None L0: r0 = C() r1 = [r0] a = r1 - r2 = 0 - r3 = CPyList_GetItemShort(a, r2) + r2 = CPyList_GetItemShort(a, 0) dec_ref a - r4 = cast(__main__.C, r3) - d = r4 + r3 = cast(__main__.C, r2) + d = r3 dec_ref d - r5 = None - return r5 + r4 = None + return r4 [case testUnaryBranchSpecialCase] def f(x: bool) -> int: @@ -765,15 +672,12 @@ def f(x: bool) -> int: [out] def f(x): x :: bool - r0, r1 :: short_int L0: if x goto L1 else goto L2 :: bool L1: - r0 = 2 - return r0 + return 2 L2: - r1 = 4 - return r1 + return 4 [case testUnicodeLiteral] def f() -> str: @@ -792,30 +696,26 @@ def g(x: str) -> int: [out] def g(x): x :: str - r0 :: short_int - r1 :: object - r2 :: str - r3 :: tuple - r4 :: native_int + r0 :: object + r1 :: str + r2 :: tuple + r3 :: object + r4 :: dict r5 :: object - r6 :: dict - r7 :: object - r8 :: int -L0: - r0 = 4 - r1 = int - r2 = unicode_1 :: static ('base') - r3 = (x) :: tuple - r4 = 1 - r5 = box(short_int, r0) - r6 = CPyDict_Build(r4, r2, r5) - dec_ref r5 - r7 = py_call_with_kwargs(r1, r3, r6) + r6 :: int +L0: + r0 = int + r1 = unicode_1 :: static ('base') + r2 = (x) :: tuple + r3 = box(short_int, 4) + r4 = CPyDict_Build(1, r1, r3) dec_ref r3 - dec_ref r6 - r8 = unbox(int, r7) - dec_ref r7 - return r8 + r5 = py_call_with_kwargs(r0, r2, r4) + dec_ref r2 + dec_ref r4 + r6 = unbox(int, r5) + dec_ref r5 + return r6 [case testListAppend] from typing import List @@ -846,53 +746,52 @@ def f(d: Dict[int, int]) -> None: [out] def f(d): d :: dict - r0, r1 :: short_int - r2 :: int - r3 :: object - r4 :: tuple[bool, int, object] - r5 :: int - r6 :: bool - r7 :: object - key, r8 :: int - r9, r10 :: object - r11 :: int - r12, r13 :: bool - r14 :: None + r0 :: short_int + r1 :: int + r2 :: object + r3 :: tuple[bool, int, object] + r4 :: int + r5 :: bool + r6 :: object + key, r7 :: int + r8, r9 :: object + r10 :: int + r11, r12 :: bool + r13 :: None L0: r0 = 0 - r1 = r0 - r2 = len d :: dict - r3 = CPyDict_GetKeysIter(d) + r1 = len d :: dict + r2 = CPyDict_GetKeysIter(d) L1: - r4 = CPyDict_NextKey(r3, r1) - r5 = r4[1] - r1 = r5 - r6 = r4[0] - if r6 goto L2 else goto L6 :: bool + r3 = CPyDict_NextKey(r2, r0) + r4 = r3[1] + r0 = r4 + r5 = r3[0] + if r5 goto L2 else goto L6 :: bool L2: - r7 = r4[2] - dec_ref r4 - r8 = unbox(int, r7) - dec_ref r7 - key = r8 - r9 = box(int, key) - r10 = CPyDict_GetItem(d, r9) + r6 = r3[2] + dec_ref r3 + r7 = unbox(int, r6) + dec_ref r6 + key = r7 + r8 = box(int, key) + r9 = CPyDict_GetItem(d, r8) + dec_ref r8 + r10 = unbox(int, r9) dec_ref r9 - r11 = unbox(int, r10) - dec_ref r10 - dec_ref r11 :: int + dec_ref r10 :: int L3: - r12 = CPyDict_CheckSize(d, r2) + r11 = CPyDict_CheckSize(d, r1) goto L1 L4: - r13 = CPy_NoErrOccured() + r12 = CPy_NoErrOccured() L5: - r14 = None - return r14 + r13 = None + return r13 L6: - dec_ref r2 :: int + dec_ref r1 :: int + dec_ref r2 dec_ref r3 - dec_ref r4 goto L4 [case testBorrowRefs] diff --git a/mypyc/test/test_emitfunc.py b/mypyc/test/test_emitfunc.py index ab8bd816b923..9d4702146113 100644 --- a/mypyc/test/test_emitfunc.py +++ b/mypyc/test/test_emitfunc.py @@ -81,9 +81,9 @@ def test_return(self) -> None: def test_load_int(self) -> None: self.assert_emit(LoadInt(5), - "cpy_r_r0 = 10;") + "cpy_r_i0 = 10;") self.assert_emit(LoadInt(5, -1, c_int_rprimitive), - "cpy_r_r00 = 5;") + "cpy_r_i1 = 5;") def test_tuple_get(self) -> None: self.assert_emit(TupleGet(self.t, 1, 0), 'cpy_r_r0 = cpy_r_t.f1;') @@ -354,9 +354,9 @@ def test_register(self) -> None: assert_string_arrays_equal( [ 'PyObject *CPyDef_myfunc(CPyTagged cpy_r_arg) {\n', - ' CPyTagged cpy_r_r0;\n', + ' CPyTagged cpy_r_i0;\n', 'CPyL0: ;\n', - ' cpy_r_r0 = 10;\n', + ' cpy_r_i0 = 10;\n', '}\n', ], result, msg='Generated code invalid')