Skip to content

Tracking issue for migrating from GenericArray to const generics #970

Closed

Description

@tarcieri

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.

Activity

  1. tarcieri commented on Mar 27, 2022

    @tarcieri
    MemberAuthor

    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.

  2. tarcieri commented on Apr 16, 2022

    @tarcieri
    MemberAuthor

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

  3. tarcieri commented on May 12, 2022

    @tarcieri
    MemberAuthor

    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.

  4. tarcieri commented on Nov 14, 2023

    @tarcieri
    MemberAuthor

    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.

  5. tarcieri commented on Jan 21, 2024

    @tarcieri
    MemberAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions