Skip to content
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
4 changes: 3 additions & 1 deletion jscomp/common/js_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,6 @@ let refmt = ref None

let is_reason = ref false

let js_stdout = ref true
let js_stdout = ref true

let all_module_aliases = ref false
4 changes: 3 additions & 1 deletion jscomp/common/js_config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,6 @@ val jsx_version : int ref
val refmt : string option ref
val is_reason : bool ref

val js_stdout : bool ref
val js_stdout : bool ref

val all_module_aliases : bool ref
28 changes: 27 additions & 1 deletion jscomp/core/js_implementation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,34 @@ let get_lambda = fun
lambda
#end -> lambda


let all_module_alias (ast : Parsetree.structure)=
Ext_list.for_all ast (fun {pstr_desc} ->
match pstr_desc with
| Pstr_module {pmb_expr = {pmod_desc = Pmod_ident _ }}
-> true
| Pstr_attribute _ -> true
| Pstr_eval _
| Pstr_value _
| Pstr_primitive _
| Pstr_type _
| Pstr_typext _
| Pstr_exception _
| Pstr_module _
| Pstr_recmodule _
| Pstr_modtype _
| Pstr_open _
| Pstr_class _
| Pstr_class_type _
| Pstr_include _
| Pstr_extension _ -> false
)

let after_parsing_impl ppf outputprefix ast =

