Skip to content

Commit 50763e5

Browse files
committed
make is_pure_module more forgiving, return false when not found
1 parent 5ef1ffa commit 50763e5

File tree

6 files changed

+92
-125
lines changed

6 files changed

+92
-125
lines changed

jscomp/core/js_cmj_load.ml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,14 @@
2828
*)
2929

3030

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

3237
#if BS_COMPILER_IN_BROWSER then
33-
let find_cmj_exn file : string * Js_cmj_format.t =
38+
let find_cmj_exn file : cmj_load_info =
3439
let target = Ext_string.uncapitalize_ascii (Filename.basename file) in
3540
match String_map.find_exn !Js_cmj_datasets.data_sets target with
3641
| v
@@ -41,18 +46,18 @@ let find_cmj_exn file : string * Js_cmj_format.t =
4146
Ext_log.warn __LOC__
4247
"@[%s corrupted in database, when looking %s while compiling %s please update @]" file target !Location.input_name ;
4348
Bs_exception.error (Cmj_not_found file)
44-
| v -> "BROWSER", v
49+
| v -> {cmj_path = "BROWSER"; cmj_table = v}
4550
(* see {!Js_packages_info.string_of_module_id} *)
4651
end
4752
| exception Not_found
4853
->
4954
Bs_exception.error (Cmj_not_found file)
5055
#else
51-
let find_cmj_exn file : string * Js_cmj_format.t =
56+
let find_cmj_exn file : cmj_load_info =
5257
match Config_util.find_opt file with
5358
| Some f
5459
->
55-
f, Js_cmj_format.from_file f
60+
{cmj_path = f; cmj_table = Js_cmj_format.from_file f}
5661
| None ->
5762
(* ONLY read the stored cmj data in browser environment *)
5863
Bs_exception.error (Cmj_not_found file)

jscomp/core/js_cmj_load.mli

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@
2727
it depends on {!Js_cmj_datasets}, for non-browser environment, it fails
2828
*)
2929

30-
30+
type path = string
31+
type cmj_load_info = {
32+
cmj_table : Js_cmj_format.t ;
33+
cmj_path : path ;
34+
}
3135

3236
(** return path and meta data *)
33-
val find_cmj_exn : string -> string * Js_cmj_format.t
37+
val find_cmj_exn :
38+
string ->
39+
cmj_load_info

jscomp/core/lam_compile_env.ml

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,10 @@
3232
module E = Js_exp_make
3333
module S = Js_stmt_make
3434

35-
type path = string
36-
37-
type ml_module_info = {
38-
cmj_table : Js_cmj_format.t ;
39-
cmj_path : path;
40-
}
4135

