-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add splice on HugrGraph ADT #98
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
base: main
Are you sure you want to change the base?
Conversation
This reverts commit 99a7416.
| splice hole add non_root_k = modify $ \host -> case (M.lookup hole (nodes host) >>= isHole) of | ||
| Just (_, sig) -> case M.lookup (root add) (nodes add) of | ||
| Just (OpDFG (DFG sig' _)) | sig == sig' -> {-inlineDFG hole-} host { | ||
| -- prefer host entry for parent of (`hole` == root of `add`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment implies M.union, but below it's actually union
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and I think it should be disjoint union
| splice :: forall m n. (Ord n, Ord m) => n -> HugrGraph m -> (m -> n) -> State (HugrGraph n) () | ||
| splice hole add non_root_k = modify $ \host -> case (M.lookup hole (nodes host) >>= isHole) of | ||
| Just (_, sig) -> case M.lookup (root add) (nodes add) of | ||
| Just (OpDFG (DFG sig' _)) | sig == sig' -> {-inlineDFG hole-} host { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Just (OpDFG (DFG sig' _)) | sig == sig' -> {-inlineDFG hole-} host { | |
| Just (OpDFG (DFG sig' _)) | sig == sig' -> host { |
| host_out = execState (splice hole add (keyMap M.!)) host | ||
| in (host_out, ns_out) | ||
|
|
||
| inlineDFG :: Ord n => n -> State (HugrGraph n) () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need inlineDFG or is it vestigial from an earlier implementation of splice?
Uses the HugrGraph ADT added in #97.
splicereplaces a HoleOp (ignoring the index) with a DFG-rooted Hugr of matching signature, i.e. inserts the DFG.inlineDFGflattens the result, if desired. However, it'd be better to combine them - see comment.I wasn't sure what the best approach was for dealing with new/old keys, but the
splicemethod is general over both key types by taking a translation function, which gives some guarantee that we are translating the keys.splice_prepend(both NodeID Hugr's) andsplice_new(arbitrary-keyed into NodeID) offer two possibilities....take a look and see what you think?My hope ATM is that we don't need to deal with order edges since these are only added for nonlocal edges, and so we can do splicing/inlining before adding order edges.
Tests are pretty basic (i.e. about the simplest possible case, with/without inline). These should be more thorough....