lower_constant
and lower_cast
should probably return new references
#4494
Labels
lower_constant
and lower_cast
should probably return new references
#4494
Feature request
Currently
@lower_constant
and@lower_cast
expect the implementation to return borrowed references. This makes it tricky to implement lowering constants and casts for memory managed types as you cannot just use native constructors (if available). For casting there might even be edge cases that cannot be implemented at all (#3492).It would be great if the following naive implementation strategy for lowering constants and casts worked. Assume we have an existing (maybe memory managed) Numba type
AType
and a new extension typeBType
with a native constuctorB(a: A)
.Lowering a constant
B
might look like:Casting
AType
toBType
could be implemented likeWithe the current refcounting conventions the implementations above will leak memory. In some cases you can avoid the memory leak by punting on the refcount pruning pass and simply call
context.nrt.decref
on the result ofcompile_internal
. However, this will not work in general (for example casting tuples will not work) and crash the interpreter.The text was updated successfully, but these errors were encountered: