Skip to content

Commit 7c44651

Browse files
committed
[mlir][shape] Extend shape.cstr_require with a message.
I realized when using this that one can't get very good error messages without an additional message attribute. Differential Revision: https://reviews.llvm.org/D87875
1 parent a16e4a6 commit 7c44651

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ def Shape_ConstWitnessOp : Shape_Op<"const_witness", [ConstantLike, NoSideEffect
741741
def Shape_CstrRequireOp : Shape_Op<"cstr_require", []> {
742742
let summary = "Represents a runtime assertion that an i1 is `true`";
743743
let description = [{
744-
Represents a runtime assretion that an i1 is true. It returns a
744+
Represents a runtime assertion that an i1 is true. It returns a
745745
!shape.witness to order this assertion.
746746

747747
For simplicity, prefer using other cstr_* ops if they are available for a
@@ -750,13 +750,17 @@ def Shape_CstrRequireOp : Shape_Op<"cstr_require", []> {
750750
Example:
751751
```mlir
752752
%bool = ...
753-
%w0 = shape.cstr_require %bool // Passing if `%bool` is true.
753+
%w0 = shape.cstr_require %bool, "msg" // Passing if `%bool` is true.
754754
```
755+
756+
Since this op can be used to express many different possible assertions
757+
(depending on whatever computation calculated `pred`), the `msg`
758+
should clarify the nature of the assertion for users.
755759
}];
756-
let arguments = (ins I1:$pred);
760+
let arguments = (ins I1:$pred, StrAttr:$msg);
757761
let results = (outs Shape_WitnessType:$result);
758762

759-
let assemblyFormat = "$pred attr-dict";
763+
let assemblyFormat = "$pred `,` $msg attr-dict";
760764

761765
let hasFolder = 1;
762766
}

mlir/test/Dialect/Shape/canonicalize.mlir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ func @cstr_require_fold() {
393393
// CHECK-NEXT: consume.witness
394394
// CHECK-NEXT: return
395395
%true = constant true
396-
%0 = shape.cstr_require %true
396+
%0 = shape.cstr_require %true, "msg"
397397
"consume.witness"(%0) : (!shape.witness) -> ()
398398
return
399399
}
@@ -405,7 +405,7 @@ func @cstr_require_no_fold(%arg0: i1) {
405405
// CHECK-NEXT: shape.cstr_require
406406
// CHECK-NEXT: consume.witness
407407
// CHECK-NEXT: return
408-
%0 = shape.cstr_require %arg0
408+
%0 = shape.cstr_require %arg0, "msg"
409409
"consume.witness"(%0) : (!shape.witness) -> ()
410410
return
411411
}

mlir/test/Dialect/Shape/ops.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func @test_constraints() {
105105
%w1 = shape.cstr_eq %0, %1
106106
%w2 = shape.const_witness true
107107
%w3 = shape.const_witness false
108-
%w4 = shape.cstr_require %true
108+
%w4 = shape.cstr_require %true, "msg"
109109
%w_all = shape.assuming_all %w0, %w1, %w2, %w3, %w4
110110
shape.assuming %w_all -> !shape.shape {
111111
%2 = "shape.any"(%0, %1) : (!shape.shape, !shape.shape) -> !shape.shape

0 commit comments

Comments
 (0)