diff options
author | Sébastien Hinderer <seb@tarides.com> | 2023-03-07 09:31:38 +0100 |
---|---|---|
committer | Sébastien Hinderer <seb@tarides.com> | 2023-03-07 09:31:38 +0100 |
commit | 0a9660e865126bd5d7bfbfd4dffcd4c5bd6d38dc (patch) | |
tree | 3782e53b3c131f749f30027cb78dbd2bbd12a3ea /bytecomp | |
parent | 34845ca5738630d3f9392717b211926fa147204b (diff) | |
download | ocaml-0a9660e865126bd5d7bfbfd4dffcd4c5bd6d38dc.tar.gz |
bytelink: display badly ordered dependencies only once
This makes sure a badly ordered dependency is recorded only once.
Diffstat (limited to 'bytecomp')
-rw-r--r-- | bytecomp/bytelink.ml | 26 | ||||
-rw-r--r-- | bytecomp/bytelink.mli | 5 |
2 files changed, 21 insertions, 10 deletions
diff --git a/bytecomp/bytelink.ml b/bytecomp/bytelink.ml index 90fcc0917a..79976dda15 100644 --- a/bytecomp/bytelink.ml +++ b/bytecomp/bytelink.ml @@ -19,6 +19,13 @@ open Misc open Config open Cmo_format +module Dep = struct + type t = string * string + let compare = compare +end + +module DepSet = Set.Make (Dep) + type error = | File_not_found of filepath | Not_an_object_file of filepath @@ -30,7 +37,7 @@ type error = | Cannot_open_dll of filepath | Required_module_unavailable of modname * modname | Camlheader of string * filepath - | Wrong_link_order of (modname * modname) list + | Wrong_link_order of DepSet.t | Multiple_definition of modname * filepath * filepath exception Error of error @@ -90,11 +97,11 @@ let add_ccobjs origin l = let missing_globals = ref Ident.Map.empty let provided_globals = ref Ident.Set.empty -let badly_ordered_dependencies : (string * string) list ref = ref [] +let badly_ordered_dependencies : DepSet.t ref = ref DepSet.empty let record_badly_ordered_dependency (id, compunit) = - badly_ordered_dependencies := - ((Ident.name id), compunit.cu_name) :: !badly_ordered_dependencies + let dep = ((Ident.name id), compunit.cu_name) in + badly_ordered_dependencies := DepSet.add dep !badly_ordered_dependencies let is_required (rel, _pos) = match rel with @@ -632,11 +639,11 @@ let link objfiles output_name = match Ident.Map.bindings missing_modules with | [] -> () | (id, cu_name) :: _ -> - match !badly_ordered_dependencies with - | [] -> + if DepSet.is_empty !badly_ordered_dependencies + then raise (Error (Required_module_unavailable (Ident.name id, cu_name))) - | l -> - raise (Error (Wrong_link_order l)) + else + raise (Error (Wrong_link_order !badly_ordered_dependencies)) end; Clflags.ccobjs := !Clflags.ccobjs @ !lib_ccobjs; (* put user's libs last *) Clflags.all_ccopts := !lib_ccopts @ !Clflags.all_ccopts; @@ -772,7 +779,8 @@ let report_error ppf = function fprintf ppf "Module `%s' is unavailable (required by `%s')" s m | Camlheader (msg, header) -> fprintf ppf "System error while copying file %s: %s" header msg - | Wrong_link_order l -> + | Wrong_link_order depset -> + let l = DepSet.elements depset in let depends_on ppf (dep, depending) = fprintf ppf "%s depends on %s" depending dep in diff --git a/bytecomp/bytelink.mli b/bytecomp/bytelink.mli index 9adf20fdcb..35a59df1bf 100644 --- a/bytecomp/bytelink.mli +++ b/bytecomp/bytelink.mli @@ -17,6 +17,9 @@ open Misc (* Link .cmo files and produce a bytecode executable. *) +module Dep : Set.OrderedType with type t = modname * modname +module DepSet : Set.S with type elt = Dep.t + val link : filepath list -> filepath -> unit val reset : unit -> unit @@ -35,7 +38,7 @@ type error = | Cannot_open_dll of filepath | Required_module_unavailable of modname * modname | Camlheader of string * filepath - | Wrong_link_order of (modname * modname) list + | Wrong_link_order of DepSet.t | Multiple_definition of modname * filepath * filepath exception Error of error |