Skip to content

Commit ba83ce9

Browse files
authored
Merge pull request #4161 from BuckleScript/loading_cmj
[refactor] meaningful names & save cmj size further
2 parents 11cab11 + a6ee05d commit ba83ce9

39 files changed

+3843
-4530
lines changed

jscomp/core/bs_cmi_load.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
(* TODO: provide native load*)
44
let browse_load ~unit_name : Env.Persistent_signature.t option=
5-
match Ext_string_array.find_sorted Builtin_cmi_datasets.module_sets unit_name with
6-
| Some index ->
5+
match Ext_string_array.find_sorted_assoc Builtin_cmi_datasets.module_sets_cmi unit_name with
6+
| Some cmi ->
77
(* Format.fprintf Format.err_formatter "reading %s@." unit_name; *)
88
Some {filename = Sys.executable_name ;
99
cmi =
10-
Lazy.force Builtin_cmi_datasets.module_sets_cmi.(index)}
10+
Lazy.force cmi}
1111
| None -> assert false

jscomp/core/builtin_cmi_datasets.ml

Lines changed: 135 additions & 268 deletions
Large diffs are not rendered by default.

jscomp/core/builtin_cmi_datasets.mli

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11

22

33

4-
(* TODO: we can hide some
5-
more internal units
6-
*)
7-
val module_sets : string array
8-
val module_sets_cmi : Cmi_format.cmi_infos Lazy.t array
4+
5+
val module_sets_cmi :
6+
(string * Cmi_format.cmi_infos Lazy.t) array

jscomp/core/builtin_cmj_datasets.ml

Lines changed: 142 additions & 292 deletions
Large diffs are not rendered by default.

jscomp/core/builtin_cmj_datasets.mli

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
val module_sets : string array
2-
val module_sets_cmj : Js_cmj_format.t Lazy.t array
3-
val query_by_name : string -> Js_cmj_format.t option
1+
2+
3+
val module_sets :
4+
(string * Js_cmj_format.t Lazy.t ) array

jscomp/core/js_cmj_format.ml

Lines changed: 8 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ type effect = string option
4242

4343

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

4846
type keyed_cmj_value = { name : string ; arity : arity ; persistent_closed_lambda : Lam.t option}
4947
type keyed_cmj_values
@@ -52,20 +50,20 @@ type keyed_cmj_values
5250
type t = {
5351
values : keyed_cmj_values ;
5452
pure : bool;
55-
npm_package_path : Js_packages_info.t ;
56-
cmj_case : cmj_case;
53+
package_spec : Js_packages_info.t ;
54+
js_file_kind : Ext_js_file_kind.t;
5755
}
5856

59-
let make ~(values:cmj_value Map_string.t) ~effect ~npm_package_path ~cmj_case : t =
57+
let make ~(values:cmj_value Map_string.t) ~effect ~package_spec ~js_file_kind : t =
6058
{
6159
values = Map_string.to_sorted_array_with_f values (fun k v -> {
6260
name = k ;
6361
arity = v.arity;
6462
persistent_closed_lambda = v.persistent_closed_lambda
6563
});
6664
pure = effect = None ;
67-
npm_package_path;
68-
cmj_case
65+
package_spec;
66+
js_file_kind
6967
}
7068

7169

@@ -178,70 +176,9 @@ let query_by_name (cmj_table : t ) name : keyed_cmj_value =
178176
let values = cmj_table.values in
179177
binarySearch values name
180178

181-
let is_pure (cmj_table : t ) =
182-
cmj_table.pure
183-
184-
let get_npm_package_path (cmj_table : t) =
185-
cmj_table.npm_package_path
186-
187-
let get_cmj_case (cmj_table : t) =
188-
cmj_table.cmj_case
189-
190-
191-
(* start dumping *)
192-
193-
let f fmt = Printf.fprintf stdout fmt
194-
195-
let pp_cmj_case (cmj_case : cmj_case) : unit =
196-
match cmj_case with
197-
| Little_js ->
198-
f "case : little, .js \n"
199-
| Little_bs ->
200-
f "case : little, .bs.js \n"
201-
| Upper_js ->
202-
f "case: upper, .js \n"
203-
| Upper_bs ->
204-
f "case: upper, .bs.js \n"
205-
206-
let pp_cmj
207-
({ values ; pure; npm_package_path ; cmj_case} : t) =
208-
f "package info: %s\n"
209-
(Format.asprintf "%a" Js_packages_info.dump_packages_info npm_package_path)
210-
;
211-
pp_cmj_case cmj_case;
212-
213-
f "effect: %s\n"
214-
(if pure then "pure" else "not pure");
215-
Ext_array.iter values
216-
(fun ({name = k ; arity; persistent_closed_lambda}) ->
217-
match arity with
218-
| Single arity ->
219-
f "%s: %s\n" k (Format.asprintf "%a" Lam_arity.print arity);
220-
(match persistent_closed_lambda with
221-
| None ->
222-
f "%s: not saved\n" k
223-
| Some lam ->
224-
begin
225-
f "%s: ======[start]\n" k ;
226-
f "%s\n" (Lam_print.lambda_to_string lam);
227-
f "%s: ======[finish]\n" k
228-
end )
229-
| Submodule xs ->
230-
(match persistent_closed_lambda with
231-
| None -> f "%s: not saved\n" k
232-
| Some lam ->
233-
begin
234-
f "%s: ======[start]\n" k ;
235-
f "%s" (Lam_print.lambda_to_string lam);
236-
f "%s: ======[finish]\n" k
237-
end
238-
);
239-
Array.iteri
240-
(fun i arity -> f "%s[%i] : %s \n"
241-
k i
242-
(Format.asprintf "%a" Lam_arity.print arity ))
243-
xs
244-
)
179+
180+
181+
245182

