Skip to content

Implement kani::Arbitrary for Wrapping, Saturating, and Simd types #328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions library/core/src/num/saturating.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! Definitions of `Saturating<T>`.

use crate::fmt;
#[cfg(kani)]
use crate::kani;
use crate::ops::{
Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign,
Mul, MulAssign, Neg, Not, Rem, RemAssign, Sub, SubAssign,
Expand Down Expand Up @@ -37,6 +39,14 @@ use crate::ops::{
#[rustc_diagnostic_item = "Saturating"]
pub struct Saturating<T>(#[stable(feature = "saturating_int_impl", since = "1.74.0")] pub T);

#[cfg(kani)]
#[stable(feature = "saturating_int_impl", since = "1.74.0")]
impl<T: kani::Arbitrary> kani::Arbitrary for Saturating<T> {
fn any() -> Self {
Self { 0: kani::any() }
}
}

#[stable(feature = "saturating_int_impl", since = "1.74.0")]
impl<T: fmt::Debug> fmt::Debug for Saturating<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
10 changes: 10 additions & 0 deletions library/core/src/num/wrapping.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! Definitions of `Wrapping<T>`.

use crate::fmt;
#[cfg(kani)]
use crate::kani;
use crate::ops::{
Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign,
Mul, MulAssign, Neg, Not, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign, Sub, SubAssign,
Expand Down Expand Up @@ -42,6 +44,14 @@ use crate::ops::{
#[rustc_diagnostic_item = "Wrapping"]
pub struct Wrapping<T>(#[stable(feature = "rust1", since = "1.0.0")] pub T);

#[cfg(kani)]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: kani::Arbitrary> kani::Arbitrary for Wrapping<T> {
fn any() -> Self {
Self { 0: kani::any() }
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: fmt::Debug> fmt::Debug for Wrapping<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
4 changes: 4 additions & 0 deletions library/portable-simd/crates/core_simd/src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ use crate::simd::{
ptr::{SimdConstPtr, SimdMutPtr},
};

#[cfg(kani)]
use crate::kani;

/// A SIMD vector with the shape of `[T; N]` but the operations of `T`.
///
/// `Simd<T, N>` supports the operators (+, *, etc.) that `T` does in "elementwise" fashion.
Expand Down Expand Up @@ -100,6 +103,7 @@ use crate::simd::{
// avoided, as it will likely become illegal on `#[repr(simd)]` structs in the future. It also
// causes rustc to emit illegal LLVM IR in some cases.
#[repr(simd, packed)]
#[cfg_attr(kani, derive(kani::Arbitrary))]
pub struct Simd<T, const N: usize>([T; N])
where
LaneCount<N>: SupportedLaneCount,
Expand Down
Loading