Challenge 26: verify Rc/Weak safety in alloc::rc with Kani#582
Open
v3risec wants to merge 3 commits intomodel-checking:mainfrom
Open
Challenge 26: verify Rc/Weak safety in alloc::rc with Kani#582v3risec wants to merge 3 commits intomodel-checking:mainfrom
v3risec wants to merge 3 commits intomodel-checking:mainfrom
Conversation
|
You should use macros to reduce code duplication. It'll also make review easier. |
… harnesses with rust macro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds Kani-based verification artifacts for
Rc/Weaksafety inlibrary/alloc/src/rc.rsfor Challenge 26.The change introduces:
#[cfg(kani)]for both required unsafe functions and a broad safe-function subsetRc<[T]>/Weak<[T]>paths can be exercised in a reusable wayNo non-verification runtime behavior is changed in normal builds.
Verification Coverage Report
Unsafe functions (required by Challenge 26)
Coverage: 12 / 12 (100%)
Verified set includes:
Rc<mem::MaybeUninit<T>,A>::assume_initRc<[mem::MaybeUninit<T>],A>::assume_initRc<T:?Sized>::from_rawRc<T:?Sized>::increment_strong_countRc<T:?Sized>::decrement_strong_countRc<T:?Sized,A:Allocator>::from_raw_inRc<T:?Sized,A:Allocator>::increment_strong_count_inRc<T:?Sized,A:Allocator>::decrement_strong_count_inRc<T:?Sized,A:Allocator>::get_mut_uncheckedRc<dyn Any,A:Allocator>::downcast_uncheckedWeak<T:?Sized>::from_rawWeak<T:?Sized,A:Allocator>::from_raw_inSafe functions (Challenge 26 list)
Coverage: 50 / 54 (92.6%)
This exceeds the challenge threshold (>= 75%).
Covered safe functions (50/54):
Rc<T:?Sized, A:Allocator>::innerRc<T:?Sized, A:Allocator>::into_inner_with_allocatorRc<T>::newRc<T>::new_uninitRc<T>::new_zeroedRc<T>::try_newRc<T>::try_new_uninitRc<T>::try_new_zeroedRc<T>::pinRc<T,A:Allocator>::new_uninit_inRc<T,A:Allocator>::new_zeroed_inRc<T,A:Allocator>::new_cyclic_inRc<T,A:Allocator>::try_new_inRc<T,A:Allocator>::try_new_uninit_inRc<T,A:Allocator>::try_new_zeroed_inRc<T,A:Allocator>::pin_inRc<T,A:Allocator>::try_unwrapRc<[T]>::new_uninit_sliceRc<[T]>::new_zeroed_sliceRc<[T]>::into_arrayRc<[T],A:Allocator>::new_uninit_slice_inRc<[T],A:Allocator>::new_zeroed_slice_inRc<T:?Sized,A:Allocator>::as_ptrRc<T:?Sized,A:Allocator>::get_mutRc<T:?Sized+CloneToUninit, A:Allocator+Clone>::make_mutRc<dyn Any,A:Allocator>::downcastRc<T:?Sized,A:Allocator>::from_box_inRcFromSlice<T: Copy>::from_sliceDrop<T: ?Sized, A:Allocator>::drop for RcClone<T: ?Sized, A:Allocator>::clone for RcDefault<T:Default>::defaultDefault<str>::defaultFrom<&str>::fromFrom<Vec<T,A:Allocator>>::fromFrom<Rc<str>>::fromToRcSlice<T, I>::to_rc_sliceWeak<T:?Sized,A:Allocator>::as_ptrWeak<T:?Sized,A:Allocator>::into_raw_with_allocatorWeak<T:?Sized,A:Allocator>::innerDrop<T:?Sized, A:Allocator>::drop for WeakRcInnerPtr::inc_strongRcInnerPtr::inc_weakUniqueRc<T:?Sized,A:Allocator>::into_rcUniqueRc<T:?Sized,A:Allocator+Clone>::downgradeDeref<T:?Sized,A:Allocator>::derefDerefMut<T:?Sized,A:Allocator>::deref_mutDrop<T:?Sized, A:Allocator>::drop for UniqueRcUniqueRcUninit<T:?Sized, A:Allocator>::newUniqueRcUninit<T:?Sized, A:Allocator>::data_ptrDrop<T:?Sized, A:Allocator>::drop for UniqueRcUninitNot yet listed as standalone harness targets (4/54):
Rc<T:?Sized,A:Allocator>::into_raw_with_allocatorRcFromSlice<T: Clone>::from_sliceTryFrom<Rc<[T],A:Allocator>>::try_fromWeak<T:?Sized,A:Allocator>::upgradeThree Criteria Met (Challenge 26)
Tis instantiated with allowed representative concrete types, and allocator-focused proofs are limited to standard-library allocator scope (Global).Approach
The verification strategy combines contracts for unsafe entry points with executable proof harnesses:
kani::requirespreconditions for pointer validity, alignment soundness, same-allocation checks, and refcount well-formedness.kani::ensures) and mutation footprints (kani::modifies) for refcount-changing operations.#[kani::proof]and#[kani::proof_for_contract()]modules for each required unsafe function and safe function coverage.?Sizedslice-based APIs.Rc<[T]>/Weak<[T]>constructions without duplicating per-harness setup logic.cfg(kani)so normal std behavior is unchanged.Scope assumptions (per challenge allowance)
i32,u8,u64,bool,(),String, arrays/slices,str, and trait objects (dyn Any).Global(both explicitRc<_, Global>/Weak<_, Global>and implicit defaultRc/Weak).Verification
All harnesses pass locally with Kani 0.65.
Resolves #382
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.