Skip to content

Commit 6a1cec7

Browse files
Merge branch 'main' into repeatinvariant
2 parents 2a05d06 + ffda6a8 commit 6a1cec7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+14513
-1148
lines changed

.github/workflows/flux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99

1010
env:
1111
FIXPOINT_VERSION: "556104ba5508891c357b0bdf819ce706e93d9349"
12-
FLUX_VERSION: "a17246965a8752e3d3d4e3559865311048bb61f7"
12+
FLUX_VERSION: "b0cec81c42bc6e210f675b46dd5b4b16774b0d0e"
1313

1414
jobs:
1515
check-flux-on-core:
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This workflow runs the tests for testable simd models.
2+
3+
name: Testable simd models
4+
5+
on:
6+
workflow_dispatch:
7+
merge_group:
8+
pull_request:
9+
branches: [ main ]
10+
push:
11+
paths:
12+
- '.github/workflows/testable-simd-models.yml'
13+
- 'testable-simd-models/**'
14+
15+
defaults:
16+
run:
17+
shell: bash
18+
19+
jobs:
20+
testable-simd-models:
21+
name: Test testable simd models
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- name: Checkout Repository
26+
uses: actions/checkout@v4
27+
28+
- name: Run tests
29+
working-directory: testable-simd-models
30+
run: cargo test -- --test-threads=1 --nocapture
31+

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,4 @@ goto-transcoder
5656
# already existing elements were commented out
5757

5858
#/target
59+
testable-simd-models/target

README.md

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Rust std-lib verification
1+
# Rust standard library verification
22

