Skip to content

Commit

Permalink
flambda-backend: Use Import_info.t in Cmt_format (#1037)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshinwell authored Dec 28, 2022
1 parent 7661d4d commit ecab74c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
23 changes: 10 additions & 13 deletions file_formats/cmt_format.ml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ and binary_part =
| Partial_signature_item of signature_item
| Partial_module_type of module_type

type import_info =
(Compilation_unit.Name.t * (Compilation_unit.t * Digest.t) option)

type cmt_infos = {
cmt_modname : Compilation_unit.t;
cmt_annots : binary_annots;
Expand All @@ -60,7 +57,7 @@ type cmt_infos = {
cmt_loadpath : string list;
cmt_source_digest : Digest.t option;
cmt_initial_env : Env.t;
cmt_imports : import_info list;
cmt_imports : Import_info.t array;
cmt_interface_digest : Digest.t option;
cmt_use_summaries : bool;
cmt_uid_to_loc : Location.t Shape.Uid.Tbl.t;
Expand Down Expand Up @@ -178,16 +175,16 @@ let save_cmt filename modname binary_annots sourcefile initial_env cmi shape =
| Some cmi -> Some (output_cmi temp_file_name oc cmi)
in
let source_digest = Option.map Digest.file sourcefile in
let get_imports () =
Env.imports ()
|> List.map (fun import ->
let name = Import_info.name import in
let crc_with_unit = Import_info.crc_with_unit import in
name, crc_with_unit)
in
let compare_imports (modname1, _crc1) (modname2, _crc2) =
let compare_imports import1 import2 =
let modname1 = Import_info.name import1 in
let modname2 = Import_info.name import2 in
Compilation_unit.Name.compare modname1 modname2
in
let get_imports () =
let imports = Array.of_list (Env.imports ()) in
Array.sort compare_imports imports;
imports
in
let cmt = {
cmt_modname = modname;
cmt_annots = clear_env binary_annots;
Expand All @@ -200,7 +197,7 @@ let save_cmt filename modname binary_annots sourcefile initial_env cmi shape =
cmt_source_digest = source_digest;
cmt_initial_env = if need_to_clear_env then
keep_only_summary initial_env else initial_env;
cmt_imports = List.sort compare_imports (get_imports ());
cmt_imports = get_imports ();
cmt_interface_digest = this_crc;
cmt_use_summaries = need_to_clear_env;
cmt_uid_to_loc = Env.get_uid_to_loc_tbl ();
Expand Down
7 changes: 1 addition & 6 deletions file_formats/cmt_format.mli
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ and binary_part =
| Partial_signature_item of signature_item
| Partial_module_type of module_type

(* CR mshinwell: this should be removed in favour of [Import_info.t],
but will require a new Merlin *)
type import_info =
(Compilation_unit.Name.t * (Compilation_unit.t * Digest.t) option)

type cmt_infos = {
cmt_modname : Compilation_unit.t;
cmt_annots : binary_annots;
Expand All @@ -65,7 +60,7 @@ type cmt_infos = {
cmt_loadpath : string list;
cmt_source_digest : string option;
cmt_initial_env : Env.t;
cmt_imports : import_info list;
cmt_imports : Import_info.t array;
cmt_interface_digest : Digest.t option;
cmt_use_summaries : bool;
cmt_uid_to_loc : Location.t Shape.Uid.Tbl.t;
Expand Down
6 changes: 1 addition & 5 deletions tools/objinfo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ let print_impl_import import =
let crco = Import_info.crc import in
print_name_crc (Compilation_unit.name unit) crco

let print_old_intf_import (name, data) =
let crco = data |> Option.map (fun (_unit, crc) -> crc) in
print_name_crc name crco

let print_line name =
printf "\t%s\n" name

Expand Down Expand Up @@ -123,7 +119,7 @@ let print_cmt_infos cmt =
let open Cmt_format in
printf "Cmt unit name: %a\n" Compilation_unit.output cmt.cmt_modname;
print_string "Cmt interfaces imported:\n";
List.iter print_old_intf_import cmt.cmt_imports;
Array.iter print_intf_import cmt.cmt_imports;
printf "Source file: %s\n"
(match cmt.cmt_sourcefile with None -> "(none)" | Some f -> f);
printf "Compilation flags:";
Expand Down
11 changes: 10 additions & 1 deletion tools/ocamlcmt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,23 @@ let print_info cmt =
let compare_imports (name1, _crco1) (name2, _crco2) =
Compilation_unit.Name.compare name1 name2
in
let imports =
let imports =
Array.map (fun import ->
Import_info.name import, Import_info.crc_with_unit import)
cmt.cmt_imports
in
Array.sort compare_imports imports;
Array.to_list imports
in
List.iter (fun (name, crco) ->
let crc =
match crco with
None -> dummy_crc
| Some (_unit, crc) -> Digest.to_hex crc
in
Printf.fprintf oc "import: %a %s\n" Compilation_unit.Name.output name crc;
) (List.sort compare_imports cmt.cmt_imports);
) imports;
Printf.fprintf oc "%!";
begin match !target_filename with
| None -> ()
Expand Down

0 comments on commit ecab74c

Please sign in to comment.