Repository navigation
Define the alloc models in kani_core for the verify-std flow - #4863
Closed
srivatsansamraj wants to merge 2 commits into
Closed
srivatsansamraj wants to merge 2 commits into
srivatsansamraj wants to merge 2 commits into
Conversation
`kani autoharness` aborted on any crate declaring a `#[rustc_comptime]`
function -- `core` has 27 of them, so the whole standard library run died
during candidate collection:
do not use `optimized_mir` for constants: Const { allow_const_fn_promotion: false }
The const-block precondition search added in model-checking#4820 guarded its fetch with
`is_mir_available` and then called `optimized_mir`. That guard is not enough: a
`#[rustc_comptime]` function's body is a const context, which rustc's
`optimized_mir` provider refuses to serve even though the MIR is available.
`instance_mir` is rustc's own dispatcher between `optimized_mir` and
`mir_for_ctfe`, so use it rather than duplicating the choice here.
The three shapes `core` has are now covered by a test: a body-less
`#[rustc_intrinsic] #[rustc_comptime]` declaration (`intrinsics::size_of`), a
`#[rustc_comptime]` function with a body (`TypeId::trait_info_of`), and one
whose body carries a const-block precondition on a const generic. The last
matters most: switching providers must not lose the detection model-checking#4820 exists for,
and the test also pins the plain `const fn` shape that `core::escape` uses.
Resolves model-checking#4839
The `Arbitrary` implementations for `Box`, `Rc` and `Arc`, the `BoundedArbitrary` implementations for `Box<[T]>`, `Vec`, `String`, `BTreeMap` and `BTreeSet`, and the models autoharness uses for them (`any_box`, `any_rc`, `any_arc`, the unbounded slice and vector models, the `slice_validity_assume` hook) lived only in the `kani` crate. `verify-std` compiles `core`, `alloc` and `std` against `kani_core`, so none of them existed there. They move, unchanged apart from paths and formatting, into `generate_alloc_arbitrary!` in `kani_core`. The `kani` crate expands it as before, and a new `kani_lib!(alloc)` arm expands it inside `alloc`. Without a `kani` crate, `find_kani_functions` now collects the marked functions from `core` and `alloc` and merges them; the two arms define disjoint sets.
9 of 42 tasks
Contributor
Author
|
Closing in favour of #4871. |
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.
The heap models autoharness relies on now exist in the
verify-stdflow. That flow compilescore,allocandstdagainstkani_core. TheArbitraryimplementations forBox,RcandArc, theBoundedArbitraryimplementations forBox<[T]>,Vec,String,BTreeMapandBTreeSet, and their models (any_box,any_rc,any_arc, the unbounded slice and vector models, theslice_validity_assumehook) lived only in thekanicrate.kani_lib!(core)cannot define them, becausecorecannot namealloc's types.Changes:
kani_coregainsgenerate_alloc_arbitrary!, holding those items, moved fromlibrary/kaniunchanged apart from paths and formatting. Thekanicrate expands it as before. Its hidden models move fromkani::arbitrary::to the crate root, beside the other models; nothing refers to them by path.kani_lib!gains an(alloc)arm that expands it in akanimodule insidealloc.kanicrate,find_kani_functionscollects the marked functions from bothcoreandallocand merges them, since the two arms define disjoint sets. Theis_optionaldocs now say when each optional model is missing.The new test
verify_std_allocinjectskani_lib!(alloc)into a copy ofallocand runs autoharness onfirst(p: Box<Pair>)andlen(v: Vec<u8>). Both get harnesses and verify. Without the compiler change,firstis skipped for a missingArbitraryimplementation andlenasks for--bounded-arguments.The test runs
autoharness --std, which fails onmainwith #4839 until #4848 lands, so this branch includes #4848's commit. Only the last commit is new here.verify-rust-std turns this on with one line in
library/alloc/src/lib.rs,kani_core::kani_lib!(alloc);, beside the existing one forcore. Autoharness there then treatsBox,Rc,ArcandVecarguments as it already does in an ordinary crate.Resolves #4807
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.