Skip to content

Commit d4b13aa

Browse files
committed
Split Import_info.t into Import_info.{Intf,Impl}.t
This improves clarity, since every `Import.t` is statically either an interface import or an implementation import and they don't support quite the same operations. In particular, every implementation import (being an import of a .cmo/x file) must have a fully-specified compilation unit, whereas in implementation import might only have a name (with unknown pack prefix). Produced by reverting commit 4bd7544 from the 'instance-typing' branch.
1 parent 8bdbcf9 commit d4b13aa

33 files changed

+171
-141
lines changed

backend/asmlibrarian.ml

+5-4
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,12 @@ let create_archive file_list lib_name =
7474
let cmxs = Array.of_list cmxs in
7575
let cmi_index = Compilation_unit.Name.Tbl.create 42 in
7676
Array.iteri (fun i import ->
77-
Compilation_unit.Name.Tbl.add cmi_index (Import_info.name import) i)
77+
Compilation_unit.Name.Tbl.add cmi_index
78+
(Import_info.Intf.name import) i)
7879
cmis;
7980
let cmx_index = Compilation_unit.Tbl.create 42 in
8081
Array.iteri (fun i import ->
81-
Compilation_unit.Tbl.add cmx_index (Import_info.cu import) i)
82+
Compilation_unit.Tbl.add cmx_index (Import_info.Impl.cu import) i)
8283
cmxs;
8384
let genfns = Cmm_helpers.Generic_fns_tbl.make () in
8485
let mk_bitmap arr ix entries ~find ~get_name =
@@ -97,11 +98,11 @@ let create_archive file_list lib_name =
9798
li_imports_cmi =
9899
mk_bitmap cmis cmi_index unit.ui_imports_cmi
99100
~find:Compilation_unit.Name.Tbl.find
100-
~get_name:Import_info.name;
101+
~get_name:Import_info.Intf.name;
101102
li_imports_cmx =
102103
mk_bitmap cmxs cmx_index unit.ui_imports_cmx
103104
~find:Compilation_unit.Tbl.find
104-
~get_name:Import_info.cu })
105+
~get_name:Import_info.Impl.cu })
105106
descr_list
106107
in
107108
let infos =

backend/asmlink.ml

+7-7
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ let check_cmi_consistency file_name cmis =
6161
try
6262
Array.iter
6363
(fun import ->
64-
let name = Import_info.name import in
65-
let crco = Import_info.crc_with_unit import in
64+
let name = Import_info.Intf.name import in
65+
let crco = Import_info.Intf.crc_with_unit import in
6666
CU.Name.Tbl.replace interfaces name ();
6767
match crco with
6868
None -> ()
@@ -80,8 +80,8 @@ let check_cmx_consistency file_name cmxs =
8080
try
8181
Array.iter
8282
(fun import ->
83-
let name = Import_info.cu import in
84-
let crco = Import_info.crc import in
83+
let name = Import_info.Impl.cu import in
84+
let crco = Import_info.Impl.crc import in
8585
implementations := name :: !implementations;
8686
match crco with
8787
None ->
@@ -115,15 +115,15 @@ let check_consistency ~unit cmis cmxs =
115115
let extract_crc_interfaces () =
116116
CU.Name.Tbl.fold (fun name () crcs ->
117117
let crc_with_unit = Cmi_consistbl.find crc_interfaces name in
118-
Import_info.create name ~crc_with_unit :: crcs)
118+
Import_info.Intf.create name ~crc_with_unit :: crcs)
119119
interfaces
120120
[]
121121

122122
let extract_crc_implementations () =
123123
Cmx_consistbl.extract !implementations crc_implementations
124124
|> List.map (fun (cu, crc) ->
125125
let crc = Option.map (fun ((), crc) -> crc) crc in
126-
Import_info.create_normal cu ~crc)
126+
Import_info.Impl.create cu ~crc)
127127

