Skip to content

Commit

Permalink
Add NodeType::op(), remove From conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
acl-cqc committed Oct 24, 2023
1 parent 8395129 commit 46efff0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/builder/build_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ pub trait Dataflow: Container {
let const_node = cid.node();
let nodetype = self.hugr().get_nodetype(const_node);
let input_extensions = nodetype.input_extensions().cloned();
let op: &OpType = nodetype.into();
let op: ops::Const = op
let op: ops::Const = nodetype
.op()
.clone()
.try_into()
.expect("ConstID does not refer to Const op.");
Expand Down
5 changes: 3 additions & 2 deletions src/extension/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use super::{ExtensionId, ExtensionSet};
use crate::{
hugr::views::HugrView,
hugr::Node,
ops::{OpTag, OpTrait, OpType},
ops::{OpTag, OpTrait},
types::EdgeKind,
Direction,
};
Expand Down Expand Up @@ -328,7 +328,7 @@ impl UnificationContext {
// Separate loop so that we can assume that a metavariable has been
// added for every (Node, Direction) in the graph already.
for tgt_node in hugr.nodes() {
let sig: &OpType = hugr.get_nodetype(tgt_node).into();
let sig = hugr.get_nodetype(tgt_node).op();
// Incoming ports with an edge that should mean equal extension reqs
for port in hugr.node_inputs(tgt_node).filter(|src_port| {
matches!(
Expand Down Expand Up @@ -695,6 +695,7 @@ mod test {
use crate::extension::{prelude::PRELUDE_REGISTRY, ExtensionSet};
use crate::hugr::{validate::ValidationError, Hugr, HugrMut, HugrView, NodeType};
use crate::macros::const_extension_ids;
use crate::ops::OpType;
use crate::ops::{self, dataflow::IOTrait, handle::NodeHandle, OpTrait};
use crate::type_row;
use crate::types::{FunctionType, Type, TypeRow};
Expand Down
13 changes: 7 additions & 6 deletions src/hugr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ impl NodeType {
}

impl NodeType {
/// Gets the underlying [OpType] i.e. without any [input_extensions]
///
/// [input_extensions]: NodeType::input_extensions
pub fn op(&self) -> &OpType {
&self.op
}

delegate! {
to self.op {
/// Tag identifying the operation.
Expand All @@ -133,12 +140,6 @@ impl NodeType {
}
}

impl<'a> From<&'a NodeType> for &'a OpType {
fn from(nt: &'a NodeType) -> Self {
&nt.op
}
}

impl OpType {
/// Convert an OpType to a NodeType by giving it some input extensions
pub fn with_extensions(self, rs: ExtensionSet) -> NodeType {
Expand Down

0 comments on commit 46efff0

Please sign in to comment.