Skip to content

Commit 382f541

Browse files
committed
Update Arc Kani harnesses for Result and try_update APIs
1 parent ff68475 commit 382f541

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

‎library/alloc/src/sync.rs‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5469,12 +5469,12 @@ mod kani_arc_harness_helpers {
54695469
vec
54705470
}
54715471

5472-
// Verification-only model of `fetch_update` for `Weak::upgrade`.
5472+
// Verification-only model of `try_update` for `Weak::upgrade`.
54735473
// These harnesses are single-threaded and `checked_increment` is pure, so
54745474
// retries only repeat the same state. Model them with one load and at most
54755475
// one strong CAS. This is not valid for concurrent or liveness verification.
5476-
pub(super) fn fetch_update_no_retry<F>(
5477-
atomic: &core::sync::atomic::AtomicUsize,
5476+
pub(super) fn try_update_no_retry<F>(
5477+
atomic: &core::sync::atomic::Atomic<usize>,
54785478
set_order: core::sync::atomic::Ordering,
54795479
fetch_order: core::sync::atomic::Ordering,
54805480
mut f: F,
@@ -7179,9 +7179,9 @@ mod verify {
71797179
// length is symbolic. With `N` fixed to 100, Kani explores:
71807180
// - `vec.len() == 100`: `into_array` calls `Arc::into_raw(self)`, casts the
71817181
// slice pointer to `*const [T; 100]`, rebuilds it with `Arc::from_raw`,
7182-
// and returns `Some(Arc<[T; 100]>)`.
7182+
// and returns `Ok(Arc<[T; 100]>)`.
71837183
// - `vec.len() != 100`: the length check fails, so `into_array` returns
7184-
// `None` without reinterpreting the slice pointer as an array.
7184+
// `Err(Arc<[T]>)` without reinterpreting the slice pointer as an array.
71857185

71867186
// Harness for Arc::into_array.
71877187
macro_rules! gen_arc_into_array_slice_harness {
@@ -7191,7 +7191,7 @@ mod verify {
71917191
let vec = verifier_nondet_vec_arc::<$ty>();
71927192
let arc: Arc<[$ty]> = Arc::from(vec);
71937193
const N: usize = 100;
7194-
let _: Option<Arc<[$ty; N]>> = arc.into_array::<N>();
7194+
let _: Result<Arc<[$ty; N]>, Arc<[$ty]>> = arc.into_array::<N>();
71957195
}
71967196
};
71977197
}
@@ -8690,7 +8690,7 @@ mod verify {
86908690
// Stub the whole retrying operation, not only its weak CAS, so CBMC does
86918691
// not retain the unbounded loop in the generated control-flow graph.
86928692
#[kani::proof]
8693-
#[kani::stub(core::sync::atomic::AtomicUsize::fetch_update, fetch_update_no_retry)]
8693+
#[kani::stub(core::sync::atomic::Atomic::<usize>::try_update, try_update_no_retry)]
86948694
pub fn $live() {
86958695
let strong: Arc<$ty, Global> = Arc::new_in(kani::any::<$ty>(), Global);
86968696
// Construct one explicit `Weak` without calling `Arc::downgrade`.
@@ -8710,7 +8710,7 @@ mod verify {
87108710
// With strong == 0, the update closure returns `None`, so the
87118711
// loop-free stub returns `Err(0)` without executing a CAS.
87128712
#[kani::proof]
8713-
#[kani::stub(core::sync::atomic::AtomicUsize::fetch_update, fetch_update_no_retry)]
8713+
#[kani::stub(core::sync::atomic::Atomic::<usize>::try_update, try_update_no_retry)]
87148714
pub fn $strong_zero() {
87158715
let strong: Arc<$ty, Global> = Arc::new_cyclic_in(
87168716
|weak| {
@@ -8720,7 +8720,7 @@ mod verify {
87208720
assert!(weak.inner().is_some());
87218721
assert_eq!(weak.inner().unwrap().strong.load(Relaxed), 0);
87228722
// With strong == 0, `checked_increment` returns `None`
8723-
// before `fetch_update` can execute a CAS retry.
8723+
// before `try_update` can execute a CAS retry.
87248724
let result = weak.upgrade();
87258725
assert!(result.is_none());
87268726
kani::any::<$ty>()
@@ -8734,11 +8734,11 @@ mod verify {
87348734
// A sentinel Weak returns through `self.inner()?`; applying the same
87358735
// stub keeps the unreachable retry loop out of this harness's model.
87368736
#[kani::proof]
8737-
#[kani::stub(core::sync::atomic::AtomicUsize::fetch_update, fetch_update_no_retry)]
8737+
#[kani::stub(core::sync::atomic::Atomic::<usize>::try_update, try_update_no_retry)]
87388738
pub fn $dangling() {
87398739
let weak: Weak<$ty, Global> = Weak::new_in(Global);
87408740
// A sentinel Weak must return through `self.inner()?` before
8741-
// reaching `AtomicUsize::fetch_update`.
8741+
// reaching `Atomic::<usize>::try_update`.
87428742
assert!(is_dangling(weak.ptr.as_ptr()));
87438743
assert!(weak.inner().is_none());
87448744
let result = Weak::<$ty, Global>::upgrade(&weak);
@@ -8747,11 +8747,11 @@ mod verify {
87478747
};
87488748
}
87498749

8750-
// Unsized cases use the same loop-free `fetch_update` model as the sized harnesses.
8750+
// Unsized cases use the same loop-free `try_update` model as the sized harnesses.
87518751
macro_rules! gen_weak_upgrade_unsized_harness {
87528752
($live:ident, $strong_zero:ident, $dangling:ident, $elem:ty) => {
87538753
#[kani::proof]
8754-
#[kani::stub(core::sync::atomic::AtomicUsize::fetch_update, fetch_update_no_retry)]
8754+
#[kani::stub(core::sync::atomic::Atomic::<usize>::try_update, try_update_no_retry)]
87558755
pub fn $live() {
87568756
let vec = verifier_nondet_vec_arc::<$elem>();
87578757
let strong: Arc<[$elem], Global> = Arc::from(vec);
@@ -8764,7 +8764,7 @@ mod verify {
87648764
}
87658765

87668766
#[kani::proof]
8767-
#[kani::stub(core::sync::atomic::AtomicUsize::fetch_update, fetch_update_no_retry)]
8767+
#[kani::stub(core::sync::atomic::Atomic::<usize>::try_update, try_update_no_retry)]
87688768
pub fn $strong_zero() {
87698769
let vec = verifier_nondet_vec_arc::<$elem>();
87708770
let strong: Arc<[$elem], Global> = Arc::from(vec);
@@ -8779,7 +8779,7 @@ mod verify {
87798779
}
87808780

87818781
#[kani::proof]
8782-
#[kani::stub(core::sync::atomic::AtomicUsize::fetch_update, fetch_update_no_retry)]
8782+
#[kani::stub(core::sync::atomic::Atomic::<usize>::try_update, try_update_no_retry)]
87838783
pub fn $dangling() {
87848784
let weak_arr: Weak<[$elem; 1], Global> = Weak::new_in(Global);
87858785
let weak: Weak<[$elem], Global> = weak_arr;

0 commit comments

Comments
 (0)