[Mlir-commits] [mlir] [MLIR][Shape] Enable strict property assembly format (PR #218903)
Mehdi Amini
llvmlistbot at llvm.org
Wed Aug 26 04:46:11 PDT 2026
https://github.com/joker-eph created https://github.com/llvm/llvm-project/pull/218903
Enable the strict properties assembly format mode for the Shape dialect.
Bind the broadcast diagnostic attribute directly. Keep its optional clause unambiguous after variadic operands, and cover the custom and rejected attr-dict spellings.
Assisted-by: Codex
>From fb39849fccd7383c19af66bd94a6d1910b135685 Mon Sep 17 00:00:00 2001
From: Mehdi Amini <joker.eph at gmail.com>
Date: Wed, 6 May 2026 13:40:40 -0700
Subject: [PATCH] [MLIR][Shape] Enable strict property assembly format
Enable the strict properties assembly format mode for the Shape dialect.
Bind the broadcast diagnostic attribute directly. Keep its optional clause
unambiguous after variadic operands, and cover the custom and rejected
attr-dict spellings.
Assisted-by: Codex
---
mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td | 1 +
mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td | 3 ++-
mlir/test/Dialect/Shape/invalid.mlir | 11 ++++++++++-
mlir/test/Dialect/Shape/ops.mlir | 11 ++++++++++-
4 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td b/mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td
index 9c0257954d3e8..d03fb094312a2 100644
--- a/mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td
+++ b/mlir/include/mlir/Dialect/Shape/IR/ShapeBase.td
@@ -22,6 +22,7 @@ include "mlir/IR/OpBase.td"
def ShapeDialect : Dialect {
let name = "shape";
+ let useStrictPropertiesInAssemblyFormat = 1;
let summary = "Types and operations for shape dialect";
let description = [{
diff --git a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
index fc9f498fdb805..5ec130c7e2e4a 100644
--- a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
+++ b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
@@ -85,7 +85,8 @@ def Shape_BroadcastOp : Shape_Op<"broadcast", [Commutative, Pure]> {
let builders = [OpBuilder<(ins "Value":$shape)>];
let assemblyFormat = [{
- $shapes attr-dict `:` type($shapes) `->` type($result)
+ $shapes (`error` `=` $error^)? attr-dict `:` type($shapes) `->`
+ type($result)
}];
let builders = [OpBuilder<(ins "::mlir::Type":$result,
diff --git a/mlir/test/Dialect/Shape/invalid.mlir b/mlir/test/Dialect/Shape/invalid.mlir
index 572583edd59bd..ede75efa77a9a 100644
--- a/mlir/test/Dialect/Shape/invalid.mlir
+++ b/mlir/test/Dialect/Shape/invalid.mlir
@@ -166,6 +166,16 @@ func.func @broadcast(%arg0 : !shape.shape, %arg1 : tensor<?xindex>) -> tensor<?x
// -----
+func.func @broadcast_error_in_attr_dict(%arg0 : !shape.shape,
+ %arg1 : !shape.shape) {
+ // expected-error at +1 {{inherent attribute 'error' cannot be parsed from attr-dict when strict properties in assembly format is enabled}}
+ %result = shape.broadcast %arg0, %arg1 {error = "incompatible shapes"}
+ : !shape.shape, !shape.shape -> !shape.shape
+ return
+}
+
+// -----
+
// Test using an unsupported shape.lib attribute type.
// expected-error at +1 {{only SymbolRefAttr allowed in shape.lib attribute array}}
@@ -300,4 +310,3 @@ func.func @invalid_meet(%arg0 : tensor<2xindex>, %arg1 : tensor<3xindex>) -> ten
%result = shape.meet %arg0, %arg1 : tensor<2xindex>, tensor<3xindex> -> tensor<?xindex>
return %result : tensor<?xindex>
}
-
diff --git a/mlir/test/Dialect/Shape/ops.mlir b/mlir/test/Dialect/Shape/ops.mlir
index 8a90ed88ffd68..35e210b9e268b 100644
--- a/mlir/test/Dialect/Shape/ops.mlir
+++ b/mlir/test/Dialect/Shape/ops.mlir
@@ -54,6 +54,16 @@ func.func @test_broadcast_fixed() {
return
}
+// CHECK-LABEL: @test_broadcast_error
+// CHECK: shape.broadcast %{{.*}}, %{{.*}} error = "incompatible shapes"
+func.func @test_broadcast_error() {
+ %0 = shape.const_shape [10, 1, 57, 92] : !shape.shape
+ %1 = shape.const_shape [4, 57, 92] : !shape.shape
+ %2 = shape.broadcast %0, %1 error = "incompatible shapes"
+ : !shape.shape, !shape.shape -> !shape.shape
+ return
+}
+
func.func @test_broadcast_extents() -> tensor<4xindex> {
%0 = shape.const_shape [10, 1, 57, 92] : tensor<4xindex>
%1 = shape.const_shape [4, 57, 92] : tensor<3xindex>
@@ -347,4 +357,3 @@ func.func @meet_index(%arg0 : index, %arg1 : index) -> index {
%result = shape.meet %arg0, %arg1 : index, index -> index
return %result : index
}
-
More information about the Mlir-commits
mailing list