X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Fcomponents%2Fng_kernel%2FnCicLibrary.ml;h=8664add9b99955cafda1661117f46f80e4c2d559;hb=a71920f51fcaecbe19812e255231e545fe013cfc;hp=98f8903d8a5d3783852e92705fc7ff667ae46d7d;hpb=cf60cad5ad896f358d6e8dd2ded1c0430ba2c55c;p=helm.git diff --git a/helm/software/components/ng_kernel/nCicLibrary.ml b/helm/software/components/ng_kernel/nCicLibrary.ml index 98f8903d8..8664add9b 100644 --- a/helm/software/components/ng_kernel/nCicLibrary.ml +++ b/helm/software/components/ng_kernel/nCicLibrary.ml @@ -13,21 +13,26 @@ exception LibraryOutOfSync of string Lazy.t -let magic = 1;; +let magic = 2;; let refresh_uri uri = NUri.uri_of_string (NUri.string_of_uri uri);; +let refresh_uri_in_universe = + List.map (fun (x,u) -> x, refresh_uri u) +;; + let rec refresh_uri_in_term = function - NCic.Const (NReference.Ref (u,spec)) -> + | NCic.Const (NReference.Ref (u,spec)) -> NCic.Const (NReference.reference_of_spec (refresh_uri u) spec) + | NCic.Sort (NCic.Type l) -> NCic.Sort (NCic.Type (refresh_uri_in_universe l)) | t -> NCicUtils.map (fun _ _ -> ()) () (fun _ -> refresh_uri_in_term) t ;; let refresh_uri_in_obj (uri,height,metasenv,subst,obj_kind) = assert (metasenv = []); assert (subst = []); - uri,height,metasenv,subst, + refresh_uri uri,height,metasenv,subst, NCicUntrusted.map_obj_kind refresh_uri_in_term obj_kind ;; @@ -57,11 +62,14 @@ let require0 ~baseuri = require_path (path_of_baseuri baseuri);; let db_path () = Helm_registry.get "matita.basedir" ^ "/ng_db.ng";; + type timestamp = - (NUri.uri * NCic.obj) list * + [ `Obj of NUri.uri * NCic.obj + | `Constr of bool * NCic.universe * NCic.universe] list * (NUri.uri * string * NReference.reference) list * NCic.obj NUri.UriMap.t * - NUri.uri list;; + NUri.uri list +;; let time0 = [],[],NUri.UriMap.empty,[];; let storage = ref [];; @@ -77,6 +85,7 @@ let load_db,set_global_aliases,get_global_aliases,add_deps,get_deps,remove_deps= Marshal.to_channel ch (magic,(!global_aliases,!rev_includes_map)) []; close_out ch in let load_db () = + HExtlib.mkdir (Helm_registry.get "matita.basedir"); try let ga,im = require_path (db_path ()) in let ga = @@ -125,6 +134,7 @@ let load_db,set_global_aliases,get_global_aliases,add_deps,get_deps,remove_deps= let init = load_db;; + class status = object val timestamp = (time0 : timestamp) @@ -137,7 +147,11 @@ class status = let time_travel status = let sto,ali,cac,inc = status#timestamp in - storage := sto; local_aliases := ali; cache := cac; includes := inc + let diff_len = List.length !storage - List.length sto in + let to_be_deleted,_ = HExtlib.split_nth diff_len !storage in + if List.length to_be_deleted > 0 then + NCicEnvironment.invalidate_item (HExtlib.list_last to_be_deleted); + storage := sto; local_aliases := ali; cache := cac; includes := inc ;; let serialize ~baseuri dump = @@ -145,10 +159,12 @@ let serialize ~baseuri dump = Marshal.to_channel ch (magic,dump) []; close_out ch; List.iter - (fun (uri,obj) -> - let ch = open_out (path_of_baseuri uri) in - Marshal.to_channel ch (magic,obj) []; - close_out ch + (function + | `Obj (uri,obj) -> + let ch = open_out (path_of_baseuri uri) in + Marshal.to_channel ch (magic,obj) []; + close_out ch + | `Constr _ -> () ) !storage; set_global_aliases (!local_aliases @ get_global_aliases ()); List.iter (fun u -> add_deps u [baseuri]) !includes; @@ -161,7 +177,7 @@ module type Serializer = type obj val register: string -> - ('a -> refresh_uri_in_term:(NCic.term -> NCic.term) -> status -> status) -> + ('a -> refresh_uri_in_universe:(NCic.universe -> NCic.universe) -> refresh_uri_in_term:(NCic.term -> NCic.term) -> status -> status) -> ('a -> obj) val serialize: baseuri:NUri.uri -> obj list -> unit val require: baseuri:NUri.uri -> status -> status @@ -181,7 +197,7 @@ module Serializer(S: sig type status end) = require1 := (fun (tag',data) as x -> if tag=tag' then - require (Obj.magic data) ~refresh_uri_in_term + require (Obj.magic data) ~refresh_uri_in_universe ~refresh_uri_in_term else !require1 x); (fun x -> tag,Obj.repr x) @@ -248,8 +264,9 @@ let aliases_of uri = Not_found -> raise (NCicEnvironment.ObjectNotFound (lazy (NUri.string_of_uri uri))) ;; -let add_obj status u obj = - storage := (u,obj)::!storage; +let add_obj status ((u,_,_,_,_) as obj) = + NCicEnvironment.check_and_add_obj obj; + storage := (`Obj (u,obj))::!storage; let _,height,_,_,obj = obj in let references = match obj with @@ -282,8 +299,18 @@ let add_obj status u obj = status#set_timestamp (!storage,!local_aliases,!cache,!includes) ;; +let add_constraint status strict u1 u2 = + NCicEnvironment.add_constraint strict u1 u2; + storage := (`Constr (strict,u1,u2)) :: !storage; + status#set_timestamp (!storage,!local_aliases,!cache,!includes) +;; + let get_obj u = - try List.assq u !storage + try + List.assq u + (HExtlib.filter_map + (function `Obj (u,o) -> Some (u,o) | _ -> None ) + !storage) with Not_found -> try fetch_obj u with Sys_error _ ->