-
Notifications
You must be signed in to change notification settings - Fork 14
fix!: Fixed bugs in model CFG handling and improved CFG signatures #2334
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| --- | ||
| source: hugr-core/tests/model.rs | ||
| expression: "roundtrip(include_str!(\"../../hugr-model/tests/fixtures/model-cfg.edn\"))" | ||
| expression: ast | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what's going on here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was some refactoring in an earlier PR that changed how the snapshot test is called. The snapshot itself didn't change, and so the snapshot file was still considered valid. Now the snapshot changed, which also led to a change in the metadata that captures how the snapshot test is called. |
||
| --- | ||
| (hugr 0) | ||
|
|
||
|
|
@@ -22,10 +22,9 @@ expression: "roundtrip(include_str!(\"../../hugr-model/tests/fixtures/model-cfg. | |
| (cfg [%0] [%1] | ||
| (signature (core.fn [?0] [?0])) | ||
| (cfg [%2] [%3] | ||
| (signature (core.fn [(core.ctrl [?0])] [(core.ctrl [?0])])) | ||
| (signature (core.ctrl [[?0]] [[?0]])) | ||
croyzor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| (block [%2] [%3 %2] | ||
| (signature | ||
| (core.fn [(core.ctrl [?0])] [(core.ctrl [?0]) (core.ctrl [?0])])) | ||
| (signature (core.ctrl [[?0]] [[?0] [?0]])) | ||
| (dfg [%4] [%5] | ||
| (signature (core.fn [?0] [(core.adt [[?0] [?0]])])) | ||
| ((core.make_adt 0) [%4] [%5] | ||
|
|
@@ -37,15 +36,15 @@ expression: "roundtrip(include_str!(\"../../hugr-model/tests/fixtures/model-cfg. | |
| (cfg [%0] [%1] | ||
| (signature (core.fn [?0] [?0])) | ||
| (cfg [%2] [%3] | ||
| (signature (core.fn [(core.ctrl [?0])] [(core.ctrl [?0])])) | ||
| (signature (core.ctrl [[?0]] [[?0]])) | ||
| (block [%2] [%6] | ||
| (signature (core.fn [(core.ctrl [?0])] [(core.ctrl [?0])])) | ||
| (signature (core.ctrl [[?0]] [[?0]])) | ||
| (dfg [%4] [%5] | ||
| (signature (core.fn [?0] [(core.adt [[?0]])])) | ||
| ((core.make_adt 0) [%4] [%5] | ||
| (signature (core.fn [?0] [(core.adt [[?0]])]))))) | ||
| (block [%6] [%3] | ||
| (signature (core.fn [(core.ctrl [?0])] [(core.ctrl [?0])])) | ||
| (signature (core.ctrl [[?0]] [[?0]])) | ||
| (dfg [%7] [%8] | ||
| (signature (core.fn [?0] [(core.adt [[?0]])])) | ||
| ((core.make_adt 0) [%7] [%8] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ | |
| self.hugr = hugr | ||
| self.link_ports: _UnionFind[InPort | OutPort] = _UnionFind() | ||
| self.link_names: dict[InPort | OutPort, str] = {} | ||
| self.link_next = 0 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could use (Parroting a comment Mark gave to me recently) |
||
|
|
||
| # TODO: Store the hugr entrypoint | ||
|
|
||
|
|
@@ -52,15 +53,20 @@ | |
| if root in self.link_names: | ||
| return self.link_names[root] | ||
| else: | ||
| index = str(len(self.link_names)) | ||
| index = str(self.link_next) | ||
| self.link_next += 1 | ||
| self.link_names[root] = index | ||
| return index | ||
|
|
||
| def export_node(self, node: Node) -> model.Node | None: | ||
| def export_node( | ||
| self, node: Node, virtual_input_links: Sequence[str] = [] | ||
| ) -> model.Node | None: | ||
| """Export the node with the given node id.""" | ||
| node_data = self.hugr[node] | ||
|
|
||
| inputs = [self.link_name(InPort(node, i)) for i in range(node_data._num_inps)] | ||
| inputs = [*inputs, *virtual_input_links] | ||
|
|
||
| outputs = [self.link_name(OutPort(node, i)) for i in range(node_data._num_outs)] | ||
| meta = [] | ||
|
|
||
|
|
@@ -308,31 +314,21 @@ | |
| case DataflowBlock() as op: | ||
| region = self.export_region_dfg(node) | ||
|
|
||
| input_types = [ | ||
| model.Apply( | ||
| "core.ctrl", | ||
| [model.List([type.to_model() for type in op.inputs])], | ||
| ) | ||
| ] | ||
| input_types = [model.List([type.to_model() for type in op.inputs])] | ||
|
|
||
| other_output_types = [type.to_model() for type in op.other_outputs] | ||
| output_types = [ | ||
| model.Apply( | ||
| "core.ctrl", | ||
| model.List( | ||
| [ | ||
| model.List( | ||
| [ | ||
| *[type.to_model() for type in row], | ||
| *other_output_types, | ||
| ] | ||
| ) | ||
| ], | ||
| *[type.to_model() for type in row], | ||
| *other_output_types, | ||
| ] | ||
| ) | ||
| for row in op.sum_ty.variant_rows | ||
| ] | ||
|
|
||
| signature = model.Apply( | ||
| "core.fn", | ||
| "core.ctrl", | ||
| [model.List(input_types), model.List(output_types)], | ||
| ) | ||
|
|
||
|
|
@@ -469,9 +465,14 @@ | |
| source_types = model.List( | ||
| [type.to_model() for type in op.inputs] | ||
| ) | ||
| source = self.link_name(OutPort(child, 0)) | ||
| source = str(self.link_next) | ||
| self.link_next += 1 | ||
|
|
||
| child_node = self.export_node(child) | ||
| child_node = self.export_node( | ||
| child, virtual_input_links=[source] | ||
| ) | ||
| else: | ||
| child_node = self.export_node(child) | ||
|
|
||
| if child_node is not None: | ||
| children.append(child_node) | ||
|
|
@@ -483,7 +484,13 @@ | |
| error = f"CFG {node} has no entry block." | ||
| raise ValueError(error) | ||
|
|
||
| signature = model.Apply("core.fn", [source_types, target_types]) | ||
| signature = model.Apply( | ||
| "core.ctrl", | ||
| [ | ||
| model.List([source_types]), | ||
| model.List([target_types]), | ||
| ], | ||
| ) | ||
|
|
||
| return model.Region( | ||
| kind=model.RegionKind.CONTROL_FLOW, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.