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

Leverage zeroslice! macro to clean up ZeroVec API #1935

Open
sffc opened this issue May 24, 2022 · 1 comment
Open

Leverage zeroslice! macro to clean up ZeroVec API #1935

sffc opened this issue May 24, 2022 · 1 comment
Labels
C-zerovec Component: Yoke, ZeroVec, DataBake S-small Size: One afternoon (small bug fix or enhancement) T-techdebt Type: ICU4X code health and tech debt
Milestone

Comments

@sffc
Copy link
Member

sffc commented May 24, 2022

With Rust 1.61 and #1926, we will now be able to do the following:

  1. Add a general-purpose zeroslice! macro
  2. Remove the old type-specific const constructors
  3. Migrate users of the problematic EqULE trait to use the new convenience macro, and then remove EqULE

For the macro, you should be able to write

// NOTE: The syntax should be bikeshed
static FOO: &ZeroSlice<u16> = zeroslice![<cb>; 222, 333, 444, 555];

which desugars to

static FOO: &ZeroSlice<u16> = $crate::ZeroSlice::from_ule_slice(
    &<cb>([222, 333, 444, 555])
);

where <cb> is a const function that converts from an aligned to unaligned array (i.e. AsULE::to_unaligned); it would be nice to have a trait for this but we still can't use trait functions in a const context. We can probably write it such that the function only needs to convert from a single T to a single T::ULE and call it in a loop. The big thing is that we can write ZeroSlice::from_ule_slice in a const context now.

@sffc sffc added C-data-infra Component: provider, datagen, fallback, adapters T-techdebt Type: ICU4X code health and tech debt S-small Size: One afternoon (small bug fix or enhancement) labels May 24, 2022
@sffc sffc added this to the ICU4X 1.0 (Polish) milestone May 26, 2022
@sffc sffc self-assigned this May 26, 2022
@sffc sffc assigned pandusonu2 and unassigned sffc Jun 7, 2022
@sffc
Copy link
Member Author

sffc commented Jun 8, 2022

Example of using the const function to build a ZeroSlice: https://github.com/unicode-org/icu4x/blob/269b807d9f0eda2905efab6c9e6bd30d8c243a80/utils/codepointtrie/benches/tries/gc_small.rs

The first step for this issue is to migrate all users of from_slice_or_alloc to use the const function if possible.

@sffc sffc added C-zerovec Component: Yoke, ZeroVec, DataBake and removed C-data-infra Component: provider, datagen, fallback, adapters labels Dec 22, 2022
@skius skius self-assigned this May 22, 2023
@skius skius removed their assignment Aug 29, 2023
@robertbastian robertbastian changed the title Leverage Rust 1.61 to clean up ZeroVec Leverage zeroslice! macro to clean up ZeroVec API Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-zerovec Component: Yoke, ZeroVec, DataBake S-small Size: One afternoon (small bug fix or enhancement) T-techdebt Type: ICU4X code health and tech debt
Projects
None yet
Development

No branches or pull requests

3 participants