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

heapless on const generics: status #102

Closed
burrbull opened this issue Jun 26, 2019 · 5 comments
Closed

heapless on const generics: status #102

burrbull opened this issue Jun 26, 2019 · 5 comments

Comments

@burrbull
Copy link
Member

burrbull commented Jun 26, 2019

I tried to port heapless types from GenericArray to usize const generics.
Here is branch.

Today I managed to compile it in release mode.
For testing you can use: cargo test --release.

Issues:

  • In debug mode compile fails.
  • Queue doesn't work. Fails on type inference. I think the problem is in the interaction of default types and const generics. pub struct Consumer<'a, T, U = usize, C = MultiCore, const N: usize>
  • I don't know how to set PowerOfTwo restriction for indexmap.

Everything else is pretty good.

rustc 1.37.0-nightly (8aa42ed7c 2019-06-24)

@XOSplicer
Copy link
Contributor

XOSplicer commented Jun 27, 2019

Hi,

this is a very interesting and strategical step forward for the heapless crate.
Porting heapless to const generics was on my mind aswell, but time is limited.

Here are my thought on the PowerOfTwo restriction:

In general what is needed is a static assertion for the const generic.

  • There exists a thread which discusses exactly this feature as a language feature, but to no conclusion Link
  • The const_assert macro of the static_assert crate might help.
  • An internal new type Foo<const N: usize>(PhantomData) with a trait PowerOfTwoMarker that is only implemented for Foo<2>, Foo<4>, Foo<8>, Foo<16> and so on might be possible, but limits the allowed values to an enumerable range for which this trait is imlememted. (I'm not sure about the PhantomData part though)

@japaric
Copy link
Member

japaric commented Jul 11, 2019

@burrbull thanks for trying this out. I think the compiler team will appreciate all the bug reports.

From my side, I would prefer not to make heapless depend / use const generics in any form (even behind a Cargo feature) until the feature has been (partially) stabilized. Nightly features are a maintenance burden that I would prefer to avoid.

@burrbull
Copy link
Member Author

It's a good day.
rust-lang/rust#65652
rust-lang/rust#65092

@jacobrosenthal
Copy link

This still seems blocked even with min_const_generics on

"using type defaults and const parameters in the same parameter list is currently not permitted"
rust-lang/rust#74806

@korken89
Copy link
Contributor

See #168 for up to date version of this.

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

5 participants