Skip to content

Commit

Permalink
Merge pull request #2402 from BuckleScript/remove_deps_on_ocaml_stdli…
Browse files Browse the repository at this point in the history
…b_slots

bypass camlinternalMod
  • Loading branch information
bobzhang committed Dec 26, 2017
2 parents 199c9f7 + 9c20364 commit c878a86
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 209 deletions.
10 changes: 4 additions & 6 deletions jscomp/all.depend
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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
Expand Down
42 changes: 15 additions & 27 deletions jscomp/core/lam.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ->
Expand Down
9 changes: 0 additions & 9 deletions jscomp/core/ocaml_stdlib_slots.ml

This file was deleted.

4 changes: 3 additions & 1 deletion jscomp/stdlib/camlinternalMod.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
109 changes: 1 addition & 108 deletions lib/js/camlinternalMod.js
Original file line number Diff line number Diff line change
@@ -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. */
1 change: 0 additions & 1 deletion lib/whole_compiler.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
91 changes: 42 additions & 49 deletions lib/whole_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ->
Expand Down Expand Up @@ -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.")

Expand Down Expand Up @@ -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
[] ->
Expand All @@ -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
Expand Down

0 comments on commit c878a86

Please sign in to comment.