Skip to content

Commit 407d24b

Browse files
authored
Merge pull request #4158 from BuckleScript/experiment_in_memory_loading_cmi
in memory loading cmi/j for browser target
2 parents 0043bf6 + cb85c61 commit 407d24b

34 files changed

+380048
-99026
lines changed

jscomp/bin/reactjs_jsx_ppx_v2.bspp.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ let jsxMapper () =
332332
{ default_mapper with structure; expr }
333333
#end
334334

335-
#if BS_COMPILER_IN_BROWSER then
335+
#if BS_BROWSER then
336336

337337
module Js = struct
338338
module Unsafe = struct

jscomp/core/bs_cmi_load.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
3+
(* TODO: provide native load*)
4+
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 ->
7+
(* Format.fprintf Format.err_formatter "reading %s@." unit_name; *)
8+
Some {filename = Sys.executable_name ;
9+
cmi =
10+
Lazy.force Builtin_cmi_datasets.module_sets_cmi.(index)}
11+
| None -> assert false

jscomp/core/bs_conditional_initial.ml

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,12 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25-
25+
(* Clflags.keep_docs := false; *)
26+
(* default to false -check later*)
27+
(* Clflags.keep_locs := false; *)
2628
let setup_env () =
27-
#if 0 then
28-
let old_loader = !Env.Persistent_signature.load in
29-
Env.Persistent_signature.load := (fun ~unit_name ->
30-
match Ext_string_array.find_sorted Js_cmi_datasets.module_sets unit_name with
31-
| Some index ->
32-
Format.fprintf Format.err_formatter "reading %s@." unit_name;
33-
Some {filename = Sys.executable_name ; cmi =
34-
Lazy.force Js_cmi_datasets.module_sets_cmi.(index)}
35-
| None -> old_loader ~unit_name
36-
);
37-
Clflags.keep_locs := false;
38-
Clflags.keep_docs := false;
29+
#if BS_BROWSER then
30+
Env.Persistent_signature.load := Bs_cmi_load.browse_load;
3931
#end
4032
Warnings.parse_options false Bsc_warnings.defaults_w;
4133
Warnings.parse_options true Bsc_warnings.defaults_warn_error;

jscomp/core/builtin_cmi_datasets.ml

Lines changed: 369 additions & 0 deletions
Large diffs are not rendered by default.

jscomp/core/builtin_cmj_datasets.ml

Lines changed: 375 additions & 0 deletions
Large diffs are not rendered by default.

jscomp/core/js_cmj_datasets.ml

Lines changed: 0 additions & 185 deletions
This file was deleted.

jscomp/core/js_cmj_datasets.mli

Lines changed: 0 additions & 1 deletion
This file was deleted.

jscomp/core/js_cmj_format.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,10 @@ let pp_cmj
243243
k i
244244
(Format.asprintf "%a" Lam_arity.print arity ))
245245
xs
246-
)
246+
)
247+
248+
type path = string
249+
type cmj_load_info = {
250+
cmj_table : t ;
251+
cmj_path : path ;
252+
}

jscomp/core/js_cmj_format.mli

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,11 @@ val from_string : string -> t
108108
val to_file :
109109
string -> check_exists:bool -> t -> unit
110110

111-
val pp_cmj: t -> unit
111+
val pp_cmj: t -> unit
112+
113+
114+
type path = string
115+
type cmj_load_info = {
116+
cmj_table : t ;
117+
cmj_path : path ;
118+
}

jscomp/core/js_cmj_load.ml

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,20 @@
2828
*)
2929

3030

31-
type path = string
32-
type cmj_load_info = {
33-
cmj_table : Js_cmj_format.t ;
34-
cmj_path : path ;
35-
}
3631

37-
#if BS_COMPILER_IN_BROWSER then
38-
let find_cmj_exn file : cmj_load_info =
32+
33+
#if BS_BROWSER then
34+
let find_cmj_exn file : Js_cmj_format.cmj_load_info =
3935
let target = Ext_string.uncapitalize_ascii (Filename.basename file) in
40-
match Map_string.find_exn !Js_cmj_datasets.data_sets target with
41-
| v
36+
match Builtin_cmj_datasets.query_by_name target with
37+
| Some v
4238
->
43-
begin match Lazy.force v with
44-
| exception _
45-
->
46-
Ext_log.warn __LOC__
47-
"@[%s corrupted in database, when looking %s while compiling %s please update @]" file target !Location.input_name ;
48-
Bs_exception.error (Cmj_not_found file)
49-
| v -> {cmj_path = "BROWSER"; cmj_table = v}
50-
(* see {!Js_packages_info.string_of_module_id} *)
51-
end
52-
| exception Not_found
39+
{cmj_path = "BROWSER"; cmj_table = v}
40+
| None
5341
->
5442
Bs_exception.error (Cmj_not_found file)
5543
#else
56-
let find_cmj_exn file : cmj_load_info =
44+
let find_cmj_exn file : Js_cmj_format.cmj_load_info =
5745
match Config_util.find_opt file with
5846
| Some f
5947
->

0 commit comments

Comments
 (0)