Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions jscomp/core/bs_cmi_load.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

(* TODO: provide native load*)
let browse_load ~unit_name : Env.Persistent_signature.t option=
match Ext_string_array.find_sorted Builtin_cmi_datasets.module_sets unit_name with
| Some index ->
match Ext_string_array.find_sorted_assoc Builtin_cmi_datasets.module_sets_cmi unit_name with
| Some cmi ->
(* Format.fprintf Format.err_formatter "reading %s@." unit_name; *)
Some {filename = Sys.executable_name ;
cmi =
Lazy.force Builtin_cmi_datasets.module_sets_cmi.(index)}
Lazy.force cmi}
| None -> assert false
403 changes: 135 additions & 268 deletions jscomp/core/builtin_cmi_datasets.ml

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions jscomp/core/builtin_cmi_datasets.mli
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@



(* TODO: we can hide some
more internal units
*)
val module_sets : string array
val module_sets_cmi : Cmi_format.cmi_infos Lazy.t array

val module_sets_cmi :
(string * Cmi_format.cmi_infos Lazy.t) array
434 changes: 142 additions & 292 deletions jscomp/core/builtin_cmj_datasets.ml

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions jscomp/core/builtin_cmj_datasets.mli
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
val module_sets : string array
val module_sets_cmj : Js_cmj_format.t Lazy.t array
val query_by_name : string -> Js_cmj_format.t option


val module_sets :
(string * Js_cmj_format.t Lazy.t ) array
79 changes: 8 additions & 71 deletions jscomp/core/js_cmj_format.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ type effect = string option


