@@ -41,7 +41,7 @@ type ml_module_info = {
41
41
42
42
type env_value =
43
43
| Visit of ml_module_info
44
- | Runtime of bool * path * Js_cmj_format .t
44
+ | Runtime of ml_module_info
45
45
(* *
46
46
[Runtime (pure, path, cmj_format)]
47
47
A built in module probably from our runtime primitives,
@@ -69,7 +69,10 @@ type ident_info = {
69
69
70
70
71
71
72
- let cached_tbl = Lam_module_ident.Hash. create 31
72
+ let cached_tbl : env_value Lam_module_ident.Hash. t
73
+ = Lam_module_ident.Hash. create 31
74
+ let (+> ) = Lam_module_ident.Hash. add cached_tbl
75
+
73
76
74
77
(* For each compilation we need reset to make it re-entrant *)
75
78
let reset () =
@@ -115,14 +118,14 @@ let add_js_module
115
118
116
119
117
120
118
- let ( +> ) = Lam_module_ident.Hash. add cached_tbl
121
+
119
122
120
123
let cached_find_ml_id_pos (module_id : Ident.t ) name : ident_info =
121
124
let oid = Lam_module_ident. of_ml module_id in
122
125
match Lam_module_ident.Hash. find_opt cached_tbl oid with
123
126
| None ->
124
127
let cmj_path, cmj_table =
125
- Js_cmj_load. find_cmj (module_id.name ^ Literals. suffix_cmj) in
128
+ Js_cmj_load. find_cmj_exn (module_id.name ^ Literals. suffix_cmj) in
126
129
oid +> Visit { cmj_table ; cmj_path } ;
127
130
let arity, closed_lambda =
128
131
Js_cmj_format. query_by_name cmj_table name
@@ -149,15 +152,13 @@ let cached_find_ml_id_pos (module_id : Ident.t) name : ident_info =
149
152
150
153
151
154
152
- type module_info = {
153
- pure : bool
154
- }
155
+
155
156
(* TODO: it does not make sense to cache
156
157
[Runtime]
157
158
and [externals]*)
158
159
type _ t =
159
160
| No_env : (path * Js_cmj_format .t ) t
160
- | Has_env : Env .t -> module_info t
161
+ | Has_env : Env .t -> bool t (* Indicate it is pure or not *)
161
162
162
163
163
164
(* -FIXME:
@@ -171,25 +172,25 @@ let query_and_add_if_not_exist
171
172
begin match oid.kind with
172
173
| Runtime ->
173
174
let (cmj_path, cmj_table) as cmj_info =
174
- Js_cmj_load. find_cmj (Lam_module_ident. name oid ^ Literals. suffix_cmj) in
175
- oid +> Runtime ( true , cmj_path, cmj_table) ;
175
+ Js_cmj_load. find_cmj_exn (Lam_module_ident. name oid ^ Literals. suffix_cmj) in
176
+ oid +> Runtime { cmj_path; cmj_table} ;
176
177
(match env with
177
178
| Has_env _ ->
178
- found { pure = true }
179
+ found true
179
180
| No_env ->
180
181
found cmj_info)
181
182
| Ml
182
183
->
183
184
let (cmj_path, cmj_table) as cmj_info =
184
- Js_cmj_load. find_cmj (Lam_module_ident. name oid ^ Literals. suffix_cmj) in
185
+ Js_cmj_load. find_cmj_exn (Lam_module_ident. name oid ^ Literals. suffix_cmj) in
185
186
( match env with
186
187
| Has_env env ->
187
188
begin match
188
189
Ocaml_types. find_serializable_signatures_by_path oid.id env with
189
190
| None -> not_found () (* actually when [not_found] in the call site, we throw... *)
190
- | Some signature ->
191
+ | Some _ ->
191
192
oid +> Visit {cmj_table;cmj_path } ;
192
- found { pure = Js_cmj_format. is_pure cmj_table}
193
+ found ( Js_cmj_format. is_pure cmj_table)
193
194
end
194
195
| No_env ->
195
196
found cmj_info)
@@ -203,7 +204,7 @@ let query_and_add_if_not_exist
203
204
begin match env with
204
205
| Has_env _
205
206
->
206
- found { pure = false }
207
+ found false
207
208
| No_env ->
208
209
found (Ext_string. empty, Js_cmj_format. no_pure_dummy)
209
210
(* FIXME: #154, it come from External, should be okay *)
@@ -213,21 +214,21 @@ let query_and_add_if_not_exist
213
214
| Some (Visit { cmj_table; cmj_path} ) ->
214
215
begin match env with
215
216
| Has_env _ ->
216
- found { pure = Js_cmj_format. is_pure cmj_table}
217
+ found ( Js_cmj_format. is_pure cmj_table)
217
218
| No_env -> found (cmj_path,cmj_table)
218
219
end
219
220
220
- | Some (Runtime ( pure , cmj_path , cmj_table ) ) ->
221
+ | Some (Runtime { cmj_path; cmj_table} ) ->
221
222
begin match env with
222
223
| Has_env _ ->
223
- found {pure }
224
+ found true
224
225
| No_env ->
225
226
found (cmj_path, cmj_table)
226
227
end
227
228
| Some External ->
228
229
begin match env with
229
230
| Has_env _ ->
230
- found {pure = false }
231
+ found false
231
232
| No_env ->
232
233
found (Ext_string. empty, Js_cmj_format. no_pure_dummy) (* External is okay *)
233
234
end
@@ -237,26 +238,47 @@ let query_and_add_if_not_exist
237
238
238
239
let get_package_path_from_cmj
239
240
( id : Lam_module_ident.t )
240
- : _ option =
241
- query_and_add_if_not_exist id No_env
242
- ~not_found: (fun _ ->
243
- None
244
- (*
245
- So after querying, it should return
246
- [Js_packages_info.Package_not_found]
247
- *)
248
- )
249
- ~found: (fun (cmj_path ,x ) ->
250
- Some (cmj_path,
251
- Js_cmj_format. get_npm_package_path x,
252
- Js_cmj_format. get_cmj_case x )
253
- )
254
-
241
+ =
242
+ match Lam_module_ident.Hash. find_opt cached_tbl id with
243
+ | Some (Visit {cmj_table ; cmj_path} ) ->
244
+ (cmj_path,
245
+ Js_cmj_format. get_npm_package_path cmj_table,
246
+ Js_cmj_format. get_cmj_case cmj_table )
247
+ | Some (
248
+ External |
249
+ Runtime _ ) ->
250
+ assert false
251
+ (* called by {!Js_name_of_module_id.string_of_module_id}
252
+ can not be External
253
+ *)
254
+ | None ->
255
+ begin match id.kind with
256
+ | Runtime
257
+ | External _ -> assert false
258
+ | Ml ->
259
+ let (cmj_path, cmj_table) =
260
+ Js_cmj_load. find_cmj_exn (Lam_module_ident. name id ^ Literals. suffix_cmj) in
261
+ id +> Visit {cmj_table;cmj_path };
262
+ (cmj_path,
263
+ Js_cmj_format. get_npm_package_path cmj_table,
264
+ Js_cmj_format. get_cmj_case cmj_table )
265
+ end
255
266
256
267
let add = Lam_module_ident.Hash_set. add
257
268
258
269
259
270
271
+ (* let is_pure_module (id : Lam_module_ident.t) =
272
+ match id.kind with
273
+ | Runtime -> true
274
+ | External _ -> false
275
+ | Ml ->
276
+ match Lam_module_ident.Hash.find_opt cached_tbl id with
277
+ | Some (Visit {cmj_table = {pure}}) -> pure
278
+ | Some _ -> assert false
279
+ | None -> *)
280
+
281
+
260
282
261
283
(* Conservative interface *)
262
284
let is_pure_module (id : Lam_module_ident.t ) =
0 commit comments