Skip to content
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

Unboxed tuples #2879

Merged
merged 4 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Extend tests
  • Loading branch information
ccasin committed Sep 5, 2024
commit cb004c234bc6aff7fd35a44db6bf78a39eecdf36
42 changes: 27 additions & 15 deletions ocaml/testsuite/tests/typing-layouts-products/unboxed_tuples.ml
Original file line number Diff line number Diff line change
Expand Up @@ -392,55 +392,67 @@ let _ =
(**********************************)
(* Test 9: Continuations / @local *)

let print4 prefix #(#(z,y),x,w) =
Printf.printf "%s: #(#(%.1f, %d), %.1f, %s)\n" prefix z y (Float_u.to_float x) w

let _ =
let[@local] swap #(x, y) = #(y, x) in
let[@local] swap #(w, x, #(y, z)) = #(#(z, y), x, w) in
let[@inline never] g i p1 p2 =
let z =
if i < 0 then
swap p1
else if i = 0 then
swap p2
else
swap #(42, 84)
swap #("hi", #42.0, #(84, 3.0))
in z
in
print_ints "Test 9, #(2,1)" (g (-1) #(1,2) #(3,4));
print4 "Test 9, #(#(3.0, 2), 1.0, a)"
(g (-1) #("a", #1.0, #(2, 3.0)) #("a",#4.0,#(5,6.0)));

let[@local] swap #(x, y) = #(y, x) in
let[@local] swap #(w, x, #(y, z)) = #(#(z, y), x, w) in
let[@inline never] g i p1 p2 =
let z =
if i < 0 then
swap p1
else if i = 0 then
swap p2
else
swap #(42, 84)
swap #("hi", #42.0, #(84, 3.0))
in z
in
print_ints "Test 9, #(4,3)" (g 0 #(1,2) #(3,4));
print4 "Test 9, #(#(6.0, 5), 4.0, b)"
(g 0 #("a", #1.0, #(2, 3.0)) #("b",#4.0,#(5,6.0)));

let[@local] swap #(x, y) = #(y, x) in
let[@local] swap #(w, x, #(y, z)) = #(#(z, y), x, w) in
let[@inline never] g i p1 p2 =
let z =
if i < 0 then
swap p1
else if i = 0 then
swap p2
else
swap #(42, 84)
swap #("hi", #42.0, #(84, 3.0))
in z
in
print_ints "Test 9, #(84,42)" (g 1 #(1,2) #(3,4))
print4 "Test 9, #(#(3.0, 84), 42.0, hi)"
(g 1 #("a", #1.0, #(2, 3.0)) #("b",#4.0,#(5,6.0)))

(**************************)
(* Test 10: Loopification *)

let[@loop] rec fib n #(x, y) =
if y > n then #(y, x) else
fib n #(y, x + y)
let print4 prefix #(w,#(x,y),z) =
Printf.printf "%s: #(%.1f, #(%.1f, %d), %d)\n" prefix
(Float_u.to_float w) x y z

let[@loop] rec fib n (#(w, #(x, y), z) as p) =
let w = Float_u.to_float w in
if Float.compare w (Float.of_int n) > 0 then p else
let next = Float_u.of_float (w +. x) in
fib n #(next, #(w, Float.to_int x), y)

let _ =
print_ints "Test 10, #(1,0)" (fib 0 #(0,1));
print_ints "Test 10, #(5,3)" (fib 4 #(0,1));
print_ints "Test 10, #(144,89)" (fib 100 #(0,1))
print4 "Test 10, #(1.0, #(0.0, 0), 0)" (fib 0 #(#1.0,#(0.0,0),0));
print4 "Test 10, #(5.0, #(3.0, 2), 1))" (fib 4 #(#1.0,#(0.0,0),0));
print4 "Test 10, #(144.0, #(89.0, 55), 34)" (fib 100 #(#1.0,#(0.0,0),0));

Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ Test 8, reverse (inlined): 5, 4.40, 3.30, 2.20, 1
Test 8, reverse (not inlined): 5, 4.40, 3.30, 2.20, 1
Test 8, extract y (inlined): 5
Test 8, extract y (not inlined): 5
Test 9, #(2,1): #(2,1)
Test 9, #(4,3): #(4,3)
Test 9, #(84,42): #(84,42)
Test 10, #(1,0): #(1,0)
Test 10, #(5,3): #(5,3)
Test 10, #(144,89): #(144,89)
Test 9, #(#(3.0, 2), 1.0, a): #(#(3.0, 2), 1.0, a)
Test 9, #(#(6.0, 5), 4.0, b): #(#(6.0, 5), 4.0, b)
Test 9, #(#(3.0, 84), 42.0, hi): #(#(3.0, 84), 42.0, hi)
Test 10, #(1.0, #(0.0, 0), 0): #(1.0, #(0.0, 0), 0)
Test 10, #(5.0, #(3.0, 2), 1)): #(5.0, #(3.0, 2), 1)
Test 10, #(144.0, #(89.0, 55), 34): #(144.0, #(89.0, 55), 34)
Loading