Skip to content

Commit f63184d

Browse files
authored
Add Runtimetags module (#2063)
* Add `Runtimetags` module. * Add test.
1 parent 298f1fa commit f63184d

File tree

8 files changed

+148
-2
lines changed

8 files changed

+148
-2
lines changed

ocaml/.depend

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ utils/profile.cmx : \
216216
utils/misc.cmx \
217217
utils/profile.cmi
218218
utils/profile.cmi :
219+
utils/runtimetags.cmo : \
220+
utils/runtimetags.cmi
221+
utils/runtimetags.cmx : \
222+
utils/runtimetags.cmi
223+
utils/runtimetags.cmi :
219224
utils/strongly_connected_components.cmo : \
220225
utils/numbers.cmi \
221226
utils/misc.cmi \
@@ -230,13 +235,15 @@ utils/symbol.cmo : \
230235
utils/linkage_name.cmi \
231236
utils/identifiable.cmi \
232237
typing/ident.cmi \
238+
utils/config.cmi \
233239
utils/compilation_unit.cmi \
234240
utils/symbol.cmi
235241
utils/symbol.cmx : \
236242
utils/misc.cmx \
237243
utils/linkage_name.cmx \
238244
utils/identifiable.cmx \
239245
typing/ident.cmx \
246+
utils/config.cmx \
240247
utils/compilation_unit.cmx \
241248
utils/symbol.cmi
242249
utils/symbol.cmi : \
@@ -1853,7 +1860,6 @@ typing/typedecl.cmi : \
18531860
typing/ident.cmi \
18541861
typing/errortrace.cmi \
18551862
typing/env.cmi \
1856-
parsing/builtin_attributes.cmi \
18571863
parsing/asttypes.cmi
18581864
typing/typedecl_properties.cmo : \
18591865
typing/types.cmi \
@@ -3705,11 +3711,13 @@ middle_end/clambda.cmi : \
37053711
middle_end/clambda_primitives.cmo : \
37063712
typing/types.cmi \
37073713
typing/primitive.cmi \
3714+
utils/misc.cmi \
37083715
lambda/lambda.cmi \
37093716
middle_end/clambda_primitives.cmi
37103717
middle_end/clambda_primitives.cmx : \
37113718
typing/types.cmx \
37123719
typing/primitive.cmx \
3720+
utils/misc.cmx \
37133721
lambda/lambda.cmx \
37143722
middle_end/clambda_primitives.cmi
37153723
middle_end/clambda_primitives.cmi : \
@@ -3955,6 +3963,7 @@ lambda/matching.cmo : \
39553963
typing/ident.cmi \
39563964
typing/env.cmi \
39573965
lambda/debuginfo.cmi \
3966+
utils/config.cmi \
39583967
utils/clflags.cmi \
39593968
typing/btype.cmi \
39603969
parsing/asttypes.cmi \
@@ -3978,6 +3987,7 @@ lambda/matching.cmx : \
39783987
typing/ident.cmx \
39793988
typing/env.cmx \
39803989
lambda/debuginfo.cmx \
3990+
utils/config.cmx \
39813991
utils/clflags.cmx \
39823992
typing/btype.cmx \
39833993
parsing/asttypes.cmi \
@@ -4594,6 +4604,7 @@ middle_end/closure/closure.cmo : \
45944604
typing/env.cmi \
45954605
lambda/debuginfo.cmi \
45964606
middle_end/convert_primitives.cmi \
4607+
utils/config.cmi \
45974608
middle_end/compilenv.cmi \
45984609
utils/compilation_unit.cmi \
45994610
utils/clflags.cmi \
@@ -4619,6 +4630,7 @@ middle_end/closure/closure.cmx : \
46194630
typing/env.cmx \
46204631
lambda/debuginfo.cmx \
46214632
middle_end/convert_primitives.cmx \
4633+
utils/config.cmx \
46224634
middle_end/compilenv.cmx \
46234635
utils/compilation_unit.cmx \
46244636
utils/clflags.cmx \
@@ -4815,6 +4827,7 @@ middle_end/flambda/closure_conversion.cmo : \
48154827
middle_end/flambda/flambda.cmi \
48164828
lambda/debuginfo.cmi \
48174829
middle_end/convert_primitives.cmi \
4830+
utils/config.cmi \
48184831
utils/compilation_unit.cmi \
48194832
middle_end/flambda/base_types/closure_origin.cmi \
48204833
middle_end/flambda/base_types/closure_id.cmi \
@@ -4844,6 +4857,7 @@ middle_end/flambda/closure_conversion.cmx : \
48444857
middle_end/flambda/flambda.cmx \
48454858
lambda/debuginfo.cmx \
48464859
middle_end/convert_primitives.cmx \
4860+
utils/config.cmx \
48474861
utils/compilation_unit.cmx \
48484862
middle_end/flambda/base_types/closure_origin.cmx \
48494863
middle_end/flambda/base_types/closure_id.cmx \

ocaml/compilerlibs/Makefile.compilerlibs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
# that they are consistent with the interface digests in the archives.
2626

2727
UTILS = \
28+
utils/runtimetags.cmo \
2829
utils/config.cmo \
2930
utils/build_path_prefix_map.cmo \
3031
utils/misc.cmo \

ocaml/dune

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
annot outcometree
9999

100100
;; lambda/
101-
debuginfo lambda matching printlambda runtimedef tmc simplif switch
101+
debuginfo lambda matching printlambda runtimedef runtimetags tmc simplif switch
102102
translmode
103103
transl_comprehension_utils
104104
transl_array_comprehension transl_list_comprehension
@@ -331,6 +331,7 @@
331331
(matching.mli as compiler-libs/matching.mli)
332332
(printlambda.mli as compiler-libs/printlambda.mli)
333333
(runtimedef.mli as compiler-libs/runtimedef.mli)
334+
(runtimetags.mli as compiler-libs/runtimetags.mli)
334335
(simplif.mli as compiler-libs/simplif.mli)
335336
(switch.mli as compiler-libs/switch.mli)
336337
(translmode.mli as compiler-libs/translmode.mli)

ocaml/otherlibs/dynlink/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ COMPILERLIBS_INTFS=\
7272

7373
# .ml files from compilerlibs that have corresponding .mli files.
7474
COMPILERLIBS_SOURCES=\
75+
utils/runtimetags.ml \
7576
utils/binutils.ml \
7677
utils/config.ml \
7778
utils/build_path_prefix_map.ml \

ocaml/otherlibs/dynlink/dune

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
debuginfo
9696
lambda
9797
runtimedef
98+
runtimetags
9899
instruct
99100
opcodes
100101
bytesections
@@ -129,6 +130,7 @@
129130
; (package ocaml))
130131

