diff --git a/jscomp/all.depend b/jscomp/all.depend index 4d42a16fdd..290253c7e7 100644 --- a/jscomp/all.depend +++ b/jscomp/all.depend @@ -408,7 +408,6 @@ core/js_packages_state.cmx : core/js_packages_info.cmx \ ext/ext_pervasives.cmx ext/ext_namespace.cmx core/js_packages_state.cmi core/ocaml_types.cmx : common/ext_log.cmx ext/ext_list.cmx \ core/ocaml_types.cmi -core/ocaml_stdlib_slots.cmx : core/bs_conditional_initial.cmx : common/js_config.cmx common/bs_version.cmx \ core/bs_conditional_initial.cmi core/ocaml_options.cmx : common/bs_version.cmx \ @@ -420,11 +419,10 @@ core/lam_module_ident.cmx : core/js_op.cmx core/j.cmx ext/hashtbl_make.cmx \ ext/hash_set.cmx ext/ext_ident.cmx stubs/bs_hash_stubs.cmx \ core/lam_module_ident.cmi core/lam_arity.cmx : core/lam_arity.cmi -core/lam.cmx : ext/ordered_hash_map_local_ident.cmx \ - core/ocaml_stdlib_slots.cmx ext/literals.cmx core/lam_module_ident.cmx \ - ext/int_vec_vec.cmx ext/int_vec_util.cmx ext/int_vec.cmx \ - ext/int_hashtbl.cmx ext/ident_set.cmx ext/ident_hashtbl.cmx \ - ext/ident_hash_set.cmx ext/hash_set_ident_mask.cmx \ +core/lam.cmx : ext/ordered_hash_map_local_ident.cmx ext/literals.cmx \ + core/lam_module_ident.cmx ext/int_vec_vec.cmx ext/int_vec_util.cmx \ + ext/int_vec.cmx ext/int_hashtbl.cmx ext/ident_set.cmx \ + ext/ident_hashtbl.cmx ext/ident_hash_set.cmx ext/hash_set_ident_mask.cmx \ syntax/external_ffi_types.cmx syntax/external_arg_spec.cmx \ ext/ext_string.cmx ext/ext_scc.cmx common/ext_log.cmx ext/ext_list.cmx \ core/lam.cmi diff --git a/jscomp/core/lam.ml b/jscomp/core/lam.ml index 0d2bafb82f..2a898783bf 100644 --- a/jscomp/core/lam.ml +++ b/jscomp/core/lam.ml @@ -1821,6 +1821,21 @@ let convert exports lam : _ * _ = | _ when s = "#undefined" -> Lconst (Const_js_undefined) + | _ when s = "#init_mod" -> + let args = Ext_list.map convert_aux args in + begin match args with + | [_loc; Lconst(Const_block(0,_,[Const_block(0,_,[])]))] + -> + unit + | _ -> prim ~primitive:Pinit_mod ~args loc + end + | _ when s = "#update_mod" -> + let args = Ext_list.map convert_aux args in + begin match args with + | [Lconst(Const_block(0,_,[Const_block(0,_,[])]));_;_] + -> unit + | _ -> prim ~primitive:Pupdate_mod ~args loc + end | _ -> let primitive = match s with @@ -1907,33 +1922,6 @@ let convert exports lam : _ * _ = | Lapply (fn,args,loc) -> begin match fn with - | Lprim ( - Pfield (id, _), - [ - Lprim ( - Pgetglobal { name = "CamlinternalMod" }, - _,_ - ) - ],loc - ) -> (* replace all {!CamlinternalMod} function *) - let args = Ext_list.map convert_aux args in - begin match Ocaml_stdlib_slots.camlinternalMod.(id), args with - | "init_mod" , [_loc ; shape] -> - begin match shape with - | Lconst (Const_block (0, _, [Const_block (0, _, [])])) - -> unit (* see {!Translmod.init_shape}*) - | _ -> prim ~primitive:Pinit_mod ~args loc - end - | "update_mod", [shape ; _obj1; _obj2] -> - (* here array access will have side effect .. *) - begin match shape with - | Lconst (Const_block (0, _, [Const_block (0, _, [])])) - -> unit (* see {!Translmod.init_shape}*) - | _ -> prim ~primitive:Pupdate_mod ~args loc - end - | _ -> assert false - end - (* | Lfunction(kind,params,Lprim(prim,inner_args,inner_loc)) when List.for_all2_no_exn (fun x y -> diff --git a/jscomp/core/ocaml_stdlib_slots.ml b/jscomp/core/ocaml_stdlib_slots.ml deleted file mode 100644 index 575994f83f..0000000000 --- a/jscomp/core/ocaml_stdlib_slots.ml +++ /dev/null @@ -1,9 +0,0 @@ - -(* Generated by scripts/gen_slots.ml, should be updated everytime when we upgrade the compiler *) -let pervasives = [| "invalid_arg";"failwith";"Exit";"min";"max";"abs";"max_int";"min_int";"lnot";"infinity";"neg_infinity";"nan";"max_float";"min_float";"epsilon_float";"^";"char_of_int";"string_of_bool";"bool_of_string";"string_of_int";"string_of_float";"@";"stdin";"stdout";"stderr";"print_char";"print_string";"print_bytes";"print_int";"print_float";"print_endline";"print_newline";"prerr_char";"prerr_string";"prerr_bytes";"prerr_int";"prerr_float";"prerr_endline";"prerr_newline";"read_line";"read_int";"read_float";"open_out";"open_out_bin";"open_out_gen";"flush";"flush_all";"output_char";"output_string";"output_bytes";"output";"output_substring";"output_byte";"output_binary_int";"output_value";"seek_out";"pos_out";"out_channel_length";"close_out";"close_out_noerr";"set_binary_mode_out";"open_in";"open_in_bin";"open_in_gen";"input_char";"input_line";"input";"really_input";"really_input_string";"input_byte";"input_binary_int";"input_value";"seek_in";"pos_in";"in_channel_length";"close_in";"close_in_noerr";"set_binary_mode_in";"LargeFile";"string_of_format";"^^";"exit";"at_exit";"valid_float_lexem";"unsafe_really_input";"do_at_exit" |] -let camlinternalOO = [| "public_method_label";"new_method";"new_variable";"new_methods_variables";"get_variable";"get_variables";"get_method_label";"get_method_labels";"get_method";"set_method";"set_methods";"narrow";"widen";"add_initializer";"dummy_table";"create_table";"init_class";"inherits";"make_class";"make_class_store";"dummy_class";"copy";"create_object";"create_object_opt";"run_initializers";"run_initializers_opt";"create_object_and_run_initializers";"lookup_tables";"params";"stats" |] -let camlinternalMod = [| "init_mod";"update_mod" |] -let string = [| "make";"init";"copy";"sub";"fill";"blit";"concat";"iter";"iteri";"map";"mapi";"trim";"escaped";"index";"rindex";"index_from";"rindex_from";"contains";"contains_from";"rcontains_from";"uppercase";"lowercase";"capitalize";"uncapitalize";"compare" |] -let array = [| "init";"make_matrix";"create_matrix";"append";"concat";"sub";"copy";"fill";"blit";"to_list";"of_list";"iter";"map";"iteri";"mapi";"fold_left";"fold_right";"sort";"stable_sort";"fast_sort" |] -let list = [| "length";"hd";"tl";"nth";"rev";"append";"rev_append";"concat";"flatten";"iter";"iteri";"map";"mapi";"rev_map";"fold_left";"fold_right";"iter2";"map2";"rev_map2";"fold_left2";"fold_right2";"for_all";"exists";"for_all2";"exists2";"mem";"memq";"find";"filter";"find_all";"partition";"assoc";"assq";"mem_assoc";"mem_assq";"remove_assoc";"remove_assq";"split";"combine";"sort";"stable_sort";"fast_sort";"sort_uniq";"merge" |] - diff --git a/jscomp/stdlib/camlinternalMod.mli b/jscomp/stdlib/camlinternalMod.mli index 96535d0e3a..fd24b66774 100644 --- a/jscomp/stdlib/camlinternalMod.mli +++ b/jscomp/stdlib/camlinternalMod.mli @@ -21,6 +21,8 @@ type shape = | Class | Module of shape array | Value of Obj.t - +#if BS then +#else val init_mod: string * int * int -> shape -> Obj.t val update_mod: shape -> Obj.t -> Obj.t -> unit +#end diff --git a/lib/js/camlinternalMod.js b/lib/js/camlinternalMod.js index c6772077de..ae1b9f17e6 100644 --- a/lib/js/camlinternalMod.js +++ b/lib/js/camlinternalMod.js @@ -1,108 +1 @@ -'use strict'; - -var Caml_obj = require("./caml_obj.js"); -var Caml_array = require("./caml_array.js"); -var Caml_builtin_exceptions = require("./caml_builtin_exceptions.js"); - -function dummy_class(loc) { - var undef = function () { - throw [ - Caml_builtin_exceptions.undefined_recursive_module, - loc - ]; - }; - return /* tuple */[ - undef, - undef, - undef, - 0 - ]; -} - -function init_mod(loc, shape) { - var undef_module = function () { - throw [ - Caml_builtin_exceptions.undefined_recursive_module, - loc - ]; - }; - var loop = function (shape, struct_, idx) { - if (typeof shape === "number") { - switch (shape) { - case 0 : - case 1 : - return Caml_array.caml_array_set(struct_, idx, undef_module); - case 2 : - return Caml_array.caml_array_set(struct_, idx, dummy_class(loc)); - - } - } else if (shape.tag) { - return Caml_array.caml_array_set(struct_, idx, shape[0]); - } else { - var comps = shape[0]; - var v = /* array */[]; - Caml_array.caml_array_set(struct_, idx, v); - var len = comps.length; - for(var i = 0 ,i_finish = len - 1 | 0; i <= i_finish; ++i){ - loop(Caml_array.caml_array_get(comps, i), v, i); - } - return /* () */0; - } - }; - var res = /* array */[]; - loop(shape, res, 0); - return Caml_array.caml_array_get(res, 0); -} - -function update_mod(shape, o, n) { - var aux = function (shape, o, n, parent, i) { - if (typeof shape === "number") { - switch (shape) { - case 0 : - parent[i] = n; - return /* () */0; - case 1 : - case 2 : - return Caml_obj.caml_update_dummy(o, n); - - } - } else if (shape.tag) { - return /* () */0; - } else { - var comps = shape[0]; - for(var i$1 = 0 ,i_finish = comps.length - 1 | 0; i$1 <= i_finish; ++i$1){ - aux(Caml_array.caml_array_get(comps, i$1), o[i$1], n[i$1], o, i$1); - } - return /* () */0; - } - }; - if (typeof shape === "number") { - throw [ - Caml_builtin_exceptions.assert_failure, - [ - "camlinternalMod.ml", - 130, - 10 - ] - ]; - } else if (shape.tag) { - throw [ - Caml_builtin_exceptions.assert_failure, - [ - "camlinternalMod.ml", - 130, - 10 - ] - ]; - } else { - var comps = shape[0]; - for(var i = 0 ,i_finish = comps.length - 1 | 0; i <= i_finish; ++i){ - aux(Caml_array.caml_array_get(comps, i), o[i], n[i], o, i); - } - return /* () */0; - } -} - -exports.init_mod = init_mod; -exports.update_mod = update_mod; -/* No side effect */ +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/lib/whole_compiler.d b/lib/whole_compiler.d index 2d2415c730..7a8761be24 100644 --- a/lib/whole_compiler.d +++ b/lib/whole_compiler.d @@ -361,7 +361,6 @@ ../lib/whole_compiler.ml : ./core/lam_compile_global.ml ../lib/whole_compiler.ml : ./core/lam_eta_conversion.ml ../lib/whole_compiler.ml : ./core/lam_pass_lets_dce.mli -../lib/whole_compiler.ml : ./core/ocaml_stdlib_slots.ml ../lib/whole_compiler.ml : ./ext/hash_set_ident_mask.ml ../lib/whole_compiler.ml : ./super_errors/super_main.ml ../lib/whole_compiler.ml : ./super_errors/super_misc.ml diff --git a/lib/whole_compiler.ml b/lib/whole_compiler.ml index db68e5829b..db786fcd91 100644 --- a/lib/whole_compiler.ml +++ b/lib/whole_compiler.ml @@ -66232,20 +66232,6 @@ let mem key (x : Int_vec.t) = let len = Int_vec.length x in unsafe_mem_aux internal_array 0 key (len - 1) -end -module Ocaml_stdlib_slots -= struct -#1 "ocaml_stdlib_slots.ml" - -(* Generated by scripts/gen_slots.ml, should be updated everytime when we upgrade the compiler *) -let pervasives = [| "invalid_arg";"failwith";"Exit";"min";"max";"abs";"max_int";"min_int";"lnot";"infinity";"neg_infinity";"nan";"max_float";"min_float";"epsilon_float";"^";"char_of_int";"string_of_bool";"bool_of_string";"string_of_int";"string_of_float";"@";"stdin";"stdout";"stderr";"print_char";"print_string";"print_bytes";"print_int";"print_float";"print_endline";"print_newline";"prerr_char";"prerr_string";"prerr_bytes";"prerr_int";"prerr_float";"prerr_endline";"prerr_newline";"read_line";"read_int";"read_float";"open_out";"open_out_bin";"open_out_gen";"flush";"flush_all";"output_char";"output_string";"output_bytes";"output";"output_substring";"output_byte";"output_binary_int";"output_value";"seek_out";"pos_out";"out_channel_length";"close_out";"close_out_noerr";"set_binary_mode_out";"open_in";"open_in_bin";"open_in_gen";"input_char";"input_line";"input";"really_input";"really_input_string";"input_byte";"input_binary_int";"input_value";"seek_in";"pos_in";"in_channel_length";"close_in";"close_in_noerr";"set_binary_mode_in";"LargeFile";"string_of_format";"^^";"exit";"at_exit";"valid_float_lexem";"unsafe_really_input";"do_at_exit" |] -let camlinternalOO = [| "public_method_label";"new_method";"new_variable";"new_methods_variables";"get_variable";"get_variables";"get_method_label";"get_method_labels";"get_method";"set_method";"set_methods";"narrow";"widen";"add_initializer";"dummy_table";"create_table";"init_class";"inherits";"make_class";"make_class_store";"dummy_class";"copy";"create_object";"create_object_opt";"run_initializers";"run_initializers_opt";"create_object_and_run_initializers";"lookup_tables";"params";"stats" |] -let camlinternalMod = [| "init_mod";"update_mod" |] -let string = [| "make";"init";"copy";"sub";"fill";"blit";"concat";"iter";"iteri";"map";"mapi";"trim";"escaped";"index";"rindex";"index_from";"rindex_from";"contains";"contains_from";"rcontains_from";"uppercase";"lowercase";"capitalize";"uncapitalize";"compare" |] -let array = [| "init";"make_matrix";"create_matrix";"append";"concat";"sub";"copy";"fill";"blit";"to_list";"of_list";"iter";"map";"iteri";"mapi";"fold_left";"fold_right";"sort";"stable_sort";"fast_sort" |] -let list = [| "length";"hd";"tl";"nth";"rev";"append";"rev_append";"concat";"flatten";"iter";"iteri";"map";"mapi";"rev_map";"fold_left";"fold_right";"iter2";"map2";"rev_map2";"fold_left2";"fold_right2";"for_all";"exists";"for_all2";"exists2";"mem";"memq";"find";"filter";"find_all";"partition";"assoc";"assq";"mem_assoc";"mem_assq";"remove_assoc";"remove_assq";"split";"combine";"sort";"stable_sort";"fast_sort";"sort_uniq";"merge" |] - - end module Ordered_hash_map_gen = struct @@ -68740,6 +68726,21 @@ let convert exports lam : _ * _ = | _ when s = "#undefined" -> Lconst (Const_js_undefined) + | _ when s = "#init_mod" -> + let args = Ext_list.map convert_aux args in + begin match args with + | [_loc; Lconst(Const_block(0,_,[Const_block(0,_,[])]))] + -> + unit + | _ -> prim ~primitive:Pinit_mod ~args loc + end + | _ when s = "#update_mod" -> + let args = Ext_list.map convert_aux args in + begin match args with + | [Lconst(Const_block(0,_,[Const_block(0,_,[])]));_;_] + -> unit + | _ -> prim ~primitive:Pupdate_mod ~args loc + end | _ -> let primitive = match s with @@ -68826,33 +68827,6 @@ let convert exports lam : _ * _ = | Lapply (fn,args,loc) -> begin match fn with - | Lprim ( - Pfield (id, _), - [ - Lprim ( - Pgetglobal { name = "CamlinternalMod" }, - _,_ - ) - ],loc - ) -> (* replace all {!CamlinternalMod} function *) - let args = Ext_list.map convert_aux args in - begin match Ocaml_stdlib_slots.camlinternalMod.(id), args with - | "init_mod" , [_loc ; shape] -> - begin match shape with - | Lconst (Const_block (0, _, [Const_block (0, _, [])])) - -> unit (* see {!Translmod.init_shape}*) - | _ -> prim ~primitive:Pinit_mod ~args loc - end - | "update_mod", [shape ; _obj1; _obj2] -> - (* here array access will have side effect .. *) - begin match shape with - | Lconst (Const_block (0, _, [Const_block (0, _, [])])) - -> unit (* see {!Translmod.init_shape}*) - | _ -> prim ~primitive:Pupdate_mod ~args loc - end - | _ -> assert false - end - (* | Lfunction(kind,params,Lprim(prim,inner_args,inner_loc)) when List.for_all2_no_exn (fun x y -> @@ -81355,12 +81329,32 @@ let record_primitive = function | _ -> () (* Utilities for compiling "module rec" definitions *) - -let mod_prim name = +let bs_init_mod args : Lambda.lambda = + Lprim(Pccall {prim_name = "#init_mod"; prim_arity = 2; + prim_alloc = true; + prim_native_name = ""; + prim_native_float = false}, args, Location.none) +let bs_update_mod args : Lambda.lambda = + Lprim (Pccall {prim_name = "#update_mod"; prim_arity = 3; + prim_alloc = true; + prim_native_name = ""; + prim_native_float = false}, args, Location.none) + +let mod_prim name args = + if !Clflags.bs_only then + if name = "init_mod" then + bs_init_mod args + else if name = "update_mod" then + bs_update_mod args + else assert false + else try - transl_normal_path - (fst (Env.lookup_value (Ldot (Lident "CamlinternalMod", name)) - Env.empty)) + Lapply + ( + transl_normal_path + (fst (Env.lookup_value (Ldot (Lident "CamlinternalMod", name)) + Env.empty)) + , args, Location.none) with Not_found -> fatal_error ("Primitive " ^ name ^ " not found.") @@ -81458,7 +81452,7 @@ let eval_rec_bindings bindings cont = | (id, None, rhs) :: rem -> bind_inits rem | (id, Some(loc, shape), rhs) :: rem -> - Llet(Strict, id, Lapply(mod_prim "init_mod", [loc; shape], Location.none), + Llet(Strict, id, (mod_prim "init_mod" [loc; shape]), bind_inits rem) and bind_strict = function [] -> @@ -81473,8 +81467,7 @@ let eval_rec_bindings bindings cont = | (id, None, rhs) :: rem -> patch_forwards rem | (id, Some(loc, shape), rhs) :: rem -> - Lsequence(Lapply(mod_prim "update_mod", [shape; Lvar id; rhs], - Location.none), + Lsequence((mod_prim "update_mod" [shape; Lvar id; rhs]), patch_forwards rem) in bind_inits bindings