[Mlir-commits] [mlir] [tblgen] Use `emitError` for inferResultTypes failures (PR #165488)
Stef Lindall
llvmlistbot at llvm.org
Tue Oct 28 16:07:53 PDT 2025
https://github.com/bethebunny updated https://github.com/llvm/llvm-project/pull/165488
>From 30a2fff5dd095a9636da78c84743d1d2dc9db549 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/test/mlir-tblgen/op-decl-and-defs.td | 2 +-
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp | 2 +-
4 files changed, 12 insertions(+), 16 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/test/mlir-tblgen/op-decl-and-defs.td b/mlir/test/mlir-tblgen/op-decl-and-defs.td
index 87b41f9dea995..30b0915d14423 100644
--- a/mlir/test/mlir-tblgen/op-decl-and-defs.td
+++ b/mlir/test/mlir-tblgen/op-decl-and-defs.td
@@ -232,7 +232,7 @@ def NS_FOp : NS_Op<"op_with_all_types_constraint",
// DEFS: void FOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Value a) {
// DEFS: if (::mlir::succeeded(FOp::inferReturnTypes(odsBuilder.getContext(),
// DEFS: else
-// DEFS: ::mlir::detail::reportFatalInferReturnTypesError(odsState);
+// DEFS: ::mlir::detail::emitInferReturnTypesError(odsState);
// DEFS: FOp FOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Value a) {
// DEFS: ::mlir::OperationState __state__(location, getOperationName());
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