@@ -31,22 +31,24 @@ type error =
31
31
Free_super_var
32
32
| Unreachable_reached
33
33
| Bad_probe_layout of Ident .t
34
- | Non_value_layout of Layout.Violation .violation
34
+ | Non_value_layout of Layout.Violation .t
35
35
36
36
exception Error of Location. t * error
37
37
38
38
let use_dup_for_constant_mutable_arrays_bigger_than = 4
39
39
40
40
(* CR layouts v2: When we're ready to allow non-values, these can be deleted or
41
41
changed to check for void. *)
42
- let sort_must_be_value loc sort =
42
+ let sort_must_be_value ~ why loc sort =
43
43
if not Sort. (equate sort value) then
44
- let violation = Layout. (Violation. not_a_sublayout (of_sort sort) value) in
44
+ let violation = Layout. (Violation. of_ (Not_a_sublayout
45
+ (of_sort ~why sort,
46
+ value ~why: V1_safety_check ))) in
45
47
raise (Error (loc, Non_value_layout violation))
46
48
47
49
let layout_must_be_value loc layout =
48
- match Layout. (sub layout value) with
49
- | Ok () -> ()
50
+ match Layout. (sub layout ( value ~why: V1_safety_check ) ) with
51
+ | Ok _ -> ()
50
52
| Error e -> raise (Error (loc, Non_value_layout e))
51
53
52
54
(* CR layouts v2: In the places where this is used, we want to allow any (the
@@ -61,9 +63,10 @@ let layout_must_be_value loc layout =
61
63
*)
62
64
let layout_must_not_be_void loc layout =
63
65
Layout. default_to_value layout;
64
- match Layout. (sub layout void) with
65
- | Ok () ->
66
- let violation = Layout. (Violation. not_a_sublayout layout value) in
66
+ match Layout. (sub layout (void ~why: V1_safety_check )) with
67
+ | Ok _ ->
68
+ let violation = Layout. (Violation. of_ (Not_a_sublayout
69
+ (layout, value ~why: V1_safety_check ))) in
67
70
raise (Error (loc, Non_value_layout violation))
68
71
| Error _ -> ()
69
72
@@ -907,8 +910,9 @@ and transl_exp0 ~in_new_scope ~scopes e =
907
910
with
908
911
| {val_type; _} -> begin
909
912
match
910
- Ctype. check_type_layout ~reason: (Fixed_layout Probe )
911
- e.exp_env (Ctype. correct_levels val_type) Layout. value
913
+ Ctype. check_type_layout
914
+ e.exp_env (Ctype. correct_levels val_type)
915
+ (Layout. value ~why: Probe )
912
916
with
913
917
| Ok _ -> ()
914
918
| Error _ -> raise (Error (e.exp_loc, Bad_probe_layout id))
@@ -1354,7 +1358,7 @@ and transl_let ~scopes ?(add_regions=false) ?(in_structure=false)
1354
1358
:: rem ->
1355
1359
(* CR layouts v2: allow non-values. Either remove this or replace
1356
1360
with void-specific sanity check. *)
1357
- sort_must_be_value expr.exp_loc sort;
1361
+ sort_must_be_value ~why: Let_binding expr.exp_loc sort;
1358
1362
let lam = transl_bound_exp ~scopes ~in_structure pat expr in
1359
1363
let lam = Translattribute. add_function_attributes lam vb_loc attr in
1360
1364
let lam = if add_regions then maybe_region_exp expr lam else lam in
@@ -1374,7 +1378,7 @@ and transl_let ~scopes ?(add_regions=false) ?(in_structure=false)
1374
1378
{vb_expr =expr ; vb_sort; vb_attributes; vb_loc; vb_pat} id =
1375
1379
(* CR layouts v2: allow non-values. Either remove this or replace
1376
1380
with void-specific sanity check. *)
1377
- sort_must_be_value expr.exp_loc vb_sort;
1381
+ sort_must_be_value ~why: Let_binding expr.exp_loc vb_sort;
1378
1382
let lam = transl_bound_exp ~scopes ~in_structure vb_pat expr in
1379
1383
let lam =
1380
1384
Translattribute. add_function_attributes lam vb_loc vb_attributes
0 commit comments