-
Notifications
You must be signed in to change notification settings - Fork 7
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
fix: allow add_input/add_output on all DFGs #1824
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 #1824 +/- ##
=======================================
Coverage 86.55% 86.55%
=======================================
Files 194 194
Lines 35156 35158 +2
Branches 31969 31971 +2
=======================================
+ Hits 30430 30432 +2
Misses 2968 2968
Partials 1758 1758
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
hugr-core/src/builder/dataflow.rs
Outdated
} | ||
|
||
/// Update the function builder's parent signature. | ||
/// Update the DFG builder's parent signature. | ||
/// | ||
/// Internal function used in [add_input] and [add_output]. | ||
/// |
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.
update_fn_signature
still needs to be updated or it will panic for anything other than FuncDefn
.
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.
Yeah, so you've moved add_input
and add_output
from FunctionBuilder<Hugr>
into DFGBuilder<Hugr>
and a proxy for that in FunctionBuilder<Hugr>
. Instead you could define
trait MutableIO : Dataflow {
fn update_signature(...); // no default impl
fn add_input(...) { .... } // code you've moved becomes default impl delegating to self.update_signature
fn add_output(...) { ....} // similarly
}
then you impl MutableIO for FunctionBuilder<Hugr>
and impl MutableIO for DFGBuilder<Hugr>
and just have to provide the two update_signature
methods, i.e. then you don't need the delegate! { to self.0 { fn add_input(...); fn add_output(...); } }
. Does that work??
1bf1e63
to
577971c
Compare
I do not like the I have posted a PR with my attempt (#1866). which exposes I am not convinced that we should do this, as mutating the signature of a DFG does adding ports to the parent DFG, which is not required in the FuncDefn case. @aborgna-q what do you think? |
Does it make sense for For TailLoop: adding an input or output would always have to add an output or input as well! The user would have to wire these up. For DataflowBlock: Adding an input or output would mean mutating all transitively connected DataFlowBlocks, and maybe the parent CFG I would argue that a trait doesn't help us here, because in each case we should return the new ports that need to be connected. In fact I should add this to DFGBuilder::add_input |
Closes: #1819