Skip to content

Commit 90ee37b

Browse files
authored
flambda-backend: Revert "Revert "Use Import_info.t in Cmt_format"" (#1045)
1 parent ac12d90 commit 90ee37b

File tree

4 files changed

+22
-25
lines changed

4 files changed

+22
-25
lines changed

file_formats/cmt_format.ml

+10-13
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ and binary_part =
4545
| Partial_signature_item of signature_item
4646
| Partial_module_type of module_type
4747

48-
type import_info =
49-
(Compilation_unit.Name.t * (Compilation_unit.t * Digest.t) option)
50-
5148
type cmt_infos = {
5249
cmt_modname : Compilation_unit.t;
5350
cmt_annots : binary_annots;
@@ -60,7 +57,7 @@ type cmt_infos = {
6057
cmt_loadpath : string list;
6158
cmt_source_digest : Digest.t option;
6259
cmt_initial_env : Env.t;
63-
cmt_imports : import_info list;
60+
cmt_imports : Import_info.t array;
6461
cmt_interface_digest : Digest.t option;
6562
cmt_use_summaries : bool;
6663
cmt_uid_to_loc : Location.t Shape.Uid.Tbl.t;
@@ -178,16 +175,16 @@ let save_cmt filename modname binary_annots sourcefile initial_env cmi shape =
178175
| Some cmi -> Some (output_cmi temp_file_name oc cmi)
179176
in
180177
let source_digest = Option.map Digest.file sourcefile in
181-
let get_imports () =
182-
Env.imports ()
183-
|> List.map (fun import ->
184-
let name = Import_info.name import in
185-
let crc_with_unit = Import_info.crc_with_unit import in
186-
name, crc_with_unit)
187-
in
188-
let compare_imports (modname1, _crc1) (modname2, _crc2) =
178+
let compare_imports import1 import2 =
179+
let modname1 = Import_info.name import1 in
180+
let modname2 = Import_info.name import2 in
189181
Compilation_unit.Name.compare modname1 modname2
190182
in
183+
let get_imports () =
184+
let imports = Array.of_list (Env.imports ()) in
185+
Array.sort compare_imports imports;
186+
imports
187+
in
191188
let cmt = {
192189
cmt_modname = modname;
193190
cmt_annots = clear_env binary_annots;
@@ -200,7 +197,7 @@ let save_cmt filename modname binary_annots sourcefile initial_env cmi shape =
200197
cmt_source_digest = source_digest;
201198
cmt_initial_env = if need_to_clear_env then
202199
keep_only_summary initial_env else initial_env;
203-
cmt_imports = List.sort compare_imports (get_imports ());
200+
cmt_imports = get_imports ();
204201
cmt_interface_digest = this_crc;
205202
cmt_use_summaries = need_to_clear_env;
206203
cmt_uid_to_loc = Env.get_uid_to_loc_tbl ();

file_formats/cmt_format.mli

+1-6
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ and binary_part =
4848
| Partial_signature_item of signature_item
4949
| Partial_module_type of module_type
5050

51-
(* CR mshinwell: this should be removed in favour of [Import_info.t],
52-
but will require a new Merlin *)
53-
type import_info =
54-
(Compilation_unit.Name.t * (Compilation_unit.t * Digest.t) option)
55-
5651
type cmt_infos = {
5752
cmt_modname : Compilation_unit.t;
5853
cmt_annots : binary_annots;
@@ -65,7 +60,7 @@ type cmt_infos = {
6560
cmt_loadpath : string list;
6661
cmt_source_digest : string option;
6762
cmt_initial_env : Env.t;
68-
cmt_imports : import_info list;
63+
cmt_imports : Import_info.t array;
6964
cmt_interface_digest : Digest.t option;
7065
cmt_use_summaries : bool;
7166
cmt_uid_to_loc : Location.t Shape.Uid.Tbl.t;

tools/objinfo.ml

+1-5
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ let print_impl_import import =
7070
let crco = Import_info.crc import in
7171
print_name_crc (Compilation_unit.name unit) crco
7272

73-
let print_old_intf_import (name, data) =
74-
let crco = data |> Option.map (fun (_unit, crc) -> crc) in
75-
print_name_crc name crco
76-
7773
let print_line name =
7874
printf "\t%s\n" name
7975

@@ -123,7 +119,7 @@ let print_cmt_infos cmt =
123119
let open Cmt_format in
124120
printf "Cmt unit name: %a\n" Compilation_unit.output cmt.cmt_modname;
125121
print_string "Cmt interfaces imported:\n";
126-
List.iter print_old_intf_import cmt.cmt_imports;
122+
Array.iter print_intf_import cmt.cmt_imports;
127123
printf "Source file: %s\n"
128124
(match cmt.cmt_sourcefile with None -> "(none)" | Some f -> f);
129125
printf "Compilation flags:";

tools/ocamlcmt.ml

+10-1
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,23 @@ let print_info cmt =
8585
let compare_imports (name1, _crco1) (name2, _crco2) =
8686
Compilation_unit.Name.compare name1 name2
8787
in
88+
let imports =
89+
let imports =
90+
Array.map (fun import ->
91+
Import_info.name import, Import_info.crc_with_unit import)
92+
cmt.cmt_imports
93+
in
94+
Array.sort compare_imports imports;
95+
Array.to_list imports
96+
in
8897
List.iter (fun (name, crco) ->
8998
let crc =
9099
match crco with
91100
None -> dummy_crc
92101
| Some (_unit, crc) -> Digest.to_hex crc
93102
in
94103
Printf.fprintf oc "import: %a %s\n" Compilation_unit.Name.output name crc;
95-
) (List.sort compare_imports cmt.cmt_imports);
104+
) imports;
96105
Printf.fprintf oc "%!";
97106
begin match !target_filename with
98107
| None -> ()

0 commit comments

Comments
 (0)