From 4691a24a98aa4f62215a1a65a76ec78ceb46c233 Mon Sep 17 00:00:00 2001 From: Alan Lawrence Date: Wed, 1 Nov 2023 09:23:46 +0000 Subject: [PATCH] new_pure -> new_closed --- src/builder.rs | 2 +- src/builder/module.rs | 2 +- src/extension/infer.rs | 8 ++++---- src/hugr.rs | 6 +++--- src/hugr/hugrmut.rs | 2 +- src/hugr/serialize.rs | 2 +- src/hugr/validate.rs | 27 ++++++++++++++------------- src/hugr/views/root_checked.rs | 6 +++--- 8 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index b2b8d73718..678819fa1d 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -146,7 +146,7 @@ pub(crate) mod test { /// 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::new_pure(ops::DFG { + let mut hugr = Hugr::new(NodeType::new_closed(ops::DFG { signature: signature.clone(), })); hugr.add_op_with_parent( diff --git a/src/builder/module.rs b/src/builder/module.rs index a78c047d74..fc2a5d4e8c 100644 --- a/src/builder/module.rs +++ b/src/builder/module.rs @@ -90,7 +90,7 @@ impl + AsRef> ModuleBuilder { }; self.hugr_mut().replace_op( f_node, - NodeType::new_pure(ops::FuncDefn { + NodeType::new_closed(ops::FuncDefn { name, signature: signature.clone(), }), diff --git a/src/extension/infer.rs b/src/extension/infer.rs index d3fa0fa632..8833071d22 100644 --- a/src/extension/infer.rs +++ b/src/extension/infer.rs @@ -827,21 +827,21 @@ mod test { // This generates a solution that causes validation to fail // because of a missing lift node fn missing_lift_node() -> Result<(), Box> { - let mut hugr = Hugr::new(NodeType::new_pure(ops::DFG { + let mut hugr = Hugr::new(NodeType::new_closed(ops::DFG { signature: FunctionType::new(type_row![NAT], type_row![NAT]) .with_extension_delta(&ExtensionSet::singleton(&A)), })); let input = hugr.add_node_with_parent( hugr.root(), - NodeType::new_pure(ops::Input { + NodeType::new_closed(ops::Input { types: type_row![NAT], }), )?; let output = hugr.add_node_with_parent( hugr.root(), - NodeType::new_pure(ops::Output { + NodeType::new_closed(ops::Output { types: type_row![NAT], }), )?; @@ -1043,7 +1043,7 @@ mod test { extension_delta: rs.clone(), }; - let mut hugr = Hugr::new(NodeType::new_pure(op)); + let mut hugr = Hugr::new(NodeType::new_closed(op)); let conditional_node = hugr.root(); let case_op = ops::Case { diff --git a/src/hugr.rs b/src/hugr.rs index deccdada1a..905e60076b 100644 --- a/src/hugr.rs +++ b/src/hugr.rs @@ -82,7 +82,7 @@ impl NodeType { } /// Instantiate an OpType with no input extensions - pub fn new_pure(op: impl Into) -> Self { + pub fn new_closed(op: impl Into) -> Self { NodeType { op: op.into(), input_extensions: Some(ExtensionSet::new()), @@ -103,7 +103,7 @@ impl NodeType { pub fn new_default(op: impl Into) -> Self { let op = op.into(); if OpTag::ModuleOp.is_superset(op.tag()) { - Self::new_pure(op) + Self::new_closed(op) } else { Self::new_open(op) } @@ -162,7 +162,7 @@ impl OpType { impl Default for Hugr { fn default() -> Self { - Self::new(NodeType::new_pure(crate::ops::Module)) + Self::new(NodeType::new_closed(crate::ops::Module)) } } diff --git a/src/hugr/hugrmut.rs b/src/hugr/hugrmut.rs index 7e066d1cb5..ab7c72288a 100644 --- a/src/hugr/hugrmut.rs +++ b/src/hugr/hugrmut.rs @@ -620,7 +620,7 @@ mod test { { let f_in = hugr - .add_node_with_parent(f, NodeType::new_pure(ops::Input::new(type_row![NAT]))) + .add_node_with_parent(f, NodeType::new_closed(ops::Input::new(type_row![NAT]))) .unwrap(); let f_out = hugr .add_op_with_parent(f, ops::Output::new(type_row![NAT, NAT])) diff --git a/src/hugr/serialize.rs b/src/hugr/serialize.rs index edc517b0c2..afac6f92b4 100644 --- a/src/hugr/serialize.rs +++ b/src/hugr/serialize.rs @@ -333,7 +333,7 @@ pub mod test { for n in [a, b, c] { h.push_child(n, root).unwrap(); - op_types[n] = NodeType::new_pure(gen_optype(&g, n)); + op_types[n] = NodeType::new_closed(gen_optype(&g, n)); } let hg = Hugr { diff --git a/src/hugr/validate.rs b/src/hugr/validate.rs index 9cca30c54b..dbdf1c1201 100644 --- a/src/hugr/validate.rs +++ b/src/hugr/validate.rs @@ -853,7 +853,8 @@ mod test { Err(ValidationError::NoParent { node }) => assert_eq!(node, other) ); b.set_parent(other, root).unwrap(); - b.replace_op(other, NodeType::new_pure(declare_op)).unwrap(); + b.replace_op(other, NodeType::new_closed(declare_op)) + .unwrap(); b.add_ports(other, Direction::Outgoing, 1); assert_eq!(b.validate(&EMPTY_REG), Ok(())); @@ -872,7 +873,7 @@ mod test { fn leaf_root() { let leaf_op: OpType = LeafOp::Noop { ty: USIZE_T }.into(); - let b = Hugr::new(NodeType::new_pure(leaf_op)); + let b = Hugr::new(NodeType::new_closed(leaf_op)); assert_eq!(b.validate(&EMPTY_REG), Ok(())); } @@ -883,7 +884,7 @@ mod test { } .into(); - let mut b = Hugr::new(NodeType::new_pure(dfg_op)); + let mut b = Hugr::new(NodeType::new_closed(dfg_op)); let root = b.root(); add_df_children(&mut b, root, 1); assert_eq!(b.update_validate(&EMPTY_REG), Ok(())); @@ -956,7 +957,7 @@ mod test { .unwrap(); // Replace the output operation of the df subgraph with a copy - b.replace_op(output, NodeType::new_pure(LeafOp::Noop { ty: NAT })) + b.replace_op(output, NodeType::new_closed(LeafOp::Noop { ty: NAT })) .unwrap(); assert_matches!( b.validate(&EMPTY_REG), @@ -966,7 +967,7 @@ mod test { // Revert it back to an output, but with the wrong number of ports b.replace_op( output, - NodeType::new_pure(ops::Output::new(type_row![BOOL_T])), + NodeType::new_closed(ops::Output::new(type_row![BOOL_T])), ) .unwrap(); assert_matches!( @@ -976,14 +977,14 @@ mod test { ); b.replace_op( output, - NodeType::new_pure(ops::Output::new(type_row![BOOL_T, BOOL_T])), + NodeType::new_closed(ops::Output::new(type_row![BOOL_T, BOOL_T])), ) .unwrap(); // After fixing the output back, replace the copy with an output op b.replace_op( copy, - NodeType::new_pure(ops::Output::new(type_row![BOOL_T, BOOL_T])), + NodeType::new_closed(ops::Output::new(type_row![BOOL_T, BOOL_T])), ) .unwrap(); assert_matches!( @@ -1010,7 +1011,7 @@ mod test { b.validate(&EMPTY_REG).unwrap(); b.replace_op( copy, - NodeType::new_pure(ops::CFG { + NodeType::new_closed(ops::CFG { signature: FunctionType::new(type_row![BOOL_T], type_row![BOOL_T]), }), ) @@ -1066,7 +1067,7 @@ mod test { // Change the types in the BasicBlock node to work on qubits instead of bits b.replace_op( block, - NodeType::new_pure(ops::BasicBlock::DFB { + NodeType::new_closed(ops::BasicBlock::DFB { inputs: type_row![Q], tuple_sum_rows: vec![type_row![]], other_outputs: type_row![Q], @@ -1079,12 +1080,12 @@ mod test { let block_output = block_children.next_back().unwrap().into(); b.replace_op( block_input, - NodeType::new_pure(ops::Input::new(type_row![Q])), + NodeType::new_closed(ops::Input::new(type_row![Q])), ) .unwrap(); b.replace_op( block_output, - NodeType::new_pure(ops::Output::new(type_row![Type::new_unit_sum(1), Q])), + NodeType::new_closed(ops::Output::new(type_row![Type::new_unit_sum(1), Q])), ) .unwrap(); assert_matches!( @@ -1316,12 +1317,12 @@ mod test { let main_signature = FunctionType::new(type_row![NAT], type_row![NAT]).with_extension_delta(&rs); - let mut hugr = Hugr::new(NodeType::new_pure(ops::DFG { + let mut hugr = Hugr::new(NodeType::new_closed(ops::DFG { signature: main_signature, })); let input = hugr.add_node_with_parent( hugr.root(), - NodeType::new_pure(ops::Input { + NodeType::new_closed(ops::Input { types: type_row![NAT], }), )?; diff --git a/src/hugr/views/root_checked.rs b/src/hugr/views/root_checked.rs index 6b3f7aba38..7bf0542bc9 100644 --- a/src/hugr/views/root_checked.rs +++ b/src/hugr/views/root_checked.rs @@ -79,7 +79,7 @@ mod test { #[test] fn root_checked() { - let root_type = NodeType::new_pure(ops::DFG { + let root_type = NodeType::new_closed(ops::DFG { signature: FunctionType::new(vec![], vec![]), }); let mut h = Hugr::new(root_type.clone()); @@ -94,7 +94,7 @@ mod test { let mut dfg_v = RootChecked::<&mut Hugr, DfgID>::try_new(&mut h).unwrap(); // That is a HugrMutInternal, so we can try: let root = dfg_v.root(); - let bb = NodeType::new_pure(BasicBlock::DFB { + let bb = NodeType::new_closed(BasicBlock::DFB { inputs: type_row![], other_outputs: type_row![], tuple_sum_rows: vec![type_row![]], @@ -129,7 +129,7 @@ mod test { let mut bb_v = RootChecked::<_, BasicBlockID>::try_new(dfp_v).unwrap(); // And it's a HugrMut: - let nodetype = NodeType::new_pure(LeafOp::MakeTuple { tys: type_row![] }); + let nodetype = NodeType::new_closed(LeafOp::MakeTuple { tys: type_row![] }); bb_v.add_node_with_parent(bb_v.root(), nodetype).unwrap(); } }