[Mlir-commits] [mlir] [mlir][python] make loading dialect module (for type and value casting) best effort only (PR #72338)

Maksim Levental llvmlistbot at llvm.org
Wed Nov 15 00:33:33 PST 2023


makslevental wrote:

I propose we remove eager dialect module loading from `lookupTypeCaster` and `lookupValueCaster` entirely. I don't remember who it was that asked for that kind of safety but IMHO if you want type casting to your own dialect's types, it's not unreasonable to ask you to first register those type casters - whether that be by importing a python module that performs the registration using the decorator syntax, or importing the C extension module that implements `mlir_type_subclass`. I don't think an explicit import if you want to avail yourself of type casting to a type in your dialect is an excessive complexity/boilerplate burden. And it's failsafe - if the type/value caster isn't registered then nbd - the corresponding map (`typeCasterMap`, `valueCasterMap`) will not hit and default types (`ir.Type`) will be returned. **But note:** `builtin` types and attributes _will_ be cast successfully (because casters for `builtin` are registered in the pybind code itself). The current PR commit implements this proposal.

https://github.com/llvm/llvm-project/pull/72338


More information about the Mlir-commits mailing list