Skip to content

Commit f9020b3

Browse files
authored
Make Sys.opaque_identity work on different layouts (#2327)
use layout_poly
1 parent 27e5cae commit f9020b3

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

ocaml/stdlib/sys.ml.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ let ocaml_release = {
159159

160160
(* Optimization *)
161161

162-
external opaque_identity : 'a -> 'a = "%opaque"
162+
external[@layout_poly] opaque_identity : ('a : any). 'a -> 'a = "%opaque"
163163

164164
module Immediate64 = struct
165165
module type Non_immediate = sig

ocaml/stdlib/sys.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ val runtime_warnings_enabled: unit -> bool
415415

416416
(** {1 Optimization} *)
417417

418-
external opaque_identity : 'a -> 'a = "%opaque"
418+
external[@layout_poly] opaque_identity : ('a : any). 'a -> 'a = "%opaque"
419419
(** For the purposes of optimization, [opaque_identity] behaves like an
420420
unknown (and thus possibly side-effecting) function.
421421

ocaml/testsuite/tests/typing-layouts/layout_poly_native.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,10 @@ let () =
5858
Printf.printf "%s\n" (revapply "abcde" (fun x -> x));
5959
()
6060

61+
let () =
62+
Printf.printf "%s\n" (N.to_string (Sys.opaque_identity #1n));
63+
Printf.printf "%s\n" (I32.to_string (Sys.opaque_identity #2l));
64+
Printf.printf "%s\n" (I64.to_string (Sys.opaque_identity #3L));
65+
Printf.printf "%s\n" (F.to_string (Sys.opaque_identity #4.));
66+
Printf.printf "%s\n" (Sys.opaque_identity "abcde");
67+
()

ocaml/testsuite/tests/typing-layouts/layout_poly_native.reference

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ abcde
2323
3
2424
4.
2525
abcde
26+
1
27+
2
28+
3
29+
4.
30+
abcde

0 commit comments

Comments
 (0)