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

Tracking issue for migrating from GenericArray to const generics #970

Closed
tarcieri opened this issue Mar 27, 2022 · 5 comments
Closed

Tracking issue for migrating from GenericArray to const generics #970

tarcieri opened this issue Mar 27, 2022 · 5 comments

Comments

@tarcieri
Copy link
Member

tarcieri commented Mar 27, 2022

We've had an informal plan to migrate from the generic-array/typenum crates for years. People ask about it quite frequently ever since min_const_generics have been stabilized. I thought it would be good to have a tracking issue we can point people to.

Unfortunately min_const_generics is not quite up to the challenge of replacing our existing usages of generic-array. Here are open issues tracking the two main features we need upstream:

The first issue (60551) is arguably the biggest blocker. All of the trait crates defined in this repo use associated ArrayLength types which would be best replaced by associated constants. While it would be possible to switch from associated constants to const generic parameters, this has all the drawbacks of using explicit generic parameters versus families of them expressed as associated types. It becomes quite unwieldy when there are several of them involved. Our use cases benefit from these constants being "carried along" with another generic parameter, so it would be best to wait until this feature is implemented.

The second issue (76560) is important because we do quite a bit of arithmetic with typenum.

It will probably be a year or two before these features are implemented upstream, at which point we can consider a wholesale migration to const generics.

@tarcieri
Copy link
Member Author

Something I've been experimenting with is flex-array, a crate which is a hybrid of const generics and typenum-based arrays, which would make it possible to start using const generics in some capacities but still retain the full expressiveness of typenum along with the ability to define array sizes stored as associated types ala generic-array's ArrayLength:

RustCrypto/utils#707

I started by trying to modify generic-array then quickly noticed that the approach would be a lot more effective if such a crate were built on const generics from the ground up.

I think a crate like this could provide a useful stepping stone for incrementally migrating to const generics.

@tarcieri
Copy link
Member Author

There's been some talk about potentially stabilizing associated constant support as the next step for const generic stabilization: rust-lang/rust#76560 (comment)

@tarcieri
Copy link
Member Author

I've published a crate named hybrid-array which aims to provide the same functionality as generic-array, but in a way that can be composed with const generics: https://github.com/RustCrypto/utils/tree/master/hybrid-array

It can hopefully provide a stepping stone from where we're at now towards a full migration to const generics. Ideally this would include being able to use const generic core arrays in public-facing APIs.

@tarcieri
Copy link
Member Author

We've migrated to hybrid-array in most of the crates in this repo now, although the work still needs to be done to update the various implementations.

@tarcieri
Copy link
Member Author

Closing this out in favor of #1481, now that the migration from generic-array to hybrid-array is largely complete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant