(* $Id: nCicRefiner.mli 9227 2008-11-21 16:00:06Z tassi $ *)
+let debug s = prerr_endline (Lazy.force s);;
+let debug _ = ();;
+
module COT : Set.OrderedType with type t = int * NCic.term =
struct
type t = int * NCic.term
exception HintNotValid
+let skel_dummy = NCic.Implicit `Type;;
+
+class type g_status =
+ object
+ method uhint_db: db
+ end
+
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
+ : 'status. #g_status as 'status -> 'self
= fun o -> {< db = o#uhint_db >}
end
(match t2 with
| NCic.Meta _ | NCic.Appl (NCic.Meta _ :: _) -> false | _ -> true)
);
+ (* here we do not use skel_dummy since it could cause an assert false in
+ * the subst function that lives in the kernel *)
let hole = NCic.Meta (-1,(0,NCic.Irl 0)) in
let t1_skeleton =
List.fold_left (fun t _ -> NCicSubstitution.subst hole t) t1 context
let t2_skeleton =
List.fold_left (fun t _ -> NCicSubstitution.subst hole t) t2 context
in
+ let rec cleanup_skeleton () = function
+ | NCic.Meta _ -> skel_dummy
+ | t -> NCicUtils.map (fun _ () -> ()) () cleanup_skeleton t
+ in
+ let t1_skeleton = cleanup_skeleton () t1_skeleton in
+ let t2_skeleton = cleanup_skeleton () t2_skeleton in
let src = pair t1_skeleton t2_skeleton in
let ctx2abstractions context t =
List.fold_left
let data_hint = ctx2abstractions context (pair t1 t2) in
let data_t1 = t2_skeleton in
let data_t2 = t1_skeleton in
-(*
- prerr_endline ("INDEXING: " ^
+
+ debug(lazy ("INDEXING: " ^
NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] src ^ " |==> " ^
- NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] data);
-*)
+ NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] data_hint));
+
hdb#set_uhint_db (
HDB.index (fst (hdb#uhint_db)) src (precedence, data_hint),
EQDB.index
| b1,b2 ->
if NCicReduction.are_convertible ~subst:[] ~metasenv:[] ctx b1 b2
then begin
-(*
- prerr_endline ("hint: " ^ NCicPp.ppterm ~metasenv:[] ~subst:[]
- ~context:ctx b1 ^ " === " ^ NCicPp.ppterm ~metasenv:[]
- ~subst:[] ~context:ctx b2);
-*)
let rec mk_rels =
function 0 -> [] | n -> NCic.Rel n :: mk_rels (n-1)
in
;;
let eq_class_of hdb t1 =
+ let eq_class =
if NDiscriminationTree.NCicIndexable.path_string_of t1 =
[Discrimination_tree.Variable]
then
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 candidates = List.sort (fun (x,_) (y,_) -> compare x y) candidates in
+ List.map snd candidates
+ in
+ debug(lazy("eq_class of: " ^ NCicPp.ppterm ~metasenv:[] ~context:[] ~subst:[]
+ t1 ^ " is\n" ^ String.concat "\n"
+ (List.map (NCicPp.ppterm ~subst:[] ~metasenv:[] ~context:[]) eq_class)));
+ eq_class
;;
let look_for_hint hdb metasenv subst context t1 t2 =
+ debug(lazy ("KEY1: "^NCicPp.ppterm ~metasenv ~subst ~context t1));
+ debug(lazy ("KEY2: "^NCicPp.ppterm ~metasenv ~subst ~context t2));
(*
- prerr_endline ("KEY1: "^NCicPp.ppterm ~metasenv ~subst ~context (pair t1 t2));
- prerr_endline ("KEY2: "^NCicPp.ppterm ~metasenv ~subst ~context (pair t2 t1));
HDB.iter hdb
(fun p ds ->
prerr_endline ("ENTRY: " ^
List.sort (fun (x,_,_,_) (y,_,_,_) -> Pervasives.compare x y) rc
in
let rc = List.map (fun (_,x,y,z) -> x,y,z) rc in
-(*
- prerr_endline "Hints:";
- List.iter
- (fun (metasenv, (t1, t2), premises) ->
- prerr_endline
- ("\t" ^ String.concat "; "
- (List.map (fun (a,b) ->
- NCicPp.ppterm ~margin:max_int ~metasenv ~subst ~context a ^
- " =?= "^
- NCicPp.ppterm ~margin:max_int ~metasenv ~subst ~context b)
- premises) ^
- " ==> "^
- NCicPp.ppterm ~margin:max_int ~metasenv ~subst ~context t1 ^
- " = "^NCicPp.ppterm ~margin:max_int ~metasenv ~subst ~context t2))
- rc;
-*)
+
+ debug(lazy ("Hints:"^
+ String.concat "\n" (List.map
+ (fun (metasenv, (t1, t2), premises) ->
+ ("\t" ^ String.concat "; "
+ (List.map (fun (a,b) ->
+ NCicPp.ppterm ~margin:max_int ~metasenv ~subst ~context a ^
+ " =?= "^
+ NCicPp.ppterm ~margin:max_int ~metasenv ~subst ~context b)
+ premises) ^
+ " ==> "^
+ NCicPp.ppterm ~margin:max_int ~metasenv ~subst ~context t1 ^
+ " = "^NCicPp.ppterm ~margin:max_int ~metasenv ~subst ~context t2))
+ rc)));
+
rc
;;