@@ -20,31 +20,32 @@ let fill_from_cmt_tbl uid_to_decl res_uid_to_loc =
2020 UidTbl. iter add_uid_loc uid_to_decl;
2121 res_uid_to_loc
2222
23- let find_opt_external_uid_loc, clear_external_cache =
24- let cache = Hashtbl. create 16 in
25- let clear_external_cache () = Hashtbl. reset cache in
26- let find_opt_external_uid_loc ~cm_paths = function
27- | Shape.Uid. (Compilation_unit _ | Internal | Predef _ ) -> None
28- | Item {comp_unit; _} as uid ->
23+ let find_opt_external_uid_loc ~cm_paths = function
24+ | Shape.Uid. (Compilation_unit _ | Internal | Predef _ ) -> None
25+ | Item {comp_unit; from; _} as uid ->
2926 let ( let* ) x f = Option. bind x f in
30- let * cmt_uid_to_decl =
31- match Hashtbl. find_opt cache comp_unit with
32- | Some _ as cmt_uid_to_decl -> cmt_uid_to_decl
33- | None ->
34- let * cm_path =
35- Utils.StringSet. elements cm_paths
36- |> List. rev
37- |> List. find_opt (fun path -> Utils.Filepath. unit path = comp_unit)
38- in
39- let * cmt_infos = Cmt_format. read cm_path |> snd in
40- let cmt_uid_to_decl = cmt_infos.cmt_uid_to_decl in
41- Hashtbl. add cache comp_unit cmt_uid_to_decl;
42- Some cmt_uid_to_decl
27+ let cached =
28+ match from with
29+ | Unit_info. Intf -> Cmt. cached_cmti comp_unit
30+ | Unit_info. Impl -> Cmt. cached_cmt comp_unit
4331 in
32+ let read_from_path () =
33+ let * cm_path =
34+ Utils.StringSet. elements cm_paths
35+ |> List. rev
36+ |> List. find_opt (fun path -> Utils.Filepath. unit path = comp_unit)
37+ in
38+ Cmt. read cm_path |> Result. to_option
39+ in
40+ let * cmi_cmt_infos =
41+ match cached with
42+ | Some _ as some -> some
43+ | None -> read_from_path ()
44+ in
45+ let cmt_infos = snd cmi_cmt_infos in
46+ let cmt_uid_to_decl = cmt_infos.cmt_uid_to_decl in
4447 let * item_decl = UidTbl. find_opt cmt_uid_to_decl uid in
4548 loc_opt_of_item_decl item_decl
46- in
47- find_opt_external_uid_loc, clear_external_cache
4849
4950let cmt_decl_dep_to_loc_dep ~cm_paths cmt_decl_dep uid_to_loc =
5051 let convert_pair (_dep_kind , uid_def , uid_decl ) =
@@ -59,7 +60,6 @@ let cmt_decl_dep_to_loc_dep ~cm_paths cmt_decl_dep uid_to_loc =
5960 Some (def_loc, decl_loc)
6061 in
6162 let res = List. filter_map convert_pair cmt_decl_dep in
62- clear_external_cache () ;
6363 res
6464
6565let init ~cm_paths cmt_infos cmti_uid_to_decl =
0 commit comments