@@ -189,6 +189,39 @@ and for_type_module ~name ~env module_type =
189189 in a typed tree, so that they never meet one of them. *)
190190let renamed_stamp_floor = 1 lsl 40
191191
192+ (* [Subst] renames the items of a signature in place, so the original and
193+ the renamed signature list the same items in the same order. Records
194+ each renamed stamp's original, nested signatures included, for
195+ references to find the declarations in the functor body. *)
196+ let rec record_renamed_stamps table (original : Types.module_type )
197+ (renamed : Types.module_type ) =
198+ match (original, renamed) with
199+ | Mty_signature items, Mty_signature renamed_items
200+ when List. length items = List. length renamed_items ->
201+ List. iter2
202+ (fun (item : Types.signature_item ) (renamed_item : Types.signature_item )
203+ ->
204+ let ids =
205+ match (item, renamed_item) with
206+ | Sig_value (id, _), Sig_value (id', _)
207+ | Sig_type (id, _, _), Sig_type (id', _, _)
208+ | Sig_typext (id, _, _), Sig_typext (id', _, _)
209+ | Sig_modtype (id , _ ), Sig_modtype (id' , _ ) ->
210+ Some (id, id')
211+ | Sig_module (id , md , _ ), Sig_module (id' , md' , _ ) ->
212+ record_renamed_stamps table md.md_type md'.md_type;
213+ Some (id, id')
214+ | _ -> None
215+ in
216+ match ids with
217+ | Some (id , id' ) ->
218+ Hashtbl. replace table (Ident. binding_time id') (Ident. binding_time id)
219+ | None -> () )
220+ items renamed_items
221+ | Mty_functor (_ , _ , result ), Mty_functor (_ , _ , renamed_result ) ->
222+ record_renamed_stamps table result renamed_result
223+ | _ -> ()
224+
192225let get_module_type_path mod_desc =
193226 match mod_desc with
194227 | Typedtree. Tmty_ident (path , _ ) | Tmty_alias (path , _ ) -> Some path
@@ -685,8 +718,9 @@ and for_module ~env (mod_expr : Typedtree.module_expr) module_name =
685718 in
686719 if Ident. current_time () < renamed_stamp_floor then
687720 Ident. set_current_time renamed_stamp_floor;
688- for_type_module ~name: module_name ~env
689- (Subst. modtype Subst. identity mod_expr.mod_type)
721+ let renamed = Subst. modtype Subst. identity mod_expr.mod_type in
722+ record_renamed_stamps env.renamed_stamps mod_expr.mod_type renamed;
723+ for_type_module ~name: module_name ~env renamed
690724 | Tmod_unpack (_expr , module_type ) ->
691725 let env = env |> Env. add_module ~name: module_name in
692726 for_type_module ~name: module_name ~env module_type
@@ -742,7 +776,11 @@ and for_structure ~name ~env str_items =
742776let file_for_cmt_infos ~module_name ~uri
743777 ({cmt_modname; cmt_annots} : Cmt_format.cmt_infos ) =
744778 let env =
745- {Env. stamps = Stamps. init () ; module_path = File (uri, module_name)}
779+ {
780+ Env. stamps = Stamps. init () ;
781+ module_path = File (uri, module_name);
782+ renamed_stamps = Hashtbl. create 1 ;
783+ }
746784 in
747785 match cmt_annots with
748786 | Partial_implementation parts ->
@@ -756,7 +794,13 @@ let file_for_cmt_infos ~module_name ~uri
756794 |> List. concat
757795 in
758796 let structure = for_structure ~name: module_name ~env items in
759- {File. uri; module_name = cmt_modname; stamps = env.stamps; structure}
797+ {
798+ File. uri;
799+ module_name = cmt_modname;
800+ stamps = env.stamps;
801+ structure;
802+ renamed_stamps = env.renamed_stamps;
803+ }
760804 | Partial_interface parts ->
761805 let items =
762806 parts |> Array. to_list
@@ -768,13 +812,31 @@ let file_for_cmt_infos ~module_name ~uri
768812 |> List. concat
769813 in
770814 let structure = for_signature ~name: module_name ~env items in
771- {uri; module_name = cmt_modname; stamps = env.stamps; structure}
815+ {
816+ uri;
817+ module_name = cmt_modname;
818+ stamps = env.stamps;
819+ structure;
820+ renamed_stamps = env.renamed_stamps;
821+ }
772822 | Implementation structure ->
773823 let structure = for_structure ~name: module_name ~env structure.str_items in
774- {uri; module_name = cmt_modname; stamps = env.stamps; structure}
824+ {
825+ uri;
826+ module_name = cmt_modname;
827+ stamps = env.stamps;
828+ structure;
829+ renamed_stamps = env.renamed_stamps;
830+ }
775831 | Interface signature ->
776832 let structure = for_signature ~name: module_name ~env signature.sig_items in
777- {uri; module_name = cmt_modname; stamps = env.stamps; structure}
833+ {
834+ uri;
835+ module_name = cmt_modname;
836+ stamps = env.stamps;
837+ structure;
838+ renamed_stamps = env.renamed_stamps;
839+ }
778840
779841let file_for_cmt ~state ~module_name ~cmt ~uri =
780842 match Hashtbl. find_opt state.cmt_cache cmt with
0 commit comments