X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;ds=sidebyside;f=matita%2Fcomponents%2Fng_refiner%2FnCicUnifHint.ml;h=5c7f92f999a4d10265bdd67a7d7c53375fb85b4c;hb=f00a612006ac05f49a42ab507a95d3298bc1457a;hp=0f0708d638f58cef8fac17303492c6f7111a68b6;hpb=2c01ff6094173915e7023076ea48b5804dca7778;p=helm.git diff --git a/matita/components/ng_refiner/nCicUnifHint.ml b/matita/components/ng_refiner/nCicUnifHint.ml index 0f0708d63..5c7f92f99 100644 --- a/matita/components/ng_refiner/nCicUnifHint.ml +++ b/matita/components/ng_refiner/nCicUnifHint.ml @@ -11,6 +11,8 @@ (* $Id: nCicRefiner.mli 9227 2008-11-21 16:00:06Z tassi $ *) +module Ref = NReference + let debug s = prerr_endline (Lazy.force s);; let debug _ = ();; @@ -51,8 +53,9 @@ class type g_status = method uhint_db: db end -class status = +class virtual status = object + inherit NCic.status val db = HDB.empty, EQDB.empty method uhint_db = db method set_uhint_db v = {< db = v >} @@ -61,10 +64,13 @@ class status = = fun o -> {< db = o#uhint_db >} end -let dummy = NCic.Const (NReference.reference_of_string "cic:/dummy_conv.dec");; +let dummy = + let uri = NUri.uri_of_string "cic:/matita/dummy/dec.con" in + NCic.Const (Ref.reference_of_spec uri Ref.Decl);; + let pair t1 t2 = (NCic.Appl [dummy;t1;t2]) ;; -let index_hint hdb context t1 t2 precedence = +let index_hint status context t1 t2 precedence = assert ( (match t1 with | NCic.Meta _ | NCic.Appl (NCic.Meta _ :: _) -> false | _ -> true) @@ -76,14 +82,14 @@ let index_hint hdb context t1 t2 precedence = * 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 + List.fold_left (fun t _ -> NCicSubstitution.subst status hole t) t1 context in let t2_skeleton = - List.fold_left (fun t _ -> NCicSubstitution.subst hole t) t2 context + List.fold_left (fun t _ -> NCicSubstitution.subst status hole t) t2 context in let rec cleanup_skeleton () = function | NCic.Meta _ -> skel_dummy - | t -> NCicUtils.map (fun _ () -> ()) () cleanup_skeleton t + | t -> NCicUtils.map status (fun _ () -> ()) () cleanup_skeleton t in let t1_skeleton = cleanup_skeleton () t1_skeleton in let t2_skeleton = cleanup_skeleton () t2_skeleton in @@ -103,18 +109,18 @@ let index_hint hdb context t1 t2 precedence = let data_t2 = t1_skeleton in debug(lazy ("INDEXING: " ^ - NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] src ^ " |==> " ^ - NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] + status#ppterm ~metasenv:[] ~subst:[] ~context:[] src ^ " |==> " ^ + status#ppterm ~metasenv:[] ~subst:[] ~context:[] (let _,x,_,_ = data_hint in x))); - hdb#set_uhint_db ( - HDB.index (fst (hdb#uhint_db)) src data_hint, + status#set_uhint_db ( + HDB.index (fst (status#uhint_db)) src data_hint, EQDB.index - (EQDB.index (snd (hdb#uhint_db)) t2_skeleton (precedence, data_t2)) + (EQDB.index (snd (status#uhint_db)) t2_skeleton (precedence, data_t2)) t1_skeleton (precedence, data_t1)) ;; -let add_user_provided_hint db t precedence = +let add_user_provided_hint status t precedence = let c, a, b = let rec aux ctx = function | NCic.Appl l -> @@ -122,15 +128,15 @@ let add_user_provided_hint db t precedence = | b::a::_ -> if let ty_a = - NCicTypeChecker.typeof ~metasenv:[] ~subst:[] ctx a + NCicTypeChecker.typeof status ~metasenv:[] ~subst:[] ctx a in let ty_b = - NCicTypeChecker.typeof ~metasenv:[] ~subst:[] ctx b + NCicTypeChecker.typeof status ~metasenv:[] ~subst:[] ctx b in - NCicReduction.are_convertible + NCicReduction.are_convertible status ~metasenv:[] ~subst:[] ctx ty_a ty_b && - NCicReduction.are_convertible + NCicReduction.are_convertible status ~metasenv:[] ~subst:[] ctx a b then ctx, a, b else raise HintNotValid @@ -141,7 +147,7 @@ let add_user_provided_hint db t precedence = in aux [] t in - index_hint db c a b precedence + index_hint status c a b precedence ;; (* @@ -175,11 +181,11 @@ let db () = in let n1 = NCic.Appl (NCic.Const(OCic2NCic.reference_of_ouri - u1 (NReference.Def h1)) :: mk_rels (List.length ctx)) + u1 (Ref.Def h1)) :: mk_rels (List.length ctx)) in let n2 = NCic.Appl (NCic.Const(OCic2NCic.reference_of_ouri - u2 (NReference.Def h2)) :: mk_rels (List.length ctx)) + u2 (Ref.Def h2)) :: mk_rels (List.length ctx)) in [ctx,b1,b2; ctx,b1,n2; ctx,n1,b2; ctx,n1,n2] end else [] @@ -206,7 +212,7 @@ let db () = ;; *) -let saturate ?(delta=0) metasenv subst context ty goal_arity = +let saturate status ?(delta=0) metasenv subst context ty goal_arity = assert (goal_arity >= 0); let rec aux metasenv = function | NCic.Prod (name,s,t) as ty -> @@ -215,14 +221,14 @@ let saturate ?(delta=0) metasenv subst context ty goal_arity = ~with_type:s `IsTerm in let t, metasenv1, args, pno = - aux metasenv1 (NCicSubstitution.subst arg t) + aux metasenv1 (NCicSubstitution.subst status arg t) in if pno + 1 = goal_arity then ty, metasenv, [], goal_arity+1 else t, metasenv1, arg::args, pno+1 | ty -> - match NCicReduction.whd ~subst context ty ~delta with + match NCicReduction.whd status ~subst context ty ~delta with | NCic.Prod _ as ty -> aux metasenv ty | _ -> ty, metasenv, [], 0 (* differs from the other impl in this line*) in @@ -230,7 +236,7 @@ let saturate ?(delta=0) metasenv subst context ty goal_arity = res, newmetasenv, arguments ;; -let eq_class_of hdb t1 = +let eq_class_of (status:#status) t1 = let eq_class = if NDiscriminationTree.NCicIndexable.path_string_of t1 = [Discrimination_tree.Variable] @@ -238,43 +244,43 @@ let eq_class_of hdb t1 = [] (* 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 = EQDB.retrieve_unifiables (snd status#uhint_db) t1 in let candidates = EqSet.elements candidates in 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:[] + debug(lazy("eq_class of: " ^ status#ppterm ~metasenv:[] ~context:[] ~subst:[] t1 ^ " is\n" ^ String.concat "\n" - (List.map (NCicPp.ppterm ~subst:[] ~metasenv:[] ~context:[]) eq_class))); + (List.map (status#ppterm ~metasenv:[] ~context:[] ~subst:[]) eq_class))); eq_class ;; -let look_for_hint hdb metasenv subst context t1 t2 = +let look_for_hint (status:#status) metasenv subst context t1 t2 = if NDiscriminationTree.NCicIndexable.path_string_of t1 = [Discrimination_tree.Variable] || NDiscriminationTree.NCicIndexable.path_string_of t2 = [Discrimination_tree.Variable] then [] else begin - debug(lazy ("KEY1: "^NCicPp.ppterm ~metasenv ~subst ~context t1)); - debug(lazy ("KEY2: "^NCicPp.ppterm ~metasenv ~subst ~context t2)); + debug(lazy ("KEY1: "^status#ppterm ~metasenv ~subst ~context t1)); + debug(lazy ("KEY2: "^status#ppterm ~metasenv ~subst ~context t2)); (* - HDB.iter hdb + HDB.iter status (fun p ds -> prerr_endline ("ENTRY: " ^ NDiscriminationTree.NCicIndexable.string_of_path p ^ " |--> " ^ - String.concat "|" (List.map (NCicPp.ppterm ~metasenv:[] ~subst:[] + String.concat "|" (List.map (status#ppterm ~metasenv:[] ~subst:[] ~context:[]) (HintSet.elements ds)))); *) - 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 = HDB.retrieve_unifiables (fst status#uhint_db) (pair t1 t2) in + let candidates2 = HDB.retrieve_unifiables (fst status#uhint_db) (pair t2 t1) in let candidates1 = List.map (fun (prec,_,_,ty) -> - prec,true,saturate ~delta:max_int metasenv subst context ty 0) + prec,true,saturate status ~delta:max_int metasenv subst context ty 0) (HintSet.elements candidates1) in let candidates2 = List.map (fun (prec,_,_,ty) -> - prec,false,saturate ~delta:max_int metasenv subst context ty 0) + prec,false,saturate status ~delta:max_int metasenv subst context ty 0) (HintSet.elements candidates2) in let rc = @@ -287,9 +293,9 @@ let look_for_hint hdb metasenv subst context t1 t2 = NCicMetaSubst.mk_meta ~attrs:[`Name name] m context ~with_type:ty `IsTerm in - let t = NCicSubstitution.subst i t in + let t = NCicSubstitution.subst status i t in aux () (m, (i,bo)::l) t - | t -> NCicUntrusted.map_term_fold_a (fun _ () -> ()) () aux acc t + | t -> NCicUntrusted.map_term_fold_a status (fun _ () -> ()) () aux acc t in let (m,l), t = aux () (m,[]) t in p,b,(t,m,l)) @@ -313,21 +319,21 @@ let look_for_hint hdb metasenv subst context t1 t2 = (fun (metasenv, (t1, t2), premises) -> ("\t" ^ String.concat "; " (List.map (fun (a,b) -> - NCicPp.ppterm ~margin:max_int ~metasenv ~subst ~context a ^ + status#ppterm ~margin:max_int ~metasenv ~subst ~context a ^ " =?= "^ - NCicPp.ppterm ~margin:max_int ~metasenv ~subst ~context b) + status#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)) + status#ppterm ~margin:max_int ~metasenv ~subst ~context t1 ^ + " = "^status#ppterm ~margin:max_int ~metasenv ~subst ~context t2)) rc))); rc end ;; -let pp_hint t p = - let context, t = +let pp_hint _t _p = +(* let context, t = let rec aux ctx = function | NCic.Prod (name, ty, rest) -> aux ((name, NCic.Decl ty) :: ctx) rest | t -> ctx, t @@ -343,7 +349,6 @@ let pp_hint t p = in let buff = Buffer.create 100 in let fmt = Format.formatter_of_buffer buff in -(* F.fprintf "@[" F.fprintf "@[" (* pp_ctx [] context *) @@ -353,7 +358,7 @@ let pp_hint t p = (* pp_ctx context recproblems *) F.fprintf "@]" F.fprintf "\vdash@;"; - NCicPp.ppterm ~fmt ~context:(recproblems@context) ~subst:[] ~metasenv:[]; + status#ppterm ~fmt ~context:(recproblems@context) ~subst:[] ~metasenv:[]; F.fprintf "@]" F.fprintf formatter "@?"; prerr_endline (Buffer.contents buff); @@ -361,7 +366,7 @@ let pp_hint t p = () ;; -let generate_dot_file status fmt = +let generate_dot_file (status:#status) fmt = let module Pp = GraphvizPp.Dot in let h_db, _ = status#uhint_db in let names = ref [] in @@ -380,18 +385,18 @@ let generate_dot_file status fmt = (fun (precedence, l,r, hint) -> let l = Str.global_substitute (Str.regexp "\n") (fun _ -> "") - (NCicPp.ppterm + (status#ppterm ~margin:max_int ~metasenv:[] ~context:[] ~subst:[] l) in let r = Str.global_substitute (Str.regexp "\n") (fun _ -> "") - (NCicPp.ppterm + (status#ppterm ~margin:max_int ~metasenv:[] ~context:[] ~subst:[] r) in let shint = "???" (* string_of_int precedence ^ "..." ^ Str.global_substitute (Str.regexp "\n") (fun _ -> "") - (NCicPp.ppterm + (status#ppterm ~margin:max_int ~metasenv:[] ~context:[] ~subst:[] hint)*) in nodes := (mangle l,l) :: (mangle r,r) :: !nodes; @@ -399,9 +404,9 @@ let generate_dot_file status fmt = (HintSet.elements dataset); ); List.iter (fun x, l -> Pp.node x ~attrs:["label",l] fmt) !nodes; - List.iter (fun x, y, l, _, _ -> + List.iter (fun x, y, _l, _, _ -> Pp.raw (Printf.sprintf "%s -- %s [ label=\"%s\" ];\n" x y "?") fmt) !edges; edges := List.sort (fun (_,_,_,p1,_) (_,_,_,p2,_) -> p1 - p2) !edges; - List.iter (fun x, y, _, p, l -> pp_hint l p) !edges; + List.iter (fun _x, _y, _, p, l -> pp_hint l p) !edges; ;;