[Mlir-commits] [mlir] [tblgen] Use `emitError` for inferResultTypes failures (PR #165488)
Stef Lindall
llvmlistbot at llvm.org
Tue Oct 28 16:06:14 PDT 2025
https://github.com/bethebunny created https://github.com/llvm/llvm-project/pull/165488
Tablegen builders generated for InferTypeOpTrait currently generate a call to `llvm::report_fatal_error`. This prevents error recovery even though the underlying machinery, including the generic builder, support failing result type inference.
This PR updates `reportFatalInferReturnTypesError` -> `emitInferReturnTypesError`, using `mlir::emitError()` instead of `llvm::report_fatal_error`, and then updates `OpDefinitionsGen` to use this function.
>From 3dfbedda08ad48890349668318a3c93c7b8c0382 Mon Sep 17 00:00:00 2001
From: Stef Lindall <stef at modular.com>
Date: Tue, 28 Oct 2025 10:43:38 -0700
Subject: [PATCH] [tblgen] Use `emitError` for inferResultTypes failures
---
.../mlir/Interfaces/InferTypeOpInterface.h | 5 ++---
mlir/lib/Interfaces/InferTypeOpInterface.cpp | 19 ++++++++-----------
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp | 2 +-
3 files changed, 11 insertions(+), 15 deletions(-)
diff --git a/mlir/include/mlir/Interfaces/InferTypeOpInterface.h b/mlir/include/mlir/Interfaces/InferTypeOpInterface.h
index 4fcbeff9df560..3cae45e17a15b 100644
--- a/mlir/include/mlir/Interfaces/InferTypeOpInterface.h
+++ b/mlir/include/mlir/Interfaces/InferTypeOpInterface.h
@@ -245,9 +245,8 @@ inferReturnTensorTypes(ArrayRef<ShapedTypeComponents> retComponents,
/// the op. Precondition: op implements InferTypeOpInterface.
LogicalResult verifyInferredResultTypes(Operation *op);
-/// Report a fatal error indicating that the result types could not be
-/// inferred.
-void reportFatalInferReturnTypesError(OperationState &state);
+/// Report an error indicating that the result types could not be inferred.
+void emitInferReturnTypesError(OperationState &state);
} // namespace detail
namespace OpTrait {
diff --git a/mlir/lib/Interfaces/InferTypeOpInterface.cpp b/mlir/lib/Interfaces/InferTypeOpInterface.cpp
index 9f4f672fb9f4d..add0101f226d7 100644
--- a/mlir/lib/Interfaces/InferTypeOpInterface.cpp
+++ b/mlir/lib/Interfaces/InferTypeOpInterface.cpp
@@ -240,15 +240,12 @@ LogicalResult mlir::detail::verifyInferredResultTypes(Operation *op) {
return result;
}
-void mlir::detail::reportFatalInferReturnTypesError(OperationState &state) {
- std::string buffer;
- llvm::raw_string_ostream os(buffer);
- os << "Failed to infer result type(s):\n"
- << "\"" << state.name << "\"(...) "
- << state.attributes.getDictionary(state.location.getContext()) << " : ("
- << llvm::interleaved(llvm::map_range(
- state.operands, [](Value val) { return val.getType(); }))
- << ") -> ( ??? )";
- emitRemark(state.location, "location of op");
- llvm::report_fatal_error(llvm::StringRef(buffer));
+void mlir::detail::emitInferReturnTypesError(OperationState &state) {
+ mlir::emitError(state.location)
+ << "Failed to infer result type(s):\n"
+ << "\"" << state.name << "\"(...) "
+ << state.attributes.getDictionary(state.location.getContext()) << " : ("
+ << llvm::interleaved(llvm::map_range(
+ state.operands, [](Value val) { return val.getType(); }))
+ << ") -> ( ??? )";
}
diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index 371864830a3c1..d75261186f45a 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -2681,7 +2681,7 @@ void OpEmitter::genSeparateArgParamBuilder() {
{1}.regions, inferredReturnTypes)))
{1}.addTypes(inferredReturnTypes);
else
- ::mlir::detail::reportFatalInferReturnTypesError({1});
+ ::mlir::detail::emitInferReturnTypesError({1});
)",
opClass.getClassName(), builderOpState);
return;
More information about the Mlir-commits
mailing list