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!: No Ports in TypeRow #1087

Merged
merged 3 commits into from
May 20, 2024
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
9 changes: 5 additions & 4 deletions hugr/src/types/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::fmt::{self, Display, Write};
use super::type_param::TypeParam;
use super::{subst_row, Substitution, Type, TypeRow};

use crate::core::PortIndex;
use crate::extension::{ExtensionRegistry, ExtensionSet, SignatureError};
use crate::{Direction, IncomingPort, OutgoingPort, Port};

Expand Down Expand Up @@ -98,28 +99,28 @@ impl FunctionType {
/// of bounds.
#[inline]
pub fn in_port_type(&self, port: impl Into<IncomingPort>) -> Option<&Type> {
self.input.get(port.into())
self.input.get(port.into().index())
}

/// Returns the type of a value output [`Port`]. Returns `None` if the port is out
/// of bounds.
#[inline]
pub fn out_port_type(&self, port: impl Into<OutgoingPort>) -> Option<&Type> {
self.output.get(port.into())
self.output.get(port.into().index())
}

/// Returns a mutable reference to the type of a value input [`Port`]. Returns `None` if the port is out
/// of bounds.
#[inline]
pub fn in_port_type_mut(&mut self, port: impl Into<IncomingPort>) -> Option<&mut Type> {
self.input.get_mut(port.into())
self.input.get_mut(port.into().index())
}

/// Returns the type of a value output [`Port`]. Returns `None` if the port is out
/// of bounds.
#[inline]
pub fn out_port_type_mut(&mut self, port: impl Into<OutgoingPort>) -> Option<&mut Type> {
self.output.get_mut(port.into())
self.output.get_mut(port.into().index())
}

/// Returns a mutable reference to the type of a value [`Port`].
Expand Down
23 changes: 10 additions & 13 deletions hugr/src/types/type_row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::{

use super::Type;
use crate::utils::display_list;
use crate::PortIndex;
use delegate::delegate;
use itertools::Itertools;

Expand Down Expand Up @@ -38,18 +37,6 @@ impl TypeRow {
}
}

#[inline(always)]
/// Returns the port type given an offset. Returns `None` if the offset is out of bounds.
pub fn get(&self, offset: impl PortIndex) -> Option<&Type> {
self.types.get(offset.index())
}

#[inline(always)]
/// Returns the port type given an offset. Returns `None` if the offset is out of bounds.
pub fn get_mut(&mut self, offset: impl PortIndex) -> Option<&mut Type> {
self.types.to_mut().get_mut(offset.index())
}

/// Returns a new `TypeRow` with `xs` concatenated onto `self`.
pub fn extend<'a>(&'a self, rest: impl IntoIterator<Item = &'a Type>) -> Self {
self.iter().chain(rest).cloned().collect_vec().into()
Expand All @@ -76,6 +63,16 @@ impl TypeRow {

/// Returns `true` if the row contains no types.
pub fn is_empty(&self) -> bool ;

#[inline(always)]
/// Returns the type at the specified index. Returns `None` if out of bounds.
pub fn get(&self, offset: usize) -> Option<&Type>;
}

to self.types.to_mut() {
#[inline(always)]
/// Returns the type at the specified index. Returns `None` if out of bounds.
pub fn get_mut(&mut self, offset: usize) -> Option<&mut Type>;
}
}
}
Expand Down