@@ -381,18 +381,15 @@ let set_private_row env loc p decl =
381
381
in
382
382
set_type_desc rv (Tconstr (p, decl.type_params, ref Mnil ))
383
383
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]. *)
389
386
(* CR layouts: Many places where [check_representable] is called in this file
390
387
should be replaced with checks at the places where values of those types are
391
388
constructed. We've been conservative here in the first version. This is the
392
389
same issue as with arrows. *)
393
390
let check_representable ~why ~allow_unboxed env loc kloc typ =
394
391
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
396
393
structures that don't support them yet. (A callsite passes
397
394
[~allow_unboxed:true] to indicate that non-value types are allowed.)
398
395
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 =
466
463
lbls in
467
464
lbls, lbls'
468
465
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 =
470
468
let mk idx arg =
471
469
let cty = transl_simple_type ~new_var_jkind env ?univars ~closed Mode.Alloc.Const. legacy arg in
472
470
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
479
477
let tyl_gfl' = List. map (fun (cty , gf ) -> cty.ctyp_type, gf) tyl_gfl in
480
478
tyl_gfl, tyl_gfl'
481
479
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
483
482
| 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
487
490
| 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
489
497
Types. Cstr_record lbls',
490
498
Cstr_record lbls
491
499
@@ -517,7 +525,8 @@ let make_constructor
517
525
match sret_type with
518
526
| None ->
519
527
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
521
530
in
522
531
tvars, targs, None , args, None
523
532
| Some sret_type ->
@@ -543,7 +552,8 @@ let make_constructor
543
552
in
544
553
let univars = if closed then Some univar_list else None in
545
554
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
547
557
in
548
558
let tret_type =
549
559
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) =
846
856
in
847
857
Ttype_variant tcstrs, Type_variant (cstrs, rep), jkind
848
858
| 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
850
865
let rep, jkind =
851
866
(* Note this is inaccurate, using `Record_boxed` in cases where the
852
867
correct representation is [Record_float], [Record_ufloat], or
0 commit comments