Skip to content

Commit 3e4e13c

Browse files
Merge pull request #368 from rust-lang/remove-generic-const-exprs
Remove `generic_const_exprs`
2 parents d21ba25 + afe28b1 commit 3e4e13c

File tree

11 files changed

+149
-118
lines changed

11 files changed

+149
-118
lines changed

.github/workflows/ci.yml

+4-8
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ jobs:
238238
run: cross test --verbose --target=${{ matrix.target }} --release
239239

240240
features:
241-
name: "Check cargo features (${{ matrix.simd }} × ${{ matrix.features }})"
241+
name: "Test cargo features (${{ matrix.simd }} × ${{ matrix.features }})"
242242
runs-on: ubuntu-latest
243243
strategy:
244244
fail-fast: false
@@ -249,12 +249,8 @@ jobs:
249249
features:
250250
- ""
251251
- "--features std"
252-
- "--features generic_const_exprs"
253-
- "--features std --features generic_const_exprs"
254252
- "--features all_lane_counts"
255-
- "--features all_lane_counts --features std"
256-
- "--features all_lane_counts --features generic_const_exprs"
257-
- "--features all_lane_counts --features std --features generic_const_exprs"
253+
- "--all-features"
258254

259255
steps:
260256
- uses: actions/checkout@v2
@@ -266,9 +262,9 @@ jobs:
266262
run: echo "CPU_FEATURE=$(lscpu | grep -o avx512[a-z]* | sed s/avx/+avx/ | tr '\n' ',' )" >> $GITHUB_ENV
267263
- name: Check build
268264
if: ${{ matrix.simd == '' }}
269-
run: RUSTFLAGS="-Dwarnings" cargo check --all-targets --no-default-features ${{ matrix.features }}
265+
run: RUSTFLAGS="-Dwarnings" cargo test --all-targets --no-default-features ${{ matrix.features }}
270266
- name: Check AVX
271267
if: ${{ matrix.simd == 'avx512' && contains(env.CPU_FEATURE, 'avx512') }}
272268
run: |
273269
echo "Found AVX features: $CPU_FEATURE"
274-
RUSTFLAGS="-Dwarnings -Ctarget-feature=$CPU_FEATURE" cargo check --all-targets --no-default-features ${{ matrix.features }}
270+
RUSTFLAGS="-Dwarnings -Ctarget-feature=$CPU_FEATURE" cargo test --all-targets --no-default-features ${{ matrix.features }}

crates/core_simd/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ license = "MIT OR Apache-2.0"
1212
default = ["as_crate"]
1313
as_crate = []
1414
std = []
15-
generic_const_exprs = []
1615
all_lane_counts = []
1716

1817
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]

crates/core_simd/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
strict_provenance,
1515
ptr_metadata
1616
)]
17-
#![cfg_attr(feature = "generic_const_exprs", feature(generic_const_exprs))]
18-
#![cfg_attr(feature = "generic_const_exprs", allow(incomplete_features))]
1917
#![warn(missing_docs, clippy::missing_inline_in_public_items)] // basically all items, really
2018
#![deny(unsafe_op_in_unsafe_fn, clippy::undocumented_unsafe_blocks)]
2119
#![allow(internal_features)]

crates/core_simd/src/masks.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
mod mask_impl;
1414

1515
mod to_bitmask;
16-
pub use to_bitmask::ToBitMask;
17-
18-
#[cfg(feature = "generic_const_exprs")]
19-
pub use to_bitmask::{bitmask_len, ToBitMaskArray};
16+
pub use to_bitmask::{ToBitMask, ToBitMaskArray};
2017

2118
use crate::simd::{intrinsics, LaneCount, Simd, SimdElement, SimdPartialEq, SupportedLaneCount};
2219
use core::cmp::Ordering;

crates/core_simd/src/masks/bitmask.rs

-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ where
119119
unsafe { Self(intrinsics::simd_bitmask(value), PhantomData) }
120120
}
121121

122-
#[cfg(feature = "generic_const_exprs")]
123122
#[inline]
124123
#[must_use = "method returns a new array and does not mutate the original value"]
125124
pub fn to_bitmask_array<const N: usize>(self) -> [u8; N] {
@@ -129,7 +128,6 @@ where
129128
unsafe { core::mem::transmute_copy(&self.0) }
130129
}
131130

