Skip to content

Commit e69b18d

Browse files
committed
compact marshal encoding scheme
1 parent 0b2c845 commit e69b18d

18 files changed

+1401
-931
lines changed

jscomp/core/bs_cmi_load.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ let load_cmi ~unit_name : Env.Persistent_signature.t option =
3838
if Js_config.get_diagnose () then
3939
Format.fprintf Format.err_formatter ">Cmi: %s@." unit_name;
4040
let cmi : Cmi_format.cmi_infos =
41-
Marshal.from_string
42-
Builtin_cmi_datasets.module_data.(cmi) 0 in
41+
Ext_marshal.from_string_uncheck
42+
Builtin_cmi_datasets.module_data.(cmi) in
4343
if Js_config.get_diagnose () then
4444
Format.fprintf Format.err_formatter "<Cmi: %s@." unit_name;
4545
Some {filename = Sys.executable_name ;

jscomp/core/js_cmj_load.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ then
4242
if Js_config.get_diagnose () then
4343
Format.fprintf Format.err_formatter ">Cmj: %s@." unit_name;
4444
let cmj_table : Js_cmj_format.t =
45-
let values, pure = Marshal.from_string Builtin_cmj_datasets.module_data.(i) 0 in
45+
let values, pure = Ext_marshal.from_string_uncheck Builtin_cmj_datasets.module_data.(i) in
4646
{values; pure; package_spec = Js_packages_info.runtime_package_specs;js_file_kind = Little_js}
4747
in
4848
if Js_config.get_diagnose () then

jscomp/ext/ext_marshal.ml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929

3030

31-
31+
(*
3232
let to_file filename v =
3333
let chan = open_out_bin filename in
3434
Marshal.to_channel chan v [];
@@ -39,5 +39,10 @@ let from_file filename =
3939
let chan = open_in_bin filename in
4040
let v = Marshal.from_channel chan in
4141
close_in chan;
42-
v
43-
42+
v *)
43+
44+
external from_bytes_unsafe: string -> int -> 'a
45+
= "caml_input_value_from_string"
46+
47+
let from_string_uncheck (s:string) =
48+
from_bytes_unsafe s 0

jscomp/ext/ext_marshal.mli

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
(** Extension to the standard library [Marshall] module
3333
*)
3434

35-
val to_file : string -> 'a -> unit
35+
(* val to_file : string -> 'a -> unit *)
3636

37-
val from_file : string -> 'a
37+
(* val from_file : string -> 'a *)
38+
39+
val from_string_uncheck : string -> 'a

jscomp/main/builtin_cmi_datasets.ml

Lines changed: 162 additions & 162 deletions
Large diffs are not rendered by default.

jscomp/syntax/ast_exp_extension.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ let toString (x : t) =
5656

5757
(* exception handling*)
5858
let fromString (x : string) : t =
59-
Marshal.from_string x 0
59+
Ext_marshal.from_string_uncheck x
6060

6161
let handle_extension record_as_js_object e (self : Bs_ast_mapper.mapper)
6262
(({txt ; loc} as lid , payload) : Parsetree.extension) =

jscomp/syntax/external_ffi_types.ml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -235,31 +235,32 @@ let check_ffi ?loc ffi : bool =
235235
end;
236236
!xrelative
237237

238-
let bs_prefix = "BS:"
238+
(* let bs_prefix = "BS:"
239239
let bs_prefix_length = String.length bs_prefix
240-
240+
*)
241241

242242
(** TODO: Make sure each version is not prefix of each other
243243
Solution:
244244
1. fixed length
245245
2. non-prefix approach
246246
*)
247-
let bs_external = bs_prefix
247+
(* let bs_external = bs_prefix *)
248248

249249

250-
let bs_external_length = String.length bs_external
250+
(* let bs_external_length = String.length bs_external *)
251251

252252

253253
let to_string (t : t) =
254-
bs_external ^ Marshal.to_string t []
255-
256-
let is_bs_primitive s =
257-
let s_len = String.length s in
258-
s_len >= bs_prefix_length &&
259-
String.unsafe_get s 0 = 'B' &&
260-
String.unsafe_get s 1 = 'S' &&
261-
String.unsafe_get s 2 = ':'
262-
254+
Marshal.to_string t []
255+
256+
(* \132\149\166\190
257+
0x84 95 A6 BE Intext_magic_small intext.h
258+
https://github.com/ocaml/merlin/commit/b094c937c3a360eb61054f7652081b88e4f3612f
259+
*)
260+
let is_bs_primitive s =
261+
String.length s >= 20 (* Marshal.header_size*) &&
262+
String.unsafe_get s 0 = '\132' &&
263+
String.unsafe_get s 1 = '\149'
263264

264265
let () = Oprint.map_primitive_name :=
265266
#if BS_RELEASE_BUILD then
@@ -273,7 +274,7 @@ let () = Oprint.map_primitive_name :=
273274
(* TODO: better error message when version mismatch *)
274275
let from_string s : t =
275276
if is_bs_primitive s then
276-
Marshal.from_string s bs_external_length
277+
Ext_marshal.from_string_uncheck s
277278
else Ffi_normal
278279

279280

lib/4.06.1/bsdep.ml

Lines changed: 271 additions & 178 deletions
Large diffs are not rendered by default.

lib/4.06.1/bsdep.ml.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../lib/4.06.1/bsdep.ml: ../ocaml/driver/compdynlink.mli ../ocaml/driver/compenv.ml ../ocaml/driver/compenv.mli ../ocaml/driver/compmisc.ml ../ocaml/driver/compmisc.mli ../ocaml/driver/compplugin.ml ../ocaml/driver/compplugin.mli ../ocaml/driver/makedepend.ml ../ocaml/driver/makedepend.mli ../ocaml/driver/pparse.ml ../ocaml/driver/pparse.mli ../ocaml/parsing/ast_helper.ml ../ocaml/parsing/ast_helper.mli ../ocaml/parsing/ast_invariants.ml ../ocaml/parsing/ast_invariants.mli ../ocaml/parsing/ast_iterator.ml ../ocaml/parsing/ast_iterator.mli ../ocaml/parsing/ast_mapper.ml ../ocaml/parsing/ast_mapper.mli ../ocaml/parsing/asttypes.mli ../ocaml/parsing/builtin_attributes.ml ../ocaml/parsing/builtin_attributes.mli ../ocaml/parsing/depend.ml ../ocaml/parsing/depend.mli ../ocaml/parsing/docstrings.ml ../ocaml/parsing/docstrings.mli ../ocaml/parsing/lexer.ml ../ocaml/parsing/lexer.mli ../ocaml/parsing/location.ml ../ocaml/parsing/location.mli ../ocaml/parsing/longident.ml ../ocaml/parsing/longident.mli ../ocaml/parsing/parse.ml ../ocaml/parsing/parse.mli ../ocaml/parsing/parser.ml ../ocaml/parsing/parser.mli ../ocaml/parsing/parsetree.mli ../ocaml/parsing/syntaxerr.ml ../ocaml/parsing/syntaxerr.mli ../ocaml/tools/ocamldep.ml ../ocaml/utils/arg_helper.ml ../ocaml/utils/arg_helper.mli ../ocaml/utils/ccomp.ml ../ocaml/utils/ccomp.mli ../ocaml/utils/clflags.ml ../ocaml/utils/clflags.mli ../ocaml/utils/identifiable.ml ../ocaml/utils/identifiable.mli ../ocaml/utils/misc.ml ../ocaml/utils/misc.mli ../ocaml/utils/numbers.ml ../ocaml/utils/numbers.mli ../ocaml/utils/profile.ml ../ocaml/utils/profile.mli ../ocaml/utils/terminfo.ml ../ocaml/utils/terminfo.mli ../ocaml/utils/warnings.ml ../ocaml/utils/warnings.mli ./common/bs_loc.ml ./common/bs_loc.mli ./common/bs_version.ml ./common/bs_version.mli ./common/bs_warnings.ml ./common/bs_warnings.mli ./common/js_config.ml ./common/js_config.mli ./common/lam_methname.ml ./common/lam_methname.mli ./core/bs_cmi_load.ml ./core/bs_conditional_initial.ml ./core/bs_conditional_initial.mli ./core/config_util.ml ./core/config_util.mli ./core/config_whole_compiler.ml ./core/config_whole_compiler.mli ./core/js_raw_info.ml ./core/lam_constant.ml ./core/lam_constant.mli ./core/lam_pointer_info.ml ./core/lam_pointer_info.mli ./core/lam_tag_info.ml ./core/matching_polyfill.ml ./core/matching_polyfill.mli ./core/record_attributes_check.ml ./ext/bsc_warnings.ml ./ext/ext_array.ml ./ext/ext_array.mli ./ext/ext_bytes.ml ./ext/ext_bytes.mli ./ext/ext_char.ml ./ext/ext_char.mli ./ext/ext_filename.ml ./ext/ext_filename.mli ./ext/ext_json_parse.ml ./ext/ext_json_parse.mli ./ext/ext_json_types.ml ./ext/ext_list.ml ./ext/ext_list.mli ./ext/ext_option.ml ./ext/ext_option.mli ./ext/ext_position.ml ./ext/ext_position.mli ./ext/ext_ref.ml ./ext/ext_ref.mli ./ext/ext_string.ml ./ext/ext_string.mli ./ext/ext_string_array.ml ./ext/ext_string_array.mli ./ext/ext_utf8.ml ./ext/ext_utf8.mli ./ext/ext_util.ml ./ext/ext_util.mli ./ext/hash_set_gen.ml ./ext/hash_set_poly.ml ./ext/hash_set_poly.mli ./ext/hash_set_string.ml ./ext/hash_set_string.mli ./ext/literals.ml ./ext/literals.mli ./ext/map_gen.ml ./ext/map_string.ml ./ext/map_string.mli ./ext/set_gen.ml ./ext/set_string.ml ./ext/set_string.mli ./main/builtin_cmi_datasets.ml ./main/builtin_cmi_datasets.mli ./stubs/bs_hash_stubs.ml ./syntax/ast_attributes.ml ./syntax/ast_attributes.mli ./syntax/ast_bs_open.ml ./syntax/ast_bs_open.mli ./syntax/ast_comb.ml ./syntax/ast_comb.mli ./syntax/ast_compatible.ml ./syntax/ast_compatible.mli ./syntax/ast_config.ml ./syntax/ast_config.mli ./syntax/ast_core_type.ml ./syntax/ast_core_type.mli ./syntax/ast_core_type_class_type.ml ./syntax/ast_core_type_class_type.mli ./syntax/ast_derive.ml ./syntax/ast_derive.mli ./syntax/ast_derive_abstract.ml ./syntax/ast_derive_abstract.mli ./syntax/ast_derive_js_mapper.ml ./syntax/ast_derive_js_mapper.mli ./syntax/ast_derive_projector.ml ./syntax/ast_derive_projector.mli ./syntax/ast_derive_util.ml ./syntax/ast_derive_util.mli ./syntax/ast_exp.ml ./syntax/ast_exp.mli ./syntax/ast_exp_apply.ml ./syntax/ast_exp_apply.mli ./syntax/ast_exp_extension.ml ./syntax/ast_exp_extension.mli ./syntax/ast_exp_handle_external.ml ./syntax/ast_exp_handle_external.mli ./syntax/ast_external.ml ./syntax/ast_external.mli ./syntax/ast_external_mk.ml ./syntax/ast_external_mk.mli ./syntax/ast_external_process.ml ./syntax/ast_external_process.mli ./syntax/ast_literal.ml ./syntax/ast_literal.mli ./syntax/ast_open_cxt.ml ./syntax/ast_open_cxt.mli ./syntax/ast_pat.ml ./syntax/ast_pat.mli ./syntax/ast_payload.ml ./syntax/ast_payload.mli ./syntax/ast_polyvar.ml ./syntax/ast_polyvar.mli ./syntax/ast_signature.ml ./syntax/ast_signature.mli ./syntax/ast_structure.ml ./syntax/ast_structure.mli ./syntax/ast_tdcls.ml ./syntax/ast_tdcls.mli ./syntax/ast_tuple_pattern_flatten.ml ./syntax/ast_tuple_pattern_flatten.mli ./syntax/ast_typ_uncurry.ml ./syntax/ast_typ_uncurry.mli ./syntax/ast_utf8_string.ml ./syntax/ast_utf8_string.mli ./syntax/ast_utf8_string_interp.ml ./syntax/ast_utf8_string_interp.mli ./syntax/ast_util.ml ./syntax/ast_util.mli ./syntax/bs_ast_invariant.ml ./syntax/bs_ast_invariant.mli ./syntax/bs_ast_mapper.ml ./syntax/bs_ast_mapper.mli ./syntax/bs_builtin_ppx.ml ./syntax/bs_builtin_ppx.mli ./syntax/bs_syntaxerr.ml ./syntax/bs_syntaxerr.mli ./syntax/external_arg_spec.ml ./syntax/external_arg_spec.mli ./syntax/external_ffi_types.ml ./syntax/external_ffi_types.mli ./syntax/ppx_entry.ml ./syntax/reactjs_jsx_ppx_v2.ml ./syntax/reactjs_jsx_ppx_v3.ml
1+
../lib/4.06.1/bsdep.ml: ../ocaml/driver/compdynlink.mli ../ocaml/driver/compenv.ml ../ocaml/driver/compenv.mli ../ocaml/driver/compmisc.ml ../ocaml/driver/compmisc.mli ../ocaml/driver/compplugin.ml ../ocaml/driver/compplugin.mli ../ocaml/driver/makedepend.ml ../ocaml/driver/makedepend.mli ../ocaml/driver/pparse.ml ../ocaml/driver/pparse.mli ../ocaml/parsing/ast_helper.ml ../ocaml/parsing/ast_helper.mli ../ocaml/parsing/ast_invariants.ml ../ocaml/parsing/ast_invariants.mli ../ocaml/parsing/ast_iterator.ml ../ocaml/parsing/ast_iterator.mli ../ocaml/parsing/ast_mapper.ml ../ocaml/parsing/ast_mapper.mli ../ocaml/parsing/asttypes.mli ../ocaml/parsing/builtin_attributes.ml ../ocaml/parsing/builtin_attributes.mli ../ocaml/parsing/depend.ml ../ocaml/parsing/depend.mli ../ocaml/parsing/docstrings.ml ../ocaml/parsing/docstrings.mli ../ocaml/parsing/lexer.ml ../ocaml/parsing/lexer.mli ../ocaml/parsing/location.ml ../ocaml/parsing/location.mli ../ocaml/parsing/longident.ml ../ocaml/parsing/longident.mli ../ocaml/parsing/parse.ml ../ocaml/parsing/parse.mli ../ocaml/parsing/parser.ml ../ocaml/parsing/parser.mli ../ocaml/parsing/parsetree.mli ../ocaml/parsing/syntaxerr.ml ../ocaml/parsing/syntaxerr.mli ../ocaml/tools/ocamldep.ml ../ocaml/utils/arg_helper.ml ../ocaml/utils/arg_helper.mli ../ocaml/utils/ccomp.ml ../ocaml/utils/ccomp.mli ../ocaml/utils/clflags.ml ../ocaml/utils/clflags.mli ../ocaml/utils/identifiable.ml ../ocaml/utils/identifiable.mli ../ocaml/utils/misc.ml ../ocaml/utils/misc.mli ../ocaml/utils/numbers.ml ../ocaml/utils/numbers.mli ../ocaml/utils/profile.ml ../ocaml/utils/profile.mli ../ocaml/utils/terminfo.ml ../ocaml/utils/terminfo.mli ../ocaml/utils/warnings.ml ../ocaml/utils/warnings.mli ./common/bs_loc.ml ./common/bs_loc.mli ./common/bs_version.ml ./common/bs_version.mli ./common/bs_warnings.ml ./common/bs_warnings.mli ./common/js_config.ml ./common/js_config.mli ./common/lam_methname.ml ./common/lam_methname.mli ./core/bs_cmi_load.ml ./core/bs_conditional_initial.ml ./core/bs_conditional_initial.mli ./core/config_util.ml ./core/config_util.mli ./core/config_whole_compiler.ml ./core/config_whole_compiler.mli ./core/js_raw_info.ml ./core/lam_constant.ml ./core/lam_constant.mli ./core/lam_pointer_info.ml ./core/lam_pointer_info.mli ./core/lam_tag_info.ml ./core/matching_polyfill.ml ./core/matching_polyfill.mli ./core/record_attributes_check.ml ./ext/bsc_warnings.ml ./ext/ext_array.ml ./ext/ext_array.mli ./ext/ext_bytes.ml ./ext/ext_bytes.mli ./ext/ext_char.ml ./ext/ext_char.mli ./ext/ext_filename.ml ./ext/ext_filename.mli ./ext/ext_json_parse.ml ./ext/ext_json_parse.mli ./ext/ext_json_types.ml ./ext/ext_list.ml ./ext/ext_list.mli ./ext/ext_marshal.ml ./ext/ext_marshal.mli ./ext/ext_option.ml ./ext/ext_option.mli ./ext/ext_position.ml ./ext/ext_position.mli ./ext/ext_ref.ml ./ext/ext_ref.mli ./ext/ext_string.ml ./ext/ext_string.mli ./ext/ext_string_array.ml ./ext/ext_string_array.mli ./ext/ext_utf8.ml ./ext/ext_utf8.mli ./ext/ext_util.ml ./ext/ext_util.mli ./ext/hash_set_gen.ml ./ext/hash_set_poly.ml ./ext/hash_set_poly.mli ./ext/hash_set_string.ml ./ext/hash_set_string.mli ./ext/literals.ml ./ext/literals.mli ./ext/map_gen.ml ./ext/map_string.ml ./ext/map_string.mli ./ext/set_gen.ml ./ext/set_string.ml ./ext/set_string.mli ./main/builtin_cmi_datasets.ml ./main/builtin_cmi_datasets.mli ./stubs/bs_hash_stubs.ml ./syntax/ast_attributes.ml ./syntax/ast_attributes.mli ./syntax/ast_bs_open.ml ./syntax/ast_bs_open.mli ./syntax/ast_comb.ml ./syntax/ast_comb.mli ./syntax/ast_compatible.ml ./syntax/ast_compatible.mli ./syntax/ast_config.ml ./syntax/ast_config.mli ./syntax/ast_core_type.ml ./syntax/ast_core_type.mli ./syntax/ast_core_type_class_type.ml ./syntax/ast_core_type_class_type.mli ./syntax/ast_derive.ml ./syntax/ast_derive.mli ./syntax/ast_derive_abstract.ml ./syntax/ast_derive_abstract.mli ./syntax/ast_derive_js_mapper.ml ./syntax/ast_derive_js_mapper.mli ./syntax/ast_derive_projector.ml ./syntax/ast_derive_projector.mli ./syntax/ast_derive_util.ml ./syntax/ast_derive_util.mli ./syntax/ast_exp.ml ./syntax/ast_exp.mli ./syntax/ast_exp_apply.ml ./syntax/ast_exp_apply.mli ./syntax/ast_exp_extension.ml ./syntax/ast_exp_extension.mli ./syntax/ast_exp_handle_external.ml ./syntax/ast_exp_handle_external.mli ./syntax/ast_external.ml ./syntax/ast_external.mli ./syntax/ast_external_mk.ml ./syntax/ast_external_mk.mli ./syntax/ast_external_process.ml ./syntax/ast_external_process.mli ./syntax/ast_literal.ml ./syntax/ast_literal.mli ./syntax/ast_open_cxt.ml ./syntax/ast_open_cxt.mli ./syntax/ast_pat.ml ./syntax/ast_pat.mli ./syntax/ast_payload.ml ./syntax/ast_payload.mli ./syntax/ast_polyvar.ml ./syntax/ast_polyvar.mli ./syntax/ast_signature.ml ./syntax/ast_signature.mli ./syntax/ast_structure.ml ./syntax/ast_structure.mli ./syntax/ast_tdcls.ml ./syntax/ast_tdcls.mli ./syntax/ast_tuple_pattern_flatten.ml ./syntax/ast_tuple_pattern_flatten.mli ./syntax/ast_typ_uncurry.ml ./syntax/ast_typ_uncurry.mli ./syntax/ast_utf8_string.ml ./syntax/ast_utf8_string.mli ./syntax/ast_utf8_string_interp.ml ./syntax/ast_utf8_string_interp.mli ./syntax/ast_util.ml ./syntax/ast_util.mli ./syntax/bs_ast_invariant.ml ./syntax/bs_ast_invariant.mli ./syntax/bs_ast_mapper.ml ./syntax/bs_ast_mapper.mli ./syntax/bs_builtin_ppx.ml ./syntax/bs_builtin_ppx.mli ./syntax/bs_syntaxerr.ml ./syntax/bs_syntaxerr.mli ./syntax/external_arg_spec.ml ./syntax/external_arg_spec.mli ./syntax/external_ffi_types.ml ./syntax/external_ffi_types.mli ./syntax/ppx_entry.ml ./syntax/reactjs_jsx_ppx_v2.ml ./syntax/reactjs_jsx_ppx_v3.ml

0 commit comments

Comments
 (0)