Skip to content

delay the external module dependency check, so we can decide whehter … #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions jscomp/j.ml
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,15 @@ and block = statement list

and program = {
name : string;
modules : required_modules ;

block : block ;
exports : exports ;
export_set : Ident_set.t ;
side_effect : string option (* None: no, Some reason *)

}
and deps_program =
{
program : program ;
modules : required_modules ;
side_effect : string option (* None: no, Some reason *)
}
12 changes: 6 additions & 6 deletions jscomp/js_dump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,7 @@ let exports cxt f (idents : Ident.t list) =
outer_cxt


let node_program f ( program : J.program) =
let node_program f ( {program ; modules ; } : J.deps_program) =
let cxt = Ext_pp_scope.empty in
(* Node style *)
let requires cxt f (modules : (Ident.t * string) list ) =
Expand Down Expand Up @@ -1330,7 +1330,7 @@ let node_program f ( program : J.program) =
outer_cxt
in

let cxt = requires cxt f program.modules in
let cxt = requires cxt f modules in

let () = P.force_newline f in
let cxt = statement_list true cxt f program.block in
Expand All @@ -1339,7 +1339,7 @@ let node_program f ( program : J.program) =


let amd_program f
({modules; block = b ; exports = exp ; side_effect } as program : J.program)
( {program ; modules ; _} : J.deps_program)
=
P.newline f ;
let cxt = Ext_pp_scope.empty in
Expand Down Expand Up @@ -1371,15 +1371,15 @@ let amd_program f
P.brace_vgroup f 1 @@ (fun _ ->
let () = P.string f L.strict_directive in
let () = P.newline f in
let cxt = statement_list true cxt f b in
let cxt = statement_list true cxt f program.block in
(* FIXME AMD : use {[ function xx ]} or {[ var x = function ..]} *)
P.newline f;
P.force_newline f;
ignore (exports cxt f program.exports));
P.string f ")";
;;

let pp_program (program : J.program) (f : Ext_pp.t) =
let pp_program ( program : J.deps_program) (f : Ext_pp.t) =
begin
P.string f "// Generated CODE, PLEASE EDIT WITH CARE";
P.newline f;
Expand All @@ -1404,6 +1404,6 @@ let pp_program (program : J.program) (f : Ext_pp.t) =
P.flush f ()
end
let dump_program
(program : J.program)
(program : J.deps_program)
(oc : out_channel) =
pp_program program (P.from_channel oc)
4 changes: 2 additions & 2 deletions jscomp/js_dump.mli
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
(** Print JS IR to vanilla Javascript code *)


val pp_program : J.program -> Ext_pp.t -> unit
val pp_program : J.deps_program -> Ext_pp.t -> unit

