From fe71efd4e1b636a8e5f17c026201eb70f35c2e7c Mon Sep 17 00:00:00 2001 From: Craig Roy Date: Mon, 4 Sep 2023 14:27:36 +0100 Subject: [PATCH 1/5] feat: Default DFGBuilder resources to being open --- src/builder/dataflow.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/builder/dataflow.rs b/src/builder/dataflow.rs index b536b9e23..c6a3124c0 100644 --- a/src/builder/dataflow.rs +++ b/src/builder/dataflow.rs @@ -76,6 +76,7 @@ impl + AsRef> DFGBuilder { impl DFGBuilder { /// Begin building a new DFG rooted HUGR. + /// Input extensions default to being an open variable /// /// # Errors /// @@ -84,13 +85,9 @@ impl DFGBuilder { let dfg_op = ops::DFG { signature: signature.clone(), }; - // TODO: Allow input extensions to be specified - let base = Hugr::new(NodeType::pure(dfg_op)); + let base = Hugr::new(NodeType::open_extensions(dfg_op)); let root = base.root(); - DFGBuilder::create_with_io( - base, root, signature, // TODO: Make input extensions a parameter - None, - ) + DFGBuilder::create_with_io(base, root, signature, None) } } From c6bfb1e9ecf6feef595ccf7f81f148759aed8302 Mon Sep 17 00:00:00 2001 From: Craig Roy Date: Mon, 4 Sep 2023 14:47:33 +0100 Subject: [PATCH 2/5] doc: Comment --- src/builder.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/builder.rs b/src/builder.rs index 2a809e6a4..0f85bd1ac 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -135,7 +135,8 @@ pub(crate) mod test { /// A helper method which creates a DFG rooted hugr with closed resources, /// for tests which want to avoid having open extension variables after - /// inference. + /// inference. Using DFGBuilder will default to a root node with an open + /// extension variable pub(crate) fn closed_dfg_root_hugr(signature: FunctionType) -> Hugr { let mut hugr = Hugr::new(NodeType::pure(ops::DFG { signature: signature.clone(), From c66b2665a4069b36a9f77a8a2eee7dbaedbda3d3 Mon Sep 17 00:00:00 2001 From: Craig Roy Date: Mon, 4 Sep 2023 14:54:16 +0100 Subject: [PATCH 3/5] feat: Default more builder methods to open extensions --- src/builder/build_traits.rs | 6 ++---- src/builder/cfg.rs | 4 ++-- src/builder/conditional.rs | 4 ++-- src/builder/tail_loop.rs | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/builder/build_traits.rs b/src/builder/build_traits.rs index 1f6d045f2..f0e624132 100644 --- a/src/builder/build_traits.rs +++ b/src/builder/build_traits.rs @@ -322,8 +322,7 @@ pub trait Dataflow: Container { let (cfg_node, _) = add_node_with_wires( self, - // TODO: Make input extensions a parameter - NodeType::pure(ops::CFG { + NodeType::open_extensions(ops::CFG { inputs: inputs.clone(), outputs: output_types.clone(), }), @@ -606,8 +605,7 @@ fn add_op_with_wires( optype: impl Into, inputs: Vec, ) -> Result<(Node, usize), BuildError> { - // TODO: Make this NodeType::open_extensions - add_node_with_wires(data_builder, NodeType::pure(optype), inputs) + add_node_with_wires(data_builder, NodeType::open_extensions(optype), inputs) } fn add_node_with_wires( diff --git a/src/builder/cfg.rs b/src/builder/cfg.rs index bb17940af..d007f04e3 100644 --- a/src/builder/cfg.rs +++ b/src/builder/cfg.rs @@ -63,7 +63,7 @@ impl CFGBuilder { }; // TODO: Allow input extensions to be specified - let base = Hugr::new(NodeType::pure(cfg_op)); + let base = Hugr::new(NodeType::open_extensions(cfg_op)); let cfg_node = base.root(); CFGBuilder::create(base, cfg_node, input, output) } @@ -280,7 +280,7 @@ impl BlockBuilder { }; // TODO: Allow input extensions to be specified - let base = Hugr::new(NodeType::pure(op)); + let base = Hugr::new(NodeType::open_extensions(op)); let root = base.root(); Self::create(base, root, predicate_variants, other_outputs, inputs) } diff --git a/src/builder/conditional.rs b/src/builder/conditional.rs index 8943ed7ee..607dda8bb 100644 --- a/src/builder/conditional.rs +++ b/src/builder/conditional.rs @@ -178,7 +178,7 @@ impl ConditionalBuilder { extension_delta, }; // TODO: Allow input extensions to be specified - let base = Hugr::new(NodeType::pure(op)); + let base = Hugr::new(NodeType::open_extensions(op)); let conditional_node = base.root(); Ok(ConditionalBuilder { @@ -197,7 +197,7 @@ impl CaseBuilder { signature: signature.clone(), }; // TODO: Allow input extensions to be specified - let base = Hugr::new(NodeType::pure(op)); + let base = Hugr::new(NodeType::open_extensions(op)); let root = base.root(); let dfg_builder = DFGBuilder::create_with_io(base, root, signature, None)?; diff --git a/src/builder/tail_loop.rs b/src/builder/tail_loop.rs index 3e785c13f..5b3a3fc66 100644 --- a/src/builder/tail_loop.rs +++ b/src/builder/tail_loop.rs @@ -82,7 +82,7 @@ impl TailLoopBuilder { rest: inputs_outputs.into(), }; // TODO: Allow input extensions to be specified - let base = Hugr::new(NodeType::pure(tail_loop.clone())); + let base = Hugr::new(NodeType::open_extensions(tail_loop.clone())); let root = base.root(); Self::create_with_io(base, root, &tail_loop) } From d7f5119c4c359b199d9b60912bed7d5099daace8 Mon Sep 17 00:00:00 2001 From: Craig Roy Date: Mon, 4 Sep 2023 15:01:02 +0100 Subject: [PATCH 4/5] refactor: Default `n_identity` to open extensions --- src/builder/conditional.rs | 1 - src/builder/dataflow.rs | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/builder/conditional.rs b/src/builder/conditional.rs index 607dda8bb..017447a82 100644 --- a/src/builder/conditional.rs +++ b/src/builder/conditional.rs @@ -129,7 +129,6 @@ impl + AsRef> ConditionalBuilder { // TODO: Allow this to be non-pure self.hugr_mut().add_op_before(sibling_node, case_op)? } else { - // TODO: Allow this to be non-pure self.add_child_op(case_op)? }; diff --git a/src/builder/dataflow.rs b/src/builder/dataflow.rs index c6a3124c0..6dfd13853 100644 --- a/src/builder/dataflow.rs +++ b/src/builder/dataflow.rs @@ -253,8 +253,7 @@ pub(crate) mod test { let inner_builder = func_builder.dfg_builder( FunctionType::new(type_row![NAT], type_row![NAT]), - // TODO: This should be None - Some(ExtensionSet::new()), + None, [int], )?; let inner_id = n_identity(inner_builder)?; From 86bf1c00b2ec0e3e2960be48078c267a57df779f Mon Sep 17 00:00:00 2001 From: Craig Roy Date: Mon, 4 Sep 2023 17:41:48 +0100 Subject: [PATCH 5/5] cleanup: Remove redundant comment --- src/builder/conditional.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/builder/conditional.rs b/src/builder/conditional.rs index 017447a82..4bc851b73 100644 --- a/src/builder/conditional.rs +++ b/src/builder/conditional.rs @@ -195,7 +195,6 @@ impl CaseBuilder { let op = ops::Case { signature: signature.clone(), }; - // TODO: Allow input extensions to be specified let base = Hugr::new(NodeType::open_extensions(op)); let root = base.root(); let dfg_builder = DFGBuilder::create_with_io(base, root, signature, None)?;