Skip to content

Make Sys.opaque_identity work on different layouts #2327

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

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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