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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
From: Siu Kwan Lam <1929845+sklam@users.noreply.github.com>
Origin: https://github.com/numba/numba/pull/8545
Date: Wed, 26 Oct 2022 15:53:07 -0500
Subject: Unbreak python <3.11
---
numba/core/byteflow.py | 105 ++++++++++++++++++++++++++--------------
numba/core/runtime/context.py | 6 ++-
numba/tests/test_withlifting.py | 4 --
3 files changed, 73 insertions(+), 42 deletions(-)
diff --git a/numba/core/byteflow.py b/numba/core/byteflow.py
index 5a49f99..674fa0e 100644
--- a/numba/core/byteflow.py
+++ b/numba/core/byteflow.py
@@ -777,22 +777,43 @@ class TraceRunner(object):
state.append(inst, value=val, res=res)
state.push(res)
- def op_RAISE_VARARGS(self, state, inst):
- if inst.arg == 0:
- exc = None
- raise UnsupportedError(
- "The re-raising of an exception is not yet supported.",
- loc=self.get_debug_loc(inst.lineno),
- )
- elif inst.arg == 1:
- exc = state.pop()
- else:
- raise ValueError("Multiple argument raise is not supported.")
- state.append(inst, exc=exc)
+ if PYVERSION >= (3, 11):
+ def op_RAISE_VARARGS(self, state, inst):
+ if inst.arg == 0:
+ exc = None
+ raise UnsupportedError(
+ "The re-raising of an exception is not yet supported.",
+ loc=self.get_debug_loc(inst.lineno),
+ )
+ elif inst.arg == 1:
+ exc = state.pop()
+ else:
+ raise ValueError("Multiple argument raise is not supported.")
+ state.append(inst, exc=exc)
- if state.has_active_try():
- self.handle_try(state)
- else:
+ if state.has_active_try():
+ self.handle_try(state)
+ else:
+ state.terminate()
+
+ else:
+ def op_RAISE_VARARGS(self, state, inst):
+ in_exc_block = any([
+ state.get_top_block("EXCEPT") is not None,
+ state.get_top_block("FINALLY") is not None
+ ])
+ if inst.arg == 0:
+ exc = None
+ if in_exc_block:
+ raise UnsupportedError(
+ "The re-raising of an exception is not yet supported.",
+ loc=self.get_debug_loc(inst.lineno),
+ )
+ elif inst.arg == 1:
+ exc = state.pop()
+ else:
+ raise ValueError("Multiple argument raise is not supported.")
+ state.append(inst, exc=exc)
state.terminate()
def op_BEGIN_FINALLY(self, state, inst):
@@ -903,6 +924,8 @@ class TraceRunner(object):
end=None,
reset_stack=False,
)
+ # Forces a new block
+ # Fork to the body of the finally
state.fork(
pc=next,
extra_block=state.make_block(
@@ -931,11 +954,12 @@ class TraceRunner(object):
'FINALLY', state, next=inst.next, end=inst.get_jump_target(),
)
- def op_POP_EXCEPT(self, state, inst):
- if PYVERSION == (3, 11):
+ if PYVERSION >= (3, 11):
+ def op_POP_EXCEPT(self, state, inst):
state.pop()
- else:
+ else:
+ def op_POP_EXCEPT(self, state, inst):
blk = state.pop_block()
if blk['kind'] not in {BlockKind('EXCEPT'), BlockKind('FINALLY')}:
raise UnsupportedError(
@@ -1379,22 +1403,30 @@ class TraceRunner(object):
state.fork(pc=inst.next)
state.fork(pc=inst.get_jump_target())
- def op_RERAISE(self, state, inst):
- # This isn't handled, but the state is set up anyway
- exc = state.pop()
- if inst.arg != 0:
- state.pop() # lasti
- state.append(inst, exc=exc)
+ if PYVERSION >= (3, 11):
+ def op_RERAISE(self, state, inst):
+ # This isn't handled, but the state is set up anyway
+ exc = state.pop()
+ if inst.arg != 0:
+ state.pop() # lasti
+ state.append(inst, exc=exc)
- if state.has_active_try():
- self.handle_try(state)
- else:
+ if state.has_active_try():
+ self.handle_try(state)
+ else:
+ state.terminate()
+ else:
+ def op_RERAISE(self, state, inst):
+ # This isn't handled, but the state is set up anyway
+ exc = state.pop()
+ state.append(inst, exc=exc)
state.terminate()
+
# NOTE: Please see notes in `interpreter.py` surrounding the implementation
# of LOAD_METHOD and CALL_METHOD.
- if PYVERSION == (3, 11):
+ if PYVERSION >= (3, 11):
def op_LOAD_METHOD(self, state, inst):
item = state.pop()
extra = state.make_null()
@@ -1665,14 +1697,15 @@ class State(object):
stack.append(self.make_temp())
# Handle changes on the blockstack
blockstack = list(self._blockstack)
- # pop expired block in destination pc
- while blockstack:
- top = blockstack[-1]
- end = top.get('end_offset') or top['end']
- if pc >= end:
- blockstack.pop()
- else:
- break
+ if PYVERSION >= (3, 11):
+ # pop expired block in destination pc
+ while blockstack:
+ top = blockstack[-1]
+ end = top.get('end_offset') or top['end']
+ if pc >= end:
+ blockstack.pop()
+ else:
+ break
if extra_block:
blockstack.append(extra_block)
diff --git a/numba/core/runtime/context.py b/numba/core/runtime/context.py
index a58d4df..1c01fac 100644
--- a/numba/core/runtime/context.py
+++ b/numba/core/runtime/context.py
@@ -3,6 +3,7 @@ import functools
from llvmlite import ir
from numba.core import types, cgutils, errors
+from numba.core.utils import PYVERSION
class NRTContext(object):
@@ -382,8 +383,9 @@ class NRTContext(object):
trystatus = cc.check_try_status(builder)
excinfo = trystatus.excinfo
has_raised = builder.not_(cgutils.is_null(builder, excinfo))
- # with builder.if_then(has_raised):
- # self.eh_end_try(builder)
+ if PYVERSION < (3, 11):
+ with builder.if_then(has_raised):
+ self.eh_end_try(builder)
return has_raised
def eh_try(self, builder):
diff --git a/numba/tests/test_withlifting.py b/numba/tests/test_withlifting.py
index e72d2d3..e2d9051 100644
--- a/numba/tests/test_withlifting.py
+++ b/numba/tests/test_withlifting.py
@@ -1193,8 +1193,6 @@ class TestBogusContext(BaseTestWithLifting):
)
def test_invalid(self):
- import dis
- dis.dis(lift_invalid)
the_ir = get_func_ir(lift_invalid)
with self.assertRaises(errors.CompilerError) as raises:
@@ -1212,8 +1210,6 @@ class TestBogusContext(BaseTestWithLifting):
with open('') as f:
pass
- import dis
- dis.dis(foo)
with self.assertRaises(errors.UnsupportedError) as raises:
foo()
|