[Mlir-commits] [mlir] 426374e - [MLIR][Python] Ignore the returned status of `loadDialectModule` in lookup functions (#179609)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Feb 3 23:25:12 PST 2026


Author: Twice
Date: 2026-02-04T15:25:07+08:00
New Revision: 426374ed120763d83691e76342db82de056b9063

URL: https://github.com/llvm/llvm-project/commit/426374ed120763d83691e76342db82de056b9063
DIFF: https://github.com/llvm/llvm-project/commit/426374ed120763d83691e76342db82de056b9063.diff

LOG: [MLIR][Python] Ignore the returned status of `loadDialectModule` in lookup functions (#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. It's also 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#L163-L166


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

Added: 
    

Modified: 
    mlir/lib/Bindings/Python/Globals.cpp

Removed: 
    


################################################################################
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