From 93f5abeef85373ce92705ccbcce533dcaf0ddc50 Mon Sep 17 00:00:00 2001 From: Mathieu Fehr Date: Fri, 28 Feb 2025 16:12:16 +0000 Subject: [PATCH] dialects: Raise a parsing error in accfg.setup when result type is invalid As there are a redundancy in the assembly format between the first parsed string and the result type, this should be a parsing error. stack-info: PR: https://github.com/xdslproject/xdsl/pull/3990, branch: math-fehr/stack/5 --- tests/filecheck/dialects/accfg/invalid.mlir | 7 +++++++ xdsl/dialects/accfg.py | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/filecheck/dialects/accfg/invalid.mlir diff --git a/tests/filecheck/dialects/accfg/invalid.mlir b/tests/filecheck/dialects/accfg/invalid.mlir new file mode 100644 index 0000000000..e9da2d3fac --- /dev/null +++ b/tests/filecheck/dialects/accfg/invalid.mlir @@ -0,0 +1,7 @@ +// RUN: xdsl-opt --split-input-file --parsing-diagnostics %s | filecheck %s + +%one = "test.op"() : () -> i32 +%zero = arith.constant 0 : i32 +%state = accfg.setup "acc1" to ("A" = %one : i32) : !accfg.state<"acc2"> + +// CHECK: expected !accfg.state<"acc1">, but got !accfg.state<"acc2"> diff --git a/xdsl/dialects/accfg.py b/xdsl/dialects/accfg.py index 17f7fc5fe9..62e6e245b4 100644 --- a/xdsl/dialects/accfg.py +++ b/xdsl/dialects/accfg.py @@ -341,14 +341,19 @@ def parse_itm() -> tuple[str, SSAValue]: attributes = parser.parse_optional_attr_dict() parser.parse_punctuation(":") + pos = parser.pos res_typ = parser.parse_type() + if res_typ != StateType(accelerator): + parser.raise_error( + f"expected {StateType(accelerator)}, but got {res_typ}", pos + ) + setup_op = cls( [val for _, val in args], [name for name, _ in args], accelerator, in_state, ) - setup_op.out_state.type = res_typ setup_op.attributes.update(attributes) return setup_op