[Mlir-commits] [mlir] [MLIR][Python][Transform] Print diagnostics also upon success (PR #172188)

Rolf Morel llvmlistbot at llvm.org
Sat Dec 13 16:16:28 PST 2025


https://github.com/rolfmorel created https://github.com/llvm/llvm-project/pull/172188

If we do not collect the diagnostics from the
CollectDiagnosticsToStringScope, even when the named_sequence applied successfully, the Scope object's destructor will assert (with a unhelpful message).

>From 91580d24723b48618d24e593fe72ef7fd934069c Mon Sep 17 00:00:00 2001
From: Rolf Morel <rolf.morel at intel.com>
Date: Sat, 13 Dec 2025 16:10:38 -0800
Subject: [PATCH] [MLIR][Python][Transform] Print diagnostics also upon success

If we do not collect the diagnostics from the
CollectDiagnosticsToStringScope, even when the named_sequence applied
successfully, the Scope object's destructor will assert (with a
unhelpful message).
---
 mlir/lib/Bindings/Python/TransformInterpreter.cpp | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/mlir/lib/Bindings/Python/TransformInterpreter.cpp b/mlir/lib/Bindings/Python/TransformInterpreter.cpp
index 920bca886f617..9e1eb37a816f6 100644
--- a/mlir/lib/Bindings/Python/TransformInterpreter.cpp
+++ b/mlir/lib/Bindings/Python/TransformInterpreter.cpp
@@ -14,8 +14,8 @@
 #include "mlir-c/IR.h"
 #include "mlir-c/Support.h"
 #include "mlir/Bindings/Python/Diagnostics.h"
-#include "mlir/Bindings/Python/NanobindAdaptors.h"
 #include "mlir/Bindings/Python/Nanobind.h"
+#include "mlir/Bindings/Python/NanobindAdaptors.h"
 
 namespace nb = nanobind;
 
@@ -70,8 +70,17 @@ static void populateTransformInterpreterSubmodule(nb::module_ &m) {
 
         MlirLogicalResult result = mlirTransformApplyNamedSequence(
             payloadRoot, transformRoot, transformModule, options.options);
-        if (mlirLogicalResultIsSuccess(result))
+        if (mlirLogicalResultIsSuccess(result)) {
+          // Even in cases of success, we might have diagnostics to report:
+          std::string msg;
+          if ((msg = scope.takeMessage()).size() > 0) {
+            fprintf(stderr,
+                    "Diagnostic generated while applying "
+                    "transform.named_sequence:\n%s",
+                    msg.data());
+          }
           return;
+        }
 
         throw nb::value_error(
             ("Failed to apply named transform sequence.\nDiagnostic message " +



More information about the Mlir-commits mailing list