@@ -45,19 +45,34 @@ let replace_matching_ids ~reference ~current =
4545 Sig_type (new_id, td, r, v) :: lst )
4646 | None -> (subst, sig_typ_decl :: lst))
4747 | Sig_module (id , mp , md , r , v ) as sig_mod_decl -> (
48- match Env. find_value_index id ref_env with
48+ match Env. find_module_index id ref_env with
4949 | Some _ ->
5050 let new_id = Ident. rename id in
5151 ( Subst. add_module id (Path. Pident new_id) subst,
5252 Sig_module (new_id, mp, md, r, v) :: lst )
5353 | None -> (subst, sig_mod_decl :: lst))
54- | Sig_modtype (id , mtd , v ) as sig_modtyp_decl -> (
54+ | Sig_modtype (id , mtd , v ) -> (
5555 match Env. find_modtype_index id ref_env with
5656 | Some _ ->
5757 let new_id = Ident. rename id in
5858 ( Subst. add_modtype id (Mty_ident (Pident new_id)) subst,
5959 Sig_modtype (new_id, mtd, v) :: lst )
60- | None -> (subst, sig_modtyp_decl :: lst))
60+ | None ->
61+ (* This is a special case for functor paramters.
62+ When two functors have different parameters,
63+ they might treated equally by Includemod.modtypes, thus
64+ one of parameters' id has to be rewritten. For example:
65+ module F (M : X) : A and module F (M : Y) : A
66+ X and Y could have the same stamp, thus they would be
67+ treated equally, so Y stamp has to be rewritten.
68+ Note: This should be removed once we have fine-grained
69+ diffing of functors *)
70+ let new_id = ref (Ident. rename id) in
71+ while Option. is_some (Env. find_modtype_index ! new_id ref_env) do
72+ new_id := Ident. rename id
73+ done ;
74+ ( Subst. add_modtype id (Mty_ident (Pident ! new_id)) subst,
75+ Sig_modtype (! new_id, mtd, v) :: lst ))
6176 | Sig_value (id , vd , v ) as sig_val -> (
6277 match Env. find_value_index id ref_env with
6378 | Some _ ->
@@ -117,9 +132,17 @@ let pair_items ~reference ~current =
117132 | _ -> subst)
118133 Subst. identity current
119134
135+ let initialized_env =
136+ Compmisc. init_path () ;
137+ let env = Compmisc. initial_env () in
138+ fun () -> env
139+
120140let for_diff ~reference ~current =
121141 let current = replace_matching_ids ~reference ~current in
122- let env = Env. add_signature reference (Env. in_signature true Env. empty) in
142+ let reference = replace_matching_ids ~reference: current ~current: reference in
143+ let env =
144+ Env. add_signature reference (Env. in_signature true (initialized_env () ))
145+ in
123146 let env = Env. add_signature current env in
124147 let subst = pair_items ~reference ~current in
125148 let modified_current = apply_subst subst current in
@@ -155,6 +178,10 @@ let pp fmt t =
155178 (match mp with
156179 | Mp_present -> " Mp_present"
157180 | Mp_absent -> " Mp_absent" );
181+ (match md_type with
182+ | Mty_functor (Named (Some pid , _pmt ), _fmt ) ->
183+ Ident. print Format. std_formatter pid
184+ | _ -> () );
158185 Format. fprintf fmt " %a" Printtyp. modtype md_type)
159186 | Env_modtype (s , id , mtyp ) ->
160187 pp_rec s;
0 commit comments