From e7dbaeb8ce8c3156664b8763b676a544ad417b7a Mon Sep 17 00:00:00 2001 From: Leo White Date: Mon, 26 Oct 2020 12:39:43 +0000 Subject: [PATCH] Fix reproducibility for `-no-alias-deps` --- .../reproducibility/cmis_on_file_system.ml | 6 ++-- typing/env.ml | 34 +++++++++++++------ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/testsuite/tests/reproducibility/cmis_on_file_system.ml b/testsuite/tests/reproducibility/cmis_on_file_system.ml index b9761dfca..92066e711 100644 --- a/testsuite/tests/reproducibility/cmis_on_file_system.ml +++ b/testsuite/tests/reproducibility/cmis_on_file_system.ml @@ -4,7 +4,7 @@ ** ocamlc.byte compile_only = "true" module = "cmis_on_file_system.ml" - flags="-bin-annot" + flags="-bin-annot -no-alias-deps -w '-49'" *** script script= "mv cmis_on_file_system.cmt lone.cmt" **** ocamlc.byte @@ -12,7 +12,7 @@ compile_only="true" ***** ocamlc.byte compile_only = "true" - flags="-bin-annot" + flags="-bin-annot -no-alias-deps -w '-49'" module="cmis_on_file_system.ml" ****** compare-binary-files program="cmis_on_file_system.cmt" @@ -24,3 +24,5 @@ at a given point in time *) type t = int let () = () + +module M = Cmis_on_file_system_companion diff --git a/typing/env.ml b/typing/env.ml index 1f35e0d10..108bb71ab 100644 --- a/typing/env.ml +++ b/typing/env.ml @@ -707,20 +707,34 @@ let find_name_module ~mark name tbl = let add_persistent_structure id env = if not (Ident.persistent id) then invalid_arg "Env.add_persistent_structure"; - if not (Current_unit_name.is_ident id) then - let summary = + if Current_unit_name.is_ident id then env + else begin + let material = + (* This addition only observably changes the environment if it shadows a + non-persistent module already in the environment. + (See PR#9345) *) match IdTbl.find_name wrap_module ~mark:false (Ident.name id) env.modules with - | exception Not_found | _, Mod_persistent -> env.summary - | _ -> Env_persistent (env.summary, id) + | exception Not_found | _, Mod_persistent -> false + | _ -> true in - { env with - modules = IdTbl.add id Mod_persistent env.modules; - summary - } - else - env + let summary = + if material then Env_persistent (env.summary, id) + else env.summary + in + let modules = + (* With [-no-alias-deps], non-material additions should not + affect the environment at all. We should only observe the + existence of a cmi when accessing components of the module. + (See #9991). *) + if material || not !Clflags.transparent_modules then + IdTbl.add id Mod_persistent env.modules + else + env.modules + in + { env with modules; summary } + end let components_of_module ~alerts ~uid env fs ps path addr mty = {