Keep more type information in Lambda#2156
Conversation
This only makes things more obvious, nothing is gained as some other information is missing.
…/ocaml-1 into chambart-function_parameter_type
|
I've edited the description and removed the [WIP] marker. This is ready for review. |
|
(Note: CI reported on #1029 a problem while compiling Camlp4, because of "empty pattern matching", not allowed by the normal syntax. I've added a commit which should fix this problem. AppVeyor/Travis don't compile Camlp4 anymore.) |
|
Commit 998d831 avoids boxing of type t =
{
x: float;
y: float;
}
let f = function
| Some {x; y = 0.} | Some {x = 0.; y = x} -> x +. x
| _ -> 0. |
|
Would someone be able to review this PR (perhaps @chambart , @lpw25 or @mshinwell)? |
| | _ -> Llet(str, kind, var, exp, body) | ||
|
|
||
| let bind str var exp body = | ||
| bind_with_value_kind str (var, Pgenval) exp body |
There was a problem hiding this comment.
I've looked at the use points for this function. They are all in Matching. Most of them do have kind information. I think it would probably be better to update the uses rather than the definition.
There was a problem hiding this comment.
I've switched two call sites to compute the value_kind, but all others in Matching, there does not seem to be a trivial way to compute the value_kind without more refactoring.
|
I would have separated the propagation/unboxing in 2 PR, but it doesn't really matter. |
|
Could we please separate the unboxing part from the propagation of kinds in this patch? They seem like distinct features. |
This reverts commit 8c62d73.
|
Ok, let's try to get the (tedious but mechanical) propagation stuff first. I've reverted the commit about the actual unboxing and will submit another PR later. |
| let lvars = List.map (fun id -> Lvar id) val_ids in | ||
| static_catch (transl_list argl) val_ids | ||
| (Matching.for_multiple_match e.exp_loc lvars val_cases partial) | ||
| let val_ids = |
There was a problem hiding this comment.
Why did you change the indentation depth here ? I know that 4 is the default, but the rest of the code is 2 here
There was a problem hiding this comment.
I didn't; emacs+ocp-indent did, and I'm a bit too lazy to find how to disable this behavior. You can ask GitHub to hide whitespace changes if this helps reviewing.
asmcomp/flambda_to_clambda.ml
Outdated
| arity = Flambda_utils.function_arity function_decl; | ||
| params = List.map (fun var -> VP.create var) (params @ [env_var]); | ||
| params = | ||
| List.map (fun var -> VP.create var, Lambda.Pgenval) (params @ [env_var]); |
There was a problem hiding this comment.
check_typo is complaining about this line (81 characters)
|
I think it's good to go when the CI is happy (the only failure is check_typo). |
|
This breaks the More precisely: there is a difference between the expected and the obtained
Shall I just go ahead and update the reference file or is there something |
|
No, nothing deep, this simply needs to be updated! |
|
Alain Frisch (2018/11/23 07:23 -0800):
No, nothing deep, this simply needs to be updated!
Done in commit eb951f1
|
|
Thanks! @shindere! |
|
Alain Frisch (2018/11/23 08:32 -0800):
Thanks! @shindere!
No problem :)
|
|
I'd like to use the -dtypedtree flag and a modified printtyped.ml to transpile from ocaml into another language without such advanced pattern matching capabilities. Is there a pattern match compiler keeping all type information? |
|
@buergerling I would recommend instead that you link to The compilation of pattern-matching is done during the Typedtree->(untyped)Lambda translation, so it does not preserve type information. This means that you would probably have to rewrite your own pattern-matching compiler yourself. You could also fork OCaml's pattern-matching compiler to emit a typed representation, and I think it would be doable, but it's a complex piece of the codebase. |
This PR adds more propagation of "value kinds" (used to drive float unboxing, in particular) through the compiler:
This is based on a version of Propagate to Lambda type information for function parameters and return #1029 from @chambart merged with trunk, i.e. keeping value kinds on lambda functions (parameters and return values).
Adding value kinds on parameters of staticcatch.
Unboxing across staticcatch handlers, as in MPR#7017, but based on value kinds from the item above. (For now, float only, not boxed numbers.)The first point is somehow independent from the other ones, but (1) it goes in the same direction as the second point; and (2) all together they will allow to make sure that functions compiled "statically" as in #2143 will not require boxing when jumping to a shared continuation.
Variants of #1322 (unboxed calling conventions) and other optimizations could also benefit from keeping more value kinds in lambda/clambda.
The text below does not apply any more to this PR
In its current state, this PR already avoids boxing
bin;The tuple binding is compiled to a staticcatch, and this optimization now makes sure to annotate the parameters of the staticcatch with value kinds derived from the pattern type. (This only works without flambda. Extra work will be needed to propagate -- and hopefully enrich -- the value kind annotations through flambda.)
Similarly, the PR avoids some boxing with or-pattern, such as for
xin:The unboxing decision for staticcatch parameters (in Cmmgen) is currently only based on value kind annotations (inherit from Lambda). One bad case is when all staticraise sites naturally produce a boxed version (e.g. by calling a float-returning function, or reading from a boxed data structure), and the statichandler can use this boxed version directly. With the new heuristics, those floats will be unboxed and then reboxed when accessed in the handler. This is similar to what happens for float mutable variables, which are always unboxed (independently of the bound expression), and I think one can live with that.~~