Skip to content

Commit

Permalink
Add dfg_builder_endo that was hinted by the docs removed
Browse files Browse the repository at this point in the history
  • Loading branch information
acl-cqc committed Jun 25, 2024
1 parent 82bbdb2 commit d4d1c4e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 18 additions & 1 deletion hugr-core/src/builder/build_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ use crate::{
types::EdgeKind,
};

use crate::extension::{ExtensionRegistry, ExtensionSet, SignatureError, PRELUDE_REGISTRY};
use crate::extension::{
ExtensionRegistry, ExtensionSet, SignatureError, PRELUDE_REGISTRY, TO_BE_INFERRED,
};
use crate::types::{FunctionType, PolyFuncType, Type, TypeArg, TypeRow};

use itertools::Itertools;
Expand Down Expand Up @@ -285,6 +287,21 @@ pub trait Dataflow: Container {
DFGBuilder::create_with_io(self.hugr_mut(), dfg_n, signature)
}

/// Return a builder for a [`crate::ops::DFG`] node, i.e. a nested dataflow subgraph,
/// that is endomorphic (the output types are the same as the input types).
/// The `inputs` must be an iterable over pairs of the type of the input and
/// the corresponding wire.
fn dfg_builder_endo(
&mut self,
inputs: impl IntoIterator<Item = (Type, Wire)>,
) -> Result<DFGBuilder<&mut Hugr>, BuildError> {
let (types, input_wires): (Vec<Type>, Vec<Wire>) = inputs.into_iter().unzip();
self.dfg_builder(
FunctionType::new_endo(types).with_extension_delta(TO_BE_INFERRED),
input_wires,
)
}

/// Return a builder for a [`crate::ops::CFG`] node,
/// i.e. a nested controlflow subgraph.
/// The `inputs` must be an iterable over pairs of the type of the input and
Expand Down
2 changes: 1 addition & 1 deletion hugr-core/src/hugr/rewrite/inline_dfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ mod test {
}
let c1 = nonlocal.then(|| make_const(&mut outer));
let inner = {
let mut inner = outer.dfg_builder(ft1(int_ty.clone()), [a])?;
let mut inner = outer.dfg_builder_endo([(int_ty.clone(), a)])?;
let [a] = inner.input_wires_arr();
let c1 = c1.unwrap_or_else(|| make_const(&mut inner))?;
let a1 = inner.add_dataflow_op(IntOpDef::iadd.with_log_width(6), [a, c1])?;
Expand Down

0 comments on commit d4d1c4e

Please sign in to comment.