val dump_program : J.program -> out_channel -> unit
val dump_program : J.deps_program -> out_channel -> unit
23 changes: 9 additions & 14 deletions jscomp/js_fold.ml
Original file line number Diff line number Diff line change
Expand Up @@ -301,21 +301,11 @@ class virtual fold =
let o = o#property_name _x in let o = o#expression _x_i1 in o)
method property : property -> 'self_type = o#unknown
method program : program -> 'self_type =
fun
{
name = _x;
modules = _x_i1;
block = _x_i2;
exports = _x_i3;
export_set = _x_i4;
side_effect = _x_i5
} ->
fun { name = _x; block = _x_i1; exports = _x_i2; export_set = _x_i3 }
->
let o = o#string _x in
let o = o#required_modules _x_i1 in
let o = o#block _x_i2 in
let o = o#exports _x_i3 in
let o = o#unknown _x_i4 in
let o = o#option (fun o -> o#string) _x_i5 in o
let o = o#block _x_i1 in
let o = o#exports _x_i2 in let o = o#unknown _x_i3 in o
method number : number -> 'self_type = o#unknown
method mutable_flag : mutable_flag -> 'self_type = o#unknown
method label : label -> 'self_type = o#string
Expand Down Expand Up @@ -397,6 +387,11 @@ class virtual fold =
let o = o#option (fun o -> o#string) _x_i1 in o
method exports : exports -> 'self_type = o#unknown
method exception_ident : exception_ident -> 'self_type = o#ident
method deps_program : deps_program -> 'self_type =
fun { program = _x; modules = _x_i1; side_effect = _x_i2 } ->
let o = o#program _x in
let o = o#required_modules _x_i1 in
let o = o#option (fun o -> o#string) _x_i2 in o
method case_clause :
(* since in ocaml, it's expression oriented langauge, [return] in
general has no jumps, it only happens when we do
Expand Down
35 changes: 12 additions & 23 deletions jscomp/js_map.ml
Original file line number Diff line number Diff line change
Expand Up @@ -322,30 +322,13 @@ class virtual map =
let _x_i1 = o#expression _x_i1 in (_x, _x_i1))
method property : property -> property = o#unknown
method program : program -> program =
fun
{
name = _x;
modules = _x_i1;
block = _x_i2;
exports = _x_i3;
export_set = _x_i4;
side_effect = _x_i5
} ->
fun { name = _x; block = _x_i1; exports = _x_i2; export_set = _x_i3 }
->
let _x = o#string _x in
let _x_i1 = o#required_modules _x_i1 in
let _x_i2 = o#block _x_i2 in
let _x_i3 = o#exports _x_i3 in
let _x_i4 = o#unknown _x_i4 in
let _x_i5 = o#option (fun o -> o#string) _x_i5
in
{
name = _x;
modules = _x_i1;
block = _x_i2;
exports = _x_i3;
export_set = _x_i4;
side_effect = _x_i5;
}
let _x_i1 = o#block _x_i1 in
let _x_i2 = o#exports _x_i2 in
let _x_i3 = o#unknown _x_i3
in { name = _x; block = _x_i1; exports = _x_i2; export_set = _x_i3; }
method number : number -> number = o#unknown
method mutable_flag : mutable_flag -> mutable_flag = o#unknown
method label : label -> label = o#string
Expand Down Expand Up @@ -444,6 +427,12 @@ class virtual map =
in { expression_desc = _x; comment = _x_i1; }
method exports : exports -> exports = o#unknown
method exception_ident : exception_ident -> exception_ident = o#ident
method deps_program : deps_program -> deps_program =
fun { program = _x; modules = _x_i1; side_effect = _x_i2 } ->
let _x = o#program _x in
let _x_i1 = o#required_modules _x_i1 in
let _x_i2 = o#option (fun o -> o#string) _x_i2
in { program = _x; modules = _x_i1; side_effect = _x_i2; }
method case_clause :
(* since in ocaml, it's expression oriented langauge, [return] in
general has no jumps, it only happens when we do
Expand Down
14 changes: 7 additions & 7 deletions jscomp/js_program_loader.ml
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,17 @@ let string_of_module_id (x : module_id) : string =
FIXME: the module order matters?
*)

let make_program name side_effect export_idents external_module_ids block : J.program =
let modules =
List.map (fun id -> Lam_module_ident.id id, string_of_module_id id )
external_module_ids in
let make_program name export_idents block : J.program =

{
name;
modules;

exports = export_idents ;
export_set = Ident_set.of_list export_idents;
block = block;
side_effect ;

}

let decorate_deps modules side_effect program : J.deps_program =

{ program ; modules ; side_effect }

10 changes: 8 additions & 2 deletions jscomp/js_program_loader.mli
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,11 @@

val make_program :
string ->
string option ->
Ident.t list -> Lam_module_ident.t list -> J.block -> J.program
Ident.t list -> J.block -> J.program

val decorate_deps :
J.required_modules ->
string option ->
J.program -> J.deps_program

val string_of_module_id : Lam_module_ident.t -> string
50 changes: 28 additions & 22 deletions jscomp/lam_compile_group.ml
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ let compile_group ({filename = file_name; env;} as meta : Lam_stats.meta)

(** Actually simplify_lets is kind of global optimization since it requires you to know whether
it's used or not
[non_export] is only used in playground
*)
let compile ~filename non_export env _sigs lam : J.program =

let compile ~filename non_export env _sigs lam =
let export_idents =
if non_export then
[]
Expand Down Expand Up @@ -305,35 +305,41 @@ let compile ~filename non_export env _sigs lam : J.program =
|> Js_output.concat
|> Js_output.to_block
in
let external_module_ids =
Lam_compile_env.get_requried_modules
meta.env
meta.required_modules
(Js_fold_basic.calculate_hard_dependencies body)
in
(* Exporting ... *)
let v =
Lam_stats_util.export_to_cmj meta maybe_pure external_module_ids
(if non_export then [] else lambda_exports)
in
(if not @@ Ext_string.is_empty filename then
Js_cmj_format.to_file
(Ext_filename.chop_extension ~loc:__LOC__ filename ^ ".cmj") v);
let js =
Js_program_loader.make_program filename v.pure meta.exports
external_module_ids body
in
(* The file is not big at all compared with [cmo] *)
(* Ext_marshal.to_file (Ext_filename.chop_extension filename ^ ".mj") js; *)

let js =
Js_program_loader.make_program filename meta.exports
body
in
js
|> Js_pass_flatten.program
|> Js_inline_and_eliminate.inline_and_shake

|> Js_pass_flatten_and_mark_dead.program
|> (fun js -> ignore @@ Js_pass_scope.program js ; js )
|> Js_shake.shake_program

|> ( fun (js: J.program) ->
let external_module_ids =
Lam_compile_env.get_requried_modules
meta.env
meta.required_modules
(Js_fold_basic.calculate_hard_dependencies js.block)
in
let required_modules =
List.map
(fun id -> Lam_module_ident.id id, Js_program_loader.string_of_module_id id )
external_module_ids in

(* Exporting ... *)
let v =
Lam_stats_util.export_to_cmj meta maybe_pure external_module_ids
(if non_export then [] else lambda_exports)
in
(if not @@ Ext_string.is_empty filename then
Js_cmj_format.to_file
(Ext_filename.chop_extension ~loc:__LOC__ filename ^ ".cmj") v);
Js_program_loader.decorate_deps required_modules v.pure js
)
| _ -> raise Not_a_module
end
| _ -> raise Not_a_module end
Expand Down
2 changes: 1 addition & 1 deletion jscomp/lam_compile_group.mli
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ val compile :
Env.t ->
Types.signature ->
Lambda.lambda ->
J.program
J.deps_program

val lambda_as_module :
Env.t ->
Expand Down
2 changes: 1 addition & 1 deletion jscomp/test/string_runtime_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
var Caml_string = require("../runtime/caml_string");
var Mt = require("./mt");
var $$String = require("../stdlib/string");
var Caml_string = require("../runtime/caml_string");
var List = require("../stdlib/list");
var Caml_string = require("../runtime/caml_string");

var suites_001 = [
/* tuple */0,
Expand Down