From f2f99681ecd753331fcf0382d81f83342e2b0c7a Mon Sep 17 00:00:00 2001 From: emmau678 Date: Fri, 17 Jan 2025 15:01:05 +0000 Subject: [PATCH] fix filecheck and parser to giev a better error message --- tests/filecheck/parser-printer/graph_region.mlir | 10 ++++++++++ tests/filecheck/parser-printer/parse_error.mlir | 8 ++++++++ xdsl/parser/core.py | 6 +++--- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/tests/filecheck/parser-printer/graph_region.mlir b/tests/filecheck/parser-printer/graph_region.mlir index b6ef50a77c..59f102121b 100644 --- a/tests/filecheck/parser-printer/graph_region.mlir +++ b/tests/filecheck/parser-printer/graph_region.mlir @@ -53,6 +53,16 @@ builtin.module { // ----- +// A graph region that refers to values that are not defined in the module. + +builtin.module { + %0 = "test.termop"(%1, %2) : (i32, i32) -> i32 +} + +// CHECK: values %1, %2 were used but not defined + +// ----- + // A forward value used with a wrong index builtin.module { diff --git a/tests/filecheck/parser-printer/parse_error.mlir b/tests/filecheck/parser-printer/parse_error.mlir index 383fe99ed7..358d54e548 100644 --- a/tests/filecheck/parser-printer/parse_error.mlir +++ b/tests/filecheck/parser-printer/parse_error.mlir @@ -14,3 +14,11 @@ test.op : () -> () // CHECK-NEXT: test.op : () -> () // CHECK-NEXT: ^ // CHECK-NEXT: Operation test.op does not have a custom format. + +// ----- + +module { + "test.op"() [^unknown_successor]: () -> () +} + +// CHECK: Unknown location of span region ends with missing block declarations for block(s) unknown_successor. diff --git a/xdsl/parser/core.py b/xdsl/parser/core.py index 7d8745bbe0..88b3955d4b 100644 --- a/xdsl/parser/core.py +++ b/xdsl/parser/core.py @@ -100,7 +100,7 @@ def __init__( super().__init__(ParserState(MLIRLexer(Input(input, name))), ctx) self.ssa_values = dict() self.blocks = dict() - self.forward_block_references = dict() + self.forward_block_references = defaultdict(list) self.forward_ssa_references = dict() def parse_module(self, allow_implicit_module: bool = True) -> ModuleOp: @@ -145,7 +145,7 @@ def parse_module(self, allow_implicit_module: bool = True) -> ModuleOp: value_names = ", ".join( "%" + name for name in self.forward_ssa_references.keys() ) - if len(self.forward_block_references.keys()) > 1: + if len(self.forward_ssa_references.keys()) > 1: self.raise_error(f"values {value_names} were used but not defined") else: self.raise_error(f"value {value_names} was used but not defined") @@ -564,7 +564,7 @@ def parse_optional_region( region.add_block(block) # Finally, check that all forward block references have been resolved. - if len(self.forward_block_references) > 0: + if self.forward_block_references: pos = self.lexer.pos raise MultipleSpansParseError( Span(pos, pos + 1, self.lexer.input),