diff --git a/crates/fayalite/src/sim/interpreter.rs b/crates/fayalite/src/sim/interpreter.rs index de582f0..35a25d0 100644 --- a/crates/fayalite/src/sim/interpreter.rs +++ b/crates/fayalite/src/sim/interpreter.rs @@ -7,7 +7,7 @@ use crate::{ intern::{Intern, Interned, Memoize}, source_location::SourceLocation, ty::CanonicalType, - util::{get_many_mut, HashMap, HashSet}, + util::{HashMap, HashSet}, }; use bitvec::{boxed::BitBox, slice::BitSlice}; use num_bigint::BigInt; @@ -2073,21 +2073,21 @@ pub(crate) struct BorrowedStatePart<'a, K: StatePartKind> { } impl< - 'a, - K: StatePartKind< - BorrowedState<'a>: DerefMut + BorrowMut<[T]>>, - >, - T, - > BorrowedStatePart<'a, K> + 'a, + K: StatePartKind< + BorrowedState<'a>: DerefMut + BorrowMut<[T]>>, + >, + T, +> BorrowedStatePart<'a, K> { - pub(crate) fn get_many_mut( + pub(crate) fn get_disjoint_mut( &mut self, indexes: [StatePartIndex; N], ) -> [&mut T; N] { - get_many_mut( - (*self.value).borrow_mut(), - indexes.map(|v| v.value as usize), - ) + (*self.value) + .borrow_mut() + .get_disjoint_mut(indexes.map(|v| v.value as usize)) + .expect("indexes are disjoint") } } @@ -2568,7 +2568,7 @@ impl_insns! { src: StatePartIndex, } => { if dest != src { - let [dest, src] = state.big_slots.get_many_mut([dest, src]); + let [dest, src] = state.big_slots.get_disjoint_mut([dest, src]); dest.clone_from(src); } next!(); @@ -2590,7 +2590,7 @@ impl_insns! { } => { if let Some(src) = state.eval_array_indexed(src) { if dest != src { - let [dest, src] = state.big_slots.get_many_mut([dest, src]); + let [dest, src] = state.big_slots.get_disjoint_mut([dest, src]); dest.clone_from(src); } } else { @@ -2619,7 +2619,7 @@ impl_insns! { } => { if let Some(dest) = state.eval_array_indexed(dest) { if dest != src { - let [dest, src] = state.big_slots.get_many_mut([dest, src]); + let [dest, src] = state.big_slots.get_disjoint_mut([dest, src]); dest.clone_from(src); } } diff --git a/crates/fayalite/src/util.rs b/crates/fayalite/src/util.rs index 233867e..4670a1f 100644 --- a/crates/fayalite/src/util.rs +++ b/crates/fayalite/src/util.rs @@ -35,8 +35,8 @@ pub use scoped_ref::ScopedRef; #[doc(inline)] pub use misc::{ - get_many_mut, interned_bit, iter_eq_by, BitSliceWriteWithBase, DebugAsDisplay, - DebugAsRawString, MakeMutSlice, RcWriter, + BitSliceWriteWithBase, DebugAsDisplay, DebugAsRawString, MakeMutSlice, RcWriter, interned_bit, + iter_eq_by, }; pub mod job_server; diff --git a/crates/fayalite/src/util/misc.rs b/crates/fayalite/src/util/misc.rs index f482eaa..99b7343 100644 --- a/crates/fayalite/src/util/misc.rs +++ b/crates/fayalite/src/util/misc.rs @@ -163,22 +163,6 @@ impl fmt::UpperHex for BitSliceWriteWithBase<'_> { } } -#[inline] -#[track_caller] -pub fn get_many_mut(slice: &mut [T], indexes: [usize; N]) -> [&mut T; N] { - for i in 0..N { - for j in 0..i { - assert!(indexes[i] != indexes[j], "duplicate index"); - } - assert!(indexes[i] < slice.len(), "index out of bounds"); - } - // Safety: checked that no indexes are duplicates and no indexes are out of bounds - unsafe { - let base = slice.as_mut_ptr(); // convert to a raw pointer before loop to avoid aliasing with &mut [T] - std::array::from_fn(|i| &mut *base.add(indexes[i])) - } -} - #[derive(Clone, Default)] pub struct RcWriter(Rc>>);