Skip to content
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

Support layout annotations #1417

Merged
merged 4 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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