Skip to content

Commit

Permalink
flambda-backend: Keep Sys.opaque_identity in Cmm and Mach (port upstr…
Browse files Browse the repository at this point in the history
…eam PR 9412) (ocaml#238)
  • Loading branch information
stedolan authored Sep 16, 2021
1 parent faaf149 commit a1a07de
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
38 changes: 38 additions & 0 deletions testsuite/tests/lib-sys/opaque.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
(* TEST *)

let[@inline never] float_unboxing s f =
let x = Sys.opaque_identity (s +. 1.) in
let mw1 = Gc.minor_words () in
let mw2 = Gc.minor_words () in
f x;
let mw3 = Gc.minor_words () in
Printf.printf "unbox: %.0f\n" ((mw3 -. mw2) -. (mw2 -. mw1))

let[@inline never] lifetimes () =
let final = ref false in
let go () =
let r = ref 42 in
Gc.finalise (fun _ -> final := true) r;
let f1 = !final in
Gc.full_major ();
let f2 = !final in
ignore (Sys.opaque_identity r);
(f1, f2) in
let (f1, f2) = go () in
Gc.full_major ();
let f3 = !final in
Printf.printf "lifetime: %b %b %b\n" f1 f2 f3

let[@inline never] dead_alloc a =
let mw1 = Gc.minor_words () in
let mw2 = Gc.minor_words () in
ignore (Sys.opaque_identity (a, a));
let mw3 = Gc.minor_words () in
Printf.printf "dead: %.0f\n" ((mw3 -. mw2) -. (mw2 -. mw1))


let () =
float_unboxing 50. (fun _ -> ());
lifetimes ();
dead_alloc 10

3 changes: 3 additions & 0 deletions testsuite/tests/lib-sys/opaque.reference
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
unbox: 0
lifetime: false false true
dead: 3

0 comments on commit a1a07de

Please sign in to comment.