-
Notifications
You must be signed in to change notification settings - Fork 14
feat: insert_hugr copies Module-level children, _with_defns links by Node #2285
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
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2285 +/- ##
==========================================
+ Coverage 82.01% 82.12% +0.10%
==========================================
Files 245 245
Lines 45474 45730 +256
Branches 41210 41466 +256
==========================================
+ Hits 37297 37555 +258
+ Misses 6172 6167 -5
- Partials 2005 2008 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
#[non_exhaustive] | ||
pub enum InsertDefnError<N: Display> { | ||
/// Module-children were requested in addition to the module entrypoint | ||
// ALAN is this worth bothering with as a separate case? Inserting a hugr |
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.
Another possibility here is to say, if the inserted Hugr's entrypoint is its module-root, then
- The
parent
node under which to insert must be the target Hugr's module root (or else panic) - The inserted Hugr's module root will be elided - i.e. all the children will be copied from one module root to the other
I think this makes a likely-to-become-fairly-common case, of trying to combine two Hugrs, a whole lot easier. It's not breaking in the "API-compatible" sense but does change behaviour (so might break tests). Thoughts?
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.
I think the current implementation which does not special case the insert-module-into-module case is simplest and therefore best.
I do think we should provide tools to make "linking two modules" as you describe as easy as possible, but not here.
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 looks right, but I admit that I don't entirely grok this.
#[non_exhaustive] | ||
pub enum InsertDefnError<N: Display> { | ||
/// Module-children were requested in addition to the module entrypoint | ||
// ALAN is this worth bothering with as a separate case? Inserting a hugr |
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.
I think the current implementation which does not special case the insert-module-into-module case is simplest and therefore best.
I do think we should provide tools to make "linking two modules" as you describe as easy as possible, but not here.
#[non_exhaustive] | ||
pub enum InsertDefnError<N: Display> { | ||
/// Module-children were requested in addition to the module entrypoint | ||
// ALAN is this worth bothering with as a separate case? Inserting a hugr |
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 needs to be cleaned up, I think the error should remain as-is. This(insert-module-into-module) is a reasonable thing to do, but not like this!
Hmmmm, ok, well. Spelling out the future in a bit more detail.... So the idea was that the new method is enough to express every plausible policy using link-name, and the next PR will add the link-name attribute/field and some of those - some subset of
This direction raises two questions for this PR:
|
I.e. we might want a solution for #2356 as part of this too |
HugrMut::insert_hugr_with_defns
andHugrMut::insert_from_view_with_defns
that take a map from module-level children of the inserted Hugr (i.e. outside the entrypoint / the bit that gets inserted at the "desired location") to an instruction to either Add them to the target Hugr, or replace (edges from) them with a node existing in the target Hugr.insert_hugr
defaults to copying all module-level children;insert_from_view
defaults to not inserting any. (The difference becauseinsert_hugr
consumes your Hugr, whereas with..._from_view
you still have it.)SimpleReplacement
usesinsert_hugr
we get back the ability to SR in FuncDefns lost in feat!: No nested FuncDefns (or AliasDefns) #2256 (I've added a test; the same should work for NodeTemplate::CompoundOp but I haven't tested this.)add_hugr(_view)_with_wires_and_defns
(we could also have a non-dataflowadd_hugr_with_defns
but I skipped this as a less-common case; we could also add a NodeTemplate::CompoundOpWithDefns with an explicit map.)Naming:
_with_defns
obviously isn't quite right, they could be decls too (even module-level constants!)._with_linkage
seems slightly premature but maybe??The plan is that when we add
link_name
to FuncDefn/FuncDecl, the "default" forinsert_hugr
will be to Replace, etc., defns/decls with the same link_name. (Not clear what to do by default if both target and inserted have a FuncDefn with the samelink_name
, but we could favour either one, add both and make an invalid hugr, or panic.)However there is an alternative possibility, to end this PR with just a set of module children to copy (i.e. 0db0ccd - see diff) and then to add a method on a Hugr(Mut) that merges together FuncDefns/Decls with the same
link_name
. This raises similar questions, e.g. does it panic on two FuncDefns with the same link_name, and is not as flexible for funcs withoutlink_name
. I guess it would probably have all the same options as InsertDefnMode here.closes #2355