Skip to content

Commit 71d7a55

Browse files
flambda-backend: Unboxed records may be null (#2648)
* Tests * Fix incorrect assumption about records --------- Co-authored-by: Diana Kalinichenko <dkalinichenko@janestreet.com>
1 parent d5ba6e9 commit 71d7a55

File tree

3 files changed

+53
-7
lines changed

3 files changed

+53
-7
lines changed

testsuite/tests/typing-layouts-non-null-value/arguments.ml

+44
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,47 @@ let _ = my_id4 (Fake_or_null.some 4)
127127
- : int Fake_or_null.t = <abstr>
128128
- : int Fake_or_null.t = <abstr>
129129
|}]
130+
131+
(* Check behavior of type arguments and unboxed annotations. *)
132+
133+
module M2 : sig
134+
type 'a t = { v : 'a } [@@unboxed]
135+
136+
val box : 'a -> 'a t
137+
val unbox : 'a t -> 'a
138+
end = struct
139+
type 'a t = { v : 'a } [@@unboxed]
140+
141+
let box v = { v }
142+
let unbox { v } = v
143+
end
144+
145+
[%%expect{|
146+
module M2 :
147+
sig
148+
type 'a t = { v : 'a; } [@@unboxed]
149+
val box : 'a -> 'a t
150+
val unbox : 'a t -> 'a
151+
end
152+
|}]
153+
154+
module M3 : sig
155+
type 'a t = V of 'a [@@unboxed]
156+
157+
val box : 'a -> 'a t
158+
val unbox : 'a t -> 'a
159+
end = struct
160+
type 'a t = V of 'a [@@unboxed]
161+
162+
let box v = V v
163+
let unbox (V v) = v
164+
end
165+
166+
[%%expect{|
167+
module M3 :
168+
sig
169+
type 'a t = V of 'a [@@unboxed]
170+
val box : 'a -> 'a t
171+
val unbox : 'a t -> 'a
172+
end
173+
|}]

testsuite/tests/typing-layouts/basics_alpha.ml

+6-6
Original file line numberDiff line numberDiff line change
@@ -693,15 +693,15 @@ module M9_4 = struct
693693
| ({vur_void = _},i) -> i
694694
end;;
695695
[%%expect {|
696-
Line 4, characters 8-16:
696+
Line 4, characters 7-21:
697697
4 | | ({vur_void = _},i) -> i
698-
^^^^^^^^
699-
Error: The record field vur_void belongs to the type void_unboxed_record
700-
but is mixed here with fields of type ('a : non_null_value)
698+
^^^^^^^^^^^^^^
699+
Error: This pattern matches values of type void_unboxed_record
700+
but a pattern was expected which matches values of type ('a : value)
701701
The layout of void_unboxed_record is void, because
702702
of the definition of t_void at line 6, characters 0-19.
703-
But the layout of void_unboxed_record must be a sublayout of non_null_value, because
704-
it's a boxed record type.
703+
But the layout of void_unboxed_record must be a sublayout of value, because
704+
it's the type of a tuple element.
705705
|}];;
706706

707707
module M9_5 = struct

typing/typecore.ml

+3-1
Original file line numberDiff line numberDiff line change
@@ -2669,7 +2669,9 @@ and type_pat_aux
26692669
let ty = generic_instance expected_ty in
26702670
Some (p0, p, is_principal expected_ty), ty
26712671
| Maybe_a_record_type ->
2672-
None, newvar (Jkind.non_null_value ~why:Boxed_record)
2672+
(* We can't assume that the jkind of a record type is [non_null_value]
2673+
because of unboxed records. *)
2674+
None, newvar (Jkind.any ~why:Dummy_jkind)
26732675
| Not_a_record_type ->
26742676
let error = Wrong_expected_kind(Record, Pattern, expected_ty) in
26752677
raise (Error (loc, !env, error))

0 commit comments

Comments
 (0)