Verify safety of iterator adapter functions (Challenge 16)#549
Open
kasimte wants to merge 1 commit intomodel-checking:mainfrom
Open
Verify safety of iterator adapter functions (Challenge 16)#549kasimte wants to merge 1 commit intomodel-checking:mainfrom
kasimte wants to merge 1 commit intomodel-checking:mainfrom
Conversation
… and safe abstractions (Challenge 16)
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
Resolves #280 (Challenge 16: Verify the safety of Iterator functions)
Adds 72 Kani verification harnesses proving the safety of all 10 unsafe functions and all 17 safe abstractions listed in Challenge 16, across 13 iterator adapter files in
library/core/src/iter/adapters/.Approach
u8(non-ZST),()(ZST),char(4-byte with validity constraints),(char, u8)(compound with padding) — to address the generic typeTrequirementkani::slice::any_slice_of_arraywithMAX_LEN=8for arbitrary-length verification#[requires]) added where the proc macro supports it (inherent impl methods). For trait impl methods,kani::assume()preconditions are used in harnesses due to a known limitation where thesafetyproc macro cannot parseImplItemFnnext_back_remainderusesRange<u8>as inner iterator instead ofslice::Iterbecause CBMC exhausts resources on the pointer-heavy.rev().take(rem).next_chunk()adapter chain.Range<u8>still exercises the sameunwrap_err_uncheckedcode pathSafety contracts added
next_unchecked#[requires(self.it.size_hint().0 > 0)]get_unchecked#[requires(self.index + idx < self.a.size() && self.index + idx < self.b.size())]Unsafe functions verified (10/10)
__iterator_get_uncheckednext_unchecked__iterator_get_unchecked__iterator_get_unchecked__iterator_get_unchecked__iterator_get_uncheckednext_unchecked__iterator_get_unchecked__iterator_get_uncheckedget_unchecked__iterator_get_uncheckedabove)Safe abstractions verified (17/17)
next_back_remainderfoldspec_next_chunknext_chunk_droplessnext_chunkas_array_refas_uninit_array_mutpushdroporiginal_stepspec_foldspec_for_eachfoldnextnthnext_backspec_foldVerification
All 72 harnesses pass:
Run with:
Test plan
Resolves #280
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.