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

Project future post-1.51.0 and min_const_generics, possible deprecation? #115

Closed
novacrazy opened this issue Mar 26, 2021 · 5 comments
Closed

Comments

@novacrazy
Copy link
Collaborator

Now that min_const_generics has been stabilized in Rust 1.51.0, should we begin deprecating this crate? We can use the existing build.rs script to check the version number and only generate the deprecation on post-1.51.0 versions.

However, an alternative would be to port much of this crate's functionality to a new (simpler) array wrapper type that fully utilizes const generics, to work alongside and ease replacement of existing code.

Please feel free to submit your thoughts on the matter.

@burdges
Copy link

burdges commented Mar 26, 2021

There are tricks folks play with this crate that do not work with min_const_generics, but one expects this crate incurs a larger compile time penalty, so..

I'd think changes here sound painful, but ideally generic_array users should transition themselves to min_const_generics if possible, and especially remove generic_array from public interfaces.

@novacrazy
Copy link
Collaborator Author

novacrazy commented Mar 26, 2021

When I have time and people desire it, I could attempt a separate crate with a (mostly) drop-in GenericArray type with the signature:

pub struct GenericArray<T, const N: usize>([T; N]);

and implement most/all of the existing GenericArray functionality on that.

If a user has typenum deeply ingrained in their project already, it would be trivial to adapt to const-generics, via: NewGenericArray<T, { N::USIZE }>

@ilyvion
Copy link
Contributor

ilyvion commented Jul 19, 2022

Came across a use-case today that doesn't work with min_const_generics but does work with generic-array. Had a user come into the Rust discord and ask why this isn't possible:

trait Trait {
    const N: usize;
    fn foo() -> [f32; Self::N];
}

We couldn't really explain why Rust won't accept this, but it was argued that you'd sometimes want it to be an associated const, not a const generic, because—just like with associated types—you want only one implementation of this trait per type. Rust is having none of it:

error: generic parameters may not be used in const operations
 --> src/lib.rs:3:23
  |
3 |     fn foo() -> [f32; Self::N];
  |                       ^^^^^^^ cannot perform const operation using `Self`
  |
  = note: type parameters may not be used in const expressions

Which seems a bit off to me, since I would like to draw a parallel to associated types, which you can use in that manner. generic-array to the rescue, however, as this works just fine:

use generic_array::{ArrayLength, GenericArray};
trait Trait {
    type N: ArrayLength<f32>;
    fn foo() -> GenericArray<f32, Self::N>;
}

So that's one reason to keep the old way around. At least I suspect that if GenericArray was changed to GenericArray<T, const N: usize> we'd be back at square one with regard to this use-case.

The motivating example compiles with #![feature(generic_const_exprs)] though, so if/when that stabilizes, this particular use-case falls away.

@novacrazy
Copy link
Collaborator Author

Revisiting this two years later, const-generics are still too minimal to fully replace generic-array. However, with #137 just now we have the opportunity to make generic-array 1.0 much more ergonomic overall. For anyone watching this issue, please suggest any additional breaking changes in #101

Will consider reopening if Rust ever has full const-generic support.

@burdges
Copy link

burdges commented Mar 26, 2023

I wish generic-array occurred less in public interfaces. It still delivers poor ergonomics, even if multiple types never occur.

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

3 participants