Skip to content

Commit ae62547

Browse files
committed
remove drilling module_system arg
- get module_system inside compiling Pimport primitive
1 parent b5aec26 commit ae62547

File tree

7 files changed

+154
-148
lines changed

7 files changed

+154
-148
lines changed

jscomp/core/js_implementation.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ let after_parsing_impl ppf outputprefix (ast : Parsetree.structure) =
166166
in
167167
let js_program =
168168
print_if_pipe ppf Clflags.dump_rawlambda Printlambda.lambda lambda
169-
|> Lam_compile_main.compile outputprefix NodeJS exports
169+
|> Lam_compile_main.compile outputprefix 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: 131 additions & 134 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-
output_prefix:string -> Js_packages_info.module_system -> Lam_compile_context.t -> (Ident.t * Lam.t) list -> Js_output.t
28+
output_prefix:string -> Lam_compile_context.t -> (Ident.t * Lam.t) list -> Js_output.t
2929

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

jscomp/core/lam_compile_main.ml

Lines changed: 5 additions & 6 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 module_system (meta : Lam_stats.t)
36+
let compile_group output_prefix (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 module_system (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 module_system { continuation = Declare (kind, id);
63+
Lam_compile.compile_lambda ~output_prefix { 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 module_system
69+
Lam_compile.compile_recursive_lets ~output_prefix
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 module_system {continuation = EffectCall Not_tail;
76+
Lam_compile.compile_lambda ~output_prefix {continuation = EffectCall Not_tail;
7777
jmp_table = Lam_compile_context.empty_handler_map;
7878
meta
7979
} lam
@@ -123,7 +123,6 @@ let _j = Js_pass_debug.dump
123123
*)
124124
let compile
125125
(output_prefix : string)
126-
(module_system : Js_packages_info.module_system)
127126
export_idents
128127
(lam : Lambda.lambda) =
129128
let export_ident_sets = Set_ident.of_list export_idents in
@@ -223,7 +222,7 @@ let maybe_pure = no_side_effects groups in
223222
let () = Ext_log.dwarn ~__POS__ "\n@[[TIME:]Pre-compile: %f@]@." (Sys.time () *. 1000.) in
224223
#endif
225224
let body =
226-
Ext_list.map groups (fun group -> compile_group output_prefix module_system meta group)
225+
Ext_list.map groups (fun group -> compile_group output_prefix meta group)
227226
|> Js_output.concat
228227
|> Js_output.output_as_block
229228
in

jscomp/core/lam_compile_main.mli

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

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

jscomp/core/lam_compile_primitive.ml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ 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 package_info = Js_packages_state.get_packages_info () in
45+
let module_system =
46+
if Js_packages_info.is_empty package_info && !Js_config.js_stdout then
47+
[Js_packages_info.NodeJS]
48+
else Js_packages_info.map package_info (fun {module_system} -> module_system)
49+
in
50+
match module_system with
51+
| [module_system] -> module_system
52+
| _ -> NodeJS
53+
4354
let import_of_path path =
4455
E.call
4556
~info:{ arity = Full; call_info = Call_na }
@@ -61,7 +72,7 @@ let wrap_then import value =
6172
];
6273
]
6374

64-
let translate output_prefix module_system loc (cxt : Lam_compile_context.t)
75+
let translate output_prefix loc (cxt : Lam_compile_context.t)
6576
(prim : Lam_primitive.t) (args : J.expression list) : J.expression =
6677
match prim with
6778
| Pis_not_none -> Js_of_lam_option.is_not_none (Ext_list.singleton_exn args)
@@ -118,8 +129,8 @@ let translate output_prefix module_system loc (cxt : Lam_compile_context.t)
118129
in
119130

120131
let path =
121-
Js_name_of_module_id.string_of_module_id module_id ~output_dir
122-
module_system
132+
let module_system = get_module_system () in
133+
Js_name_of_module_id.string_of_module_id module_id ~output_dir module_system
123134
in
124135

125136
match module_value with

jscomp/core/lam_compile_primitive.mli

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

3131
val translate :
3232
string ->
33-
Js_packages_info.module_system ->
3433
Location.t ->
3534
Lam_compile_context.t ->
3635
Lam_primitive.t ->

0 commit comments

Comments
 (0)