Skip to content

Commit e4e38b8

Browse files
committed
Improve: Static analysis annotation
1 parent 344a749 commit e4e38b8

File tree

2 files changed

+42
-31
lines changed

2 files changed

+42
-31
lines changed

rust/lib.rs

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl<T, const PAUSE: bool> BasicSpinMutex<T, PAUSE> {
9393
/// let mut guard = mutex.lock();
9494
/// *guard = 42;
9595
/// ```
96-
pub fn lock(&self) -> BasicSpinMutexGuard<T, PAUSE> {
96+
pub fn lock(&self) -> BasicSpinMutexGuard<'_, T, PAUSE> {
9797
while self
9898
.locked
9999
.compare_exchange_weak(false, true, Ordering::Acquire, Ordering::Relaxed)
@@ -126,7 +126,7 @@ impl<T, const PAUSE: bool> BasicSpinMutex<T, PAUSE> {
126126
/// println!("Lock is currently held by another thread");
127127
/// };
128128
/// ```
129-
pub fn try_lock(&self) -> Option<BasicSpinMutexGuard<T, PAUSE>> {
129+
pub fn try_lock(&self) -> Option<BasicSpinMutexGuard<'_, T, PAUSE>> {
130130
if self
131131
.locked
132132
.compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed)
@@ -743,7 +743,7 @@ impl ThreadPool {
743743
/// // Work executes when _op is dropped
744744
/// }
745745
/// ```
746-
pub fn for_threads<F>(&mut self, function: F) -> ForThreadsOperation<F>
746+
pub fn for_threads<F>(&mut self, function: F) -> ForThreadsOperation<'_, F>
747747
where
748748
F: Fn(usize, usize) + Sync,
749749
{
@@ -773,7 +773,7 @@ impl ThreadPool {
773773
/// std::hint::black_box(result); // Prevent optimization
774774
/// });
775775
/// ```
776-
pub fn for_n<F>(&mut self, n: usize, function: F) -> ForNOperation<F>
776+
pub fn for_n<F>(&mut self, n: usize, function: F) -> ForNOperation<'_, F>
777777
where
778778
F: Fn(Prong) + Sync,
779779
{
@@ -810,7 +810,7 @@ impl ThreadPool {
810810
/// }
811811
/// });
812812
/// ```
813-
pub fn for_n_dynamic<F>(&mut self, n: usize, function: F) -> ForNDynamicOperation<F>
813+
pub fn for_n_dynamic<F>(&mut self, n: usize, function: F) -> ForNDynamicOperation<'_, F>
814814
where
815815
F: Fn(Prong) + Sync,
816816
{
@@ -853,7 +853,7 @@ impl ThreadPool {
853853
/// prong.thread_index, start_index, start_index + count);
854854
/// });
855855
/// ```
856-
pub fn for_slices<F>(&mut self, n: usize, function: F) -> ForSlicesOperation<F>
856+
pub fn for_slices<F>(&mut self, n: usize, function: F) -> ForSlicesOperation<'_, F>
857857
where
858858
F: Fn(Prong, usize) + Sync,
859859
{
@@ -2366,32 +2366,38 @@ impl<T> RoundRobinVec<T> {
23662366
let threads_in_colocation = pool.count_threads_in(colocation_index);
23672367
let thread_local_index = pool.locate_thread_in(thread_index, colocation_index);
23682368

2369-
if node_len > current_len {
2370-
// Growing: construct new elements in parallel
2371-
let new_elements = node_len - current_len;
2372-
let split = IndexedSplit::new(new_elements, threads_in_colocation);
2373-
let range = split.get(thread_local_index);
2374-
2375-
unsafe {
2376-
let ptr = node_vec.as_mut_ptr();
2377-
for i in range {
2378-
let idx = current_len + i;
2379-
core::ptr::write(ptr.add(idx), value.clone());
2369+
match node_len.cmp(&current_len) {
2370+
std::cmp::Ordering::Greater => {
2371+
// Growing: construct new elements in parallel
2372+
let new_elements = node_len - current_len;
2373+
let split = IndexedSplit::new(new_elements, threads_in_colocation);
2374+
let range = split.get(thread_local_index);
2375+
2376+
unsafe {
2377+
let ptr = node_vec.as_mut_ptr();
2378+
for i in range {
2379+
let idx = current_len + i;
2380+
core::ptr::write(ptr.add(idx), value.clone());
2381+
}
23802382
}
23812383
}
2382-
} else if node_len < current_len {
2383-
// Shrinking: drop elements in parallel
2384-
let elements_to_drop = current_len - node_len;
2385-
let split = IndexedSplit::new(elements_to_drop, threads_in_colocation);
2386-
let range = split.get(thread_local_index);
2387-
2388-
unsafe {
2389-
let ptr = node_vec.as_mut_ptr();
2390-
for i in range {
2391-
let idx = node_len + i;
2392-
core::ptr::drop_in_place(ptr.add(idx));
2384+
std::cmp::Ordering::Less => {
2385+
// Shrinking: drop elements in parallel
2386+
let elements_to_drop = current_len - node_len;
2387+
let split = IndexedSplit::new(elements_to_drop, threads_in_colocation);
2388+
let range = split.get(thread_local_index);
2389+
2390+
unsafe {
2391+
let ptr = node_vec.as_mut_ptr();
2392+
for i in range {
2393+
let idx = node_len + i;
2394+
core::ptr::drop_in_place(ptr.add(idx));
2395+
}
23932396
}
23942397
}
2398+
std::cmp::Ordering::Equal => {
2399+
// No change needed
2400+
}
23952401
}
23962402
}
23972403
});
@@ -2428,11 +2434,13 @@ impl<T> SafePtr<T> {
24282434
}
24292435

24302436
/// Accesses the element at the given index.
2437+
#[allow(clippy::mut_from_ref)]
24312438
pub fn get_mut_at(&self, index: usize) -> &mut T {
24322439
unsafe { &mut *self.0.add(index) }
24332440
}
24342441

24352442
/// Accesses the element.
2443+
#[allow(clippy::mut_from_ref)]
24362444
pub fn get_mut(&self) -> &mut T {
24372445
unsafe { &mut *self.0 }
24382446
}
@@ -2778,7 +2786,7 @@ where
27782786
/// The remaining chunks have size `floor(tasks / threads)`.
27792787
///
27802788
/// This ensures optimal load balancing across threads with minimal size variance.
2781-
/// See: https://lemire.me/blog/2025/05/22/dividing-an-array-into-fair-sized-chunks/
2789+
/// See: <https://lemire.me/blog/2025/05/22/dividing-an-array-into-fair-sized-chunks/>
27822790
#[derive(Debug, Clone)]
27832791
pub struct IndexedSplit {
27842792
quotient: usize,

scripts/search.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ fn create_distributed_embeddings(
6464
memory_scope_percent: usize,
6565
) -> Option<DistributedEmbeddings> {
6666
let colocations_count = fu::count_colocations();
67-
println!("Initializing storage across {} colocations", colocations_count);
67+
println!(
68+
"Initializing storage across {} colocations",
69+
colocations_count
70+
);
6871

6972
// Calculate total capacity based on total system memory and scope percentage
7073
let total_memory = fu::volume_any_pages();
@@ -371,4 +374,4 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
371374
println!("");
372375
println!("✅ Search benchmarking completed!");
373376
Ok(())
374-
}
377+
}

0 commit comments

Comments
 (0)