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: change &NodeType->&OpType conversion into op() accessor #623

Merged
merged 2 commits into from
Oct 27, 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
4 changes: 2 additions & 2 deletions src/builder/build_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,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 @@ -13,7 +13,7 @@
use super::{ExtensionId, ExtensionSet};
use crate::{
hugr::views::HugrView,
ops::{OpTag, OpTrait, OpType},
ops::{OpTag, OpTrait},
types::EdgeKind,
Direction, Node,
};
Expand Down Expand Up @@ -327,7 +327,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 @@ -694,6 +694,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 @@ -122,6 +122,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 @@ -134,12 +141,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