[Mlir-commits] [mlir] [MLIR][Python] Make Python-defined dialect loading context-aware (PR #210501)

Renato Golin llvmlistbot at llvm.org
Thu Jul 23 03:57:25 PDT 2026


================
@@ -957,18 +957,11 @@ def _emit_module(cls) -> ir.Module:
         return m
 
     @classmethod
-    def load(
-        cls,
-        *,
-        reload: bool = False,
-    ) -> None:
-        if hasattr(cls, "_mlir_module") and not reload:
-            if cls._mlir_module.context is not ir.Context.current:
-                raise RuntimeError(
-                    "This dialect was loaded in a different context. "
-                    "Please set reload=True to reload the dialect in the current context."
-                )
-            return
+    def load(cls) -> None:
+        if ir.Context.current.is_dialect_loaded(cls.DIALECT_NAMESPACE):
+            raise RuntimeError(
----------------
rengolin wrote:

I think the main problem here is that in C++ dialects are static at runtime, so doing this would not make sense (or would always be a noop). If there's a way to detect if the dialect has changed since (some boolean flag that sets to true when loaded and false when changed), then we can reserve the assertion above to only when the flag is false (ie. dialect changed and tried to reload).

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


More information about the Mlir-commits mailing list