let single_na = Single Lam_arity.na
(** we don't force people to use package *)
type cmj_case = Ext_namespace.file_kind

type keyed_cmj_value = { name : string ; arity : arity ; persistent_closed_lambda : Lam.t option}
type keyed_cmj_values
Expand All @@ -52,20 +50,20 @@ type keyed_cmj_values
type t = {
values : keyed_cmj_values ;
pure : bool;
npm_package_path : Js_packages_info.t ;
cmj_case : cmj_case;
package_spec : Js_packages_info.t ;
js_file_kind : Ext_js_file_kind.t;
}

let make ~(values:cmj_value Map_string.t) ~effect ~npm_package_path ~cmj_case : t =
let make ~(values:cmj_value Map_string.t) ~effect ~package_spec ~js_file_kind : t =
{
values = Map_string.to_sorted_array_with_f values (fun k v -> {
name = k ;
arity = v.arity;
persistent_closed_lambda = v.persistent_closed_lambda
});
pure = effect = None ;
npm_package_path;
cmj_case
package_spec;
js_file_kind
}


Expand Down Expand Up @@ -178,70 +176,9 @@ let query_by_name (cmj_table : t ) name : keyed_cmj_value =
let values = cmj_table.values in
binarySearch values name

let is_pure (cmj_table : t ) =
cmj_table.pure

let get_npm_package_path (cmj_table : t) =
cmj_table.npm_package_path

let get_cmj_case (cmj_table : t) =
cmj_table.cmj_case


(* start dumping *)

let f fmt = Printf.fprintf stdout fmt

let pp_cmj_case (cmj_case : cmj_case) : unit =
match cmj_case with
| Little_js ->
f "case : little, .js \n"
| Little_bs ->
f "case : little, .bs.js \n"
| Upper_js ->
f "case: upper, .js \n"
| Upper_bs ->
f "case: upper, .bs.js \n"

let pp_cmj
({ values ; pure; npm_package_path ; cmj_case} : t) =
f "package info: %s\n"
(Format.asprintf "%a" Js_packages_info.dump_packages_info npm_package_path)
;
pp_cmj_case cmj_case;

f "effect: %s\n"
(if pure then "pure" else "not pure");
Ext_array.iter values
(fun ({name = k ; arity; persistent_closed_lambda}) ->
match arity with
| Single arity ->
f "%s: %s\n" k (Format.asprintf "%a" Lam_arity.print arity);
(match persistent_closed_lambda with
| None ->
f "%s: not saved\n" k
| Some lam ->
begin
f "%s: ======[start]\n" k ;
f "%s\n" (Lam_print.lambda_to_string lam);
f "%s: ======[finish]\n" k
end )
| Submodule xs ->
(match persistent_closed_lambda with
| None -> f "%s: not saved\n" k
| Some lam ->
begin
f "%s: ======[start]\n" k ;
f "%s" (Lam_print.lambda_to_string lam);
f "%s: ======[finish]\n" k
end
);
Array.iteri
(fun i arity -> f "%s[%i] : %s \n"
k i
(Format.asprintf "%a" Lam_arity.print arity ))
xs
)




type path = string
type cmj_load_info = {
Expand Down
36 changes: 17 additions & 19 deletions jscomp/core/js_cmj_format.mli
Original file line number Diff line number Diff line change
Expand Up @@ -64,37 +64,34 @@ type cmj_value = {

type effect = string option

type cmj_case = Ext_namespace.file_kind
type keyed_cmj_value = {
name : string ;
arity : arity ;
persistent_closed_lambda : Lam.t option
}

type t
type t = private {
values : keyed_cmj_value array ;
pure : bool;
package_spec : Js_packages_info.t ;
js_file_kind : Ext_js_file_kind.t;
}


val make:
values: cmj_value Map_string.t ->
effect: effect ->
npm_package_path: Js_packages_info.t ->
cmj_case:cmj_case ->
package_spec: Js_packages_info.t ->
js_file_kind:Ext_js_file_kind.t ->
t

type keyed_cmj_value =
{ name : string ;
arity : arity ;
persistent_closed_lambda : Lam.t option}

val query_by_name :
t ->
string ->
keyed_cmj_value

val is_pure :
t -> bool

val get_npm_package_path :
t ->
Js_packages_info.t

val get_cmj_case :
t ->
cmj_case

val single_na : arity

Expand All @@ -107,12 +104,13 @@ val from_file_with_digest :

val from_string : string -> t

(* Note writing the file if its content is not chnaged
(*
Note writing the file if its content is not changed
*)
val to_file :
string -> check_exists:bool -> t -> unit

val pp_cmj: t -> unit



type path = string
Expand Down
9 changes: 6 additions & 3 deletions jscomp/core/js_cmj_load.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@

#if BS_BROWSER then
let load_unit_exn unit_name : Js_cmj_format.cmj_load_info =
match Builtin_cmj_datasets.query_by_name unit_name with
| Some v
match Ext_string_array.find_sorted_assoc
Builtin_cmj_datasets.module_sets
unit_name with
| Some cmj_table
->
{package_path = "BROWSER"; cmj_table = v}
let lazy cmj_table = cmj_table in
{package_path = "BROWSER"; cmj_table}
| None
->
Bs_exception.error (Cmj_not_found unit_name)
Expand Down
12 changes: 6 additions & 6 deletions jscomp/core/js_packages_info.mli
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ val runtime_package_path:
string ->
string

type package_info
=
{
module_system : module_system ;
path : string
}
type package_info = {
module_system : module_system ;
path : string
}

type t

val is_runtime_package:
t ->
bool



val same_package_by_name :
t ->
Expand Down
8 changes: 4 additions & 4 deletions jscomp/core/lam_arity_analysis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ let rec get_arity (meta : Lam_stats.t) (lam : Lam.t) : Lam_arity.t =
| Lvar v -> arity_of_var meta v
| Lconst _ -> Lam_arity.non_function_arity_info
| Llet(_,_,_, l ) -> get_arity meta l
| Lprim {primitive = Pfield (_, Fld_module {name = fld_name});
| Lprim {primitive = Pfield (_, Fld_module {name });
args = [ Lglobal_module id ]; _} ->
begin match (Lam_compile_env.query_external_id_info id fld_name).arity with
begin match (Lam_compile_env.query_external_id_info id name).arity with
| Single x -> x
| Submodule _ -> Lam_arity.na
end
| Lprim {primitive = Pfield (m,_);
args = [ Lprim{primitive = Pfield(n,Fld_module {name = fld_name});
args = [ Lprim{primitive = Pfield(_,Fld_module {name });
args = [ Lglobal_module id]} ]
; _} ->
begin match (Lam_compile_env.query_external_id_info id fld_name ).arity with
begin match (Lam_compile_env.query_external_id_info id name).arity with
| Submodule subs -> subs.(m) (* TODO: shall we store it as array?*)
| Single _ -> Lam_arity.na
end
Expand Down
10 changes: 6 additions & 4 deletions jscomp/core/lam_compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,14 @@ let rec
compile_external_field (* Like [List.empty]*)
(lamba_cxt : Lam_compile_context.t)
(id : Ident.t)
pos
name
: Js_output.t =
match Lam_compile_env.query_external_id_info id pos with
match Lam_compile_env.query_external_id_info id name with
| { persistent_closed_lambda = Some lam}
when Lam_util.not_function lam
->
compile_lambda lamba_cxt lam
| { name} ->
| _ ->
Js_output.output_of_expression lamba_cxt.continuation
~no_effects:no_effects_const
(E.ml_var_dot id name )
Expand Down Expand Up @@ -254,7 +254,9 @@ and compile_external_field_apply
E.call ~info:(call_info_of_ap_status ap_status) fn args
| App_na ->
match ident_info.arity with
| Submodule _ -> E.call ~info:Js_call_info.dummy fn args
| Submodule _
| Single Arity_na
-> E.call ~info:Js_call_info.dummy fn args
| Single x ->
apply_with_arity
fn ~arity:(Lam_arity.extract_arity x) args
Expand Down
53 changes: 26 additions & 27 deletions jscomp/core/lam_compile_env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -129,32 +129,31 @@ let query_external_id_info (module_id : Ident.t) (name : string) : ident_info =



let get_package_path_from_cmj
( id : Lam_module_ident.t)
let get_package_path_from_cmj ( id : Lam_module_ident.t)
=
match Lam_module_ident.Hash.find_opt cached_tbl id with
| Some (Ml {cmj_table ; package_path}) ->
(package_path,
Js_cmj_format.get_npm_package_path cmj_table,
Js_cmj_format.get_cmj_case cmj_table )
| Some External ->
assert false
(* called by {!Js_name_of_module_id.string_of_module_id}
let cmj_load_info =
match Lam_module_ident.Hash.find_opt cached_tbl id with
| Some (Ml cmj_load_info) -> cmj_load_info
| Some External ->
assert false
(* called by {!Js_name_of_module_id.string_of_module_id}
can not be External
*)
| None ->
begin match id.kind with
| Runtime
| External _ -> assert false
| Ml ->
let cmj_load_info =
Js_cmj_load.load_unit_exn (Lam_module_ident.name id) in
let cmj_table = cmj_load_info.cmj_table in
id +> Ml cmj_load_info;
(cmj_load_info.package_path,
Js_cmj_format.get_npm_package_path cmj_table,
Js_cmj_format.get_cmj_case cmj_table )
end
*)
| None ->
begin match id.kind with
| Runtime
| External _ -> assert false
| Ml ->
let cmj_load_info =
Js_cmj_load.load_unit_exn (Lam_module_ident.name id) in
id +> Ml cmj_load_info;
cmj_load_info

end in
let cmj_table = cmj_load_info.cmj_table in
(cmj_load_info.package_path,
cmj_table.package_spec,
cmj_table.js_file_kind)

let add = Lam_module_ident.Hash_set.add

Expand All @@ -172,11 +171,11 @@ let is_pure_module (oid : Lam_module_ident.t) =
match Js_cmj_load.load_unit_exn (Lam_module_ident.name oid) with
| cmj_load_info ->
oid +> Ml cmj_load_info ;
Js_cmj_format.is_pure cmj_load_info.cmj_table
cmj_load_info.cmj_table.pure
| exception _ -> false
end
| Some (Ml{cmj_table}(*|Runtime {cmj_table}*)) ->
Js_cmj_format.is_pure cmj_table
| Some (Ml{cmj_table}) ->
cmj_table.pure
| Some External -> false
end

Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/lam_compile_env.mli
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ val is_pure_module : Lam_module_ident.t -> bool

val get_package_path_from_cmj :
Lam_module_ident.t ->
(string * Js_packages_info.t * Js_cmj_format.cmj_case)
(string * Js_packages_info.t * Ext_js_file_kind.t)



Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/lam_compile_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
(* module E = Js_exp_make *)
(* module S = Js_stmt_make *)

let get_cmj_case output_prefix : Ext_namespace.file_kind =
let get_cmj_case output_prefix : Ext_js_file_kind.t =
let little =
Ext_char.is_lower_case (Filename.basename output_prefix).[0]
in
Expand Down
Loading