-
Notifications
You must be signed in to change notification settings - Fork 463
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
New internal representation for uncurried types. #5870
Conversation
We can create a builtin type, called
Using a keyword would help to avoid aliases, which make our ad-hoc error message improvement more robust |
There's an issue with using a constraint to give the arity to function definitions. E.g. Now considering to instead pass the arity via an annotation, which is then picked up by the type checker. |
The current representation is making use of this type: (* In js.ml *)
type ('fn, 'arity) uncurried = Uncurried of 'fn [@unboxed] A function definition @res.arity(2) Js.Uncurried((x,y) => x+y) whose type becomes: Js.uncurried<(int, int) => int, [#2]> This seems to work well on all the examples now. |
Now using built-in type |
de65464
to
9e2b411
Compare
Some comments:
|
I suggest we adapt the type checker to do the propagation. The current encoding is unsafe, since user can also create uncurried type by hand. Another caveat is when do such unsafe encodings, make sure the internal optimization will not change the arity, so you do need some opaque operations to prevent such optimizations |
The variant is part of the encoding. Used for function definitions (and a few places in the compiler pipeline). |
The arity is indeed set by the type checker at the moment, by taking |
Not sure I understand the comment about creating a type by hand. This is what user could do by hand before: type fun2 = Js.Fn.arity2<(int, int) => int>; Unclear what the new problem is. |
@cristianoc I reread the encoding, the encoding looks good to me modulo some comments about the naming, it is a nice trick to generate the phantom variant types. What is the implication for the vanilla ocaml syntax? |
The compiler code is refactored so the runtime representation of uncurried function definitions and types live in a single file. In the case of ocaml functions, the compiler's ppx calls into that file, which generates the same definitions as with the ReScript syntax. So the vanilla ocaml syntax, e.g. in some compiler libs, stays the same, and produces the same code as if it were written in ReScript. |
faa7363
to
c513303
Compare
c513303
to
2aa76c5
Compare
Only for arity 5. The representation of `(. int, int) => string` would be `Js.uncurried( ((int,int)=>int, [unit, unit])` where the second type parameter encodes the arity. Does not require to pre-declare all the arities.
Using a constraint to determine the arity in a function definition is problematic as the constraint limits type propagation during inference. Instead, pass the arity via an attribute @res.arity on the Js.Uncurried variant. And specialize the type checker to handle that arity and use type unification to propagate the arity.
3e9cbc4
to
6721cd1
Compare
The representation is making use of a built-in type that corresponds to the following declaration:
A function definition
(. x, y) => x+y
is encoded as:whose type becomes: