Skip to content

Commit

Permalink
[feature] #423 add an option which requires people to enable cross mo…
Browse files Browse the repository at this point in the history
…dule options explicitly
  • Loading branch information
Hongbo Zhang committed May 27, 2016
1 parent 7b1c2ef commit 62aad0b
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 10 deletions.
5 changes: 5 additions & 0 deletions jscomp/js_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ let set_npm_package_path s =

let get_npm_package_path () = !npm_package_path

let cross_module_inline = ref false

let get_cross_module_inline () = !cross_module_inline
let set_cross_module_inline b =
cross_module_inline := b

let (//) = Filename.concat
(* for a single pass compilation, [output_dir]
Expand Down
4 changes: 4 additions & 0 deletions jscomp/js_config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ val get_goog_package_name : unit -> string option
val set_npm_package_path : string -> unit
val get_npm_package_path : unit -> (string * string) option

val cross_module_inline : bool ref
val set_cross_module_inline : bool -> unit
val get_cross_module_inline : unit -> bool

val set_env : env -> unit
val cmd_set_module : string -> unit
val default_gen_tds : bool ref
Expand Down
2 changes: 2 additions & 0 deletions jscomp/js_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ let buckle_script_flags =
"disable built-in ppx for ml files (internal use)")
:: ("-js-no-builtin-ppx-mli", Arg.Set Js_config.no_builtin_ppx_mli,
"disable built-in ppx for mli files (internal use)")
:: ("-js-cross-module-opt", Arg.Set Js_config.cross_module_inline,
"enable cross module inlining, default(false)")
:: ("-js-gen-tds", Arg.Set Js_config.default_gen_tds,
" set will generate `.d.ts` file for typescript (experimental)")
:: (
Expand Down
3 changes: 2 additions & 1 deletion jscomp/lam_compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ let rec
the compiler has to be the same running
*)
-> f (E.str Sys.os_type)
| _, _, Some lam when Lam_util.not_function lam
| _, _, Some lam
when Lam_util.not_function lam
(* since it's only for alias, there is no arguments,
we should not inline function definition here, even though
it is very small
Expand Down
13 changes: 10 additions & 3 deletions jscomp/lam_compile_env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,28 @@ let find_and_add_if_not_exist (id, pos) env ~not_found ~found =
name ;
signatures = signature ;
arity ;
closed_lambda
closed_lambda =
if Js_config.get_cross_module_inline () then
closed_lambda
else None
}
end
| Visit { signatures = serializable_sigs ; cmj_table = { values ; _} } ->
let name = (Type_util.get_name serializable_sigs pos ) in
let arity , closed_lambda = (
match String_map.find name values with
| exception Not_found -> (NA, None)
| {arity; closed_lambda;_} -> arity, closed_lambda
| {arity; closed_lambda;_} ->
arity, closed_lambda
) in
found { id;
name;
signatures = serializable_sigs;
arity;
closed_lambda
closed_lambda =
if Js_config.get_cross_module_inline () then
closed_lambda
else None
(* TODO shall we cache the arity ?*)
}
| Runtime _ -> assert false
Expand Down
2 changes: 1 addition & 1 deletion jscomp/lam_compile_group.ml
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ let lambda_as_module
(lam : Lambda.lambda) =
begin
Lam_current_unit.set_file filename ;
Lam_current_unit.iset_debug_file "tuple_alloc.ml";
Lam_current_unit.set_debug_file "rand.ml";
Ext_pervasives.with_file_as_chan
(Js_config.get_output_file filename)
(fun chan -> Js_dump.dump_deps_program
Expand Down
2 changes: 1 addition & 1 deletion jscomp/lam_pass_remove_alias.ml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ let simplify_alias
_ }
->
let lam_size = Lam_analysis.size body in
if Ext_list.same_length args params
if Ext_list.same_length args params (* && false *)
then
if Lam_inline_util.maybe_functor v.name
(* && (Ident_set.mem v meta.export_idents) && false *)
Expand Down
2 changes: 1 addition & 1 deletion jscomp/runtime/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ $(addsuffix .cmj, $(OTHERS)): caml_builtin_exceptions.cmj block.cmj js.cmj
RUNTIME := $(addsuffix .cmj, $(SOURCE_LIST))


COMPFLAGS += $(MODULE_FLAGS) -I ../stdlib -nostdlib -nopervasives -open Pervasives -w -40 -js-npm-output-path $(npm_package_name):lib/js
COMPFLAGS += $(MODULE_FLAGS) -I ../stdlib -nostdlib -nopervasives -open Pervasives -w -40 -js-npm-output-path $(npm_package_name):lib/js -js-cross-module-opt



Expand Down
2 changes: 1 addition & 1 deletion jscomp/stdlib/Makefile.shared
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ CAMLC=$(CAMLRUN) $(COMPILER)
#COMPFLAGS=-strict-sequence -w +33..39 -g -warn-error A -bin-annot -nostdlib \
# -safe-string
COMPFLAGS= $(MODULE_FLAGS) -strict-sequence -w +33..39 -g -warn-error A -nostdlib \
-safe-string -I ../runtime -js-npm-output-path $(npm_package_name):lib/js -js-no-builtin-ppx-ml -js-no-builtin-ppx-mli
-safe-string -I ../runtime -js-npm-output-path $(npm_package_name):lib/js -js-no-builtin-ppx-ml -js-no-builtin-ppx-mli -js-cross-module-opt


# OPTCOMPILER=ocamlopt.opt
Expand Down
2 changes: 1 addition & 1 deletion jscomp/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SOURCE_LIST := $(shell cat test.mllib)
TESTS := $(addsuffix .cmj, $(SOURCE_LIST) )

COMPFLAGS+= $(MODULE_FLAGS) -w -40
COMPFLAGS+= -js-npm-output-path $(npm_package_name):lib/js/test/
COMPFLAGS+= -js-cross-module-opt -js-npm-output-path $(npm_package_name):lib/js/test/


$(TESTS): $(CAMLC)
Expand Down
7 changes: 6 additions & 1 deletion jscomp/test/test.mllib
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,9 @@ uncurry_glob_test
nested_obj_test
nested_obj_literal

method_name_test
method_name_test

# sig
# delaunay
# rand
# builder

0 comments on commit 62aad0b

Please sign in to comment.