Js_config.all_module_aliases :=
!Clflags.assume_no_mli = Mli_non_exists &&
all_module_alias ast
;
if !Js_config.binary_ast then
Binary_ast.write_ast ~sourcefile:!Location.input_name
Ml ~output:(outputprefix ^
Expand Down
27 changes: 13 additions & 14 deletions jscomp/core/lam_compile_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -254,20 +254,19 @@ let compile
|> Js_shake.shake_program
|> _j "shake"
|> ( fun (program: J.program) ->
let external_module_ids =
Lam_compile_env.get_required_modules
may_required_modules
(Js_fold_basic.calculate_hard_dependencies program.block)
|>
(fun x ->
if !Js_config.sort_imports then
Ext_list.sort_via_array x
(fun id1 id2 ->
Ext_string.compare (Lam_module_ident.name id1) (Lam_module_ident.name id2)
)
else
x
)
let external_module_ids : Lam_module_ident.t list =
if !Js_config.all_module_aliases then []
else
let x = Lam_compile_env.get_required_modules
may_required_modules
(Js_fold_basic.calculate_hard_dependencies program.block) in
if !Js_config.sort_imports then
Ext_list.sort_via_array x
(fun id1 id2 ->
Ext_string.compare (Lam_module_ident.name id1) (Lam_module_ident.name id2)
)
else
x
in
Warnings.check_fatal ();
let effect =
Expand Down
5 changes: 4 additions & 1 deletion jscomp/core/lam_convert.ml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ let prim = Lam.prim
type required_modules = Lam_module_ident.Hash_set.t


(** drop Lseq (List! ) etc *)
(** drop Lseq (List! ) etc
see #3852, we drop all these required global modules
but added it back based on our own module analysis
*)
let rec drop_global_marker (lam : Lam.t) =
match lam with
| Lsequence (Lglobal_module id, rest) ->
Expand Down
3 changes: 2 additions & 1 deletion jscomp/test/bigarray_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

var Bigarray = require("../../lib/js/bigarray.js");
var Caml_int32 = require("../../lib/js/caml_int32.js");
var Caml_external_polyfill = require("../../lib/js/caml_external_polyfill.js");

Expand Down Expand Up @@ -42,4 +43,4 @@ exports.sum = sum;
exports.init = init;
exports.init2 = init2;
exports.init3 = init3;
/* No side effect */
/* Bigarray Not a pure module */
6 changes: 5 additions & 1 deletion jscomp/test/build.ninja
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

bsc = ../lib/bsc.exe
bsc_flags = -absname -no-alias-deps -bs-no-version-header -bs-diagnose -bs-cross-module-opt -bs-package-name bs-platform -bs-package-output commonjs:jscomp/test -w -40-52 -warn-error A+8-3-30-26+101-102-103-104-52 -bin-annot -I runtime -I $stdlib -I others
bsc_flags = -absname -bs-no-version-header -bs-diagnose -bs-cross-module-opt -bs-package-name bs-platform -bs-package-output commonjs:jscomp/test -w -40-52 -warn-error A+8-3-30-26+101-102-103-104-52 -bin-annot -I runtime -I $stdlib -I others

rule cc
command = $bsc -bs-cmi -bs-cmj $bsc_flags -I test $in
Expand Down Expand Up @@ -297,6 +297,10 @@ build test/gpr_3609_test.cmi test/gpr_3609_test.cmj : cc test/gpr_3609_test.ml |
build test/gpr_3697_test.cmi test/gpr_3697_test.cmj : cc test/gpr_3697_test.ml | $stdlib
build test/gpr_373_test.cmi test/gpr_373_test.cmj : cc test/gpr_373_test.ml | $stdlib
build test/gpr_3770_test.cmi test/gpr_3770_test.cmj : cc test/gpr_3770_test.ml | $stdlib
build test/gpr_3852_alias.cmi test/gpr_3852_alias.cmj : cc test/gpr_3852_alias.ml | test/gpr_3852_effect.cmj $stdlib
build test/gpr_3852_alias_reify.cmj : cc_cmi test/gpr_3852_alias_reify.ml | test/gpr_3852_alias_reify.cmi test/gpr_3852_effect.cmj $stdlib
build test/gpr_3852_alias_reify.cmi : cc test/gpr_3852_alias_reify.mli | $stdlib
build test/gpr_3852_effect.cmi test/gpr_3852_effect.cmj : cc test/gpr_3852_effect.ml | $stdlib
build test/gpr_3865.cmi test/gpr_3865.cmj : cc test/gpr_3865.re | test/gpr_3865_bar.cmj test/gpr_3865_foo.cmj $stdlib
build test/gpr_3865_bar.cmi test/gpr_3865_bar.cmj : cc test/gpr_3865_bar.re | $stdlib
build test/gpr_3865_foo.cmi test/gpr_3865_foo.cmj : cc test/gpr_3865_foo.re | $stdlib
Expand Down
7 changes: 7 additions & 0 deletions jscomp/test/gpr_3852_alias.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';


var A = 0;

exports.A = A;
/* No side effect */
5 changes: 5 additions & 0 deletions jscomp/test/gpr_3852_alias.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@


module A = Gpr_3852_effect

(* It should generate a dummy JS file *)
8 changes: 8 additions & 0 deletions jscomp/test/gpr_3852_alias_reify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

var Gpr_3852_effect = require("./gpr_3852_effect.js");

var A = Gpr_3852_effect;

exports.A = A;
/* Gpr_3852_effect Not a pure module */
1 change: 1 addition & 0 deletions jscomp/test/gpr_3852_alias_reify.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module A = Gpr_3852_effect
3 changes: 3 additions & 0 deletions jscomp/test/gpr_3852_alias_reify.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module A : sig
val v : int
end
9 changes: 9 additions & 0 deletions jscomp/test/gpr_3852_effect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';


console.log("hello");

var v = 0;

exports.v = v;
/* Not a pure module */
3 changes: 3 additions & 0 deletions jscomp/test/gpr_3852_effect.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

let v = 0
let () = Js.log "hello"
4 changes: 4 additions & 0 deletions lib/4.02.3/bsdep.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29759,6 +29759,8 @@ val refmt : string option ref
val is_reason : bool ref

val js_stdout : bool ref

val all_module_aliases : bool ref
end = struct
#1 "js_config.ml"
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
Expand Down Expand Up @@ -29873,6 +29875,8 @@ let refmt = ref None
let is_reason = ref false

let js_stdout = ref true

let all_module_aliases = ref false
end
module Bs_warnings : sig
#1 "bs_warnings.mli"
Expand Down
4 changes: 4 additions & 0 deletions lib/4.02.3/bsppx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2649,6 +2649,8 @@ val refmt : string option ref
val is_reason : bool ref

val js_stdout : bool ref

val all_module_aliases : bool ref
end = struct
#1 "js_config.ml"
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
Expand Down Expand Up @@ -2763,6 +2765,8 @@ let refmt = ref None
let is_reason = ref false

let js_stdout = ref true

let all_module_aliases = ref false
end
(** Interface as module *)
module Asttypes
Expand Down
4 changes: 4 additions & 0 deletions lib/4.02.3/unstable/all_ounit_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7411,6 +7411,8 @@ val refmt : string option ref
val is_reason : bool ref

val js_stdout : bool ref

val all_module_aliases : bool ref
end = struct
#1 "js_config.ml"
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
Expand Down Expand Up @@ -7525,6 +7527,8 @@ let refmt = ref None
let is_reason = ref false

let js_stdout = ref true

let all_module_aliases = ref false
end
module Ml_binary : sig
#1 "ml_binary.mli"
Expand Down
4 changes: 4 additions & 0 deletions lib/4.02.3/unstable/bspack.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8178,6 +8178,8 @@ val refmt : string option ref
val is_reason : bool ref

val js_stdout : bool ref

val all_module_aliases : bool ref
end = struct
#1 "js_config.ml"
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
Expand Down Expand Up @@ -8292,6 +8294,8 @@ let refmt = ref None
let is_reason = ref false

let js_stdout = ref true

let all_module_aliases = ref false
end
module Ml_binary : sig
#1 "ml_binary.mli"
Expand Down
36 changes: 21 additions & 15 deletions lib/4.02.3/unstable/js_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11709,6 +11709,8 @@ val refmt : string option ref
val is_reason : bool ref

val js_stdout : bool ref

val all_module_aliases : bool ref
end = struct
#1 "js_config.ml"
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
Expand Down Expand Up @@ -11823,6 +11825,8 @@ let refmt = ref None
let is_reason = ref false

let js_stdout = ref true

let all_module_aliases = ref false
end
module Bs_warnings : sig
#1 "bs_warnings.mli"
Expand Down Expand Up @@ -112598,7 +112602,10 @@ let prim = Lam.prim
type required_modules = Lam_module_ident.Hash_set.t


(** drop Lseq (List! ) etc *)
(** drop Lseq (List! ) etc
see #3852, we drop all these required global modules
but added it back based on our own module analysis
*)
let rec drop_global_marker (lam : Lam.t) =
match lam with
| Lsequence (Lglobal_module id, rest) ->
Expand Down Expand Up @@ -116270,20 +116277,19 @@ let compile
|> Js_shake.shake_program
|> _j "shake"
|> ( fun (program: J.program) ->
let external_module_ids =
Lam_compile_env.get_required_modules
may_required_modules
(Js_fold_basic.calculate_hard_dependencies program.block)
|>
(fun x ->
if !Js_config.sort_imports then
Ext_list.sort_via_array x
(fun id1 id2 ->
Ext_string.compare (Lam_module_ident.name id1) (Lam_module_ident.name id2)
)
else
x
)
let external_module_ids : Lam_module_ident.t list =
if !Js_config.all_module_aliases then []
else
let x = Lam_compile_env.get_required_modules
may_required_modules
(Js_fold_basic.calculate_hard_dependencies program.block) in
if !Js_config.sort_imports then
Ext_list.sort_via_array x
(fun id1 id2 ->
Ext_string.compare (Lam_module_ident.name id1) (Lam_module_ident.name id2)
)
else
x
in
Warnings.check_fatal ();
let effect =
Expand Down
4 changes: 4 additions & 0 deletions lib/4.02.3/unstable/native_ppx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11687,6 +11687,8 @@ val refmt : string option ref
val is_reason : bool ref

val js_stdout : bool ref

val all_module_aliases : bool ref
end = struct
#1 "js_config.ml"
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
Expand Down Expand Up @@ -11801,6 +11803,8 @@ let refmt = ref None
let is_reason = ref false

let js_stdout = ref true

let all_module_aliases = ref false
end
module Bs_warnings : sig
#1 "bs_warnings.mli"
Expand Down
Loading