[Mlir-commits] [mlir] [MLIR][Python] Make location optional in Python-defined dialect loading (PR #186172)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Mar 12 09:35:57 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Twice (PragmaTwice)
<details>
<summary>Changes</summary>
Now we need to provide a location when call `load()`, e.g.
```python
with Context(), Location.unknown():
MyDialect.load()
```
But it's actually weird: IRDL is just an implementation details, so for users they don't know why they need to provide a location for loading a dialect, which is unrelated to constructing an IR module.
---
Full diff: https://github.com/llvm/llvm-project/pull/186172.diff
1 Files Affected:
- (modified) mlir/python/mlir/dialects/ext.py (+5-3)
``````````diff
diff --git a/mlir/python/mlir/dialects/ext.py b/mlir/python/mlir/dialects/ext.py
index 5bcc595220f69..15651a1c4e858 100644
--- a/mlir/python/mlir/dialects/ext.py
+++ b/mlir/python/mlir/dialects/ext.py
@@ -22,6 +22,7 @@
from ._ods_common import _cext, segmented_accessor
from .irdl import Variadicity
from ..passmanager import PassManager
+from contextlib import nullcontext
ir = _cext.ir
@@ -804,9 +805,10 @@ def _emit_dialect(cls) -> None:
@classmethod
def _emit_module(cls) -> ir.Module:
- m = ir.Module.create()
- with ir.InsertionPoint(m.body):
- cls._emit_dialect()
+ with ir.Location.unknown() if not ir.Location.current else nullcontext():
+ m = ir.Module.create()
+ with ir.InsertionPoint(m.body):
+ cls._emit_dialect()
return m
``````````
</details>
https://github.com/llvm/llvm-project/pull/186172
More information about the Mlir-commits
mailing list