Skip to content

Commit 790016a

Browse files
committed
opaque
1 parent 9c60ae1 commit 790016a

File tree

7 files changed

+17
-17
lines changed

7 files changed

+17
-17
lines changed

boot/ocamlc

25.3 KB
Binary file not shown.

boot/ocamldep

12.4 KB
Binary file not shown.

boot/ocamllex

716 Bytes
Binary file not shown.

otherlibs/threads/pervasives.ml

-4
Original file line numberDiff line numberDiff line change
@@ -597,10 +597,6 @@ let (^^) (Format (fmt1, str1)) (Format (fmt2, str2)) =
597597
Format (CamlinternalFormatBasics.concat_fmt fmt1 fmt2,
598598
str1 ^ "%," ^ str2)
599599

600-
(* Optimisation *)
601-
602-
external opaque : 'a -> 'a = "%opaque"
603-
604600
(* Miscellaneous *)
605601

606602
external sys_exit : int -> 'a = "caml_sys_exit"

stdlib/pervasives.ml

-4
Original file line numberDiff line numberDiff line change
@@ -502,10 +502,6 @@ let ( ^^ ) (Format (fmt1, str1)) (Format (fmt2, str2)) =
502502
Format (CamlinternalFormatBasics.concat_fmt fmt1 fmt2,
503503
str1 ^ "%," ^ str2)
504504

505-
(* Optimisation *)
506-
507-
external opaque : 'a -> 'a = "%opaque"
508-
509505
(* Miscellaneous *)
510506

511507
external sys_exit : int -> 'a = "caml_sys_exit"

stdlib/pervasives.mli

-9
Original file line numberDiff line numberDiff line change
@@ -1098,15 +1098,6 @@ val ( ^^ ) :
10981098
[f1], then results from [f2].
10991099
*)
11001100

1101-
(** {6 Optimisation} *)
1102-
1103-
external opaque : 'a -> 'a = "%opaque"
1104-
(** Semantically, [opaque v] behaves as the identity function; but when
1105-
used with Flambda mode, for the purposes of optimisation passes such
1106-
expression is side-effecting and yields an unknown result. This may
1107-
be used to prevent necessary code in applications such as benchmarks from
1108-
being optimised away. *)
1109-
11101101
(** {6 Program termination} *)
11111102

11121103
val exit : int -> 'a

stdlib/sys.mli

+17
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,20 @@ val enable_runtime_warnings: bool -> unit
280280

281281
val runtime_warnings_enabled: unit -> bool
282282
(** Return whether runtime warnings are currently enabled. *)
283+
284+
(** {6 Optimization} *)
285+
286+
external opaque_identity : 'a -> 'a = "%opaque"
287+
(** For the purposes of optimization, [opaque_identity] behaves like an
288+
unknown (and thus possibly side-effecting) function.
289+
290+
At runtime, [opaque_identity] disappears altogether.
291+
292+
A typical use of this function is to prevent pure computations from being
293+
optimized away in benchmarking loops. For example:
294+
{[
295+
for _round = 1 to 100_000 do
296+
ignore (Sys.opaque_identity (my_pure_computation ()))
297+
done
298+
}]
299+
*)

0 commit comments

Comments
 (0)