@@ -3298,13 +3298,10 @@ let collect_unknown_apply_args env funct ty_fun mode_fun rev_args sargs ret_tvar
3298
3298
let ty_fun = expand_head env ty_fun in
3299
3299
match get_desc ty_fun with
3300
3300
| Tvar _ ->
3301
- let sort_arg = Jkind.Sort. new_var () in
3302
- let ty_arg_mono =
3303
- newvar (Jkind. of_sort ~why: Function_argument sort_arg)
3304
- in
3301
+ let ty_arg_mono, sort_arg = new_rep_var ~why: Function_argument () in
3305
3302
let ty_arg = newmono ty_arg_mono in
3306
3303
let ty_res =
3307
- newvar (Jkind. of_new_sort_var ~why: Function_result )
3304
+ newvar (Jkind. of_new_sort ~why: Function_result )
3308
3305
in
3309
3306
if ret_tvar &&
3310
3307
not (is_prim ~name: " %identity" funct) &&
@@ -3817,7 +3814,7 @@ let rec approx_type env sty =
3817
3814
let arg =
3818
3815
if is_optional p
3819
3816
then type_option (newvar (Jkind. value ~why: Type_argument ))
3820
- else newvar (Jkind. of_new_sort_var ~why: Function_argument )
3817
+ else newvar (Jkind. of_new_sort ~why: Function_argument )
3821
3818
in
3822
3819
let ret = approx_type env sty in
3823
3820
let marg = Alloc. of_const arg_mode in
@@ -4912,10 +4909,9 @@ and type_expect_
4912
4909
tuple_pat_mode mode modes, mode_tuple mode modes
4913
4910
in
4914
4911
begin_def () ;
4915
- let sort = Jkind.Sort. new_var () in
4912
+ let expected_ty, sort = new_rep_var ~why: Match () in
4916
4913
let arg =
4917
- type_expect env arg_expected_mode sarg
4918
- (mk_expected (newvar (Jkind. of_sort ~why: Match sort)))
4914
+ type_expect env arg_expected_mode sarg (mk_expected expected_ty)
4919
4915
in
4920
4916
end_def () ;
4921
4917
if maybe_expansive arg then lower_contravariant env arg.exp_type;
@@ -5079,7 +5075,7 @@ and type_expect_
5079
5075
in
5080
5076
match expected_opath, opt_exp_opath with
5081
5077
| None , None ->
5082
- newvar (Jkind. of_new_sort_var ~why: Record_projection ), None
5078
+ newvar (Jkind. of_new_sort ~why: Record_projection ), None
5083
5079
| Some _ , None -> ty_expected, expected_opath
5084
5080
| Some (_ , _ , true ), Some _ -> ty_expected, expected_opath
5085
5081
| (None | Some (_ , _ , false )), Some (_ , p' , _ ) ->
@@ -5244,7 +5240,7 @@ and type_expect_
5244
5240
type_label_access env srecord Env. Mutation lid in
5245
5241
let ty_record =
5246
5242
if expected_type = None
5247
- then newvar (Jkind. of_new_sort_var ~why: Record_assignment )
5243
+ then newvar (Jkind. of_new_sort ~why: Record_assignment )
5248
5244
else record.exp_type
5249
5245
in
5250
5246
let (label_loc, label, newval) =
@@ -5864,29 +5860,19 @@ and type_expect_
5864
5860
let spat_params, ty_params, param_sort =
5865
5861
let initial_jkind, initial_sort = match sands with
5866
5862
| [] ->
5867
- let sort = Jkind.Sort. new_var () in
5868
- Jkind. of_sort ~why: Function_argument sort, sort
5863
+ Jkind. of_new_sort_var ~why: Function_argument
5869
5864
(* CR layouts v5: eliminate value requirement for tuple elements *)
5870
5865
| _ -> Jkind. value ~why: Tuple_element , Jkind.Sort. value
5871
5866
in
5872
5867
loop slet.pbop_pat (newvar initial_jkind) initial_sort sands
5873
5868
in
5874
- let body_sort = Jkind.Sort. new_var () in
5875
- let ty_func_result =
5876
- newvar (Jkind. of_sort ~why: Function_result body_sort)
5877
- in
5869
+ let ty_func_result, body_sort = new_rep_var ~why: Function_result () in
5878
5870
let arrow_desc = Nolabel , Alloc. legacy, Alloc. legacy in
5879
5871
let ty_func =
5880
5872
newty (Tarrow (arrow_desc, newmono ty_params, ty_func_result, commu_ok))
5881
5873
in
5882
- let op_result_sort = Jkind.Sort. new_var () in
5883
- let ty_result =
5884
- newvar (Jkind. of_sort ~why: Function_result op_result_sort)
5885
- in
5886
- let sort_andops = Jkind.Sort. new_var () in
5887
- let ty_andops =
5888
- newvar (Jkind. of_sort ~why: Function_argument sort_andops)
5889
- in
5874
+ let ty_result, op_result_sort = new_rep_var ~why: Function_result () in
5875
+ let ty_andops, sort_andops = new_rep_var ~why: Function_argument () in
5890
5876
let ty_op =
5891
5877
newty (Tarrow (arrow_desc, newmono ty_andops,
5892
5878
newty (Tarrow (arrow_desc, newmono ty_func,
@@ -7072,8 +7058,7 @@ and type_statement ?explanation ?(position=RNontail) env sexp =
7072
7058
getting a sort variable for its jkind. *)
7073
7059
(* CR layouts v10: Abstract jkinds will introduce cases where we really
7074
7060
have [any] and can't get a sort here. *)
7075
- let sort = Jkind.Sort. new_var () in
7076
- let tv = newvar (Jkind. of_sort ~why: Statement sort) in
7061
+ let tv, sort = new_rep_var ~why: Statement () in
7077
7062
if is_Tvar ty && get_level ty > get_level tv then
7078
7063
Location. prerr_warning
7079
7064
(final_subexpression exp).exp_loc
@@ -7448,9 +7433,8 @@ and type_let
7448
7433
attrs, pat_mode, exp_mode, spat)
7449
7434
spat_sexp_list in
7450
7435
let is_recursive = (rec_flag = Recursive ) in
7451
- let sorts = List. map (fun _ -> Jkind.Sort. new_var () ) spatl in
7452
- let nvs =
7453
- List. map (fun s -> newvar (Jkind. of_sort ~why: Let_binding s)) sorts
7436
+ let nvs, sorts =
7437
+ List. split (List. map (fun _ -> new_rep_var ~why: Let_binding () ) spatl)
7454
7438
in
7455
7439
if is_recursive then begin_def () ;
7456
7440
let (pat_list, new_env, force, pvs, mvs) =
@@ -7713,14 +7697,9 @@ and type_andops env sarg sands expected_sort expected_ty =
7713
7697
if ! Clflags. principal then begin_def () ;
7714
7698
let op_path, op_desc = type_binding_op_ident env sop in
7715
7699
let op_type = op_desc.val_type in
7716
- let sort_arg = Jkind.Sort. new_var () in
7717
- let ty_arg = newvar (Jkind. of_sort ~why: Function_argument sort_arg) in
7718
- let sort_rest = Jkind.Sort. new_var () in
7719
- let ty_rest = newvar (Jkind. of_sort ~why: Function_argument sort_rest) in
7720
- let op_result_sort = Jkind.Sort. new_var () in
7721
- let ty_result =
7722
- newvar (Jkind. of_sort ~why: Function_result op_result_sort)
7723
- in
7700
+ let ty_arg, sort_arg = new_rep_var ~why: Function_argument () in
7701
+ let ty_rest, sort_rest = new_rep_var ~why: Function_argument () in
7702
+ let ty_result, op_result_sort = new_rep_var ~why: Function_result () in
7724
7703
let arrow_desc = (Nolabel ,Alloc. legacy,Alloc. legacy) in
7725
7704
let ty_rest_fun =
7726
7705
newty (Tarrow (arrow_desc, newmono ty_arg, ty_result, commu_ok))
@@ -8239,8 +8218,8 @@ let type_expression env jkind sexp =
8239
8218
maybe_check_uniqueness_exp exp; exp
8240
8219
8241
8220
let type_representable_expression ~why env sexp =
8242
- let sort = Jkind.Sort. new_var () in
8243
- let exp = type_expression env ( Jkind. of_sort ~why sort) sexp in
8221
+ let jkind, sort = Jkind. of_new_sort_var ~why in
8222
+ let exp = type_expression env jkind sexp in
8244
8223
exp, sort
8245
8224
8246
8225
let type_expression env sexp =
0 commit comments