Conversation
This branch has not been deployed
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 verification coverage for Challenge 8 (
smallsort). The verification targets all seven functions listed by the challenge, with the main focus on the three specializedsmall_sorttrait APIs:StableSmallSortTypeImpl::small_sortUnstableSmallSortTypeImpl::small_sortUnstableSmallSortFreezeTypeImpl::small_sortswap_if_lessinsertion_sort_shift_leftsort4_stablehas_efficient_in_place_swapFor the three
small_sortAPIs, the end-to-end harnesses check:execution of the real implementation without introducing unverified stubs or path pruning,
sortedness under a valid ordering,
preservation of the input multiset,
symbolic slice lengths up to the threshold selected by the corresponding specialization.
Specialization coverage
The harnesses exercise the relevant
smallsortdispatch paths.Stable small sort
The stable implementation covers:
non-
Freezefallback sorting up to length 16,Freezegeneral sorting up to length 32,the
size_of::<T>() <= 16general path using the 8-element presort primitive,the
size_of::<T>() > 16general path using the 4-element presort primitive.The non-
Freezepath is split into separate memory-safety, sortedness, and permutation proofs to keep solver cost manageable.Unstable small sort
The unstable implementations cover:
non-
Freezefallback,Freeze + Copynetwork sorting,Freeze + Copygeneral sorting for both small and larger element sizes,Freeze + Copyoversized fallback,Freeze + !Copygeneral sorting,Freeze + !Copyoversized fallback.Equivalent specialization coverage is included for
UnstableSmallSortFreezeTypeImpldirectly.The general route is instantiated with both element sizes at or below the 16-byte presort cutoff and element sizes above that cutoff, ensuring both general-sort presort strategies are exercised.
Helper functions
swap_if_lessandsort4_stablehave explicit safety contracts and dedicatedproof_for_contractharnesses.insertion_sort_shift_leftis exercised with symbolic length and offset over the range used by the current small-sort implementations.has_efficient_in_place_swapis checked across representative zero-sized, small, large, and interior-mutable element types.Current limitations
Some full-domain proofs still exceed the current 10-minute per-harness verification budget. The length-32 Freeze/general/network paths inline several expensive operations into a single SAT instance, including presorting, insertion extension, and bidirectional merge. An full-domain Stable Freeze experiment required more than 20 minutes locally.
The next step is to investigate modular verification of the expensive internal primitives so the top-level proofs can reuse verified summaries instead of repeatedly expanding the complete implementations.
The sorting properties of the three specialized
small_sortmethods are currently expressed as end-to-end harness assertions rather than reusable Kani function postcondition contracts. Direct contracts on these specialized methods are currently limited by specialization and generic old-state handling in the pinned toolchain.No
assume(false)path pruning or unverified behavioral stubs are used to make the sorting proofs succeed.Resolves #56
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.