From c9c491f2d9b6d2f54c145996b56d89c07728e64a Mon Sep 17 00:00:00 2001 From: Alan Lawrence Date: Mon, 20 May 2024 16:48:30 +0100 Subject: [PATCH 1/3] TypeRow::get(_mut) take usize not PortIndex; convert in FunctionType --- hugr/src/types/signature.rs | 9 +++++---- hugr/src/types/type_row.rs | 13 ++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/hugr/src/types/signature.rs b/hugr/src/types/signature.rs index 41bc7b58c..89c832fa1 100644 --- a/hugr/src/types/signature.rs +++ b/hugr/src/types/signature.rs @@ -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}; @@ -98,28 +99,28 @@ impl FunctionType { /// of bounds. #[inline] pub fn in_port_type(&self, port: impl Into) -> 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) -> 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) -> 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) -> 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`]. diff --git a/hugr/src/types/type_row.rs b/hugr/src/types/type_row.rs index 9bba60553..8801d0a44 100644 --- a/hugr/src/types/type_row.rs +++ b/hugr/src/types/type_row.rs @@ -9,7 +9,6 @@ use std::{ use super::Type; use crate::utils::display_list; -use crate::PortIndex; use delegate::delegate; use itertools::Itertools; @@ -39,15 +38,15 @@ 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()) + /// Returns the type at the specified index. Returns `None` if out of bounds. + pub fn get(&self, offset: usize) -> Option<&Type> { + self.types.get(offset) } #[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 the type at the specified index. Returns `None` if out of bounds. + pub fn get_mut(&mut self, offset: usize) -> Option<&mut Type> { + self.types.to_mut().get_mut(offset) } /// Returns a new `TypeRow` with `xs` concatenated onto `self`. From dd51a1bae8df2051c1e26fa0eeae5098f651996d Mon Sep 17 00:00:00 2001 From: Alan Lawrence Date: Mon, 20 May 2024 16:49:22 +0100 Subject: [PATCH 2/3] Use delegate for get --- hugr/src/types/type_row.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/hugr/src/types/type_row.rs b/hugr/src/types/type_row.rs index 8801d0a44..689df0642 100644 --- a/hugr/src/types/type_row.rs +++ b/hugr/src/types/type_row.rs @@ -37,12 +37,6 @@ impl TypeRow { } } - #[inline(always)] - /// Returns the type at the specified index. Returns `None` if out of bounds. - pub fn get(&self, offset: usize) -> Option<&Type> { - self.types.get(offset) - } - #[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> { @@ -75,6 +69,10 @@ 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>; } } } From 902841aae704c8f95d7aadb901c4e0cd4e8d2f34 Mon Sep 17 00:00:00 2001 From: Alan Lawrence Date: Mon, 20 May 2024 16:51:08 +0100 Subject: [PATCH 3/3] delegate for get_mut too --- hugr/src/types/type_row.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hugr/src/types/type_row.rs b/hugr/src/types/type_row.rs index 689df0642..3d97a8068 100644 --- a/hugr/src/types/type_row.rs +++ b/hugr/src/types/type_row.rs @@ -37,12 +37,6 @@ impl TypeRow { } } - #[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> { - self.types.to_mut().get_mut(offset) - } - /// Returns a new `TypeRow` with `xs` concatenated onto `self`. pub fn extend<'a>(&'a self, rest: impl IntoIterator) -> Self { self.iter().chain(rest).cloned().collect_vec().into() @@ -74,6 +68,12 @@ impl TypeRow { /// 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>; + } } }