From 2dcec734301045aba3550cb63aaa0198120850da Mon Sep 17 00:00:00 2001 From: Shourya Goel <114918019+Sh0g0-1758@users.noreply.github.com> Date: Tue, 17 Oct 2023 22:14:08 +0530 Subject: [PATCH 1/5] [simd] Add trait positive/negative impl tests (#487) --- src/lib.rs | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index c317bc7a70..f2e4f3c923 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4835,5 +4835,58 @@ mod tests { assert_impls!([NotZerocopy; 0]: !FromZeroes, !FromBytes, !AsBytes, !Unaligned); assert_impls!([u8; 1]: FromZeroes, FromBytes, AsBytes, Unaligned); assert_impls!([NotZerocopy; 1]: !FromZeroes, !FromBytes, !AsBytes, !Unaligned); + + #[cfg(feature = "simd")] + { + macro_rules! test_simd_arch_mod { + ($arch:ident, $($typ:ident),*) => { + { + use core::arch::$arch::{$($typ),*}; + use crate::*; + $( assert_impls!($typ: KnownLayout, FromZeroes, FromBytes, AsBytes, !Unaligned); )* + } + }; + } + #[cfg(target_arch = "x86")] + test_simd_arch_mod!(x86, __m128, __m128d, __m128i, __m256, __m256d, __m256i); + + #[cfg(target_arch = "x86_64")] + test_simd_arch_mod!(x86_64, __m128, __m128d, __m128i, __m256, __m256d, __m256i); + + #[cfg(target_arch = "wasm32")] + test_simd_arch_mod!(wasm32, v128); + + #[cfg(all(feature = "simd-nightly", target_arch = "powerpc"))] + test_simd_arch_mod!( + powerpc, + vector_bool_long, + vector_double, + vector_signed_long, + vector_unsigned_long + ); + + #[cfg(all(feature = "simd-nightly", target_arch = "powerpc64"))] + test_simd_arch_mod!( + powerpc64, + vector_bool_long, + vector_double, + vector_signed_long, + vector_unsigned_long + ); + #[cfg(target_arch = "aarch64")] + #[rustfmt::skip] + test_simd_arch_mod!( + aarch64, float32x2_t, float32x4_t, float64x1_t, float64x2_t, int8x8_t, int8x8x2_t, + int8x8x3_t, int8x8x4_t, int8x16_t, int8x16x2_t, int8x16x3_t, int8x16x4_t, int16x4_t, + int16x8_t, int32x2_t, int32x4_t, int64x1_t, int64x2_t, poly8x8_t, poly8x8x2_t, poly8x8x3_t, + poly8x8x4_t, poly8x16_t, poly8x16x2_t, poly8x16x3_t, poly8x16x4_t, poly16x4_t, poly16x8_t, + poly64x1_t, poly64x2_t, uint8x8_t, uint8x8x2_t, uint8x8x3_t, uint8x8x4_t, uint8x16_t, + uint8x16x2_t, uint8x16x3_t, uint8x16x4_t, uint16x4_t, uint16x8_t, uint32x2_t, uint32x4_t, + uint64x1_t, uint64x2_t + ); + #[cfg(all(feature = "simd-nightly", target_arch = "arm"))] + #[rustfmt::skip] + test_simd_arch_mod!(arm, int8x4_t, uint8x4_t); + } } } From cfc5f9aadbc010203fa5752bd32df5ad9fc341ef Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 18 Oct 2023 08:08:21 -0700 Subject: [PATCH 2/5] [CI] Bump actions/checkout from 4.1.0 to 4.1.1 (#518) Bumps [actions/checkout](https://github.com/actions/checkout) from 4.1.0 to 4.1.1. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/8ade135a41bc03ea155e62e844d188df1ea18608...b4ffde65f46336ab88eb53be808477a3936bae11) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/ci.yml | 14 +++++++------- .github/workflows/dependency-review.yml | 2 +- .../workflows/roll-pinned-toolchain-versions.yml | 2 +- .github/workflows/scorecard.yml | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 03e1dbbe86..ec531c0296 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,7 +71,7 @@ jobs: name: Build & Test (crate:${{ matrix.crate }}, toolchain:${{ matrix.toolchain }}, target:${{ matrix.target }}, features:${{ matrix.features }}) steps: - - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - uses: actions/cache@v3 with: @@ -236,7 +236,7 @@ jobs: runs-on: ubuntu-latest name: 'Run tests under Kani' steps: - - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - uses: model-checking/kani-github-action@v1.0 with: args: "--package zerocopy --all-features --output-format=terse --randomize-layout --memory-safety-checks --overflow-checks --undefined-function-checks --unwinding-checks" @@ -245,7 +245,7 @@ jobs: runs-on: ubuntu-latest name: Check Rust formatting steps: - - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Check Rust formatting run: | set -eo pipefail @@ -260,7 +260,7 @@ jobs: runs-on: ubuntu-latest name: Check README.md steps: - - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - uses: actions/cache@v3 with: @@ -285,7 +285,7 @@ jobs: runs-on: ubuntu-latest name: Check MSRVs match steps: - - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - uses: actions/cache@v3 with: @@ -328,7 +328,7 @@ jobs: runs-on: ubuntu-latest name: Check crate versions match steps: - - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - uses: actions/cache@v3 with: @@ -403,7 +403,7 @@ jobs: runs-on: ubuntu-latest name: Generate cache steps: - - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - uses: actions/cache@v3 with: diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index dc49c09bca..104d2718a3 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -22,6 +22,6 @@ jobs: egress-policy: audit - name: 'Checkout Repository' - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: 'Dependency Review' uses: actions/dependency-review-action@6c5ccdad469c9f8a2996bfecaec55a631a347034 # v3.1.0 diff --git a/.github/workflows/roll-pinned-toolchain-versions.yml b/.github/workflows/roll-pinned-toolchain-versions.yml index 89b41bacb9..bc480b4007 100644 --- a/.github/workflows/roll-pinned-toolchain-versions.yml +++ b/.github/workflows/roll-pinned-toolchain-versions.yml @@ -24,7 +24,7 @@ jobs: name: Roll pinned toolchain ${{ matrix.toolchain }} version steps: - name: Checkout code - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: ref: main persist-credentials: false diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml index 122c38b417..87d7bca16d 100644 --- a/.github/workflows/scorecard.yml +++ b/.github/workflows/scorecard.yml @@ -29,7 +29,7 @@ jobs: steps: - name: "Checkout code" - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: persist-credentials: false From 0642560dd92d70faa338fbb4033e96c8969c8ffa Mon Sep 17 00:00:00 2001 From: Google PR Creation Bot <145818923+google-pr-creation-bot@users.noreply.github.com> Date: Wed, 18 Oct 2023 08:08:58 -0700 Subject: [PATCH 3/5] [ci] Roll pinned nightly toolchain (#517) --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 6f804e50f0..1285a01c66 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ all-features = true [package.metadata.ci] # The versions of the stable and nightly compiler toolchains to use in CI. pinned-stable = "1.73.0" -pinned-nightly = "nightly-2023-10-16" +pinned-nightly = "nightly-2023-10-17" [features] default = ["byteorder"] From 0da18dae45242a4afa768b307e098a80aa336d94 Mon Sep 17 00:00:00 2001 From: Joshua Liebow-Feeser Date: Wed, 18 Oct 2023 09:21:16 -0700 Subject: [PATCH 4/5] Improve test_new_aligned_sized to catch more bugs (#511) In #506, a bug was discovered which `test_new_aligned_sized` did not previously catch. This commit improves that test to catch that bug. --- src/lib.rs | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f2e4f3c923..6c35a63dd2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4196,7 +4196,8 @@ mod tests { let mut buf = Align::<[u8; 8], AU64>::default(); // `buf.t` should be aligned to 8, so this should always succeed. test_new_helper(Ref::<_, AU64>::new(&mut buf.t[..]).unwrap()); - buf.t = [0xFFu8; 8]; + let ascending: [u8; 8] = (0..8).collect::>().try_into().unwrap(); + buf.t = ascending; test_new_helper(Ref::<_, AU64>::new_zeroed(&mut buf.t[..]).unwrap()); { // In a block so that `r` and `suffix` don't live too long. @@ -4206,7 +4207,7 @@ mod tests { test_new_helper(r); } { - buf.t = [0xFFu8; 8]; + buf.t = ascending; let (r, suffix) = Ref::<_, AU64>::new_from_prefix_zeroed(&mut buf.t[..]).unwrap(); assert!(suffix.is_empty()); test_new_helper(r); @@ -4218,46 +4219,54 @@ mod tests { test_new_helper(r); } { - buf.t = [0xFFu8; 8]; + buf.t = ascending; let (prefix, r) = Ref::<_, AU64>::new_from_suffix_zeroed(&mut buf.t[..]).unwrap(); assert!(prefix.is_empty()); test_new_helper(r); } - // A buffer with alignment 8 and length 16. - let mut buf = Align::<[u8; 16], AU64>::default(); + // A buffer with alignment 8 and length 24. We choose this length very + // intentionally: if we instead used length 16, then the prefix and + // suffix lengths would be identical. In the past, we used length 16, + // which resulted in this test failing to discover the bug uncovered in + // #506. + let mut buf = Align::<[u8; 24], AU64>::default(); // `buf.t` should be aligned to 8 and have a length which is a multiple // of `size_of::()`, so this should always succeed. - test_new_helper_slice(Ref::<_, [AU64]>::new_slice(&mut buf.t[..]).unwrap(), 2); - buf.t = [0xFFu8; 16]; - test_new_helper_slice(Ref::<_, [AU64]>::new_slice_zeroed(&mut buf.t[..]).unwrap(), 2); + test_new_helper_slice(Ref::<_, [AU64]>::new_slice(&mut buf.t[..]).unwrap(), 3); + let ascending: [u8; 24] = (0..24).collect::>().try_into().unwrap(); + // 16 ascending bytes followed by 8 zeros. + let mut ascending_prefix = ascending; + ascending_prefix[16..].copy_from_slice(&[0, 0, 0, 0, 0, 0, 0, 0]); + // 8 zeros followed by 16 ascending bytes. + let mut ascending_suffix = ascending; + ascending_suffix[..8].copy_from_slice(&[0, 0, 0, 0, 0, 0, 0, 0]); + test_new_helper_slice(Ref::<_, [AU64]>::new_slice_zeroed(&mut buf.t[..]).unwrap(), 3); { - buf.set_default(); - buf.t[8..].fill(0xFF); + buf.t = ascending_suffix; let (r, suffix) = Ref::<_, [AU64]>::new_slice_from_prefix(&mut buf.t[..], 1).unwrap(); - assert_eq!(suffix, [0xFF; 8]); + assert_eq!(suffix, &ascending[8..]); test_new_helper_slice(r, 1); } { - buf.t = [0xFFu8; 16]; + buf.t = ascending_suffix; let (r, suffix) = Ref::<_, [AU64]>::new_slice_from_prefix_zeroed(&mut buf.t[..], 1).unwrap(); - assert_eq!(suffix, [0xFF; 8]); + assert_eq!(suffix, &ascending[8..]); test_new_helper_slice(r, 1); } { - buf.set_default(); - buf.t[..8].fill(0xFF); + buf.t = ascending_prefix; let (prefix, r) = Ref::<_, [AU64]>::new_slice_from_suffix(&mut buf.t[..], 1).unwrap(); - assert_eq!(prefix, [0xFF; 8]); + assert_eq!(prefix, &ascending[..16]); test_new_helper_slice(r, 1); } { - buf.t = [0xFFu8; 16]; + buf.t = ascending_prefix; let (prefix, r) = Ref::<_, [AU64]>::new_slice_from_suffix_zeroed(&mut buf.t[..], 1).unwrap(); - assert_eq!(prefix, [0xFF; 8]); + assert_eq!(prefix, &ascending[..16]); test_new_helper_slice(r, 1); } } From 14416a5007759fdcf4c95779bc1073657e0a068a Mon Sep 17 00:00:00 2001 From: Joshua Liebow-Feeser Date: Wed, 18 Oct 2023 10:51:21 -0700 Subject: [PATCH 5/5] [ci] Work around Miri bug on aarch64 targets (#519) Works around https://github.com/rust-lang/miri/issues/3125 --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ec531c0296..82a58357b7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -171,6 +171,9 @@ jobs: - name: Run tests under Miri run: | + # Work around https://github.com/rust-lang/miri/issues/3125 + [ "${{ matrix.target }}" == "aarch64-unknown-linux-gnu" ] && cargo clean + # Run under both the stacked borrows model (default) and under the tree # borrows model to ensure we're compliant with both. for EXTRA_FLAGS in "" "-Zmiri-tree-borrows"; do