Skip to content

Commit 5dbcda9

Browse files
committed
fix getting correct module_system
1 parent ecd771a commit 5dbcda9

File tree

7 files changed

+148
-153
lines changed

7 files changed

+148
-153
lines changed

jscomp/core/js_implementation.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ let after_parsing_impl ppf outputprefix (ast : Parsetree.structure) =
164164
let lambda, exports =
165165
Translmod.transl_implementation modulename typedtree_coercion
166166
in
167-
let js_program =
167+
let js_program module_system =
168168
print_if_pipe ppf Clflags.dump_rawlambda Printlambda.lambda lambda
169-
|> Lam_compile_main.compile outputprefix exports
169+
|> Lam_compile_main.compile outputprefix module_system exports
170170
in
171171
if not !Js_config.cmj_only then
172172
Lam_compile_main.lambda_as_module js_program outputprefix);

jscomp/core/lam_compile.ml

Lines changed: 129 additions & 126 deletions
Large diffs are not rendered by default.

jscomp/core/lam_compile.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
(** Compile single lambda IR to JS IR *)
2626

2727
val compile_recursive_lets :
28-
string -> Lam_compile_context.t -> (Ident.t * Lam.t) list -> Js_output.t
28+
string -> Js_packages_info.module_system -> Lam_compile_context.t -> (Ident.t * Lam.t) list -> Js_output.t
2929

30-
val compile_lambda : string -> Lam_compile_context.t -> Lam.t -> Js_output.t
30+
val compile_lambda : string -> Js_packages_info.module_system -> Lam_compile_context.t -> Lam.t -> Js_output.t

jscomp/core/lam_compile_main.ml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
(* module S = Js_stmt_make *)
3434

3535

36-
let compile_group output_prefix (meta : Lam_stats.t)
36+
let compile_group output_prefix module_system (meta : Lam_stats.t)
3737
(x : Lam_group.t) : Js_output.t =
3838
match x with
3939
(*
@@ -60,20 +60,20 @@ let compile_group output_prefix (meta : Lam_stats.t)
6060
(* let lam = Optimizer.simplify_lets [] lam in *)
6161
(* can not apply again, it's wrong USE it with care*)
6262
(* ([Js_stmt_make.comment (Gen_of_env.query_type id env )], None) ++ *)
63-
Lam_compile.compile_lambda output_prefix { continuation = Declare (kind, id);
63+
Lam_compile.compile_lambda output_prefix module_system { continuation = Declare (kind, id);
6464
jmp_table = Lam_compile_context.empty_handler_map;
6565
meta
6666
} lam
6767

6868
| Recursive id_lams ->
69-
Lam_compile.compile_recursive_lets output_prefix
69+
Lam_compile.compile_recursive_lets output_prefix module_system
7070
{ continuation = EffectCall Not_tail;
7171
jmp_table = Lam_compile_context.empty_handler_map;
7272
meta
7373
}
7474
id_lams
7575
| Nop lam -> (* TODO: Side effect callls, log and see statistics *)
76-
Lam_compile.compile_lambda output_prefix {continuation = EffectCall Not_tail;
76+
Lam_compile.compile_lambda output_prefix module_system {continuation = EffectCall Not_tail;
7777
jmp_table = Lam_compile_context.empty_handler_map;
7878
meta
7979
} lam
@@ -122,7 +122,8 @@ let _j = Js_pass_debug.dump
122122
it's used or not
123123
*)
124124
let compile
125-
(output_prefix : string)
125+
(output_prefix : string)
126+
(module_system : Js_packages_info.module_system)
126127
export_idents
127128
(lam : Lambda.lambda) =
128129
let export_ident_sets = Set_ident.of_list export_idents in
@@ -222,7 +223,7 @@ let maybe_pure = no_side_effects groups in
222223
let () = Ext_log.dwarn ~__POS__ "\n@[[TIME:]Pre-compile: %f@]@." (Sys.time () *. 1000.) in
223224
#endif
224225
let body =
225-
Ext_list.map groups (fun group -> compile_group output_prefix meta group)
226+
Ext_list.map groups (fun group -> compile_group output_prefix module_system meta group)
226227
|> Js_output.concat
227228
|> Js_output.output_as_block
228229
in
@@ -287,18 +288,18 @@ js
287288
let (//) = Filename.concat
288289

289290
let lambda_as_module
290-
(lambda_output : J.deps_program)
291+
(lambda_output : Js_packages_info.module_system -> J.deps_program)
291292
(output_prefix : string)
292293
: unit =
293294
let package_info = Js_packages_state.get_packages_info () in
294295
if Js_packages_info.is_empty package_info && !Js_config.js_stdout then begin
295-
Js_dump_program.dump_deps_program ~output_prefix NodeJS lambda_output stdout
296+
Js_dump_program.dump_deps_program ~output_prefix NodeJS (lambda_output NodeJS) stdout
296297
end else
297298
Js_packages_info.iter package_info (fun {module_system; path; suffix} ->
298299
let output_chan chan =
299300
Js_dump_program.dump_deps_program ~output_prefix
300301
module_system
301-
lambda_output
302+
(lambda_output module_system)
302303
chan in
303304
let basename =
304305
Ext_namespace.change_ext_ns_suffix

jscomp/core/lam_compile_main.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
(** Compile and register the hook of function to compile a lambda to JS IR
2828
*)
2929

30-
val compile : string -> Ident.t list -> Lambda.lambda -> J.deps_program
30+
val compile : string -> Js_packages_info.module_system -> Ident.t list -> Lambda.lambda -> J.deps_program
3131
(** For toplevel, [filename] is [""] which is the same as
3232
{!Env.get_unit_name ()}
3333
*)
3434

35-
val lambda_as_module : J.deps_program -> string -> unit
35+
val lambda_as_module : (Js_packages_info.module_system -> J.deps_program) -> string -> unit

jscomp/core/lam_compile_primitive.ml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,6 @@ let module_of_expression = function
4040
| J.Var (J.Qualified (module_id, value)) -> [ (module_id, value) ]
4141
| _ -> []
4242

43-
let get_module_system () =
44-
let packages_info = Js_packages_state.get_packages_info () in
45-
let module_systems =
46-
Js_packages_info.map packages_info (fun { module_system } -> module_system)
47-
in
48-
match module_systems with
49-
(* fixme: test mode where the module system is empty *)
50-
| [] -> assert false
51-
| module_system :: _rest -> module_system
52-
5343
let import_of_path path =
5444
E.call
5545
~info:{ arity = Full; call_info = Call_na }
@@ -71,7 +61,7 @@ let wrap_then import value =
7161
];
7262
]
7363

74-
let translate output_prefix loc (cxt : Lam_compile_context.t)
64+
let translate output_prefix module_system loc (cxt : Lam_compile_context.t)
7565
(prim : Lam_primitive.t) (args : J.expression list) : J.expression =
7666
match prim with
7767
| Pis_not_none -> Js_of_lam_option.is_not_none (Ext_list.singleton_exn args)
@@ -127,7 +117,7 @@ let translate output_prefix loc (cxt : Lam_compile_context.t)
127117

128118
let path =
129119
Js_name_of_module_id.string_of_module_id module_id ~output_dir
130-
(get_module_system ())
120+
module_system
131121
in
132122

133123
match module_value with

jscomp/core/lam_compile_primitive.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
val translate :
3232
string ->
33+
Js_packages_info.module_system ->
3334
Location.t ->
3435
Lam_compile_context.t ->
3536
Lam_primitive.t ->

0 commit comments

Comments
 (0)