@@ -40,7 +40,7 @@ type ml_module_info = {
4040}
4141
4242type env_value =
43- | Visit of ml_module_info
43+ | Ml of ml_module_info
4444 | Runtime of ml_module_info
4545 (* *
4646 [Runtime (pure, path, cmj_format)]
@@ -56,7 +56,6 @@ type env_value =
5656
5757
5858type ident_info = {
59- (* id : Ident.t; *)
6059 name : string ;
6160 arity : Js_cmj_format .arity ;
6261 closed_lambda : Lam .t option
@@ -89,16 +88,16 @@ let reset () =
8988*)
9089let add_js_module
9190 (hint_name : External_ffi_types.module_bind_name )
92- module_name : Ident. t
91+ ( module_name : string ) : Ident. t
9392 =
9493 let id =
95- Ident. create @@
94+ Ident. create
9695 (match hint_name with
9796 | 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+ *)
102101 | Phint_nothing ->
103102 Ext_modulename. js_id_name_of_hint_name module_name
104103 )
@@ -120,35 +119,28 @@ let add_js_module
120119
121120
122121
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 =
124123 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+ }
152144
153145
154146
@@ -157,81 +149,46 @@ let cached_find_ml_id_pos (module_id : Ident.t) name : ident_info =
157149 [Runtime]
158150 and [externals]*)
159151type _ t =
160- | No_env : ( path * Js_cmj_format .t ) t
152+ | No_env : bool t
161153 | Has_env : Env .t -> bool t (* Indicate it is pure or not *)
162154
163155
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+ *)
166161let query_and_add_if_not_exist
167162 (type u )
168163 (oid : Lam_module_ident.t )
169- ( env : u t ) ~ not_found ~( found : u -> _ ) =
164+ =
170165 match Lam_module_ident.Hash. find_opt cached_tbl oid with
171166 | None ->
172167 begin match oid.kind with
173168 | Runtime ->
174169 let (cmj_path, cmj_table) as cmj_info =
175170 Js_cmj_load. find_cmj_exn (Lam_module_ident. name oid ^ Literals. suffix_cmj) in
176171 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
182173 | Ml
183174 ->
184175 let (cmj_path, cmj_table) as cmj_info =
185176 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
199179 | External _ ->
200180 oid +> External ;
201181 (* * This might be wrong, if we happen to expand an js module
202182 we should assert false (but this in general should not happen)
183+ FIXME: #154, it come from External, should be okay
203184 *)
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
234186 end
187+ | Some (Ml { cmj_table })
188+ | Some (Runtime {cmj_table} ) ->
189+ Js_cmj_format. is_pure cmj_table
190+ | Some External -> false
191+
235192
236193
237194
@@ -240,7 +197,7 @@ let get_package_path_from_cmj
240197 ( id : Lam_module_ident.t )
241198 =
242199 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} ) ->
244201 (cmj_path,
245202 Js_cmj_format. get_npm_package_path cmj_table,
246203 Js_cmj_format. get_cmj_case cmj_table )
@@ -258,7 +215,7 @@ let get_package_path_from_cmj
258215 | Ml ->
259216 let (cmj_path, cmj_table) =
260217 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 };
262219 (cmj_path,
263220 Js_cmj_format. get_npm_package_path cmj_table,
264221 Js_cmj_format. get_cmj_case cmj_table )
@@ -267,26 +224,11 @@ let get_package_path_from_cmj
267224let add = Lam_module_ident.Hash_set. add
268225
269226
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-
283227(* Conservative interface *)
284228let is_pure_module (id : Lam_module_ident.t ) =
285229 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+
290232
291233let get_required_modules
292234 extras
0 commit comments