Skip to content

Commit

Permalink
feat: Provide+implement Replace API (#613)
Browse files Browse the repository at this point in the history
* Add struct Replace, implement both apply() and verify()
* Generalize some SimpleReplace tests to convert requests into Replaces
too
* Tiny change to spec to allow Replaces to patch up broken inter-graph
edges
* Generalize builder::Container::add_constant to allow specifying "None"
for open Extensions

---------

Co-authored-by: Alec Edgington <[email protected]>
  • Loading branch information
acl-cqc and cqc-alec authored Nov 8, 2023
1 parent 061ec3e commit 9259797
Show file tree
Hide file tree
Showing 5 changed files with 906 additions and 6 deletions.
4 changes: 2 additions & 2 deletions specification/hugr.md
Original file line number Diff line number Diff line change
Expand Up @@ -1236,10 +1236,10 @@ The `Replace` method takes as input:
$G$ and `SrcNode` in $\Gamma \setminus R$;
- a list $\mu\_\textrm{out}$ of `NewEdgeSpec` which all have their `SrcNode`in
$G$ and `TgtNode` in $\Gamma \setminus R$, where `TgtNode` and `TgtPos` describe
an existing incoming edge of that kind from a node in $R$.
an existing incoming edge of that kind from a node in $S^\*$.
- a list $\mu\_\textrm{new}$ of `NewEdgeSpec` which all have both `SrcNode` and `TgtNode`
in $\Gamma \setminus R$, where `TgtNode` and `TgtPos` describe an existing incoming
edge of that kind from a node in $R$.
edge of that kind from a node in $S^\*$.
Note that considering all three $\mu$ lists together,
- the `TgtNode` + `TgtPos`s of all `NewEdgeSpec`s with `EdgeKind` == `Value` will be unique
Expand Down
4 changes: 2 additions & 2 deletions src/builder/build_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ pub trait Container {
fn add_constant(
&mut self,
constant: ops::Const,
extensions: ExtensionSet,
extensions: impl Into<Option<ExtensionSet>>,
) -> Result<ConstID, BuildError> {
let const_n = self.add_child_node(NodeType::new(constant, extensions))?;
let const_n = self.add_child_node(NodeType::new(constant, extensions.into()))?;

Ok(const_n.into())
}
Expand Down
1 change: 1 addition & 0 deletions src/hugr/rewrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pub mod insert_identity;
pub mod outline_cfg;
pub mod replace;
pub mod simple_replace;

use crate::{Hugr, HugrView, Node};
Expand Down
Loading

0 comments on commit 9259797

Please sign in to comment.