Skip to content

Commit 0c569a7

Browse files
committed
Merge remote-tracking branch 'origin/main' into alloc-rs-contracts
2 parents 8fef60f + f804a33 commit 0c569a7

File tree

211 files changed

+3833
-2202
lines changed

Some content is hidden

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

211 files changed

+3833
-2202
lines changed

.github/workflows/kani-metrics.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
python-version: '3.x'
2727

2828
- name: Compute Kani Metrics
29-
run: ./scripts/run-kani.sh --run metrics --path ${{github.workspace}}
29+
run: ./scripts/run-kani.sh --run metrics --with-autoharness --path ${{github.workspace}}
3030

3131
- name: Create Pull Request
3232
uses: peter-evans/create-pull-request@v7

.github/workflows/kani.yml

Lines changed: 84 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,58 @@ jobs:
7373
with:
7474
submodules: true
7575

76-
# Step 2: Run Kani on the std library for selected functions
76+
# Step 2: Run Kani autoharness on the std library for selected functions.
77+
# Uses "--include-pattern" to make sure we do not try to run across all
78+
# possible functions as that may take a lot longer than expected. Instead,
79+
# explicitly list all functions (or prefixes thereof) the proofs of which
80+
# are known to pass.
7781
- name: Run Kani Verification
7882
run: |
79-
scripts/run-kani.sh --kani-args \
83+
scripts/run-kani.sh --run autoharness --kani-args \
8084
--include-pattern alloc::__default_lib_allocator:: \
85+
--include-pattern alloc::layout::Layout::from_size_align \
86+
--include-pattern ascii::ascii_char::AsciiChar::from_u8 \
87+
--include-pattern char::convert::from_u32_unchecked \
88+
--include-pattern "num::nonzero::NonZero::<i8>::count_ones" \
89+
--include-pattern "num::nonzero::NonZero::<i16>::count_ones" \
90+
--include-pattern "num::nonzero::NonZero::<i32>::count_ones" \
91+
--include-pattern "num::nonzero::NonZero::<i64>::count_ones" \
92+
--include-pattern "num::nonzero::NonZero::<i128>::count_ones" \
93+
--include-pattern "num::nonzero::NonZero::<isize>::count_ones" \
94+
--include-pattern "num::nonzero::NonZero::<u8>::count_ones" \
95+
--include-pattern "num::nonzero::NonZero::<u16>::count_ones" \
96+
--include-pattern "num::nonzero::NonZero::<u32>::count_ones" \
97+
--include-pattern "num::nonzero::NonZero::<u64>::count_ones" \
98+
--include-pattern "num::nonzero::NonZero::<u128>::count_ones" \
99+
--include-pattern "num::nonzero::NonZero::<usize>::count_ones" \
100+
--include-pattern "num::nonzero::NonZero::<i8>::rotate_" \
101+
--include-pattern "num::nonzero::NonZero::<i16>::rotate_" \
102+
--include-pattern "num::nonzero::NonZero::<i32>::rotate_" \
103+
--include-pattern "num::nonzero::NonZero::<i64>::rotate_" \
104+
--include-pattern "num::nonzero::NonZero::<i128>::rotate_" \
105+
--include-pattern "num::nonzero::NonZero::<isize>::rotate_" \
106+
--include-pattern "num::nonzero::NonZero::<u8>::rotate_" \
107+
--include-pattern "num::nonzero::NonZero::<u16>::rotate_" \
108+
--include-pattern "num::nonzero::NonZero::<u32>::rotate_" \
109+
--include-pattern "num::nonzero::NonZero::<u64>::rotate_" \
110+
--include-pattern "num::nonzero::NonZero::<u128>::rotate_" \
111+
--include-pattern "num::nonzero::NonZero::<usize>::rotate_" \
112+
--include-pattern ptr::align_offset::mod_inv \
113+
--include-pattern ptr::alignment::Alignment::as_nonzero \
114+
--include-pattern ptr::alignment::Alignment::as_usize \
115+
--include-pattern ptr::alignment::Alignment::log2 \
116+
--include-pattern ptr::alignment::Alignment::mask \
117+
--include-pattern ptr::alignment::Alignment::new \
118+
--include-pattern ptr::alignment::Alignment::new_unchecked \
119+
--include-pattern time::Duration::from_micros \
120+
--include-pattern time::Duration::from_millis \
121+
--include-pattern time::Duration::from_nanos \
122+
--include-pattern time::Duration::from_secs \
123+
--exclude-pattern time::Duration::from_secs_f \
124+
--include-pattern unicode::unicode_data::conversions::to_ \
125+
--exclude-pattern ::precondition_check \
126+
--harness-timeout 5m \
127+
--default-unwind 1000 \
81128
--jobs=3 --output-format=terse
82129
83130
run-kani-list:
@@ -93,8 +140,14 @@ jobs:
93140

