]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/ng_refiner/nCicRefiner.ml
- hExtlib: added debugging information for split_nth
[helm.git] / helm / software / components / ng_refiner / nCicRefiner.ml
index e38842ac82c57c6c454582438a5726f6f89ba86a..68a1b2cbe983f0746a33e2fc9fe54b02de009ea7 100644 (file)
@@ -250,7 +250,7 @@ let rec typeof hdb
       let ind = if args = [] then C.Const r else C.Appl (C.Const r::args) in
       let metasenv, subst, term, _ = 
         typeof_aux metasenv subst context (Some ind) term in
-      let parameters, arguments = HExtlib.split_nth leftno args in
+      let parameters, arguments = HExtlib.split_nth "NR 1" leftno args in
       let outtype =  
         match outtype with
         | C.Implicit _ as ot -> 
@@ -384,8 +384,8 @@ and force_to_sort hdb
   match NCicReduction.whd ~subst context ty with
   | C.Meta (_,(0,(C.Irl 0 | C.Ctx []))) as ty -> 
      metasenv, subst, t, ty
-  | C.Meta (i,(_,(C.Irl 0 | C.Ctx []))) -> 
-     metasenv, subst, t, C.Meta(i,(0,C.Irl 0))
+  | C.Meta (i,(_,(C.Irl 0 | C.Ctx []))) -> assert false (*CSC: ???
+     metasenv, subst, t, C.Meta(i,(0,C.Irl 0)) *)
   | C.Meta (i,(_,lc)) ->
      let len = match lc with C.Irl len->len | C.Ctx l->List.length l in
      let metasenv, subst, newmeta = 
@@ -524,12 +524,12 @@ let relocalise old_localise dt t add =
 
 let undebruijnate inductive ref t rev_fl =
   NCicSubstitution.psubst (fun x -> x) 
-    (HExtlib.list_mapi 
+   (List.rev (HExtlib.list_mapi 
       (fun (_,_,rno,_,_,_) i -> 
          NCic.Const 
            (if inductive then NReference.mk_fix i rno ref
             else NReference.mk_cofix i ref))
-      rev_fl)
+      rev_fl))
     t
 ;; 
 
@@ -538,6 +538,7 @@ let typeof_obj hdb
   ?(localise=fun _ -> Stdpp.dummy_loc) 
   ~look_for_coercion (uri,height,metasenv,subst,obj)
 = 
+prerr_endline ("===============\n" ^ NCicPp.ppobj (uri,height,metasenv,subst,obj));
   let check_type metasenv subst context (ty as orig_ty) =  (* XXX fattorizza *)
     let metasenv, subst, ty, sort = 
       typeof hdb ~localise ~look_for_coercion metasenv subst context ty None
@@ -613,17 +614,20 @@ let typeof_obj hdb
       List.fold_left
        (fun (metasenv,subst,res,i) (it_relev,n,ty,cl) ->
          let context,ty_sort = NCicReduction.split_prods ~subst [] ~-1 ty in
-         let sx_context_ty_rev,_= HExtlib.split_nth leftno (List.rev context) in
+         let sx_context_ty_rev,_= HExtlib.split_nth "NR 2" leftno (List.rev context) in
          let metasenv,subst,cl =
           List.fold_right
            (fun (k_relev,n,te) (metasenv,subst,res) ->
-            let _,k_relev = HExtlib.split_nth leftno k_relev in
+            let k_relev =
+              try snd (HExtlib.split_nth "NR 3" leftno k_relev)
+              with Failure _ -> k_relev in
              let te = NCicTypeChecker.debruijn uri len [] te in
+             let metasenv, subst, te, _ = check_type metasenv subst tys te in
              let context,te = NCicReduction.split_prods ~subst tys leftno te in
              let _,chopped_context_rev =
-              HExtlib.split_nth (List.length tys) (List.rev context) in
+              HExtlib.split_nth "NR 4" (List.length tys) (List.rev context) in
              let sx_context_te_rev,_ =
-              HExtlib.split_nth leftno chopped_context_rev in
+              HExtlib.split_nth "NR 5" leftno chopped_context_rev in
              let metasenv,subst,_ =
               try
                List.fold_left2
@@ -664,11 +668,8 @@ let typeof_obj hdb
                    else
                     metasenv,subst,item1::context
                 ) (metasenv,subst,[]) sx_context_ty_rev sx_context_te_rev
-              with Invalid_argument "List.fold_left2" -> assert false
-             in
-             let metasenv, subst, te, con_sort = 
-               check_type metasenv subst context te 
-             in
+              with Invalid_argument "List.fold_left2" -> assert false in
+             let con_sort= NCicTypeChecker.typeof ~subst ~metasenv context te in
               (match
                 NCicReduction.whd ~subst context con_sort,
                 NCicReduction.whd ~subst [] ty_sort
@@ -700,14 +701,26 @@ let typeof_obj hdb
                     (lazy (localise te,
                       "Non positive occurence in " ^ NUri.string_of_uri uri)))
               else
+               let relsno = List.length itl + leftno in
                let te = 
                  NCicSubstitution.psubst 
-                  (fun i -> NCic.Const (NReference.reference_of_spec uri
-                     (NReference.Ind (ind,i,leftno))))
-                  (List.rev (HExtlib.list_seq 0 (List.length itl)))
-                   te 
-               in      
-               metasenv,subst,(k_relev,n,te)::res
+                  (fun i ->
+                    if i <= leftno  then
+                     NCic.Rel i
+                    else
+                     NCic.Const (NReference.reference_of_spec uri
+                      (NReference.Ind (ind,relsno - i,leftno))))
+                  (HExtlib.list_seq 1 (relsno+1))
+                   te in
+               let te =
+                List.fold_right
+                 (fun (name,decl) te ->
+                   match decl with
+                      NCic.Decl ty -> NCic.Prod (name,ty,te)
+                    | NCic.Def (bo,ty) -> NCic.LetIn (name,ty,bo,te)
+                 ) sx_context_te_rev te
+               in
+                metasenv,subst,(k_relev,n,te)::res
               ) cl (metasenv,subst,[])
          in
           metasenv,subst,(it_relev,n,ty,cl)::res,i+1