[Mlir-commits] [mlir] [MLIR][Python] Ignore the returned status of dialect module loading in lookup functions (PR #179609)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Feb 3 21:29:16 PST 2026


https://github.com/PragmaTwice created https://github.com/llvm/llvm-project/pull/179609

Since `loadDialectModule` doesn't work for Python-defined dialects (`mlir.dialects.ext`), currently we should lookup for dialect/operation/opadaptor class even if the `loadDialectModule` function fails. Because users can import some modules manually, and we do already ignore it in some cases:
https://github.com/llvm/llvm-project/blob/e2061328a8ae51cdf80e211ad27dd13d7bba766d/mlir/lib/Bindings/Python/Globals.cpp#L166


Related to https://github.com/llvm/llvm-project/pull/176920#discussion_r2762029022.

>From c46baaa968aa0b16cae012a4d1ba22ff6f57020a Mon Sep 17 00:00:00 2001
From: Twice <twice at apache.org>
Date: Wed, 4 Feb 2026 13:24:14 +0800
Subject: [PATCH] [MLIR][Python] Ignore the returned status of dialect module
 loading in lookup functions

---
 mlir/lib/Bindings/Python/Globals.cpp | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/mlir/lib/Bindings/Python/Globals.cpp b/mlir/lib/Bindings/Python/Globals.cpp
index 3d7ee3d30656e..eb31bc29021ff 100644
--- a/mlir/lib/Bindings/Python/Globals.cpp
+++ b/mlir/lib/Bindings/Python/Globals.cpp
@@ -189,8 +189,8 @@ std::optional<nb::callable> PyGlobals::lookupValueCaster(MlirTypeID mlirTypeID,
 std::optional<nb::object>
 PyGlobals::lookupDialectClass(const std::string &dialectNamespace) {
   // Make sure dialect module is loaded.
-  if (!loadDialectModule(dialectNamespace))
-    return std::nullopt;
+  (void)loadDialectModule(dialectNamespace);
+
   nb::ft_lock_guard lock(mutex);
   const auto foundIt = dialectClassMap.find(dialectNamespace);
   if (foundIt != dialectClassMap.end()) {
@@ -206,8 +206,7 @@ PyGlobals::lookupOperationClass(llvm::StringRef operationName) {
   // Make sure dialect module is loaded.
   auto split = operationName.split('.');
   llvm::StringRef dialectNamespace = split.first;
-  if (!loadDialectModule(dialectNamespace))
-    return std::nullopt;
+  (void)loadDialectModule(dialectNamespace);
 
   nb::ft_lock_guard lock(mutex);
   auto foundIt = operationClassMap.find(operationName);
@@ -224,8 +223,7 @@ PyGlobals::lookupOpAdaptorClass(llvm::StringRef operationName) {
   // Make sure dialect module is loaded.
   auto split = operationName.split('.');
   llvm::StringRef dialectNamespace = split.first;
-  if (!loadDialectModule(dialectNamespace))
-    return std::nullopt;
+  (void)loadDialectModule(dialectNamespace);
 
   nb::ft_lock_guard lock(mutex);
   auto foundIt = opAdaptorClassMap.find(operationName);



More information about the Mlir-commits mailing list