94141
# Step 2: Run list on the std library
95142
- name: Run Kani List
96-
run: head/scripts/run-kani.sh --run list --path ${{github.workspace}}/head
97-
143+
run: |
144+
head/scripts/run-kani.sh --run list --with-autoharness --path ${{github.workspace}}/head
145+
# remove duplicate white space to reduce file size (GitHub permits at
146+
# most one 1MB)
147+
ls -l ${{github.workspace}}/head/kani-list.md
148+
perl -p -i -e 's/ +/ /g' ${{github.workspace}}/head/kani-list.md
149+
ls -l ${{github.workspace}}/head/kani-list.md
150+
98151
# Step 3: Add output to job summary
99152
- name: Add Kani List output to job summary
100153
uses: actions/github-script@v6
@@ -106,3 +159,30 @@ jobs:
106159
.addHeading('Kani List Output', 2)
107160
.addRaw(kaniOutput, false)
108161
.write();
162+
163+
run-autoharness-analyzer:
164+
name: Kani Autoharness Analyzer
165+
runs-on: ubuntu-latest
166+
steps:
167+
# Step 1: Check out the repository
168+
- name: Checkout Repository
169+
uses: actions/checkout@v4
170+
with:
171+
submodules: true
172+
173+
# Step 2: Run autoharness analyzer on the std library
174+
- name: Run Autoharness Analyzer
175+
run: scripts/run-kani.sh --run autoharness-analyzer
176+
177+
# Step 3: Add output to job summary
178+
- name: Add Autoharness Analyzer output to job summary
179+
run: |
180+
echo "# Autoharness Failure Summary" >> "$GITHUB_STEP_SUMMARY"
181+
echo "## Crate core, all functions" >> "$GITHUB_STEP_SUMMARY"
182+
cat autoharness_analyzer/core_autoharness_data.md >> "$GITHUB_STEP_SUMMARY"
183+
echo "## Crate core, unsafe functions" >> "$GITHUB_STEP_SUMMARY"
184+
cat autoharness_analyzer/core_autoharness_data.md >> "$GITHUB_STEP_SUMMARY"
185+
echo "## Crate std, all functions" >> "$GITHUB_STEP_SUMMARY"
186+
cat autoharness_analyzer/std_autoharness_data.md >> "$GITHUB_STEP_SUMMARY"
187+
echo "## Crate std, unsafe functions" >> "$GITHUB_STEP_SUMMARY"
188+
cat autoharness_analyzer/std_unsafe_autoharness_data.md >> "$GITHUB_STEP_SUMMARY"

doc/src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@
3131
- [15: Contracts and Tests for SIMD Intrinsics](./challenges/0015-intrinsics-simd.md)
3232
- [16: Verify the safety of Iterator functions](./challenges/0016-iter.md)
3333
- [17: Verify the safety of slice functions](./challenges/0017-slice.md)
34-
- [18: Verify the safety of slice iter functions](./challenges/0018-slice-iter-pt1.md)
34+
- [18: Verify the safety of slice iter functions](./challenges/0018-slice-iter.md)

library/Cargo.lock

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

library/alloc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ bench = false
1616

1717
[dependencies]
1818
core = { path = "../core", public = true }
19-
compiler_builtins = { version = "=0.1.152", features = ['rustc-dep-of-std'] }
2019
safety = { path = "../contracts/safety" }
20+
compiler_builtins = { version = "=0.1.156", features = ['rustc-dep-of-std'] }
2121

2222
[features]
2323
compiler-builtins-mem = ['compiler_builtins/mem']

library/alloc/src/alloc.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ unsafe extern "Rust" {
1616
// otherwise.
1717
#[rustc_allocator]
1818
#[rustc_nounwind]
19-
#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
19+
#[rustc_std_internal_symbol]
2020
fn __rust_alloc(size: usize, align: usize) -> *mut u8;
2121
#[rustc_deallocator]
2222
#[rustc_nounwind]
23-
#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
23+
#[rustc_std_internal_symbol]
2424
fn __rust_dealloc(ptr: *mut u8, size: usize, align: usize);
2525
#[rustc_reallocator]
2626
#[rustc_nounwind]
27-
#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
27+
#[rustc_std_internal_symbol]
2828
fn __rust_realloc(ptr: *mut u8, old_size: usize, align: usize, new_size: usize) -> *mut u8;
2929
#[rustc_allocator_zeroed]
3030
#[rustc_nounwind]
31-
#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
31+
#[rustc_std_internal_symbol]
3232
fn __rust_alloc_zeroed(size: usize, align: usize) -> *mut u8;
3333

34-
#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
34+
#[rustc_std_internal_symbol]
3535
static __rust_no_alloc_shim_is_unstable: u8;
3636
}
3737

@@ -360,7 +360,7 @@ unsafe extern "Rust" {
360360
// This is the magic symbol to call the global alloc error handler. rustc generates
361361
// it to call `__rg_oom` if there is a `#[alloc_error_handler]`, or to call the
362362
// default implementations below (`__rdl_oom`) otherwise.
363-
#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
363+
#[rustc_std_internal_symbol]
364364
fn __rust_alloc_error_handler(size: usize, align: usize) -> !;
365365
}
366366

