Skip to content

Commit a8974ed

Browse files
Merge branch 'main' into daniel/byte_operation
2 parents 009c561 + 38d490c commit a8974ed

14 files changed

+414
-9
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Session.vim
2020
/book/
2121
/build/
2222
/target
23+
library/target
2324
*.rlib
2425
*.rmeta
2526
*.mir

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ See [the Rust repository](https://github.com/rust-lang/rust) for details.
4747

4848
## Introducing a New Tool
4949

50-
Please use the [template available in this repository](.github/TOOL_REQUEST_TEMPLATE.md) to introduce a new verification tool.
50+
Please use the [template available in this repository](./doc/src/tool_template.md) to introduce a new verification tool.

doc/src/SUMMARY.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
[Introduction](intro.md)
44

55
- [General Rules](./general-rules.md)
6-
- [Challenge Template](./template.md)
7-
- [Tool application](./todo.md)
6+
- [Challenge Template](./challenge_template.md)
7+
- [Tool Application Template](./tool_template.md)
88

99
- [Verification Tools](./tools.md)
1010
- [Kani](./tools/kani.md)
File renamed without changes.

doc/src/general-rules.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ A proposed solution to a verification problem will only **be reviewed** if all t
3939
* The contribution must be automated and should be checked and pass as part of the PR checks.
4040
* All tools used by the solution must be in [the list of accepted tools](tools.md#approved-tools),
4141
and previously integrated in the repository.
42-
If that is not the case, please submit a separate [tool application first](todo.md).
42+
If that is not the case, please submit a separate [tool application first](./general-rules.md#tool-applications).
4343
* There is no restriction on the number of contributors for a solution.
4444
Make sure you have the rights to submit your solution and that all contributors are properly mentioned.
4545
* The solution cannot impact the runtime logic of the standard library unless the change is proposed and incorporated
@@ -56,7 +56,7 @@ The type of obstacles users face may depend on which part of the standard librar
5656
Everyone is welcome to submit new challenge proposals for review by our committee.
5757
Follow the following steps to create a new proposal:
5858

59-
1. Create a tracking issue using the Issue template [Challenge Proposal](template.md) for your challenge.
59+
1. Create a tracking issue using the [challenge template](./challenge_template.md) for your challenge.
6060
2. In your fork of this repository do the following:
6161
1. Copy the template file (`book/src/challenge_template.md`) to `book/src/challenges/<ID_NUMBER>-<challenge-name>.md`.
6262
2. Fill in the details according to the template instructions.
@@ -69,7 +69,7 @@ Follow the following steps to create a new proposal:
6969

7070
Solutions must be automated using one of the tools previously approved and listed [here](tools.md#approved-tools):
7171

72-
* Any new tool that participants want to enable will require an application using the Issue template [Tool application](todo.md).
72+
* Any new tool that participants want to enable will require an application using the [tool application template](./tool_template.md).
7373
* The tool will be analyzed by an independent committee consisting of members from the Rust open-source developers and AWS
7474
* A new tool application should clearly specify the differences to existing techniques and provide sufficient background
7575
of why this is needed.

doc/src/todo.md

-3
This file was deleted.
File renamed without changes.

library/alloc/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ edition = "2021"
1111
[dependencies]
1212
core = { path = "../core" }
1313
compiler_builtins = { version = "0.1.123", features = ['rustc-dep-of-std'] }
14+
safety = { path = "../contracts/safety" }
1415

1516
[dev-dependencies]
1617
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }

library/alloc/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
//
9292
// Library features:
9393
// tidy-alphabetical-start
94+
#![cfg_attr(kani, feature(kani))]
9495
#![cfg_attr(not(no_global_oom_handling), feature(const_alloc_error))]
9596
#![cfg_attr(not(no_global_oom_handling), feature(const_btree_len))]
9697
#![feature(alloc_layout_extra)]

library/core/src/num/int_macros.rs

+9
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ macro_rules! int_impl {
511511
without modifying the original"]
512512
#[inline(always)]
513513
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
514+
#[requires(!self.overflowing_add(rhs).1)]
514515
pub const unsafe fn unchecked_add(self, rhs: Self) -> Self {
515516
assert_unsafe_precondition!(
516517
check_language_ub,
@@ -663,6 +664,7 @@ macro_rules! int_impl {
663664
without modifying the original"]
664665
#[inline(always)]
665666
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
667+
#[requires(!self.overflowing_sub(rhs).1)] // Preconditions: No overflow should occur
666668
pub const unsafe fn unchecked_sub(self, rhs: Self) -> Self {
667669
assert_unsafe_precondition!(
668670
check_language_ub,
@@ -815,6 +817,7 @@ macro_rules! int_impl {
815817
without modifying the original"]
816818
#[inline(always)]
817819
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
820+
#[requires(!self.overflowing_mul(rhs).1)]
818821
pub const unsafe fn unchecked_mul(self, rhs: Self) -> Self {
819822
assert_unsafe_precondition!(
820823
check_language_ub,
@@ -1164,6 +1167,8 @@ macro_rules! int_impl {
11641167
#[rustc_const_unstable(feature = "unchecked_neg", issue = "85122")]
11651168
#[inline(always)]
11661169
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1170+
#[requires(self != $SelfT::MIN)]
1171+
#[ensures(|result| *result == -self)]
11671172
pub const unsafe fn unchecked_neg(self) -> Self {
11681173
assert_unsafe_precondition!(
11691174
check_language_ub,
@@ -1297,6 +1302,7 @@ macro_rules! int_impl {
12971302
#[rustc_const_unstable(feature = "unchecked_shifts", issue = "85122")]
12981303
#[inline(always)]
12991304
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1305+
#[requires(rhs < <$ActualT>::BITS)]
13001306
pub const unsafe fn unchecked_shl(self, rhs: u32) -> Self {
13011307
assert_unsafe_precondition!(
13021308
check_language_ub,
@@ -1423,6 +1429,7 @@ macro_rules! int_impl {
14231429
#[rustc_const_unstable(feature = "unchecked_shifts", issue = "85122")]
14241430
#[inline(always)]
14251431
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
1432+
#[requires(rhs < <$ActualT>::BITS)] // i.e. requires the right hand side of the shift (rhs) to be less than the number of bits in the type. This prevents undefined behavior.
14261433
pub const unsafe fn unchecked_shr(self, rhs: u32) -> Self {
14271434
assert_unsafe_precondition!(
14281435
check_language_ub,
@@ -2153,6 +2160,7 @@ macro_rules! int_impl {
21532160
without modifying the original"]
21542161
#[inline(always)]
21552162
#[rustc_allow_const_fn_unstable(unchecked_shifts)]
2163+
#[ensures(|result| *result == self << (rhs & (Self::BITS - 1)))]
21562164
pub const fn wrapping_shl(self, rhs: u32) -> Self {
21572165
// SAFETY: the masking by the bitsize of the type ensures that we do not shift
21582166
// out of bounds
@@ -2183,6 +2191,7 @@ macro_rules! int_impl {
21832191
without modifying the original"]
21842192
#[inline(always)]
21852193
#[rustc_allow_const_fn_unstable(unchecked_shifts)]
2194+
#[ensures(|result| *result == self >> (rhs & (Self::BITS - 1)))]
21862195
pub const fn wrapping_shr(self, rhs: u32) -> Self {
21872196
// SAFETY: the masking by the bitsize of the type ensures that we do not shift
21882197
// out of bounds

0 commit comments

Comments
 (0)