246183
type path = string
247184
type cmj_load_info = {

jscomp/core/js_cmj_format.mli

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,37 +64,34 @@ type cmj_value = {
6464

6565
type effect = string option
6666

67-
type cmj_case = Ext_namespace.file_kind
67+
type keyed_cmj_value = {
68+
name : string ;
69+
arity : arity ;
70+
persistent_closed_lambda : Lam.t option
71+
}
6872

69-
type t
73+
type t = private {
74+
values : keyed_cmj_value array ;
75+
pure : bool;
76+
package_spec : Js_packages_info.t ;
77+
js_file_kind : Ext_js_file_kind.t;
78+
}
7079

7180

7281
val make:
7382
values: cmj_value Map_string.t ->
7483
effect: effect ->
75-
npm_package_path: Js_packages_info.t ->
76-
cmj_case:cmj_case ->
84+
package_spec: Js_packages_info.t ->
85+
js_file_kind:Ext_js_file_kind.t ->
7786
t
7887

79-
type keyed_cmj_value =
80-
{ name : string ;
81-
arity : arity ;
82-
persistent_closed_lambda : Lam.t option}
88+
8389
val query_by_name :
8490
t ->
8591
string ->
8692
keyed_cmj_value
8793

88-
val is_pure :
89-
t -> bool
9094

91-
val get_npm_package_path :
92-
t ->
93-
Js_packages_info.t
94-
95-
val get_cmj_case :
96-
t ->
97-
cmj_case
9895

9996
val single_na : arity
10097

@@ -107,12 +104,13 @@ val from_file_with_digest :
107104

108105
val from_string : string -> t
109106

110-
(* Note writing the file if its content is not chnaged
107+
(*
108+
Note writing the file if its content is not changed
111109
*)
112110
val to_file :
113111
string -> check_exists:bool -> t -> unit
114112

115-
val pp_cmj: t -> unit
113+
116114

117115

118116
type path = string

jscomp/core/js_cmj_load.ml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@
3232

3333
#if BS_BROWSER then
3434
let load_unit_exn unit_name : Js_cmj_format.cmj_load_info =
35-
match Builtin_cmj_datasets.query_by_name unit_name with
36-
| Some v
35+
match Ext_string_array.find_sorted_assoc
36+
Builtin_cmj_datasets.module_sets
37+
unit_name with
38+
| Some cmj_table
3739
->
38-
{package_path = "BROWSER"; cmj_table = v}
40+
let lazy cmj_table = cmj_table in
41+
{package_path = "BROWSER"; cmj_table}
3942
| None
4043
->
4144
Bs_exception.error (Cmj_not_found unit_name)

jscomp/core/js_packages_info.mli

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,18 @@ val runtime_package_path:
3838
string ->
3939
string
4040

41-
type package_info
42-
=
43-
{
44-
module_system : module_system ;
45-
path : string
46-
}
41+
type package_info = {
42+
module_system : module_system ;
43+
path : string
44+
}
4745

4846
type t
4947

5048
val is_runtime_package:
5149
t ->
5250
bool
51+
52+
5353

5454
val same_package_by_name :
5555
t ->

jscomp/core/lam_arity_analysis.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@ let rec get_arity (meta : Lam_stats.t) (lam : Lam.t) : Lam_arity.t =
4444
| Lvar v -> arity_of_var meta v
4545
| Lconst _ -> Lam_arity.non_function_arity_info
4646
| Llet(_,_,_, l ) -> get_arity meta l
47-
| Lprim {primitive = Pfield (_, Fld_module {name = fld_name});
47+
| Lprim {primitive = Pfield (_, Fld_module {name });
4848
args = [ Lglobal_module id ]; _} ->
49-
begin match (Lam_compile_env.query_external_id_info id fld_name).arity with
49+
begin match (Lam_compile_env.query_external_id_info id name).arity with
5050
| Single x -> x
5151
| Submodule _ -> Lam_arity.na
5252
end
5353
| Lprim {primitive = Pfield (m,_);
54-
args = [ Lprim{primitive = Pfield(n,Fld_module {name = fld_name});
54+
args = [ Lprim{primitive = Pfield(_,Fld_module {name });
5555
args = [ Lglobal_module id]} ]
5656
; _} ->
57-
begin match (Lam_compile_env.query_external_id_info id fld_name ).arity with
57+
begin match (Lam_compile_env.query_external_id_info id name).arity with
5858
| Submodule subs -> subs.(m) (* TODO: shall we store it as array?*)
5959
| Single _ -> Lam_arity.na
6060
end

0 commit comments

Comments
 (0)