Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Default more builder methods to open extension sets #492

Merged
merged 6 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
6 changes: 2 additions & 4 deletions src/builder/build_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}),
Expand Down Expand Up @@ -606,8 +605,7 @@ fn add_op_with_wires<T: Dataflow + ?Sized>(
optype: impl Into<OpType>,
inputs: Vec<Wire>,
) -> 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<T: Dataflow + ?Sized>(
Expand Down
4 changes: 2 additions & 2 deletions src/builder/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl CFGBuilder<Hugr> {
};

// 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)
}
Expand Down Expand Up @@ -280,7 +280,7 @@ impl BlockBuilder<Hugr> {
};

// 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)
}
Expand Down
6 changes: 2 additions & 4 deletions src/builder/conditional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ impl<B: AsMut<Hugr> + AsRef<Hugr>> ConditionalBuilder<B> {
// 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)?
};

Expand Down Expand Up @@ -178,7 +177,7 @@ impl ConditionalBuilder<Hugr> {
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 {
Expand All @@ -196,8 +195,7 @@ impl CaseBuilder<Hugr> {
let op = ops::Case {
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)?;

Expand Down
12 changes: 4 additions & 8 deletions src/builder/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ impl<T: AsMut<Hugr> + AsRef<Hugr>> DFGBuilder<T> {

impl DFGBuilder<Hugr> {
/// Begin building a new DFG rooted HUGR.
/// Input extensions default to being an open variable
///
/// # Errors
///
Expand All @@ -84,13 +85,9 @@ impl DFGBuilder<Hugr> {
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)
}
}

Expand Down Expand Up @@ -256,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)?;
Expand Down
2 changes: 1 addition & 1 deletion src/builder/tail_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl TailLoopBuilder<Hugr> {
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)
}
Expand Down