Skip to content

Commit e10b252

Browse files
committed
continue shrinking the size of cmj
1 parent 213c50f commit e10b252

13 files changed

+340
-388
lines changed

jscomp/core/builtin_cmi_datasets.ml

-18
Large diffs are not rendered by default.

jscomp/core/builtin_cmj_datasets.ml

+53-53
Large diffs are not rendered by default.

jscomp/core/js_cmj_format.ml

+14-13
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ type t = {
5656
cmj_case : cmj_case;
5757
}
5858

59-
let mk ~(values:cmj_value Map_string.t) ~effect ~npm_package_path ~cmj_case : t =
59+
let make ~(values:cmj_value Map_string.t) ~effect ~npm_package_path ~cmj_case : t =
6060
{
6161
values = Map_string.to_sorted_array_with_f values (fun k v -> {
6262
name = k ;
@@ -130,13 +130,14 @@ let to_file name ~check_exists (v : t) =
130130
let keyComp (a : string) b =
131131
Map_string.compare_key a b.name
132132

133-
let not_found = single_na, None
133+
let not_found key = {name = key; arity = single_na; persistent_closed_lambda = None }
134134

135-
let get_result midVal =
136-
midVal.arity,
137-
if Js_config.get_cross_module_inline () then midVal.persistent_closed_lambda
138-
else None
139135

136+
let get_result midVal =
137+
if midVal.persistent_closed_lambda = None ||
138+
Js_config.get_cross_module_inline () then midVal
139+
else {midVal with persistent_closed_lambda = None}
140+
140141
let rec binarySearchAux arr lo hi (key : string) =
141142
let mid = (lo + hi)/2 in
142143
let midVal = Array.unsafe_get arr mid in
@@ -147,33 +148,33 @@ let rec binarySearchAux arr lo hi (key : string) =
147148
if hi = mid then
148149
let loVal = (Array.unsafe_get arr lo) in
149150
if loVal.name = key then get_result loVal
150-
else not_found
151+
else not_found key
151152
else binarySearchAux arr lo mid key
152153
else (* a[lo] =< a[mid] < key <= a[hi] *)
153154
if lo = mid then
154155
let hiVal = (Array.unsafe_get arr hi) in
155156
if hiVal.name = key then get_result hiVal
156-
else not_found
157+
else not_found key
157158
else binarySearchAux arr mid hi key
158159

159-
let binarySearch (sorted : keyed_cmj_values) (key : string) =
160+
let binarySearch (sorted : keyed_cmj_values) (key : string) : keyed_cmj_value =
160161
let len = Array.length sorted in
161-
if len = 0 then not_found
162+
if len = 0 then not_found key
162163
else
163164
let lo = Array.unsafe_get sorted 0 in
164165
let c = keyComp key lo in
165-
if c < 0 then not_found
166+
if c < 0 then not_found key
166167
else
167168
let hi = Array.unsafe_get sorted (len - 1) in
168169
let c2 = keyComp key hi in
169-
if c2 > 0 then not_found
170+
if c2 > 0 then not_found key
170171
else binarySearchAux sorted 0 (len - 1) key
171172

172173

173174
(* FIXME: better error message when ocamldep
174175
get self-cycle
175176
*)
176-
let query_by_name (cmj_table : t ) name =
177+
let query_by_name (cmj_table : t ) name : keyed_cmj_value =
177178
let values = cmj_table.values in
178179
binarySearch values name
179180

jscomp/core/js_cmj_format.mli

+7-3
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,21 @@ type cmj_case = Ext_namespace.file_kind
6969
type t
7070

7171

72-
val mk:
72+
val make:
7373
values: cmj_value Map_string.t ->
7474
effect: effect ->
7575
npm_package_path: Js_packages_info.t ->
7676
cmj_case:cmj_case ->
7777
t
78-
78+
79+
type keyed_cmj_value =
80+
{ name : string ;
81+
arity : arity ;
82+
persistent_closed_lambda : Lam.t option}
7983
val query_by_name :
8084
t ->
8185
string ->
82-
arity * Lam.t option
86+
keyed_cmj_value
8387

8488
val is_pure :
8589
t -> bool

jscomp/core/lam_compile.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ let rec
180180
pos
181181
: Js_output.t =
182182
match Lam_compile_env.query_external_id_info id pos with
183-
| { closed_lambda = Some lam}
183+
| { persistent_closed_lambda = Some lam}
184184
when Lam_util.not_function lam
185185
->
186186
compile_lambda lamba_cxt lam
@@ -225,7 +225,7 @@ and compile_external_field_apply
225225
let ident_info =
226226
Lam_compile_env.query_external_id_info module_id field_name in
227227
let ap_args = appinfo.ap_args in
228-
match ident_info.closed_lambda with
228+
match ident_info.persistent_closed_lambda with
229229
| Some (Lfunction{ params; body; _})
230230
when Ext_list.same_length params ap_args ->
231231
(* TODO: serialize it when exporting to save compile time *)

jscomp/core/lam_compile_env.ml

+5-12
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ type env_value =
4141

4242

4343

44-
type ident_info = {
44+
type ident_info = Js_cmj_format.keyed_cmj_value = {
4545
name : string;
4646
arity : Js_cmj_format.arity;
47-
closed_lambda : Lam.t option
47+
persistent_closed_lambda : Lam.t option
4848
}
4949

5050
(*
@@ -115,16 +115,9 @@ let query_external_id_info (module_id : Ident.t) (name : string) : ident_info =
115115
cmj_load_info.cmj_table
116116
| Some (Ml { cmj_table } )
117117
-> cmj_table
118-
| Some External -> assert false in
119-
let arity , closed_lambda =
120-
Js_cmj_format.query_by_name cmj_table name
121-
in
122-
{
123-
name;
124-
arity;
125-
closed_lambda
126-
(* TODO shall we cache the arity ?*)
127-
}
118+
| Some External -> assert false in
119+
Js_cmj_format.query_by_name cmj_table name
120+
128121

129122

130123

jscomp/core/lam_compile_env.mli

+2-6
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@
3030

3131

3232

33-
type ident_info = {
34-
name : string;
35-
arity : Js_cmj_format.arity;
36-
closed_lambda : Lam.t option
37-
}
33+
3834

3935

4036

@@ -81,7 +77,7 @@ val add_js_module :
8177
val query_external_id_info :
8278
Ident.t ->
8379
string ->
84-
ident_info
80+
Js_cmj_format.keyed_cmj_value
8581

8682

8783
val is_pure_module : Lam_module_ident.t -> bool

jscomp/core/lam_pass_remove_alias.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ let simplify_alias
121121
ap_args = args; ap_loc = loc ; ap_status = status} ->
122122
begin
123123
match Lam_compile_env.query_external_id_info ident fld_name with
124-
| {closed_lambda=Some Lfunction{params; body; _} }
124+
| {persistent_closed_lambda=Some Lfunction{params; body; _} }
125125
(** be more cautious when do cross module inlining *)
126126
when
127127
Ext_list.same_length params args &&

jscomp/core/lam_stats_export.ml

+8-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,13 @@ let values_of_export
9696
else
9797
None
9898
| None -> None in
99-
Map_string.add acc x.name Js_cmj_format.{arity ; persistent_closed_lambda }
99+
match arity, persistent_closed_lambda with
100+
| Single Arity_na,
101+
(None | Some (Lconst (Const_pointer (_, Pt_module_alias)))) -> acc
102+
| _ ->
103+
let cmj_value : Js_cmj_format.cmj_value =
104+
{arity ; persistent_closed_lambda } in
105+
Map_string.add acc x.name cmj_value
100106
)
101107

102108
(* ATTENTION: all runtime modules, if it is not hard required,
@@ -136,7 +142,7 @@ let export_to_cmj
136142
: Js_cmj_format.t =
137143
let values = values_of_export meta export_map in
138144

139-
Js_cmj_format.mk
145+
Js_cmj_format.make
140146
~values
141147
~effect
142148
~npm_package_path: (Js_packages_state.get_packages_info ())

jscomp/main/cmij_main.ml

+23-17
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,11 @@
2828

2929

3030
let get_files ext dir =
31-
let arr =
32-
Ext_array.filter_map (Sys.readdir dir)
33-
(fun x ->
34-
if Ext_string.ends_with x ext
35-
then Some (Filename.concat dir x) else None )
36-
in
37-
(* Sort to guarantee it works the same across OSes *)
38-
Array.sort (fun (x : string) y -> Pervasives.compare x y ) arr;
39-
Array.to_list arr
31+
Ext_array.filter_map (Sys.readdir dir)
32+
(fun x ->
33+
if Ext_string.ends_with x ext
34+
then Some (Filename.concat dir x) else None )
35+
|> Array.to_list
4036

4137
(** the cache should be readable and also update *)
4238

@@ -113,16 +109,26 @@ let i s = lazy (Marshal.from_string s 0)
113109
;;
114110

115111
let stdlib = "stdlib-406"
112+
let (//) = Filename.concat
113+
let (|~) = Ext_string.contain_substring
116114

117115
let () =
118-
from_cmj (
119-
Filename.concat "runtime" "js.cmj" ::
120-
get_files Literals.suffix_cmj stdlib @
121-
get_files Literals.suffix_cmj "others")
116+
let cmj_files =
117+
(
118+
"runtime" // "js.cmj" ::
119+
get_files Literals.suffix_cmj stdlib @
120+
get_files Literals.suffix_cmj "others") in
121+
from_cmj cmj_files
122122
(Filename.concat "core" "builtin_cmj_datasets.ml");
123-
from_cmi (
124-
Filename.concat "runtime" "js.cmi" ::
125-
get_files Literals.suffix_cmi stdlib @
126-
get_files Literals.suffix_cmi "others")
123+
let cmi_files =
124+
"runtime" // "js.cmi" ::
125+
(get_files Literals.suffix_cmi stdlib @
126+
get_files Literals.suffix_cmi "others" )
127+
|> List.filter (fun x ->
128+
x|~ "js_internalOO" ||
129+
x|~ "camlinternal" ||
130+
not (x |~ "internal"))
131+
in
132+
from_cmi cmi_files
127133
(Filename.concat "core" "builtin_cmi_datasets.ml")
128134

0 commit comments

Comments
 (0)