Skip to content

Commit

Permalink
refactor: avoid breaking the public API
Browse files Browse the repository at this point in the history
  • Loading branch information
qartik committed Dec 19, 2024
1 parent be7c998 commit 1bf1e63
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions hugr-core/src/builder/dataflow.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use delegate::delegate;
use itertools::Itertools;

use super::build_traits::{HugrBuilder, SubContainer};
Expand Down Expand Up @@ -80,7 +81,7 @@ impl DFGBuilder<Hugr> {
DFGBuilder::create_with_io(base, root, signature)
}

/// Add a new input to the function being constructed.
/// Add a new input to the DFG being constructed.
///
/// Returns the new wire from the input node.
pub fn add_input(&mut self, input_type: Type) -> Wire {
Expand Down Expand Up @@ -119,7 +120,7 @@ impl DFGBuilder<Hugr> {
self.input_wires().last().unwrap()
}

/// Add a new output to the function being constructed.
/// Add a new output to the DFG being constructed.
pub fn add_output(&mut self, output_type: Type) {
let [_, out_node] = self.io();

Expand Down Expand Up @@ -154,7 +155,7 @@ impl DFGBuilder<Hugr> {
self.num_out_wires += 1;
}

/// Update the function builder's parent signature.
/// Update the DFG builder's parent signature.
///
/// Internal function used in [add_input] and [add_output].
///
Expand Down Expand Up @@ -262,6 +263,18 @@ impl FunctionBuilder<Hugr> {
let db = DFGBuilder::create_with_io(base, root, body)?;
Ok(Self::from_dfg_builder(db))
}

delegate! {
to self.0 {
/// Add a new input to the function being constructed.
///
/// Returns the new wire from the input node.
pub fn add_input(&mut self, input_type: Type) -> Wire;

/// Add a new input to the function being constructed.
pub fn add_output(&mut self, output_type: Type);
}
}
}

impl<B: AsMut<Hugr> + AsRef<Hugr>, T> Container for DFGWrapper<B, T> {
Expand Down Expand Up @@ -465,8 +478,8 @@ pub(crate) mod test {
f_build.set_order(&noop0.node(), &f_build.io()[1]);

// Add a new input and output, and connect them with a noop in between
f_build.0.add_output(qb_t());
let i1 = f_build.0.add_input(qb_t());
f_build.add_output(qb_t());
let i1 = f_build.add_input(qb_t());
let noop1 = f_build.add_dataflow_op(Noop(qb_t()), [i1])?;

let hugr = f_build.finish_hugr_with_outputs([noop0.out_wire(0), noop1.out_wire(0)])?;
Expand Down

0 comments on commit 1bf1e63

Please sign in to comment.