Skip to content

Commit de88fbf

Browse files
committed
[refact] clean up the dependency, make sure runtime will not read files from stdlib (#351)
* [refact] clean up the dependency, make sure runtime will not read files from stdlib * [refact] prepare npm_package path slot
1 parent b4449d1 commit de88fbf

27 files changed

+9365
-151
lines changed

jscomp/Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ lam_fold.ml: lambda_fold.mlp lambda.mlp
2222

2323
./bin/bsc: _build/compiler.cmxa
2424
echo "Linking"
25-
$(NATIVE) -g -linkall -o $@ -I +compiler-libs ocamlcommon.cmxa ocamlbytecomp.cmxa $^ 2>>build.compile
25+
$(NATIVE) -g -linkall -o $@ -I +compiler-libs ocamlcommon.cmxa $^ 2>>build.compile
2626
# Note: we can remove main.cmx since we have js_main.cmx which use [js_implementation.implementation],
2727
# The motivation is to save compilation time and in the future, more freedom to add new
2828
# compilation flags (since we don't need bytecode anymore)
@@ -50,7 +50,7 @@ snapshotcmj:
5050

5151
releasebuild:
5252
@echo "Make release compiler"
53-
$(NATIVE) -g -inline 100 -linkall -w -a -I +compiler-libs -I bin ocamlcommon.cmxa ocamlbytecomp.cmxa bin/compiler.mli bin/compiler.ml -o bin/bsc
53+
$(NATIVE) -g -inline 100 -linkall -w -a -I +compiler-libs -I bin ocamlcommon.cmxa bin/compiler.mli bin/compiler.ml -o bin/bsc
5454

5555
stdlib:
5656
cd stdlib && ./build.sh
@@ -102,7 +102,7 @@ big-world:bin/big_compiler.ml bin/big_compiler.mli
102102

103103
world-test:
104104
@echo "Making compiler"
105-
ocamlopt.opt -g -inline 100 -w -a -linkall -I +compiler-libs -I bin ocamlcommon.cmxa ocamlbytecomp.cmxa bin/compiler.mli bin/compiler.ml -o bin/bsc
105+
ocamlopt.opt -g -inline 100 -w -a -linkall -I +compiler-libs -I bin ocamlcommon.cmxa bin/compiler.mli bin/compiler.ml -o bin/bsc
106106
@echo "Making compiler finished"
107107

108108
@echo "Making runtime"

jscomp/config_util.ml

+21-19
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,31 @@ let find file = Misc.find_in_path_uncap !Config.load_path file
4040
make sure that the distributed files are platform independent
4141
*)
4242
let find_cmj file =
43-
begin match find file with
43+
match find file with
4444
| f
4545
->
4646
Js_cmj_format.from_file f
4747
| exception Not_found ->
48-
(* TODO: add an logger module *)
49-
let target = String.uncapitalize (Filename.basename file) in
50-
begin match
48+
(* ONLY read the stored cmj data in browser environment *)
49+
if Js_config.get_env () = Browser then
50+
let target = String.uncapitalize (Filename.basename file) in
51+
match
5152
String_map.find target
5253
Js_cmj_datasets.cmj_data_sets with
53-
| v
54-
->
55-
begin match Lazy.force v with
56-
| exception _
54+
| v
5755
->
58-
Ext_log.warn __LOC__
59-
"@[%s corrupted in database, when looking %s while compiling %s please update @]" file target (Lam_current_unit.get_file ()) ;
60-
Js_cmj_format.no_pure_dummy; (* FIXME *)
61-
| v -> v
62-
end
63-
| exception Not_found
64-
->
65-
Ext_log.warn __LOC__ "@[%s not found @]" file ;
66-
Js_cmj_format.no_pure_dummy (* FIXME *)
67-
end
68-
end
56+
begin match Lazy.force v with
57+
| exception _
58+
->
59+
Ext_log.warn __LOC__
60+
"@[%s corrupted in database, when looking %s while compiling %s please update @]" file target (Lam_current_unit.get_file ()) ;
61+
Js_cmj_format.no_pure_dummy; (* FIXME *)
62+
| v -> v
63+
end
64+
| exception Not_found
65+
->
66+
Ext_log.warn __LOC__ "@[%s not found @]" file ;
67+
Js_cmj_format.no_pure_dummy
68+
else
69+
Ext_pervasives.failwithf "@[in %s, %s not found @]" __LOC__ file
70+

jscomp/config_util.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ val find : string -> string
3838
(** [find filename] Input is a file name, output is absolute path *)
3939

4040

41-
val find_cmj : string -> Js_cmj_format.cmj_table
41+
val find_cmj : string -> Js_cmj_format.t

