Skip to content

Commit 2d8f2d5

Browse files
committed
Remove Record_optional_labels entirely.
1 parent f7450bb commit 2d8f2d5

10 files changed

+20
-37
lines changed

compiler/ml/ctype.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3721,8 +3721,7 @@ let rec subtype_rec env trace t1 t2 cstrs =
37213721
(_, _, {type_kind = Type_record (fields2, repr2)}) ) ->
37223722
let same_repr =
37233723
match (repr1, repr2) with
3724-
| ( (Record_regular | Record_optional_labels),
3725-
(Record_regular | Record_optional_labels) ) ->
3724+
| Record_regular, Record_regular ->
37263725
true (* handled in the fields checks *)
37273726
| Record_unboxed b1, Record_unboxed b2 -> b1 = b2
37283727
| Record_inlined _, Record_inlined _ -> repr1 = repr2

compiler/ml/matching.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1530,7 +1530,7 @@ let make_record_matching loc all_labels def = function
15301530
let access =
15311531
match lbl.lbl_repres with
15321532
| Record_float_unused -> assert false
1533-
| Record_regular | Record_optional_labels ->
1533+
| Record_regular ->
15341534
Lprim (Pfield (lbl.lbl_pos, Lambda.fld_record lbl), [arg], loc)
15351535
| Record_inlined _ ->
15361536
Lprim

compiler/ml/predef.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ let common_initial_env add_type add_extension empty_env =
316316
ld_type = newgenty (Tconstr (path_option, [tvar], ref Mnil));
317317
};
318318
],
319-
Record_optional_labels );
319+
Record_regular );
320320
}
321321
and decl_uncurried =
322322
let tvar1, tvar2 = (newgenvar (), newgenvar ()) in

compiler/ml/printtyped.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ let record_representation i ppf =
130130
function
131131
| Record_regular -> line i ppf "Record_regular\n"
132132
| Record_float_unused -> assert false
133-
| Record_optional_labels -> line i ppf "Record_optional_labels\n"
134133
| Record_unboxed b -> line i ppf "Record_unboxed %b\n" b
135134
| Record_inlined {tag = i} -> line i ppf "Record_inlined %d\n" i
136135
| Record_extension -> line i ppf "Record_extension\n"

compiler/ml/rec_check.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,7 @@ let rec expression : Env.env -> Typedtree.expression -> Use.t =
261261
match rep with
262262
| Record_unboxed _ -> fun x -> x
263263
| Record_float_unused -> assert false
264-
| Record_optional_labels | Record_regular | Record_inlined _
265-
| Record_extension ->
266-
Use.guard
264+
| Record_regular | Record_inlined _ | Record_extension -> Use.guard
267265
in
268266
let field env = function
269267
| _, Kept _ -> Use.empty

