Skip to content

Commit

Permalink
fix filecheck and parser to giev a better error message
Browse files Browse the repository at this point in the history
  • Loading branch information
emmau678 committed Jan 17, 2025
1 parent 6b2b23c commit f2f9968
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
10 changes: 10 additions & 0 deletions tests/filecheck/parser-printer/graph_region.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions tests/filecheck/parser-printer/parse_error.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -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.
6 changes: 3 additions & 3 deletions xdsl/parser/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit f2f9968

Please sign in to comment.