Skip to content

Conversation

@acl-cqc
Copy link
Collaborator

@acl-cqc acl-cqc commented Dec 24, 2025

Uses the HugrGraph ADT added in #97.

splice replaces a HoleOp (ignoring the index) with a DFG-rooted Hugr of matching signature, i.e. inserts the DFG.
inlineDFG flattens 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 splice method 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) and splice_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....

Base automatically changed from refactor/hugr_graph to main January 12, 2026 20:06
@acl-cqc acl-cqc marked this pull request as ready for review January 13, 2026 18:57
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`)
Copy link
Collaborator

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

Copy link
Collaborator

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 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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) ()
Copy link
Collaborator

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants