1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
From: Siu Kwan Lam <1929845+sklam@users.noreply.github.com>
Origin: https://github.com/numba/numba/pull/8545
Date: Tue, 29 Nov 2022 18:58:38 -0600
Subject: Address reviews on byteflow.py
---
numba/core/byteflow.py | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/numba/core/byteflow.py b/numba/core/byteflow.py
index eeddb19..e16d4e0 100644
--- a/numba/core/byteflow.py
+++ b/numba/core/byteflow.py
@@ -142,7 +142,7 @@ class Flow(object):
state.get_inst().opname not in _NO_RAISE_OPS):
# Is in a *try* block
state.fork(pc=state.get_inst().next)
- runner.handle_try(state)
+ runner._adjust_except_stack(state)
return True
else:
state.advance_pc()
@@ -335,14 +335,20 @@ class TraceRunner(object):
msg = "Use of unsupported opcode (%s) found" % inst.opname
raise UnsupportedError(msg, loc=self.get_debug_loc(inst.lineno))
- def handle_try(self, state):
+ def _adjust_except_stack(self, state):
+ """
+ Adjust stack when entering an exception handler to match expectation
+ by the bytecode.
+ """
tryblk = state.get_top_block('TRY')
state.pop_block_and_above(tryblk)
nstack = state.stack_depth
kwargs = {}
expected_depth = tryblk['stack_depth']
if nstack > expected_depth:
+ # Pop extra item in the stack
kwargs['npop'] = nstack - expected_depth
+ # Set extra stack itemcount due to the exception values.
extra_stack = 1
if tryblk['push_lasti']:
extra_stack += 1
@@ -367,8 +373,8 @@ class TraceRunner(object):
def op_RETURN_GENERATOR(self, state, inst):
# This impl doesn't follow what CPython does. CPython is hacking
- # the frame stack in the interpreter. We cannot. From usage, it always
- # have a POP_TOP after it so we push a dummy value to the stack.
+ # the frame stack in the interpreter. From usage, it always
+ # has a POP_TOP after it so we push a dummy value to the stack.
#
# Example bytecode:
# > 0 NOP(arg=None, lineno=80)
@@ -791,7 +797,7 @@ class TraceRunner(object):
state.append(inst, exc=exc)
if state.has_active_try():
- self.handle_try(state)
+ self._adjust_except_stack(state)
else:
state.terminate()
@@ -1265,7 +1271,7 @@ class TraceRunner(object):
op = dis._nb_ops[inst.arg][1]
rhs = state.pop()
lhs = state.pop()
- res = state.make_temp()
+ res = state.make_temp(prefix=f"binop_{op}")
state.append(inst, op=op, lhs=lhs, rhs=rhs, res=res)
state.push(res)
@@ -1413,7 +1419,7 @@ class TraceRunner(object):
state.append(inst, exc=exc)
if state.has_active_try():
- self.handle_try(state)
+ self._adjust_except_stack(state)
else:
state.terminate()
else:
|