Skip to content

Commit

Permalink
remove drilling module_system arg
Browse files Browse the repository at this point in the history
- get module_system inside compiling Pimport primitive
  • Loading branch information
mununki committed Apr 23, 2023
1 parent b5aec26 commit ae62547
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 148 deletions.
2 changes: 1 addition & 1 deletion jscomp/core/js_implementation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ let after_parsing_impl ppf outputprefix (ast : Parsetree.structure) =
in
let js_program =
print_if_pipe ppf Clflags.dump_rawlambda Printlambda.lambda lambda
|> Lam_compile_main.compile outputprefix NodeJS exports
|> Lam_compile_main.compile outputprefix exports
in
if not !Js_config.cmj_only then
Lam_compile_main.lambda_as_module js_program outputprefix);
Expand Down
265 changes: 131 additions & 134 deletions jscomp/core/lam_compile.ml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions jscomp/core/lam_compile.mli
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
(** Compile single lambda IR to JS IR *)

val compile_recursive_lets :
output_prefix:string -> Js_packages_info.module_system -> Lam_compile_context.t -> (Ident.t * Lam.t) list -> Js_output.t
output_prefix:string -> Lam_compile_context.t -> (Ident.t * Lam.t) list -> Js_output.t

val compile_lambda : output_prefix:string -> Js_packages_info.module_system -> Lam_compile_context.t -> Lam.t -> Js_output.t
val compile_lambda : output_prefix:string -> Lam_compile_context.t -> Lam.t -> Js_output.t
11 changes: 5 additions & 6 deletions jscomp/core/lam_compile_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
(* module S = Js_stmt_make *)


let compile_group output_prefix module_system (meta : Lam_stats.t)
let compile_group output_prefix (meta : Lam_stats.t)
(x : Lam_group.t) : Js_output.t =
match x with
(*
Expand All @@ -60,20 +60,20 @@ let compile_group output_prefix module_system (meta : Lam_stats.t)
(* let lam = Optimizer.simplify_lets [] lam in *)
(* can not apply again, it's wrong USE it with care*)
(* ([Js_stmt_make.comment (Gen_of_env.query_type id env )], None) ++ *)
Lam_compile.compile_lambda ~output_prefix module_system { continuation = Declare (kind, id);
Lam_compile.compile_lambda ~output_prefix { continuation = Declare (kind, id);
jmp_table = Lam_compile_context.empty_handler_map;
meta
} lam

| Recursive id_lams ->
Lam_compile.compile_recursive_lets ~output_prefix module_system
Lam_compile.compile_recursive_lets ~output_prefix
{ continuation = EffectCall Not_tail;
jmp_table = Lam_compile_context.empty_handler_map;
meta
}
id_lams
| Nop lam -> (* TODO: Side effect callls, log and see statistics *)
Lam_compile.compile_lambda ~output_prefix module_system {continuation = EffectCall Not_tail;
Lam_compile.compile_lambda ~output_prefix {continuation = EffectCall Not_tail;
jmp_table = Lam_compile_context.empty_handler_map;
meta
} lam
Expand Down Expand Up @@ -123,7 +123,6 @@ let _j = Js_pass_debug.dump
*)
let compile
(output_prefix : string)
(module_system : Js_packages_info.module_system)
export_idents
(lam : Lambda.lambda) =
let export_ident_sets = Set_ident.of_list export_idents in
Expand Down Expand Up @@ -223,7 +222,7 @@ let maybe_pure = no_side_effects groups in
let () = Ext_log.dwarn ~__POS__ "\n@[[TIME:]Pre-compile: %f@]@." (Sys.time () *. 1000.) in
#endif
let body =
Ext_list.map groups (fun group -> compile_group output_prefix module_system meta group)
Ext_list.map groups (fun group -> compile_group output_prefix meta group)
|> Js_output.concat
|> Js_output.output_as_block
in
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/lam_compile_main.mli
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
(** Compile and register the hook of function to compile a lambda to JS IR
*)

val compile : string -> Js_packages_info.module_system -> Ident.t list -> Lambda.lambda -> J.deps_program
val compile : string -> Ident.t list -> Lambda.lambda -> J.deps_program
(** For toplevel, [filename] is [""] which is the same as
{!Env.get_unit_name ()}
*)
Expand Down
17 changes: 14 additions & 3 deletions jscomp/core/lam_compile_primitive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ let module_of_expression = function
| J.Var (J.Qualified (module_id, value)) -> [ (module_id, value) ]
| _ -> []

let get_module_system () =
let package_info = Js_packages_state.get_packages_info () in
let module_system =
if Js_packages_info.is_empty package_info && !Js_config.js_stdout then
[Js_packages_info.NodeJS]
else Js_packages_info.map package_info (fun {module_system} -> module_system)
in
match module_system with
| [module_system] -> module_system
| _ -> NodeJS

let import_of_path path =
E.call
~info:{ arity = Full; call_info = Call_na }
Expand All @@ -61,7 +72,7 @@ let wrap_then import value =
];
]

let translate output_prefix module_system loc (cxt : Lam_compile_context.t)
let translate output_prefix loc (cxt : Lam_compile_context.t)
(prim : Lam_primitive.t) (args : J.expression list) : J.expression =
match prim with
| Pis_not_none -> Js_of_lam_option.is_not_none (Ext_list.singleton_exn args)
Expand Down Expand Up @@ -118,8 +129,8 @@ let translate output_prefix module_system loc (cxt : Lam_compile_context.t)
in

let path =
Js_name_of_module_id.string_of_module_id module_id ~output_dir
module_system
let module_system = get_module_system () in
Js_name_of_module_id.string_of_module_id module_id ~output_dir module_system
in

match module_value with
Expand Down
1 change: 0 additions & 1 deletion jscomp/core/lam_compile_primitive.mli
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

val translate :
string ->
Js_packages_info.module_system ->
Location.t ->
Lam_compile_context.t ->
Lam_primitive.t ->
Expand Down

0 comments on commit ae62547

Please sign in to comment.