-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor!: Replace Circuit trait with a struct (#370)
Replaces the `trait Circuit : HugrView` with a struct containing a `T: HugrView` and a node id indicating the container node for the circuit in the hugr. There are a few design going into this definition: - #### Struct with checked parent node type. The previous `Circuit` trait asked the user to only use it for dataflow-based hugrs. This of course lead to functions assuming things about the hugr structure and panicking with random errors when passed an otherwise valid hugr. Bar checking the root node at each method call, this can only be solved with an opaque struct that checks its preconditions at construction time. The code here will throw a user-friendly error when trying to use incompatible hugrs: ``` Node(0) cannot be used as a circuit parent. A Module is not a dataflow container. ``` - #### Generic `T` defaulting to `Hugr` Most uses in this library manipulate circuits as owned structures (e.g. passing circuits around in badger). However, sometimes we don't own the hugr so we cannot create a `Circuit<Hugr>` from it. With the generics definition we can use `Circuit<&Hugr>` or `Circuit<&mut Hugr>` to respectively view or modify non-owned structures. - #### Parent node pointer Circuits represented as hugrs are not necessarily a flat dataflow structure. For example, a guppy-defined circuit may include calls to other methods from the module. By including a pointer to the entry point of the circuit we can keep all this structure, and rewrite it latter as necessary. This is also useful for non-owned hugrs; we can have a `Circuit<&Hugr>` pointing to a region in the hugr without needing to modify anything else. Closes #112. BREAKING CHANGE: Replaced the `Circuit` trait with a wrapper struct. --------- Co-authored-by: Seyon Sivarajah <[email protected]>
- Loading branch information
Showing
38 changed files
with
846 additions
and
557 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.