[refactoring] use named fields for Consistbl.Inconsistency exception

master
Gabriel Scherer 2019-01-07 16:48:03 +01:00
parent e74569cca8
commit c76edb9677
6 changed files with 41 additions and 12 deletions

View File

@ -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

View File

@ -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

View File

@ -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 "@[<hv 0>The files %s@ and %s@ \
disagree over interface %s@]@."
user auth name;

View File

@ -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 =

View File

@ -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

View File

@ -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