-
Notifications
You must be signed in to change notification settings - Fork 89
Make various primitives non_null_value
#2604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
1813f9f
`non_null_value_creation_reason`
d-kalinichenko 82612ce
Immediates are non-null
d-kalinichenko 172cc23
Primitives are non-null
d-kalinichenko 16639a4
Extensible variants are non-null
d-kalinichenko 426eb97
Boxed variants are non-null
d-kalinichenko 28967ac
Boxed records are non-null
d-kalinichenko b5f7464
Tuples are non-null
d-kalinichenko de49322
Polymorphic variants are non-null
d-kalinichenko 035015e
Arrows are non-null
d-kalinichenko 9f47dc2
First-class modules are non-null
d-kalinichenko 2d294f3
Basic tests
d-kalinichenko d23fdca
More tests
d-kalinichenko 5aa0193
More tests
d-kalinichenko bae707b
Leave `lazy_t` nullable for now
d-kalinichenko 4b3d96a
More basic tests
d-kalinichenko ec73e3c
More tests
d-kalinichenko a3db382
Format
d-kalinichenko 45affe2
Update ocaml/testsuite/tests/typing-layouts-non-null-value/basics.ml
dkalinichenko-js a898318
stable -> upstream_compatible
d-kalinichenko e213962
Update comments and tests
d-kalinichenko d6bb569
Display `non_null_value` as `value` (#2613)
dkalinichenko-js File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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) | ||
goldfirere marked this conversation as resolved.
Show resolved
Hide resolved
goldfirere marked this conversation as resolved.
Show resolved
Hide resolved
|
||
;; | ||
|
||
[%%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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.