module HintSet = Set.Make(COT)
-module DB =
+module HDB =
Discrimination_tree.Make(NDiscriminationTree.NCicIndexable)(HintSet)
-type db = DB.t
+module EQDB =
+ Discrimination_tree.Make(NDiscriminationTree.NCicIndexable)(HintSet)
+
+type db =
+ HDB.t * (* hint database: (dummy A B)[?] |-> \forall X.(summy a b)[X] *)
+ EQDB.t (* eqclass DB: A[?] |-> \forall X.B[X] and viceversa *)
+
+exception HintNotValid
+
+class status =
+ object
+ val db = HDB.empty, EQDB.empty
+ method uhint_db = db
+ method set_uhint_db v = {< db = v >}
+ method set_unifhint_status
+ : 'status. < uhint_db : db; .. > as 'status -> 'self
+ = fun o -> {< db = o#uhint_db >}
+ end
let dummy = NCic.Const (NReference.reference_of_string "cic:/dummy_conv.dec");;
let pair t1 t2 = (NCic.Appl [dummy;t1;t2]) ;;
(match t2 with
| NCic.Meta _ | NCic.Appl (NCic.Meta _ :: _) -> false | _ -> true)
);
- let pair' = pair t1 t2 in
- let data =
+ let hole = NCic.Meta (-1,(0,NCic.Irl 0)) in
+ let t1_skeleton =
+ List.fold_left (fun t _ -> NCicSubstitution.subst hole t) t1 context
+ in
+ let t2_skeleton =
+ List.fold_left (fun t _ -> NCicSubstitution.subst hole t) t2 context
+ in
+ let src = pair t1_skeleton t2_skeleton in
+ let ctx2abstractions context t =
List.fold_left
(fun t (n,e) ->
match e with
| NCic.Decl ty -> NCic.Prod (n,ty,t)
| NCic.Def (b,ty) -> NCic.LetIn (n,ty,b,t))
- pair' context in
- let src =
- List.fold_left
- (fun t (_,e) ->
- match e with
- | NCic.Decl _ ->
- NCicSubstitution.subst (NCic.Meta (-1,(0,NCic.Irl 0))) t
- | NCic.Def _ ->
- NCicSubstitution.subst (NCic.Meta (-1,(0,NCic.Irl 0))) t)
- pair' context in
+ t context
+ in
+ let data_hint = ctx2abstractions context (pair t1 t2) in
+ let data_t1 = t2_skeleton in
+ let data_t2 = t1_skeleton in
(*
prerr_endline ("INDEXING: " ^
NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] src ^ " |==> " ^
NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] data);
*)
- DB.index hdb src (precedence, data)
+ hdb#set_uhint_db (
+ HDB.index (fst (hdb#uhint_db)) src (precedence, data_hint),
+ EQDB.index
+ (EQDB.index (snd (hdb#uhint_db)) t2_skeleton (precedence, data_t2))
+ t1_skeleton (precedence, data_t1))
;;
-let empty_db = DB.empty ;;
-
-let user_db = ref empty_db ;;
-
-let add_user_provided_hint t precedence =
- let u = UriManager.uri_of_string "cic:/foo/bar.con" in
+let add_user_provided_hint db t precedence =
let c, a, b =
let rec aux ctx = function
| NCic.Appl l ->
(match List.rev l with
- | b::a::_ -> ctx, a, b
+ | b::a::_ ->
+ if
+ let ty_a =
+ NCicTypeChecker.typeof ~metasenv:[] ~subst:[] ctx a
+ in
+ let ty_b =
+ NCicTypeChecker.typeof ~metasenv:[] ~subst:[] ctx b
+ in
+ NCicReduction.are_convertible
+ ~metasenv:[] ~subst:[] ctx ty_a ty_b
+ &&
+ NCicReduction.are_convertible
+ ~metasenv:[] ~subst:[] ctx a b
+ then ctx, a, b
+ else raise HintNotValid
| _ -> assert false)
- | NCic.Prod (n,s,t) ->
- aux ((n, NCic.Decl s) :: ctx) t
- | NCic.LetIn (n,ty,t,b) ->
- aux ((n, NCic.Def (t,ty)) :: ctx) b
+ | NCic.Prod (n,s,t) -> aux ((n, NCic.Decl s) :: ctx) t
+ | NCic.LetIn (n,ty,t,b) -> aux ((n, NCic.Def (t,ty)) :: ctx) b
| _ -> assert false
in
- aux [] (fst (OCic2NCic.convert_term u t))
+ aux [] t
in
- user_db := index_hint !user_db c a b precedence
+ index_hint db c a b precedence
;;
let db () =
aux [] l r
| _ -> []
in
- let hints =
+ let _hints =
List.fold_left
(fun acc (_,_,l) ->
acc @
if List.length l > 1 then
combine mk_hint l
else [])
- [] (CoercDb.to_list ())
+ [] (CoercDb.to_list (CoercDb.dump ()))
in
+ prerr_endline "MISTERO";
+ assert false (* ERA
List.fold_left
(fun db -> function
| (ctx,b1,b2) -> index_hint db ctx b1 b2 0)
!user_db (List.flatten hints)
+*)
;;
let saturate ?(delta=0) metasenv subst context ty goal_arity =
res, newmetasenv, arguments
;;
+let eq_class_of hdb t1 =
+ if NDiscriminationTree.NCicIndexable.path_string_of t1 =
+ [Discrimination_tree.Variable]
+ then
+ [] (* if the trie is unable to handle the key, we skip the query since
+ it sould retulr the whole content of the trie *)
+ else
+ let candidates = EQDB.retrieve_unifiables (snd hdb#uhint_db) t1 in
+ let candidates = HintSet.elements candidates in
+ List.map snd (List.sort (fun (x,_) (y,_) -> compare x y) candidates)
+;;
+
let look_for_hint hdb metasenv subst context t1 t2 =
(*
prerr_endline ("KEY1: "^NCicPp.ppterm ~metasenv ~subst ~context (pair t1 t2));
prerr_endline ("KEY2: "^NCicPp.ppterm ~metasenv ~subst ~context (pair t2 t1));
- DB.iter hdb
+ HDB.iter hdb
(fun p ds ->
prerr_endline ("ENTRY: " ^
NDiscriminationTree.NCicIndexable.string_of_path p ^ " |--> " ^
String.concat "|" (List.map (NCicPp.ppterm ~metasenv:[] ~subst:[]
~context:[]) (HintSet.elements ds))));
*)
- let candidates1 = DB.retrieve_unifiables hdb (pair t1 t2) in
- let candidates2 = DB.retrieve_unifiables hdb (pair t2 t1) in
+ let candidates1 = HDB.retrieve_unifiables (fst hdb#uhint_db) (pair t1 t2) in
+ let candidates2 = HDB.retrieve_unifiables (fst hdb#uhint_db) (pair t2 t1) in
let candidates1 =
List.map (fun (prec,ty) ->
prec,true,saturate ~delta:max_int metasenv subst context ty 0)