]> matita.cs.unibo.it Git - helm.git/blobdiff - components/tactics/closeCoercionGraph.ml
Coercions are now generalized to the general form
[helm.git] / components / tactics / closeCoercionGraph.ml
index 6c253df9f73c9274ec1087b122415f9312374962..0ab937ace0a89b6643034a21936cdc9242d31af4 100644 (file)
@@ -81,20 +81,25 @@ exception UnableToCompose
 
 (* generate_composite (c2 (c1 s)) in the universe graph univ
  * both living in the same context and metasenv *)
-let generate_composite c1 c2 context metasenv univ arity last_lam_with_inn_arg =
+let generate_composite' (c1,sat1) (c2,sat2) context metasenv univ arity
+ last_lam_with_inn_arg
+=
+assert (sat1 = 0);
+assert (sat2 = 0);
+let saturationsres = 0 in
   let original_metasenv = metasenv in 
   let c1_ty,univ = CicTypeChecker.type_of_aux' metasenv context c1 univ in
   let c2_ty,univ = CicTypeChecker.type_of_aux' metasenv context c2 univ in
   let rec mk_implicits = function
     | 0 -> [] | n -> (Cic.Implicit None) :: mk_implicits (n-1)
   in
-  let rec mk_lambda_spline c namer = function
+  let rec mk_lambda_spine c namer = function
     | 0 -> c
     | n -> 
         Cic.Lambda 
           (namer n,
            (Cic.Implicit None), 
-           mk_lambda_spline (CicSubstitution.lift 1 c) namer (n-1))
+           mk_lambda_spine (CicSubstitution.lift 1 c) namer (n-1))
   in 
   let count_saturations_needed t arity = 
     let rec aux acc n = function
@@ -177,7 +182,7 @@ let generate_composite c1 c2 context metasenv univ arity last_lam_with_inn_arg =
       | Cic.Appl l -> List.tl l
       | _ -> assert false
     in
-    (* i should cut off the laet elem of l_c2 *)
+    (* i should cut off the last elem of l_c2 *)
     let meta2no = fst (metas_that_saturate (l_c1 @ l_c2)) in
     List.sort 
       (fun (i,ctx1,ty1) (j,ctx1,ty1) -> 
@@ -204,8 +209,8 @@ let generate_composite c1 c2 context metasenv univ arity last_lam_with_inn_arg =
   let saturations_for_c1, names_c1 = count_saturations_needed c1_ty 0 in 
   let saturations_for_c2, names_c2 = count_saturations_needed c2_ty arity in
   let c = compose c1 saturations_for_c1 c2 saturations_for_c2 in
-  let spline_len = saturations_for_c1 + saturations_for_c2 in
-  let c = mk_lambda_spline c (namer (names_c1 @ names_c2)) spline_len in
+  let spine_len = saturations_for_c1 + saturations_for_c2 in
+  let c = mk_lambda_spine c (namer (names_c1 @ names_c2)) spine_len in
   debug_print (lazy ("COMPOSTA: " ^ CicPp.ppterm c));
   let old_insert_coercions = !CicRefine.insert_coercions in
   let c, metasenv, univ = 
@@ -218,13 +223,13 @@ let generate_composite c1 c2 context metasenv univ arity last_lam_with_inn_arg =
 (*       let metasenv = order_metasenv metasenv in *)
 (*       debug_print(lazy("ORDERED MENV: "^CicMetaSubst.ppmetasenv [] metasenv)); *)
       let body_metasenv, lambdas_metasenv = 
-        split_metasenv metasenv (spline_len + List.length context)
+        split_metasenv metasenv (spine_len + List.length context)
       in
       debug_print(lazy("B_MENV: "^CicMetaSubst.ppmetasenv [] body_metasenv));
       debug_print(lazy("L_MENV: "^CicMetaSubst.ppmetasenv [] lambdas_metasenv));
       let body_metasenv = order_body_menv term body_metasenv in
       debug_print(lazy("ORDERED_B_MENV: "^CicMetaSubst.ppmetasenv [] body_metasenv));
-      let subst = create_subst_from_metas_to_rels spline_len body_metasenv in
+      let subst = create_subst_from_metas_to_rels spine_len body_metasenv in
       debug_print (lazy("SUBST: "^CicMetaSubst.ppsubst body_metasenv subst));
       let term = CicMetaSubst.apply_subst subst term in
       let metasenv = CicMetaSubst.apply_subst_metasenv subst metasenv in
@@ -233,7 +238,7 @@ let generate_composite c1 c2 context metasenv univ arity last_lam_with_inn_arg =
         CicRefine.type_of_aux' metasenv context term ugraph
       in
       let body_metasenv, lambdas_metasenv = 
-        split_metasenv metasenv (spline_len + List.length context)
+        split_metasenv metasenv (spine_len + List.length context)
       in
       let lambdas_metasenv = 
         List.filter 
@@ -264,7 +269,7 @@ let generate_composite c1 c2 context metasenv univ arity last_lam_with_inn_arg =
         CicRefine.insert_coercions := old_insert_coercions;
         raise exn
   in  
-  c, metasenv, univ 
+  c, metasenv, univ, saturationsres
 ;;
 
 let build_obj c univ arity =
@@ -291,7 +296,7 @@ let filter_duplicates l coercions =
           CoercDb.eq_carr s src && 
           CoercDb.eq_carr t tgt &&
           try 
-            List.for_all2 (fun u1 u2 -> UriManager.eq u1 u2) l1 l2
+            List.for_all2 (fun (u1,_) (u2,_) -> UriManager.eq u1 u2) l1 l2
           with
           | Invalid_argument "List.for_all2" -> false)
         coercions))
