Skip to content

Commit 11cab11

Browse files
authored
Merge pull request #4160 from BuckleScript/loading_cmj
similar interface between loading cmi and cmj
2 parents d12998f + 7de866f commit 11cab11

File tree

10 files changed

+468
-455
lines changed

10 files changed

+468
-455
lines changed

jscomp/core/builtin_cmj_datasets.ml

Lines changed: 140 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,146 +1,146 @@
11

22
let i s = lazy (Marshal.from_string s 0)
33
let module_sets = [|
4-
"gc.cmj";
5-
"js.cmj";
6-
"oo.cmj";
7-
"arg.cmj";
8-
"dom.cmj";
9-
"map.cmj";
10-
"obj.cmj";
11-
"set.cmj";
12-
"sys.cmj";
13-
"belt.cmj";
14-
"char.cmj";
15-
"lazy.cmj";
16-
"list.cmj";
17-
"node.cmj";
18-
"sort.cmj";
19-
"unix.cmj";
20-
"weak.cmj";
21-
"array.cmj";
22-
"bytes.cmj";
23-
"int32.cmj";
24-
"int64.cmj";
25-
"js_re.cmj";
26-
"queue.cmj";
27-
"scanf.cmj";
28-
"stack.cmj";
29-
"uchar.cmj";
30-
"buffer.cmj";
31-
"digest.cmj";
32-
"format.cmj";
33-
"genlex.cmj";
34-
"js_exn.cmj";
35-
"js_int.cmj";
36-
"js_obj.cmj";
37-
"lexing.cmj";
38-
"printf.cmj";
39-
"random.cmj";
40-
"stream.cmj";
41-
"string.cmj";
42-
"belt_Id.cmj";
43-
"complex.cmj";
44-
"hashtbl.cmj";
45-
"js_cast.cmj";
46-
"js_date.cmj";
47-
"js_dict.cmj";
48-
"js_json.cmj";
49-
"js_list.cmj";
50-
"js_math.cmj";
51-
"js_null.cmj";
52-
"marshal.cmj";
53-
"node_fs.cmj";
54-
"parsing.cmj";
55-
"belt_Int.cmj";
56-
"belt_Map.cmj";
57-
"belt_Set.cmj";
58-
"bigarray.cmj";
59-
"callback.cmj";
60-
"filename.cmj";
61-
"js_array.cmj";
62-
"js_float.cmj";
63-
"js_types.cmj";
64-
"printexc.cmj";
65-
"std_exit.cmj";
66-
"belt_List.cmj";
67-
"ephemeron.cmj";
68-
"js_array2.cmj";
69-
"js_global.cmj";
70-
"js_option.cmj";
71-
"js_result.cmj";
72-
"js_string.cmj";
73-
"js_vector.cmj";
74-
"nativeint.cmj";
75-
"node_path.cmj";
76-
"spacetime.cmj";
77-
"stdLabels.cmj";
78-
"belt_Array.cmj";
79-
"belt_Debug.cmj";
80-
"belt_Float.cmj";
81-
"belt_Range.cmj";
82-
"js_console.cmj";
83-
"js_promise.cmj";
84-
"js_string2.cmj";
85-
"listLabels.cmj";
86-
"moreLabels.cmj";
87-
"pervasives.cmj";
88-
"unixLabels.cmj";
89-
"arrayLabels.cmj";
90-
"belt_MapInt.cmj";
91-
"belt_Option.cmj";
92-
"belt_Result.cmj";
93-
"belt_SetInt.cmj";
94-
"bytesLabels.cmj";
95-
"dom_storage.cmj";
96-
"js_mapperRt.cmj";
97-
"node_buffer.cmj";
98-
"node_module.cmj";
99-
"belt_HashMap.cmj";
100-
"belt_HashSet.cmj";
101-
"belt_MapDict.cmj";
102-
"belt_SetDict.cmj";
103-
"dom_storage2.cmj";
104-
"js_undefined.cmj";
105-
"node_process.cmj";
106-
"stringLabels.cmj";
107-
"js_internalOO.cmj";
108-
"belt_MapString.cmj";
109-
"belt_SetString.cmj";
110-
"belt_SortArray.cmj";
111-
"camlinternalOO.cmj";
112-
"js_typed_array.cmj";
113-
"belt_HashMapInt.cmj";
114-
"belt_HashSetInt.cmj";
115-
"belt_MutableMap.cmj";
116-
"belt_MutableSet.cmj";
117-
"camlinternalMod.cmj";
118-
"js_typed_array2.cmj";
119-
"camlinternalLazy.cmj";
120-
"belt_MutableQueue.cmj";
121-
"belt_MutableStack.cmj";
122-
"belt_SortArrayInt.cmj";
123-
"js_null_undefined.cmj";
124-
"belt_HashMapString.cmj";
125-
"belt_HashSetString.cmj";
126-
"belt_MutableMapInt.cmj";
127-
"belt_MutableSetInt.cmj";
128-
"camlinternalFormat.cmj";
129-
"node_child_process.cmj";
130-
"belt_internalAVLset.cmj";
131-
"belt_internalMapInt.cmj";
132-
"belt_internalSetInt.cmj";
133-
"belt_SortArrayString.cmj";
134-
"belt_internalAVLtree.cmj";
135-
"belt_internalBuckets.cmj";
136-
"camlinternalBigarray.cmj";
137-
"belt_MutableMapString.cmj";
138-
"belt_MutableSetString.cmj";
139-
"belt_internalMapString.cmj";
140-
"belt_internalSetString.cmj";
141-
"belt_internalSetBuckets.cmj";
142-
"belt_internalBucketsType.cmj";
143-
"camlinternalFormatBasics.cmj"
4+
"Gc";
5+
"Js";
6+
"Oo";
7+
"Arg";
8+
"Dom";
9+
"Map";
10+
"Obj";
11+
"Set";
12+
"Sys";
13+
"Belt";
14+
"Char";
15+
"Lazy";
16+
"List";
17+
"Node";
18+
"Sort";
19+
"Unix";
20+
"Weak";
21+
"Array";
22+
"Bytes";
23+
"Int32";
24+
"Int64";
25+
"Js_re";
26+
"Queue";
27+
"Scanf";
28+
"Stack";
29+
"Uchar";
30+
"Buffer";
31+
"Digest";
32+
"Format";
33+
"Genlex";
34+
"Js_exn";
35+
"Js_int";
36+
"Js_obj";
37+
"Lexing";
38+
"Printf";
39+
"Random";
40+
"Stream";
41+
"String";
42+
"Belt_Id";
43+
"Complex";
44+
"Hashtbl";
45+
"Js_cast";
46+
"Js_date";
47+
"Js_dict";
48+
"Js_json";
49+
"Js_list";
50+
"Js_math";
51+
"Js_null";
52+
"Marshal";
53+
"Node_fs";
54+
"Parsing";
55+
"Belt_Int";
56+
"Belt_Map";
57+
"Belt_Set";
58+
"Bigarray";
59+
"Callback";
60+
"Filename";
61+
"Js_array";
62+
"Js_float";
63+
"Js_types";
64+
"Printexc";
65+
"Std_exit";
66+
"Belt_List";
67+
"Ephemeron";
68+
"Js_array2";
69+
"Js_global";
70+
"Js_option";
71+
"Js_result";
72+
"Js_string";
73+
"Js_vector";
74+
"Nativeint";
75+
"Node_path";
76+
"Spacetime";
77+
"StdLabels";
78+
"Belt_Array";
79+
"Belt_Debug";
80+
"Belt_Float";
81+
"Belt_Range";
82+
"Js_console";
83+
"Js_promise";
84+
"Js_string2";
85+
"ListLabels";
86+
"MoreLabels";
87+
"Pervasives";
88+
"UnixLabels";
89+
"ArrayLabels";
90+
"Belt_MapInt";
91+
"Belt_Option";
92+
"Belt_Result";
93+
"Belt_SetInt";
94+
"BytesLabels";
95+
"Dom_storage";
96+
"Js_mapperRt";
97+
"Node_buffer";
98+
"Node_module";
99+
"Belt_HashMap";
100+
"Belt_HashSet";
101+
"Belt_MapDict";
102+
"Belt_SetDict";
103+
"Dom_storage2";
104+
"Js_undefined";
105+
"Node_process";
106+
"StringLabels";
107+
"Js_internalOO";
108+
"Belt_MapString";
109+
"Belt_SetString";
110+
"Belt_SortArray";
111+
"CamlinternalOO";
112+
"Js_typed_array";
113+
"Belt_HashMapInt";
114+
"Belt_HashSetInt";
115+
"Belt_MutableMap";
116+
"Belt_MutableSet";
117+
"CamlinternalMod";
118+
"Js_typed_array2";
119+
"CamlinternalLazy";
120+
"Belt_MutableQueue";
121+
"Belt_MutableStack";
122+
"Belt_SortArrayInt";
123+
"Js_null_undefined";
124+
"Belt_HashMapString";
125+
"Belt_HashSetString";
126+
"Belt_MutableMapInt";
127+
"Belt_MutableSetInt";
128+
"CamlinternalFormat";
129+
"Node_child_process";
130+
"Belt_internalAVLset";
131+
"Belt_internalMapInt";
132+
"Belt_internalSetInt";
133+
"Belt_SortArrayString";
134+
"Belt_internalAVLtree";
135+
"Belt_internalBuckets";
136+
"CamlinternalBigarray";
137+
"Belt_MutableMapString";
138+
"Belt_MutableSetString";
139+
"Belt_internalMapString";
140+
"Belt_internalSetString";
141+
"Belt_internalSetBuckets";
142+
"Belt_internalBucketsType";
143+
"CamlinternalFormatBasics"
144144
|]
145145
let module_sets_cmj : Js_cmj_format.t Lazy.t array = [|
146146
i "\132\149\166\190\000\000\001\227\000\000\000{\000\000\001\157\000\000\001\132\192\b\000\000(\000\176#get\144\160\160A@@@\176$stat\144\160\160A@@@\176(finalise\144\160\160B@@\144\180B\160\176\001\005+$prim@\160\176\001\005*\004\003@@\151\176\149\1763caml_final_registerB \160\144\004\012\160\144\004\011@\176\1920stdlib-406/gc.ml\001\000\136\001\018\028\001\018\028\192\004\002\001\000\136\001\018\028\001\018b@\176*print_stat\144\160\160A@@@\176*quick_stat\144\160\160A@@@\176,create_alarm\144\160\160A@@@\176,delete_alarm\144\160\160A@@\144\180A\160\176\001\005\015!a@@\151\176\163@\144(contents\160\144\004\t\160\146C@\176\192\004&\001\000\162\001\020t\001\020\137\192\004'\001\000\162\001\020t\001\020\147@\176-finalise_last\144\160\160B@@\144\180B\160\176\001\005\003%param@\160\176\001\005\002\004\003@@\146\168@\160\"()\160A@\176/allocated_bytes\144\160\160A@@@\1760finalise_release\144\160\160A@@\144\180A\160\176\001\005)\004U@@\151\176\149\1762caml_final_releaseA\004R\160\144\004\b@\176\192\004O\001\000\143\001\019\011\001\019\011\192\004P\001\000\143\001\019\011\001\019J@A\160A\160\160A'lib/es6\160\160@&lib/js@B";

jscomp/core/js_cmj_load.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@
3131

3232

3333
#if BS_BROWSER then
34-
let find_cmj_exn file : Js_cmj_format.cmj_load_info =
35-
let target = Ext_string.uncapitalize_ascii (Filename.basename file) in
36-
match Builtin_cmj_datasets.query_by_name target with
34+
let load_unit_exn unit_name : Js_cmj_format.cmj_load_info =
35+
match Builtin_cmj_datasets.query_by_name unit_name with
3736
| Some v
3837
->
3938
{package_path = "BROWSER"; cmj_table = v}
4039
| None
4140
->
42-
Bs_exception.error (Cmj_not_found file)
41+
Bs_exception.error (Cmj_not_found unit_name)
4342
#else
44-
let find_cmj_exn file : Js_cmj_format.cmj_load_info =
43+
let load_unit_exn unit_name : Js_cmj_format.cmj_load_info =
44+
let file = unit_name ^ Literals.suffix_cmj in
4545
match Config_util.find_opt file with
4646
| Some f
4747
->

jscomp/core/js_cmj_load.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@
3030

3131

3232
(** return path and meta data *)
33-
val find_cmj_exn :
33+
val load_unit_exn :
3434
string ->
3535
Js_cmj_format.cmj_load_info

jscomp/core/lam_compile_env.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ let query_external_id_info (module_id : Ident.t) (name : string) : ident_info =
110110
match Lam_module_ident.Hash.find_opt cached_tbl oid with
111111
| None ->
112112
let cmj_load_info =
113-
Js_cmj_load.find_cmj_exn (module_id.name ^ Literals.suffix_cmj) in
113+
Js_cmj_load.load_unit_exn module_id.name in
114114
oid +> Ml cmj_load_info ;
115115
cmj_load_info.cmj_table
116116
| Some (Ml { cmj_table } )
@@ -148,7 +148,7 @@ let get_package_path_from_cmj
148148
| External _ -> assert false
149149
| Ml ->
150150
let cmj_load_info =
151-
Js_cmj_load.find_cmj_exn (Lam_module_ident.name id ^ Literals.suffix_cmj) in
151+
Js_cmj_load.load_unit_exn (Lam_module_ident.name id) in
152152
let cmj_table = cmj_load_info.cmj_table in
153153
id +> Ml cmj_load_info;
154154
(cmj_load_info.package_path,
@@ -169,7 +169,7 @@ let is_pure_module (oid : Lam_module_ident.t) =
169169
begin match Lam_module_ident.Hash.find_opt cached_tbl oid with
170170
| None ->
171171
begin
172-
match Js_cmj_load.find_cmj_exn (Lam_module_ident.name oid ^ Literals.suffix_cmj) with
172+
match Js_cmj_load.load_unit_exn (Lam_module_ident.name oid) with
173173
| cmj_load_info ->
174174
oid +> Ml cmj_load_info ;
175175
Js_cmj_format.is_pure cmj_load_info.cmj_table

jscomp/core/lam_stats_export.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ let values_of_export
9999
match arity, persistent_closed_lambda with
100100
| Single Arity_na,
101101
(None | Some (Lconst (Const_pointer (_, Pt_module_alias)))) -> acc
102+
(* TODO: empty module can be saved too
103+
This is common since we have a module of externals quite common
104+
*)
102105
| _ ->
103106
let cmj_value : Js_cmj_format.cmj_value =
104107
{arity ; persistent_closed_lambda } in

jscomp/main/cmij_main.ml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ let get_files ext dir =
3737
(** the cache should be readable and also update *)
3838

3939
let from_cmj (files : string list) (output_file : string) =
40+
let cmp = Ext_filename.module_name in
4041
let files = List.sort (fun filea fileb ->
41-
Ext_string_array.cmp (Filename.basename filea) (Filename.basename fileb)) files in
42-
let keys = Ext_list.map files (fun x -> "\"" ^Filename.basename x ^ "\"") in
42+
Ext_string_array.cmp (cmp filea) (cmp fileb)) files in
43+
let keys = Ext_list.map files (fun x -> "\"" ^cmp x ^ "\"") in
4344
let v = open_out_bin output_file in
4445
Ext_pervasives.finally v ~clean:close_out (fun f ->
4546
output_string f {|
@@ -77,9 +78,10 @@ let from_cmj (files : string list) (output_file : string) =
7778

7879

7980
let from_cmi (files : string list) (output_file : string) =
81+
let cmp = Ext_filename.module_name in
8082
let files = List.sort (fun filea fileb ->
81-
Ext_string_array.cmp (Ext_filename.module_name filea) (Ext_filename.module_name fileb)) files in
82-
let keys = Ext_list.map files (fun x -> "\"" ^ Ext_filename.module_name x ^ "\"") in
83+
Ext_string_array.cmp (cmp filea) (cmp fileb)) files in
84+
let keys = Ext_list.map files (fun x -> "\"" ^ cmp x ^ "\"") in
8385
let v = open_out_bin output_file in
8486
Ext_pervasives.finally v ~clean:close_out (fun f ->
8587
output_string f {|

0 commit comments

Comments
 (0)