compiler/ml/translcore.ml

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ and transl_exp0 (e : Typedtree.expression) : Lambda.lambda =
923923
let targ = transl_exp arg in
924924
match lbl.lbl_repres with
925925
| Record_float_unused -> assert false
926-
| Record_regular | Record_optional_labels ->
926+
| Record_regular ->
927927
Lprim (Pfield (lbl.lbl_pos, Lambda.fld_record lbl), [targ], e.exp_loc)
928928
| Record_inlined _ ->
929929
Lprim
@@ -938,8 +938,7 @@ and transl_exp0 (e : Typedtree.expression) : Lambda.lambda =
938938
let access =
939939
match lbl.lbl_repres with
940940
| Record_float_unused -> assert false
941-
| Record_regular | Record_optional_labels ->
942-
Psetfield (lbl.lbl_pos, Lambda.fld_record_set lbl)
941+
| Record_regular -> Psetfield (lbl.lbl_pos, Lambda.fld_record_set lbl)
943942
| Record_inlined _ ->
944943
Psetfield (lbl.lbl_pos, Lambda.fld_record_inline_set lbl)
945944
| Record_unboxed _ -> assert false
@@ -1159,6 +1158,7 @@ and transl_record loc env fields repres opt_init_expr =
11591158
else lambda
11601159
| _ -> (
11611160
let size = Array.length fields in
1161+
let optional = Ext_array.exists fields (fun (ld, _) -> ld.lbl_optional) in
11621162
(* Determine if there are "enough" fields (only relevant if this is a
11631163
functional-style record update *)
11641164
let no_init =
@@ -1167,12 +1167,7 @@ and transl_record loc env fields repres opt_init_expr =
11671167
| _ -> false
11681168
in
11691169
if
1170-
no_init
1171-
|| size < 20
1172-
&&
1173-
match repres with
1174-
| Record_optional_labels -> false
1175-
| _ -> true
1170+
no_init || (size < 20 && not optional)
11761171
(* TODO: More strategies
11771172
3 + 2 * List.length lbl_expr_list >= size (density)
11781173
*)
@@ -1188,8 +1183,7 @@ and transl_record loc env fields repres opt_init_expr =
11881183
let access =
11891184
match repres with
11901185
| Record_float_unused -> assert false
1191-
| Record_regular | Record_optional_labels ->
1192-
Pfield (i, Lambda.fld_record lbl)
1186+
| Record_regular -> Pfield (i, Lambda.fld_record lbl)
11931187
| Record_inlined _ -> Pfield (i, Lambda.fld_record_inline lbl)
11941188
| Record_unboxed _ -> assert false
11951189
| Record_extension ->
@@ -1213,10 +1207,10 @@ and transl_record loc env fields repres opt_init_expr =
12131207
| Record_float_unused -> assert false
12141208
| Record_regular ->
12151209
Lconst
1216-
(Const_block (Lambda.blk_record fields mut Record_regular, cl))
1217-
| Record_optional_labels ->
1218-
Lconst
1219-
(Const_block (Lambda.blk_record fields mut Record_optional, cl))
1210+
(Const_block
1211+
( Lambda.blk_record fields mut
1212+
(if optional then Record_optional else Record_regular),
1213+
cl ))
12201214
| Record_inlined {tag; name; num_nonconsts; attrs} ->
12211215
Lconst
12221216
(Const_block
@@ -1233,10 +1227,9 @@ and transl_record loc env fields repres opt_init_expr =
12331227
match repres with
12341228
| Record_regular ->
12351229
Lprim
1236-
(Pmakeblock (Lambda.blk_record fields mut Record_regular), ll, loc)
1237-
| Record_optional_labels ->
1238-
Lprim
1239-
( Pmakeblock (Lambda.blk_record fields mut Record_optional),
1230+
( Pmakeblock
1231+
(Lambda.blk_record fields mut
1232+
(if optional then Record_optional else Record_regular)),
12401233
ll,
12411234
loc )
12421235
| Record_float_unused -> assert false
@@ -1277,7 +1270,7 @@ and transl_record loc env fields repres opt_init_expr =
12771270
let upd =
12781271
match repres with
12791272
| Record_float_unused -> assert false
1280-
| Record_regular | Record_optional_labels ->
1273+
| Record_regular ->
12811274
Psetfield (lbl.lbl_pos, Lambda.fld_record_set lbl)
12821275
| Record_inlined _ ->
12831276
Psetfield (lbl.lbl_pos, Lambda.fld_record_inline_set lbl)

compiler/ml/typecore.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ module Label = NameChoice (struct
949949
lbl with
950950
lbl_name = name;
951951
lbl_pos = Array.length lbl.lbl_all;
952-
lbl_repres = Record_optional_labels;
952+
lbl_repres = Record_regular;
953953
}
954954
in
955955
let lbl_all_list = Array.to_list lbl.lbl_all @ [l] in
@@ -2651,7 +2651,7 @@ and type_expect_ ?type_clash_context ?in_function ?(recarg = Rejected) env sexp
26512651
} ));
26522652
([||], representation)
26532653
| [], _ ->
2654-
if fields = [] && repr_opt <> None then ([||], Record_optional_labels)
2654+
if fields = [] && repr_opt <> None then ([||], Record_regular)
26552655
else raise (Error (loc, env, Empty_record_literal))
26562656
in
26572657
let labels_missing = ref [] in

compiler/ml/typedecl.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ let transl_declaration ~type_record_as_object env sdecl id =
635635
Type_record
636636
( lbls',
637637
if unbox then Record_unboxed false
638-
else if optional then Record_optional_labels
638+
else if optional then Record_regular
639639
else Record_regular ),
640640
sdecl )
641641
| None ->

compiler/ml/types.ml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ and record_representation =
156156
attrs: Parsetree.attributes;
157157
}
158158
| Record_extension (* Inlined record under extension *)
159-
| Record_optional_labels
160159

161160
and label_declaration = {
162161
ld_id: Ident.t;
@@ -310,10 +309,6 @@ let same_record_representation x y =
310309
match x with
311310
| Record_regular -> y = Record_regular
312311
| Record_float_unused -> y = Record_float_unused
313-
| Record_optional_labels -> (
314-
match y with
315-
| Record_optional_labels -> true
316-
| _ -> false)
317312
| Record_inlined {tag; name; num_nonconsts} -> (
318313
match y with
319314
| Record_inlined y ->

compiler/ml/types.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ and record_representation =
284284
attrs: Parsetree.attributes;
285285
}
286286
| Record_extension (* Inlined record under extension *)
287-
| Record_optional_labels
288287

289288
and label_declaration = {
290289
ld_id: Ident.t;

0 commit comments

Comments
 (0)