From f24bd10c53b93056297a9f579b6f2be303693913 Mon Sep 17 00:00:00 2001 From: John Date: Wed, 24 Apr 2024 17:00:58 -0500 Subject: [PATCH] cl-structures: intern_pool isn't unsafe Nor is it an intern pool, it's more of an unstable typed arena. Ah well. --- compiler/cl-structures/src/intern_pool.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/compiler/cl-structures/src/intern_pool.rs b/compiler/cl-structures/src/intern_pool.rs index 654ab94..c76d68b 100644 --- a/compiler/cl-structures/src/intern_pool.rs +++ b/compiler/cl-structures/src/intern_pool.rs @@ -40,7 +40,7 @@ macro_rules! make_intern_key {($($(#[$meta:meta])* $name:ident),*$(,)?) => {$( /// # Safety /// /// The provided value should be within the bounds of its associated container - unsafe fn from_raw_unchecked(value: usize) -> Self { + fn from_raw_unchecked(value: usize) -> Self { Self(value) } fn get(&self) -> usize { @@ -70,7 +70,7 @@ pub trait InternKey: std::fmt::Debug { /// The provided value should be within the bounds of its associated container. // ID::from_raw_unchecked here isn't *actually* unsafe, since bounds should always be // checked, however, the function has unverifiable preconditions. - unsafe fn from_raw_unchecked(value: usize) -> Self; + fn from_raw_unchecked(value: usize) -> Self; /// Gets the index of the [`InternKey`] by value fn get(&self) -> usize; } @@ -107,13 +107,13 @@ impl Pool { } pub fn key_iter(&self) -> iter::InternKeyIter { // Safety: Pool currently has pool.len() entries, and data cannot be removed - unsafe { InternKeyIter::new(0..self.pool.len()) } + InternKeyIter::new(0..self.pool.len()) } /// Constructs an [ID](InternKey) from a [usize], if it's within bounds #[doc(hidden)] pub fn try_key_from(&self, value: usize) -> Option { - (value < self.pool.len()).then(|| unsafe { ID::from_raw_unchecked(value) }) + (value < self.pool.len()).then(|| ID::from_raw_unchecked(value)) } pub fn insert(&mut self, value: T) -> ID { @@ -121,7 +121,7 @@ impl Pool { self.pool.push(value); // Safety: value was pushed to `self.pool[id]` - unsafe { ID::from_raw_unchecked(id) } + ID::from_raw_unchecked(id) } } @@ -173,7 +173,7 @@ mod iter { /// - Range must not exceed bounds of the associated [Pool](super::Pool) /// - Items must not be removed from the pool /// - Items must be contiguous within the pool - pub(super) unsafe fn new(range: Range) -> Self { + pub(super) fn new(range: Range) -> Self { Self { range, _id: Default::default() } } } @@ -183,7 +183,7 @@ mod iter { fn next(&mut self) -> Option { // Safety: InternKeyIter can only be created by InternKeyIter::new() - Some(unsafe { ID::from_raw_unchecked(self.range.next()?) }) + Some(ID::from_raw_unchecked(self.range.next()?)) } fn size_hint(&self) -> (usize, Option) { self.range.size_hint() @@ -192,7 +192,7 @@ mod iter { impl DoubleEndedIterator for InternKeyIter { fn next_back(&mut self) -> Option { // Safety: see above - Some(unsafe { ID::from_raw_unchecked(self.range.next_back()?) }) + Some(ID::from_raw_unchecked(self.range.next_back()?)) } } impl ExactSizeIterator for InternKeyIter {}