Skip to content

Commit

Permalink
new_pure -> new_closed
Browse files Browse the repository at this point in the history
  • Loading branch information
acl-cqc committed Nov 1, 2023
1 parent dbf29b4 commit 4691a24
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/builder/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl<T: AsMut<Hugr> + AsRef<Hugr>> ModuleBuilder<T> {
};
self.hugr_mut().replace_op(
f_node,
NodeType::new_pure(ops::FuncDefn {
NodeType::new_closed(ops::FuncDefn {
name,
signature: signature.clone(),
}),
Expand Down
8 changes: 4 additions & 4 deletions src/extension/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Error>> {
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],
}),
)?;
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/hugr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl NodeType {
}

/// Instantiate an OpType with no input extensions
pub fn new_pure(op: impl Into<OpType>) -> Self {
pub fn new_closed(op: impl Into<OpType>) -> Self {
NodeType {
op: op.into(),
input_extensions: Some(ExtensionSet::new()),
Expand All @@ -103,7 +103,7 @@ impl NodeType {
pub fn new_default(op: impl Into<OpType>) -> 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)
}
Expand Down Expand Up @@ -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))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/hugr/hugrmut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
2 changes: 1 addition & 1 deletion src/hugr/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
27 changes: 14 additions & 13 deletions src/hugr/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(()));

Expand All @@ -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(()));
}

Expand All @@ -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(()));
Expand Down Expand Up @@ -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),
Expand All @@ -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!(
Expand All @@ -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!(
Expand All @@ -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]),
}),
)
Expand Down Expand Up @@ -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],
Expand All @@ -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!(
Expand Down Expand Up @@ -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],
}),
)?;
Expand Down
6 changes: 3 additions & 3 deletions src/hugr/views/root_checked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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![]],
Expand Down Expand Up @@ -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();
}
}

0 comments on commit 4691a24

Please sign in to comment.