Skip to content

Commit c11a79f

Browse files
committed
Remove call to make_params in enter_type
1 parent 0f0b89a commit c11a79f

File tree

4 files changed

+39
-33
lines changed

4 files changed

+39
-33
lines changed

ocaml/typing/typeclass.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1615,7 +1615,7 @@ let class_infos define_class kind
16151615
let ci_params =
16161616
let make_param (sty, v) =
16171617
try
1618-
let param = transl_type_param ~generic:false env (Pident ty_id) sty in
1618+
let param = transl_type_param env (Pident ty_id) sty in
16191619
(* CR layouts: we require class type parameters to be values, but
16201620
we should lift this restriction. Doing so causes bad error messages
16211621
today, so we wait for tomorrow. *)

ocaml/typing/typedecl.ml

+16-10
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ let get_unboxed_from_attributes sdecl =
107107
(* [make_params] creates sort variables - these can be defaulted away (as in
108108
transl_type_decl) or unified with existing sort-variable-free types (as in
109109
transl_with_constraint). *)
110-
let make_params ~generic env path params =
110+
let make_params env path params =
111111
TyVarEnv.reset (); (* [transl_type_param] binds type variables *)
112112
let make_param (sty, v) =
113113
try
114-
(transl_type_param ~generic env path sty, v)
114+
(transl_type_param env path sty, v)
115115
with Already_bound ->
116116
raise(Error(sty.ptyp_loc, Repeated_parameter))
117117
in
@@ -194,22 +194,28 @@ let enter_type rec_flag env sdecl (id, uid) =
194194
layout of the variable put in manifests here is updated when constraints
195195
are checked and then unified with the real manifest and checked against the
196196
kind. *)
197-
let layout =
197+
let type_layout =
198198
(* We set ~legacy_immediate to true because we're looking at a declaration
199199
that was already allowed to be [@@immediate] *)
200200
layout_of_attributes_default
201201
~legacy_immediate:true ~context:(Type_declaration path)
202202
~default:(Layout.any ~why:Initial_typedecl_env)
203203
sdecl.ptype_attributes
204204
in
205+
let type_params =
206+
List.map (fun (param, _) ->
207+
let name = get_type_param_name param in
208+
let layout = get_type_param_layout path param in
209+
Btype.newgenvar ?name layout)
210+
sdecl.ptype_params
211+
in
205212
let decl =
206-
{ type_params = List.map (fun (ctyp, _) -> ctyp.ctyp_type)
207-
(make_params ~generic:true env path sdecl.ptype_params);
213+
{ type_params;
208214
type_arity = arity;
209215
type_kind = Type_abstract;
210-
type_layout = layout;
216+
type_layout;
211217
type_private = sdecl.ptype_private;
212-
type_manifest = Some (Ctype.newvar layout);
218+
type_manifest = Some (Ctype.newvar type_layout);
213219
type_variance = Variance.unknown_signature ~injective:false ~arity;
214220
type_separability = Types.Separability.default_signature ~arity;
215221
type_is_newtype = false;
@@ -590,7 +596,7 @@ let transl_declaration env sdecl (id, uid) =
590596
TyVarEnv.reset ();
591597
Ctype.begin_def ();
592598
let path = Path.Pident id in
593-
let tparams = make_params ~generic:false env path sdecl.ptype_params in
599+
let tparams = make_params env path sdecl.ptype_params in
594600
let params = List.map (fun (cty, _) -> cty.ctyp_type) tparams in
595601
let cstrs = List.map
596602
(fun (sty, sty', loc) ->
@@ -1743,7 +1749,7 @@ let transl_type_extension extend env loc styext =
17431749
| Some err -> raise (Error(loc, Extension_mismatch (type_path, env, err)))
17441750
end;
17451751
let ttype_params =
1746-
make_params ~generic:false env type_path styext.ptyext_params
1752+
make_params env type_path styext.ptyext_params
17471753
in
17481754
let type_params = List.map (fun (cty, _) -> cty.ctyp_type) ttype_params in
17491755
List.iter2 (Ctype.unify_var env)
@@ -2083,7 +2089,7 @@ let transl_with_constraint id ?fixed_row_path ~sig_env ~sig_decl ~outer_env
20832089
declaration [sdecl] in the outer environment [outer_env]. *)
20842090
let env = outer_env in
20852091
let loc = sdecl.ptype_loc in
2086-
let tparams = make_params ~generic:false env (Pident id) sdecl.ptype_params in
2092+
let tparams = make_params env (Pident id) sdecl.ptype_params in
20872093
let params = List.map (fun (cty, _) -> cty.ctyp_type) tparams in
20882094
let arity = List.length params in
20892095
let constraints =

ocaml/typing/typetexp.ml

+19-21
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ let newvar ?name layout =
425425
let valid_tyvar_name name =
426426
name <> "" && name.[0] <> '_'
427427

428-
let transl_type_param_var ~generic env loc attrs name_opt
428+
let transl_type_param_var env loc attrs name_opt
429429
(layout : layout) (layout_annot : const_layout option) =
430430
let tvar = Ttyp_var (name_opt, layout_annot) in
431431
let name =
@@ -438,35 +438,26 @@ let transl_type_param_var ~generic env loc attrs name_opt
438438
raise Already_bound;
439439
name
440440
in
441-
let ty = if generic
442-
then
443-
(* this case is used in [Typedecl.enter_type], when we're creating
444-
a temporary env just for layout checking; no need to actually
445-
add the variable to the env *)
446-
Btype.newgenvar ~name layout
447-
else
448-
let ty = new_global_var ~name layout in
449-
Option.iter (fun name -> TyVarEnv.add name ty) name_opt;
450-
ty
451-
in
441+
let ty = new_global_var ~name layout in
442+
Option.iter (fun name -> TyVarEnv.add name ty) name_opt;
452443
{ ctyp_desc = tvar; ctyp_type = ty; ctyp_env = env;
453444
ctyp_loc = loc; ctyp_attributes = attrs }
454445

455-
let transl_type_param_jst ~generic env loc attrs path :
446+
let transl_type_param_jst env loc attrs path :
456447
Jane_syntax.Core_type.t -> _ =
457448
function
458449
| Jtyp_layout (Ltyp_var { name; layout = annot }) ->
459450
let layout =
460451
Layout.of_annotation ~context:(Type_parameter (path, name)) annot
461452
in
462-
transl_type_param_var ~generic env loc attrs name layout (Some annot.txt)
453+
transl_type_param_var env loc attrs name layout (Some annot.txt)
463454
| Jtyp_layout (Ltyp_poly _ | Ltyp_alias _) ->
464455
Misc.fatal_error "non-type-variable in transl_type_param_jst"
465456

466-
let transl_type_param ~generic env path styp =
457+
let transl_type_param env path styp =
467458
let loc = styp.ptyp_loc in
468459
match Jane_syntax.Core_type.of_ast styp with
469-
| Some (etyp, attrs) -> transl_type_param_jst ~generic env loc attrs path etyp
460+
| Some (etyp, attrs) -> transl_type_param_jst env loc attrs path etyp
470461
| None ->
471462
(* Our choice for now is that if you want a parameter of layout any, you have
472463
to ask for it with an annotation. Some restriction here seems necessary
@@ -475,25 +466,32 @@ let transl_type_param ~generic env path styp =
475466
let layout = Layout.of_new_sort_var ~why:Unannotated_type_parameter in
476467
let attrs = styp.ptyp_attributes in
477468
match styp.ptyp_desc with
478-
Ptyp_any -> transl_type_param_var ~generic env loc attrs None layout None
469+
Ptyp_any -> transl_type_param_var env loc attrs None layout None
479470
| Ptyp_var name ->
480-
transl_type_param_var ~generic env loc attrs (Some name) layout None
471+
transl_type_param_var env loc attrs (Some name) layout None
481472
| _ -> assert false
482473

483-
let transl_type_param ~generic env path styp =
474+
let transl_type_param env path styp =
484475
(* Currently useless, since type parameters cannot hold attributes
485476
(but this could easily be lifted in the future). *)
486477
Builtin_attributes.warning_scope styp.ptyp_attributes
487-
(fun () -> transl_type_param ~generic env path styp)
478+
(fun () -> transl_type_param env path styp)
488479

489-
(* returns just the layout of the param *)
490480
let get_type_param_layout path styp =
491481
match Jane_syntax.Core_type.of_ast styp with
492482
| None -> Layout.of_new_sort_var ~why:Unannotated_type_parameter
493483
| Some (Jtyp_layout (Ltyp_var { name; layout }), _attrs) ->
494484
Layout.of_annotation ~context:(Type_parameter (path, name)) layout
495485
| Some _ -> Misc.fatal_error "non-type-variable in get_type_param_layout"
496486

487+
let get_type_param_name styp =
488+
(* We don't need to check for jane-syntax here, just to get the
489+
name. *)
490+
match styp.ptyp_desc with
491+
| Ptyp_any -> None
492+
| Ptyp_var name -> Some name
493+
| _ -> Misc.fatal_error "non-type-variable in get_type_param_name"
494+
497495
let get_alloc_mode styp =
498496
match Builtin_attributes.has_local styp.ptyp_attributes with
499497
| Ok true -> Alloc_mode.Local

ocaml/typing/typetexp.mli

+3-1
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,12 @@ val transl_simple_type_delayed
6969
val transl_type_scheme:
7070
Env.t -> Parsetree.core_type -> Typedtree.core_type
7171
val transl_type_param:
72-
generic:bool -> Env.t -> Path.t -> Parsetree.core_type -> Typedtree.core_type
72+
Env.t -> Path.t -> Parsetree.core_type -> Typedtree.core_type
7373
(* the Path.t above is of the type/class whose param we are processing;
7474
the level defaults to the current level *)
75+
7576
val get_type_param_layout: Path.t -> Parsetree.core_type -> layout
77+
val get_type_param_name: Parsetree.core_type -> string option
7678

7779
val get_alloc_mode : Parsetree.core_type -> alloc_mode_const
7880

0 commit comments

Comments
 (0)