From e1c0c371b038c12e5c9d5b80ec517d3aeea890e7 Mon Sep 17 00:00:00 2001 From: Guilherme Leobas Date: Tue, 14 Mar 2023 12:03:11 -0300 Subject: [PATCH] restore dynamic exceptions lowering code --- numba/core/lowering.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/numba/core/lowering.py b/numba/core/lowering.py index 7ade50275ec..62672dc087e 100644 --- a/numba/core/lowering.py +++ b/numba/core/lowering.py @@ -140,6 +140,12 @@ def post_block(self, block): Called after lowering a block. """ + def return_dynamic_exception(self, exc_class, exc_args, nb_types, loc=None): + self.call_conv.return_dynamic_user_exc( + self.builder, exc_class, exc_args, nb_types, + loc=loc, func_name=self.func_ir.func_id.func_name, + ) + def return_exception(self, exc_class, exc_args=None, loc=None): """Propagate exception to the caller. """ @@ -557,6 +563,9 @@ def lower_inst(self, inst): return impl(self.builder, (target, value)) + elif isinstance(inst, ir.DynamicRaise): + self.lower_dynamic_raise(inst) + elif isinstance(inst, ir.StaticRaise): self.lower_static_raise(inst) @@ -597,6 +606,25 @@ def lower_setitem(self, target_var, index_var, value_var, signature): return impl(self.builder, (target, index, value)) + def lower_dynamic_raise(self, inst): + exc_args = inst.exc_args + args = [] + nb_types = [] + for exc_arg in exc_args: + if isinstance(exc_arg, ir.Var): + # dynamic values + typ = self.typeof(exc_arg.name) + val = self.loadvar(exc_arg.name) + self.incref(typ, val) + else: + typ = None + val = exc_arg + nb_types.append(typ) + args.append(val) + + self.return_dynamic_exception(inst.exc_class, tuple(args), + tuple(nb_types), loc=self.loc) + def lower_static_raise(self, inst): if inst.exc_class is None: # Reraise