From c76edb96775576861a5b391092677c5d48e7b30b Mon Sep 17 00:00:00 2001 From: Gabriel Scherer Date: Mon, 7 Jan 2019 16:48:03 +0100 Subject: [PATCH] [refactoring] use named fields for Consistbl.Inconsistency exception --- asmcomp/asmlink.ml | 12 ++++++++++-- bytecomp/bytelink.ml | 6 +++++- toplevel/topdirs.ml | 6 +++++- typing/persistent_env.ml | 6 +++++- utils/consistbl.ml | 12 ++++++++++-- utils/consistbl.mli | 11 ++++++----- 6 files changed, 41 insertions(+), 12 deletions(-) diff --git a/asmcomp/asmlink.ml b/asmcomp/asmlink.ml index d08793396..9756b18f0 100644 --- a/asmcomp/asmlink.ml +++ b/asmcomp/asmlink.ml @@ -59,7 +59,11 @@ let check_consistency file_name unit crc = then Cmi_consistbl.set crc_interfaces name crc file_name else Cmi_consistbl.check crc_interfaces name crc file_name) unit.ui_imports_cmi - with Cmi_consistbl.Inconsistency(name, user, auth) -> + with Cmi_consistbl.Inconsistency { + unit_name = name; + inconsistent_source = user; + original_source = auth; + } -> raise(Error(Inconsistent_interface(name, user, auth))) end; begin try @@ -73,7 +77,11 @@ let check_consistency file_name unit crc = | Some crc -> Cmx_consistbl.check crc_implementations name crc file_name) unit.ui_imports_cmx - with Cmx_consistbl.Inconsistency(name, user, auth) -> + with Cmx_consistbl.Inconsistency { + unit_name = name; + inconsistent_source = user; + original_source = auth; + } -> raise(Error(Inconsistent_implementation(name, user, auth))) end; begin try diff --git a/bytecomp/bytelink.ml b/bytecomp/bytelink.ml index 0065ebd35..27298dea0 100644 --- a/bytecomp/bytelink.ml +++ b/bytecomp/bytelink.ml @@ -178,7 +178,11 @@ let check_consistency file_name cu = then Consistbl.set crc_interfaces name crc file_name else Consistbl.check crc_interfaces name crc file_name) cu.cu_imports - with Consistbl.Inconsistency(name, user, auth) -> + with Consistbl.Inconsistency { + unit_name = name; + inconsistent_source = user; + original_source = auth; + } -> raise(Error(Inconsistent_import(name, user, auth))) end; begin try diff --git a/toplevel/topdirs.ml b/toplevel/topdirs.ml index 78ab7eb51..53b06e193 100644 --- a/toplevel/topdirs.ml +++ b/toplevel/topdirs.ml @@ -119,7 +119,11 @@ exception Load_failed let check_consistency ppf filename cu = try Env.import_crcs ~source:filename cu.cu_imports - with Persistent_env.Consistbl.Inconsistency(name, user, auth) -> + with Persistent_env.Consistbl.Inconsistency { + unit_name = name; + inconsistent_source = user; + original_source = auth; + } -> fprintf ppf "@[The files %s@ and %s@ \ disagree over interface %s@]@." user auth name; diff --git a/typing/persistent_env.ml b/typing/persistent_env.ml index 29807e059..b5860bf12 100644 --- a/typing/persistent_env.ml +++ b/typing/persistent_env.ml @@ -125,7 +125,11 @@ let import_crcs penv ~source crcs = let check_consistency penv ps = try import_crcs penv ~source:ps.ps_filename ps.ps_crcs - with Consistbl.Inconsistency(name, source, auth) -> + with Consistbl.Inconsistency { + unit_name = name; + inconsistent_source = source; + original_source = auth; + } -> error (Inconsistent_import(name, auth, source)) let can_load_cmis penv = diff --git a/utils/consistbl.ml b/utils/consistbl.ml index 7281fed16..b3299114a 100644 --- a/utils/consistbl.ml +++ b/utils/consistbl.ml @@ -30,13 +30,21 @@ end) = struct let clear = Module_name.Tbl.clear - exception Inconsistency of Module_name.t * filepath * filepath + exception Inconsistency of { + unit_name : Module_name.t; + inconsistent_source : string; + original_source : string; + } exception Not_available of Module_name.t let check_ tbl name crc source = let (old_crc, old_source) = Module_name.Tbl.find tbl name in - if crc <> old_crc then raise(Inconsistency(name, source, old_source)) + if crc <> old_crc then raise(Inconsistency { + unit_name = name; + inconsistent_source = source; + original_source = old_source; + }) let check tbl name crc source = try check_ tbl name crc source diff --git a/utils/consistbl.mli b/utils/consistbl.mli index 5c8c54280..5067addfa 100644 --- a/utils/consistbl.mli +++ b/utils/consistbl.mli @@ -69,11 +69,12 @@ end) : sig (* [filter pred tbl] removes from [tbl] table all (name, CRC) pairs such that [pred name] is [false]. *) - exception Inconsistency of Module_name.t * filepath * filepath - (* Raised by [check] when a CRC mismatch is detected. - First string is the name of the compilation unit. - Second string is the source that caused the inconsistency. - Third string is the source that set the CRC. *) + exception Inconsistency of { + unit_name : Module_name.t; + inconsistent_source : string; + original_source : string; + } + (* Raised by [check] when a CRC mismatch is detected. *) exception Not_available of Module_name.t (* Raised by [check_noadd] when a name doesn't have an associated