Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue for const generics (RFC 2000) #44580
Comments
This comment has been minimized.
This comment has been minimized.
|
#44275 added a @EpicatSupercell has expressed interest in working on this, I'll mentor them through the initial implementation. However, we can't go too far because of the limitations described in #44275. That is, we need @nikomatsakis' lazy normalization to allow constant expressions embedded in types to observe the bounds in scope (from the function / type definition / impl / etc. item they're in), without producing cyclic dependencies half the time. |
This comment has been minimized.
This comment has been minimized.
|
Implementation waypoints (for more direct mentoring, seek
Note that all of this should allow |
eddyb
added
the
E-mentor
label
Sep 18, 2017
eddyb
self-assigned this
Sep 18, 2017
This comment has been minimized.
This comment has been minimized.
|
I'd like to take a stab at this :) |
carols10cents
added
the
hacktoberfest
label
Sep 29, 2017
fitzgen
referenced this issue
Oct 3, 2017
Open
Tracking rustc bugs/features/RFCs that affect bindgen #849
This comment has been minimized.
This comment has been minimized.
samsartor
commented
Oct 26, 2017
This comment has been minimized.
This comment has been minimized.
|
@samsartor there was a refactoring that had to be done before the main implementation work. That is now almost done (I'm waiting for feedback currently). I don't actually know how much work there is after that. Parsing const params was what I started with initially, before the refactoring. It's not done but I should be able to get that done relatively soon. |
This comment has been minimized.
This comment has been minimized.
|
@jplatte It would be nice, if you could link the pull request. I was not able to find it. |
This comment has been minimized.
This comment has been minimized.
|
There is no PR yet. All my work can be found here. |
This comment has been minimized.
This comment has been minimized.
RobertWHurst
commented
Nov 6, 2017
|
Nice work so far @jplatte |
This comment has been minimized.
This comment has been minimized.
|
There is now a PR for the groundwork ( |
This comment has been minimized.
This comment has been minimized.
huhlig
commented
Nov 17, 2017
|
I think this is already included but it would be good to handle the C++ style folding for handling linear algebra style n dimensional arrays with varying lengths, I.E. a 4x4 [[f64;4];4]or a 4x3x5x6 dimensional array [[[[f64;6];5];3];4] and be able to properly wrap and generate specialized methods for both it AND proper trait implementations for scalars properly dimensioned vectors, etc. See https://gist.github.com/huhlig/8b21850b54a75254be4b093551f8c2cb for a rudamentary example. |
This comment has been minimized.
This comment has been minimized.
|
I don't recall anyone proposing fold expressions for Rust before, much less as part of this RFC. But since this is Rust, is there any reason we couldn't implement fold expressions as an ordinary macro, rather than new dedicated syntax? |
kennytm
referenced this issue
Nov 19, 2017
Closed
The trait `std::convert::AsRef<[u8]>` is not implemented for string.len() > 32 #17
This comment has been minimized.
This comment has been minimized.
|
#51880 is done |
This comment has been minimized.
This comment has been minimized.
|
@withoutboats @oli-obk What do you think about blocking proper unification of expressions like I think we'd already have a mechanism to encode it, when @varkor adds Any non- Being able to export the symbolic values into We have to be careful not to assume anything of inference variables, but for e.g. |
This comment has been minimized.
This comment has been minimized.
|
@varkor A test-case I think should work with just lazy normalization, no unification: /*const*/ fn append<const N: usize, T>(xs: [T; N - 1], x: T) -> [T; N] {
let new = MaybeUninit::<[T; N]>::uninitialized();
unsafe {
let p = new.as_mut_ptr() as *mut T;
(p as *mut _).write(xs);
p.add(N - 1).write(x);
}
new.into_inner()
}That would only work because:
So overall, we can probably rely on WF rules to force "validation" of const expressions onto the users, but we'd still want unification for other things (including not needing hacks like |
eddyb
referenced this issue
Aug 25, 2018
Closed
Empty bounds lists in where clauses cause the type to not be WF-checked. #53696
This comment has been minimized.
This comment has been minimized.
added a commit
to mqudsi/rusqlite
that referenced
this issue
Sep 5, 2018
mqudsi
referenced this issue
Sep 5, 2018
Closed
Add impls for i128 16-byte integer db conversions (behind feature gate) #392
This comment has been minimized.
This comment has been minimized.
|
Small question which originates from discussion of Units of Measure. What should we do if type generic over constant does not directly depend on it? For example: struct Foo<T, const N: usize> {
a: T,
// Will such array be "the way" to handle this problem?
// Or do we want some kind of `std:marker::PhantomConstData`? (which can be a simple
// type alias to the same array)
// Or maybe make `PhantomData` to accept constants?
_phantom: [(), N],
} |
This comment has been minimized.
This comment has been minimized.
I assume you meant I think it would make sense to have a special |
This comment has been minimized.
This comment has been minimized.
Ekleog
commented
Sep 6, 2018
|
Hmm… Re-reading the RFC with the latest comments in mind, I'm wondering: would something like this be allowed? struct Foo<T, const V: T> {
_phantom: PhantomConst<T, V>,
}I can't see it being banned anywhere, but would have thought it'd deserve at least an example. |
This comment has been minimized.
This comment has been minimized.
|
@Ekleog: as far as I'm aware, const parameter types may not depend on type parameters initially (though it would definitely make sense for an extension). (The implementation is trickier if we allow this, so it makes sense to start with the simplest version.) |
This comment has been minimized.
This comment has been minimized.
Zauberklavier
commented
Sep 7, 2018
|
How is the progress on this? Do we know an approximate time when this should hit nightly? |
This comment has been minimized.
This comment has been minimized.
|
@Zauberklavier As soon as this pull request is done. To quote from it:
|
This comment has been minimized.
This comment has been minimized.
|
@newpavlov I assumed constant parameters would be allowed without being used in fields. |
This comment has been minimized.
This comment has been minimized.
|
@eddyb that's what I recall from the RFC discussion also. |
This comment has been minimized.
This comment has been minimized.
Ekleog
commented
Sep 9, 2018
This comment has been minimized.
This comment has been minimized.
burdges
commented
Sep 21, 2018
|
Do const parameters impact the variance of type parameters they involve? |
This comment has been minimized.
This comment has been minimized.
|
Currently I believe const generics can't have type parameters in their type. |
This was referenced Oct 7, 2018
This comment has been minimized.
This comment has been minimized.
rodrimati1992
commented
Nov 2, 2018
|
I am not clear on what the first working version of this will be able to do. For example whether the code in this comment would compile: If that code compiled,it would be a way to enforce constraints for constants before getting a syntax for it. |
This comment has been minimized.
This comment has been minimized.
|
@rodrimati1992 You can probably just do |
This comment has been minimized.
This comment has been minimized.
rodrimati1992
commented
Nov 5, 2018
•
So,with trait aliases I could rewrite is to this?:
The idea with the Assert<cond B:bool,Msg> trait is using a type error to print an error message embedded in a type,which in the case of AssertLessThan128 is:
which I expect to be more helpful than |
This comment has been minimized.
This comment has been minimized.
|
You can also do |
This comment has been minimized.
This comment has been minimized.
rodrimati1992
commented
Nov 5, 2018
•
|
I thought the std::fmt architecture is not going to be there until With this thing you can have error messages with multiple values in it (embedded in types). Maybe it's better to wait for const generics to talk about this,since it'll be easier to show executable examples. |
This comment has been minimized.
This comment has been minimized.
|
@rodrimati1992 see https://github.com/rust-lang/rfcs/blob/master/text/2345-const-panic.md, there's going to be a special case to get const |
This comment has been minimized.
This comment has been minimized.
|
@rodrimati1992 Ahh, I see, that's indeed a clever trick! |
withoutboats commentedSep 14, 2017
•
edited by varkor
Tracking issue for rust-lang/rfcs#2000
cc @eddyb
Blocking stabilization: