Hello Numba developers. I’m hoping to get an explanation of how
mangling_args works for types with parameters. I have a Numba class that depends on parameters which I’m currently just putting in the name. However, because my name may end up in the IR, I want to omit these parameters if possible to reduce the lowering time.
I see that Type defines
mangling_args, which takes parameters instead, but I’m curious about how exactly it works. How are the parameters used exactly? If the parameters are different does this ensure lowering will pick up the correct function based on the parameters? If parameters are large do these appear in the final IR or is there some compression occurring?
The responsibility of
mangling_args is to return information that will correctly identify different instances of the
types.Type. If we use a C++ template type as example,
MyType<int, float> should return
("MyType", (types.int32, types.float32)). That provides enough information to identify the instantiation of the
In Numba code, the
Tuple.mangling_args source code is a good example.
The result of
mangling_args is used by the symbol mangler (see source):
In : from numba import types
In : from numba.core.itanium_mangler import mangle_type_or_value
In : t=types.Tuple.from_types([types.int32, types.float32])
In : mangle_type_or_value(t)
The resulting string is used as part of the final symbol name. A function
foo that takes
t might have symbol name like
c++filt will demangles into
mangling_args returns the same information for different instances of the type, I would expect LLVM to fail because of symbol collision whenever it loads object-files with the same symbol name into memory.
If you have a type with a lot of type-parameters, you might want to consider doing some compression/substitution inside
mangling_args. Currently, no compression is performed by the mangler in Numba.