Skip to content

Commit

Permalink
restore dynamic exceptions lowering code
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermeleobas committed Mar 14, 2023
1 parent 66a683b commit e1c0c37
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions numba/core/lowering.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e1c0c37

Please sign in to comment.