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

refactor: Remove add_node_before #617

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion src/builder/conditional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl<B: AsMut<Hugr> + AsRef<Hugr>> ConditionalBuilder<B> {
// add case before any existing subsequent cases
if let Some(&sibling_node) = self.case_nodes[case + 1..].iter().flatten().next() {
// TODO: Allow this to be non-pure
self.hugr_mut().add_node_before(sibling_node, NodeType::open_extensions(case_op))?
self.hugr_mut().add_op_before(sibling_node, case_op)?
} else {
self.add_child_node(NodeType::open_extensions(case_op))?
};
Expand Down
2 changes: 1 addition & 1 deletion src/extension/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,7 @@ mod test {
}),
)?;

let entry = hugr.add_node_before(exit, NodeType::open_extensions(dfb))?;
let entry = hugr.add_op_before(exit, dfb)?;
let entry_in = hugr.add_node_with_parent(
entry,
NodeType::open_extensions(ops::Input { types: inputs }),
Expand Down
15 changes: 1 addition & 14 deletions src/hugr/hugrmut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,6 @@ pub trait HugrMut: HugrMutInternals {
self.hugr_mut().add_op_before(sibling, op)
}

/// A generalisation of [`HugrMut::add_op_before`], needed temporarily until
/// add_op type methods all default to creating nodes with open extensions.
/// See issue #424
#[inline]
fn add_node_before(&mut self, sibling: Node, nodetype: NodeType) -> Result<Node, HugrError> {
self.valid_non_root(sibling)?;
self.hugr_mut().add_node_before(sibling, nodetype)
}

/// Add a node to the graph as the next sibling of another node.
///
/// The sibling node's parent becomes the new node's parent.
Expand Down Expand Up @@ -216,11 +207,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::pure(op))
}

fn add_node_before(&mut self, sibling: Node, nodetype: NodeType) -> Result<Node, HugrError> {
let node = self.as_mut().add_node(nodetype);
let node = self.as_mut().add_node(NodeType::open_extensions(op));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove add_node too, but I'll open another PR for that

self.as_mut()
.hierarchy
.insert_before(node.index, sibling.index)?;
Expand Down
Loading