1 module Ref = NReference
4 | Ce of NCic.hypothesis * NCic.obj list
5 | Fix of Ref.reference * string * NCic.term
7 (***** A function to restrict the context of a term getting rid of unsed
10 let restrict octx ctx ot =
11 let odummy = Cic.Implicit None in
12 let dummy = NCic.Meta (~-1,(0,NCic.Irl 0)) in
13 let rec aux m acc ot t =
16 | ohe::otl as octx,he::tl ->
17 if CicTypeChecker.does_not_occur octx 0 1 ot then
18 aux (m+1) acc (CicSubstitution.subst odummy ot)
19 (NCicSubstitution.subst dummy t) (otl,tl)
22 None,_ -> assert false
23 | Some (name,Cic.Decl oty),Ce ((name', NCic.Decl ty),objs) ->
24 aux (m+1) ((m+1,objs,None)::acc) (Cic.Lambda (name,oty,ot))
25 (NCic.Lambda (name',ty,t)) (otl,tl)
26 | Some (name,Cic.Decl oty),Fix (ref,name',ty) ->
27 aux (m+1) ((m+1,[],Some ref)::acc) (Cic.Lambda (name,oty,ot))
28 (NCic.Lambda (name',ty,t)) (otl,tl)
29 | Some (name,Cic.Def (obo,oty)),Ce ((name', NCic.Def (bo,ty)),objs) ->
30 aux (m+1) ((m+1,objs,None)::acc) (Cic.LetIn (name,obo,oty,ot))
31 (NCic.LetIn (name',bo,ty,t)) (otl,tl)
32 | _,_ -> assert false)
33 | _,_ -> assert false in
34 let rec split_lambdas_and_letins octx ctx infos (ote,te) =
35 match infos, ote, te with
36 ([], _, _) -> octx,ctx,ote
37 | ((_,objs,None)::tl, Cic.Lambda(name,oso,ota), NCic.Lambda(name',so,ta)) ->
38 split_lambdas_and_letins ((Some(name,(Cic.Decl oso)))::octx)
39 (Ce ((name',NCic.Decl so),objs)::ctx) tl (ota,ta)
40 | ((_,objs,Some r)::tl,Cic.Lambda(name,oso,ota),NCic.Lambda(name',so,ta)) ->
41 split_lambdas_and_letins ((Some(name,(Cic.Decl oso)))::octx)
42 (Fix (r,name',so)::ctx) tl (ota,ta)
43 | ((_,objs,None)::tl,Cic.LetIn(name,obo,oty,ota),NCic.LetIn(nam',bo,ty,ta))->
44 split_lambdas_and_letins ((Some (name,(Cic.Def (obo,oty))))::octx)
45 (Ce ((nam',NCic.Def (bo,ty)),objs)::ctx) tl (ota,ta)
46 | (_, _, _) -> assert false
48 let long_t,infos = aux 0 [] ot dummy (octx,ctx) in
49 let clean_octx,clean_ctx,clean_ot= split_lambdas_and_letins [] [] infos long_t
51 (*prerr_endline ("RESTRICT PRIMA: " ^ CicPp.pp ot (List.map (function None -> None | Some (name,_) -> Some name) octx));
52 prerr_endline ("RESTRICT DOPO: " ^ CicPp.pp clean_ot (List.map (function None -> None | Some (name,_) -> Some name) clean_octx));
54 clean_octx,clean_ctx,clean_ot, List.map (fun (rel,_,_) -> rel) infos
58 (**** The translation itself ****)
60 let cn_to_s = function
61 | Cic.Anonymous -> "_"
65 let splat mk_pi ctx t =
69 | Ce ((name, NCic.Def (bo,ty)),l') -> NCic.LetIn (name, ty, bo, t),l@l'
70 | Ce ((name, NCic.Decl ty),l') when mk_pi -> NCic.Prod (name, ty, t),l@l'
71 | Ce ((name, NCic.Decl ty),l') -> NCic.Lambda (name, ty, t),l@l'
72 | Fix (_,name,ty) when mk_pi -> NCic.Prod (name, ty, t),l
73 | Fix (_,name,ty) -> NCic.Lambda (name,ty,t),l)
77 let context_tassonomy ctx =
78 let rec split inner acc acc1 = function
79 | Ce _ :: tl when inner -> split inner (acc+1) (acc1+1) tl
80 | Fix _ ::tl -> split false acc (acc1+1) tl
84 (function Ce ((_, NCic.Decl _),_) | Fix _ -> true | _ -> false) l
86 acc, List.length l, List.length only_decl, acc1
91 let splat_args_for_rel ctx t ?rels n_fix =
96 let rec mk_irl = function 0 -> [] | n -> n::mk_irl (n - 1) in
97 mk_irl (List.length ctx)
99 let bound, free, _, primo_ce_dopo_fix = context_tassonomy ctx in
102 let rec aux = function
103 | n,_ when n = bound + n_fix -> []
105 (match List.nth ctx (n-1) with
106 | Fix (refe, _, _) when n < primo_ce_dopo_fix ->
107 NCic.Const refe :: aux (n-1,tl)
108 | Fix _ | Ce ((_, NCic.Decl _),_)-> NCic.Rel (he - n_fix)::aux(n-1,tl)
109 | Ce ((_, NCic.Def _),_) -> aux (n-1,tl))
110 | _,_ -> assert false
112 NCic.Appl (t:: aux (List.length ctx,rels))
115 let splat_args ctx t n_fix rels =
116 let bound, free, _, primo_ce_dopo_fix = context_tassonomy ctx in
119 let rec aux = function
122 (match List.nth ctx (n-1) with
123 | Ce ((_, NCic.Decl _),_) when n <= bound -> NCic.Rel he:: aux (n-1,tl)
124 | Fix (refe, _, _) when n < primo_ce_dopo_fix ->
125 splat_args_for_rel ctx (NCic.Const refe) ~rels n_fix :: aux (n-1,tl)
126 | Fix _ | Ce ((_, NCic.Decl _),_) -> NCic.Rel (he - n_fix)::aux(n-1,tl)
127 | Ce ((_, NCic.Def _),_) -> aux (n - 1,tl)
129 | _,_ -> assert false
131 NCic.Appl (t:: aux ((List.length ctx,rels)))
134 exception Nothing_to_do;;
136 let fix_outty curi tyno t context outty =
138 match fst (CicEnvironment.get_obj CicUniv.oblivion_ugraph curi) with
139 Cic.InductiveDefinition (tyl,_,leftno,_) ->
140 let _,_,arity,_ = List.nth tyl tyno in
141 let rec count_prods leftno context arity =
142 match leftno, CicReduction.whd context arity with
144 | 0, Cic.Prod (name,so,ty) ->
145 1 + count_prods 0 (Some (name, Cic.Decl so)::context) ty
146 | n, Cic.Prod (name,so,ty) ->
147 count_prods (leftno - 1) (Some (name, Cic.Decl so)::context) ty
148 | _,_ -> assert false
150 (*prerr_endline (UriManager.string_of_uri curi);
151 prerr_endline ("LEFTNO: " ^ string_of_int leftno ^ " " ^ CicPp.ppterm arity);*)
152 leftno, count_prods leftno [] arity
153 | _ -> assert false in
155 let tty,_= CicTypeChecker.type_of_aux' [] context t CicUniv.oblivion_ugraph in
156 match CicReduction.whd context tty with
157 Cic.MutInd (_,_,ens) -> ens,[]
158 | Cic.Appl (Cic.MutInd (_,_,ens)::args) ->
159 ens,fst (HExtlib.split_nth leftno args)
162 let rec aux n irl context outsort =
163 match n, CicReduction.whd context outsort with
164 0, Cic.Prod _ -> raise Nothing_to_do
166 let irl = List.rev irl in
167 let ty = CicSubstitution.lift rightno (Cic.MutInd (curi,tyno,ens)) in
169 if args = [] && irl = [] then ty
171 Cic.Appl (ty::(List.map (CicSubstitution.lift rightno) args)@irl) in
172 let he = CicSubstitution.lift (rightno + 1) outty in
175 else Cic.Appl (he::List.map (CicSubstitution.lift 1) irl)
177 Cic.Lambda (Cic.Anonymous, ty, t)
178 | n, Cic.Prod (name,so,ty) ->
180 aux (n - 1) (Cic.Rel n::irl) (Some (name, Cic.Decl so)::context) ty
182 Cic.Lambda (name,so,ty')
183 | _,_ -> assert false
185 (*prerr_endline ("RIGHTNO = " ^ string_of_int rightno ^ " OUTTY = " ^ CicPp.ppterm outty);*)
187 fst (CicTypeChecker.type_of_aux' [] context outty CicUniv.oblivion_ugraph)
189 try aux rightno [] context outsort
190 with Nothing_to_do -> outty
191 (*prerr_endline (CicPp.ppterm outty ^ " <==> " ^ CicPp.ppterm outty');*)
195 let module C = Cic in
196 let rec aux context =
199 | C.Var (uri,exp_named_subst) ->
200 let exp_named_subst' =
201 List.map (function i,t -> i, (aux context t)) exp_named_subst in
202 C.Var (uri,exp_named_subst')
204 | C.Meta _ -> assert false
206 | C.Cast (v,t) -> C.Cast (aux context v, aux context t)
208 C.Prod (n, aux context s, aux ((Some (n, C.Decl s))::context) t)
209 | C.Lambda (n,s,t) ->
210 C.Lambda (n, aux context s, aux ((Some (n, C.Decl s))::context) t)
211 | C.LetIn (n,s,ty,t) ->
213 (n, aux context s, aux context ty,
214 aux ((Some (n, C.Def(s,ty)))::context) t)
215 | C.Appl l -> C.Appl (List.map (aux context) l)
216 | C.Const (uri,exp_named_subst) ->
217 let exp_named_subst' =
218 List.map (function i,t -> i, (aux context t)) exp_named_subst
220 C.Const (uri,exp_named_subst')
221 | C.MutInd (uri,tyno,exp_named_subst) ->
222 let exp_named_subst' =
223 List.map (function i,t -> i, (aux context t)) exp_named_subst
225 C.MutInd (uri, tyno, exp_named_subst')
226 | C.MutConstruct (uri,tyno,consno,exp_named_subst) ->
227 let exp_named_subst' =
228 List.map (function i,t -> i, (aux context t)) exp_named_subst
230 C.MutConstruct (uri, tyno, consno, exp_named_subst')
231 | C.MutCase (uri, tyno, outty, term, patterns) ->
232 let outty = fix_outty uri tyno term context outty in
233 C.MutCase (uri, tyno, aux context outty,
234 aux context term, List.map (aux context) patterns)
235 | C.Fix (funno, funs) ->
238 (fun (types,len) (n,_,ty,_) ->
239 ((Some (C.Name n,(C.Decl (CicSubstitution.lift len ty)))))::types,
245 (fun (name, indidx, ty, bo) ->
246 (name, indidx, aux context ty, aux (tys@context) bo)
249 | C.CoFix (funno, funs) ->
252 (fun (types,len) (n,ty,_) ->
253 ((Some (C.Name n,(C.Decl (CicSubstitution.lift len ty)))))::types,
259 (fun (name, ty, bo) ->
260 (name, aux context ty, aux (tys@context) bo)
267 let get_fresh,reset_seed =
271 string_of_int !seed),
272 (function () -> seed := 0)
276 let alpha t1 t2 ref ref' =
277 let rec aux t1 t2 = match t1,t2 with
278 | NCic.Rel n, NCic.Rel m when n=m -> ()
279 | NCic.Appl l1, NCic.Appl l2 -> List.iter2 aux l1 l2
280 | NCic.Lambda (_,s1,t1), NCic.Lambda (_,s2,t2)
281 | NCic.Prod (_,s1,t1), NCic.Prod (_,s2,t2) -> aux s1 s2; aux t1 t2
282 | NCic.LetIn (_,s1,ty1,t1), NCic.LetIn (_,s2,ty2,t2) ->
283 aux s1 s2; aux ty1 ty2; aux t1 t2
285 NCic.Const r2 when NReference.eq r1 ref && NReference.eq r2 ref' -> ()
286 | NCic.Const r1, NCic.Const r2 when NReference.eq r1 r2 -> ()
287 | NCic.Meta _,NCic.Meta _ -> ()
288 | NCic.Implicit _,NCic.Implicit _ -> ()
289 | NCic.Sort x,NCic.Sort y when x=y -> ()
290 | NCic.Match (_,t1,t11,tl1), NCic.Match (_,t2,t22,tl2) ->
291 aux t1 t2;aux t11 t22;List.iter2 aux tl1 tl2
292 | _-> raise NotSimilar
294 try aux t1 t2; true with NotSimilar -> false
297 exception Found of NReference.reference;;
298 let cache = Hashtbl.create 313;;
299 let same_obj ref ref' =
301 | (_,_,_,_,NCic.Fixpoint (_,l1,_)), (_,_,_,_,NCic.Fixpoint (_,l2,_))
302 when List.for_all2 (fun (_,_,_,ty1,bo1) (_,_,_,ty2,bo2) ->
303 alpha ty1 ty2 ref ref' && alpha bo1 bo2 ref ref') l1 l2 ->
307 let find_in_cache name obj ref =
310 (function (ref',obj') ->
313 NReference.Ref (_,_,NReference.Fix (fixno,recno)) -> recno,fixno
314 | _ -> assert false in
317 NReference.Ref (_,_,NReference.Fix (fixno',recno)) -> recno,fixno'
318 | _ -> assert false in
319 if recno = recno' && fixno = fixno' && same_obj ref ref' (obj,obj') then (
321 prerr_endline ("!!!!!!!!!!! CACHE HIT !!!!!!!!!!\n" ^
322 NReference.string_of_reference ref ^ "\n" ^
323 NReference.string_of_reference ref' ^ "\n");
328 prerr_endline ("CACHE SAME NAME: " ^ NReference.string_of_reference ref ^ " <==> " ^ NReference.string_of_reference ref');
331 ) (Hashtbl.find_all cache name);
332 (* prerr_endline "<<< CACHE MISS >>>"; *)
335 | (_,_,_,_,NCic.Fixpoint (true,fl,_)) , NReference.Ref (x,y,NReference.Fix _) ->
336 ignore(List.fold_left (fun i (_,name,rno,_,_) ->
337 let ref = NReference.mk_fix i rno ref in
338 Hashtbl.add cache name (ref,obj);
344 with Found ref -> Some ref
347 (* we are lambda-lifting also variables that do not occur *)
348 (* ctx does not distinguish successive blocks of cofix, since there may be no
349 * lambda separating them *)
350 let convert_term uri t =
351 (* k=true if we are converting a term to be pushed in a ctx or if we are
352 converting the type of a fix;
353 k=false if we are converting a term to be put in the body of a fix;
354 in the latter case, we must permute Rels since the Fix abstraction will
355 preceed its lefts parameters; in the former case, there is nothing to
357 let rec aux k octx (ctx : ctx list) n_fix uri = function
358 | Cic.CoFix _ as cofix ->
359 let octx,ctx,fix,rels = restrict octx ctx cofix in
361 match fix with Cic.CoFix (cofixno,fl)->cofixno,fl | _-> assert false in
363 UriManager.uri_of_string
364 (UriManager.buri_of_uri uri^"/"^
365 UriManager.name_of_uri uri ^ "___" ^ get_fresh () ^ ".con")
367 let bctx, fixpoints_tys, tys, _ =
369 (fun (name,ty,_) (bctx, fixpoints, tys, idx) ->
370 let ty, fixpoints_ty = aux true octx ctx n_fix uri ty in
371 let r = Ref.reference_of_ouri buri(Ref.CoFix idx) in
372 bctx @ [Fix (r,name,ty)], fixpoints_ty @ fixpoints,ty::tys,idx-1)
373 fl ([], [], [], List.length fl-1)
375 let bctx = bctx @ ctx in
376 let n_fl = List.length fl in
379 (fun (types,len) (n,ty,_) ->
380 (Some (Cic.Name n,(Cic.Decl (CicSubstitution.lift len ty)))::types,
385 (fun (name,_,bo) ty (l,fixpoints) ->
386 let bo, fixpoints_bo = aux false boctx bctx n_fl buri bo in
387 let splty,fixpoints_splty = splat true ctx ty in
388 let splbo,fixpoints_splbo = splat false ctx bo in
389 (([],name,~-1,splty,splbo)::l),
390 fixpoints_bo @ fixpoints_splty @ fixpoints_splbo @ fixpoints)
391 fl tys ([],fixpoints_tys)
394 NUri.nuri_of_ouri buri,0,[],[],
395 NCic.Fixpoint (false, fl, (`Generated, `Definition))
398 (NCic.Const (Ref.reference_of_ouri buri (Ref.CoFix cofixno)))
401 | Cic.Fix _ as fix ->
402 let octx,ctx,fix,rels = restrict octx ctx fix in
404 match fix with Cic.Fix (fixno,fl) -> fixno,fl | _ -> assert false in
406 UriManager.uri_of_string
407 (UriManager.buri_of_uri uri^"/"^
408 UriManager.name_of_uri uri ^ "___" ^ get_fresh () ^ ".con")
410 let bad_bctx, fixpoints_tys, tys, _ =
412 (fun (name,recno,ty,_) (bctx, fixpoints, tys, idx) ->
413 let ty, fixpoints_ty = aux true octx ctx n_fix uri ty in
414 let r = (* recno is dummy here, must be lifted by the ctx len *)
415 Ref.reference_of_ouri buri (Ref.Fix (idx,recno))
417 bctx @ [Fix (r,name,ty)], fixpoints_ty@fixpoints,ty::tys,idx-1)
418 fl ([], [], [], List.length fl-1)
420 let _, _, free_decls, _ = context_tassonomy (bad_bctx @ ctx) in
423 | Fix (Ref.Ref (_,_,Ref.Fix (idx, recno)),name, ty) ->
424 Fix (Ref.reference_of_ouri buri
425 (Ref.Fix (idx,recno+free_decls)),name,ty)
426 | _ -> assert false) bad_bctx @ ctx
428 let n_fl = List.length fl in
431 (fun (types,len) (n,_,ty,_) ->
432 (Some (Cic.Name n,(Cic.Decl (CicSubstitution.lift len ty)))::types,
435 let rno_fixno = ref 0 in
436 let fl, fixpoints,_ =
438 (fun (name,rno,_,bo) ty (l,fixpoints,idx) ->
439 let bo, fixpoints_bo = aux false boctx bctx n_fl buri bo in
440 let splty,fixpoints_splty = splat true ctx ty in
441 let splbo,fixpoints_splbo = splat false ctx bo in
442 let rno = rno + free_decls in
443 if idx = fixno then rno_fixno := rno;
444 (([],name,rno,splty,splbo)::l),
445 fixpoints_bo@fixpoints_splty@fixpoints_splbo@fixpoints,idx+1)
446 fl tys ([],fixpoints_tys,0)
449 NUri.nuri_of_ouri buri,max_int,[],[],
450 NCic.Fixpoint (true, fl, (`Generated, `Definition)) in
451 let r = Ref.reference_of_ouri buri (Ref.Fix (fixno,!rno_fixno)) in
453 let _,name,_,_,_ = List.nth fl fixno in
454 match find_in_cache name obj r with
458 splat_args ctx (NCic.Const r) n_fix rels, fixpoints @ obj
460 let bound, _, _, primo_ce_dopo_fix = context_tassonomy ctx in
461 (match List.nth ctx (n-1) with
462 | Fix (r,_,_) when n < primo_ce_dopo_fix ->
463 splat_args_for_rel ctx (NCic.Const r) n_fix, []
464 | Ce _ when n <= bound -> NCic.Rel n, []
465 | Fix _ when n <= bound -> assert false
466 | Fix _ | Ce _ when k = true -> NCic.Rel n, []
467 | Fix _ | Ce _ -> NCic.Rel (n-n_fix), [])
468 | Cic.Lambda (name, (s as old_s), t) ->
469 let s, fixpoints_s = aux k octx ctx n_fix uri s in
470 let s', fixpoints_s' = aux true octx ctx n_fix uri old_s in
471 let ctx = Ce ((cn_to_s name, NCic.Decl s'),fixpoints_s') :: ctx in
472 let octx = Some (name, Cic.Decl old_s) :: octx in
473 let t, fixpoints_t = aux k octx ctx n_fix uri t in
474 NCic.Lambda (cn_to_s name, s, t), fixpoints_s @ fixpoints_t
475 | Cic.Prod (name, (s as old_s), t) ->
476 let s, fixpoints_s = aux k octx ctx n_fix uri s in
477 let s', fixpoints_s' = aux true octx ctx n_fix uri old_s in
478 let ctx = Ce ((cn_to_s name, NCic.Decl s'),fixpoints_s') :: ctx in
479 let octx = Some (name, Cic.Decl old_s) :: octx in
480 let t, fixpoints_t = aux k octx ctx n_fix uri t in
481 NCic.Prod (cn_to_s name, s, t), fixpoints_s @ fixpoints_t
482 | Cic.LetIn (name, (te as old_te), (ty as old_ty), t) ->
483 let te, fixpoints_s = aux k octx ctx n_fix uri te in
484 let te', fixpoints_s' = aux true octx ctx n_fix uri old_te in
485 let ty, fixpoints_ty = aux k octx ctx n_fix uri ty in
486 let ty', fixpoints_ty' = aux true octx ctx n_fix uri old_ty in
487 let fixpoints' = fixpoints_s' @ fixpoints_ty' in
488 let ctx = Ce ((cn_to_s name, NCic.Def (te', ty')),fixpoints') :: ctx in
489 let octx = Some (name, Cic.Def (old_te, old_ty)) :: octx in
490 let t, fixpoints_t = aux k octx ctx n_fix uri t in
491 NCic.LetIn (cn_to_s name, ty, te, t),
492 fixpoints_s @ fixpoints_t @ fixpoints_ty
494 let t, fixpoints_t = aux k octx ctx n_fix uri t in
495 let ty, fixpoints_ty = aux k octx ctx n_fix uri ty in
496 NCic.LetIn ("cast", ty, t, NCic.Rel 1), fixpoints_t @ fixpoints_ty
497 | Cic.Sort Cic.Prop -> NCic.Sort NCic.Prop,[]
498 | Cic.Sort Cic.CProp -> NCic.Sort NCic.CProp,[]
499 | Cic.Sort (Cic.Type u) ->
500 NCic.Sort (NCic.Type (CicUniv.get_rank u+1)),[]
501 | Cic.Sort Cic.Set -> NCic.Sort (NCic.Type 0),[]
502 (* calculate depth in the univ_graph*)
507 let t, fixpoints = aux k octx ctx n_fix uri t in
508 (t::l,fixpoints@acc))
512 | (NCic.Appl l1)::l2 -> NCic.Appl (l1@l2), fixpoints
513 | _ -> NCic.Appl l, fixpoints)
514 | Cic.Const (curi, ens) ->
515 aux_ens k curi octx ctx n_fix uri ens
516 (match fst(CicEnvironment.get_obj CicUniv.oblivion_ugraph curi) with
517 | Cic.Constant (_,Some _,_,_,_) ->
518 NCic.Const (Ref.reference_of_ouri curi Ref.Def)
519 | Cic.Constant (_,None,_,_,_) ->
520 NCic.Const (Ref.reference_of_ouri curi Ref.Decl)
522 | Cic.MutInd (curi, tyno, ens) ->
523 aux_ens k curi octx ctx n_fix uri ens
524 (NCic.Const (Ref.reference_of_ouri curi (Ref.Ind tyno)))
525 | Cic.MutConstruct (curi, tyno, consno, ens) ->
526 aux_ens k curi octx ctx n_fix uri ens
527 (NCic.Const (Ref.reference_of_ouri curi (Ref.Con (tyno,consno))))
528 | Cic.Var (curi, ens) ->
529 (match fst (CicEnvironment.get_obj CicUniv.oblivion_ugraph curi) with
530 Cic.Variable (_,Some bo,_,_,_) ->
531 aux k octx ctx n_fix uri (CicSubstitution.subst_vars ens bo)
533 | Cic.MutCase (curi, tyno, outty, t, branches) ->
534 let r = Ref.reference_of_ouri curi (Ref.Ind tyno) in
535 let outty, fixpoints_outty = aux k octx ctx n_fix uri outty in
536 let t, fixpoints_t = aux k octx ctx n_fix uri t in
537 let branches, fixpoints =
540 let t, fixpoints = aux k octx ctx n_fix uri t in
541 (t::l,fixpoints@acc))
544 NCic.Match (r,outty,t,branches), fixpoints_outty@fixpoints_t@fixpoints
545 | Cic.Implicit _ | Cic.Meta _ -> assert false
546 and aux_ens k curi octx ctx n_fix uri ens he =
551 match fst (CicEnvironment.get_obj CicUniv.oblivion_ugraph curi) with
552 Cic.Constant (_,_,_,params,_)
553 | Cic.InductiveDefinition (_,params,_,_) -> params
555 | Cic.CurrentProof _ -> assert false
559 (fun luri (l,objs) ->
560 match fst (CicEnvironment.get_obj CicUniv.oblivion_ugraph luri) with
561 Cic.Variable (_,Some _,_,_,_) -> l, objs
562 | Cic.Variable (_,None,_,_,_) ->
563 let t = List.assoc luri ens in
564 let t,o = aux k octx ctx n_fix uri t in
569 NCic.Appl (he::ens),objs
571 aux false [] [] 0 uri t
574 let cook mode vars t =
575 let t = fix_outtype t in
576 let varsno = List.length vars in
577 let t = CicSubstitution.lift varsno t in
578 let rec aux n acc l =
580 snd(List.fold_left (fun (i,res) uri -> i+1,(uri,Cic.Rel i)::res) (1,[]) acc)
583 [] -> CicSubstitution.subst_vars subst t
586 match fst (CicEnvironment.get_obj CicUniv.oblivion_ugraph uri) with
587 Cic.Variable (_,bo,ty,_,_) ->
588 HExtlib.map_option fix_outtype bo, fix_outtype ty
589 | _ -> assert false in
590 let ty = CicSubstitution.subst_vars subst ty in
591 let bo = HExtlib.map_option (CicSubstitution.subst_vars subst) bo in
592 let id = Cic.Name (UriManager.name_of_uri uri) in
593 let t = aux (n-1) (uri::acc) uris in
594 match bo,ty,mode with
595 None,ty,`Lambda -> Cic.Lambda (id,ty,t)
596 | None,ty,`Pi -> Cic.Prod (id,ty,t)
597 | Some bo,ty,_ -> Cic.LetIn (id,bo,ty,t)
602 let convert_obj_aux uri = function
603 | Cic.Constant (name, None, ty, vars, _) ->
604 let ty = cook `Pi vars ty in
605 let nty, fixpoints = convert_term uri ty in
606 assert(fixpoints = []);
607 NCic.Constant ([], name, None, nty, (`Provided,`Theorem,`Regular)),
609 | Cic.Constant (name, Some bo, ty, vars, _) ->
610 let bo = cook `Lambda vars bo in
611 let ty = cook `Pi vars ty in
612 let nbo, fixpoints_bo = convert_term uri bo in
613 let nty, fixpoints_ty = convert_term uri ty in
614 assert(fixpoints_ty = []);
615 NCic.Constant ([], name, Some nbo, nty, (`Provided,`Theorem,`Regular)),
616 fixpoints_bo @ fixpoints_ty
617 | Cic.InductiveDefinition (itl,vars,leftno,_) ->
618 let ind = let _,x,_,_ = List.hd itl in x in
621 (fun (name, _, ty, cl) (itl,acc) ->
622 let ty = cook `Pi vars ty in
623 let ty, fix_ty = convert_term uri ty in
626 (fun (name, ty) (cl,acc) ->
627 let ty = cook `Pi vars ty in
628 let ty, fix_ty = convert_term uri ty in
629 ([], name, ty)::cl, acc @ fix_ty)
632 ([], name, ty, cl)::itl, fix_ty @ fix_cl @ acc)
635 NCic.Inductive(ind, leftno + List.length
636 (List.filter (fun v ->
637 match fst (CicEnvironment.get_obj CicUniv.oblivion_ugraph v) with
638 Cic.Variable (_,Some _,_,_,_) -> false
639 | Cic.Variable (_,None,_,_,_) -> true
642 , itl, (`Provided, `Regular)),
645 | Cic.CurrentProof _ -> assert false
648 let convert_obj uri obj =
650 let o, fixpoints = convert_obj_aux uri obj in
651 let obj = NUri.nuri_of_ouri uri,max_int, [], [], o in