131132
;; .ml:
133+
(copy_files ../../utils/runtimetags.ml)
132134
(copy_files ../../utils/binutils.ml)
133135
(copy_files ../../utils/local_store.ml)
134136
(copy_files ../../utils/config.ml)
@@ -190,6 +192,7 @@
190192
(copy_files ../../bytecomp/symtable.ml)
191193

192194
;; .mli:
195+
(copy_files ../../utils/runtimetags.mli)
193196
(copy_files ../../utils/binutils.mli)
194197
(copy_files ../../utils/local_store.mli)
195198
(copy_files ../../utils/config.mli)
@@ -298,6 +301,7 @@
298301
%{deps}))
299302
(deps
300303
; NOTE: Be sure to keep these arguments in dependency order!
304+
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Runtimetags.cmo
301305
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Int_replace_polymorphic_compare.cmo
302306
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Binutils.cmo
303307
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Local_store.cmo
@@ -376,6 +380,7 @@
376380
%{deps}))
377381
(deps
378382
; NOTE: Be sure to keep these arguments in dependency order!
383+
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Runtimetags.cmx
379384
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Int_replace_polymorphic_compare.cmx
380385
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Binutils.cmx
381386
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Local_store.cmx
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
(* TEST
2+
flags = "-I ${ocamlsrcdir}/utils"
3+
include ocamlcommon
4+
* expect
5+
*)
6+
7+
let check_tag name left right =
8+
match Int.equal left right with
9+
| true -> Format.printf "values for %S agree@." name
10+
| false -> Format.printf "values for %S disagree (%d vs %d)@." name left right
11+
12+
let check_tags l =
13+
List.iter (fun (name, left, right) -> check_tag name left right) l
14+
15+
let () = check_tags [
16+
"first_non_constant_constructor_tag", Obj.first_non_constant_constructor_tag, Runtimetags.first_non_constant_constructor_tag;
17+
"last_non_constant_constructor_tag", Obj.last_non_constant_constructor_tag, Runtimetags.last_non_constant_constructor_tag;
18+
"forcing_tag", Obj.forcing_tag, Runtimetags.forcing_tag;
19+
"cont_tag", Obj.cont_tag, Runtimetags.cont_tag;
20+
"lazy_tag", Obj.lazy_tag, Runtimetags.lazy_tag;
21+
"closure_tag", Obj.closure_tag, Runtimetags.closure_tag;
22+
"object_tag", Obj.object_tag, Runtimetags.object_tag;
23+
"infix_tag", Obj.infix_tag, Runtimetags.infix_tag;
24+
"forward_tag", Obj.forward_tag, Runtimetags.forward_tag;
25+
"no_scan_tag", Obj.no_scan_tag, Runtimetags.no_scan_tag;
26+
"abstract_tag", Obj.abstract_tag, Runtimetags.abstract_tag;
27+
"string_tag", Obj.string_tag, Runtimetags.string_tag;
28+
"double_tag", Obj.double_tag, Runtimetags.double_tag;
29+
"double_array_tag", Obj.double_array_tag, Runtimetags.double_array_tag;
30+
"custom_tag", Obj.custom_tag, Runtimetags.custom_tag;
31+
"int_tag", Obj.int_tag, Runtimetags.int_tag;
32+
"out_of_heap_tag", Obj.out_of_heap_tag, Runtimetags.out_of_heap_tag;
33+
"unaligned_tag", Obj.unaligned_tag, Runtimetags.unaligned_tag;
34+
]
35+
36+
[%%expect{|
37+
val check_tag : string -> int -> int -> unit = <fun>
38+
val check_tags : (string * int * int) list -> unit = <fun>
39+
values for "first_non_constant_constructor_tag" agree
40+
values for "last_non_constant_constructor_tag" agree
41+
values for "forcing_tag" agree
42+
values for "cont_tag" agree
43+
values for "lazy_tag" agree
44+
values for "closure_tag" agree
45+
values for "object_tag" agree
46+
values for "infix_tag" agree
47+
values for "forward_tag" agree
48+
values for "no_scan_tag" agree
49+
values for "abstract_tag" agree
50+
values for "string_tag" agree
51+
values for "double_tag" agree
52+
values for "double_array_tag" agree
53+
values for "custom_tag" agree
54+
values for "int_tag" agree
55+
values for "out_of_heap_tag" agree
56+
values for "unaligned_tag" agree
57+
|}]

ocaml/utils/runtimetags.ml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
(**************************************************************************)
2+
(* *)
3+
(* OCaml *)
4+
(* *)
5+
(* Max Slater, Jane Street *)
6+
(* *)
7+
(* Copyright 2023 Jane Street Group LLC *)
8+
(* *)
9+
(* All rights reserved. This file is distributed under the terms of *)
10+
(* the GNU Lesser General Public License version 2.1, with the *)
11+
(* special exception on linking described in the file LICENSE. *)
12+
(* *)
13+
(**************************************************************************)
14+
15+
(* Defines the runtime tags used by the target runtime.
16+
Must be kept in sync with ocaml/stdlib/obj.ml and ocaml/runtime/caml/mlvalues.h *)
17+
18+
let first_non_constant_constructor_tag = 0
19+
let last_non_constant_constructor_tag = 243
20+
let forcing_tag = 244
21+
let cont_tag = 245
22+
let lazy_tag = 246
23+
let closure_tag = 247
24+
let object_tag = 248
25+
let infix_tag = 249
26+
let forward_tag = 250
27+
let no_scan_tag = 251
28+
let abstract_tag = 251
29+
let string_tag = 252
30+
let double_tag = 253
31+
let double_array_tag = 254
32+
let custom_tag = 255
33+
let int_tag = 1000
34+
let out_of_heap_tag = 1001
35+
let unaligned_tag = 1002

ocaml/utils/runtimetags.mli

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
(**************************************************************************)
2+
(* *)
3+
(* OCaml *)
4+
(* *)
5+
(* Max Slater, Jane Street *)
6+
(* *)
7+
(* Copyright 2023 Jane Street Group LLC *)
8+
(* *)
9+
(* All rights reserved. This file is distributed under the terms of *)
10+
(* the GNU Lesser General Public License version 2.1, with the *)
11+
(* special exception on linking described in the file LICENSE. *)
12+
(* *)
13+
(**************************************************************************)
14+
15+
val first_non_constant_constructor_tag : int
16+
val last_non_constant_constructor_tag : int
17+
val forcing_tag : int
18+
val cont_tag : int
19+
val lazy_tag : int
20+
val closure_tag : int
21+
val object_tag : int
22+
val infix_tag : int
23+
val forward_tag : int
24+
val no_scan_tag : int
25+
val abstract_tag : int
26+
val string_tag : int
27+
val double_tag : int
28+
val double_array_tag : int
29+
val custom_tag : int
30+
val int_tag : int
31+
val out_of_heap_tag : int
32+
val unaligned_tag : int

0 commit comments

Comments
 (0)