I’m not super familiar with the C bindings, but I’m learning more. Right now, I’m looking at the C-API’s accessors for dialect objects, it looks like mlir/CAPI/Registration.h provides a MLIR_DEFINE_CAPI_DIALECT_REGISTRATION macro that allows dialects to opt-in to the C bindings.
Is there a way to get a MlirDialectHandle for not-explicitly registered dialects? Notably, the builtin dialect isn’t explicitly registered, which makes it a special case. Also, it does seem useful to be able to look up dialects by name when they’re already loaded into a context.
Are there others? If just builtin, which is already special, then maybe we just add a special accessor for it.
There has been a design tension between less scaffolding/more name based/automatic interfaces to dialects and minimal/explicit.
I’m responsible for that macro (and, even if you don’t remember, you reviewed the change iirc ). I had intended a more comprehensive setup at some point, including just having ODS do the right thing – but something was needed for bootstrapping. I doubt 5 years from now, we’ll be hand coding all of these accessors, but I don’t have an immediately better idea at the moment.
This looks technically possible. The handle is just a pointer to a struct, which itself has pointers to the dialect constructor, namespace getter, etc. It can be set up without registering the dialect with the context. But the dialect needs to provide some code to do that. In C++, this is handled by passing the dialect class as a template argument, but it needs to be either a macro or a manually declared function in C.
It is already possible to get a dialect by namespace using mlirContextGetOrLoadDialect.