Skip to content

Commit 4e57670

Browse files
flambda-backend: Define 'a or_null (#2614)
* `or_null` predef * `Or_null.t` in `Stdlib_alpha` * Enable `test_or_null` * Test that `Or_null` is exported * Formatting * Fix comment * Update `ppx-empty-cases` test numbering * `Just` -> `This` * Due to issues with arrays and separability, mark `float` as nullable * Fix tests * Fix test --------- Co-authored-by: Diana Kalinichenko <dkalinichenko@janestreet.com>
1 parent 479660e commit 4e57670

File tree

11 files changed

+555
-350
lines changed

11 files changed

+555
-350
lines changed

otherlibs/stdlib_alpha/or_null.ml

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@
1212
(* *)
1313
(**************************************************************************)
1414

15-
type ('a : non_null_value) t = 'a option
15+
type ('a : non_null_value) t = 'a or_null =
16+
| Null
17+
| This of 'a

otherlibs/stdlib_alpha/or_null.mli

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@
1313
(**************************************************************************)
1414

1515
(** Unboxed option type. Unimplemented. *)
16-
type ('a : non_null_value) t
16+
type ('a : non_null_value) t = 'a or_null =
17+
| Null
18+
| This of 'a

testsuite/tests/ppx-empty-cases/test.compilers.reference

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,35 @@
33
(empty_cases_returning_string/269 =
44
(function {nlocal = 0} param/271
55
(raise
6-
(makeblock 0 (getpredef Match_failure/32!!) [0: "test.ml" 28 50])))
6+
(makeblock 0 (getpredef Match_failure/33!!) [0: "test.ml" 28 50])))
77
empty_cases_returning_float64/272 =
88
(function {nlocal = 0} param/274 : unboxed_float
99
(raise
10-
(makeblock 0 (getpredef Match_failure/32!!) [0: "test.ml" 29 50])))
10+
(makeblock 0 (getpredef Match_failure/33!!) [0: "test.ml" 29 50])))
1111
empty_cases_accepting_string/275 =
1212
(function {nlocal = 0} param/277
1313
(raise
14-
(makeblock 0 (getpredef Match_failure/32!!) [0: "test.ml" 30 50])))
14+
(makeblock 0 (getpredef Match_failure/33!!) [0: "test.ml" 30 50])))
1515
empty_cases_accepting_float64/278 =
1616
(function {nlocal = 0} param/280[unboxed_float]
1717
(raise
18-
(makeblock 0 (getpredef Match_failure/32!!) [0: "test.ml" 31 50])))
18+
(makeblock 0 (getpredef Match_failure/33!!) [0: "test.ml" 31 50])))
1919
non_empty_cases_returning_string/281 =
2020
(function {nlocal = 0} param/283
2121
(raise
22-
(makeblock 0 (getpredef Assert_failure/42!!) [0: "test.ml" 32 68])))
22+
(makeblock 0 (getpredef Assert_failure/43!!) [0: "test.ml" 32 68])))
2323
non_empty_cases_returning_float64/284 =
2424
(function {nlocal = 0} param/286 : unboxed_float
2525
(raise
26-
(makeblock 0 (getpredef Assert_failure/42!!) [0: "test.ml" 33 68])))
26+
(makeblock 0 (getpredef Assert_failure/43!!) [0: "test.ml" 33 68])))
2727
non_empty_cases_accepting_string/287 =
2828
(function {nlocal = 0} param/289
2929
(raise
30-
(makeblock 0 (getpredef Assert_failure/42!!) [0: "test.ml" 34 68])))
30+
(makeblock 0 (getpredef Assert_failure/43!!) [0: "test.ml" 34 68])))
3131
non_empty_cases_accepting_float64/290 =
3232
(function {nlocal = 0} param/292[unboxed_float]
3333
(raise
34-
(makeblock 0 (getpredef Assert_failure/42!!) [0: "test.ml" 35 68]))))
34+
(makeblock 0 (getpredef Assert_failure/43!!) [0: "test.ml" 35 68]))))
3535
(makeblock 0 empty_cases_returning_string/269
3636
empty_cases_returning_float64/272 empty_cases_accepting_string/275
3737
empty_cases_accepting_float64/278 non_empty_cases_returning_string/281

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ let _ = [| Fake_or_null.some 3 |]
4949

5050
let _ = [: Fake_or_null.some "test " :]
5151

52-
let _ = Some (Fake_or_null.some 4.2)
52+
let _ = Some (Fake_or_null.some 42)
5353

5454
let _ = lazy (Fake_or_null.none)
5555
;;
@@ -58,7 +58,7 @@ let _ = lazy (Fake_or_null.none)
5858
- : 'a Fake_or_null.t list = [<abstr>]
5959
- : int Fake_or_null.t array = [|<abstr>|]
6060
- : string Fake_or_null.t iarray = [:<abstr>:]
61-
- : float Fake_or_null.t option = Some <abstr>
61+
- : int Fake_or_null.t option = Some <abstr>
6262
- : 'a Fake_or_null.t lazy_t = lazy <abstr>
6363
|}]
6464

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

+17-3
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,6 @@ let _ = id_non_null_value None
166166

167167
let _ = id_non_null_value (Some 0)
168168

169-
let _ = id_non_null_value 3.14
170-
171169
let _ = id_non_null_value [| 3.; 8. |]
172170

173171
let _ = id_non_null_value 4L
@@ -189,7 +187,6 @@ let _ = id_non_null_value (Bytes.empty)
189187
- : string * string = ("a", "b")
190188
- : 'a option = None
191189
- : int option = Some 0
192-
- : float = 3.14
193190
- : float array = [|3.; 8.|]
194191
- : int64 = 4L
195192
- : nativeint = 15n
@@ -199,6 +196,23 @@ let _ = id_non_null_value (Bytes.empty)
199196
- : bytes = Bytes.of_string ""
200197
|}]
201198

199+
(* CR layouts v3: [float] should be non-null: *)
200+
201+
let _ = id_non_null_value 3.14
202+
;;
203+
204+
[%%expect{|
205+
Line 1, characters 26-30:
206+
1 | let _ = id_non_null_value 3.14
207+
^^^^
208+
Error: This expression has type float but an expression was expected of type
209+
('a : non_null_value)
210+
The layout of float is value, because
211+
it is the primitive value type float.
212+
But the layout of float must be a sublayout of non_null_value, because
213+
of the definition of id_non_null_value at line 3, characters 4-21.
214+
|}]
215+
202216
(* Boxed records and variants are non-null: *)
203217

204218
type t1 = { x : int; y : string }

0 commit comments

Comments
 (0)