-
Notifications
You must be signed in to change notification settings - Fork 36
Separation between Felt, Bool, and Uint types #423
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
base: next
Are you sure you want to change the base?
Conversation
Would we be able to verify at compile time that const expressions match the declared type? I'm mainly thinking of declaring a constant to be a
Similar question to the one above, but also, if we are able to verify the type of |
Yes it should be able to verify annotations, both on const and let expressions.
I do agree in principle that we don't really need it.
Footnotes
|
|
On second thought, I don't think inference can be done perfectly in all cases anyway without making the type system too complex. Take the following example with 2 mutually exclusive flags What should I think ensuring inference is conservative when ambiguous + adding an explicit type cast via let annotations that respect subtyping rules under variance would let the user disambiguate in case both interpretations were valid. Here that would mean infering |
I think allowing the user to specify the type may lead to some confusion because the user my assume that specifying the type somehow enforces this type. If we do this, we should make sure to report very clear warnings that we don't actually know if what the user has specified is correct.
A couple of comments here:
So, I would re-write the above example as:
In the above, Is the issue here that The constraints generated would be exactly the same as in the original example, but here, |
The order wasn't the issue, the example was meant to show valid type conversions, and their consequence before and after CSE (mainly that If we narrow it down to On the other points you've mentioned, I do agree with that design, and it shouldn't be too big of a change to incorporate in this PR. |
Makes sense. I think the can always do
The only thing I'm wondering is whether it should be just |
65d0047 to
3d22950
Compare
3d22950 to
7f30ca7
Compare
|
Hey @bobbinth! I have rebased on next, done and merged the necessary tweaks we've discussed to the type system itself under the I am still merging in the integration into the existing codebase, based on next. That part should come fairly soon. When implementing binary operations, I've noticed a few cases that, while technically correct, lose some information that could be used to refine the type system in a couple cases. I opened a separate issue #432 to track it for now, since that shouldn't affect the soundness, while only adding precision in certain cases. Do let me know if you'd like us to include it (or parts of it) in this PR! |
This PR is pretty big as is - so, I'd probably leave it for a follow-up (unless including it in this PR will simplify things somehow). |
|
Hey @bobbinth! I have merged the changes up to date in the current branch. It is now integrated in the pipeline. We currently have the following structure: The subtyping rules are as described in And those for binary operations ( Notes:
I'll update the task list in the top message of this thread. Remaining task-list:
|
95f7393 to
b2c75b6
Compare
bitwalker
left a comment
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 like there is still a number of stubbed out bits/TODOs, but I'm approving as-is for now, contingent on my couple suggestions around the typing crate rename and how we manage dependencies within the workspace.
|
Hey @bitwalker, thanks for the review! I've implemented your suggestions in 9419d39, and renamed the directory accordingly to improve clarity. |
|
Hey! We've been able to sync about how
In the meantime, I'm merging other missing features/integrations into |
|
Given the changes you are planning to make to this branch, are there portions that are reviewable now/are not expected to change much? |
The next commit should be just that: while it is retro-compatible at the moment, there are still overlaps before I integrate it fully on most crates (ast, sema, mir, air-types) I'll ping you as soon as it's at that stage! |
|
Hey @adr1anh The tests are currently failing due to the missing type-checking pass (all errors seem to stem from an error due to some types being None), otherwise most changes are fully merged in. From this point, not much should change besides the new pass, a few tests, and the assert_bool handling once Mir::Cast is merged in. I've updated the task lists above, for a quick recap here is what's left: Leftover tasks:
|
This PR aims to solve #334
It adds proper type annotations, checking, and inference
Mainly, it splits Scalar types values into 4 possibilities:
_: anUntyped(scalar) type hole, used to represent aScalarTypethat is not yet known or defineduint: a constant unsigned integer, aimed to be used only as an index and type forRangeExpressionfelt: a single field elementbool: a boolean value formed from afeltvalueAggregate types have a new syntax:
ScalarType[len]: aVectorcontaininglenscalars of typeScalarType, wherelenis a positive integer:_[len]: aVectoroflenscalar type holesuint[len]: aVectoroflenunsigned integersfelt[len]: aVectoroflenfield elementsbool[len]: aVectoroflenboolean valuesScalarType[rows, cols]: aMatrixcontainingrowsrows andcolscolumns of typeScalarType, whererowsandcolsare positive integers:_[rows, cols]: aMatrixofrowsrows andcolscolumns of scalar type holesuint[rows, cols]: aMatrixofrowsrows andcolscolumns of unsigned integersfelt[rows, cols]: aMatrixofrowsrows andcolscolumns of field elementsbool[rows, cols]: aMatrixofrowsrows andcolscolumns of boolean valuesI am unsure of which syntax to use for Matrices. I have re-used the one used in the Display implementation.
An alternative would be:
SCALAR_TYPE[[cols], rows], which has the advantage of matching our notation for Tables (Matrices of unknown row length).Both are possible and not an issue to change.
It also adds optional type annotations in the parser for:
const x: TYPE = EXPR, whereTYPEis one of the above types.let x: TYPE = EXPR;, whereTYPEis one of the above types.fn func(x: TYPE) -> TYPE, whereTYPEis one of the above types.ev evaluator(SCALAR_TYPE[a, b]), whereSCALAR_TYPEis one of the aboveScalarTypesanda,bare column labelsMost of individual pieces are implemented, but rely on a few fixes and improvements to work properly together. Those will be merged as soonn as the underlying issues are resolved.
I've marked those as [WIP] below.
Check-list:
type annotationslet x: TYPE = EXPR;: still a bug with type update order, a fix is on the way using atyfield in all/most AST nodesfn func(x: TYPE) -> TYPE: relies on theletexpression fixev evaluator(SCALAR_TYPE[a, b]): relies on theletexpression fixtyfield to all AST nodes that can have a type to preserve infered types + implTypeMut.uintvaluesBinaryExpression)Leaving it as a Draft PR until the issues outlined above are resolved.