132-
#[cfg(feature = "generic_const_exprs")]
133131
#[inline]
134132
#[must_use = "method returns a new mask and does not mutate the original value"]
135133
pub fn from_bitmask_array<const N: usize>(bitmask: [u8; N]) -> Self {

crates/core_simd/src/masks/full_masks.rs

+7-18
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
//! Masks that take up full SIMD vector registers.
22
3-
use super::MaskElement;
3+
use super::{to_bitmask::ToBitMaskArray, MaskElement};
44
use crate::simd::intrinsics;
55
use crate::simd::{LaneCount, Simd, SupportedLaneCount, ToBitMask};
66

7-
#[cfg(feature = "generic_const_exprs")]
8-
use crate::simd::ToBitMaskArray;
9-
107
#[repr(transparent)]
118
pub struct Mask<T, const LANES: usize>(Simd<T, LANES>)
129
where
@@ -145,23 +142,19 @@ where
145142
unsafe { Mask(intrinsics::simd_cast(self.0)) }
146143
}
147144

148-
#[cfg(feature = "generic_const_exprs")]
149145
#[inline]
150146
#[must_use = "method returns a new array and does not mutate the original value"]
151147
pub fn to_bitmask_array<const N: usize>(self) -> [u8; N]
152148
where
153149
super::Mask<T, LANES>: ToBitMaskArray,
154-
[(); <super::Mask<T, LANES> as ToBitMaskArray>::BYTES]: Sized,
155150
{
156-
assert_eq!(<super::Mask<T, LANES> as ToBitMaskArray>::BYTES, N);
157-
158-
// Safety: N is the correct bitmask size
151+
// Safety: Bytes is the right size array
159152
unsafe {
160153
// Compute the bitmask
161-
let bitmask: [u8; <super::Mask<T, LANES> as ToBitMaskArray>::BYTES] =
154+
let bitmask: <super::Mask<T, LANES> as ToBitMaskArray>::BitMaskArray =
162155
intrinsics::simd_bitmask(self.0);
163156

164-
// Transmute to the return type, previously asserted to be the same size
157+
// Transmute to the return type
165158
let mut bitmask: [u8; N] = core::mem::transmute_copy(&bitmask);
166159

167160
// LLVM assumes bit order should match endianness
@@ -175,17 +168,13 @@ where
175168
}
176169
}
177170

