-
Notifications
You must be signed in to change notification settings - Fork 182
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
Integer and float variable kinds #470
Integer and float variable kinds #470
Conversation
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 main problem I see is that int/float are not 'distinct' from ordinary types. I think we need some tests like
exists<T, int N> {
T = N, N = usize
}
this should pass, and something like
exists<T, int N> {
T = N, T = char
}
this should have no solution.
I guess I didn't expect to add an enum to
but I'm not sure which setup is nicer. This one may be more elegant. |
Adding the enum to |
chalk-solve/src/infer/unify.rs
Outdated
( | ||
&TyData::InferenceVar(var1, kind1), | ||
&TyData::InferenceVar(var2, kind2), | ||
) if kind1 == kind2 => { |
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.
Nit: Maybe this would be nicer if we combined the three cases and moved the if
into the arm?
I'm imagining
(
&TyData::InferenceVar(var1, kind1),
&TyData::InferenceVar(var2, kind2),
) => {
if kind1 == kind2 {
...
} else if kind1.is_general() || kind2.is_general() {
...
} else {
Err(...)
}
}
goal { | ||
exists<T, float N> { | ||
T = N, N = f32 | ||
} |
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.
let's add
exists<int N, float F> { N = F }
and check it gives an error
This introduces a new notation to distinguish integer inference variables from general inference variables: ?0i. The "i" represents that it is an integer variable. Another new notation is for integer variables in goals. Similar to consts, integer variables are notated as `int N`, for example: ``` exists<int N> { ... } ```
Adds new notation for float inference variables, just like what was added for integers. - `?0f` is a float inference variable - `float N` is the notation for float variables in goals, for example: ``` exists<float N> { ... } ```
The recursive solver would fail on these new tests without this change.
Closes #327
This adds support for integer and float variable kinds. Example usage: