forked from ocaml-flambda/flambda-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make various primitives
non_null_value
(ocaml-flambda#2604)
* `non_null_value_creation_reason` * Immediates are non-null * Primitives are non-null * Extensible variants are non-null * Boxed variants are non-null * Boxed records are non-null * Tuples are non-null * Polymorphic variants are non-null * Arrows are non-null * First-class modules are non-null * Basic tests * More tests * More tests * Leave `lazy_t` nullable for now * More basic tests * More tests * Format * Update ocaml/testsuite/tests/typing-layouts-non-null-value/basics.ml Co-authored-by: Richard Eisenberg <[email protected]> * stable -> upstream_compatible * Update comments and tests * Display `non_null_value` as `value` (ocaml-flambda#2613) * Naive hack * Promote tests * More hacks * More hacks + promote tests * Test hiding * Stub `Or_null` module * Test sublayot error * Formatting --------- Co-authored-by: Diana Kalinichenko <[email protected]> --------- Co-authored-by: Diana Kalinichenko <[email protected]> Co-authored-by: Richard Eisenberg <[email protected]>
- Loading branch information
1 parent
ba58471
commit fd39aec
Showing
23 changed files
with
1,198 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
(**************************************************************************) | ||
(* *) | ||
(* OCaml *) | ||
(* *) | ||
(* Diana Kalinichenko, Jane Street, New York *) | ||
(* *) | ||
(* Copyright 2024 Jane Street Group LLC *) | ||
(* *) | ||
(* All rights reserved. This file is distributed under the terms of *) | ||
(* the GNU Lesser General Public License version 2.1, with the *) | ||
(* special exception on linking described in the file LICENSE. *) | ||
(* *) | ||
(**************************************************************************) | ||
|
||
type ('a : non_null_value) t = 'a option |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
(**************************************************************************) | ||
(* *) | ||
(* OCaml *) | ||
(* *) | ||
(* Diana Kalinichenko, Jane Street, New York *) | ||
(* *) | ||
(* Copyright 2024 Jane Street Group LLC *) | ||
(* *) | ||
(* All rights reserved. This file is distributed under the terms of *) | ||
(* the GNU Lesser General Public License version 2.1, with the *) | ||
(* special exception on linking described in the file LICENSE. *) | ||
(* *) | ||
(**************************************************************************) | ||
|
||
(** Unboxed option type. Unimplemented. *) | ||
type ('a : non_null_value) t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module Or_null = Or_null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module Or_null = Or_null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
ocaml/testsuite/tests/typing-layouts-non-null-value/arguments.ml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
(* TEST | ||
flags = "-extension-universe alpha"; | ||
expect; | ||
*) | ||
|
||
module Fake_or_null : sig | ||
type ('a : non_null_value) t : value | ||
|
||
val none : 'a t | ||
val some : 'a -> 'a t | ||
end = struct | ||
type ('a : non_null_value) t = 'a option | ||
|
||
let none = None | ||
let some x = Some x | ||
end | ||
;; | ||
|
||
[%%expect{| | ||
module Fake_or_null : | ||
sig | ||
type ('a : non_null_value) t : value | ||
val none : ('a : non_null_value). 'a t | ||
val some : ('a : non_null_value). 'a -> 'a t | ||
end | ||
|}] | ||
|
||
let _ = Fake_or_null.some (Fake_or_null.none) | ||
;; | ||
|
||
[%%expect{| | ||
Line 1, characters 26-45: | ||
1 | let _ = Fake_or_null.some (Fake_or_null.none) | ||
^^^^^^^^^^^^^^^^^^^ | ||
Error: This expression has type 'a Fake_or_null.t | ||
but an expression was expected of type ('b : non_null_value) | ||
The layout of 'a Fake_or_null.t is value, because | ||
of the definition of t at line 2, characters 2-38. | ||
But the layout of 'a Fake_or_null.t must be a sublayout of non_null_value, because | ||
of the definition of some at line 5, characters 2-23. | ||
|}] | ||
|
||
|
||
(* Built-in containers accept nullable values: *) | ||
|
||
let _ = [ Fake_or_null.none ] | ||
|
||
let _ = [| Fake_or_null.some 3 |] | ||
|
||
let _ = [: Fake_or_null.some "test " :] | ||
|
||
let _ = Some (Fake_or_null.some 4.2) | ||
|
||
let _ = lazy (Fake_or_null.none) | ||
;; | ||
|
||
[%%expect{| | ||
- : 'a Fake_or_null.t list = [<abstr>] | ||
- : int Fake_or_null.t array = [|<abstr>|] | ||
- : string Fake_or_null.t iarray = [:<abstr>:] | ||
- : float Fake_or_null.t option = Some <abstr> | ||
- : 'a Fake_or_null.t lazy_t = lazy <abstr> | ||
|}] | ||
|
||
module M1 : sig | ||
type 'a t | ||
|
||
val mk : 'a -> 'a t | ||
end = struct | ||
type 'a t = 'a | ||
|
||
let mk x = x | ||
end | ||
|
||
(* CR layouts v3.0: abstract types and type parameters to | ||
abstract types should default to non-null: *) | ||
|
||
let _ = Fake_or_null.some (M1.mk 2) | ||
;; | ||
[%%expect{| | ||
module M1 : sig type 'a t val mk : 'a -> 'a t end | ||
Line 14, characters 26-35: | ||
14 | let _ = Fake_or_null.some (M1.mk 2) | ||
^^^^^^^^^ | ||
Error: This expression has type int M1.t | ||
but an expression was expected of type ('a : non_null_value) | ||
The layout of int M1.t is value, because | ||
of the definition of t at line 2, characters 2-11. | ||
But the layout of int M1.t must be a sublayout of non_null_value, because | ||
of the definition of some at line 5, characters 2-23. | ||
|}] | ||
|
||
let _ = M1.mk (Fake_or_null.some 5) | ||
;; | ||
|
||
[%%expect{| | ||
- : int Fake_or_null.t M1.t = <abstr> | ||
|}] | ||
|
||
let my_id1 x = x | ||
let my_id2 (x : 'a) = x | ||
let my_id3 : 'a . 'a -> 'a = fun x -> x | ||
let my_id4 (type a) (x : a) = x | ||
;; | ||
|
||
[%%expect{| | ||
val my_id1 : 'a -> 'a = <fun> | ||
val my_id2 : 'a -> 'a = <fun> | ||
val my_id3 : 'a -> 'a = <fun> | ||
val my_id4 : 'a -> 'a = <fun> | ||
|}] | ||
|
||
(* By default, type variables in functions are nullable: *) | ||
|
||
let _ = my_id1 (Fake_or_null.some 1) | ||
|
||
let _ = my_id2 (Fake_or_null.some 2) | ||
|
||
let _ = my_id3 (Fake_or_null.some 3) | ||
|
||
let _ = my_id4 (Fake_or_null.some 4) | ||
;; | ||
|
||
[%%expect{| | ||
- : int Fake_or_null.t = <abstr> | ||
- : int Fake_or_null.t = <abstr> | ||
- : int Fake_or_null.t = <abstr> | ||
- : int Fake_or_null.t = <abstr> | ||
|}] |
Oops, something went wrong.