[Mlir-commits] [mlir] [MLIR][Python] Extend bindings for external projects without duplication (PR #173241)
Maksim Levental
llvmlistbot at llvm.org
Tue Dec 23 08:33:38 PST 2025
makslevental wrote:
Sorry I just noticed you add a python snippet:
```python
from mlir.ir import *
from mlir_sdist import dialects as sdist_dialects
with Context() as ctx:
sdist_dialects.register_dialects(ctx)
module = Module.parse("""
%0 = arith.constant 0 : i32
sdist_utils.hello
""")
# CHECK: sdist_utils.hello
print(str(module))
```
If this is working for you then it's purely luck because if `mlir_sdist` links against `SDistPythonCAPI` then it's linking against a completely separate `MLIRCAPIR` and etc and so you're just lucky [`register_dialects` doesn't use any state](https://github.com/llvm/llvm-project/blob/97fc5682112d019230a3ab23cced3bdf093f6094/mlir/lib/CAPI/IR/DialectHandle.cpp#L25-L30) in `SDistPythonCAPI`. Plenty of other APIs [aren't so lucky](https://github.com/llvm/llvm-project/blob/7c4e8c6a273f25b3ef33e9c123b3969632ab59bb/mlir/lib/CAPI/RegisterEverything/RegisterEverything.cpp#L32).
https://github.com/llvm/llvm-project/pull/173241
More information about the Mlir-commits
mailing list