Skip to content

Commit

Permalink
Support layout annotations (ocaml-flambda#1417)
Browse files Browse the repository at this point in the history
* Add layout annotations to the language.

This commit also includes various improvements to jane-syntax.

Documentation coming in a separate commit.

This commit has been rebased to include the following
commits:

Pprintast now depends on Printast

Initial implementation of layout annotations

This was taken from ccasin/ocaml-jst#1,
but rebased and cleaned. There are a handful of failing tests,
still, but they're all newly introduced in this patch.

Rename ~reason to ~context for annotations (only)

Move layout annotations into aliases

This now prevents e.g. [(int : immediate)] but allows
[int as ('a : immediate)], as discussed with the type-systems
group.

Add control over printing verbosity

Move alias over to jane-syntax architecture

Move variable layout annotation into jane-syntax

Support for annotations on _

Check layout annotation during conversion

Handle type parameters uniformly

Convert Ptyp_poly to use jane-syntax architecture

Comments from Antal

Move annotations on extension constructors into JS

Combine unboxed constants with other layouts

Newtypes are now in jane-syntax.

Constructor declarations in jane-syntax

Make testsuite pass

Some minor cleanup of old XXXs.

Some cleanup from review

A little cleanup in Jane_syntax from review

Fix compilation with dune-based build

Incorporate test case from old PR, improving msg

Respond to Antal's review

More review fixes

Move test that now passes

Responses to comments

rename test

Remove "assert false" in favor of "Misc.fatal_error"

Add comment about generic parameters

transl_type_param_layout --> get_type_param_layout

Rename error constructors

Remove module that will interfere with merging

* Remove call to make_params in enter_type

* Keep minimizer compatible

* Format chameleon
  • Loading branch information
goldfirere authored and Ekdohibs committed Aug 31, 2023
1 parent 6f1bafc commit 8b4429e
Show file tree
Hide file tree
Showing 105 changed files with 12,575 additions and 8,507 deletions.
9 changes: 9 additions & 0 deletions chamelon/compat.jst.ml
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,12 @@ let mk_value_binding ~vb_pat ~vb_expr ~vb_attributes =
vb_loc = Location.none;
vb_sort = Layouts.Sort.value;
}

let mkTtyp_any = Ttyp_var (None, None)
let mkTtyp_var s = Ttyp_var (Some s, None)

let is_type_name_used desc typ_name =
match desc with
| Ttyp_alias (_, Some s, _) -> s = typ_name
| Ttyp_constr (_, li, _) -> Longident.last li.txt = typ_name
| _ -> false
4 changes: 4 additions & 0 deletions chamelon/compat.mli
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ val mkTexp_match :
expression * computation case list * partial ->
expression_desc

val mkTtyp_any : core_type_desc
val mkTtyp_var : string -> core_type_desc
val is_type_name_used : core_type_desc -> string -> bool

type matched_expression_desc =
| Texp_ident of
Path.t
Expand Down
9 changes: 9 additions & 0 deletions chamelon/compat.upstream.ml
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,12 @@ let mk_constructor_description cstr_name =

let mk_value_binding ~vb_pat ~vb_expr ~vb_attributes =
{ vb_pat; vb_expr; vb_attributes; vb_loc = Location.none }

let mkTtyp_any = Ttyp_any
let mkTtyp_var s = Ttyp_var s

let is_type_name_used desc typ_name =
match desc with
| Ttyp_alias (_, s) -> s = typ_name
| Ttyp_constr (_, li, _) -> Longident.last li.txt = typ_name
| _ -> false
4 changes: 2 additions & 2 deletions chamelon/minimizer/dummy.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let dummy_type_expr = newty2 ~level:0 (mkTvar (Some "a"))

let dummy_core_type =
{
ctyp_desc = Ttyp_any;
ctyp_desc = mkTtyp_any;
ctyp_type = dummy_type_expr;
ctyp_env = Env.empty;
ctyp_loc = Location.none;
Expand All @@ -19,7 +19,7 @@ let dummy_core_type =

let a_typ =
{
ctyp_desc = Ttyp_var "a";
ctyp_desc = mkTtyp_var "a";
ctyp_type = newty2 ~level:0 (mkTvar (Some "a"));
ctyp_env = Env.empty;
ctyp_loc = Location.none;
Expand Down
6 changes: 1 addition & 5 deletions chamelon/minimizer/removedeadcode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ let is_used_typ str typ_name =
Tast_mapper.default with
typ =
(fun mapper ct ->
(match ct.ctyp_desc with
| Ttyp_alias (_, s) -> if s = typ_name then is_used := true
| Ttyp_constr (_, li, _) ->
if Longident.last li.txt = typ_name then is_used := true
| _ -> ());
if is_type_name_used ct.ctyp_desc typ_name then is_used := true;
if not !is_used then Tast_mapper.default.typ mapper ct else ct);
expr =
(fun mapper e ->
Expand Down
Loading

0 comments on commit 8b4429e

Please sign in to comment.