Skip to content

Commit

Permalink
Revert "Don't implement as_mut, implement HugrMutInternals + HugrMut …
Browse files Browse the repository at this point in the history
…(w/ default methods only)"

This reverts commit 2be330d.
  • Loading branch information
acl-cqc committed Oct 6, 2023
1 parent c6c7478 commit 91d1dea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
11 changes: 8 additions & 3 deletions src/hugr/hugrmut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl InsertionResult {
}

/// Impl for non-wrapped Hugrs. Overwrites the recursive default-impls to directly use the hugr.
impl<T: RootTagged<RootHandle = Node> + AsMut<Hugr>> HugrMut for T {
impl<T: RootTagged + AsMut<Hugr>> HugrMut for T {
fn add_node_with_parent(&mut self, parent: Node, node: NodeType) -> Result<Node, HugrError> {
let node = self.as_mut().add_node(node);
self.as_mut()
Expand Down Expand Up @@ -515,7 +515,7 @@ pub(crate) mod sealed {
}

/// Impl for non-wrapped Hugrs. Overwrites the recursive default-impls to directly use the hugr.
impl<T: RootTagged<RootHandle = Node> + AsMut<Hugr>> HugrMutInternals for T {
impl<T: RootTagged + AsMut<Hugr>> HugrMutInternals for T {
fn hugr_mut(&mut self) -> &mut Hugr {
self.as_mut()
}
Expand Down Expand Up @@ -571,7 +571,12 @@ pub(crate) mod sealed {
}

fn replace_op(&mut self, node: Node, op: NodeType) -> Result<NodeType, HugrError> {
// We know RootHandle=Node here so no need to check
if node == self.root() && !Self::RootHandle::TAG.is_superset(op.tag()) {
return Err(HugrError::InvalidTag {
required: Self::RootHandle::TAG,
actual: op.tag(),
});
}
let cur = self.hugr_mut().op_types.get_mut(node.index);
Ok(std::mem::replace(cur, op))
}
Expand Down
9 changes: 3 additions & 6 deletions src/hugr/views/root_checked.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::marker::PhantomData;

use crate::hugr::hugrmut::sealed::HugrMutInternals;
use crate::hugr::{HugrError, HugrMut};
use crate::hugr::HugrError;
use crate::ops::handle::NodeHandle;
use crate::{Hugr, Node};

Expand Down Expand Up @@ -44,15 +43,13 @@ impl<H: AsRef<Hugr>, Root> AsRef<Hugr> for RootChecked<H, Root> {
}
}

impl<H: AsMut<Hugr> + AsRef<Hugr>, Root: NodeHandle> HugrMutInternals for RootChecked<H, Root> {
impl<H: AsMut<Hugr> + AsRef<Hugr>, Root: NodeHandle> AsMut<Hugr> for RootChecked<H, Root> {
#[inline(always)]
fn hugr_mut(&mut self) -> &mut Hugr {
fn as_mut(&mut self) -> &mut Hugr {
self.0.as_mut()
}
}

impl<H: AsMut<Hugr> + AsRef<Hugr>, Root: NodeHandle> HugrMut for RootChecked<H, Root> {}

#[cfg(test)]
mod test {
use super::RootChecked;
Expand Down

0 comments on commit 91d1dea

Please sign in to comment.