This PR proposes a refactor of Typecore.type_application.
This work was originally done by @lpw25 in Jane Street's fork of the compiler with extensions. Jane Street has asked for help from Tarides to upstream these changes.
This PR introduces a more descriptive type for arguments of a function application:
type expression_desc =
| ...
| Texp_apply of expression * (arg_label * apply_arg) list
and apply_arg = (expression, unit) arg_or_omitted
and ('a, 'b) arg_or_omitted =
| Arg of 'a
| Omitted of 'b
These were formerly represented with the type expression option.
The typing of applications is now clearly split in two phases: first collect_apply_args maps over the arguments, classify them and collect additional information. Then type_apply_arg and type_omitted_parameters perform the actual typing.
The classification was previously done by imperatively filling lists such as eliminated_optional_arguments and omitted_parameters. Now it uses the type parameters of arg_or_omitted to store additional information and specific type constructors are introduced for these cases:
Thus, the flow for typing an application can now be summarized with these three functions:
collect_apply_args :
... (arg_label * expression) list ->
... * (untyped_apply_arg, untyped_omitted_param) arg_or_omitted list
type_apply_arg :
... (untyped_apply_arg, untyped_omitted_param) arg_or_omitted ->
... * (Typedtree.expression, untyped_omitted_param) arg_or_omitted
type_omitted_parameters :
... (Typedtree.expression, untyped_omitted_param) arg_or_omitted list ->
... * (Typedtree.expression, unit) arg_or_omitted list
I was not familiar with the typing process of function application before doing this work but my impression is that these changes do make the code clearer and more robust.
This PR proposes a refactor of
Typecore.type_application
. This work was originally done by @lpw25 in Jane Street's fork of the compiler with extensions. Jane Street has asked for help from Tarides to upstream these changes.This PR introduces a more descriptive type for arguments of a function application:
These were formerly represented with the type
expression option
.The typing of applications is now clearly split in two phases: first
collect_apply_args
maps over the arguments, classify them and collect additional information. Thentype_apply_arg
andtype_omitted_parameters
perform the actual typing.The classification was previously done by imperatively filling lists such as
eliminated_optional_arguments
andomitted_parameters
. Now it uses the type parameters ofarg_or_omitted
to store additional information and specific type constructors are introduced for these cases:Thus, the flow for typing an application can now be summarized with these three functions:
I was not familiar with the typing process of function application before doing this work but my impression is that these changes do make the code clearer and more robust.
cc @OlivierNicole @goldfirere