4236
type env_value =
43-
| Ml of ml_module_info
44-
| Runtime of ml_module_info
37+
| Ml of Js_cmj_load.cmj_load_info
38+
| Runtime of Js_cmj_load.cmj_load_info
4539
(**
4640
[Runtime (pure, path, cmj_format)]
4741
A built in module probably from our runtime primitives,
@@ -124,10 +118,10 @@ let query_external_id_info (module_id : Ident.t) (name : string) : ident_info =
124118
let cmj_table =
125119
match Lam_module_ident.Hash.find_opt cached_tbl oid with
126120
| None ->
127-
let cmj_path, cmj_table =
121+
let cmj_load_info =
128122
Js_cmj_load.find_cmj_exn (module_id.name ^ Literals.suffix_cmj) in
129-
oid +> Ml { cmj_table ; cmj_path } ;
130-
cmj_table
123+
oid +> Ml cmj_load_info ;
124+
cmj_load_info.cmj_table
131125
| Some (Ml { cmj_table } )
132126
-> cmj_table
133127
| Some (Runtime _) -> assert false
@@ -145,12 +139,6 @@ let query_external_id_info (module_id : Ident.t) (name : string) : ident_info =
145139

146140

147141

148-
(* TODO: it does not make sense to cache
149-
[Runtime]
150-
and [externals]*)
151-
type _ t =
152-
| No_env : bool t
153-
| Has_env : Env.t -> bool t (* Indicate it is pure or not *)
154142

155143

156144

@@ -178,10 +166,10 @@ let get_package_path_from_cmj
178166
| Runtime
179167
| External _ -> assert false
180168
| Ml ->
181-
let (cmj_path, cmj_table) =
169+
let ({Js_cmj_load.cmj_table} as cmj_load_info) =
182170
Js_cmj_load.find_cmj_exn (Lam_module_ident.name id ^ Literals.suffix_cmj) in
183-
id +> Ml {cmj_table;cmj_path };
184-
(cmj_path,
171+
id +> Ml cmj_load_info;
172+
(cmj_load_info.cmj_path,
185173
Js_cmj_format.get_npm_package_path cmj_table,
186174
Js_cmj_format.get_cmj_case cmj_table )
187175
end
@@ -198,10 +186,13 @@ let is_pure_module (oid : Lam_module_ident.t) =
198186
| Ml ->
199187
begin match Lam_module_ident.Hash.find_opt cached_tbl oid with
200188
| None ->
201-
let (cmj_path, cmj_table) =
202-
Js_cmj_load.find_cmj_exn (Lam_module_ident.name oid ^ Literals.suffix_cmj) in
203-
oid +> Ml {cmj_table;cmj_path } ;
204-
Js_cmj_format.is_pure cmj_table
189+
begin
190+
match Js_cmj_load.find_cmj_exn (Lam_module_ident.name oid ^ Literals.suffix_cmj) with
191+
| cmj_load_info ->
192+
oid +> Ml cmj_load_info ;
193+
Js_cmj_format.is_pure cmj_load_info.cmj_table
194+
| exception _ -> false
195+
end
205196
| Some (Ml{cmj_table}|Runtime {cmj_table}) ->
206197
Js_cmj_format.is_pure cmj_table
207198
| Some External -> false

jscomp/core/lam_compile_env.mli

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,10 @@
2424

2525

2626

27-
28-
29-
30-
31-
3227
(** Helper for global Ocaml module index into meaningful names *)
3328

3429

3530

36-
type path = string
37-
38-
39-
40-
41-
type _ t =
42-
| No_env : bool t
43-
| Has_env : Env.t -> bool t
4431

4532

4633
type ident_info = {

lib/4.02.3/unstable/js_compiler.ml

Lines changed: 30 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -86968,10 +86968,16 @@ module Js_cmj_load : sig
8696886968
it depends on {!Js_cmj_datasets}, for non-browser environment, it fails
8696986969
*)
8697086970

86971-
86971+
type path = string
86972+
type cmj_load_info = {
86973+
cmj_table : Js_cmj_format.t ;
86974+
cmj_path : path ;
86975+
}
8697286976

8697386977
(** return path and meta data *)
86974-
val find_cmj_exn : string -> string * Js_cmj_format.t
86978+
val find_cmj_exn :
86979+
string ->
86980+
cmj_load_info
8697586981

8697686982
end = struct
8697786983
#1 "js_cmj_load.ml"
@@ -87005,9 +87011,14 @@ end = struct
8700587011
*)
8700687012

8700787013

87014+
type path = string
87015+
type cmj_load_info = {
87016+
cmj_table : Js_cmj_format.t ;
87017+
cmj_path : path ;
87018+
}
8700887019

8700987020

87010-
let find_cmj_exn file : string * Js_cmj_format.t =
87021+
let find_cmj_exn file : cmj_load_info =
8701187022
let target = Ext_string.uncapitalize_ascii (Filename.basename file) in
8701287023
match String_map.find_exn !Js_cmj_datasets.data_sets target with
8701387024
| v
@@ -87018,7 +87029,7 @@ let find_cmj_exn file : string * Js_cmj_format.t =
8701887029
Ext_log.warn __LOC__
8701987030
"@[%s corrupted in database, when looking %s while compiling %s please update @]" file target !Location.input_name ;
8702087031
Bs_exception.error (Cmj_not_found file)
87021-
| v -> "BROWSER", v
87032+
| v -> {cmj_path = "BROWSER"; cmj_table = v}
8702287033
(* see {!Js_packages_info.string_of_module_id} *)
8702387034
end
8702487035
| exception Not_found
@@ -96336,23 +96347,10 @@ module Lam_compile_env : sig
9633696347

9633796348

9633896349

96339-
96340-
96341-
96342-
96343-
9634496350
(** Helper for global Ocaml module index into meaningful names *)
9634596351

9634696352

9634796353

96348-
type path = string
96349-
96350-
96351-
96352-
96353-
type _ t =
96354-
| No_env : bool t
96355-
| Has_env : Env.t -> bool t
9635696354

9635796355

9635896356
type ident_info = {
@@ -96464,16 +96462,10 @@ end = struct
9646496462
module E = Js_exp_make
9646596463
module S = Js_stmt_make
9646696464

96467-
type path = string
96468-
96469-
type ml_module_info = {
96470-
cmj_table : Js_cmj_format.t ;
96471-
cmj_path : path;
96472-
}
9647396465

9647496466
type env_value =
96475-
| Ml of ml_module_info
96476-
| Runtime of ml_module_info
96467+
| Ml of Js_cmj_load.cmj_load_info
96468+
| Runtime of Js_cmj_load.cmj_load_info
9647796469
(**
9647896470
[Runtime (pure, path, cmj_format)]
9647996471
A built in module probably from our runtime primitives,
@@ -96556,10 +96548,10 @@ let query_external_id_info (module_id : Ident.t) (name : string) : ident_info =
9655696548
let cmj_table =
9655796549
match Lam_module_ident.Hash.find_opt cached_tbl oid with
9655896550
| None ->
96559-
let cmj_path, cmj_table =
96551+
let cmj_load_info =
9656096552
Js_cmj_load.find_cmj_exn (module_id.name ^ Literals.suffix_cmj) in
96561-
oid +> Ml { cmj_table ; cmj_path } ;
96562-
cmj_table
96553+
oid +> Ml cmj_load_info ;
96554+
cmj_load_info.cmj_table
9656396555
| Some (Ml { cmj_table } )
9656496556
-> cmj_table
9656596557
| Some (Runtime _) -> assert false
@@ -96577,12 +96569,6 @@ let query_external_id_info (module_id : Ident.t) (name : string) : ident_info =
9657796569

9657896570

9657996571

96580-
(* TODO: it does not make sense to cache
96581-
[Runtime]
96582-
and [externals]*)
96583-
type _ t =
96584-
| No_env : bool t
96585-
| Has_env : Env.t -> bool t (* Indicate it is pure or not *)
9658696572

9658796573

9658896574

@@ -96610,10 +96596,10 @@ let get_package_path_from_cmj
9661096596
| Runtime
9661196597
| External _ -> assert false
9661296598
| Ml ->
96613-
let (cmj_path, cmj_table) =
96599+
let ({Js_cmj_load.cmj_table} as cmj_load_info) =
9661496600
Js_cmj_load.find_cmj_exn (Lam_module_ident.name id ^ Literals.suffix_cmj) in
96615-
id +> Ml {cmj_table;cmj_path };
96616-
(cmj_path,
96601+
id +> Ml cmj_load_info;
96602+
(cmj_load_info.cmj_path,
9661796603
Js_cmj_format.get_npm_package_path cmj_table,
9661896604
Js_cmj_format.get_cmj_case cmj_table )
9661996605
end
@@ -96630,10 +96616,13 @@ let is_pure_module (oid : Lam_module_ident.t) =
9663096616
| Ml ->
9663196617
begin match Lam_module_ident.Hash.find_opt cached_tbl oid with
9663296618
| None ->
96633-
let (cmj_path, cmj_table) =
96634-
Js_cmj_load.find_cmj_exn (Lam_module_ident.name oid ^ Literals.suffix_cmj) in
96635-
oid +> Ml {cmj_table;cmj_path } ;
96636-
Js_cmj_format.is_pure cmj_table
96619+
begin
96620+
match Js_cmj_load.find_cmj_exn (Lam_module_ident.name oid ^ Literals.suffix_cmj) with
96621+
| cmj_load_info ->
96622+
oid +> Ml cmj_load_info ;
96623+
Js_cmj_format.is_pure cmj_load_info.cmj_table
96624+
| exception _ -> false
96625+
end
9663796626
| Some (Ml{cmj_table}|Runtime {cmj_table}) ->
9663896627
Js_cmj_format.is_pure cmj_table
9663996628
| Some External -> false

0 commit comments

Comments
 (0)