Skip to content

Commit 9e7bec8

Browse files
committed
Improve comment in Obj about set_field-like operations
1 parent 8e9c865 commit 9e7bec8

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

stdlib/obj.mli

+14-2
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,26 @@ external magic : 'a -> 'b = "%identity"
2424
external is_block : t -> bool = "caml_obj_is_block"
2525
external is_int : t -> bool = "%obj_is_int"
2626
external tag : t -> int = "caml_obj_tag"
27-
external set_tag : t -> int -> unit = "caml_obj_set_tag"
2827
external size : t -> int = "%obj_size"
2928
external field : t -> int -> t = "%obj_field"
3029

3130
(** When using flambda:
31+
3232
[set_field] MUST NOT be called on immutable blocks. (Blocks allocated
33-
in C stubs, or with [new_block] below, are always considered mutable.) *)
33+
in C stubs, or with [new_block] below, are always considered mutable.)
34+
35+
The same goes for [set_double_field] and [set_tag]. However, for
36+
[set_tag], in the case of immutable blocks where the middle-end optimizers
37+
never see code that discriminates on their tag (for example records), the
38+
operation should be safe. Such uses are nonetheless discouraged.
39+
40+
For experts only:
41+
[set_field] can be made safe by first wrapping the block in
42+
[Sys.opaque_identity], so any information about its contents will not
43+
be propagated.
44+
*)
3445
external set_field : t -> int -> t -> unit = "%obj_set_field"
46+
external set_tag : t -> int -> unit = "caml_obj_set_tag"
3547

3648
val double_field : t -> int -> float (* @since 3.11.2 *)
3749
val set_double_field : t -> int -> float -> unit (* @since 3.11.2 *)

0 commit comments

Comments
 (0)