@@ -425,7 +425,7 @@ let newvar ?name layout =
425
425
let valid_tyvar_name name =
426
426
name <> " " && name.[0 ] <> '_'
427
427
428
- let transl_type_param_var ~ generic env loc attrs name_opt
428
+ let transl_type_param_var env loc attrs name_opt
429
429
(layout : layout ) (layout_annot : const_layout option ) =
430
430
let tvar = Ttyp_var (name_opt, layout_annot) in
431
431
let name =
@@ -438,35 +438,26 @@ let transl_type_param_var ~generic env loc attrs name_opt
438
438
raise Already_bound ;
439
439
name
440
440
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;
452
443
{ ctyp_desc = tvar; ctyp_type = ty; ctyp_env = env;
453
444
ctyp_loc = loc; ctyp_attributes = attrs }
454
445
455
- let transl_type_param_jst ~ generic env loc attrs path :
446
+ let transl_type_param_jst env loc attrs path :
456
447
Jane_syntax.Core_type. t -> _ =
457
448
function
458
449
| Jtyp_layout (Ltyp_var { name; layout = annot } ) ->
459
450
let layout =
460
451
Layout. of_annotation ~context: (Type_parameter (path, name)) annot
461
452
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)
463
454
| Jtyp_layout (Ltyp_poly _ | Ltyp_alias _ ) ->
464
455
Misc. fatal_error " non-type-variable in transl_type_param_jst"
465
456
466
- let transl_type_param ~ generic env path styp =
457
+ let transl_type_param env path styp =
467
458
let loc = styp.ptyp_loc in
468
459
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
470
461
| None ->
471
462
(* Our choice for now is that if you want a parameter of layout any, you have
472
463
to ask for it with an annotation. Some restriction here seems necessary
@@ -475,25 +466,32 @@ let transl_type_param ~generic env path styp =
475
466
let layout = Layout. of_new_sort_var ~why: Unannotated_type_parameter in
476
467
let attrs = styp.ptyp_attributes in
477
468
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
479
470
| 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
481
472
| _ -> assert false
482
473
483
- let transl_type_param ~ generic env path styp =
474
+ let transl_type_param env path styp =
484
475
(* Currently useless, since type parameters cannot hold attributes
485
476
(but this could easily be lifted in the future). *)
486
477
Builtin_attributes. warning_scope styp.ptyp_attributes
487
- (fun () -> transl_type_param ~generic env path styp)
478
+ (fun () -> transl_type_param env path styp)
488
479
489
- (* returns just the layout of the param *)
490
480
let get_type_param_layout path styp =
491
481
match Jane_syntax.Core_type. of_ast styp with
492
482
| None -> Layout. of_new_sort_var ~why: Unannotated_type_parameter
493
483
| Some (Jtyp_layout (Ltyp_var { name; layout } ), _attrs ) ->
494
484
Layout. of_annotation ~context: (Type_parameter (path, name)) layout
495
485
| Some _ -> Misc. fatal_error " non-type-variable in get_type_param_layout"
496
486
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
+
497
495
let get_alloc_mode styp =
498
496
match Builtin_attributes. has_local styp.ptyp_attributes with
499
497
| Ok true -> Alloc_mode. Local
0 commit comments