]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/cic_unification/coercGraph.ml
Fixes unexpected behaviour of ncut when multiple goals are selected.
[helm.git] / helm / software / components / cic_unification / coercGraph.ml
index 17301e4d6bb4cbb81ef8498a3ccf69e6daf37c93..9f953ccf8f07b370cce20ab074a5f255c93fd8a9 100644 (file)
@@ -135,13 +135,9 @@ let source_of t =
   | Some _ -> assert false (* t must be a coercion not to funclass *)
 ;;
 
-let generate_dot_file () =
-  let l = CoercDb.to_list () in
+let generate_dot_file fmt =
+  let l = CoercDb.to_list (CoercDb.dump ()) in
   let module Pp = GraphvizPp.Dot in
-  let buf = Buffer.create 10240 in
-  let fmt = Format.formatter_of_buffer buf in
-  Pp.header ~node_attrs:["fontsize", "9"; "width", ".4"; "height", ".4"]
-    ~edge_attrs:["fontsize", "10"] fmt;
   if List.exists (fun (_,t,_) -> CoercDb.string_of_carr t = "Type") l then
     Format.fprintf fmt "subgraph cluster_rest { style=\"filled\";
     color=\"white\"; label=<%s>; labelloc=\"b\"; %s; }\n" 
@@ -227,8 +223,6 @@ let generate_dot_file () =
             fmt)
         ul)
     l;
-  Pp.trailer fmt;
-  Buffer.contents buf
 ;;
     
 let coerced_arg l =
@@ -263,7 +257,7 @@ let splat e l = List.map (fun (x1,x2,_) -> e, Some (x1,x2)) l;;
 
 (* : carr -> (carr * uri option) where the option is always Some *)
 let get_coercions_to carr = 
-  let l = CoercDb.to_list () in
+  let l = CoercDb.to_list (CoercDb.dump ()) in
   let splat_coercion_to carr (src,tgt,cl) =
     if CoercDb.eq_carr tgt carr then Some (splat src cl) else None
   in
@@ -273,7 +267,7 @@ let get_coercions_to carr =
 
 (* : carr -> (carr * uri option) where the option is always Some *)
 let get_coercions_from carr = 
-  let l = CoercDb.to_list () in
+  let l = CoercDb.to_list (CoercDb.dump ()) in
   let splat_coercion_from carr (src,tgt,cl) =
     if CoercDb.eq_carr src carr then Some (splat tgt cl) else None
   in
@@ -304,10 +298,16 @@ let lb (c,_,_) =
 
 (* given the set { (s,u1,u2) | u1:s->t1 /\ u2:s->t2 } removes the elements 
  * (s,_,_) such that (s',_,_) is in the set and there exists a coercion s->s' *)
-let rec min acc = function
+let rec min acc skipped = function
   | c::tl -> 
-    if List.exists (lb c) (tl@acc) then min acc tl else min (c::acc) tl
-  | [] -> acc
+    if List.exists (lb c) (tl@acc) 
+    then min acc (c::skipped) tl else min (c::acc) skipped tl
+  | [] -> acc, skipped
+;;
+
+
+let sort l = 
+  let low, high = min [] [] l in low @ high
 ;;
 
 let meets metasenv subst context (grow_left,left) (grow_right,right) =
@@ -321,12 +321,12 @@ let meets metasenv subst context (grow_left,left) (grow_right,right) =
   in
   List.map 
     (fun (c,uo1,uo2) -> 
-      let metasenv, uo1 = 
-        if grow_left then saturate metasenv uo1 else metasenv, None in
-      let metasenv, uo2 = 
-        if grow_right then saturate metasenv uo2 else metasenv, None in
+      let metasenv, uo1 = saturate metasenv uo1 in
+      let metasenv, uo2 = saturate metasenv uo2 in
       c,metasenv, uo1, uo2)
-    (min [] (intersect (grow left) (grow right)))
+    (sort (intersect 
+      (if grow_left then grow left else [left,None]) 
+      (if grow_right then grow right else [right,None])))
 ;;
 
 (* EOF *)