Skip to content

Commit

Permalink
Add explicitly polymorphic constructors to Typedtree
Browse files Browse the repository at this point in the history
  • Loading branch information
stedolan committed Jun 28, 2021
1 parent 0a8fbaa commit c9f43bb
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 11 deletions.
12 changes: 9 additions & 3 deletions typing/printtyped.ml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ let arg_label i ppf = function
| Labelled s -> line i ppf "Labelled \"%s\"\n" s
;;

let typevars ppf vs =
List.iter (fun x -> fprintf ppf " %a" Pprintast.tyvar x.txt) vs
;;

let record_representation i ppf = let open Types in function
| Record_regular -> line i ppf "Record_regular\n"
| Record_float -> line i ppf "Record_float\n"
Expand Down Expand Up @@ -514,8 +518,9 @@ and extension_constructor i ppf x =

and extension_constructor_kind i ppf x =
match x with
Text_decl(a, r) ->
Text_decl(v, a, r) ->
line i ppf "Text_decl\n";
if v <> [] then line (i+1) ppf "vars%a\n" typevars v;
constructor_arguments (i+1) ppf a;
option (i+1) core_type ppf r;
| Text_rebind(p, _) ->
Expand Down Expand Up @@ -882,10 +887,11 @@ and core_type_x_core_type_x_location i ppf (ct1, ct2, l) =
core_type (i+1) ppf ct1;
core_type (i+1) ppf ct2;

and constructor_decl i ppf {cd_id; cd_name = _; cd_args; cd_res; cd_loc;
cd_attributes} =
and constructor_decl i ppf {cd_id; cd_name = _; cd_vars;
cd_args; cd_res; cd_loc; cd_attributes} =
line i ppf "%a\n" fmt_location cd_loc;
line (i+1) ppf "%a\n" fmt_ident cd_id;
if cd_vars <> [] then line (i+1) ppf "cd_vars =%a\n" typevars cd_vars;
attributes i ppf cd_attributes;
constructor_arguments (i+1) ppf cd_args;
option (i+1) core_type ppf cd_res
Expand Down
2 changes: 1 addition & 1 deletion typing/tast_iterator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ let type_exception sub {tyexn_constructor; _} =

let extension_constructor sub {ext_kind; _} =
match ext_kind with
| Text_decl (ctl, cto) ->
| Text_decl (_, ctl, cto) ->
constructor_args sub ctl;
Option.iter (sub.typ sub) cto
| Text_rebind _ -> ()
Expand Down
4 changes: 2 additions & 2 deletions typing/tast_mapper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ let type_exception sub x =
let extension_constructor sub x =
let ext_kind =
match x.ext_kind with
Text_decl(ctl, cto) ->
Text_decl(constructor_args sub ctl, Option.map (sub.typ sub) cto)
Text_decl(v, ctl, cto) ->
Text_decl(v, constructor_args sub ctl, Option.map (sub.typ sub) cto)
| Text_rebind _ as d -> d
in
{x with ext_kind}
Expand Down
3 changes: 2 additions & 1 deletion typing/typedecl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ let transl_declaration env sdecl (id, uid) =
let tcstr =
{ cd_id = name;
cd_name = scstr.pcd_name;
cd_vars = scstr.pcd_vars;
cd_args = targs;
cd_res = tret_type;
cd_loc = scstr.pcd_loc;
Expand Down Expand Up @@ -990,7 +991,7 @@ let transl_extension_constructor ~scope env type_path type_params
make_constructor env sext.pext_loc type_path typext_params
svars sargs sret_type
in
args, ret_type, Text_decl(targs, tret_type)
args, ret_type, Text_decl(svars, targs, tret_type)
| Pext_rebind lid ->
let usage : Env.constructor_usage =
if priv = Public then Env.Exported else Env.Exported_private
Expand Down
3 changes: 2 additions & 1 deletion typing/typedtree.ml
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ and constructor_declaration =
{
cd_id: Ident.t;
cd_name: string loc;
cd_vars: string loc list;
cd_args: constructor_arguments;
cd_res: core_type option;
cd_loc: Location.t;
Expand Down Expand Up @@ -557,7 +558,7 @@ and extension_constructor =
}

and extension_constructor_kind =
Text_decl of constructor_arguments * core_type option
Text_decl of string loc list * constructor_arguments * core_type option
| Text_rebind of Path.t * Longident.t loc

and class_type =
Expand Down
3 changes: 2 additions & 1 deletion typing/typedtree.mli
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ and constructor_declaration =
{
cd_id: Ident.t;
cd_name: string loc;
cd_vars: string loc list;
cd_args: constructor_arguments;
cd_res: core_type option;
cd_loc: Location.t;
Expand Down Expand Up @@ -698,7 +699,7 @@ and extension_constructor =
}

and extension_constructor_kind =
Text_decl of constructor_arguments * core_type option
Text_decl of string loc list * constructor_arguments * core_type option
| Text_rebind of Path.t * Longident.t loc

and class_type =
Expand Down
5 changes: 3 additions & 2 deletions typing/untypeast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ let constructor_declaration sub cd =
let loc = sub.location sub cd.cd_loc in
let attrs = sub.attributes sub cd.cd_attributes in
Type.constructor ~loc ~attrs
~vars:cd.cd_vars
~args:(constructor_arguments sub cd.cd_args)
?res:(Option.map (sub.typ sub) cd.cd_res)
(map_loc sub cd.cd_name)
Expand Down Expand Up @@ -283,8 +284,8 @@ let extension_constructor sub ext =
Te.constructor ~loc ~attrs
(map_loc sub ext.ext_name)
(match ext.ext_kind with
| Text_decl (args, ret) ->
Pext_decl ([], constructor_arguments sub args,
| Text_decl (vs, args, ret) ->
Pext_decl (vs, constructor_arguments sub args,
Option.map (sub.typ sub) ret)
| Text_rebind (_p, lid) -> Pext_rebind (map_loc sub lid)
)
Expand Down

0 comments on commit c9f43bb

Please sign in to comment.