]> matita.cs.unibo.it Git - helm.git/blobdiff - components/tactics/substTactic.ml
cic_acic should be compiled before cic_exportation
[helm.git] / components / tactics / substTactic.ml
index fd11631ac6343f4cb2368e1054e0210cfcbae1ed..feff68f3fb8186f4ab4644ff2b07cce1b0e7accc 100644 (file)
@@ -40,7 +40,7 @@ module TC   = CicTypeChecker
 let lift_rewrite_tac ~context ~direction ~pattern equality =
    let lift_rewrite_tac status =
       let (proof, goal) = status in
-      let (_, metasenv, _, _, _) = proof in
+      let (_, metasenv, _subst, _, _, _) = proof in
       let _, new_context, _ = CicUtil.lookup_meta goal metasenv in
       let n = List.length new_context - List.length context in
       let equality = S.lift n equality in
@@ -51,7 +51,7 @@ let lift_rewrite_tac ~context ~direction ~pattern equality =
 let lift_destruct_tac ~context ~what =
    let lift_destruct_tac status =
       let (proof, goal) = status in
-      let (_, metasenv, _, _, _) = proof in
+      let (_, metasenv, _subst, _, _, _) = proof in
       let _, new_context, _ = CicUtil.lookup_meta goal metasenv in
       let n = List.length new_context - List.length context in
       let what = S.lift n what in
@@ -67,6 +67,11 @@ let msg3 = lazy "Subst: no progress"
 let rec subst_tac ~try_tactic ~hyp =
    let hole = C.Implicit (Some `Hole) in
    let meta = C.Implicit None in
+   let rec ind = function
+      | C.MutInd _       -> true
+      | C.Appl (t :: tl) -> ind t
+      | _                -> false
+   in
    let rec constr = function
       | C.MutConstruct _ -> true
       | C.Appl (t :: tl) -> constr t
@@ -74,7 +79,7 @@ let rec subst_tac ~try_tactic ~hyp =
    in
    let subst_tac status =
       let (proof, goal) = status in
-      let (_, metasenv, _, _, _) = proof in
+      let (_, metasenv, _subst, _, _, _) = proof in
       let _, context, _ = CicUtil.lookup_meta goal metasenv in
       let what = match PEH.get_rel context hyp with
          | Some t -> t
@@ -105,7 +110,7 @@ let rec subst_tac ~try_tactic ~hyp =
          [lift_destruct_tac ~context ~what; PESR.clear ~hyps:[hyp]]
       in
       let whd_g () =
-         let whd_pattern = C.Appl [meta; meta; hole; hole] in
+         let whd_pattern = C.Appl [meta; hole; hole; hole] in
         let pattern = None, [hyp, whd_pattern], None in
         [RT.whd_tac ~pattern; subst_tac ~try_tactic ~hyp]
       in
@@ -114,8 +119,8 @@ let rec subst_tac ~try_tactic ~hyp =
            when LO.is_eq_URI uri -> subst_g `LeftToRight i t
          | (C.Appl [(C.MutInd (uri, 0, [])); _; t; C.Rel i]) 
            when LO.is_eq_URI uri -> subst_g `RightToLeft i t
-        | (C.Appl [(C.MutInd (uri, 0, [])); _; t1; t2]) 
-           when LO.is_eq_URI uri && constr t1 && constr t2 -> destruct_g ()
+        | (C.Appl [(C.MutInd (uri, 0, [])); t; t1; t2]) 
+           when LO.is_eq_URI uri && ind t && constr t1 && constr t2 -> destruct_g ()
         | (C.Appl [(C.MutInd (uri, 0, [])); _; t1; t2])
            when LO.is_eq_URI uri -> whd_g ()    
         | _ -> raise (PET.Fail msg1)
@@ -143,7 +148,7 @@ let subst_tac =
          | _                  -> None
       in
       let (proof, goal) = status in
-      let (_, metasenv, _, _, _) = proof in
+      let (_, metasenv, _subst, _, _, _) = proof in
       let _, context, _ = CicUtil.lookup_meta goal metasenv in
       let tactics = HEL.list_rev_map_filter map context in
       let result = PET.apply_tactic (T.seq ~tactics) status in
@@ -154,11 +159,6 @@ let subst_tac =
    let try_tac tactic = T.try_tactic ~tactic 
    let then_tac start continuation = T.then_ ~start ~continuation 
 
-let rec repeat_tactic ~tactic =
-   try_tac (then_tac tactic (repeat_tactic ~tactic))
-
 let subst_tac = 
-   let subst_tac status =
-      PET.apply_tactic (repeat_tactic ~tactic:subst_tac) status
-   in 
-   PET.mk_tactic subst_tac
+   let tactic = T.repeat_tactic ~tactic:subst_tac in
+   T.try_tactic ~tactic