Skip to content

Commit

Permalink
fix getting correct module_system
Browse files Browse the repository at this point in the history
  • Loading branch information
mununki committed Dec 27, 2022
1 parent ecd771a commit 5dbcda9
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 153 deletions.
4 changes: 2 additions & 2 deletions jscomp/core/js_implementation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ let after_parsing_impl ppf outputprefix (ast : Parsetree.structure) =
let lambda, exports =
Translmod.transl_implementation modulename typedtree_coercion
in
let js_program =
let js_program module_system =
print_if_pipe ppf Clflags.dump_rawlambda Printlambda.lambda lambda
|> Lam_compile_main.compile outputprefix exports
|> Lam_compile_main.compile outputprefix module_system exports
in
if not !Js_config.cmj_only then
Lam_compile_main.lambda_as_module js_program outputprefix);
Expand Down
255 changes: 129 additions & 126 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 :
string -> Lam_compile_context.t -> (Ident.t * Lam.t) list -> Js_output.t
string -> Js_packages_info.module_system -> Lam_compile_context.t -> (Ident.t * Lam.t) list -> Js_output.t

val compile_lambda : string -> Lam_compile_context.t -> Lam.t -> Js_output.t
val compile_lambda : string -> Js_packages_info.module_system -> Lam_compile_context.t -> Lam.t -> Js_output.t
19 changes: 10 additions & 9 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 (meta : Lam_stats.t)
let compile_group output_prefix module_system (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 (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 { continuation = Declare (kind, id);
Lam_compile.compile_lambda output_prefix module_system { continuation = Declare (kind, id);
jmp_table = Lam_compile_context.empty_handler_map;
meta
} lam

| Recursive id_lams ->
Lam_compile.compile_recursive_lets output_prefix
Lam_compile.compile_recursive_lets output_prefix module_system
{ 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 {continuation = EffectCall Not_tail;
Lam_compile.compile_lambda output_prefix module_system {continuation = EffectCall Not_tail;
jmp_table = Lam_compile_context.empty_handler_map;
meta
} lam
Expand Down Expand Up @@ -122,7 +122,8 @@ let _j = Js_pass_debug.dump
it's used or not
*)
let compile
(output_prefix : string)
(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 @@ -222,7 +223,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 meta group)
Ext_list.map groups (fun group -> compile_group output_prefix module_system meta group)
|> Js_output.concat
|> Js_output.output_as_block
in
Expand Down Expand Up @@ -287,18 +288,18 @@ js
let (//) = Filename.concat

let lambda_as_module
(lambda_output : J.deps_program)
(lambda_output : Js_packages_info.module_system -> J.deps_program)
(output_prefix : string)
: unit =
let package_info = Js_packages_state.get_packages_info () in
if Js_packages_info.is_empty package_info && !Js_config.js_stdout then begin
Js_dump_program.dump_deps_program ~output_prefix NodeJS lambda_output stdout
Js_dump_program.dump_deps_program ~output_prefix NodeJS (lambda_output NodeJS) stdout
end else
Js_packages_info.iter package_info (fun {module_system; path; suffix} ->
let output_chan chan =
Js_dump_program.dump_deps_program ~output_prefix
module_system
lambda_output
(lambda_output module_system)
chan in
let basename =
Ext_namespace.change_ext_ns_suffix
Expand Down
4 changes: 2 additions & 2 deletions jscomp/core/lam_compile_main.mli
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
(** Compile and register the hook of function to compile a lambda to JS IR
*)

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

val lambda_as_module : J.deps_program -> string -> unit
val lambda_as_module : (Js_packages_info.module_system -> J.deps_program) -> string -> unit
14 changes: 2 additions & 12 deletions jscomp/core/lam_compile_primitive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,6 @@ let module_of_expression = function
| J.Var (J.Qualified (module_id, value)) -> [ (module_id, value) ]
| _ -> []

let get_module_system () =
let packages_info = Js_packages_state.get_packages_info () in
let module_systems =
Js_packages_info.map packages_info (fun { module_system } -> module_system)
in
match module_systems with
(* fixme: test mode where the module system is empty *)
| [] -> assert false
| module_system :: _rest -> module_system

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

let translate output_prefix loc (cxt : Lam_compile_context.t)
let translate output_prefix module_system 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 @@ -127,7 +117,7 @@ let translate output_prefix loc (cxt : Lam_compile_context.t)

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

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

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

0 comments on commit 5dbcda9

Please sign in to comment.