From afa7173d93f71979ee5b876a4a7e137c1491d379 Mon Sep 17 00:00:00 2001 From: Leo White Date: Fri, 30 Nov 2018 10:02:33 +0000 Subject: [PATCH 1/2] Apply substitution to all modules when packing --- typing/typemod.ml | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/typing/typemod.ml b/typing/typemod.ml index af93876cc..1162d982a 100644 --- a/typing/typemod.ml +++ b/typing/typemod.ml @@ -2484,18 +2484,31 @@ let type_interface sourcefile env ast = (* "Packaging" of several compilation units into one unit having them as sub-modules. *) -let rec package_signatures subst = function - [] -> [] - | (name, sg) :: rem -> - let sg' = Subst.signature subst sg in - let oldid = Ident.create_persistent name - and newid = Ident.create_local name in - Sig_module(newid, Mp_present, {md_type=Mty_signature sg'; - md_attributes=[]; - md_loc=Location.none; - }, - Trec_not, Exported) :: - package_signatures (Subst.add_module oldid (Pident newid) subst) rem +let package_signatures units = + let units_with_ids = + List.map + (fun (name, sg) -> + let oldid = Ident.create_persistent name in + let newid = Ident.create_local name in + (oldid, newid, sg)) + units + in + let subst = + List.fold_left + (fun acc (oldid, newid, _) -> + Subst.add_module oldid (Pident newid) acc) + Subst.identity units_with_ids + in + List.map + (fun (_, newid, sg) -> + let sg = Subst.signature subst sg in + let md = + { md_type=Mty_signature sg; + md_attributes=[]; + md_loc=Location.none; } + in + Sig_module(newid, Mp_present, md, Trec_not, Exported)) + units_with_ids let package_units initial_env objfiles cmifile modulename = (* Read the signatures of the units *) @@ -2513,7 +2526,7 @@ let package_units initial_env objfiles cmifile modulename = objfiles in (* Compute signature of packaged unit *) Ident.reinit(); - let sg = package_signatures Subst.identity units in + let sg = package_signatures units in (* See if explicit interface is provided *) let prefix = Filename.remove_extension cmifile in let mlifile = prefix ^ !Config.interface_suffix in From f0cd88623ee7893cfbce81e0771c30d8c0abbe71 Mon Sep 17 00:00:00 2001 From: Leo White Date: Sat, 1 Dec 2018 16:20:41 +0000 Subject: [PATCH 2/2] Add Changes entry --- Changes | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Changes b/Changes index 553316b97..0af0bd53a 100644 --- a/Changes +++ b/Changes @@ -703,6 +703,8 @@ Working version - GPR#2131: fix wrong calls to Env.normalize_path on non-module paths (Alain Frisch, review by Jacques Garrigue) +- GPR#2175: Apply substitution to all modules when packing + (Leo White, review by Gabriel Scherer) OCaml 4.07.1 (4 October 2018) -----------------------------