Skip to content

Commit

Permalink
Fix warnings for Rust 1.60.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
n3vu0r committed May 28, 2023
1 parent 8701241 commit 9eb1723
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/insertion_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ impl<T> Drop for InsertionHole<'_, T> {

/// Inserts `v[v.len() - 1]` into pre-sorted sequence `v[..v.len() - 1]` so that whole `v[..]`
/// becomes sorted.
#[warn(unsafe_op_in_unsafe_fn)]
unsafe fn insert_tail<T, F>(mut v: ArrayViewMut1<'_, T>, is_less: &mut F)
where
F: FnMut(&T, &T) -> bool,
Expand Down Expand Up @@ -96,6 +97,7 @@ where
/// Inserts `v[0]` into pre-sorted sequence `v[1..]` so that whole `v[..]` becomes sorted.
///
/// This is the integral subroutine of insertion sort.
#[warn(unsafe_op_in_unsafe_fn)]
unsafe fn insert_head<T, F>(mut v: ArrayViewMut1<'_, T>, is_less: &mut F)
where
F: FnMut(&T, &T) -> bool,
Expand Down
2 changes: 2 additions & 0 deletions src/par/insertion_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use ndarray::{s, ArrayViewMut1, IndexLonger};

/// Inserts `v[v.len() - 1]` into pre-sorted sequence `v[..v.len() - 1]` so that whole `v[..]`
/// becomes sorted.
#[warn(unsafe_op_in_unsafe_fn)]
unsafe fn insert_tail<T, F>(mut v: ArrayViewMut1<'_, T>, is_less: &F)
where
F: Fn(&T, &T) -> bool,
Expand Down Expand Up @@ -63,6 +64,7 @@ where
/// Inserts `v[0]` into pre-sorted sequence `v[1..]` so that whole `v[..]` becomes sorted.
///
/// This is the integral subroutine of insertion sort.
#[warn(unsafe_op_in_unsafe_fn)]
unsafe fn insert_head<T, F>(mut v: ArrayViewMut1<'_, T>, is_less: &F)
where
F: Fn(&T, &T) -> bool,
Expand Down
34 changes: 22 additions & 12 deletions src/par/merge_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ where
///
/// Even if `is_less` panics at any point during the merge process, this function will fully copy
/// all elements from `left` and `right` into `dest` (not necessarily in sorted order).
#[warn(unsafe_op_in_unsafe_fn)]
unsafe fn par_merge<T, F>(
mut left: ArrayViewMut1<'_, T>,
mut right: ArrayViewMut1<'_, T>,
Expand Down Expand Up @@ -585,10 +586,14 @@ unsafe fn par_merge<T, F>(
// Consume the lesser side.
// If equal, prefer the left run to maintain stability.
if is_less(&s.right[s.right_start], &s.left[s.left_start]) {
ptr::copy_nonoverlapping(&s.right[s.right_start], &mut s.dest[s.dest_start], 1);
unsafe {
ptr::copy_nonoverlapping(&s.right[s.right_start], &mut s.dest[s.dest_start], 1)
};
s.right_start += 1;
} else {
ptr::copy_nonoverlapping(&s.left[s.left_start], &mut s.dest[s.dest_start], 1);
unsafe {
ptr::copy_nonoverlapping(&s.left[s.left_start], &mut s.dest[s.dest_start], 1)
};
s.left_start += 1;
};
s.dest_start += 1;
Expand All @@ -615,8 +620,8 @@ unsafe fn par_merge<T, F>(
//let dest_r = SendPtr(dest.add(left_l.len() + right_l.len()));
let (dest_l, dest_r) = dest.split_at(Axis(0), left_l.len() + right_l.len());
rayon::join(
move || par_merge(left_l, right_l, dest_l, is_less),
move || par_merge(left_r, right_r, dest_r, is_less),
move || unsafe { par_merge(left_l, right_l, dest_l, is_less) },
move || unsafe { par_merge(left_r, right_r, dest_r, is_less) },
);
}
// Finally, `s` gets dropped if we used sequential merge, thus copying the remaining elements
Expand Down Expand Up @@ -680,6 +685,7 @@ unsafe fn par_merge<T, F>(
/// must equal the left bound of the following chunk.
///
/// The buffer must be at least as long as `v`.
#[warn(unsafe_op_in_unsafe_fn)]
unsafe fn recurse<T, F>(
mut v: ArrayViewMut1<'_, T>,
mut buf: ArrayViewMut1<'_, T>,
Expand All @@ -704,7 +710,7 @@ unsafe fn recurse<T, F>(
//let src = v.add(start);
//let dest = buf.add(start);
for i in start..end {
ptr::copy_nonoverlapping(&v[i], &mut buf[i], 1);
unsafe { ptr::copy_nonoverlapping(&v[i], &mut buf[i], 1) };
}
}
return;
Expand Down Expand Up @@ -750,14 +756,18 @@ unsafe fn recurse<T, F>(
//let buf = SendPtr(buf);
rayon::join(
move || {
recurse(
v_left, buf_left, /*v.get(), buf.get(),*/ left, !into_buf, is_less,
)
unsafe {
recurse(
v_left, buf_left, /*v.get(), buf.get(),*/ left, !into_buf, is_less,
)
}
},
move || {
recurse(
v_right, buf_right, /*v.get(), buf.get(),*/ right, !into_buf, is_less,
)
unsafe {
recurse(
v_right, buf_right, /*v.get(), buf.get(),*/ right, !into_buf, is_less,
)
}
},
);

Expand All @@ -770,7 +780,7 @@ unsafe fn recurse<T, F>(
//let src_right = slice::from_raw_parts_mut(src.add(mid), end - mid);
//par_merge(src_left, src_right, dest.add(start), is_less);
let (src_left, src_right) = src.multi_slice_mut((s![start..mid], s![mid..end]));
par_merge(src_left, src_right, dest.slice_mut(s![start..]), is_less);
unsafe { par_merge(src_left, src_right, dest.slice_mut(s![start..]), is_less) };

/// When dropped, copies from `src` into `dest` a sequence of length `len`.
struct CopyOnDrop<'a, T> {
Expand Down

0 comments on commit 9eb1723

Please sign in to comment.