Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: Improve error message for unknown block successor #3762

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Collaborator

@compor compor Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"span" is parser terminology, no? Same with "unknown location".

The block name could be in quotes - maybe have a look how we do it in other block references within error messages.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error message is definitely not correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it a problem to use parser terminology here (since it's a parse error)?

Copy link
Contributor Author

@emmau678 emmau678 Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how would I know what the correct error might be? (this one is the one that's currently being printed when the code is run) - or is this the debugging you refer to in the next comment, that is proving difficult?

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this change do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it creates automatic values for non-existent keys so you don't get a key error

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonably now that I understand the code a bit more.

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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a separate change but I don't mind including it here.

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be self.pos?

raise MultipleSpansParseError(
Span(pos, pos + 1, self.lexer.input),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@emmau678 This is the error message that should be triggered, and it doesn't line up with the error message being printed. An actual span should be printed instead of "Unknown location" and there should be the following messages about "dangling block references:"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, thank you @alexarice. I will make some updates this afternoon (I am mostly busy until then)

Expand Down
Loading