33
[![Rust Tests](https://github.com/model-checking/verify-rust-std/actions/workflows/rustc.yml/badge.svg)](https://github.com/model-checking/verify-rust-std/actions/workflows/rustc.yml)
44
[![Build Book](https://github.com/model-checking/verify-rust-std/actions/workflows/book.yml/badge.svg)](https://github.com/model-checking/verify-rust-std/actions/workflows/book.yml)
@@ -8,7 +8,7 @@ This repository is a fork of the official Rust programming
88
language repository, created solely to verify the Rust standard
99
library. It should not be used as an alternative to the official
1010
Rust releases. The repository is tool agnostic and welcomes the addition of
11-
new tools.
11+
new tools. The currently accepted tools are [Flux](https://model-checking.github.io/verify-rust-std/tools/flux.html), [GOTO Transcoder (ESBMC)](https://model-checking.github.io/verify-rust-std/tools/goto-transcoder.html), [Kani](https://model-checking.github.io/verify-rust-std/tools/kani.html), and [VeriFast](https://model-checking.github.io/verify-rust-std/tools/verifast.html).
1212

1313
The goal is to have a verified [Rust standard library](https://doc.rust-lang.org/std/) and prove that it is safe.
1414
1. Contributing to the core mechanism of verifying the rust standard library
@@ -21,8 +21,39 @@ memory safety and a subset of undefined behaviors in the Rust standard library.
2121
Each challenge describes the goal, the success criteria, and whether it has a financial award to be awarded upon its
2222
successful completion.
2323

24-
See [our book](https://model-checking.github.io/verify-rust-std/intro.html) for more details on the challenge rules
25-
and the list of existing challenges.
24+
These are the challenges:
25+
26+
| Challenge | Reward | Status | Proof |
27+
| --------- | ------ | ------ | ----- |
28+
| [1: Verify core transmuting methods](https://model-checking.github.io/verify-rust-std/challenges/0001-core-transmutation.html) | N/A | Open | |
29+
| [2: Verify the memory safety of core intrinsics using raw pointers](https://model-checking.github.io/verify-rust-std/challenges/0002-intrinsics-memory.html) | N/A | Open | |
30+
| [3: Verifying Raw Pointer Arithmetic Operations](https://model-checking.github.io/verify-rust-std/challenges/0003-pointer-arithmentic.html) | N/A | [Resolved](https://github.com/model-checking/verify-rust-std/pull/212) | [Kani](https://github.com/model-checking/verify-rust-std/pull/212/files) |
31+
| [4: Memory safety of BTreeMap's `btree::node` module](https://model-checking.github.io/verify-rust-std/challenges/0004-btree-node.html) | 10,000 USD | Open | |
32+
| [5: Verify functions iterating over inductive data type: `linked_list`](https://model-checking.github.io/verify-rust-std/challenges/0005-linked-list.html) | 5,000 USD | [Resolved](https://github.com/model-checking/verify-rust-std/pull/238) | [VeriFast](https://github.com/model-checking/verify-rust-std/tree/main/verifast-proofs/alloc/collections/linked_list.rs) |
33+
| [6: Safety of `NonNull`](https://model-checking.github.io/verify-rust-std/challenges/0006-nonnull.html) | N/A | [Resolved](https://github.com/model-checking/verify-rust-std/pull/247) | [Kani](https://github.com/model-checking/verify-rust-std/blob/main/library/core/src/ptr/non_null.rs) |
34+
| [7: Safety of Methods for Atomic Types & Atomic Intrinsics](https://model-checking.github.io/verify-rust-std/challenges/0007-atomic-types.html) | 10,000 USD | Open | |
35+
| [8: Contracts for SmallSort](https://model-checking.github.io/verify-rust-std/challenges/0008-smallsort.html) | 10,000 USD | Open | |
36+
| [9: Safe abstractions for `core::time::Duration`](https://model-checking.github.io/verify-rust-std/challenges/0009-duration.html) | N/A | [Resolved](https://github.com/model-checking/verify-rust-std/pull/136) | [Kani](https://github.com/model-checking/verify-rust-std/blob/main/library/core/src/time.rs) |
37+
| [10: Memory safety of String](https://model-checking.github.io/verify-rust-std/challenges/0010-string.html) | N/A | Open | |
38+
| [11: Safety of Methods for Numeric Primitive Types](https://model-checking.github.io/verify-rust-std/challenges/0011-floats-ints.html) | N/A | [Resolved](https://github.com/model-checking/verify-rust-std/issues/59) | [Kani](https://github.com/model-checking/verify-rust-std/tree/main/library/core/src/num) |
39+
| [12: Safety of `NonZero`](https://model-checking.github.io/verify-rust-std/challenges/0012-nonzero.html) | N/A | Open | |
40+
| [13: Safety of `CStr`](https://model-checking.github.io/verify-rust-std/challenges/0013-cstr.html) | N/A | Open | |
41+
| [14: Safety of Primitive Conversions](https://model-checking.github.io/verify-rust-std/challenges/0014-convert-num.html) | TBD | [Resolved](https://github.com/model-checking/verify-rust-std/pull/247) | [Kani](https://github.com/model-checking/verify-rust-std/blob/main/library/core/src/convert/num.rs) |
42+
| [15: Contracts and Tests for SIMD Intrinsics](https://model-checking.github.io/verify-rust-std/challenges/0015-intrinsics-simd.html) | | Open | |
43+
| [16: Verify the safety of Iterator functions](https://model-checking.github.io/verify-rust-std/challenges/0016-iter.html) | 10,000 USD | Open | |
44+
| [17: Verify the safety of slice functions](https://model-checking.github.io/verify-rust-std/challenges/0017-slice.html) | 10,000 USD | Open | |
45+
| [18: Verify the safety of slice iter functions](https://model-checking.github.io/verify-rust-std/challenges/0018-slice-iter.html) | 10,000 USD | Open | |
46+
| [19: Safety of `RawVec`](https://model-checking.github.io/verify-rust-std/challenges/0019-rawvec.html) | 10,000 USD | [Resolved](https://github.com/model-checking/verify-rust-std/pull/422) | [VeriFast](https://github.com/model-checking/verify-rust-std/tree/main/verifast-proofs/alloc/raw_vec/mod.rs) |
47+
| [20: Verify the safety of char-related functions in str::pattern](https://model-checking.github.io/verify-rust-std/challenges/0020-str-pattern-pt1.html) | 25,000 USD | Open | |
48+
| [21: Verify the safety of substring-related functions in str::pattern](https://model-checking.github.io/verify-rust-std/challenges/0021-str-pattern-pt2.html) | 25,000 USD | Open | |
49+
| [22: Verify the safety of str iter functions](https://model-checking.github.io/verify-rust-std/challenges/0022-str-iter.html) | 10,000 USD | Open | |
50+
| [23: Verify the safety of Vec functions part 1](https://model-checking.github.io/verify-rust-std/challenges/0023-vec-pt1.html) | 15,000 USD | Open | |
51+
| [24: Verify the safety of Vec functions part 2](https://model-checking.github.io/verify-rust-std/challenges/0024-vec-pt2.html) | 15,000 USD | Open | |
52+
| [25: Verify the safety of `VecDeque` functions](https://model-checking.github.io/verify-rust-std/challenges/0025-vecdeque.html) | 10,000 USD | Open | |
53+
| [26: Verify reference-counted Cell implementation](https://model-checking.github.io/verify-rust-std/challenges/0026-rc.html) | 10,000 USD | Open | |
54+
| [27: Verify atomically reference-counted Cell implementation](https://model-checking.github.io/verify-rust-std/challenges/0027-arc.html) | 10,000 USD | Open | |
55+
56+
See [our book](https://model-checking.github.io/verify-rust-std/intro.html) for more details on the challenge rules.
2657

2758
We welcome everyone to participate!
2859

doc/src/challenges/0001-core-transmutation.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# Challenge 1: Verify `core` transmuting methods
22

3-
- **Status:** Open
3+
- **Status:** Resolved
44
- **Tracking Issue:** [#19](https://github.com/model-checking/verify-rust-std/issues/19)
55
- **Start date:** *2024/06/12*
66
- **End date:** *2025/04/10*
77
- **Reward:** *N/A*
8+
- **Contributors**: [Alex Le Blanc](https://github.com/AlexLB99), [Patrick Lam](https://github.com/patricklam)
89

910
-------------------
1011

library/Cargo.lock

Lines changed: 6 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

library/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,3 @@ rustflags = ["-Cpanic=abort"]
5959
rustc-std-workspace-core = { path = 'rustc-std-workspace-core' }
6060
rustc-std-workspace-alloc = { path = 'rustc-std-workspace-alloc' }
6161
rustc-std-workspace-std = { path = 'rustc-std-workspace-std' }
62-
compiler_builtins = { path = "compiler-builtins/compiler-builtins" }

library/alloc/src/alloc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ unsafe extern "Rust" {
1717
#[rustc_allocator]
1818
#[rustc_nounwind]
1919
#[rustc_std_internal_symbol]
20+
#[rustc_allocator_zeroed_variant = "__rust_alloc_zeroed"]
2021
fn __rust_alloc(size: usize, align: usize) -> *mut u8;
2122
#[rustc_deallocator]
2223
#[rustc_nounwind]

library/alloc/src/collections/btree/map.rs

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,30 +40,15 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT;
4040

4141
/// An ordered map based on a [B-Tree].
4242
///
43-
/// B-Trees represent a fundamental compromise between cache-efficiency and actually minimizing
44-
/// the amount of work performed in a search. In theory, a binary search tree (BST) is the optimal
45-
/// choice for a sorted map, as a perfectly balanced BST performs the theoretical minimum amount of
46-
/// comparisons necessary to find an element (log<sub>2</sub>n). However, in practice the way this
47-
/// is done is *very* inefficient for modern computer architectures. In particular, every element
48-
/// is stored in its own individually heap-allocated node. This means that every single insertion
49-
/// triggers a heap-allocation, and every single comparison should be a cache-miss. Since these
50-
/// are both notably expensive things to do in practice, we are forced to, at the very least,
51-
/// reconsider the BST strategy.
52-
///
53-
/// A B-Tree instead makes each node contain B-1 to 2B-1 elements in a contiguous array. By doing
54-
/// this, we reduce the number of allocations by a factor of B, and improve cache efficiency in
55-
/// searches. However, this does mean that searches will have to do *more* comparisons on average.
56-
/// The precise number of comparisons depends on the node search strategy used. For optimal cache
57-
/// efficiency, one could search the nodes linearly. For optimal comparisons, one could search
58-
/// the node using binary search. As a compromise, one could also perform a linear search
59-
/// that initially only checks every i<sup>th</sup> element for some choice of i.
43+
/// Given a key type with a [total order], an ordered map stores its entries in key order.
44+
/// That means that keys must be of a type that implements the [`Ord`] trait,
45+
/// such that two keys can always be compared to determine their [`Ordering`].
46+
/// Examples of keys with a total order are strings with lexicographical order,
47+
/// and numbers with their natural order.
6048
///
61-
/// Currently, our implementation simply performs naive linear search. This provides excellent
62-
/// performance on *small* nodes of elements which are cheap to compare. However in the future we
63-
/// would like to further explore choosing the optimal search strategy based on the choice of B,
64-
/// and possibly other factors. Using linear search, searching for a random element is expected
65-
/// to take B * log(n) comparisons, which is generally worse than a BST. In practice,
66-
/// however, performance is excellent.
49+
/// Iterators obtained from functions such as [`BTreeMap::iter`], [`BTreeMap::into_iter`], [`BTreeMap::values`], or
50+
/// [`BTreeMap::keys`] produce their items in key order, and take worst-case logarithmic and
51+
/// amortized constant time per item returned.
6752
///
6853
/// It is a logic error for a key to be modified in such a way that the key's ordering relative to
6954
/// any other key, as determined by the [`Ord`] trait, changes while it is in the map. This is
@@ -72,14 +57,6 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT;
7257
/// `BTreeMap` that observed the logic error and not result in undefined behavior. This could
7358
/// include panics, incorrect results, aborts, memory leaks, and non-termination.
7459
///
75-
/// Iterators obtained from functions such as [`BTreeMap::iter`], [`BTreeMap::into_iter`], [`BTreeMap::values`], or
76-
/// [`BTreeMap::keys`] produce their items in order by key, and take worst-case logarithmic and
77-
/// amortized constant time per item returned.
78-
///
79-
/// [B-Tree]: https://en.wikipedia.org/wiki/B-tree
80-
/// [`Cell`]: core::cell::Cell
81-
/// [`RefCell`]: core::cell::RefCell
82-
///
8360
/// # Examples
8461
///
8562
/// ```
@@ -169,6 +146,43 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT;
169146
/// // modify an entry before an insert with in-place mutation
170147
/// player_stats.entry("mana").and_modify(|mana| *mana += 200).or_insert(100);
171148
/// ```
149+
///
150+
/// # Background
151+
///
152+
/// A B-tree is (like) a [binary search tree], but adapted to the natural granularity that modern
153+
/// machines like to consume data at. This means that each node contains an entire array of elements,
154+
/// instead of just a single element.
155+
///
156+
/// B-Trees represent a fundamental compromise between cache-efficiency and actually minimizing
157+
/// the amount of work performed in a search. In theory, a binary search tree (BST) is the optimal
158+
/// choice for a sorted map, as a perfectly balanced BST performs the theoretical minimum number of
159+
/// comparisons necessary to find an element (log<sub>2</sub>n). However, in practice the way this
160+
/// is done is *very* inefficient for modern computer architectures. In particular, every element
161+
/// is stored in its own individually heap-allocated node. This means that every single insertion
162+
/// triggers a heap-allocation, and every comparison is a potential cache-miss due to the indirection.
163+
/// Since both heap-allocations and cache-misses are notably expensive in practice, we are forced to,
164+
/// at the very least, reconsider the BST strategy.
165+
///
166+
/// A B-Tree instead makes each node contain B-1 to 2B-1 elements in a contiguous array. By doing
167+
/// this, we reduce the number of allocations by a factor of B, and improve cache efficiency in
168+
/// searches. However, this does mean that searches will have to do *more* comparisons on average.
169+
/// The precise number of comparisons depends on the node search strategy used. For optimal cache
170+
/// efficiency, one could search the nodes linearly. For optimal comparisons, one could search
171+
/// the node using binary search. As a compromise, one could also perform a linear search
172+
/// that initially only checks every i<sup>th</sup> element for some choice of i.
173+
///
174+
/// Currently, our implementation simply performs naive linear search. This provides excellent
175+
/// performance on *small* nodes of elements which are cheap to compare. However in the future we
176+
/// would like to further explore choosing the optimal search strategy based on the choice of B,
177+
/// and possibly other factors. Using linear search, searching for a random element is expected
178+
/// to take B * log(n) comparisons, which is generally worse than a BST. In practice,
179+
/// however, performance is excellent.
180+
///
181+
/// [B-Tree]: https://en.wikipedia.org/wiki/B-tree
182+
/// [binary search tree]: https://en.wikipedia.org/wiki/Binary_search_tree
183+
/// [total order]: https://en.wikipedia.org/wiki/Total_order
184+
/// [`Cell`]: core::cell::Cell
185+
/// [`RefCell`]: core::cell::RefCell
172186
#[stable(feature = "rust1", since = "1.0.0")]
173187
#[cfg_attr(not(test), rustc_diagnostic_item = "BTreeMap")]
174188
#[rustc_insignificant_dtor]

library/core/Cargo.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,11 @@ check-cfg = [
4747

4848
[package.metadata.flux]
4949
enabled = true
50-
include = [ "src/ascii{*.rs,/**/*.rs}" ]
50+
check_overflow = "lazy"
51+
include = [ "src/ascii*.rs",
52+
"src/num/mod.rs",
53+
"src/pat.rs",
54+
"src/bstr/*.rs",
55+
"src/hash/*.rs",
56+
"src/time.rs",
57+
]

0 commit comments

Comments
 (0)