Skip to content
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

Update zerovec!/zeroslice! macro syntax to nested arrays #3611

Merged
merged 3 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions components/collator/src/elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ pub(crate) const FFFD_CE32: CollationElement32 = CollationElement32(FFFD_CE32_VA

pub(crate) const EMPTY_U16: &ZeroSlice<u16> = zeroslice![];
const SINGLE_REPLACEMENT_CHARACTER_U16: &ZeroSlice<u16> =
zeroslice![u16; <u16 as AsULE>::ULE::from_unsigned; REPLACEMENT_CHARACTER as u16];
zeroslice!(u16; <u16 as AsULE>::ULE::from_unsigned; [REPLACEMENT_CHARACTER as u16]);

pub(crate) const EMPTY_CHAR: &ZeroSlice<char> = zeroslice![];
const SINGLE_REPLACEMENT_CHARACTER_CHAR: &ZeroSlice<char> =
zeroslice![char; <char as AsULE>::ULE::from_aligned; REPLACEMENT_CHARACTER];
zeroslice!(char; <char as AsULE>::ULE::from_aligned; [REPLACEMENT_CHARACTER]);

/// If `opt` is `Some`, unwrap it. If `None`, panic if debug assertions
/// are enabled and return `default` if debug assertions are not enabled.
Expand Down
4 changes: 2 additions & 2 deletions components/collator/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ const _: () = {
};

const SINGLE_U32: &ZeroSlice<u32> =
zeroslice![u32; <u32 as AsULE>::ULE::from_unsigned; FFFD_CE32_VALUE];
zeroslice!(u32; <u32 as AsULE>::ULE::from_unsigned; [FFFD_CE32_VALUE]);
const SINGLE_U64: &ZeroSlice<u64> =
zeroslice![u64; <u64 as AsULE>::ULE::from_unsigned; FFFD_CE_VALUE];
zeroslice!(u64; <u64 as AsULE>::ULE::from_unsigned; [FFFD_CE_VALUE]);

fn data_ce_to_primary(data_ce: u64, c: char) -> u32 {
// Collation::getThreeBytePrimaryForOffsetData
Expand Down
4 changes: 2 additions & 2 deletions components/collections/src/codepointinvlist/cpinvlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ const BMP_MAX: u32 = 0xFFFF;

/// Represents the inversion list for a set of all code points in the Basic Multilingual Plane.
const BMP_INV_LIST_VEC: ZeroVec<u32> =
zerovec![u32; <u32 as AsULE>::ULE::from_unsigned; 0x0, BMP_MAX + 1];
zerovec!(u32; <u32 as AsULE>::ULE::from_unsigned; [0x0, BMP_MAX + 1]);

/// Represents the inversion list for all of the code points in the Unicode range.
const ALL_VEC: ZeroVec<u32> =
zerovec![u32; <u32 as AsULE>::ULE::from_unsigned; 0x0, (char::MAX as u32) + 1];
zerovec!(u32; <u32 as AsULE>::ULE::from_unsigned; [0x0, (char::MAX as u32) + 1]);

/// A membership wrapper for [`CodePointInversionList`].
///
Expand Down
2,212 changes: 1,108 additions & 1,104 deletions components/collections/src/codepointtrie/benches/tries/gc_fast.rs

Large diffs are not rendered by default.

1,686 changes: 845 additions & 841 deletions components/collections/src/codepointtrie/benches/tries/gc_small.rs

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions utils/zerovec/src/zerovec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -940,16 +940,16 @@ impl<T: AsULE> FromIterator<T> for ZeroVec<'_, T> {
/// use zerovec::{ZeroSlice, zeroslice, ule::AsULE};
/// use zerovec::ule::UnvalidatedChar;
///
/// const SIGNATURE: &ZeroSlice<char> = zeroslice![char; <char as AsULE>::ULE::from_aligned; 'b', 'y', 'e', '✌'];
/// const SIGNATURE: &ZeroSlice<char> = zeroslice!(char; <char as AsULE>::ULE::from_aligned; ['b', 'y', 'e', '✌']);
/// const EMPTY: &ZeroSlice<u32> = zeroslice![];
/// const UC: &ZeroSlice<UnvalidatedChar> =
/// zeroslice![
/// zeroslice!(
/// UnvalidatedChar;
/// <UnvalidatedChar as AsULE>::ULE::from_unvalidated_char;
/// UnvalidatedChar::from_char('a'),
/// ];
/// [UnvalidatedChar::from_char('a')]
/// );
/// let empty: &ZeroSlice<u32> = zeroslice![];
/// let nums = zeroslice![u32; <u32 as AsULE>::ULE::from_unsigned; 1, 2, 3, 4, 5];
/// let nums = zeroslice!(u32; <u32 as AsULE>::ULE::from_unsigned; [1, 2, 3, 4, 5]);
/// assert_eq!(nums.last().unwrap(), 5);
/// ```
///
Expand All @@ -962,14 +962,14 @@ impl<T: AsULE> FromIterator<T> for ZeroVec<'_, T> {
/// RawBytesULE(num.to_be_bytes())
/// }
///
/// const NUMBERS_BE: &ZeroSlice<i16> = zeroslice![i16; be_convert; 1, -2, 3, -4, 5];
/// const NUMBERS_BE: &ZeroSlice<i16> = zeroslice!(i16; be_convert; [1, -2, 3, -4, 5]);
/// ```
#[macro_export]
macro_rules! zeroslice {
() => (
$crate::ZeroSlice::new_empty()
);
($aligned:ty; $convert:expr; $($x:expr),+ $(,)?) => (
($aligned:ty; $convert:expr; [$($x:expr),+ $(,)?]) => (
$crate::ZeroSlice::<$aligned>::from_ule_slice(
{const X: &[<$aligned as $crate::ule::AsULE>::ULE] = &[
$($convert($x)),*
Expand All @@ -978,7 +978,7 @@ macro_rules! zeroslice {
);
}

/// Creates a borrowed `ZeroVec`. Convenience wrapper for `zeroslice![...].as_zerovec()`. The value
/// Creates a borrowed `ZeroVec`. Convenience wrapper for `zeroslice!(...).as_zerovec()`. The value
/// will be created at compile-time, meaning that all arguments must also be constant.
///
/// See [`zeroslice!`](crate::zeroslice) for more information.
Expand All @@ -988,7 +988,7 @@ macro_rules! zeroslice {
/// ```
/// use zerovec::{ZeroVec, zerovec, ule::AsULE};
///
/// const SIGNATURE: ZeroVec<char> = zerovec![char; <char as AsULE>::ULE::from_aligned; 'a', 'y', 'e', '✌'];
/// const SIGNATURE: ZeroVec<char> = zerovec!(char; <char as AsULE>::ULE::from_aligned; ['a', 'y', 'e', '✌']);
/// assert!(!SIGNATURE.is_owned());
///
/// const EMPTY: ZeroVec<u32> = zerovec![];
Expand All @@ -999,8 +999,8 @@ macro_rules! zerovec {
() => (
$crate::ZeroVec::new()
);
($aligned:ty; $convert:expr; $($x:expr),+ $(,)?) => (
$crate::zeroslice![$aligned; $convert; $($x),+].as_zerovec()
($aligned:ty; $convert:expr; [$($x:expr),+ $(,)?]) => (
$crate::zeroslice![$aligned; $convert; [$($x),+]].as_zerovec()
);
}

Expand Down
6 changes: 3 additions & 3 deletions utils/zerovec/src/zerovec/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,16 +577,16 @@ mod test {
}
{
// single element slice
const DATA: &ZeroSlice<u16> = zeroslice![u16; <u16 as AsULE>::ULE::from_unsigned; 211];
const DATA: &ZeroSlice<u16> = zeroslice!(u16; <u16 as AsULE>::ULE::from_unsigned; [211]);
assert_eq!((211, zeroslice![]), DATA.split_first().unwrap());
}
{
// slice with many elements.
const DATA: &ZeroSlice<u16> =
zeroslice![u16; <u16 as AsULE>::ULE::from_unsigned; 211, 281, 421, 32973];
zeroslice!(u16; <u16 as AsULE>::ULE::from_unsigned; [211, 281, 421, 32973]);
const EXPECTED_VALUE: (u16, &ZeroSlice<u16>) = (
211,
zeroslice![u16; <u16 as AsULE>::ULE::from_unsigned; 281, 421, 32973],
zeroslice!(u16; <u16 as AsULE>::ULE::from_unsigned; [281, 421, 32973]),
);

assert_eq!(EXPECTED_VALUE, DATA.split_first().unwrap());
Expand Down