@@ -25,40 +25,40 @@ module CU = Compilation_unit
2525type error =
2626 | File_not_found of filepath
2727 | Not_an_object_file of filepath
28- | Missing_implementations of (Linkage_name .t * string list ) list
28+ | Missing_implementations of (CU .t * string list ) list
2929 | Inconsistent_interface of CU.Name .t * filepath * filepath
30- | Inconsistent_implementation of CU.Name . t * filepath * filepath
30+ | Inconsistent_implementation of CU .t * filepath * filepath
3131 | Assembler_error of filepath
3232 | Linking_error of int
3333 | Multiple_definition of CU.Name .t * filepath * filepath
34- | Missing_cmx of filepath * CU.Name . t
34+ | Missing_cmx of filepath * CU .t
3535
3636exception Error of error
3737
3838(* Consistency check between interfaces and implementations *)
3939
40- module Cmi_consistbl = Consistbl. Make (CU. Name )
40+ module Cmi_consistbl = Consistbl. Make (CU. Name ) ( CU )
4141let crc_interfaces = Cmi_consistbl. create ()
4242let interfaces = ref ([] : CU.Name.t list )
4343
44- module Cmx_consistbl = Consistbl. Make (CU. Name )
44+ module Cmx_consistbl = Consistbl. Make (CU ) ( Unit )
4545let crc_implementations = Cmx_consistbl. create ()
46- let implementations = ref ([] : CU.Name. t list )
47- let implementations_defined = ref ([] : (CU.Name. t * string ) list )
48- let cmx_required = ref ([] : CU.Name. t list )
46+ let implementations = ref ([] : CU.t list )
47+ let implementations_defined = ref ([] : (CU.t * string ) list )
48+ let cmx_required = ref ([] : CU.t list )
4949
5050let check_consistency file_name unit crc =
5151 begin try
5252 List. iter
5353 (fun (name , crco ) ->
54- let name = CU.Name. of_string name in
5554 interfaces := name :: ! interfaces;
5655 match crco with
5756 None -> ()
58- | Some crc ->
57+ | Some ( full_name , crc ) ->
5958 if CU.Name. equal name (CU. name unit .ui_unit)
60- then Cmi_consistbl. set crc_interfaces name crc file_name
61- else Cmi_consistbl. check crc_interfaces name crc file_name)
59+ then Cmi_consistbl. set crc_interfaces name full_name crc file_name
60+ else
61+ Cmi_consistbl. check crc_interfaces name full_name crc file_name)
6262 unit .ui_imports_cmi
6363 with Cmi_consistbl. Inconsistency {
6464 unit_name = name;
@@ -70,14 +70,13 @@ let check_consistency file_name unit crc =
7070 begin try
7171 List. iter
7272 (fun (name , crco ) ->
73- let name = name |> CU.Name. of_string in
7473 implementations := name :: ! implementations;
7574 match crco with
7675 None ->
7776 if List. mem name ! cmx_required then
7877 raise(Error (Missing_cmx (file_name, name)))
7978 | Some crc ->
80- Cmx_consistbl. check crc_implementations name crc file_name)
79+ Cmx_consistbl. check crc_implementations name () crc file_name)
8180 unit .ui_imports_cmx
8281 with Cmx_consistbl. Inconsistency {
8382 unit_name = name;
@@ -88,25 +87,22 @@ let check_consistency file_name unit crc =
8887 end ;
8988 let ui_name = CU. name unit .ui_unit in
9089 begin try
91- let source = List. assoc ui_name ! implementations_defined in
92- raise (Error (Multiple_definition (CU. name unit .ui_unit , file_name, source)))
90+ let source = List. assoc unit .ui_unit ! implementations_defined in
91+ raise (Error (Multiple_definition (ui_name , file_name, source)))
9392 with Not_found -> ()
9493 end ;
95- implementations := ui_name :: ! implementations;
96- Cmx_consistbl. set crc_implementations ui_name crc file_name;
94+ implementations := unit .ui_unit :: ! implementations;
95+ Cmx_consistbl. set crc_implementations unit .ui_unit () crc file_name;
9796 implementations_defined :=
98- (ui_name , file_name) :: ! implementations_defined;
97+ (unit .ui_unit , file_name) :: ! implementations_defined;
9998 if CU. is_packed unit .ui_unit then
100- cmx_required := ui_name :: ! cmx_required
99+ cmx_required := unit .ui_unit :: ! cmx_required
101100
102- let extract_crc_interfaces0 () =
103- Cmi_consistbl. extract ! interfaces crc_interfaces
104101let extract_crc_interfaces () =
105- extract_crc_interfaces0 ()
106- |> List. map (fun (name , crc ) -> (name |> CU.Name. to_string, crc))
102+ Cmi_consistbl. extract ! interfaces crc_interfaces
107103let extract_crc_implementations () =
108104 Cmx_consistbl. extract ! implementations crc_implementations
109- |> List. map (fun (name , crc ) -> ( name |> CU.Name. to_string, crc) )
105+ |> List. map (fun (name , crco ) -> name, Option. map snd crco )
110106
111107(* Add C objects and options and "custom" info from a library descriptor.
112108 See bytecomp/bytelink.ml for comments on the order of C objects. *)
@@ -135,7 +131,7 @@ let runtime_lib () =
135131
136132let missing_globals =
137133 (Hashtbl. create 17 :
138- (Linkage_name . t, string list ref ) Hashtbl. t)
134+ (CU . t, string list ref ) Hashtbl. t)
139135
140136let is_required name =
141137 try ignore (Hashtbl. find missing_globals name); true
@@ -193,26 +189,17 @@ let read_file obj_name =
193189 end
194190 else raise(Error (Not_an_object_file file_name))
195191
196- let linkage_name_of_modname modname =
192+ let assume_no_prefix modname =
197193 (* We're the linker, so we assume that everything's already been packed, so
198194 no module needs its prefix considered. *)
199- modname |> Linkage_name. of_string
195+ CU. create CU.Prefix. empty modname
200196
201197let scan_file file tolink =
202198 match file with
203199 | Unit (file_name ,info ,crc ) ->
204200 (* This is a .cmx file. It must be linked in any case. *)
205- let linkage_name =
206- info.ui_unit
207- |> Compilation_unit. name
208- |> Compilation_unit.Name. to_string
209- |> linkage_name_of_modname
210- in
211- remove_required linkage_name;
212- List. iter (fun (name , crc ) ->
213- let name = name |> linkage_name_of_modname in
214- add_required file_name (name, crc))
215- info.ui_imports_cmx;
201+ remove_required info.ui_unit;
202+ List. iter (add_required file_name) info.ui_imports_cmx;
216203 (info, file_name, crc) :: tolink
217204 | Library (file_name ,infos ) ->
218205 (* This is an archive file. Each unit contained in it will be linked
@@ -221,20 +208,15 @@ let scan_file file tolink =
221208 List. fold_right
222209 (fun (info , crc ) reqd ->
223210 let ui_name = CU. name info.ui_unit in
224- let linkage_name =
225- ui_name |> CU.Name. to_string |> linkage_name_of_modname
226- in
227211 if info.ui_force_link
228212 || ! Clflags. link_everything
229- || is_required linkage_name
213+ || is_required info.ui_unit
230214 then begin
231- remove_required linkage_name ;
215+ remove_required info.ui_unit ;
232216 let req_by =
233217 Printf. sprintf " %s(%s)" file_name (ui_name |> CU.Name. to_string)
234218 in
235- info.ui_imports_cmx |> List. iter (fun (modname , digest ) ->
236- let linkage_name = modname |> Linkage_name. of_string in
237- add_required req_by (linkage_name, digest));
219+ List. iter (add_required req_by) info.ui_imports_cmx;
238220 (info, file_name, crc) :: reqd
239221 end else
240222 reqd)
@@ -254,22 +236,24 @@ let make_globals_map units_list ~crc_interfaces =
254236 let defined =
255237 List. map (fun (unit , _ , impl_crc ) ->
256238 let name = CU. name unit .ui_unit in
257- let intf_crc = CU.Name.Tbl. find crc_interfaces name in
239+ let intf_crc =
240+ CU.Name.Tbl. find crc_interfaces name
241+ |> Option. map (fun (_unit , crc ) -> crc)
242+ in
258243 CU.Name.Tbl. remove crc_interfaces name;
259244 let syms = List. map Symbol. for_compilation_unit unit .ui_defines in
260- (name , intf_crc, Some impl_crc, syms))
245+ (unit .ui_unit , intf_crc, Some impl_crc, syms))
261246 units_list
262247 in
263248 CU.Name.Tbl. fold (fun name intf acc ->
264- (name, intf, None , [] ) :: acc)
249+ let intf = Option. map (fun (_unit , crc ) -> crc) intf in
250+ (assume_no_prefix name, intf, None , [] ) :: acc)
265251 crc_interfaces defined
266252
267253let make_startup_file ~ppf_dump units_list ~crc_interfaces =
268254 let compile_phrase p = Asmgen. compile_phrase ~ppf_dump p in
269255 Location. input_name := " caml_startup" ; (* set name of "current" input *)
270- let startup_comp_unit =
271- CU. create CU.Prefix. empty (CU.Name. of_string " _startup" )
272- in
256+ let startup_comp_unit = CU. of_string " _startup" in
273257 Compilenv. reset startup_comp_unit;
274258 Emit. begin_assembly () ;
275259 let name_list =
@@ -390,16 +374,14 @@ let link ~ppf_dump objfiles output_name =
390374 else stdlib :: (objfiles @ [stdexit]) in
391375 let obj_infos = List. map read_file objfiles in
392376 let units_tolink = List. fold_right scan_file obj_infos [] in
393- Array. iter (fun name -> remove_required (name |> Linkage_name. of_string))
394- Runtimedef. builtin_exceptions;
395377 begin match extract_missing_globals() with
396378 [] -> ()
397379 | mg -> raise(Error (Missing_implementations mg))
398380 end ;
399381 List. iter
400382 (fun (info , file_name , crc ) -> check_consistency file_name info crc)
401383 units_tolink;
402- let crc_interfaces = extract_crc_interfaces0 () in
384+ let crc_interfaces = extract_crc_interfaces () in
403385 Clflags. ccobjs := ! Clflags. ccobjs @ ! lib_ccobjs;
404386 Clflags. all_ccopts := ! lib_ccopts @ ! Clflags. all_ccopts;
405387 (* put user's opts first *)
@@ -439,7 +421,7 @@ let report_error ppf = function
439421 List. iter
440422 (fun (md , rq ) ->
441423 fprintf ppf " @ @[<hov 2>%a referenced from %a@]"
442- Linkage_name . print md
424+ Compilation_unit . print md
443425 print_references rq) in
444426 fprintf ppf
445427 " @[<v 2>No implementations provided for the following modules:%a@]"
@@ -457,7 +439,7 @@ let report_error ppf = function
457439 over implementation %a@]"
458440 Location. print_filename file1
459441 Location. print_filename file2
460- CU.Name. print intf
442+ CU. print intf
461443 | Assembler_error file ->
462444 fprintf ppf " Error while assembling %a" Location. print_filename file
463445 | Linking_error exitcode ->
@@ -476,9 +458,9 @@ let report_error ppf = function
476458 Please recompile %a@ with the correct `-I' option@ \
477459 so that %a.cmx@ is found.@]"
478460 Location. print_filename filename
479- CU.Name. print name
461+ CU. print name
480462 Location. print_filename filename
481- CU.Name. print name
463+ CU.Name. print ( CU. name name)
482464
483465let () =
484466 Location. register_error_of_exn
0 commit comments