Skip to content

Commit

Permalink
Add NodeType::new_default, switch Builder/HugrMut meths; remove infer…
Browse files Browse the repository at this point in the history
….rs check
  • Loading branch information
acl-cqc committed Oct 31, 2023
1 parent 919c548 commit 0b3442a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/builder/build_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ pub trait Dataflow: Container {
op: impl Into<OpType>,
input_wires: impl IntoIterator<Item = Wire>,
) -> Result<BuildHandle<DataflowOpID>, BuildError> {
self.add_dataflow_node(NodeType::new_open(op), input_wires)
self.add_dataflow_node(NodeType::new_default(op), input_wires)
}

/// Add a dataflow [`NodeType`] to the sibling graph, wiring up the `input_wires` to the
Expand Down Expand Up @@ -628,7 +628,7 @@ fn add_op_with_wires<T: Dataflow + ?Sized>(
optype: impl Into<OpType>,
inputs: Vec<Wire>,
) -> Result<(Node, usize), BuildError> {
add_node_with_wires(data_builder, NodeType::new_open(optype), inputs)
add_node_with_wires(data_builder, NodeType::new_default(optype), inputs)
}

fn add_node_with_wires<T: Dataflow + ?Sized>(
Expand Down
3 changes: 0 additions & 3 deletions src/extension/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,6 @@ impl UnificationContext {
m_output,
node_type.op_signature().extension_reqs,
);
if OpTag::ModuleOp.is_superset(node_type.tag()) {
self.add_solution(m_input, ExtensionSet::new());
}
}
// We have a solution for everything!
Some(sig) => {
Expand Down
13 changes: 12 additions & 1 deletion src/hugr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ impl NodeType {
}
}

/// Instantiate an [OpType] with the default set of input extensions
/// for that OpType.
pub fn new_default(op: impl Into<OpType>) -> Self {
let op = op.into();
let input_extensions = OpTag::ModuleOp.is_superset(op.tag()).then(ExtensionSet::new);
NodeType {
op,
input_extensions
}
}

/// Use the input extensions to calculate the concrete signature of the node
pub fn signature(&self) -> Option<Signature> {
self.input_extensions
Expand Down Expand Up @@ -237,7 +248,7 @@ impl Hugr {

/// Add a node to the graph, with the default conversion from OpType to NodeType
pub(crate) fn add_op(&mut self, op: impl Into<OpType>) -> Node {
self.add_node(NodeType::new_open(op))
self.add_node(NodeType::new_default(op))
}

/// Add a node to the graph.
Expand Down
4 changes: 2 additions & 2 deletions src/hugr/hugrmut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub trait HugrMut: HugrMutInternals {
parent: Node,
op: impl Into<OpType>,
) -> Result<Node, HugrError> {
self.add_node_with_parent(parent, NodeType::new_open(op))
self.add_node_with_parent(parent, NodeType::new_default(op))
}

/// Add a node to the graph with a parent in the hierarchy.
Expand Down Expand Up @@ -217,7 +217,7 @@ impl<T: RootTagged<RootHandle = Node> + AsMut<Hugr>> HugrMut for T {
}

fn add_op_before(&mut self, sibling: Node, op: impl Into<OpType>) -> Result<Node, HugrError> {
self.add_node_before(sibling, NodeType::new_open(op))
self.add_node_before(sibling, NodeType::new_default(op))
}

fn add_node_before(&mut self, sibling: Node, nodetype: NodeType) -> Result<Node, HugrError> {
Expand Down

0 comments on commit 0b3442a

Please sign in to comment.