Skip to content

Commit 69511cd

Browse files
Comments and formatting
1 parent 7860594 commit 69511cd

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

ocaml/typing/typedecl.ml

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -381,18 +381,15 @@ let set_private_row env loc p decl =
381381
in
382382
set_type_desc rv (Tconstr (p, decl.type_params, ref Mnil))
383383

384-
(* Makes sure a type is representable. Will lower "any" to "value". *)
385-
(* CR layouts: In the places where this is used, we first call this to
386-
ensure a type is representable, and then call [Ctype.type_jkind] to get the
387-
most precise jkind. These could be combined into some new function
388-
[Ctype.type_jkind_representable] that avoids duplicated work *)
384+
(* Makes sure a type is representable. Will lower [any] to a sort variable
385+
if [allow_unboxed = true], and to [value] if [allow_unboxed = false]. *)
389386
(* CR layouts: Many places where [check_representable] is called in this file
390387
should be replaced with checks at the places where values of those types are
391388
constructed. We've been conservative here in the first version. This is the
392389
same issue as with arrows. *)
393390
let check_representable ~why ~allow_unboxed env loc kloc typ =
394391
match Ctype.type_sort ~why env typ with
395-
(* CR layouts v3: This is a convenient place to rule out non-value types in
392+
(* CR layouts v5: This is a convenient place to rule out non-value types in
396393
structures that don't support them yet. (A callsite passes
397394
[~allow_unboxed:true] to indicate that non-value types are allowed.)
398395
When we support mixed blocks everywhere, this [check_representable]
@@ -466,7 +463,8 @@ let transl_labels ~new_var_jkind ~allow_unboxed env univars closed lbls kloc =
466463
lbls in
467464
lbls, lbls'
468465

469-
let transl_types_gf ~new_var_jkind ~allow_unboxed env loc univars closed tyl kloc =
466+
let transl_types_gf ~new_var_jkind ~allow_unboxed
467+
env loc univars closed tyl kloc =
470468
let mk idx arg =
471469
let cty = transl_simple_type ~new_var_jkind env ?univars ~closed Mode.Alloc.Const.legacy arg in
472470
let gf = Typemode.transl_global_flags
@@ -479,13 +477,23 @@ let transl_types_gf ~new_var_jkind ~allow_unboxed env loc univars closed tyl klo
479477
let tyl_gfl' = List.map (fun (cty, gf) -> cty.ctyp_type, gf) tyl_gfl in
480478
tyl_gfl, tyl_gfl'
481479

482-
let transl_constructor_arguments ~new_var_jkind ~unboxed env loc univars closed = function
480+
let transl_constructor_arguments ~new_var_jkind ~unboxed
481+
env loc univars closed = function
483482
| Pcstr_tuple l ->
484-
let flds, flds' = transl_types_gf ~new_var_jkind ~allow_unboxed:(not unboxed) env loc univars closed l (Cstr_tuple { unboxed }) in
485-
Types.Cstr_tuple flds',
486-
Cstr_tuple flds
483+
let flds, flds' =
484+
(* CR layouts: we forbid [@@unboxed] variants from being
485+
non-value, see comment in [check_representable]. *)
486+
transl_types_gf ~new_var_jkind ~allow_unboxed:(not unboxed)
487+
env loc univars closed l (Cstr_tuple { unboxed })
488+
in
489+
Types.Cstr_tuple flds', Cstr_tuple flds
487490
| Pcstr_record l ->
488-
let lbls, lbls' = transl_labels ~new_var_jkind ~allow_unboxed:false env univars closed l (Inlined_record { unboxed }) in
491+
let lbls, lbls' =
492+
(* CR layouts: we forbid fields of inlined records from being
493+
non-value, see comment in [check_representable]. *)
494+
transl_labels ~new_var_jkind ~allow_unboxed:false
495+
env univars closed l (Inlined_record { unboxed })
496+
in
489497
Types.Cstr_record lbls',
490498
Cstr_record lbls
491499

@@ -517,7 +525,8 @@ let make_constructor
517525
match sret_type with
518526
| None ->
519527
let args, targs =
520-
transl_constructor_arguments ~new_var_jkind:Any ~unboxed env loc None true sargs
528+
transl_constructor_arguments ~new_var_jkind:Any ~unboxed
529+
env loc None true sargs
521530
in
522531
tvars, targs, None, args, None
523532
| Some sret_type ->
@@ -543,7 +552,8 @@ let make_constructor
543552
in
544553
let univars = if closed then Some univar_list else None in
545554
let args, targs =
546-
transl_constructor_arguments ~new_var_jkind:Sort ~unboxed env loc univars closed sargs
555+
transl_constructor_arguments ~new_var_jkind:Sort ~unboxed
556+
env loc univars closed sargs
547557
in
548558
let tret_type =
549559
transl_simple_type ~new_var_jkind:Sort env ?univars ~closed Mode.Alloc.Const.legacy
@@ -846,7 +856,12 @@ let transl_declaration env sdecl (id, uid) =
846856
in
847857
Ttype_variant tcstrs, Type_variant (cstrs, rep), jkind
848858
| Ptype_record lbls ->
849-
let lbls, lbls' = transl_labels ~new_var_jkind:Any ~allow_unboxed:(not unbox) env None true lbls (Record { unboxed = unbox }) in
859+
let lbls, lbls' =
860+
(* CR layouts: we forbid [@@unboxed] records from being
861+
non-value, see comment in [check_representable]. *)
862+
transl_labels ~new_var_jkind:Any ~allow_unboxed:(not unbox)
863+
env None true lbls (Record { unboxed = unbox })
864+
in
850865
let rep, jkind =
851866
(* Note this is inaccurate, using `Record_boxed` in cases where the
852867
correct representation is [Record_float], [Record_ufloat], or

0 commit comments

Comments
 (0)