-
Notifications
You must be signed in to change notification settings - Fork 89
Move layout restriction from -> to fun #2107
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
28 commits
Select commit
Hold shift + click to select a range
ef83626
wip
alanechang b0f9372
change Wildcard and Unification_var to sort vars
alanechang e8bedff
test changes
alanechang eac5307
more tests
alanechang b0cc09f
fix test
alanechang b1f8c65
test changes
alanechang 9306375
Rework jkind default (#2158)
alanechang 1fab504
rebase over type var print order change
alanechang 81a75ca
Add a bunch of tests
goldfirere 4262e98
check instead of constrain
alanechang a885f86
jkind check in unify_univar
alanechang c006e5e
update test outputs
alanechang 0f8fdf1
change unify_univar to take jkinds
alanechang de31691
Testing representability of function argument
goldfirere 136dfbb
More tests
goldfirere e19affc
Yet more tests
goldfirere 7ea22b0
Accept test output
goldfirere e8c4817
Propagate new test to _alpha
goldfirere 1c2a3e6
More tests, this time about inference
goldfirere 41e8647
add tests to _alpha
alanechang b57bbb9
small test changes
alanechang d8b5597
relax approx_type
alanechang 7b4c549
reword history message
alanechang feea377
add cr for bad error message
alanechang 899010b
fix test
alanechang 0d1034f
rename layout to jkind
alanechang 2b16e4a
add comments about check_type_jkind_exn
alanechang 31bca7e
add comment about unify_univar invariant
alanechang 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,110 @@ | ||
(* TEST | ||
flags = "-extension layouts" | ||
* native | ||
* bytecode | ||
*) | ||
|
||
(* See also Test 10 in modules.ml, which tests for type-checking failures in | ||
code that is similar to this. *) | ||
|
||
let unbox = Stdlib__Float_u.of_float | ||
|
||
module type S = sig | ||
type t : any | ||
|
||
val add : t -> t -> t | ||
val one : unit -> t | ||
val print : (unit -> t) -> unit | ||
end | ||
|
||
(* type substitution *) | ||
module M1 : S with type t = float# = struct | ||
type t = float# | ||
|
||
let add x y = Stdlib__Float_u.add x y | ||
let one () = unbox 1. | ||
let print f = Printf.printf "Printing a float#: %f\n" (Stdlib__Float_u.to_float (f ())) | ||
end | ||
|
||
module M2 : S with type t = int = struct | ||
alanechang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
type t = int | ||
|
||
let add x y = x + y | ||
let one () = 1 | ||
let print f = Printf.printf "Printing a int: %d\n" (f ()) | ||
end | ||
|
||
let () = Printf.printf "%f\n" (Stdlib__Float_u.to_float (M1.add (unbox 10.) (unbox 10.))) | ||
let () = Printf.printf "%d\n" (M2.add 10 10) | ||
|
||
(* destructive substitution *) | ||
module M3 : S with type t := float# = struct | ||
let add x y = Stdlib__Float_u.add x y | ||
let one () = unbox 1. | ||
let print f = Printf.printf "Printing a float#: %f\n" (Stdlib__Float_u.to_float (f ())) | ||
end | ||
|
||
module M4 : S with type t := int = struct | ||
let add x y = x + y | ||
let one () = 1 | ||
let print f = Printf.printf "Printing a int: %d\n" (f ()) | ||
end | ||
|
||
let () = Printf.printf "%f\n" (Stdlib__Float_u.to_float (M3.add (unbox 10.) (unbox 10.))) | ||
let () = Printf.printf "%d\n" (M4.add 10 10) | ||
|
||
(* functor *) | ||
module type Q = sig | ||
include S | ||
|
||
val print_one : unit -> unit | ||
end | ||
|
||
module Make (M : S) : Q = struct | ||
include M | ||
|
||
let print_one () = M.print M.one | ||
end | ||
|
||
module M1' = Make (M1) | ||
module M2' = Make (M2) | ||
|
||
let () = M1'.print_one () | ||
let () = M2'.print_one () | ||
|
||
(* edge cases and order of evaluation *) | ||
let g : type (a : any). unit -> a -> a = fun () -> assert false | ||
|
||
let () = | ||
try | ||
let r = | ||
g | ||
() | ||
(Printf.printf "a\n"; | ||
unbox 10.) | ||
in | ||
Printf.printf "%f\n" (Stdlib__Float_u.to_float r) | ||
with | ||
| _ -> Printf.printf "b\n" | ||
;; | ||
|
||
let () = | ||
try | ||
let r = | ||
g | ||
() | ||
(Printf.printf "c\n"; | ||
10) | ||
in | ||
Printf.printf "%d\n" r | ||
with | ||
| _ -> Printf.printf "d\n" | ||
;; | ||
|
||
(* This should type check *) | ||
let rec f : type (a : any). unit -> a -> a = fun () -> f () | ||
|
||
let f' () = | ||
let _ = f () 10 in | ||
f () (unbox 10.) | ||
;; |
10 changes: 10 additions & 0 deletions
10
ocaml/testsuite/tests/typing-layouts/any_in_types.reference
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,10 @@ | ||
20.000000 | ||
20 | ||
20.000000 | ||
20 | ||
Printing a float#: 1.000000 | ||
Printing a int: 1 | ||
a | ||
b | ||
c | ||
d |
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.