]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/cic_unification/cicUnification.ml
Huge commit:
[helm.git] / helm / software / components / cic_unification / cicUnification.ml
index 86f280842f6a7480bb95cb60b35f00811b89b9fc..bcae08df80e69cafa21de0e5e695fa83ff737eb7 100644 (file)
@@ -593,55 +593,97 @@ debug_print (lazy ("restringo Meta n." ^ (string_of_int n) ^ "on variable n." ^
                   (match l1, l2 with
                   | (((Cic.Const (uri1, ens1)) as c1) :: tl1), 
                      (((Cic.Const (uri2, ens2)) as c2) :: tl2) when
-                    CoercGraph.is_a_coercion c1 && 
-                    CoercGraph.is_a_coercion c2 &&
+                    CoercDb.is_a_coercion' c1 && 
+                    CoercDb.is_a_coercion' c2 &&
                     not (UriManager.eq uri1 uri2) ->
-                      let body1, attrs1, ugraph = 
-                        match CicEnvironment.get_obj ugraph uri1 with
-                        | Cic.Constant (_,Some bo, _, _, attrs),u  -> bo,attrs,u
-                        | _ -> assert false
-                      in
-                      let body2, attrs2, ugraph = 
-                        match CicEnvironment.get_obj ugraph uri2 with
-                        | Cic.Constant (_,Some bo, _, _, attrs),u -> bo, attrs,u
-                        | _ -> assert false
-                      in
-                      let is_composite1 = 
-                        List.exists 
-                         (function `Class (`Coercion _) -> true | _-> false) 
-                         attrs1 
-                      in
-                      let is_composite2 = 
-                        List.exists 
-                         (function `Class (`Coercion _) -> true | _-> false) 
-                         attrs2 
-                      in
-                      (match is_composite1, is_composite2 with
-                      | false, false -> raise exn
-                      | true, false ->
-                          let body1 = CicSubstitution.subst_vars ens1 body1 in
-                          let appl = Cic.Appl (body1::tl1) in
-                          let redappl = CicReduction.head_beta_reduce appl in
-                          fo_unif_subst 
-                            test_equality_only subst context metasenv 
-                              redappl t2 ugraph
-                      | false, true -> 
-                          let body2 = CicSubstitution.subst_vars ens2 body2 in
-                          let appl = Cic.Appl (body2::tl2) in
-                          let redappl = CicReduction.head_beta_reduce appl in
-                          fo_unif_subst 
-                            test_equality_only subst context metasenv 
-                             t1 redappl ugraph
-                      | true, true ->
-                          let body1 = CicSubstitution.subst_vars ens1 body1 in
-                          let appl1 = Cic.Appl (body1::tl1) in
-                          let redappl1 = CicReduction.head_beta_reduce appl1 in
-                          let body2 = CicSubstitution.subst_vars ens2 body2 in
-                          let appl2 = Cic.Appl (body2::tl2) in
-                          let redappl2 = CicReduction.head_beta_reduce appl2 in
-                          fo_unif_subst 
-                            test_equality_only subst context metasenv 
-                             redappl1 redappl2 ugraph)
+(*DEBUGGING ONLY:
+prerr_endline ("<<<< " ^ CicMetaSubst.ppterm_in_context ~metasenv subst (C.Appl l1) context ^ " <==> " ^ CicMetaSubst.ppterm_in_context ~metasenv subst (C.Appl l2) context);
+let res =
+*)
+                     let rec look_for_first_coercion c tl =
+                      match
+                       CicMetaSubst.apply_subst subst (HExtlib.list_last tl)
+                      with
+                         Cic.Appl ((Cic.Const (uri1,ens1) as c')::tl')
+                          when CoercDb.is_a_coercion' c' ->
+                           look_for_first_coercion c' tl'
+                       | last_tl -> c,last_tl
+                     in
+                      let c1,last_tl1 = look_for_first_coercion c1 tl1 in 
+                      let c2,last_tl2 = look_for_first_coercion c2 tl2 in
+                      let car1 =
+                        CoercDb.coerc_carr_of_term (CoercGraph.source_of c1) in
+                      let car2 = 
+                        CoercDb.coerc_carr_of_term (CoercGraph.source_of c2) in
+                      if CoercDb.eq_carr car1 car2 then
+                       (match last_tl1,last_tl2 with
+                           C.Meta (i1,_),C.Meta(i2,_) when i1=i2 -> raise exn
+                         | C.Meta _, _
+                         | _, C.Meta _ ->
+                           let subst,metasenv,ugraph =
+                            fo_unif_subst test_equality_only subst context
+                             metasenv last_tl1 last_tl2 ugraph
+                           in
+                            fo_unif_subst test_equality_only subst context
+                             metasenv (C.Appl l1) (C.Appl l2) ugraph
+                         | _ -> raise exn)
+                      else
+                       let meets = CoercGraph.meets car1 car2 in
+                        (match meets with
+                        | [] -> raise exn
+                        | _::_::_ ->
+prerr_endline ("1: NON DOVEVA SUCCEDERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+assert false
+                        | [m] -> 
+                          let last_tl1',(subst,metasenv,ugraph) =
+                           match last_tl1 with
+                            | Cic.Meta (i1,l1)
+                              when not (CoercDb.eq_carr m car1) ->
+                               (match
+                                 CoercGraph.look_for_coercion' metasenv subst
+                                  context m car1
+                                with
+                                 | CoercGraph.SomeCoercion [metasenv,last,coerced]
+                                   ->
+                                    last,
+                                    fo_unif_subst test_equality_only subst context
+                                     metasenv coerced last_tl1 ugraph
+                                 | _ ->
+prerr_endline ("2: NON DOVEVA SUCCEDERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+assert false)
+                            | _ -> last_tl1,(subst,metasenv,ugraph) in
+                          let last_tl2',(subst,metasenv,ugraph) =
+                           match last_tl2 with
+                              Cic.Meta (i2,l2) when not (CoercDb.eq_carr m car2) ->
+                               (match
+                                 CoercGraph.look_for_coercion' metasenv subst
+                                  context m car2
+                                with
+                                 | CoercGraph.SomeCoercion [metasenv,last,coerced]
+                                   ->
+                                    last,
+                                    fo_unif_subst test_equality_only subst context
+                                     metasenv coerced last_tl2 ugraph
+                                 | _ ->
+prerr_endline ("3: NON DOVEVA SUCCEDERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+assert false)
+                            | _ -> last_tl2,(subst,metasenv,ugraph)
+                          in
+(*DEBUGGING ONLY:
+prerr_endline ("OK " ^ CicMetaSubst.ppterm_in_context ~metasenv subst last_tl1' context ^ " <==> " ^ CicMetaSubst.ppterm_in_context ~metasenv subst last_tl2' context);
+*)
+                           let subst,metasenv,ugraph =
+                            fo_unif_subst test_equality_only subst context
+                             metasenv last_tl1' last_tl2' ugraph
+                           in
+                            fo_unif_subst test_equality_only subst context
+                             metasenv (C.Appl l1) (C.Appl l2) ugraph)
+(*DEBUGGING ONLY:
+in
+let subst,metasenv,ugraph = res in
+prerr_endline (">>>> " ^ CicMetaSubst.ppterm_in_context ~metasenv subst (C.Appl l1) context ^ " <==> " ^ CicMetaSubst.ppterm_in_context ~metasenv subst (C.Appl l2) context);
+res
+*)
                   (*CSC: This is necessary because of the "elim H" tactic
                          where the type of H is only reducible to an
                          inductive type. This could be extended from inductive