Skip to content

Commit a1a07de

Browse files
authored
flambda-backend: Keep Sys.opaque_identity in Cmm and Mach (port upstream PR 9412) (#238)
1 parent faaf149 commit a1a07de

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

testsuite/tests/lib-sys/opaque.ml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
(* TEST *)
2+
3+
let[@inline never] float_unboxing s f =
4+
let x = Sys.opaque_identity (s +. 1.) in
5+
let mw1 = Gc.minor_words () in
6+
let mw2 = Gc.minor_words () in
7+
f x;
8+
let mw3 = Gc.minor_words () in
9+
Printf.printf "unbox: %.0f\n" ((mw3 -. mw2) -. (mw2 -. mw1))
10+
11+
let[@inline never] lifetimes () =
12+
let final = ref false in
13+
let go () =
14+
let r = ref 42 in
15+
Gc.finalise (fun _ -> final := true) r;
16+
let f1 = !final in
17+
Gc.full_major ();
18+
let f2 = !final in
19+
ignore (Sys.opaque_identity r);
20+
(f1, f2) in
21+
let (f1, f2) = go () in
22+
Gc.full_major ();
23+
let f3 = !final in
24+
Printf.printf "lifetime: %b %b %b\n" f1 f2 f3
25+
26+
let[@inline never] dead_alloc a =
27+
let mw1 = Gc.minor_words () in
28+
let mw2 = Gc.minor_words () in
29+
ignore (Sys.opaque_identity (a, a));
30+
let mw3 = Gc.minor_words () in
31+
Printf.printf "dead: %.0f\n" ((mw3 -. mw2) -. (mw2 -. mw1))
32+
33+
34+
let () =
35+
float_unboxing 50. (fun _ -> ());
36+
lifetimes ();
37+
dead_alloc 10
38+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
unbox: 0
2+
lifetime: false false true
3+
dead: 3

0 commit comments

Comments
 (0)