-
Notifications
You must be signed in to change notification settings - Fork 187
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
Const ty #945
Const ty #945
Conversation
27b28fe
to
6e4d510
Compare
2be3503
to
ce9d1ab
Compare
c3c13bc
to
01f5393
Compare
@Y-Nak Will we allow dependent functions, with a return type that depends on the value of an argument?
In the current implementation, should the syntax of |
This PR is pretty restrictive so that we can introduce the basic const generics. I should've titled this PR as I'm trying to design a more sophisticated type system now in the separate PR, which will allow the snippet below. pub struct X<const N: u8> {}
pub fn bar(n: u8) -> X<n> {
return X<n>{}
} |
┌─ const_generics_cycle.fe:1:28 | ||
│ | ||
1 │ pub struct Foo<T, const U: T> {} | ||
│ ^ recursive const parameter type is detected here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave up trying to trace the cycle that this situation creates, but it seems to me that it should be possible to allow this? (Not suggesting that this is important)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed this in the meeting; feel free to ignore. (I don't personally care whether this stays a "recursive" error, or is changed to be a 'not a primitive type' error)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed this by making the generic parameter evaluation lazy, which is the same as the ADT field evaluation approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The recursive type error occurs only if a parameter type depends on itself.
e.g.,
struct Foo<T, const U: U> {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
This PR introduces basic const types.
Currently, there are some restrictions on the usage of const types, which will be mitigated when a type checker is implemented.
Usage
ADTs, functions, and traits can be declared with const type parameters.
The basic example would be
Const type parameters can treated in the same way as normal type parameters in trait or method implementation.
e.g.,
Limitations
There are two major restrictions on the type system.
bool
and integral types(e.g.,u8
,u16
, ...) are allowed for a const type.These limitations will be mitigated when we redesign type system.
MIsc
Replace
fxhash
withrustc_hash
inparser2
.