Skip to content

Commit

Permalink
FunctionBuilder::new takes impl Into<PolyFuncType>
Browse files Browse the repository at this point in the history
  • Loading branch information
acl-cqc committed Jun 24, 2024
1 parent f91b4c9 commit 43fc4a6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions hugr-core/src/builder/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ impl FunctionBuilder<Hugr> {
/// # Errors
///
/// Error in adding DFG child nodes.
pub fn new(name: impl Into<String>, signature: PolyFuncType) -> Result<Self, BuildError> {
pub fn new(
name: impl Into<String>,
signature: impl Into<PolyFuncType>,
) -> Result<Self, BuildError> {
let signature = signature.into();
let body = signature.body().clone();
let op = ops::FuncDefn {
signature,
Expand Down Expand Up @@ -328,10 +332,8 @@ pub(crate) mod test {
#[test]
fn simple_inter_graph_edge() {
let builder = || -> Result<Hugr, BuildError> {
let mut f_build = FunctionBuilder::new(
"main",
FunctionType::new(type_row![BIT], type_row![BIT]).into(),
)?;
let mut f_build =
FunctionBuilder::new("main", FunctionType::new(type_row![BIT], type_row![BIT]))?;

let [i1] = f_build.input_wires_arr();
let noop = f_build.add_dataflow_op(Noop { ty: BIT }, [i1])?;
Expand All @@ -352,10 +354,8 @@ pub(crate) mod test {

#[test]
fn error_on_linear_inter_graph_edge() -> Result<(), BuildError> {
let mut f_build = FunctionBuilder::new(
"main",
FunctionType::new(type_row![QB], type_row![QB]).into(),
)?;
let mut f_build =
FunctionBuilder::new("main", FunctionType::new(type_row![QB], type_row![QB]))?;

let [i1] = f_build.input_wires_arr();
let noop = f_build.add_dataflow_op(Noop { ty: QB }, [i1])?;
Expand Down
2 changes: 1 addition & 1 deletion hugr-core/src/hugr/views/sibling_subgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ impl SiblingSubgraph {
/// The new Hugr will contain a [FuncDefn][crate::ops::FuncDefn] root
/// with the same signature as the subgraph and the specified `name`
pub fn extract_subgraph(&self, hugr: &impl HugrView, name: impl Into<String>) -> Hugr {
let mut builder = FunctionBuilder::new(name, self.signature(hugr).into()).unwrap();
let mut builder = FunctionBuilder::new(name, self.signature(hugr)).unwrap();
// Take the unfinished Hugr from the builder, to avoid unnecessary
// validation checks that require connecting the inputs and outputs.
let mut extracted = mem::take(builder.hugr_mut());
Expand Down

0 comments on commit 43fc4a6

Please sign in to comment.