Skip to content

Commit

Permalink
Make Sys.opaque_identity work on different layouts (ocaml-flambda#2327
Browse files Browse the repository at this point in the history
)

use layout_poly
  • Loading branch information
alanechang authored and Forestryks committed Mar 25, 2024
1 parent 9841d09 commit b6ac955
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ocaml/stdlib/sys.ml.in
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ let ocaml_release = {

(* Optimization *)

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

module Immediate64 = struct
module type Non_immediate = sig
Expand Down
2 changes: 1 addition & 1 deletion ocaml/stdlib/sys.mli
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ val runtime_warnings_enabled: unit -> bool

(** {1 Optimization} *)

external opaque_identity : 'a -> 'a = "%opaque"
external[@layout_poly] opaque_identity : ('a : any). 'a -> 'a = "%opaque"
(** For the purposes of optimization, [opaque_identity] behaves like an
unknown (and thus possibly side-effecting) function.
Expand Down
7 changes: 7 additions & 0 deletions ocaml/testsuite/tests/typing-layouts/layout_poly_native.ml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,10 @@ let () =
Printf.printf "%s\n" (revapply "abcde" (fun x -> x));
()

let () =
Printf.printf "%s\n" (N.to_string (Sys.opaque_identity #1n));
Printf.printf "%s\n" (I32.to_string (Sys.opaque_identity #2l));
Printf.printf "%s\n" (I64.to_string (Sys.opaque_identity #3L));
Printf.printf "%s\n" (F.to_string (Sys.opaque_identity #4.));
Printf.printf "%s\n" (Sys.opaque_identity "abcde");
()
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ abcde
3
4.
abcde
1
2
3
4.
abcde

0 comments on commit b6ac955

Please sign in to comment.