X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=components%2Ftactics%2FautoCache.ml;h=57701310c445b3de47adc3e56aa3806708e397fc;hb=c704c720763e174eb05f62f1bf70359744b8a0e9;hp=b4e074a6450604cade8197f00a8f0df01520547e;hpb=be87825f491f5eff5f02ee78dd23f34fc0e46e71;p=helm.git diff --git a/components/tactics/autoCache.ml b/components/tactics/autoCache.ml index b4e074a64..57701310c 100644 --- a/components/tactics/autoCache.ml +++ b/components/tactics/autoCache.ml @@ -23,74 +23,37 @@ * http://cs.unibo.it/helm/. *) -module Codomain = struct - type t = Cic.term - let compare = Pervasives.compare -end -module S = Set.Make(Codomain) -module TI = Discrimination_tree.DiscriminationTreeIndexing(S) -type universe = TI.t -(* (proof,ty) list *) type cache_key = Cic.term type cache_elem = | Failed_in of int | Succeded of Cic.term | UnderInspection | Notfound -type cache = (universe * ((cache_key * cache_elem) list));; +type cache = (Universe.universe * ((cache_key * cache_elem) list));; + + +let cache_empty = (Universe.empty,[]);; -let cache_empty = (TI.empty,[]);; let get_candidates (univ,_) ty = - S.elements (TI.retrieve_unifiables univ ty) + Universe.get_candidates univ ty ;; -let rec head = function - | Cic.Prod(_,_,t) -> CicSubstitution.subst (Cic.Meta (-1,[])) (head t) - | t -> t -;; -let index ((univ,oldcache) as cache) key term = - match key with - | Cic.Meta _ -> cache - | _ -> - prerr_endline("ADD: "^CicPp.ppterm key^" |-> "^CicPp.ppterm term); - (TI.index univ key term,oldcache) + +let index (univ,cache) key term = + Universe.index univ key term,cache ;; -let cache_add_library dbd proof gl cache = - let univ = MetadataQuery.universe_of_goals ~dbd proof gl in - let terms = List.map CicUtil.term_of_uri univ in - let tyof t = fst(CicTypeChecker.type_of_aux' [] [] t CicUniv.empty_ugraph)in - List.fold_left - (fun acc term -> - let key = head (tyof term) in - index acc key term) - cache terms + +let index_term_and_unfolded_term (univ,cache) context t ty = + Universe.index_local_term univ context t ty, cache ;; -let cache_add_context ctx metasenv cache = - let tail = function [] -> [] | h::tl -> tl in - let rc,_,_ = - List.fold_left - (fun (acc,i,ctx) ctxentry -> - match ctxentry with - | Some (_,Cic.Decl t) -> - let key = CicSubstitution.lift i (head t) in - let elem = Cic.Rel i in - index acc key elem, i+1, tail ctx - | Some (_,Cic.Def (_,Some t)) -> - let key = CicSubstitution.lift i (head t) in - let elem = Cic.Rel i in - index acc key elem, i+1, tail ctx - | Some (_,Cic.Def (t,None)) -> - let ctx = tail ctx in - let key,_ = - CicTypeChecker.type_of_aux' metasenv ctx t CicUniv.empty_ugraph - in - let elem = Cic.Rel i in - let key = CicSubstitution.lift i (head key) in - index acc key elem, i+1, ctx - | _ -> acc,i+1,tail ctx) - (cache,1,ctx) ctx + +let cache_add_list (univ,cache) context terms_and_types = + let univ = + List.fold_left + (fun univ (t,ty) -> + Universe.index_local_term univ context t ty) + univ terms_and_types in - rc -;; + univ, cache let cache_examine (_,oldcache) cache_key = try List.assoc cache_key oldcache with Not_found -> Notfound @@ -114,7 +77,7 @@ let cache_add_failure cache cache_key depth = assert false (* if succed it can't fail *) ;; let cache_add_success ((univ,_) as cache) cache_key proof = - TI.index univ cache_key proof,snd + Universe.index univ cache_key proof,snd (match cache_examine cache cache_key with | Failed_in _ -> cache_replace cache cache_key (Succeded proof) | UnderInspection -> cache_replace cache cache_key (Succeded proof)