178-
#[cfg(feature = "generic_const_exprs")]
179171
#[inline]
180172
#[must_use = "method returns a new mask and does not mutate the original value"]
181173
pub fn from_bitmask_array<const N: usize>(mut bitmask: [u8; N]) -> Self
182174
where
183175
super::Mask<T, LANES>: ToBitMaskArray,
184-
[(); <super::Mask<T, LANES> as ToBitMaskArray>::BYTES]: Sized,
185176
{
186-
assert_eq!(<super::Mask<T, LANES> as ToBitMaskArray>::BYTES, N);
187-
188-
// Safety: N is the correct bitmask size
177+
// Safety: Bytes is the right size array
189178
unsafe {
190179
// LLVM assumes bit order should match endianness
191180
if cfg!(target_endian = "big") {
@@ -194,8 +183,8 @@ where
194183
}
195184
}
196185

197-
// Transmute to the bitmask type, previously asserted to be the same size
198-
let bitmask: [u8; <super::Mask<T, LANES> as ToBitMaskArray>::BYTES] =
186+
// Transmute to the bitmask
187+
let bitmask: <super::Mask<T, LANES> as ToBitMaskArray>::BitMaskArray =
199188
core::mem::transmute_copy(&bitmask);
200189

201190
// Compute the regular mask

crates/core_simd/src/masks/to_bitmask.rs

+43-30
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::{mask_impl, Mask, MaskElement};
22
use crate::simd::{LaneCount, SupportedLaneCount};
3+
use core::borrow::{Borrow, BorrowMut};
34

45
mod sealed {
56
pub trait Sealed {}
@@ -30,19 +31,26 @@ pub trait ToBitMask: Sealed {
3031
/// Converts masks to and from byte array bitmasks.
3132
///
3233
/// Each bit of the bitmask corresponds to a mask lane, starting with the LSB of the first byte.
33-
#[cfg(feature = "generic_const_exprs")]
3434
pub trait ToBitMaskArray: Sealed {
35-
/// The length of the bitmask array.
36-
const BYTES: usize;
35+
/// The bitmask array.
36+
type BitMaskArray: Copy
37+
+ Unpin
38+
+ Send
39+
+ Sync
40+
+ AsRef<[u8]>
41+
+ AsMut<[u8]>
42+
+ Borrow<[u8]>
43+
+ BorrowMut<[u8]>
44+
+ 'static;
3745

3846
/// Converts a mask to a bitmask.
39-
fn to_bitmask_array(self) -> [u8; Self::BYTES];
47+
fn to_bitmask_array(self) -> Self::BitMaskArray;
4048

4149
/// Converts a bitmask to a mask.
42-
fn from_bitmask_array(bitmask: [u8; Self::BYTES]) -> Self;
50+
fn from_bitmask_array(bitmask: Self::BitMaskArray) -> Self;
4351
}
4452

45-
macro_rules! impl_integer_intrinsic {
53+
macro_rules! impl_integer {
4654
{ $(impl ToBitMask<BitMask=$int:ty> for Mask<_, $lanes:literal>)* } => {
4755
$(
4856
impl<T: MaskElement> ToBitMask for Mask<T, $lanes> {
@@ -62,7 +70,27 @@ macro_rules! impl_integer_intrinsic {
6270
}
6371
}
6472

65-
impl_integer_intrinsic! {
73+
macro_rules! impl_array {
74+
{ $(impl ToBitMaskArray<Bytes=$int:literal> for Mask<_, $lanes:literal>)* } => {
75+
$(
76+
impl<T: MaskElement> ToBitMaskArray for Mask<T, $lanes> {
77+
type BitMaskArray = [u8; $int];
78+
79+
#[inline]
80+
fn to_bitmask_array(self) -> Self::BitMaskArray {
81+
self.0.to_bitmask_array()
82+
}
83+
84+
#[inline]
85+
fn from_bitmask_array(bitmask: Self::BitMaskArray) -> Self {
86+
Self(mask_impl::Mask::from_bitmask_array(bitmask))
87+
}
88+
}
89+
)*
90+
}
91+
}
92+
93+
impl_integer! {
6694
impl ToBitMask<BitMask=u8> for Mask<_, 1>
6795
impl ToBitMask<BitMask=u8> for Mask<_, 2>
6896
impl ToBitMask<BitMask=u8> for Mask<_, 4>
@@ -72,27 +100,12 @@ impl_integer_intrinsic! {
72100
impl ToBitMask<BitMask=u64> for Mask<_, 64>
73101
}
74102

75-
/// Returns the minimum number of bytes in a bitmask with `lanes` lanes.
76-
#[cfg(feature = "generic_const_exprs")]
77-
#[allow(clippy::missing_inline_in_public_items)]
78-
pub const fn bitmask_len(lanes: usize) -> usize {
79-
(lanes + 7) / 8
80-
}
81-
82-
#[cfg(feature = "generic_const_exprs")]
83-
impl<T: MaskElement, const LANES: usize> ToBitMaskArray for Mask<T, LANES>
84-
where
85-
LaneCount<LANES>: SupportedLaneCount,
86-
{
87-
const BYTES: usize = bitmask_len(LANES);
88-
89-
#[inline]
90-
fn to_bitmask_array(self) -> [u8; Self::BYTES] {
91-
self.0.to_bitmask_array()
92-
}
93-
94-
#[inline]
95-
fn from_bitmask_array(bitmask: [u8; Self::BYTES]) -> Self {
96-
Mask(mask_impl::Mask::from_bitmask_array(bitmask))
97-
}
103+
impl_array! {
104+
impl ToBitMaskArray<Bytes=1> for Mask<_, 1>
105+
impl ToBitMaskArray<Bytes=1> for Mask<_, 2>
106+
impl ToBitMaskArray<Bytes=1> for Mask<_, 4>
107+
impl ToBitMaskArray<Bytes=1> for Mask<_, 8>
108+
impl ToBitMaskArray<Bytes=2> for Mask<_, 16>
109+
impl ToBitMaskArray<Bytes=4> for Mask<_, 32>
110+
impl ToBitMaskArray<Bytes=8> for Mask<_, 64>
98111
}

crates/core_simd/src/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ mod swizzle;
33

44
pub(crate) mod intrinsics;
55

6-
#[cfg(feature = "generic_const_exprs")]
7-
mod to_bytes;
8-
96
mod alias;
107
mod cast;
118
mod elements;
@@ -18,6 +15,7 @@ mod ops;
1815
mod ord;
1916
mod select;
2017
mod swizzle_dyn;
18+
mod to_bytes;
2119
mod vector;
2220
mod vendor;
2321

@@ -37,5 +35,6 @@ pub mod simd {
3735
pub use crate::core_simd::ord::*;
3836
pub use crate::core_simd::swizzle::*;
3937
pub use crate::core_simd::swizzle_dyn::*;
38+
pub use crate::core_simd::to_bytes::ToBytes;
4039
pub use crate::core_simd::vector::*;
4140
}

0 commit comments

Comments
 (0)