Skip to content

Commit 8d29282

Browse files
committed
fix #3852
1 parent 3e1a574 commit 8d29282

File tree

12 files changed

+125
-36
lines changed

12 files changed

+125
-36
lines changed

jscomp/common/js_config.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,6 @@ let refmt = ref None
109109

110110
let is_reason = ref false
111111

112-
let js_stdout = ref true
112+
let js_stdout = ref true
113+
114+
let all_module_aliases = ref false

jscomp/common/js_config.mli

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,6 @@ val jsx_version : int ref
103103
val refmt : string option ref
104104
val is_reason : bool ref
105105

106-
val js_stdout : bool ref
106+
val js_stdout : bool ref
107+
108+
val all_module_aliases : bool ref

jscomp/core/js_implementation.ml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,34 @@ let get_lambda = fun
126126
lambda
127127
#end -> lambda
128128

129+
130+
let all_module_alias (ast : Parsetree.structure)=
131+
Ext_list.for_all ast (fun {pstr_desc} ->
132+
match pstr_desc with
133+
| Pstr_module {pmb_expr = {pmod_desc = Pmod_ident _ }}
134+
-> true
135+
| Pstr_attribute _ -> true
136+
| Pstr_eval _
137+
| Pstr_value _
138+
| Pstr_primitive _
139+
| Pstr_type _
140+
| Pstr_typext _
141+
| Pstr_exception _
142+
| Pstr_module _
143+
| Pstr_recmodule _
144+
| Pstr_modtype _
145+
| Pstr_open _
146+
| Pstr_class _
147+
| Pstr_class_type _
148+
| Pstr_include _
149+
| Pstr_extension _ -> false
150+
)
151+
129152
let after_parsing_impl ppf outputprefix ast =
130-
153+
Js_config.all_module_aliases :=
154+
!Clflags.assume_no_mli = Mli_non_exists &&
155+
all_module_alias ast
156+
;
131157
if !Js_config.binary_ast then
132158
Binary_ast.write_ast ~sourcefile:!Location.input_name
133159
Ml ~output:(outputprefix ^

jscomp/core/lam_compile_main.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ let compile
255255
|> _j "shake"
256256
|> ( fun (program: J.program) ->
257257
let external_module_ids : Lam_module_ident.t list =
258+
if !Js_config.all_module_aliases then []
259+
else
258260
let x = Lam_compile_env.get_required_modules
259261
may_required_modules
260262
(Js_fold_basic.calculate_hard_dependencies program.block) in

jscomp/test/gpr_3852_alias.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
'use strict';
22

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

54
var A = 0;
65

76
exports.A = A;
8-
/* Gpr_3852_effect Not a pure module */
7+
/* No side effect */

lib/4.02.3/bsdep.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29759,6 +29759,8 @@ val refmt : string option ref
2975929759
val is_reason : bool ref
2976029760

2976129761
val js_stdout : bool ref
29762+
29763+
val all_module_aliases : bool ref
2976229764
end = struct
2976329765
#1 "js_config.ml"
2976429766
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -29873,6 +29875,8 @@ let refmt = ref None
2987329875
let is_reason = ref false
2987429876

2987529877
let js_stdout = ref true
29878+
29879+
let all_module_aliases = ref false
2987629880
end
2987729881
module Bs_warnings : sig
2987829882
#1 "bs_warnings.mli"

lib/4.02.3/bsppx.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2649,6 +2649,8 @@ val refmt : string option ref
26492649
val is_reason : bool ref
26502650

26512651
val js_stdout : bool ref
2652+
2653+
val all_module_aliases : bool ref
26522654
end = struct
26532655
#1 "js_config.ml"
26542656
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -2763,6 +2765,8 @@ let refmt = ref None
27632765
let is_reason = ref false
27642766

27652767
let js_stdout = ref true
2768+
2769+
let all_module_aliases = ref false
27662770
end
27672771
(** Interface as module *)
27682772
module Asttypes

lib/4.02.3/unstable/all_ounit_tests.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7411,6 +7411,8 @@ val refmt : string option ref
74117411
val is_reason : bool ref
74127412

74137413
val js_stdout : bool ref
7414+
7415+
val all_module_aliases : bool ref
74147416
end = struct
74157417
#1 "js_config.ml"
74167418
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -7525,6 +7527,8 @@ let refmt = ref None
75257527
let is_reason = ref false
75267528

75277529
let js_stdout = ref true
7530+
7531+
let all_module_aliases = ref false
75287532
end
75297533
module Ml_binary : sig
75307534
#1 "ml_binary.mli"

lib/4.02.3/unstable/bspack.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8178,6 +8178,8 @@ val refmt : string option ref
81788178
val is_reason : bool ref
81798179

81808180
val js_stdout : bool ref
8181+
8182+
val all_module_aliases : bool ref
81818183
end = struct
81828184
#1 "js_config.ml"
81838185
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -8292,6 +8294,8 @@ let refmt = ref None
82928294
let is_reason = ref false
82938295

82948296
let js_stdout = ref true
8297+
8298+
let all_module_aliases = ref false
82958299
end
82968300
module Ml_binary : sig
82978301
#1 "ml_binary.mli"

lib/4.02.3/unstable/js_compiler.ml

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11709,6 +11709,8 @@ val refmt : string option ref
1170911709
val is_reason : bool ref
1171011710

1171111711
val js_stdout : bool ref
11712+
11713+
val all_module_aliases : bool ref
1171211714
end = struct
1171311715
#1 "js_config.ml"
1171411716
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -11823,6 +11825,8 @@ let refmt = ref None
1182311825
let is_reason = ref false
1182411826

1182511827
let js_stdout = ref true
11828+
11829+
let all_module_aliases = ref false
1182611830
end
1182711831
module Bs_warnings : sig
1182811832
#1 "bs_warnings.mli"
@@ -112598,7 +112602,10 @@ let prim = Lam.prim
112598112602
type required_modules = Lam_module_ident.Hash_set.t
112599112603

112600112604

112601-
(** drop Lseq (List! ) etc *)
112605+
(** drop Lseq (List! ) etc
112606+
see #3852, we drop all these required global modules
112607+
but added it back based on our own module analysis
112608+
*)
112602112609
let rec drop_global_marker (lam : Lam.t) =
112603112610
match lam with
112604112611
| Lsequence (Lglobal_module id, rest) ->
@@ -116270,20 +116277,19 @@ let compile
116270116277
|> Js_shake.shake_program
116271116278
|> _j "shake"
116272116279
|> ( fun (program: J.program) ->
116273-
let external_module_ids =
116274-
Lam_compile_env.get_required_modules
116275-
may_required_modules
116276-
(Js_fold_basic.calculate_hard_dependencies program.block)
116277-
|>
116278-
(fun x ->
116279-
if !Js_config.sort_imports then
116280-
Ext_list.sort_via_array x
116281-
(fun id1 id2 ->
116282-
Ext_string.compare (Lam_module_ident.name id1) (Lam_module_ident.name id2)
116283-
)
116284-
else
116285-
x
116286-
)
116280+
let external_module_ids : Lam_module_ident.t list =
116281+
if !Js_config.all_module_aliases then []
116282+
else
116283+
let x = Lam_compile_env.get_required_modules
116284+
may_required_modules
116285+
(Js_fold_basic.calculate_hard_dependencies program.block) in
116286+
if !Js_config.sort_imports then
116287+
Ext_list.sort_via_array x
116288+
(fun id1 id2 ->
116289+
Ext_string.compare (Lam_module_ident.name id1) (Lam_module_ident.name id2)
116290+
)
116291+
else
116292+
x
116287116293
in
116288116294
Warnings.check_fatal ();
116289116295
let effect =

0 commit comments

Comments
 (0)