128128
(* Add C objects and options and "custom" info from a library descriptor.
129129
See bytecomp/bytelink.ml for comments on the order of C objects. *)
@@ -159,7 +159,7 @@ let is_required name =
159159
with Not_found -> false
160160

161161
let add_required by import =
162-
let name = Import_info.cu import in
162+
let name = Import_info.Impl.cu import in
163163
try
164164
let rq = Hashtbl.find missing_globals name in
165165
rq := by :: !rq

backend/asmlink.mli

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ val cached_generic_functions : (module Compiler_owee.Unix_intf.S) -> ppf_dump:fo
3030

3131
val reset : unit -> unit
3232
val check_consistency: filepath -> Cmx_format.unit_infos -> Digest.t -> unit
33-
val extract_crc_interfaces: unit -> Import_info.t list
34-
val extract_crc_implementations: unit -> Import_info.t list
33+
val extract_crc_interfaces: unit -> Import_info.Intf.t list
34+
val extract_crc_implementations: unit -> Import_info.Impl.t list
3535

3636
type error =
3737
| File_not_found of filepath

backend/asmpackager.ml

+11-6
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ let check_units members =
7272
| PM_impl infos ->
7373
List.iter
7474
(fun import ->
75-
let unit = Import_info.cu import in
75+
let unit = Import_info.Impl.cu import in
7676
let name = CU.name unit in
7777
if List.mem name forbidden
7878
then raise(Error(Forward_reference(mb.pm_file, name))))
@@ -188,9 +188,14 @@ let get_approx ui : Clambda.value_approximation =
188188
let build_package_cmx members cmxfile =
189189
let unit_names =
190190
List.map (fun m -> m.pm_name) members in
191-
let filter lst =
191+
let filter_cmi lst =
192192
List.filter (fun import ->
193-
not (List.mem (Import_info.name import) unit_names)) lst in
193+
not (List.mem (Import_info.Intf.name import) unit_names)) lst
194+
in
195+
let filter_cmx lst =
196+
List.filter (fun import ->
197+
let name = Compilation_unit.name (Import_info.Impl.cu import) in
198+
not (List.mem name unit_names)) lst in
194199
let union lst =
195200
List.fold_left
196201
(List.fold_left
@@ -233,11 +238,11 @@ let build_package_cmx members cmxfile =
233238
List.flatten (List.map (fun info -> info.ui_defines) units) @
234239
[ui.ui_unit];
235240
ui_imports_cmi =
236-
(Import_info.create modname
241+
(Import_info.Intf.create modname
237242
~crc_with_unit:(Some (ui.ui_unit, Env.crc_of_unit modname))) ::
238-
filter (Asmlink.extract_crc_interfaces ());
243+
filter_cmi (Asmlink.extract_crc_interfaces ());
239244
ui_imports_cmx =
240-
filter(Asmlink.extract_crc_implementations());
245+
filter_cmx(Asmlink.extract_crc_implementations());
241246
ui_generic_fns =
242247
{ curry_fun =
243248
union(List.map (fun info -> info.ui_generic_fns.curry_fun) units);

file_formats/cmx_format.mli

+6-6
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ type unit_infos =
5959
(* All compilation units in the
6060
.cmx file (i.e. [ui_unit] and
6161
any produced via [Asmpackager]) *)
62-
mutable ui_imports_cmi: Import_info.t list;
62+
mutable ui_imports_cmi: Import_info.Intf.t list;
6363
(* Interfaces imported *)
64-
mutable ui_imports_cmx: Import_info.t list;
64+
mutable ui_imports_cmx: Import_info.Impl.t list;
6565
(* Infos imported *)
6666
mutable ui_generic_fns: generic_fns; (* Generic functions needed *)
6767
mutable ui_export_info: export_info;
@@ -71,8 +71,8 @@ type unit_infos =
7171
type unit_infos_raw =
7272
{ uir_unit: Compilation_unit.t;
7373
uir_defines: Compilation_unit.t list;
74-
uir_imports_cmi: Import_info.t array;
75-
uir_imports_cmx: Import_info.t array;
74+
uir_imports_cmi: Import_info.Intf.t array;
75+
uir_imports_cmx: Import_info.Impl.t array;
7676
uir_generic_fns: generic_fns;
7777
uir_export_info: export_info_raw;
7878
uir_checks: Checks.Raw.t;
@@ -95,8 +95,8 @@ type lib_unit_info =
9595
li_imports_cmx : Bitmap.t } (* subset of lib_imports_cmx *)
9696

9797
type library_infos =
98-
{ lib_imports_cmi: Import_info.t array;
99-
lib_imports_cmx: Import_info.t array;
98+
{ lib_imports_cmi: Import_info.Intf.t array;
99+
lib_imports_cmx: Import_info.Impl.t array;
100100
lib_units: lib_unit_info list;
101101
lib_generic_fns: generic_fns;
102102
(* In the following fields the lists are reversed with respect to

middle_end/compilenv.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ let get_unit_info comp_unit =
205205
(None, None)
206206
end
207207
in
208-
let import = Import_info.create_normal comp_unit ~crc in
208+
let import = Import_info.Impl.create comp_unit ~crc in
209209
current_unit.ui_imports_cmx <- import :: current_unit.ui_imports_cmx;
210210
CU.Name.Tbl.add global_infos_table cmx_name infos;
211211
infos

ocaml/boot/ocamlc

-88 Bytes
Binary file not shown.

ocaml/bytecomp/bytelink.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ let check_consistency file_name cu =
184184
begin try
185185
Array.iter
186186
(fun import ->
187-
let name = Import_info.name import in
188-
let crco = Import_info.crc_with_unit import in
187+
let name = Import_info.Intf.name import in
188+
let crco = Import_info.Intf.crc_with_unit import in
189189
interfaces := name :: !interfaces;
190190
match crco with
191191
None -> ()
@@ -215,7 +215,7 @@ let check_consistency file_name cu =
215215
let extract_crc_interfaces () =
216216
Consistbl.extract !interfaces crc_interfaces
217217
|> List.map (fun (name, crc_with_unit) ->
218-
Import_info.create name ~crc_with_unit)
218+
Import_info.Intf.create name ~crc_with_unit)
219219

220220
let clear_crc_interfaces () =
221221
Consistbl.clear crc_interfaces;

ocaml/bytecomp/bytelink.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ val reset : unit -> unit
2222

2323
val check_consistency: filepath -> Cmo_format.compilation_unit_descr -> unit
2424

25-
val extract_crc_interfaces: unit -> Import_info.t list
25+
val extract_crc_interfaces: unit -> Import_info.Intf.t list
2626

2727
type error =
2828
| File_not_found of filepath

ocaml/bytecomp/bytepackager.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ let package_object_files ~ppf_dump files targetfile targetname coercion =
224224
let pos_final = pos_out oc in
225225
let imports =
226226
List.filter
227-
(fun import -> not (List.mem (Import_info.name import) unit_names))
227+
(fun import -> not (List.mem (Import_info.Intf.name import) unit_names))
228228
(Bytelink.extract_crc_interfaces()) in
229229
let for_pack_prefix = CU.Prefix.from_clflags () in
230230
let modname = targetname |> CU.Name.of_string in
@@ -236,7 +236,7 @@ let package_object_files ~ppf_dump files targetfile targetname coercion =
236236
cu_reloc = List.rev !relocs;
237237
cu_imports =
238238
Array.of_list
239-
((Import_info.create modname
239+
((Import_info.Intf.create modname
240240
~crc_with_unit:(Some (cu_name, Env.crc_of_unit modname)))
241241
:: imports);
242242
cu_primitives = !primitives;

ocaml/bytecomp/symtable.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ let init_toplevel () =
316316
(* Recover CRC infos for interfaces *)
317317
let crcintfs =
318318
try
319-
(Obj.magic (sect.read_struct "CRCS") : Import_info.t array)
319+
(Obj.magic (sect.read_struct "CRCS") : Import_info.Intf.t array)
320320
with Not_found -> [| |] in
321321
(* Done *)
322322
sect.close_reader();

ocaml/bytecomp/symtable.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ val transl_const: Lambda.structured_constant -> Obj.t
3232

3333
(* Functions for the toplevel *)
3434

35-
val init_toplevel: unit -> Import_info.t array
35+
val init_toplevel: unit -> Import_info.Intf.t array
3636
val update_global_table: unit -> unit
3737
val get_global_value: Ident.t -> Obj.t
3838
val is_global_defined: Ident.t -> bool

ocaml/file_formats/cmi_format.ml

+5-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ module Serialized = Types.Make_wrapped(struct type 'a t = int end)
5252
(* these type abbreviations are not exported;
5353
they are used to provide consistency across
5454
input_value and output_value usage. *)
55-
type crcs = Import_info.t array (* smaller on disk than using a list *)
55+
type crcs = Import_info.Intf.t array (* smaller on disk than using a list *)
5656
type flags = pers_flags list
5757
type header = Compilation_unit.t * Serialized.signature
5858

@@ -170,10 +170,11 @@ let output_cmi filename oc cmi =
170170
output_value oc ((cmi.cmi_name, sign) : header);
171171
flush oc;
172172
let crc = Digest.file filename in
173-
let crcs =
174-
Array.append [| Import_info.create_normal cmi.cmi_name ~crc:(Some crc) |]
175-
cmi.cmi_crcs
173+
let my_info =
174+
Import_info.Intf.create (Compilation_unit.name cmi.cmi_name)
175+
~crc_with_unit:(Some (cmi.cmi_name, crc))
176176
in
177+
let crcs = Array.append [| my_info |] cmi.cmi_crcs in
177178
output_value oc (crcs : crcs);
178179
output_value oc (cmi.cmi_flags : flags);
179180
crc

ocaml/file_formats/cmi_format.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type pers_flags =
2424
type 'sg cmi_infos_generic = {
2525
cmi_name : Compilation_unit.t;
2626
cmi_sign : 'sg;
27-
cmi_crcs : Import_info.t array;
27+
cmi_crcs : Import_info.Intf.t array;
2828
cmi_flags : pers_flags list;
2929
}
3030

ocaml/file_formats/cmo_format.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type compilation_unit_descr =
3030
mutable cu_pos: int; (* Absolute position in file *)
3131
cu_codesize: int; (* Size of code block *)
3232
cu_reloc: (reloc_info * int) list; (* Relocation information *)
33-
cu_imports: Import_info.t array; (* Names and CRC of intfs imported *)
33+
cu_imports: Import_info.Intf.t array; (* Names and CRC of intfs imported *)
3434
cu_required_globals: Compilation_unit.t list;
3535
(* Compilation units whose
3636
initialization side effects

ocaml/file_formats/cmt_format.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type cmt_infos = {
5757
cmt_loadpath : string list;
5858
cmt_source_digest : Digest.t option;
5959
cmt_initial_env : Env.t;
60-
cmt_imports : Import_info.t array;
60+
cmt_imports : Import_info.Intf.t array;
6161
cmt_interface_digest : Digest.t option;
6262
cmt_use_summaries : bool;
6363
cmt_uid_to_loc : Location.t Shape.Uid.Tbl.t;
@@ -176,8 +176,8 @@ let save_cmt filename modname binary_annots sourcefile initial_env cmi shape =
176176
in
177177
let source_digest = Option.map Digest.file sourcefile in
178178
let compare_imports import1 import2 =
179-
let modname1 = Import_info.name import1 in
180-
let modname2 = Import_info.name import2 in
179+
let modname1 = Import_info.Intf.name import1 in
180+
let modname2 = Import_info.Intf.name import2 in
181181
Compilation_unit.Name.compare modname1 modname2
182182
in
183183
let get_imports () =

ocaml/file_formats/cmt_format.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ type cmt_infos = {
6060
cmt_loadpath : string list;
6161
cmt_source_digest : string option;
6262
cmt_initial_env : Env.t;
63-
cmt_imports : Import_info.t array;
63+
cmt_imports : Import_info.Intf.t array;
6464
cmt_interface_digest : Digest.t option;
6565
cmt_use_summaries : bool;
6666
cmt_uid_to_loc : Location.t Shape.Uid.Tbl.t;

ocaml/file_formats/cmx_format.mli

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ type unit_infos =
4545
(* All compilation units in the
4646
.cmx file (i.e. [ui_name] and
4747
any produced via [Asmpackager]) *)
48-
mutable ui_imports_cmi: Import_info.t array;
48+
mutable ui_imports_cmi: Import_info.Intf.t array;
4949
(* Interfaces imported *)
50-
mutable ui_imports_cmx: Import_info.t array;
50+
mutable ui_imports_cmx: Import_info.Impl.t array;
5151
(* Infos imported *)
5252
mutable ui_curry_fun:
5353
(Lambda.function_kind * machtype list * machtype) list;

ocaml/file_formats/cmxs_format.mli

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
type dynunit = {
2323
dynu_name: Compilation_unit.t;
2424
dynu_crc: Digest.t;
25-
dynu_imports_cmi: Import_info.t array;
26-
dynu_imports_cmx: Import_info.t array;
25+
dynu_imports_cmi: Import_info.Intf.t array;
26+
dynu_imports_cmx: Import_info.Impl.t array;
2727
dynu_defines: Compilation_unit.t list;
2828
}
2929

ocaml/middle_end/compilenv.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ let get_unit_info comp_unit =
168168
(None, None)
169169
end
170170
in
171-
let import = Import_info.create_normal comp_unit ~crc in
171+
let import = Import_info.Impl.create comp_unit ~crc in
172172
current_unit.ui_imports_cmx <-
173173
Array.append [| import |] current_unit.ui_imports_cmx;
174174
CU.Name.Tbl.add global_infos_table cmx_name infos;

ocaml/otherlibs/dynlink/dynlink.ml

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ module DC = Dynlink_common
2424
module DT = Dynlink_types
2525

2626
let convert_cmi_import import =
27-
let name = Import_info.name import |> Compilation_unit.Name.to_string in
28-
let crc = Import_info.crc import in
27+
let name = Import_info.Intf.name import |> Compilation_unit.Name.to_string in
28+
let crc = Import_info.Intf.crc import in
2929
name, crc
3030

3131
module Bytecode = struct
@@ -91,8 +91,8 @@ module Bytecode = struct
9191

9292
let fold_initial_units ~init ~f =
9393
Array.fold_left (fun acc import ->
94-
let modname = Import_info.name import in
95-
let crc = Import_info.crc import in
94+
let modname = Import_info.Intf.name import in
95+
let crc = Import_info.Intf.crc import in
9696
let id =
9797
Compilation_unit.to_global_ident_for_bytecode
9898
(assume_no_prefix modname)
@@ -237,8 +237,8 @@ module Native = struct
237237
let crc (t : t) = Some t.dynu_crc
238238

239239
let convert_cmx_import import =
240-
let cu = Import_info.cu import |> Compilation_unit.name_as_string in
241-
let crc = Import_info.crc import in
240+
let cu = Import_info.Impl.cu import |> Compilation_unit.name_as_string in
241+
let crc = Import_info.Impl.crc import in
242242
cu, crc
243243

244244
let interface_imports (t : t) =

ocaml/otherlibs/dynlink/extract_crc.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ let digest_interface unit loadpath =
4545
let crc =
4646
match cmi.Cmi_format.cmi_crcs |> Array.to_list with
4747
import :: _ ->
48-
(match Import_info.crc import with
48+
(match Import_info.Intf.crc import with
4949
| Some crc -> crc
5050
| None -> raise Corrupted_interface)
5151
| _ -> raise Corrupted_interface

0 commit comments

Comments
 (0)