@@ -427,7 +427,7 @@ pub mod __alloc_error_handler {
427427
unsafe extern "Rust" {
428428
// This symbol is emitted by rustc next to __rust_alloc_error_handler.
429429
// Its value depends on the -Zoom={panic,abort} compiler option.
430-
#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
430+
#[rustc_std_internal_symbol]
431431
static __rust_alloc_error_handler_should_panic: u8;
432432
}
433433

library/alloc/src/boxed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
952952
/// assert_eq!(*x, i);
953953
/// }
954954
/// ```
955-
#[stable(feature = "box_uninit_write", since = "CURRENT_RUSTC_VERSION")]
955+
#[stable(feature = "box_uninit_write", since = "1.87.0")]
956956
#[inline]
957957
pub fn write(mut boxed: Self, value: T) -> Box<T, A> {
958958
unsafe {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub(super) struct SetValZST;
99
/// Returns `true` only for type `SetValZST`, `false` for all other types (blanket implementation).
1010
/// `TypeId` requires a `'static` lifetime, use of this trait avoids that restriction.
1111
///
12-
/// [`TypeId`]: std::any::TypeId
12+
/// [`TypeId`]: core::any::TypeId
1313
pub(super) trait IsSetVal {
1414
fn is_set_val() -> bool;
1515
}

library/alloc/src/collections/linked_list.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,7 @@ impl<T, A: Allocator> LinkedList<T, A> {
11511151
/// assert_eq!(evens.into_iter().collect::<Vec<_>>(), vec![2, 4, 6, 8, 14]);
11521152
/// assert_eq!(odds.into_iter().collect::<Vec<_>>(), vec![1, 3, 5, 9, 11, 13, 15]);
11531153
/// ```
1154-
#[stable(feature = "extract_if", since = "CURRENT_RUSTC_VERSION")]
1154+
#[stable(feature = "extract_if", since = "1.87.0")]
11551155
pub fn extract_if<F>(&mut self, filter: F) -> ExtractIf<'_, T, F, A>
11561156
where
11571157
F: FnMut(&mut T) -> bool,
@@ -1931,7 +1931,7 @@ impl<'a, T, A: Allocator> CursorMut<'a, T, A> {
19311931
}
19321932

19331933
/// An iterator produced by calling `extract_if` on LinkedList.
1934-
#[stable(feature = "extract_if", since = "CURRENT_RUSTC_VERSION")]
1934+
#[stable(feature = "extract_if", since = "1.87.0")]
19351935
#[must_use = "iterators are lazy and do nothing unless consumed"]
19361936
pub struct ExtractIf<
19371937
'a,
@@ -1946,7 +1946,7 @@ pub struct ExtractIf<
19461946
old_len: usize,
19471947
}
19481948

1949-
#[stable(feature = "extract_if", since = "CURRENT_RUSTC_VERSION")]
1949+
#[stable(feature = "extract_if", since = "1.87.0")]
19501950
impl<T, F, A: Allocator> Iterator for ExtractIf<'_, T, F, A>
19511951
where
19521952
F: FnMut(&mut T) -> bool,
@@ -1975,7 +1975,7 @@ where
19751975
}
19761976
}
19771977

1978-
#[stable(feature = "extract_if", since = "CURRENT_RUSTC_VERSION")]
1978+
#[stable(feature = "extract_if", since = "1.87.0")]
19791979
impl<T: fmt::Debug, F> fmt::Debug for ExtractIf<'_, T, F> {
19801980
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19811981
f.debug_tuple("ExtractIf").field(&self.list).finish()

library/alloc/src/ffi/c_str.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ impl CString {
574574
#[stable(feature = "as_c_str", since = "1.20.0")]
575575
#[rustc_diagnostic_item = "cstring_as_c_str"]
576576
pub fn as_c_str(&self) -> &CStr {
577-
&*self
577+
unsafe { CStr::from_bytes_with_nul_unchecked(self.as_bytes_with_nul()) }
578578
}
579579

580580
/// Converts this `CString` into a boxed [`CStr`].
@@ -705,14 +705,14 @@ impl ops::Deref for CString {
705705

706706
#[inline]
707707
fn deref(&self) -> &CStr {
708-
unsafe { CStr::from_bytes_with_nul_unchecked(self.as_bytes_with_nul()) }
708+
self.as_c_str()
709709
}
710710
}
711711

712712
#[stable(feature = "rust1", since = "1.0.0")]
713713
impl fmt::Debug for CString {
714714
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
715-
fmt::Debug::fmt(&**self, f)
715+
fmt::Debug::fmt(self.as_c_str(), f)
716716
}
717717
}
718718

@@ -1116,7 +1116,7 @@ impl CStr {
11161116
/// with the corresponding <code>&[str]</code> slice. Otherwise, it will
11171117
/// replace any invalid UTF-8 sequences with
11181118
/// [`U+FFFD REPLACEMENT CHARACTER`][U+FFFD] and return a
1119-
/// <code>[Cow]::[Owned]\(&[str])</code> with the result.
1119+
/// <code>[Cow]::[Owned]\([String])</code> with the result.
11201120
///
11211121
/// [str]: prim@str "str"
11221122
/// [Borrowed]: Cow::Borrowed

0 commit comments

Comments
 (0)