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

feat: Provide+implement Replace API #613

Merged
merged 75 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 73 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
2467729
Add Replacement struct, NewEdgeSpec/NewEdgeKind, verify, invalidation…
acl-cqc Oct 16, 2023
8e531d4
WIP Implement
acl-cqc Oct 16, 2023
e9f4ba8
Allow returning HugrError or Msg
acl-cqc Oct 16, 2023
886fba6
Check edges
acl-cqc Oct 17, 2023
ccf5200
Allow replacing edges from any node in S*; update spec
acl-cqc Oct 17, 2023
50abda1
xxx_edges => mu_xxx (xxx = out, new, in -> inp)
acl-cqc Oct 17, 2023
366209c
Make NewEdgeSpec+Replacement fields pub; run SimpleReplacement tests …
acl-cqc Oct 17, 2023
2b8c86f
fmt
acl-cqc Oct 18, 2023
de14f04
fix - new_node already in `h`, no need to translate
acl-cqc Oct 18, 2023
a996f47
Convert ReplaceError::Msg into cases
acl-cqc Oct 20, 2023
d78cbf2
clippy
acl-cqc Oct 20, 2023
e6c3d8c
Rewrite incoming-edge check
acl-cqc Oct 20, 2023
d70444e
Shorter 'descends'
acl-cqc Oct 20, 2023
6e94467
Check parent in apply
acl-cqc Oct 20, 2023
dcccde9
insertion shouldn't fail?? Drop HugrError
acl-cqc Oct 20, 2023
7366aa7
v1 verify checks port kind
acl-cqc Oct 20, 2023
46d2f48
BadEdgeKind stores Direction (temp remove check on adding Order edges)
acl-cqc Oct 20, 2023
1d15e72
Break out check_existing_edge; transfer_edge does checks too
acl-cqc Oct 20, 2023
e371fc3
BadEdgeSpec: str -> Direction, Node -> Edge
acl-cqc Oct 20, 2023
16b52b4
apply fails w/BadEdgeSpec for replacement nodes
acl-cqc Oct 20, 2023
3701d50
Note what checks required
acl-cqc Oct 20, 2023
677692a
Factor out get_removed_nodes
acl-cqc Oct 20, 2023
b2a7f00
transfer_edges: translation func returns Result<Node, WhichHugr>
acl-cqc Oct 20, 2023
86d6f39
Use get_removed in apply
acl-cqc Oct 20, 2023
4738710
Add missing docs; move 'impl NewEdgeSpec' after struct def for Replac…
acl-cqc Oct 20, 2023
94f0586
fixup! Use get_removed
acl-cqc Oct 20, 2023
c4d5996
WIP test - failing in extension inference?!
acl-cqc Oct 20, 2023
c23b798
Directly build Hugr rather than using Builder
acl-cqc Oct 23, 2023
476f0a3
Fix initial Hugr building (using Lift!)
acl-cqc Oct 23, 2023
52c7c54
Fix root type of replacement, fmt
acl-cqc Oct 24, 2023
50b7b5c
Fix: translate transfer-keys using node_map
acl-cqc Oct 24, 2023
1bef633
Check transfer keys too
acl-cqc Oct 24, 2023
72f9bf2
WIP debug
acl-cqc Oct 24, 2023
be28f21
Revert "WIP debug"
acl-cqc Oct 24, 2023
3ae6d10
Removal a list not a set, order matters
acl-cqc Oct 24, 2023
d41300a
Rename variables in test
acl-cqc Oct 24, 2023
1c96bbd
Update_validate, open_extensions, fix ports+wiring for predicate
acl-cqc Oct 24, 2023
d383856
Merge commit 'origin/main^' into new/replace
acl-cqc Oct 25, 2023
5eaf13a
Update renamed predicate->tuple/unit_sum
acl-cqc Oct 25, 2023
3fec96a
Remove lift nodes, use open_extensions for Const + load-constant
acl-cqc Oct 30, 2023
51164a0
CI fmt
acl-cqc Oct 30, 2023
5aeedb2
Merge remote-tracking branch 'origin/main' into HEAD
acl-cqc Nov 2, 2023
0ce6900
Update re. port directions
acl-cqc Oct 30, 2023
002e89a
CI fmt more
acl-cqc Oct 30, 2023
b35eb86
Rewrite test using builder again; no lift nodes, Const has singleton-…
acl-cqc Nov 2, 2023
7a3029d
clippy
acl-cqc Nov 2, 2023
b463fd3
Spec tweaks courtesy of Alec
acl-cqc Nov 6, 2023
31a743d
Yes PartialEq, no Eq
acl-cqc Nov 6, 2023
8ace22b
transfers->adoptions, fix doclinks, spec names
acl-cqc Nov 6, 2023
0014577
Note non-signature equality
acl-cqc Nov 6, 2023
5436256
WrongRootNodeTag: expected->removed, actual->replacement
acl-cqc Nov 6, 2023
154b298
Merge remote-tracking branch 'origin/main' into new/replace
acl-cqc Nov 6, 2023
da568ca
no open_extensions
acl-cqc Nov 6, 2023
f1c2114
TransfersNotSeparateDescendants is a general case of ConflictingTrans…
acl-cqc Nov 6, 2023
a5cca09
Assert about the Hugr
acl-cqc Nov 6, 2023
961026f
Start on test - build conditional Hugr
acl-cqc Nov 6, 2023
b8180d7
Test duplicate 'adoptions' rhs
acl-cqc Nov 7, 2023
e5c426d
Rename {case,r}_t/f to {case,r}1/2
acl-cqc Nov 7, 2023
326365f
Test wrong root node type
acl-cqc Nov 7, 2023
2d6a7b6
Functional style using `..r.clone()`, test CantReplaceRoot
acl-cqc Nov 7, 2023
8b5ed23
MultipleParents
acl-cqc Nov 7, 2023
71786a9
InvalidTransferTarget
acl-cqc Nov 7, 2023
65abd61
Invalid(TransferTarget=>AdoptingParent), (Transfers=>Adoptees)NotSepa…
acl-cqc Nov 7, 2023
804a005
Comments, one BadEdgeSpec
acl-cqc Nov 7, 2023
ed440b6
Another BadEdgeSpec test
acl-cqc Nov 7, 2023
c502018
NotSeparateDescendants - comment nodes are best-effort
acl-cqc Nov 7, 2023
b1dbfc4
BadEdgeKind
acl-cqc Nov 7, 2023
fcf8827
Run tests on both verify + apply, include one on mu_new
acl-cqc Nov 7, 2023
eb3c519
WIP test NoRemovedEdge...failing
acl-cqc Nov 7, 2023
17b1618
Fix for both
acl-cqc Nov 7, 2023
8788dc7
refactor: move descends_any inside check_existing_edge
acl-cqc Nov 7, 2023
aba2f41
Merge remote-tracking branch 'origin/main' into new/replace
acl-cqc Nov 7, 2023
1b39df7
Generalize Container::add_constant, pass None
acl-cqc Nov 7, 2023
ce9311a
Merge 'origin/main' into new/replace, update add_{op=>node}_...
acl-cqc Nov 8, 2023
bbb172d
Simplify invalidation_set
acl-cqc Nov 8, 2023
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
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>>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Slight generalization here @ss2165 if you are happy with that? All existing calls remain legal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can do something slightly odd in this PR (i.e. explicitly specify an ExtensionSet that is...not what you might expect) if we'd rather keep like this, 'coz either way we should probably at least try to make another PR where we remove this (and use None/open-extensions) everywhere

) -> 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