Skip to content

Commit dacc2d5

Browse files
authored
Derive Arbitrary for various core_arch::x86 types (#348)
This enables autoharness to generate an additional 4067 harnesses (and successfully prove 363 of them). Using a patch instead of directly modifying the source code here for `library/stdarch` is a git submodule. Modifying the source code directly would require forking that other repository, tweaking our submodule pointer, and thereby causing additional challenges for our fork update automation. The long-term solution should be automated derive-arbitrary support in autoharness. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
1 parent e00a6b9 commit dacc2d5

File tree

4 files changed

+68
-2
lines changed

4 files changed

+68
-2
lines changed

.github/workflows/goto-transcoder.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ jobs:
2727
uses: actions/checkout@v4
2828
with:
2929
submodules: true
30+
- name: Apply stdarch patch
31+
run: cd library/stdarch && patch -p1 < ../../stdarch.patch
3032

3133
# Step 2: Generate contracts programs
3234
- name: Generate contracts

.github/workflows/kani-metrics.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ jobs:
1818
uses: actions/checkout@v4
1919
with:
2020
submodules: true
21-
21+
- name: Apply stdarch patch
22+
run: cd library/stdarch && patch -p1 < ../../stdarch.patch
23+
2224
# The Kani metrics collection uses a Python script (kani_std_analysis.py), so make sure Python is installed
2325
- name: Set up Python
2426
uses: actions/setup-python@v4

.github/workflows/kani.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ jobs:
4343
with:
4444
path: head
4545
submodules: true
46-
46+
- name: Apply stdarch patch
47+
run: cd head/library/stdarch && patch -p1 < ../../stdarch.patch
48+
4749
# Step 2: Install jq
4850
- name: Install jq
4951
if: matrix.os == 'ubuntu-latest'
@@ -72,6 +74,8 @@ jobs:
7274
uses: actions/checkout@v4
7375
with:
7476
submodules: true
77+
- name: Apply stdarch patch
78+
run: cd library/stdarch && patch -p1 < ../../stdarch.patch
7579

7680
# Step 2: Run Kani autoharness on the std library for selected functions.
7781
# Uses "--include-pattern" to make sure we do not try to run across all
@@ -82,6 +86,8 @@ jobs:
8286
# - We use >::disjoint_bitor (and >::unchecked_disjoint_bitor) as pattern
8387
# as whitespace is not supported, cf.
8488
# https://github.com/model-checking/kani/issues/4046
89+
# - core_arch::x86::__m128d::as_f64x2 is just one example of hundreds of
90+
# core_arch::x86:: functions that are known to verify successfully.
8591
- name: Run Kani Verification
8692
run: |
8793
scripts/run-kani.sh --run autoharness --kani-args \
@@ -91,6 +97,7 @@ jobs:
9197
--include-pattern alloc::layout::Layout::from_size_align \
9298
--include-pattern ascii::ascii_char::AsciiChar::from_u8 \
9399
--include-pattern char::convert::from_u32_unchecked \
100+
--include-pattern core_arch::x86::__m128d::as_f64x2 \
94101
--include-pattern "num::nonzero::NonZero::<i8>::count_ones" \
95102
--include-pattern "num::nonzero::NonZero::<i16>::count_ones" \
96103
--include-pattern "num::nonzero::NonZero::<i32>::count_ones" \
@@ -257,6 +264,8 @@ jobs:
257264
with:
258265
path: head
259266
submodules: true
267+
- name: Apply stdarch patch
268+
run: cd head/library/stdarch && patch -p1 < ../../stdarch.patch
260269

261270
# Step 2: Run list on the std library
262271
- name: Run Kani List
@@ -289,6 +298,8 @@ jobs:
289298
uses: actions/checkout@v4
290299
with:
291300
submodules: true
301+
- name: Apply stdarch patch
302+
run: cd library/stdarch && patch -p1 < ../../stdarch.patch
292303

293304
# Step 2: Run autoharness analyzer on the std library
294305
- name: Run Autoharness Analyzer

stdarch.patch

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
--- a/crates/core_arch/src/aarch64/neon/mod.rs
2+
+++ b/crates/core_arch/src/aarch64/neon/mod.rs
3+
@@ -2,6 +2,9 @@
4+
5+
#![allow(non_camel_case_types)]
6+
7+
+#[cfg(kani)]
8+
+use crate::kani;
9+
+
10+
#[rustfmt::skip]
11+
mod generated;
12+
#[rustfmt::skip]
13+
--- a/crates/core_arch/src/arm_shared/neon/mod.rs
14+
+++ b/crates/core_arch/src/arm_shared/neon/mod.rs
15+
@@ -1,5 +1,8 @@
16+
//! ARMv7 NEON intrinsics
17+
18+
+#[cfg(kani)]
19+
+use crate::kani;
20+
+
21+
#[rustfmt::skip]
22+
mod generated;
23+
#[rustfmt::skip]
24+
--- a/crates/core_arch/src/macros.rs
25+
+++ b/crates/core_arch/src/macros.rs
26+
@@ -128,6 +128,15 @@ macro_rules! types {
27+
}
28+
}
29+
30+
+ #[cfg(kani)]
31+
+ $(#[$stability])+
32+
+ impl kani::Arbitrary for $name {
33+
+ fn any() -> Self {
34+
+ let data: [$elem_type; $len] = kani::any();
35+
+ Self { 0: data }
36+
+ }
37+
+ }
38+
+
39+
$(#[$stability])+
40+
impl crate::fmt::Debug for $name {
41+
#[inline]
42+
--- a/crates/core_arch/src/x86/mod.rs
43+
+++ b/crates/core_arch/src/x86/mod.rs
44+
@@ -1,5 +1,7 @@
45+
//! `x86` and `x86_64` intrinsics.
46+
47+
+#[cfg(kani)]
48+
+use crate::kani;
49+
use crate::mem::transmute;
50+
51+
#[macro_use]

0 commit comments

Comments
 (0)