Repository navigation
Let alloc define the Kani models for its own types - #4871
feliperodri wants to merge 1 commit into
Conversation
`kani verify-std` compiles `core`, `alloc` and `std` against `kani_core`, and the only way to inject Kani definitions is `kani_lib!(core)`. `core` cannot name `Vec`, so no amount of work in `core::kani` can give autoharness a way to make one up, and every std function taking an `alloc` container is skipped for a missing `Arbitrary`/`BoundedArbitrary` implementation. Add a `kani_lib!(alloc)` arm that defines the implementations and models needing `alloc`'s types, and move them out of `library/kani` into `kani_core` so both flows expand one definition: `Arbitrary` for `Box`/`Rc`/`Arc`, `BoundedArbitrary` for `Vec`/`String`/`Box<[T]>`/`BTreeMap`/`BTreeSet`, and the `any_box`/`any_rc`/`any_arc`/`any_vec_unbounded`/`any_slice_*_unbounded` models with the `slice_validity_assume` hook they rely on. `find_kani_functions` stopped at the first crate with any marked function, so markers defined in `alloc` would have been ignored even once they existed; it now collects from every crate it looks at, keeping the first definition of each. The `verify-std` test gains a phase that injects `kani_lib!(alloc)` and verifies a `Vec` and a `Box` harness inside `alloc` itself. The regular `cargo kani` flow is unchanged: `autoharness --list` reports the same support for `Vec`, `String`, `Box`, `Rc`, `Arc`, `BTreeMap`, `Box<[T]>` and `&[T]` arguments as before the move. Towards model-checking#4807
|
#4863 does the same thing, so it's closed. #4863's test runs On the dependency: Scope: agree on leaving all three out; we'll send the For |
Draft — I want feedback on the shape before polishing. Takes the approach @srivatsansamraj proposed in #4807.
Why
When we verify the standard library, autoharness can't make up a
Vecor aString, so it skips every function that takes one. The models aren't missing — they're inlibrary/kani— butverify-stdbuildscore/alloc/stdagainstkani_core, and the only hook iskani_lib!(core).corecan't nameVec, so there's no way in. That's a blind spot in the containers most std code is actually about, in the one flow where we're trying to verify all of std.What's here
A
kani_lib!(alloc)arm, and the alloc-dependent definitions moved out oflibrary/kaniintokani_coreso both flows expand the same source:ArbitraryforBox/Rc/Arc,BoundedArbitraryforVec/String/Box<[T]>/BTreeMap/BTreeSet, and theany_vec_unbounded/any_slice_*_unbounded/any_box/any_rc/any_arcmodels. Plus one compiler fix:find_kani_functionsstopped at the first crate with any marked function, so anything defined inallocwould have been ignored even once it existed.On verify-rust-std's side this is two lines in
alloc/src/lib.rs: thekanifeature gate and the macro call.What I'd like input on
Is the
(alloc)arm the right seam? It works — the test injects it into a real std copy and both aVecand aBoxharness verify insidealloc— but it meanskani_corenow has a macro whose body only makes sense in one specific crate, andkani_lib!(alloc)silently depends onkani_lib!(core)having run. If you'd rather see that dependency expressed some other way, now's the time.Scope. I deliberately left three things out and want to know if any of them belong here:
kani::vec::any_vec(public API, #4027 is deprecating it anyway); thenondet_fn*models (missing from verify-std too, but nothing to do withalloc); andHashMap/HashSet, which needstd, i.e. akani_lib!(std)arm that doesn't exist yet.Risk
The move is the risky part, not the new arm —
library/kaniis what regularcargo kaniusers get, and I've relocated ~350 lines of it. So I checked rather than assumed:autoharness --liston a probe crate takingVec<i32>,&Vec<i32>,&mut Vec<i32>,String,Box<i32>,Rc<i32>,Arc<i32>,Box<[i32]>,BTreeMap<i32, i32>and&[i32]produces byte-identical output before and after. Everything else is additive.Two things worth knowing
This unlocks by-value arguments, not
&mut Vec<T>. The issue counts ~120Vecmethods, but most take&mut self, and a reference to aBoundedArbitrarytype isn't supported today — that's true in the regular flow too, not something this PR introduces. Closing that needs the same treatment slices get (generate the value, hand out a reference to it), which I'd do separately. So think of this as the prerequisite, with the by-value functions (Vec::into_iter,String::into_bytes, and thealloc/stdfunctions taking these by value) as the immediate win.I couldn't get a full-std
autoharness --listto compare against the issue's numbers. Two unrelated ICEs get in the way: the one #4848 fixes, and an assertion inintrinsics.rs:243while compilingproc_macro(assertion failed: matches!(output.kind(), RigidTy::Int(I32))). Identical with and without this change, so it isn't mine — I'll file the second one. Theverify-stdtest is what actually demonstrates the models resolving in the no-core flow.Suites: kani 611, expected 478, ui 152, cargo-kani 71, cargo-ui 30, script-based-pre 76 — all passing, plus fmt, clippy and the unit tests.
Towards #4807