]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/ng_refiner/nCicUnification.ml
improved check in delift for flexible lc entries.
[helm.git] / helm / software / components / ng_refiner / nCicUnification.ml
index b7141398465eb08afe6d453f690782dfd64dc1ad..2f6332d51d748ad0c90ecf71c81c5219ccd79cec 100644 (file)
@@ -96,14 +96,14 @@ let pp s =
   prerr_endline (Printf.sprintf "%-20s" !indent ^ " " ^ Lazy.force s)
 ;;
 
+let pp _ = ();;
+
 let ppcontext = NCicPp.ppcontext;;
 let ppmetasenv = NCicPp.ppmetasenv;;
 
 let ppcontext ~metasenv:_metasenv ~subst:_subst _context = "...";;
 let ppmetasenv ~subst:_subst _metasenv = "...";;
 
-let pp _ = ();;
-
 let fix_sorts swap exc t =
   let rec aux () = function
     | NCic.Sort (NCic.Type u) as orig ->
@@ -152,20 +152,11 @@ let rec lambda_intros rdb metasenv subst context t args =
        in
        metasenv, subst, bo
    | (arg,ty)::tail ->
+       let metasenv, subst, telescopic_ty = 
+         delift_term_wrt_terms rdb metasenv subst context_of_args ty 
+           (List.rev processed_args)
+       in
        let name = "HBeta"^string_of_int n in
-       let metasenv,_,instance,_ =
-        NCicMetaSubst.mk_meta metasenv context_of_args `Term in
-       let meta_applied =
-        NCicUntrusted.mk_appl instance (List.rev processed_args) in
-let metasenv,subst,_,_ =
- !refiner_typeof ((rdb :> NRstatus.status)#set_coerc_db NCicCoercion.empty_db) metasenv subst context_of_args meta_applied None
-in
-       let metasenv,subst =
-        unify rdb true metasenv subst context_of_args meta_applied ty in
-       let telescopic_ty = NCicSubstitution.lift n instance in
-       let telescopic_ty =
-        NCicUntrusted.mk_appl
-         telescopic_ty (mk_irl (List.length processed_args)) in
        let metasenv, subst, bo =
         mk_lambda metasenv subst ((name,NCic.Decl telescopic_ty)::context) (n+1)
          (arg::processed_args) tail
@@ -359,7 +350,9 @@ and unify rdb test_eq_only metasenv subst context t1 t2 =
                     (C.Meta (i,l)) lambda_Mj,
                    i
               | NCic.Meta (i,_) -> (metasenv, subst), i
-              | _ -> prerr_endline ("XXX: " ^ NCicPp.ppterm ~metasenv ~subst ~context (NCicReduction.whd ~subst context t1)); assert false
+              | _ ->
+                 raise (UnificationFailure (lazy "Locked term vs non
+                  flexible term; probably not saturated enough yet!"))
              in
               let t1 = NCicReduction.whd ~subst context t1 in
               let j, lj = 
@@ -621,8 +614,8 @@ pp (lazy (string_of_bool norm1 ^ " ?? " ^ string_of_bool norm2));
             | _ -> [] *) in
           let unif_from_stack t1 t2 b metasenv subst =
               try
-                let t1 = NCicReduction.from_stack t1 in
-                let t2 = NCicReduction.from_stack t2 in
+                let t1 = NCicReduction.from_stack ~delta:max_int t1 in
+                let t2 = NCicReduction.from_stack ~delta:max_int t2 in
                 unif_machines metasenv subst (put_in_whd t1 t2)
               with UnificationFailure _ | Uncertain _ when not b ->
                 metasenv, subst
@@ -667,8 +660,23 @@ pp (lazy (string_of_bool norm1 ^ " ?? " ^ string_of_bool norm2));
           | UnificationFailure _ -> raise (UnificationFailure msg)
           | Uncertain _ -> raise exn
  (*D*)  in outside(); rc with exn -> outside (); raise exn 
+
+and delift_term_wrt_terms rdb metasenv subst context t args =
+  let metasenv, _, instance, _ =
+    NCicMetaSubst.mk_meta metasenv context `Term in
+  let meta_applied = NCicUntrusted.mk_appl instance args in
+  let metasenv,subst,meta_applied,_ =
+    !refiner_typeof ((rdb:> NRstatus.status)#set_coerc_db NCicCoercion.empty_db)
+      metasenv subst context meta_applied None
+  in
+  let metasenv, subst =
+   unify rdb true metasenv subst context meta_applied t in
+  let t = NCicSubstitution.lift (List.length args) instance in
+  let t = NCicUntrusted.mk_appl t (mk_irl (List.length args)) in
+   metasenv, subst, t
 ;;
 
+
 let unify rdb ?(test_eq_only=false) = 
   indent := "";      
   unify rdb test_eq_only;;