Skip to content

Commit a85b118

Browse files
committed
Derive Arbitrary for various core_arch::x86 types
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.
1 parent f804a33 commit a85b118

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-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: 13 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 library/stdarch && patch -p1 < ../../stdarch.patch
48+
4749
# Step 2: Install jq
4850
- name: Install jq
4951
if: matrix.os == 'ubuntu-latest'
@@ -72,18 +74,24 @@ 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
7882
# possible functions as that may take a lot longer than expected. Instead,
7983
# explicitly list all functions (or prefixes thereof) the proofs of which
8084
# are known to pass.
85+
# Notes:
86+
# - core_arch::x86::__m128d::as_f64x2 is just one example of hundreds of
87+
# core_arch::x86:: functions that are known to verify successfully.
8188
- name: Run Kani Verification
8289
run: |
8390
scripts/run-kani.sh --run autoharness --kani-args \
8491
--include-pattern alloc::layout::Layout::from_size_align \
8592
--include-pattern ascii::ascii_char::AsciiChar::from_u8 \
8693
--include-pattern char::convert::from_u32_unchecked \
94+
--include-pattern core_arch::x86::__m128d::as_f64x2 \
8795
--include-pattern "num::nonzero::NonZero::<i8>::count_ones" \
8896
--include-pattern "num::nonzero::NonZero::<i16>::count_ones" \
8997
--include-pattern "num::nonzero::NonZero::<i32>::count_ones" \
@@ -136,6 +144,8 @@ jobs:
136144
with:
137145
path: head
138146
submodules: true
147+
- name: Apply stdarch patch
148+
run: cd head/library/stdarch && patch -p1 < ../../stdarch.patch
139149

140150
# Step 2: Run list on the std library
141151
- name: Run Kani List
@@ -168,6 +178,8 @@ jobs:
168178
uses: actions/checkout@v4
169179
with:
170180
submodules: true
181+
- name: Apply stdarch patch
182+
run: cd library/stdarch && patch -p1 < ../../stdarch.patch
171183

172184
# Step 2: Run autoharness analyzer on the std library
173185
- name: Run Autoharness Analyzer

stdarch.patch

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
diff --git a/crates/core_arch/src/macros.rs b/crates/core_arch/src/macros.rs
2+
index f59e278b..f3d33636 100644
3+
--- a/crates/core_arch/src/macros.rs
4+
+++ b/crates/core_arch/src/macros.rs
5+
@@ -128,6 +128,15 @@ macro_rules! types {
6+
}
7+
}
8+
9+
+ #[cfg(kani)]
10+
+ $(#[$stability])+
11+
+ impl kani::Arbitrary for $name {
12+
+ fn any() -> Self {
13+
+ let data: [$elem_type; $len] = kani::any();
14+
+ Self { 0: data }
15+
+ }
16+
+ }
17+
+
18+
$(#[$stability])+
19+
impl crate::fmt::Debug for $name {
20+
#[inline]
21+
diff --git a/crates/core_arch/src/x86/mod.rs b/crates/core_arch/src/x86/mod.rs
22+
index 0404b194..d57d1fc8 100644
23+
--- a/crates/core_arch/src/x86/mod.rs
24+
+++ b/crates/core_arch/src/x86/mod.rs
25+
@@ -1,5 +1,7 @@
26+
//! `x86` and `x86_64` intrinsics.
27+
28+
+#[cfg(kani)]
29+
+use crate::kani;
30+
use crate::mem::transmute;
31+
32+
#[macro_use]

0 commit comments

Comments
 (0)