remove get_many_mut since it was stabilized in std as get_disjoint_mut
Some checks failed
/ deps (pull_request) Has been cancelled
/ test (pull_request) Has been cancelled

This commit is contained in:
Jacob Lifshay 2025-08-24 15:52:36 -07:00
parent 65f9ab32f4
commit ae7c4be9dc
Signed by: programmerjake
SSH key fingerprint: SHA256:HnFTLGpSm4Q4Fj502oCFisjZSoakwEuTsJJMSke63RQ
3 changed files with 17 additions and 33 deletions

View file

@ -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<Target: IndexMut<usize, Output = T> + BorrowMut<[T]>>,
>,
T,
> BorrowedStatePart<'a, K>
'a,
K: StatePartKind<
BorrowedState<'a>: DerefMut<Target: IndexMut<usize, Output = T> + BorrowMut<[T]>>,
>,
T,
> BorrowedStatePart<'a, K>
{
pub(crate) fn get_many_mut<const N: usize>(
pub(crate) fn get_disjoint_mut<const N: usize>(
&mut self,
indexes: [StatePartIndex<K>; 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<StatePartKindBigSlots>,
} => {
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);
}
}

View file

@ -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;

View file

@ -163,22 +163,6 @@ impl fmt::UpperHex for BitSliceWriteWithBase<'_> {
}
}
#[inline]
#[track_caller]
pub fn get_many_mut<T, const N: usize>(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<Cell<Vec<u8>>>);