Skip to content

Commit 2a30bfc

Browse files
authored
[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.
1 parent 455b4fd commit 2a30bfc

File tree

7 files changed

+12
-11
lines changed

7 files changed

+12
-11
lines changed

mlir/include/mlir/IR/OpImplementation.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1604,7 +1604,8 @@ class OpAsmParser : public AsmParser {
16041604
size_t typeSize = llvm::range_size(types);
16051605
if (operandSize != typeSize)
16061606
return emitError(loc)
1607-
<< operandSize << " operands present, but expected " << typeSize;
1607+
<< "number of operands and types do not match: got " << operandSize
1608+
<< " operands and " << typeSize << " types";
16081609

16091610
for (auto [operand, type] : llvm::zip_equal(operands, types))
16101611
if (resolveOperand(operand, type, result))

mlir/test/Dialect/LLVMIR/invalid.mlir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ func.func @alloca_non_integer_alignment() {
9191
// -----
9292

9393
func.func @gep_missing_input_result_type(%pos : i64, %base : !llvm.ptr) {
94-
// expected-error@+1 {{2 operands present, but expected 0}}
94+
// expected-error@+1 {{number of operands and types do not match: got 2 operands and 0 types}}
9595
llvm.getelementptr %base[%pos] : () -> (), i64
9696
}
9797

9898
// -----
9999

100100
func.func @gep_missing_input_type(%pos : i64, %base : !llvm.ptr) {
101-
// expected-error@+1 {{2 operands present, but expected 0}}
101+
// expected-error@+1 {{number of operands and types do not match: got 2 operands and 0 types}}
102102
llvm.getelementptr %base[%pos] : () -> (!llvm.ptr), i64
103103
}
104104

mlir/test/Dialect/Linalg/transform-ops-invalid.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ transform.sequence failures(propagate) {
7777
transform.sequence failures(propagate) {
7878
^bb0(%arg0: !transform.any_op):
7979
%0 = transform.param.constant 2 : i64 -> !transform.param<i64>
80-
// expected-error@below {{custom op 'transform.structured.vectorize' 1 operands present, but expected 2}}
80+
// expected-error@+1 {{custom op 'transform.structured.vectorize' number of operands and types do not match: got 1 operands and 2 types}}
8181
transform.structured.vectorize %arg0 vector_sizes [%0, 2] : !transform.any_op, !transform.param<i64>, !transform.param<i64>
8282

8383
}

mlir/test/Dialect/SCF/invalid.mlir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ func.func @parallel_more_results_than_reduces(
247247

248248
func.func @parallel_more_results_than_initial_values(
249249
%arg0 : index, %arg1: index, %arg2: index) {
250-
// expected-error@+1 {{'scf.parallel' 0 operands present, but expected 1}}
250+
// expected-error@+1 {{'scf.parallel' number of operands and types do not match: got 0 operands and 1 types}}
251251
%res = scf.parallel (%i0) = (%arg0) to (%arg1) step (%arg2) -> f32 {
252252
scf.reduce(%arg0 : index) {
253253
^bb0(%lhs: index, %rhs: index):
@@ -609,7 +609,7 @@ func.func @wrong_num_results(%in: tensor<100xf32>, %out: tensor<100xf32>) {
609609
%c1 = arith.constant 1 : index
610610
%num_threads = arith.constant 100 : index
611611

612-
// expected-error @+1 {{1 operands present, but expected 2}}
612+
// expected-error@+1 {{number of operands and types do not match: got 1 operands and 2 types}}
613613
%result:2 = scf.forall (%thread_idx) in (%num_threads) shared_outs(%o = %out) -> (tensor<100xf32>, tensor<100xf32>) {
614614
%1 = tensor.extract_slice %in[%thread_idx][1][1] : tensor<100xf32> to tensor<1xf32>
615615
scf.forall.in_parallel {

mlir/test/Dialect/SPIRV/IR/memory-ops.mlir

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func.func @access_chain_non_composite() -> () {
5757

5858
func.func @access_chain_no_indices(%index0 : i32) -> () {
5959
%0 = spirv.Variable : !spirv.ptr<!spirv.array<4x!spirv.array<4xf32>>, Function>
60-
// expected-error @+1 {{custom op 'spirv.AccessChain' 0 operands present, but expected 1}}
60+
// expected-error @+1 {{custom op 'spirv.AccessChain' number of operands and types do not match: got 0 operands and 1 types}}
6161
%1 = spirv.AccessChain %0[] : !spirv.ptr<!spirv.array<4x!spirv.array<4xf32>>, Function>, i32 -> !spirv.ptr<f32, Function>
6262
return
6363
}
@@ -75,7 +75,7 @@ func.func @access_chain_missing_comma(%index0 : i32) -> () {
7575

7676
func.func @access_chain_invalid_indices_types_count(%index0 : i32) -> () {
7777
%0 = spirv.Variable : !spirv.ptr<!spirv.array<4x!spirv.array<4xf32>>, Function>
78-
// expected-error @+1 {{custom op 'spirv.AccessChain' 1 operands present, but expected 2}}
78+
// expected-error @+1 {{custom op 'spirv.AccessChain' number of operands and types do not match: got 1 operands and 2 types}}
7979
%1 = spirv.AccessChain %0[%index0] : !spirv.ptr<!spirv.array<4x!spirv.array<4xf32>>, Function>, i32, i32 -> !spirv.ptr<!spirv.array<4xf32>, Function>
8080
return
8181
}
@@ -84,7 +84,7 @@ func.func @access_chain_invalid_indices_types_count(%index0 : i32) -> () {
8484

8585
func.func @access_chain_missing_indices_type(%index0 : i32) -> () {
8686
%0 = spirv.Variable : !spirv.ptr<!spirv.array<4x!spirv.array<4xf32>>, Function>
87-
// expected-error @+1 {{custom op 'spirv.AccessChain' 2 operands present, but expected 1}}
87+
// expected-error @+1 {{custom op 'spirv.AccessChain' number of operands and types do not match: got 2 operands and 1 types}}
8888
%1 = spirv.AccessChain %0[%index0, %index0] : !spirv.ptr<!spirv.array<4x!spirv.array<4xf32>>, Function>, i32 -> !spirv.ptr<f32, Function>
8989
return
9090
}

mlir/test/Dialect/Tensor/invalid.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func.func @tensor.from_elements_wrong_result_type() {
9090
// -----
9191

9292
func.func @tensor.from_elements_wrong_elements_count() {
93-
// expected-error@+2 {{1 operands present, but expected 2}}
93+
// expected-error@+2 {{number of operands and types do not match: got 1 operands and 2 types}}
9494
%c0 = arith.constant 0 : index
9595
%0 = tensor.from_elements %c0 : tensor<2xindex>
9696
return

mlir/test/Dialect/Vector/invalid.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1803,7 +1803,7 @@ func.func @deinterleave_scalable_rank_fail(%vec : vector<2x[4]xf32>) {
18031803
// -----
18041804

18051805
func.func @invalid_from_elements(%a: f32) {
1806-
// expected-error @+1 {{'vector.from_elements' 1 operands present, but expected 2}}
1806+
// expected-error @+1 {{'vector.from_elements' number of operands and types do not match: got 1 operands and 2 types}}
18071807
vector.from_elements %a : vector<2xf32>
18081808
return
18091809
}

0 commit comments

Comments
 (0)