From 4092fa257659cd72db0b8868d02da160ce74d483 Mon Sep 17 00:00:00 2001 From: Luke Maurer Date: Mon, 31 Jul 2023 14:48:43 +0100 Subject: [PATCH] Simplifications following PR #1667 A couple of small simplifications that are obvious by themselves but would have made #1667 a bit harder to review: * `Env.sign_of_cmi` is only called via `read_sign_of_cmi` with `~freshen:true`, so just rename `sign_of_cmi` to `read_sign_of_cmi` and freshen unconditionally * `Persistent_env.save_pers_struct` requires a `pers_struct` but doesn't use all of it, so split out its arguments --- ocaml/typing/env.ml | 10 +++------- ocaml/typing/persistent_env.ml | 21 ++++++--------------- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/ocaml/typing/env.ml b/ocaml/typing/env.ml index a88a08e9167..18b15db6c2e 100644 --- a/ocaml/typing/env.ml +++ b/ocaml/typing/env.ml @@ -926,7 +926,7 @@ let components_of_module ~alerts ~uid env ps path addr mty shape = } } -let sign_of_cmi ~freshen { Persistent_env.Persistent_signature.cmi; _ } = +let read_sign_of_cmi { Persistent_env.Persistent_signature.cmi; _ } = let name = cmi.cmi_name in let sign = cmi.cmi_sign in let flags = cmi.cmi_flags in @@ -954,10 +954,8 @@ let sign_of_cmi ~freshen { Persistent_env.Persistent_signature.cmi; _ } = let mda_components = let mty = Subst.Lazy.Mty_signature sign in let mty = - if freshen then - Subst.Lazy.modtype (Subst.Rescope (Path.scope path)) - Subst.identity mty - else mty + Subst.Lazy.modtype (Subst.Rescope (Path.scope path)) + Subst.identity mty in components_of_module ~alerts ~uid:md.md_uid empty Subst.identity @@ -970,8 +968,6 @@ let sign_of_cmi ~freshen { Persistent_env.Persistent_signature.cmi; _ } = mda_shape; } -let read_sign_of_cmi = sign_of_cmi ~freshen:true - let persistent_env : module_data Persistent_env.t ref = s_table Persistent_env.empty () diff --git a/ocaml/typing/persistent_env.ml b/ocaml/typing/persistent_env.ml index 41ef8a01bad..3e1e67b68f1 100644 --- a/ocaml/typing/persistent_env.ml +++ b/ocaml/typing/persistent_env.ml @@ -168,17 +168,17 @@ let fold {persistent_structures; _} f x = (* Reading persistent structures from .cmi files *) -let save_pers_struct penv crc ps = +let save_pers_struct penv crc comp_unit flags filename = let {crc_units; _} = penv in - let modname = CU.name ps.ps_name in + let modname = CU.name comp_unit in List.iter (function | Rectypes -> () | Alerts _ -> () | Unsafe_string -> () | Opaque -> register_import_as_opaque penv modname) - ps.ps_flags; - Consistbl.set crc_units modname ps.ps_name crc ps.ps_filename; + flags; + Consistbl.set crc_units modname comp_unit crc filename; add_import penv modname let acknowledge_pers_struct penv check modname pers_sig pm = @@ -385,7 +385,7 @@ let save_cmi penv psig = let { cmi_name = modname; cmi_sign = _; - cmi_crcs = imports; + cmi_crcs = _; cmi_flags = flags; } = cmi in let crc = @@ -394,16 +394,7 @@ let save_cmi penv psig = (fun temp_filename oc -> output_cmi temp_filename oc cmi) in (* Enter signature in consistbl so that imports() will also return its crc *) - let ps = - { ps_name = modname; - ps_crcs = - Array.append - [| Import_info.create_normal cmi.cmi_name ~crc:(Some crc) |] - imports; - ps_filename = filename; - ps_flags = flags; - } in - save_pers_struct penv crc ps + save_pers_struct penv crc modname flags filename ) ~exceptionally:(fun () -> remove_file filename)