[Mlir-commits] [mlir] 2a30bfc - [mlir] Improve error message when number of operands and types differ (#118488)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Dec 4 00:36:08 PST 2024
Author: Markus Böck
Date: 2024-12-04T09:36:05+01:00
New Revision: 2a30bfcef368667247ebbe30be84f73b92dbe800
URL: https://github.com/llvm/llvm-project/commit/2a30bfcef368667247ebbe30be84f73b92dbe800
DIFF: https://github.com/llvm/llvm-project/commit/2a30bfcef368667247ebbe30be84f73b92dbe800.diff
LOG: [mlir] Improve error message when number of operands and types differ (#118488)
If using a variadic operand, the error message given if the number of
types and operands do not match would be along the lines of:
```
3 operands present, but expected 2
```
This error message is confusing for multiple reasons, particular for
beginners:
* If the intention is to have 3 operands, it does not point out why it
expects 2. The user may actually just want to add a type to the type
list
* It reads as if a verifier error rather than a parser error, giving the
impression the Op only supports 2 operands.
This PR attempts to improve the error message by first noting the issue
("number of operands and types mismatch") and mentioning how many
operands and types it received.
Added:
Modified:
mlir/include/mlir/IR/OpImplementation.h
mlir/test/Dialect/LLVMIR/invalid.mlir
mlir/test/Dialect/Linalg/transform-ops-invalid.mlir
mlir/test/Dialect/SCF/invalid.mlir
mlir/test/Dialect/SPIRV/IR/memory-ops.mlir
mlir/test/Dialect/Tensor/invalid.mlir
mlir/test/Dialect/Vector/invalid.mlir
Removed:
################################################################################
diff --git a/mlir/include/mlir/IR/OpImplementation.h b/mlir/include/mlir/IR/OpImplementation.h
index a7222794f320b2..6c1ff4d0e5e6b9 100644
--- a/mlir/include/mlir/IR/OpImplementation.h
+++ b/mlir/include/mlir/IR/OpImplementation.h
@@ -1604,7 +1604,8 @@ class OpAsmParser : public AsmParser {
size_t typeSize = llvm::range_size(types);
if (operandSize != typeSize)
return emitError(loc)
- << operandSize << " operands present, but expected " << typeSize;
+ << "number of operands and types do not match: got " << operandSize
+ << " operands and " << typeSize << " types";
for (auto [operand, type] : llvm::zip_equal(operands, types))
if (resolveOperand(operand, type, result))
diff --git a/mlir/test/Dialect/LLVMIR/invalid.mlir b/mlir/test/Dialect/LLVMIR/invalid.mlir
index 5677d7ff41202f..25806d9d0edd72 100644
--- a/mlir/test/Dialect/LLVMIR/invalid.mlir
+++ b/mlir/test/Dialect/LLVMIR/invalid.mlir
@@ -91,14 +91,14 @@ func.func @alloca_non_integer_alignment() {
// -----
func.func @gep_missing_input_result_type(%pos : i64, %base : !llvm.ptr) {
- // expected-error at +1 {{2 operands present, but expected 0}}
+ // expected-error at +1 {{number of operands and types do not match: got 2 operands and 0 types}}
llvm.getelementptr %base[%pos] : () -> (), i64
}
// -----
func.func @gep_missing_input_type(%pos : i64, %base : !llvm.ptr) {
- // expected-error at +1 {{2 operands present, but expected 0}}
+ // expected-error at +1 {{number of operands and types do not match: got 2 operands and 0 types}}
llvm.getelementptr %base[%pos] : () -> (!llvm.ptr), i64
}
diff --git a/mlir/test/Dialect/Linalg/transform-ops-invalid.mlir b/mlir/test/Dialect/Linalg/transform-ops-invalid.mlir
index fbebb97a11983e..6584596cdfdb21 100644
--- a/mlir/test/Dialect/Linalg/transform-ops-invalid.mlir
+++ b/mlir/test/Dialect/Linalg/transform-ops-invalid.mlir
@@ -77,7 +77,7 @@ transform.sequence failures(propagate) {
transform.sequence failures(propagate) {
^bb0(%arg0: !transform.any_op):
%0 = transform.param.constant 2 : i64 -> !transform.param<i64>
- // expected-error at below {{custom op 'transform.structured.vectorize' 1 operands present, but expected 2}}
+ // expected-error at +1 {{custom op 'transform.structured.vectorize' number of operands and types do not match: got 1 operands and 2 types}}
transform.structured.vectorize %arg0 vector_sizes [%0, 2] : !transform.any_op, !transform.param<i64>, !transform.param<i64>
}
diff --git a/mlir/test/Dialect/SCF/invalid.mlir b/mlir/test/Dialect/SCF/invalid.mlir
index 337eb9eeb8fa57..80576be8801276 100644
--- a/mlir/test/Dialect/SCF/invalid.mlir
+++ b/mlir/test/Dialect/SCF/invalid.mlir
@@ -247,7 +247,7 @@ func.func @parallel_more_results_than_reduces(
func.func @parallel_more_results_than_initial_values(
%arg0 : index, %arg1: index, %arg2: index) {
- // expected-error at +1 {{'scf.parallel' 0 operands present, but expected 1}}
+ // expected-error at +1 {{'scf.parallel' number of operands and types do not match: got 0 operands and 1 types}}
%res = scf.parallel (%i0) = (%arg0) to (%arg1) step (%arg2) -> f32 {
scf.reduce(%arg0 : index) {
^bb0(%lhs: index, %rhs: index):
@@ -609,7 +609,7 @@ func.func @wrong_num_results(%in: tensor<100xf32>, %out: tensor<100xf32>) {
%c1 = arith.constant 1 : index
%num_threads = arith.constant 100 : index
- // expected-error @+1 {{1 operands present, but expected 2}}
+ // expected-error at +1 {{number of operands and types do not match: got 1 operands and 2 types}}
%result:2 = scf.forall (%thread_idx) in (%num_threads) shared_outs(%o = %out) -> (tensor<100xf32>, tensor<100xf32>) {
%1 = tensor.extract_slice %in[%thread_idx][1][1] : tensor<100xf32> to tensor<1xf32>
scf.forall.in_parallel {
diff --git a/mlir/test/Dialect/SPIRV/IR/memory-ops.mlir b/mlir/test/Dialect/SPIRV/IR/memory-ops.mlir
index 5aef6135afd97e..57ff94762ff68c 100644
--- a/mlir/test/Dialect/SPIRV/IR/memory-ops.mlir
+++ b/mlir/test/Dialect/SPIRV/IR/memory-ops.mlir
@@ -57,7 +57,7 @@ func.func @access_chain_non_composite() -> () {
func.func @access_chain_no_indices(%index0 : i32) -> () {
%0 = spirv.Variable : !spirv.ptr<!spirv.array<4x!spirv.array<4xf32>>, Function>
- // expected-error @+1 {{custom op 'spirv.AccessChain' 0 operands present, but expected 1}}
+ // expected-error @+1 {{custom op 'spirv.AccessChain' number of operands and types do not match: got 0 operands and 1 types}}
%1 = spirv.AccessChain %0[] : !spirv.ptr<!spirv.array<4x!spirv.array<4xf32>>, Function>, i32 -> !spirv.ptr<f32, Function>
return
}
@@ -75,7 +75,7 @@ func.func @access_chain_missing_comma(%index0 : i32) -> () {
func.func @access_chain_invalid_indices_types_count(%index0 : i32) -> () {
%0 = spirv.Variable : !spirv.ptr<!spirv.array<4x!spirv.array<4xf32>>, Function>
- // expected-error @+1 {{custom op 'spirv.AccessChain' 1 operands present, but expected 2}}
+ // expected-error @+1 {{custom op 'spirv.AccessChain' number of operands and types do not match: got 1 operands and 2 types}}
%1 = spirv.AccessChain %0[%index0] : !spirv.ptr<!spirv.array<4x!spirv.array<4xf32>>, Function>, i32, i32 -> !spirv.ptr<!spirv.array<4xf32>, Function>
return
}
@@ -84,7 +84,7 @@ func.func @access_chain_invalid_indices_types_count(%index0 : i32) -> () {
func.func @access_chain_missing_indices_type(%index0 : i32) -> () {
%0 = spirv.Variable : !spirv.ptr<!spirv.array<4x!spirv.array<4xf32>>, Function>
- // expected-error @+1 {{custom op 'spirv.AccessChain' 2 operands present, but expected 1}}
+ // expected-error @+1 {{custom op 'spirv.AccessChain' number of operands and types do not match: got 2 operands and 1 types}}
%1 = spirv.AccessChain %0[%index0, %index0] : !spirv.ptr<!spirv.array<4x!spirv.array<4xf32>>, Function>, i32 -> !spirv.ptr<f32, Function>
return
}
diff --git a/mlir/test/Dialect/Tensor/invalid.mlir b/mlir/test/Dialect/Tensor/invalid.mlir
index 77cae1cc5f242d..83cb4b9d4ab247 100644
--- a/mlir/test/Dialect/Tensor/invalid.mlir
+++ b/mlir/test/Dialect/Tensor/invalid.mlir
@@ -90,7 +90,7 @@ func.func @tensor.from_elements_wrong_result_type() {
// -----
func.func @tensor.from_elements_wrong_elements_count() {
- // expected-error at +2 {{1 operands present, but expected 2}}
+ // expected-error at +2 {{number of operands and types do not match: got 1 operands and 2 types}}
%c0 = arith.constant 0 : index
%0 = tensor.from_elements %c0 : tensor<2xindex>
return
diff --git a/mlir/test/Dialect/Vector/invalid.mlir b/mlir/test/Dialect/Vector/invalid.mlir
index 9f7efa15ed5207..1a70791fae1257 100644
--- a/mlir/test/Dialect/Vector/invalid.mlir
+++ b/mlir/test/Dialect/Vector/invalid.mlir
@@ -1803,7 +1803,7 @@ func.func @deinterleave_scalable_rank_fail(%vec : vector<2x[4]xf32>) {
// -----
func.func @invalid_from_elements(%a: f32) {
- // expected-error @+1 {{'vector.from_elements' 1 operands present, but expected 2}}
+ // expected-error @+1 {{'vector.from_elements' number of operands and types do not match: got 1 operands and 2 types}}
vector.from_elements %a : vector<2xf32>
return
}
More information about the Mlir-commits
mailing list