@@ -340,10 +345,10 @@ let number_if_already_defined buri name l =
 (* given a new coercion uri from src to tgt returns 
  * a list of (new coercion uri, coercion obj, universe graph) 
  *)
-let close_coercion_graph src tgt uri baseuri =
+let close_coercion_graph src tgt uri saturations baseuri =
   (* check if the coercion already exists *)
   let coercions = CoercDb.to_list () in
-  let todo_list = get_closure_coercions src tgt uri coercions in
+  let todo_list = get_closure_coercions src tgt (uri,saturations) coercions in
   let todo_list = filter_duplicates todo_list coercions in
   try
     let new_coercions = 
@@ -352,43 +357,45 @@ let close_coercion_graph src tgt uri baseuri =
           try 
             (match l with
             | [] -> assert false 
-            | he :: tl ->
+            | (he,saturations1) :: tl ->
                 let arity = match tgt with CoercDb.Fun n -> n | _ -> 0 in
                 let first_step = 
                   Cic.Constant ("", 
                     Some (CoercDb.term_of_carr (CoercDb.Uri he)),
-                    Cic.Sort Cic.Prop, [], obj_attrs arity)
+                    Cic.Sort Cic.Prop, [], obj_attrs arity), saturations1
                 in
                 let o,_ = 
-                  List.fold_left (fun (o,univ) coer ->
+                  List.fold_left (fun (o,univ) (coer,saturations) ->
                     match o with 
-                    | Cic.Constant (_,Some c,_,[],_) ->
-                        let t, menv, univ = 
-                          generate_composite c 
-                            (CoercDb.term_of_carr (CoercDb.Uri coer)) 
+                    | Cic.Constant (_,Some u,_,[],_),saturations1 ->
+                        let t, menv, univ, saturationsres = 
+                          generate_composite' (u,saturations1) 
+                            (CoercDb.term_of_carr (CoercDb.Uri coer),
+                             saturations) 
                             [] [] univ arity true
                         in
                         if (menv = []) then
                           HLog.warn "MENV non empty after composing coercions";
-                        build_obj t univ arity
+                        let o,univ = build_obj t univ arity in
+                         (o,saturationsres),univ
                     | _ -> assert false 
                   ) (first_step, CicUniv.empty_ugraph) tl
                 in
                 let name_src = CoercDb.name_of_carr src in
                 let name_tgt = CoercDb.name_of_carr tgt in
-                let by = List.map UriManager.name_of_uri l in
+                let by = List.map (fun u,_ -> UriManager.name_of_uri u) l in
                 let name = mangle name_tgt name_src by in
                 let c_uri = 
                   number_if_already_defined baseuri name 
-                    (List.map (fun (_,_,u,_) -> u) acc) 
+                    (List.map (fun (_,_,u,_,_) -> u) acc) 
                 in
-                let named_obj = 
+                let named_obj,saturations = 
                   match o with
-                  | Cic.Constant (_,bo,ty,vl,attrs) ->
-                      Cic.Constant (name,bo,ty,vl,attrs)
+                  | Cic.Constant (_,bo,ty,vl,attrs),saturations ->
+                      Cic.Constant (name,bo,ty,vl,attrs),saturations
                   | _ -> assert false 
                 in
-                  (src,tgt,c_uri,named_obj))::acc
+                  (src,tgt,c_uri,saturations,named_obj))::acc
           with UnableToCompose -> acc
       ) [] todo_list
     in
@@ -397,3 +404,12 @@ let close_coercion_graph src tgt uri baseuri =
 ;;
 
 CicCoercion.set_close_coercion_graph close_coercion_graph;;
+
+(* generate_composite (c2 (c1 s)) in the universe graph univ
+ * both living in the same context and metasenv *)
+let generate_composite c1 c2 context metasenv univ arity b =
+ let a,b,c,_ =
+  generate_composite' (c1,0) (c2,0) context metasenv univ arity b
+ in
+  a,b,c
+;;