Skip to content

Commit

Permalink
Simplifications following PR #1667 (#1668)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lukemaurer authored Aug 3, 2023
1 parent 81cce63 commit a493702
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
10 changes: 3 additions & 7 deletions ocaml/typing/env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 ()

Expand Down
21 changes: 6 additions & 15 deletions ocaml/typing/persistent_env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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 =
Expand All @@ -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)

Expand Down

0 comments on commit a493702

Please sign in to comment.