summaryrefslogtreecommitdiffstats
path: root/typing/env.ml
diff options
context:
space:
mode:
authorJacques Garrigue <garrigue at math.nagoya-u.ac.jp>2014-05-07 00:34:20 +0000
committerJacques Garrigue <garrigue at math.nagoya-u.ac.jp>2014-05-07 00:34:20 +0000
commit1ce29d9bfca4e5f8a6f76c8f1d04521abc2dafc6 (patch)
treebc9cf016ae76d9191fa4b02ac83cf4239e2f93d6 /typing/env.ml
parent3dd57a94e308eb8222b09da3b939667b9773ccf4 (diff)
re-commit Leo's weak-dependencies pull request
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14755 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'typing/env.ml')
-rw-r--r--typing/env.ml42
1 files changed, 31 insertions, 11 deletions
diff --git a/typing/env.ml b/typing/env.ml
index 247e060f2..f7ef02d22 100644
--- a/typing/env.ml
+++ b/typing/env.ml
@@ -286,7 +286,7 @@ type pers_struct =
{ ps_name: string;
ps_sig: signature;
ps_comps: module_components;
- ps_crcs: (string * Digest.t) list;
+ ps_crcs: (string * Digest.t option) list;
ps_filename: string;
ps_flags: pers_flags list;
mutable ps_crcs_checked: bool }
@@ -297,12 +297,25 @@ let persistent_structures =
(* Consistency between persistent structures *)
let crc_units = Consistbl.create()
+let imported_units = ref ([] : string list)
+
+let clear_imports () =
+ Consistbl.clear crc_units;
+ imported_units := []
+
+let add_imports ps =
+ List.iter
+ (fun (name, _) -> imported_units := name :: !imported_units)
+ ps.ps_crcs
let check_consistency ps =
if ps.ps_crcs_checked then () else
try
List.iter
- (fun (name, crc) -> Consistbl.check crc_units name crc ps.ps_filename)
+ (fun (name, crco) ->
+ match crco with
+ None -> ()
+ | Some crc -> Consistbl.check crc_units name crc ps.ps_filename)
ps.ps_crcs;
ps.ps_crcs_checked <- true
with Consistbl.Inconsistency(name, source, auth) ->
@@ -330,6 +343,7 @@ let read_pers_struct modname filename =
ps_flags = flags } in
if ps.ps_name <> modname then
error (Illegal_renaming(modname, ps.ps_name, filename));
+ add_imports ps;
if not !Clflags.transparent_modules then check_consistency ps;
List.iter
(function Rectypes ->
@@ -364,7 +378,7 @@ let find_pers_struct ?(check=true) name =
let reset_cache () =
current_unit := "";
Hashtbl.clear persistent_structures;
- Consistbl.clear crc_units;
+ clear_imports ();
Hashtbl.clear value_declarations;
Hashtbl.clear type_declarations;
Hashtbl.clear used_constructors;
@@ -1564,15 +1578,20 @@ let read_signature modname filename =
let crc_of_unit name =
let ps = find_pers_struct ~check:false name in
- try
- List.assoc name ps.ps_crcs
- with Not_found ->
- assert false
+ let crco =
+ try
+ List.assoc name ps.ps_crcs
+ with Not_found ->
+ assert false
+ in
+ match crco with
+ None -> assert false
+ | Some crc -> crc
(* Return the list of imported interfaces with their CRCs *)
-let imported_units() =
- Consistbl.extract crc_units
+let imports() =
+ Consistbl.extract !imported_units crc_units
(* Save a signature to a file *)
@@ -1601,12 +1620,13 @@ let save_signature_with_imports sg modname filename imports =
{ ps_name = modname;
ps_sig = sg;
ps_comps = comps;
- ps_crcs = (cmi.cmi_name, crc) :: imports;
+ ps_crcs = (cmi.cmi_name, Some crc) :: imports;
ps_filename = filename;
ps_flags = cmi.cmi_flags;
ps_crcs_checked = true } in
Hashtbl.add persistent_structures modname (Some ps);
Consistbl.set crc_units modname crc filename;
+ imported_units := modname :: !imported_units;
sg
with exn ->
close_out oc;
@@ -1614,7 +1634,7 @@ let save_signature_with_imports sg modname filename imports =
raise exn
let save_signature sg modname filename =
- save_signature_with_imports sg modname filename (imported_units())
+ save_signature_with_imports sg modname filename (imports())
(* Folding on environments *)