Skip to content

Commit 7d862d0

Browse files
authored
No unboxed versions for mixed-float records (#3915)
No mixed float implicit unboxed records
1 parent 1c732b7 commit 7d862d0

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

testsuite/tests/typing-layouts/hash_types.ml

+12-2
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ val f : 'a rep -> int = <fun>
146146
(***********************************)
147147
(* Implicit unboxed records basics *)
148148

149-
(* Boxed, including mixed-block, records get implicit unboxed records *)
149+
(* Boxed records, including non-float mixed-block records, get implicit unboxed
150+
records *)
150151
type r = { i : int ; s : string }
151152
type u : immediate & value = r#
152153
[%%expect{|
@@ -160,7 +161,7 @@ type r = { s : string; f : float#; }
160161
type u = r#
161162
|}]
162163

163-
(* But not float or [@@unboxed] records *)
164+
(* But not float, mixed float/float#, or [@@unboxed] records *)
164165
type r = { f : float ; f2 : float }
165166
type bad = r#
166167
[%%expect{|
@@ -170,6 +171,15 @@ Line 2, characters 11-13:
170171
^^
171172
Error: The type "r" has no unboxed version.
172173
|}]
174+
type r = { f : float ; f2 : float# }
175+
type bad = r#
176+
[%%expect{|
177+
type r = { f : float; f2 : float#; }
178+
Line 2, characters 11-13:
179+
2 | type bad = r#
180+
^^
181+
Error: The type "r" has no unboxed version.
182+
|}]
173183
type r = { i : int } [@@unboxed]
174184
type bad = r#
175185
[%%expect{|

typing/typedecl.ml

+18-10
Original file line numberDiff line numberDiff line change
@@ -1124,23 +1124,31 @@ let transl_declaration env sdecl (id, uid) =
11241124
also have unboxed versions, but these aren't stored in
11251125
[type_unboxed_version].
11261126
*)
1127+
let record_gets_unboxed_version = function
1128+
| Record_unboxed | Record_inlined _ | Record_float | Record_ufloat -> false
1129+
| Record_boxed _ -> true
1130+
| Record_mixed shape ->
1131+
Array.for_all
1132+
(fun (kind : mixed_block_element) ->
1133+
match kind with
1134+
| Value | Float64 | Float32 | Bits32 | Bits64 | Vec128 | Word -> true
1135+
| Float_boxed -> false)
1136+
shape
11271137
let gets_unboxed_version decl =
11281138
(* This must be kept in sync with the match in [derive_unboxed_version] *)
11291139
match decl.type_kind with
1130-
| Type_abstract _ | Type_open | Type_record_unboxed_product _ | Type_variant _
1131-
| Type_record (_, (Record_unboxed | Record_inlined _ | Record_float
1132-
| Record_ufloat), _)->
1133-
false
1134-
| Type_record (_, (Record_boxed _ | Record_mixed _), _) ->
1135-
true
1140+
| Type_abstract _ | Type_open | Type_record_unboxed_product _
1141+
| Type_variant _ -> false
1142+
| Type_record (_, repr, _) -> record_gets_unboxed_version repr
11361143
let derive_unboxed_version env path_in_group_has_unboxed_version decl =
11371144
(* This must be kept in sync with the match in [gets_unboxed_version] *)
11381145
match decl.type_kind with
1139-
| Type_abstract _ | Type_open | Type_record_unboxed_product _ | Type_variant _
1140-
| Type_record (_, (Record_unboxed | Record_inlined _ | Record_float
1141-
| Record_ufloat), _)->
1146+
| Type_abstract _ | Type_open | Type_record_unboxed_product _
1147+
| Type_variant _ ->
1148+
None
1149+
| Type_record (_, repr, _) when not (record_gets_unboxed_version repr) ->
11421150
None
1143-
| Type_record (lbls, (Record_boxed _ | Record_mixed _), umc) ->
1151+
| Type_record (lbls, _, umc) ->
11441152
let keep_attribute a =
11451153
(* If we keep [@deprecated_mutable], then a record that aliases
11461154
a record with a [@deprecated_mutable] label will cause two alerts,

0 commit comments

Comments
 (0)