]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/ng_refiner/nCicUnifHint.ml
Bug fixed: the debrujinate function (hence the one to compute objects height)
[helm.git] / helm / software / components / ng_refiner / nCicUnifHint.ml
index ae186cc6317b2901f998ef55c5c77fb4c5b82782..d166b19360fa391fd0a4febc334fe7f28bdaded5 100644 (file)
@@ -24,6 +24,16 @@ module DB =
 
 type db = DB.t
 
+class status =
+ object
+  val db = DB.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]) ;;
 
@@ -57,30 +67,23 @@ let index_hint hdb context t1 t2 precedence =
     NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] src ^ " |==> " ^
     NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] data);
 *)
-  DB.index hdb src (precedence, data)
+  hdb#set_uhint_db (DB.index hdb#uhint_db src (precedence, data))
 ;;
 
-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
           | _ -> 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 () = 
@@ -137,19 +140,22 @@ let db () =
           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 =
  assert (goal_arity >= 0);
   let rec aux metasenv = function
    | NCic.Prod (name,s,t) as ty ->
-       let metasenv1, arg,_ = 
+       let metasenv1, _, arg,_ = 
           NCicMetaSubst.mk_meta ~name:name metasenv context (`WithType s) in
        let t, metasenv1, args, pno = 
            aux metasenv1 (NCicSubstitution.subst arg t) 
@@ -178,8 +184,8 @@ let look_for_hint hdb metasenv subst context t1 t2 =
       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 = DB.retrieve_unifiables hdb#uhint_db (pair t1 t2) in
+  let candidates2 = DB.retrieve_unifiables 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) 
@@ -196,7 +202,8 @@ let look_for_hint hdb metasenv subst context t1 t2 =
          let rec aux () (m,l as acc) = function
            | NCic.Meta _ as t -> acc, t
            | NCic.LetIn (name,ty,bo,t) ->
-               let m,i,_=NCicMetaSubst.mk_meta ~name m context (`WithType ty)in
+               let m,_,i,_=
+                 NCicMetaSubst.mk_meta ~name m context (`WithType ty)in
                let t = NCicSubstitution.subst i t in
                aux () (m, (i,bo)::l) t
            | t -> NCicUntrusted.map_term_fold_a (fun _ () -> ()) () aux acc t
@@ -208,8 +215,8 @@ let look_for_hint hdb metasenv subst context t1 t2 =
   let rc = 
   List.map
    (function 
-    | (prec,true,(NCic.Appl [_; t1; t2],metasenv,l))-> prec,metasenv, (t1,t2),l
-    | (prec,false,(NCic.Appl [_; t1; t2],metasenv,l))-> prec,metasenv, (t2,t1),l
+    | (prec,true,(NCic.Appl [_; t1; t2],metasenv,l))-> prec,metasenv,(t1,t2),l
+    | (prec,false,(NCic.Appl [_; t1; t2],metasenv,l))-> prec,metasenv,(t2,t1),l
     | _ -> assert false)
     rc
   in
@@ -218,17 +225,19 @@ let look_for_hint hdb metasenv subst context t1 t2 =
   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 
-            (String.concat "\n"
-                (List.map (fun (a,b) ->
-                   NCicPp.ppterm ~metasenv ~subst ~context a ^
-                   " =?= "^NCicPp.ppterm ~metasenv ~subst ~context b)
+          ("\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) ^     
-              "\n--------------------------------------------------"^
-              "\n"^NCicPp.ppterm ~metasenv ~subst ~context t1 ^
-              " = "^NCicPp.ppterm ~metasenv ~subst ~context t2 ^ "\n\n"))
+              "  ==> "^
+              NCicPp.ppterm ~margin:max_int ~metasenv ~subst ~context t1 ^
+              " = "^NCicPp.ppterm ~margin:max_int ~metasenv ~subst ~context t2))
       rc;
 *)
   rc