Generate nondeterministic reference-count state for Rc/Arc Arbitrary - #4788
Open
rbeauchamp wants to merge 1 commit into
Open
Generate nondeterministic reference-count state for Rc/Arc Arbitrary#4788rbeauchamp wants to merge 1 commit into
rbeauchamp wants to merge 1 commit into
Conversation
…odel-checking#4752) Count observers (strong_count, weak_count, get_mut, try_unwrap, make_mut) branch only on uniqueness, so the Arbitrary impls and the AnyRc/AnyArc autoharness models now leak one representative per behavioral equivalence class: strong_count in {1, 2}, weak_count in {0, 1}. Previously every generated value had strong_count == 1, so functions observing count state were 'verified' for states real callers can violate.
This was referenced Sep 8, 2026
15 tasks
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.
Description
kani::any::<Rc<T>>()/kani::any::<Arc<T>>()(and theAnyRc/AnyArcautoharness models) always produced a fresh allocation:strong_count == 1andweak_count == 0on every generated value. A function observing reference-count state could be verified for states a real caller can violate — e.g.assert_eq!(Arc::strong_count(&a), 1)passed even thoughlet _y = a.clone(); f(a)trips it at runtime. This is an input-space under-approximation (false-negative hazard) affectingstrong_count,weak_count,get_mut,try_unwrap,make_mut, etc.Design
Every documented count-dependent behavior of
Rc/Arcbranches only on uniqueness:strong_count == 1, and forget_mut/try_unwrapadditionallyweak_count == 0. The behavioral equivalence classes of real reference-count states are therefore exactly four —strong ∈ {1, ≥2} × weak ∈ {0, ≥1}— and the generator now covers all four with one representative each (strong_count ∈ {1, 2},weak_count ∈ {0, 1}) by nondeterministically leaking aclone()and/or adowngrade(). A leaked reference is observationally identical to one held by a caller for the duration of the function under verification. Generation stays loop-free, so it needs no unwinding bound, and the pointee remains fully nondeterministic.Note: this intentionally makes previously-"verified" uniqueness assertions fail — that is the soundness fix taking effect, not a regression.
Context
Surfaced in #4752 (during review of #4698). The issue offered two directions — model nondeterministic refcount state, or document the limitation; this PR implements the former, and the equivalence-class argument means the {1, 2} × {0, 1} representatives are behaviorally complete for the documented API surface rather than a lossy bound.
Manual testing
tests/kani/RefCount/nondet_rc_arc.rs(12 harnesses): count validity (strong_count >= 1), reachability of shared/weak states (#[kani::should_panic]on the old always-unique assertions — each now fails on exactly the count assertion), bothget_mutoutcomes,get_mutsucceeds underassume(unique && no weak), and extreme pointee values (kani::cover!(*rc == 255)SATISFIED) under sharing.tests/script-based-pre/cargo_autoharness_smart_pointers/witharc_count, which fails through theAnyArcmodel path onassertion failed: Arc::strong_count(&a) == 1(verifying the models carry the same semantics);.expectedupdated.FunctionContracts/receiver_contracts,SizeAndAlignOfDst,UnsizedCoercion,AsyncAwait,Drop): 28/28 pass.Resolves #4752
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.