jscomp/js_cmj_datasets.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
val cmj_data_sets : Js_cmj_format.cmj_table Lazy.t String_map.t
1+
val cmj_data_sets : Js_cmj_format.t Lazy.t String_map.t

jscomp/js_cmj_format.ml

+11-8
Original file line numberDiff line numberDiff line change
@@ -38,46 +38,49 @@ type cmj_value = {
3838

3939
type effect = string option
4040

41-
type cmj_table = {
41+
type t = {
4242
values : cmj_value String_map.t;
4343
effect : effect;
4444
goog_package : string option;
45+
npm_package_path : string option ;
4546
}
4647

47-
let cmj_magic_number = "BUCKLE20160310"
48+
let cmj_magic_number = "BUCKLE20160506"
4849
let cmj_magic_number_length =
4950
String.length cmj_magic_number
5051

5152
let pure_dummy =
5253
{
5354
values = String_map.empty;
5455
effect = None;
55-
goog_package = None
56+
goog_package = None;
57+
npm_package_path = None;
5658
}
5759

5860
let no_pure_dummy =
5961
{
6062
values = String_map.empty;
6163
effect = (Some "");
62-
goog_package = None
64+
goog_package = None;
65+
npm_package_path = None;
6366
}
6467

6568

6669

67-
let from_file name : cmj_table =
70+
let from_file name : t =
6871
let ic = open_in_bin name in
6972
let buffer = really_input_string ic cmj_magic_number_length in
7073
if buffer <> cmj_magic_number then
7174
failwith
7275
("cmj files have incompatible versions, please rebuilt using the new compiler : "
7376
^ __LOC__)
7477
else
75-
let v : cmj_table = input_value ic in
78+
let v : t = input_value ic in
7679
close_in ic ;
7780
v
7881

7982

80-
let from_string s : cmj_table =
83+
let from_string s : t =
8184
let magic_number = String.sub s 0 cmj_magic_number_length in
8285
if magic_number = cmj_magic_number then
8386
Marshal.from_string s cmj_magic_number_length
@@ -86,7 +89,7 @@ let from_string s : cmj_table =
8689
("cmj files have incompatible versions, please rebuilt using the new compiler : "
8790
^ __LOC__)
8891

89-
let to_file name (v : cmj_table) =
92+
let to_file name (v : t) =
9093
let oc = open_out_bin name in
9194
output_string oc cmj_magic_number;
9295
output_value oc v;

jscomp/js_cmj_format.mli

+8-7
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,18 @@ type cmj_value = {
6060

6161
type effect = string option
6262

63-
type cmj_table = {
63+
type t = {
6464
values : cmj_value String_map.t;
6565
effect : effect;
66-
goog_package : string option
66+
goog_package : string option;
67+
npm_package_path : string option;
6768
}
6869

69-
val pure_dummy : cmj_table
70-
val no_pure_dummy : cmj_table
70+
val pure_dummy : t
71+
val no_pure_dummy : t
7172

7273

73-
val from_file : string -> cmj_table
74-
val from_string : string -> cmj_table
74+
val from_file : string -> t
75+
val from_string : string -> t
7576

76-
val to_file : string -> cmj_table -> unit
77+
val to_file : string -> t -> unit

jscomp/js_config.ml

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ let get_goog_package_name () =
7474
| AmdJS
7575
| NodeJS -> None
7676

77+
let get_npm_package_path () = None
78+
7779
let default_gen_tds = ref false
7880

7981
let stdlib_set = String_set.of_list [

jscomp/js_config.mli

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ val get_env : unit -> env
3737
val get_ext : unit -> string
3838

3939
val get_goog_package_name : unit -> string option
40+
val get_npm_package_path : unit -> string option
41+
4042
val set_env : env -> unit
4143
val cmd_set_module : string -> unit
4244
val default_gen_tds : bool ref

jscomp/lam_compile_env.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type module_id = Lam_module_ident.t
3636

3737
type ml_module_info = {
3838
signatures : Types.signature ;
39-
cmj_table : Js_cmj_format.cmj_table
39+
cmj_table : Js_cmj_format.t
4040
}
4141

4242
type env_value =
@@ -141,7 +141,7 @@ let find_and_add_if_not_exist (id, pos) env ~not_found ~found =
141141
[Runtime]
142142
and [externals]*)
143143
type _ t =
144-
| No_env : Js_cmj_format.cmj_table t
144+
| No_env : Js_cmj_format.t t
145145
| Has_env : Env.t -> module_info t
146146

147147

jscomp/lam_compile_env.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type module_info = {
5757
}
5858

5959
type _ t =
60-
| No_env : Js_cmj_format.cmj_table t
60+
| No_env : Js_cmj_format.t t
6161
| Has_env : Env.t -> module_info t
6262

6363
val find_and_add_if_not_exist :

jscomp/lam_stats_export.ml

+6-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ let export_to_cmj
7171
external_ids
7272
export_map
7373

74-
: Js_cmj_format.cmj_table =
74+
: Js_cmj_format.t =
7575
let values =
7676

7777
List.fold_left
@@ -157,5 +157,9 @@ let export_to_cmj
157157
| Some _ -> maybe_pure
158158

159159
in
160-
{values; effect ; goog_package = Js_config.get_goog_package_name ()}
160+
{values;
161+
effect ;
162+
goog_package = Js_config.get_goog_package_name ();
163+
npm_package_path = Js_config.get_npm_package_path ();
164+
}
161165

jscomp/lam_stats_export.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ val export_to_cmj :
3131
Lam_stats.meta ->
3232
Js_cmj_format.effect ->
3333
Lam_module_ident.t list ->
34-
Lambda.lambda Ident_map.t -> Js_cmj_format.cmj_table
34+
Lambda.lambda Ident_map.t -> Js_cmj_format.t
3535

jscomp/lib/.libdepend

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
bench.cmo : js.cmo
2-
bench.cmj : js.cmj
3-
fn.cmo :
41
fn.cmj :
5-
js.cmo :
6-
js.cmj :
7-
js_date.cmo :
8-
js_date.cmj :
9-
js_intf.cmo :
10-
js_intf.cmj :
2+
fn.cmx :
3+
js.cmj : ../stdlib/obj.cmi
4+
js.cmx : ../stdlib/obj.cmx

jscomp/lib/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ clean::
3030
-include .libdepend
3131

3232
depend:
33-
$(CAMLDEP) $(INCLUDES) *.mli *.ml | sed -e 's/\.cmx/.cmj/g' > .libdepend
34-
33+
$(CAMLDEP) $(INCLUDES) *.mli *.ml | sed -e 's/\.cmo/.cmj/g' > .libdepend
34+
$(CAMLDEP) $(INCLUDES) *.ml | sed -e 's/\.cmx/.cmj/g' >>.runtimedepend

jscomp/runtime/.runtimedepend

+31-31
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
block.cmi :
22
caml_array.cmi :
33
caml_backtrace.cmi :
4-
caml_basic.cmi : js.cmo
4+
caml_basic.cmi : js.cmj
55
caml_builtin_exceptions.cmi :
66
caml_exceptions.cmi : caml_builtin_exceptions.cmi
77
caml_float.cmi :
@@ -21,64 +21,64 @@ caml_string.cmi :
2121
caml_sys.cmi :
2222
caml_utils.cmi :
2323
caml_weak.cmi :
24-
js_primitive.cmi : js.cmo
25-
block.cmo : block.cmi
24+
js_primitive.cmi : js.cmj
25+
block.cmj : block.cmi
2626
block.cmx : block.cmi
27-
caml_array.cmo : js.cmo caml_array.cmi
27+
caml_array.cmj : js.cmj caml_array.cmi
2828
caml_array.cmx : js.cmx caml_array.cmi
29-
caml_backtrace.cmo : caml_backtrace.cmi
29+
caml_backtrace.cmj : caml_backtrace.cmi
3030
caml_backtrace.cmx : caml_backtrace.cmi
31-
caml_basic.cmo : js.cmo caml_basic.cmi
31+
caml_basic.cmj : js.cmj caml_basic.cmi
3232
caml_basic.cmx : js.cmx caml_basic.cmi
33-
caml_builtin_exceptions.cmo : caml_builtin_exceptions.cmi
33+
caml_builtin_exceptions.cmj : caml_builtin_exceptions.cmi
3434
caml_builtin_exceptions.cmx : caml_builtin_exceptions.cmi
35-
caml_exceptions.cmo : caml_builtin_exceptions.cmi caml_exceptions.cmi
35+
caml_exceptions.cmj : caml_builtin_exceptions.cmi caml_exceptions.cmi
3636
caml_exceptions.cmx : caml_builtin_exceptions.cmx caml_exceptions.cmi
37-
caml_float.cmo : typed_array.cmo js.cmo caml_float.cmi
37+
caml_float.cmj : typed_array.cmj js.cmj caml_float.cmi
3838
caml_float.cmx : typed_array.cmx js.cmx caml_float.cmi
39-
caml_format.cmo : js.cmo caml_utils.cmi caml_format.cmi
39+
caml_format.cmj : js.cmj caml_utils.cmi caml_format.cmi
4040
caml_format.cmx : js.cmx caml_utils.cmx caml_format.cmi
41-
caml_gc.cmo : caml_gc.cmi
41+
caml_gc.cmj : caml_gc.cmi
4242
caml_gc.cmx : caml_gc.cmi
43-
caml_hash.cmo : js.cmo caml_queue.cmi caml_hash.cmi
43+
caml_hash.cmj : js.cmj caml_queue.cmi caml_hash.cmi
4444
caml_hash.cmx : js.cmx caml_queue.cmx caml_hash.cmi
45-
caml_int32.cmo : caml_int32.cmi
45+
caml_int32.cmj : caml_int32.cmi
4646
caml_int32.cmx : caml_int32.cmi
47-
caml_int64.cmo : typed_array.cmo js.cmo caml_utils.cmi caml_int64.cmi
47+
caml_int64.cmj : typed_array.cmj js.cmj caml_utils.cmi caml_int64.cmi
4848
caml_int64.cmx : typed_array.cmx js.cmx caml_utils.cmx caml_int64.cmi
49-
caml_io.cmo : js.cmo
49+
caml_io.cmj : js.cmj
5050
caml_io.cmx : js.cmx
51-
caml_lexer.cmo : caml_lexer.cmi
51+
caml_lexer.cmj : caml_lexer.cmi
5252
caml_lexer.cmx : caml_lexer.cmi
53-
caml_md5.cmo : js.cmo caml_md5.cmi
53+
caml_md5.cmj : js.cmj caml_md5.cmi
5454
caml_md5.cmx : js.cmx caml_md5.cmi
55-
caml_obj.cmo : js.cmo caml_obj.cmi
55+
caml_obj.cmj : js.cmj caml_obj.cmi
5656
caml_obj.cmx : js.cmx caml_obj.cmi
57-
caml_oo.cmo : js.cmo caml_oo.cmi
57+
caml_oo.cmj : js.cmj caml_oo.cmi
5858
caml_oo.cmx : js.cmx caml_oo.cmi
59-
caml_parser.cmo : caml_parser.cmi
59+
caml_parser.cmj : caml_parser.cmi
6060
caml_parser.cmx : caml_parser.cmi
61-
caml_primitive.cmo : caml_primitive.cmi
61+
caml_primitive.cmj : caml_primitive.cmi
6262
caml_primitive.cmx : caml_primitive.cmi
63-
caml_queue.cmo : caml_queue.cmi
63+
caml_queue.cmj : caml_queue.cmi
6464
caml_queue.cmx : caml_queue.cmi
65-
caml_string.cmo : js.cmo caml_string.cmi
65+
caml_string.cmj : js.cmj caml_string.cmi
6666
caml_string.cmx : js.cmx caml_string.cmi
67-
caml_sys.cmo : js.cmo caml_sys.cmi
67+
caml_sys.cmj : js.cmj caml_sys.cmi
6868
caml_sys.cmx : js.cmx caml_sys.cmi
69-
caml_utils.cmo : caml_utils.cmi
69+
caml_utils.cmj : caml_utils.cmi
7070
caml_utils.cmx : caml_utils.cmi
71-
caml_weak.cmo : js.cmo caml_array.cmi caml_weak.cmi
71+
caml_weak.cmj : js.cmj caml_array.cmi caml_weak.cmi
7272
caml_weak.cmx : js.cmx caml_array.cmx caml_weak.cmi
73-
curry.cmo : js.cmo caml_oo.cmi
73+
curry.cmj : js.cmj caml_oo.cmi
7474
curry.cmx : js.cmx caml_oo.cmx
75-
fn.cmo :
75+
fn.cmj :
7676
fn.cmx :
77-
js.cmo :
77+
js.cmj :
7878
js.cmx :
79-
js_primitive.cmo : js.cmo js_primitive.cmi
79+
js_primitive.cmj : js.cmj js_primitive.cmi
8080
js_primitive.cmx : js.cmx js_primitive.cmi
81-
typed_array.cmo :
81+
typed_array.cmj :
8282
typed_array.cmx :
8383
block.cmo : block.cmi
8484
block.cmj : block.cmi

jscomp/runtime/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ clean::
3030
-include .runtimedepend
3131

3232
depend:
33-
$(CAMLDEP) $(INCLUDES) *.mli *.ml > .runtimedepend
33+
$(CAMLDEP) $(INCLUDES) *.mli *.ml | sed -e 's/\.cmo/.cmj/g' > .runtimedepend
3434
$(CAMLDEP) $(INCLUDES) *.ml | sed -e 's/\.cmx/.cmj/g' >>.runtimedepend
3535

jscomp/runtime/caml_format.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
let repeat = Caml_utils.repeat
3333
let caml_failwith s = raise (Failure s)
3434
let caml_invalid_argument s= raise (Invalid_argument s )
35-
35+
let (^) = Js.String.append
3636
let (>>>) = Nativeint.shift_right_logical
3737

3838
let to_nat x = Nativeint.of_int x

0 commit comments

Comments
 (0)