X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Focaml%2Fcic_proof_checking%2FcicEnvironment.ml;h=0c5c9c01e9030259fff0591ca2a43260e347a84a;hb=a785a3526d4dcbb6c5810ed4fb943132c9ff2d45;hp=e15186fdecdb489f437d50c91bbad63b3e54e00c;hpb=655906d74521fa49de332f54ec34bfc9d9744151;p=helm.git diff --git a/helm/ocaml/cic_proof_checking/cicEnvironment.ml b/helm/ocaml/cic_proof_checking/cicEnvironment.ml index e15186fde..0c5c9c01e 100644 --- a/helm/ocaml/cic_proof_checking/cicEnvironment.ml +++ b/helm/ocaml/cic_proof_checking/cicEnvironment.ml @@ -37,8 +37,9 @@ let cleanup_tmp = true;; -let trust_obj = function uri -> true;; -(*let trust_obj = function uri -> false;;*) +let trust = ref (fun _ -> true);; +let set_trust f = trust := f +let trust_obj uri = !trust uri type type_checked_obj = CheckedObj of Cic.obj (* cooked obj *) @@ -50,6 +51,7 @@ exception AlreadyCooked of string;; exception CircularDependency of string;; exception CouldNotFreeze of string;; exception CouldNotUnfreeze of string;; +exception Term_not_found of UriManager.uri;; (* Cache that uses == instead of = for testing equality *) (* Invariant: an object is always in at most one of the *) @@ -63,6 +65,7 @@ module Cache : uri:UriManager.uri -> unit val find_cooked : key:UriManager.uri -> Cic.obj val add_cooked : key:UriManager.uri -> Cic.obj -> unit + val remove: UriManager.uri -> unit val dump_to_channel : ?callback:(string -> unit) -> out_channel -> unit val restore_from_channel : ?callback:(string -> unit) -> in_channel -> unit @@ -75,6 +78,7 @@ module Cache : val mem : UriManager.uri -> bool val find : UriManager.uri -> Cic.obj val add : UriManager.uri -> Cic.obj -> unit + val remove : UriManager.uri -> unit (** (de)serialization of type checker cache *) val dump_to_channel : ?callback:(string -> unit) -> out_channel -> unit @@ -103,6 +107,12 @@ module Cache : let add uri obj = HT.add hashtable uri obj ;; + let remove uri = + if mem uri then + HT.remove hashtable uri + else + raise (Term_not_found uri); + ;; (* used to hash cons uris on restore to grant URI structure unicity *) let restore_uris = @@ -289,7 +299,12 @@ module Cache : ;; let find_cooked ~key:uri = CacheOfCookedObjects.find uri;; let add_cooked ~key:uri obj = CacheOfCookedObjects.add uri obj;; - + let remove uri = + if (!unchecked_list <> []) || (!frozen_list <> []) then + failwith "CicEnvironment.remove while type checking" + else + CacheOfCookedObjects.remove uri + ;; let dump_to_channel = CacheOfCookedObjects.dump_to_channel;; let restore_from_channel = CacheOfCookedObjects.restore_from_channel;; let empty = CacheOfCookedObjects.empty;; @@ -314,20 +329,29 @@ let find_or_add_unchecked_to_cache uri = (* The body exists ==> it is not an axiom *) Some (Http_getter.getxml' bodyuri) with - Http_getter_types.Unresolvable_URI _ -> + Http_getter_types.Key_not_found _ -> (* The body does not exist ==> we consider it an axiom *) None in - CicUniv.directly_to_env_begin (); - let obj = CicParser.obj_of_xml filename bodyfilename in - CicUniv.directly_to_env_end (); + let cleanup () = if cleanup_tmp then begin - Unix.unlink filename ; + if Sys.file_exists filename then Unix.unlink filename ; match bodyfilename with - Some f -> Unix.unlink f + Some f -> if Sys.file_exists f then Unix.unlink f | None -> () end ; + in + CicUniv.directly_to_env_begin (); + let obj = + try + CicParser.obj_of_xml filename bodyfilename + with exn -> + cleanup (); + raise exn + in + CicUniv.directly_to_env_end (); + cleanup (); obj ) ;; @@ -416,3 +440,6 @@ let add_type_checked_term uri obj = | _ -> assert false Cache.add_cooked ;; + +let remove_term = Cache.remove +