@@ -40,7 +40,7 @@ type ml_module_info = {
40
40
}
41
41
42
42
type env_value =
43
- | Visit of ml_module_info
43
+ | Ml of ml_module_info
44
44
| Runtime of ml_module_info
45
45
(* *
46
46
[Runtime (pure, path, cmj_format)]
@@ -56,7 +56,6 @@ type env_value =
56
56
57
57
58
58
type ident_info = {
59
- (* id : Ident.t; *)
60
59
name : string ;
61
60
arity : Js_cmj_format .arity ;
62
61
closed_lambda : Lam .t option
@@ -89,16 +88,16 @@ let reset () =
89
88
*)
90
89
let add_js_module
91
90
(hint_name : External_ffi_types.module_bind_name )
92
- module_name : Ident. t
91
+ ( module_name : string ) : Ident. t
93
92
=
94
93
let id =
95
- Ident. create @@
94
+ Ident. create
96
95
(match hint_name with
97
96
| Phint_name hint_name ->
98
- Ext_string. capitalize_ascii hint_name
99
- (* make sure the module name is capitalized
100
- TODO: maybe a warning if the user hint is not good
101
- *)
97
+ Ext_string. capitalize_ascii hint_name
98
+ (* make sure the module name is capitalized
99
+ TODO: maybe a warning if the user hint is not good
100
+ *)
102
101
| Phint_nothing ->
103
102
Ext_modulename. js_id_name_of_hint_name module_name
104
103
)
@@ -120,35 +119,28 @@ let add_js_module
120
119
121
120
122
121
123
- let cached_find_ml_id_pos (module_id : Ident.t ) name : ident_info =
122
+ let query_external_id_info (module_id : Ident.t ) ( name : string ) : ident_info =
124
123
let oid = Lam_module_ident. of_ml module_id in
125
- match Lam_module_ident.Hash. find_opt cached_tbl oid with
126
- | None ->
127
- let cmj_path, cmj_table =
128
- Js_cmj_load. find_cmj_exn (module_id.name ^ Literals. suffix_cmj) in
129
- oid +> Visit { cmj_table ; cmj_path } ;
130
- let arity, closed_lambda =
131
- Js_cmj_format. query_by_name cmj_table name
132
- in
133
- {
134
- name ;
135
- arity ;
136
- closed_lambda
137
- }
138
-
139
- | Some (Visit { cmj_table } )
140
- ->
141
- let arity , closed_lambda =
142
- Js_cmj_format. query_by_name cmj_table name
143
- in
144
- {
145
- name;
146
- arity;
147
- closed_lambda
148
- (* TODO shall we cache the arity ?*)
149
- }
150
- | Some (Runtime _ ) -> assert false
151
- | Some External -> assert false
124
+ let cmj_table =
125
+ match Lam_module_ident.Hash. find_opt cached_tbl oid with
126
+ | None ->
127
+ let cmj_path, cmj_table =
128
+ Js_cmj_load. find_cmj_exn (module_id.name ^ Literals. suffix_cmj) in
129
+ oid +> Ml { cmj_table ; cmj_path } ;
130
+ cmj_table
131
+ | Some (Ml { cmj_table } )
132
+ -> cmj_table
133
+ | Some (Runtime _ ) -> assert false
134
+ | Some External -> assert false in
135
+ let arity , closed_lambda =
136
+ Js_cmj_format. query_by_name cmj_table name
137
+ in
138
+ {
139
+ name;
140
+ arity;
141
+ closed_lambda
142
+ (* TODO shall we cache the arity ?*)
143
+ }
152
144
153
145
154
146
@@ -157,81 +149,46 @@ let cached_find_ml_id_pos (module_id : Ident.t) name : ident_info =
157
149
[Runtime]
158
150
and [externals]*)
159
151
type _ t =
160
- | No_env : ( path * Js_cmj_format .t ) t
152
+ | No_env : bool t
161
153
| Has_env : Env .t -> bool t (* Indicate it is pure or not *)
162
154
163
155
164
- (* -FIXME:
165
- Here [not_found] only means cmi not found, not cmj not found *)
156
+ (*
157
+ FIXME:
158
+ Here [not_found] only means cmi not found, not cmj not found
159
+ We do need handle cases when [not_found] hit in a graceful way
160
+ *)
166
161
let query_and_add_if_not_exist
167
162
(type u )
168
163
(oid : Lam_module_ident.t )
169
- ( env : u t ) ~ not_found ~( found : u -> _ ) =
164
+ =
170
165
match Lam_module_ident.Hash. find_opt cached_tbl oid with
171
166
| None ->
172
167
begin match oid.kind with
173
168
| Runtime ->
174
169
let (cmj_path, cmj_table) as cmj_info =
175
170
Js_cmj_load. find_cmj_exn (Lam_module_ident. name oid ^ Literals. suffix_cmj) in
176
171
oid +> Runtime {cmj_path;cmj_table} ;
177
- (match env with
178
- | Has_env _ ->
179
- found true
180
- | No_env ->
181
- found cmj_info)
172
+ Js_cmj_format. is_pure cmj_table
182
173
| Ml
183
174
->
184
175
let (cmj_path, cmj_table) as cmj_info =
185
176
Js_cmj_load. find_cmj_exn (Lam_module_ident. name oid ^ Literals. suffix_cmj) in
186
- ( match env with
187
- | Has_env env ->
188
- begin match
189
- Ocaml_types. find_serializable_signatures_by_path oid.id env with
190
- | None -> not_found () (* actually when [not_found] in the call site, we throw... *)
191
- | Some _ ->
192
- oid +> Visit {cmj_table;cmj_path } ;
193
- found (Js_cmj_format. is_pure cmj_table)
194
- end
195
- | No_env ->
196
- found cmj_info)
197
-
198
-
177
+ oid +> Ml {cmj_table;cmj_path } ;
178
+ Js_cmj_format. is_pure cmj_table
199
179
| External _ ->
200
180
oid +> External ;
201
181
(* * This might be wrong, if we happen to expand an js module
202
182
we should assert false (but this in general should not happen)
183
+ FIXME: #154, it come from External, should be okay
203
184
*)
204
- begin match env with
205
- | Has_env _
206
- ->
207
- found false
208
- | No_env ->
209
- found (Ext_string. empty, Js_cmj_format. no_pure_dummy)
210
- (* FIXME: #154, it come from External, should be okay *)
211
- end
212
-
213
- end
214
- | Some (Visit { cmj_table; cmj_path} ) ->
215
- begin match env with
216
- | Has_env _ ->
217
- found (Js_cmj_format. is_pure cmj_table)
218
- | No_env -> found (cmj_path,cmj_table)
219
- end
220
-
221
- | Some (Runtime {cmj_path; cmj_table} ) ->
222
- begin match env with
223
- | Has_env _ ->
224
- found true
225
- | No_env ->
226
- found (cmj_path, cmj_table)
227
- end
228
- | Some External ->
229
- begin match env with
230
- | Has_env _ ->
231
- found false
232
- | No_env ->
233
- found (Ext_string. empty, Js_cmj_format. no_pure_dummy) (* External is okay *)
185
+ false
234
186
end
187
+ | Some (Ml { cmj_table })
188
+ | Some (Runtime {cmj_table} ) ->
189
+ Js_cmj_format. is_pure cmj_table
190
+ | Some External -> false
191
+
235
192
236
193
237
194
@@ -240,7 +197,7 @@ let get_package_path_from_cmj
240
197
( id : Lam_module_ident.t )
241
198
=
242
199
match Lam_module_ident.Hash. find_opt cached_tbl id with
243
- | Some (Visit {cmj_table ; cmj_path} ) ->
200
+ | Some (Ml {cmj_table ; cmj_path} ) ->
244
201
(cmj_path,
245
202
Js_cmj_format. get_npm_package_path cmj_table,
246
203
Js_cmj_format. get_cmj_case cmj_table )
@@ -258,7 +215,7 @@ let get_package_path_from_cmj
258
215
| Ml ->
259
216
let (cmj_path, cmj_table) =
260
217
Js_cmj_load. find_cmj_exn (Lam_module_ident. name id ^ Literals. suffix_cmj) in
261
- id +> Visit {cmj_table;cmj_path };
218
+ id +> Ml {cmj_table;cmj_path };
262
219
(cmj_path,
263
220
Js_cmj_format. get_npm_package_path cmj_table,
264
221
Js_cmj_format. get_cmj_case cmj_table )
@@ -267,26 +224,11 @@ let get_package_path_from_cmj
267
224
let add = Lam_module_ident.Hash_set. add
268
225
269
226
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
-
282
-
283
227
(* Conservative interface *)
284
228
let is_pure_module (id : Lam_module_ident.t ) =
285
229
id.kind = Runtime ||
286
- query_and_add_if_not_exist id No_env
287
- ~not_found: (fun _ -> false )
288
- ~found: (fun (_ ,x ) ->
289
- Js_cmj_format. is_pure x)
230
+ query_and_add_if_not_exist id
231
+
290
232
291
233
let get_required_modules
292
234
extras
0 commit comments