2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department, University of Bologna, Italy.
6 ||T|| HELM is free software; you can redistribute it and/or
7 ||A|| modify it under the terms of the GNU General Public License
8 \ / version 2 or (at your option) any later version.
9 \ / This software is distributed as is, NO WARRANTY.
10 V_______________________________________________________________ *)
14 exception RefineFailure of (Stdpp.location * string) Lazy.t;;
15 exception Uncertain of (Stdpp.location * string) Lazy.t;;
16 exception AssertFailure of string Lazy.t;;
19 module Ref = NReference
21 let debug = ref false;;
26 prerr_endline (Printf.sprintf "%-20s" !indent ^ " " ^ Lazy.force s)
31 let time1 = Unix.gettimeofday () in
32 indent := !indent ^ String.make 1 c;
33 times := time1 :: !times;
34 prerr_endline ("{{{" ^ !indent ^ " ")
40 let time2 = Unix.gettimeofday () in
42 match !times with time1::tl -> times := tl; time1 | [] -> assert false in
43 prerr_endline ("}}} " ^ string_of_float (time2 -. time1));
44 if not ok then prerr_endline "exception raised!";
46 indent := String.sub !indent 0 (String.length !indent -1)
48 Invalid_argument _ -> indent := "??"; ()
53 let wrap_exc msg = function
54 | NCicUnification.Uncertain _ -> Uncertain msg
55 | NCicUnification.UnificationFailure _ -> RefineFailure msg
56 | NCicTypeChecker.TypeCheckerFailure _ -> RefineFailure msg
60 let exp_implicit rdb ~localise metasenv subst context with_type t =
63 let metasenv,subst,expty =
65 None -> metasenv,subst,None
67 let (metasenv,subst),typ =
70 ~unify:(fun m s c t1 t2 ->
71 try Some (NCicUnification.unify rdb m s c t1 t2)
72 with NCicUnification.UnificationFailure _ | NCicUnification.Uncertain _ -> None)
73 metasenv subst context 0 (0,NCic.Irl 0) typ
75 NCicMetaSubst.MetaSubstFailure _
76 | NCicMetaSubst.Uncertain _ ->
77 raise (RefineFailure (lazy (localise t,"Trying to create a closed meta with a non closed type: " ^ NCicPp.ppterm ~metasenv ~subst ~context typ)))
80 metasenv,subst,Some typ
82 NCicMetaSubst.mk_meta metasenv [] ?with_type:expty `IsTerm,subst
83 | `Type -> NCicMetaSubst.mk_meta metasenv context ?with_type `IsType,subst
84 | `Term -> NCicMetaSubst.mk_meta metasenv context ?with_type `IsTerm,subst
87 ~attrs:[`Name s] metasenv context ?with_type `IsTerm,subst
89 raise (RefineFailure (lazy (localise t, "A vector of implicit terms " ^
90 "can only be used in argument position")))
94 let check_allowed_sort_elimination rdb localise r orig =
97 | C.Appl l -> C.Appl (l @ [arg])
98 | t -> C.Appl [t;arg] in
99 (* ctx, ind_type @ lefts, sort_of_ind_ty@lefts, outsort *)
100 let rec aux metasenv subst context ind arity1 arity2 =
101 (*D*)inside 'S'; try let rc =
102 let arity1 = NCicReduction.whd ~subst context arity1 in
103 pp (lazy(NCicPp.ppterm ~subst ~metasenv ~context arity1 ^ " elimsto " ^
104 NCicPp.ppterm ~subst ~metasenv ~context arity2 ^ "\nMENV:\n"^
105 NCicPp.ppmetasenv ~subst metasenv));
107 | C.Prod (name,so1,de1) (* , t ==?== C.Prod _ *) ->
108 let metasenv, _, meta, _ =
109 NCicMetaSubst.mk_meta metasenv ((name,C.Decl so1)::context) `IsType
111 let metasenv, subst =
112 try NCicUnification.unify rdb metasenv subst context
113 arity2 (C.Prod (name, so1, meta))
114 with exc -> raise (wrap_exc (lazy (localise orig, Printf.sprintf
115 "expected %s, found %s" (* XXX localizzare meglio *)
116 (NCicPp.ppterm ~subst ~metasenv ~context (C.Prod (name, so1, meta)))
117 (NCicPp.ppterm ~subst ~metasenv ~context arity2))) exc)
119 aux metasenv subst ((name, C.Decl so1)::context)
120 (mkapp (NCicSubstitution.lift 1 ind) (C.Rel 1)) de1 meta
121 | C.Sort _ (* , t ==?== C.Prod _ *) ->
122 let metasenv, _, meta, _ = NCicMetaSubst.mk_meta metasenv [] `IsSort in
123 let metasenv, subst =
124 try NCicUnification.unify rdb metasenv subst context
125 arity2 (C.Prod ("_", ind, meta))
126 with exc -> raise (wrap_exc (lazy (localise orig, Printf.sprintf
127 "expected %s, found %s" (* XXX localizzare meglio *)
128 (NCicPp.ppterm ~subst ~metasenv ~context (C.Prod ("_", ind, meta)))
129 (NCicPp.ppterm ~subst ~metasenv ~context arity2))) exc)
131 (try NCicTypeChecker.check_allowed_sort_elimination
132 ~metasenv ~subst r context ind arity1 arity2;
134 with exc -> raise (wrap_exc (lazy (localise orig,
135 "Sort elimination not allowed ")) exc))
137 (*D*)in outside true; rc with exc -> outside false; raise exc
143 ?(localise=fun _ -> Stdpp.dummy_loc)
144 metasenv subst context term expty
146 let force_ty skip_lambda skip_appl metasenv subst context orig t infty expty =
147 (*D*)inside 'F'; try let rc =
151 | C.Implicit _ -> assert false
152 | C.Lambda _ when skip_lambda -> metasenv, subst, t, expty
153 | C.Appl _ when skip_appl -> metasenv, subst, t, expty
155 pp (lazy ("forcing infty=expty: "^
156 (NCicPp.ppterm ~metasenv ~subst ~context infty) ^ " === " ^
157 (NCicPp.ppterm ~metasenv ~subst:[] ~context expty)));
159 let metasenv, subst =
160 (*D*)inside 'U'; try let rc =
161 NCicUnification.unify rdb metasenv subst context infty expty
162 (*D*)in outside true; rc with exc -> outside false; raise exc
164 metasenv, subst, t, expty
166 | NCicUnification.Uncertain _
167 | NCicUnification.UnificationFailure _ as exc ->
168 try_coercions rdb ~localise
169 metasenv subst context t orig infty expty true exc)
170 | None -> metasenv, subst, t, infty
171 (*D*)in outside true; rc with exc -> outside false; raise exc
173 let rec typeof_aux metasenv subst context expty =
175 (*D*)inside 'R'; try let rc =
176 pp (lazy (NCicPp.ppterm ~metasenv ~subst ~context t ^ " ::exp:: " ^
177 match expty with None -> "None" | Some e ->
178 NCicPp.ppterm ~metasenv ~subst ~context e));
179 let metasenv, subst, t, infty =
184 match List.nth context (n - 1) with
185 | (_,C.Decl ty) -> NCicSubstitution.lift n ty
186 | (_,C.Def (_,ty)) -> NCicSubstitution.lift n ty
188 raise (RefineFailure (lazy (localise t,"unbound variable"))))
190 metasenv, subst, t, infty
192 (try metasenv, subst, t, C.Sort (NCicEnvironment.typeof_sort s)
194 | NCicEnvironment.UntypableSort msg ->
195 raise (RefineFailure (lazy (localise t, Lazy.force msg)))
196 | NCicEnvironment.AssertFailure msg -> raise (AssertFailure msg))
197 | C.Implicit infos ->
198 let (metasenv,_,t,ty),subst =
199 exp_implicit rdb ~localise metasenv subst context expty t infos
202 typeof_aux metasenv subst context None t
204 metasenv, subst, t, ty
205 | C.Meta (n,l) as t ->
208 let _,_,_,ty = NCicUtils.lookup_subst n subst in metasenv, ty
209 with NCicUtils.Subst_not_found _ ->
210 NCicMetaSubst.extend_meta metasenv n
212 metasenv, subst, t, NCicSubstitution.subst_meta l ty
214 metasenv, subst, t, NCicTypeChecker.typeof ~subst ~metasenv context t
215 | C.Prod (name,(s as orig_s),(t as orig_t)) ->
216 let metasenv, subst, s, s1 = typeof_aux metasenv subst context None s in
217 let metasenv, subst, s, s1 =
219 metasenv subst context s orig_s localise s1 in
220 let context1 = (name,(C.Decl s))::context in
221 let metasenv, subst, t, s2 = typeof_aux metasenv subst context1 None t in
222 let metasenv, subst, t, s2 =
224 metasenv subst context1 t orig_t localise s2 in
225 let metasenv, subst, s, t, ty =
226 sort_of_prod localise metasenv subst
227 context orig_s orig_t (name,s) t (s1,s2)
229 metasenv, subst, NCic.Prod(name,s,t), ty
230 | C.Lambda (n,(s as orig_s),t) as orig ->
231 let exp_s, exp_ty_t, force_after =
233 | None -> None, None, false
235 match NCicReduction.whd ~subst context expty with
236 | C.Prod (_,s,t) -> Some s, Some t, false
237 | _ -> None, None, true
239 let (metasenv,subst), s =
242 (* optimized case: implicit and implicitly typed meta
243 * the optimization prevents proliferation of metas *)
245 | C.Implicit _ -> (metasenv,subst),exp_s
247 let metasenv, subst, s = match s with
249 when (try (match NCicUtils.lookup_meta n metasenv with
250 | _,_,C.Implicit (`Typeof _) -> true
253 | _ -> false) -> metasenv, subst, s
254 | _ -> check_type rdb ~localise metasenv subst context s in
256 pp(lazy("Force source to: "^NCicPp.ppterm ~metasenv ~subst
258 NCicUnification.unify ~test_eq_only:true rdb metasenv subst context s exp_s,s
259 with exc -> raise (wrap_exc (lazy (localise orig_s, Printf.sprintf
260 "Source type %s was expected to be %s" (NCicPp.ppterm ~metasenv
261 ~subst ~context s) (NCicPp.ppterm ~metasenv ~subst ~context
264 let metasenv, subst, s =
265 check_type rdb ~localise metasenv subst context s in
268 let context_for_t = (n,C.Decl s) :: context in
269 let metasenv, subst, t, ty_t =
270 typeof_aux metasenv subst context_for_t exp_ty_t t
273 force_ty false true metasenv subst context orig
274 (C.Lambda(n,s,t)) (C.Prod (n,s,ty_t)) expty
276 metasenv, subst, C.Lambda(n,s,t), C.Prod (n,s,ty_t)
277 | C.LetIn (n,ty,t,bo) ->
278 let metasenv, subst, ty =
279 check_type rdb ~localise metasenv subst context ty in
280 let metasenv, subst, t, _ =
281 typeof_aux metasenv subst context (Some ty) t in
282 let context1 = (n, C.Def (t,ty)) :: context in
283 let metasenv, subst, expty1 =
285 | None -> metasenv, subst, None
288 NCicUnification.delift_type_wrt_terms
289 rdb metasenv subst context1 (NCicSubstitution.lift 1 x)
290 [NCicSubstitution.lift 1 t]
294 let metasenv, subst, bo, bo_ty =
295 typeof_aux metasenv subst context1 expty1 bo
297 let bo_ty = NCicSubstitution.subst ~avoid_beta_redexes:true t bo_ty in
298 metasenv, subst, C.LetIn (n, ty, t, bo), bo_ty
299 | C.Appl ((he as orig_he)::(_::_ as args)) ->
300 let upto = match orig_he with C.Meta _ -> List.length args | _ -> 0 in
302 if upto > 0 then NCicReduction.head_beta_reduce ~upto t else t
305 let metasenv, subst, he, ty_he =
306 typeof_aux metasenv subst context None he in
307 let metasenv, subst, t, ty =
308 eat_prods rdb ~localise force_ty metasenv subst context expty t
309 orig_he he ty_he args in
310 metasenv, subst, hbr t, ty
312 if args = [C.Implicit `Vector] && expty <> None then
313 (* we try here to expand the vector a 0 implicits, but we use
314 * the expected type *)
316 let metasenv, subst, he, ty_he =
317 typeof_aux metasenv subst context expty he in
318 metasenv, subst, hbr he, ty_he
319 with Uncertain _ | RefineFailure _ -> refine_appl ()
321 | C.Appl _ -> raise (AssertFailure (lazy "Appl of length < 2"))
322 | C.Match (Ref.Ref (_,Ref.Ind (_,tyno,_)) as r,
323 outtype,(term as orig_term),pl) as orig ->
324 let _, leftno, itl, _, _ = NCicEnvironment.get_checked_indtys r in
325 let _, _, arity, cl = List.nth itl tyno in
326 let constructorsno = List.length cl in
327 let _, metasenv, args =
328 NCicMetaSubst.saturate metasenv subst context arity 0 in
329 let ind = if args = [] then C.Const r else C.Appl (C.Const r::args) in
330 let metasenv, subst, term, _ =
331 typeof_aux metasenv subst context (Some ind) term in
332 let parameters, arguments = HExtlib.split_nth leftno args in
335 | C.Implicit _ as ot ->
336 let rec aux = function
337 | [] -> NCic.Lambda ("_",NCic.Implicit `Type,ot)
338 | _::tl -> NCic.Lambda ("_",NCic.Implicit `Type,aux tl)
343 let metasenv, subst, outtype, outsort =
344 typeof_aux metasenv subst context None outtype in
346 (* next lines are to do a subst-expansion of the outtype, so
347 that when it becomes a beta-abstraction, the beta-redex is
348 fired during substitution *)
349 let _,fresh_metanoouttype,newouttype,_ =
350 NCicMetaSubst.mk_meta metasenv context `IsTerm in
352 (fresh_metanoouttype,([`Name "outtype"],context,outtype,outsort))
354 let outtype = newouttype in
356 (* let's control if the sort elimination is allowed: [(I q1 ... qr)|B] *)
358 if parameters = [] then C.Const r
359 else C.Appl ((C.Const r)::parameters) in
360 let metasenv, subst, ind, ind_ty =
361 typeof_aux metasenv subst context None ind in
362 let metasenv, subst =
363 check_allowed_sort_elimination rdb localise r orig_term metasenv subst
364 context ind ind_ty outsort
366 (* let's check if the type of branches are right *)
367 if List.length pl <> constructorsno then
368 raise (RefineFailure (lazy (localise orig,
369 "Wrong number of cases in a match")));
371 let metasenv, subst =
373 | None -> metasenv, subst
375 NCicUnification.unify rdb metasenv subst context resty expty
378 let _, metasenv, subst, pl =
380 (fun p (j, metasenv, subst, branches) ->
382 let cons = Ref.mk_constructor j r in
383 if parameters = [] then C.Const cons
384 else C.Appl (C.Const cons::parameters)
386 let metasenv, subst, cons, ty_cons =
387 typeof_aux metasenv subst context None cons in
389 NCicTypeChecker.type_of_branch
390 ~subst context leftno outtype cons ty_cons in
391 pp (lazy ("TYPEOFBRANCH: " ^
392 NCicPp.ppterm ~metasenv ~subst ~context p ^ " ::inf:: " ^
393 NCicPp.ppterm ~metasenv ~subst ~context ty_branch ));
394 let metasenv, subst, p, _ =
395 typeof_aux metasenv subst context (Some ty_branch) p in
396 j-1, metasenv, subst, p :: branches)
397 pl (List.length pl, metasenv, subst, [])
399 let resty = C.Appl (outtype::arguments@[term]) in
400 let resty = NCicReduction.head_beta_reduce ~subst resty in
401 metasenv, subst, C.Match (r, outtype, term, pl),resty
402 | C.Match _ -> assert false
404 pp (lazy (NCicPp.ppterm ~metasenv ~subst ~context t ^ " ::inf:: "^
405 NCicPp.ppterm ~metasenv ~subst ~context infty ));
406 force_ty true true metasenv subst context orig t infty expty
407 (*D*)in outside true; rc with exc -> outside false; raise exc
409 typeof_aux metasenv subst context expty term
411 and check_type rdb ~localise metasenv subst context (ty as orig_ty) =
412 let metasenv, subst, ty, sort =
413 typeof rdb ~localise metasenv subst context ty None
415 let metasenv, subst, ty, _ =
416 force_to_sort rdb metasenv subst context ty orig_ty localise sort
420 and try_coercions rdb
422 metasenv subst context t orig_t infty expty perform_unification exc
424 let cs_subst = NCicSubstitution.subst ~avoid_beta_redexes:true in
426 pp (lazy "WWW: trying coercions -- preliminary unification");
427 let metasenv, subst =
428 NCicUnification.unify rdb metasenv subst context infty expty
429 in metasenv, subst, t, expty
432 (* we try with a coercion *)
433 let rec first exc = function
435 pp (lazy "WWW: no more coercions!");
436 raise (wrap_exc (lazy (localise orig_t, Printf.sprintf
437 "The term\n%s\nhas type\n%s\nbut is here used with type\n%s"
438 (NCicPp.ppterm ~metasenv ~subst ~context t)
439 (NCicPp.ppterm ~metasenv ~subst ~context infty)
440 (NCicPp.ppterm ~metasenv ~subst ~context expty))) exc)
441 | (_,metasenv, newterm, newtype, meta)::tl ->
443 pp (lazy("K=" ^ NCicPp.ppterm ~metasenv ~subst ~context newterm));
444 pp (lazy ( "UNIFICATION in CTX:\n"^
445 NCicPp.ppcontext ~metasenv ~subst context
447 NCicPp.ppmetasenv metasenv ~subst
449 NCicPp.ppterm ~metasenv ~subst ~context t ^ " === " ^
450 NCicPp.ppterm ~metasenv ~subst ~context meta ^ "\n"));
451 let metasenv, subst =
452 NCicUnification.unify rdb metasenv subst context t meta
454 pp (lazy ( "UNIFICATION in CTX:\n"^
455 NCicPp.ppcontext ~metasenv ~subst context
457 NCicPp.ppmetasenv metasenv ~subst
459 NCicPp.ppterm ~metasenv ~subst ~context newtype ^ " === " ^
460 NCicPp.ppterm ~metasenv ~subst ~context expty ^ "\n"));
461 let metasenv, subst =
462 if perform_unification then
463 NCicUnification.unify rdb metasenv subst context newtype expty
466 metasenv, subst, newterm, newtype
468 | NCicUnification.UnificationFailure _ -> first exc tl
469 | NCicUnification.Uncertain _ as exc -> first exc tl
473 pp (lazy "WWW: trying coercions -- inner check");
474 match infty, expty, t with
475 | _,_, NCic.Match (Ref.Ref (_,Ref.Ind (_,tyno,leftno)) as r,outty,m,pl) ->
476 (*{{{*) pp (lazy "CASE");
477 (* {{{ helper functions *)
478 let get_cl_and_left_p refit outty =
480 | NReference.Ref (uri, NReference.Ind (_,tyno,leftno)) ->
481 let _, leftno, itl, _, _ = NCicEnvironment.get_checked_indtys r in
482 let _, _, ty, cl = List.nth itl tyno in
483 let constructorsno = List.length cl in
486 match NCicReduction.whd ~subst ~delta:max_int ctx t with
487 | NCic.Prod (name,src,tgt) ->
488 let ctx = (name, (NCic.Decl src)) :: ctx in
494 let rec skip_lambda_delifting t n =
497 | NCic.Lambda (_,_,t),n ->
498 pp (lazy ("WWW: failing term? "^ NCicPp.ppterm ~subst:[] ~metasenv:[] ~context:[] t));
499 skip_lambda_delifting
500 (* substitute dangling indices with a dummy *)
501 (NCicSubstitution.subst (NCic.Sort NCic.Prop) t) (n - 1)
504 let get_l_r_p n = function
505 | NCic.Lambda (_,NCic.Const (Ref.Ref (_,Ref.Ind (_,_,_))),_) -> [],[]
506 | NCic.Lambda (_,NCic.Appl
507 (NCic.Const (Ref.Ref (_,Ref.Ind (_,_,_))) :: args),_) ->
508 HExtlib.split_nth n args
511 let pis = count_pis ty in
512 let rno = pis - leftno in
513 let t = skip_lambda_delifting outty rno in
514 let left_p, _ = get_l_r_p leftno t in
515 let instantiate_with_left cl =
519 (fun t p -> match t with
520 | NCic.Prod (_,_,t) ->
526 let cl = instantiate_with_left (List.map (fun (_,_,x) -> x) cl) in
527 cl, left_p, leftno, rno
530 let rec keep_lambdas_and_put_expty ctx t bo right_p matched n =
533 let rec mkr n = function
534 | [] -> [] | _::tl -> NCic.Rel n :: mkr (n+1) tl
536 pp (lazy ("input replace: " ^ NCicPp.ppterm ~context:ctx ~metasenv:[] ~subst:[] bo));
538 NCicRefineUtil.replace_lifting
539 ~equality:(fun _ -> NCicRefineUtil.alpha_equivalence)
541 ~what:(matched::right_p)
542 ~with_what:(NCic.Rel 1::List.rev (mkr 2 right_p))
545 pp (lazy ("output replace: " ^ NCicPp.ppterm ~context:ctx ~metasenv:[] ~subst:[] bo));
547 | NCic.Lambda (name, src, tgt),_ ->
548 NCic.Lambda (name, src,
549 keep_lambdas_and_put_expty
550 ((name, NCic.Decl src)::ctx) tgt (NCicSubstitution.lift 1 bo)
551 (List.map (NCicSubstitution.lift 1) right_p) (NCicSubstitution.lift 1 matched) (n-1))
554 (*let eq = NCic.Const (NReference.reference_of_string ("cic:/matita/ng/Plogic/equality/eq.ind(1,0,2)")) in
555 let eq_refl = NCic.Const (NReference.reference_of_string ("cic:/matita/ng/Plogic/equality/eq.con(0,1,2)")) in*)
556 let eq = NCic.Const (NReference.reference_of_string ("cic:/matita/ng/Plogic/jmeq/jmeq.ind(1,0,2)")) in
557 let eq_refl = NCic.Const (NReference.reference_of_string ("cic:/matita/ng/Plogic/jmeq/jmeq.con(0,1,2)")) in
559 metasenv subst context cty outty mty m i
561 let rec aux context outty par j mty m = function
562 | NCic.Prod (name, src, tgt) ->
565 ((name, NCic.Decl src) :: context)
566 (NCicSubstitution.lift 1 outty) (NCic.Rel j::par) (j+1)
567 (NCicSubstitution.lift 1 mty) (NCicSubstitution.lift 1 m) tgt
569 NCic.Prod (name, src, t), k
570 | NCic.Const (Ref.Ref (_,Ref.Ind (_,_,leftno)) as r) ->
572 let k = NCic.Const(Ref.mk_constructor i r) in
573 NCicUntrusted.mk_appl k par
575 (* the type has no parameters, so kty = mty
577 try NCicTypechecker.typeof ~subst ~metasenv context k
578 with NCicTypeChecker.TypeCheckerFailure _ -> assert false
581 NCic.Appl [eq; mty; m; mty; k],
582 (NCicSubstitution.lift 1
583 (NCicReduction.head_beta_reduce ~delta:max_int
584 (NCicUntrusted.mk_appl outty [k])))),[mty,m,mty,k]
585 | NCic.Appl (NCic.Const (Ref.Ref (_,Ref.Ind (_,_,leftno)) as r)::pl) ->
586 let left_p,right_p = HExtlib.split_nth leftno pl in
587 let has_rights = right_p <> [] in
589 let k = NCic.Const(Ref.mk_constructor i r) in
590 NCicUntrusted.mk_appl k (left_p@par)
594 NCicTypeChecker.typeof ~subst ~metasenv context k
596 | NCic.Appl (NCic.Const (Ref.Ref (_,Ref.Ind (_,_,_)))::args) ->
597 snd (HExtlib.split_nth leftno args)
599 with NCicTypeChecker.TypeCheckerFailure _-> assert false
603 | NCic.Appl (NCic.Const (Ref.Ref (_,Ref.Ind (_,_,_)))::args) ->
604 snd (HExtlib.split_nth leftno args)
608 (fun x y (tacc,pacc) ->
610 try NCicTypeChecker.typeof ~subst ~metasenv context x
611 with NCicTypeChecker.TypeCheckerFailure _ -> assert false
614 try NCicTypeChecker.typeof ~subst ~metasenv context y
615 with NCicTypeChecker.TypeCheckerFailure _ -> assert false
617 NCic.Prod ("_", NCic.Appl [eq;xty;x;yty;y],
618 NCicSubstitution.lift 1 tacc), (xty,x,yty,y)::pacc)
619 (orig_right_p @ [m]) (right_p @ [k])
620 (NCicReduction.head_beta_reduce ~delta:max_int
621 (NCicUntrusted.mk_appl outty (right_p@[k])), [])
623 (* if has_rights then
624 NCicReduction.head_beta_reduce ~delta:max_int
625 (NCic.Appl (outty ::right_p @ [k])),k
628 NCic.Appl [eq; mty; m; k],
629 (NCicSubstitution.lift 1
630 (NCicReduction.head_beta_reduce ~delta:max_int
631 (NCic.Appl (outty ::right_p @ [k]))))),k*)
634 aux context outty [] 1 mty m cty
636 let add_lambda_for_refl_m pbo eqs cty =
637 (* k lives in the right context *)
638 (* if rno <> 0 then pbo else *)
639 let rec aux = function
640 | NCic.Lambda (name,src,bo), NCic.Prod (_,_,ty) ->
641 NCic.Lambda (name,src,
643 | t,_ -> snd (List.fold_right
644 (fun (xty,x,yty,y) (n,acc) -> n+1, NCic.Lambda ("p" ^ string_of_int n,
645 NCic.Appl [eq; xty; x; yty; y],
646 NCicSubstitution.lift 1 acc)) eqs (1,t))
648 NCic.Appl [eq; mty; m; k],NCicSubstitution.lift 1 t)*)
652 let add_pi_for_refl_m context new_outty mty m lno rno =
653 (*if rno <> 0 then new_outty else*)
654 let rec aux context mty m = function
655 | NCic.Lambda (name, src, tgt) ->
656 let context = (name, NCic.Decl src)::context in
657 NCic.Lambda (name, src, aux context (NCicSubstitution.lift 1 mty) (NCicSubstitution.lift 1 m) tgt)
661 | NCic.Appl (_::params) -> (snd (HExtlib.split_nth lno params))@[m]
665 List.map (fun x -> NCic.Rel x)
666 (List.rev (HExtlib.list_seq 1 (rno+2))) in
670 try NCicTypeChecker.typeof ~subst ~metasenv context x
671 with NCicTypeChecker.TypeCheckerFailure _ -> assert false
674 try NCicTypeChecker.typeof ~subst ~metasenv context y
675 with NCicTypeChecker.TypeCheckerFailure _ -> assert false
678 ("_", NCic.Appl [eq;xty;x;yty;y],
679 (NCicSubstitution.lift 1 acc)))
682 ("_", NCic.Appl [eq;mty;m;NCic.Rel 1],
683 NCicSubstitution.lift 1 t)*)
685 aux context mty m new_outty
686 in (* }}} end helper functions *)
687 (* constructors types with left params already instantiated *)
688 let outty = NCicUntrusted.apply_subst subst context outty in
689 let cl, left_p, leftno,rno =
690 get_cl_and_left_p r outty
695 NCicTypeChecker.typeof ~subst ~metasenv context m
697 | (NCic.Const (Ref.Ref (_,Ref.Ind (_,_,_))) | NCic.Meta _) as mty -> [], mty
698 | NCic.Appl ((NCic.Const (Ref.Ref (_,Ref.Ind (_,_,_)))|NCic.Meta _)::args) as mty ->
699 snd (HExtlib.split_nth leftno args), mty
701 with NCicTypeChecker.TypeCheckerFailure _ ->
702 raise (AssertFailure(lazy "already ill-typed matched term"))
704 let mty = NCicUntrusted.apply_subst subst context mty in
705 let outty = NCicUntrusted.apply_subst subst context outty in
706 let expty = NCicUntrusted.apply_subst subst context expty in
708 keep_lambdas_and_put_expty context outty expty right_p m (rno+1)
711 (lazy ("CASE: new_outty: " ^ NCicPp.ppterm
712 ~context ~metasenv ~subst new_outty));
713 let _,pl,subst,metasenv =
715 (fun cty pbo (i, acc, s, menv) ->
716 pp (lazy ("begin iteration"));
717 (* Pi k_par, (Pi H:m=(K_i left_par k_par)),
718 * (new_)outty right_par (K_i left_par k_par) *)
720 add_params menv s context cty outty mty m i in
722 (lazy ("CASE: infty_pbo: "^ NCicPp.ppterm
723 ~context ~metasenv ~subst infty_pbo));
724 let expty_pbo, eqs = (* k is (K_i left_par k_par) *)
725 add_params menv s context cty new_outty mty m i in
727 (lazy ("CASE: expty_pbo: "^ NCicPp.ppterm
728 ~context ~metasenv ~subst expty_pbo));
729 let pbo = add_lambda_for_refl_m pbo eqs cty in
731 (lazy ("CASE: pbo: " ^ NCicPp.ppterm
732 ~context ~metasenv ~subst pbo));
733 let metasenv, subst, pbo, _ =
734 try_coercions rdb ~localise menv s context pbo
735 orig_t (*??*) infty_pbo expty_pbo perform_unification exc
738 (lazy ("CASE: pbo2: " ^ NCicPp.ppterm
739 ~context ~metasenv ~subst pbo));
740 (i-1, pbo::acc, subst, metasenv))
741 cl pl (List.length pl, [], subst, metasenv)
743 (*let metasenv, subst =
745 NCicUnification.unify rdb metasenv subst context outty new_outty
746 with _ -> raise (RefineFailure (lazy (localise orig_t, "try_coercions")))
748 let new_outty = add_pi_for_refl_m context new_outty mty m leftno rno in
749 pp (lazy ("CASE: new_outty: " ^ (NCicPp.ppterm
750 ~metasenv ~subst ~context new_outty)));
753 (fun t -> NCicTypeChecker.typeof ~subst ~metasenv context t) right_p in
755 List.map2 (fun x y -> NCic.Appl[eq_refl;x;y]) (right_tys@[mty])
757 let t = NCic.Appl (NCic.Match(r,new_outty,m,pl) :: eqs)
759 metasenv, subst, t, expty (*}}}*)
760 | NCic.Prod (nameprod, src, ty),NCic.Prod (_, src2, ty2), _ ->
761 let rec mk_fresh_name ctx firstch n =
762 let candidate = (String.make 1 firstch) ^ (string_of_int n) in
763 if (List.for_all (fun (s,_) -> s <> candidate) ctx) then candidate
764 else mk_fresh_name ctx firstch (n+1)
766 (*{{{*) pp (lazy "LAM");
767 pp (lazy ("LAM: t = " ^ NCicPp.ppterm ~metasenv ~subst ~context t));
768 let name_con = mk_fresh_name context 'c' 0
769 (*FreshNamesGenerator.mk_fresh_name
770 ~subst metasenv context ~typ:src2 Cic.Anonymous*)
772 let context_src2 = ((name_con, NCic.Decl src2) :: context) in
773 (* contravariant part: the argument of f:src->ty *)
774 let metasenv, subst, rel1, _ =
775 try_coercions rdb ~localise metasenv subst context_src2
776 (NCic.Rel 1) orig_t (NCicSubstitution.lift 1 src2)
777 (NCicSubstitution.lift 1 src) perform_unification exc
779 (* covariant part: the result of f(c x); x:src2; (c x):src *)
782 | NCic.Lambda (n,_,bo) -> n, cs_subst rel1 (NCicSubstitution.lift_from 2 1 bo)
783 | _ -> name_con, NCicUntrusted.mk_appl (NCicSubstitution.lift 1 t) [rel1]
785 (* we fix the possible dependency problem in the source ty *)
786 let ty = cs_subst rel1 (NCicSubstitution.lift_from 2 1 ty) in
787 let metasenv, subst, bo, _ =
788 try_coercions rdb ~localise metasenv subst context_src2
789 bo orig_t ty ty2 perform_unification exc
791 let coerced = NCic.Lambda (name_t,src2, bo) in
792 pp (lazy ("LAM: coerced = " ^ NCicPp.ppterm ~metasenv ~subst ~context coerced));
793 metasenv, subst, coerced, expty (*}}}*)
796 pp(lazy("try_coercion " ^
797 NCicPp.ppterm ~metasenv ~subst ~context infty ^ " |---> " ^
798 NCicPp.ppterm ~metasenv ~subst ~context expty));
800 (NCicCoercion.look_for_coercion
801 rdb metasenv subst context infty expty)
803 and force_to_sort rdb metasenv subst context t orig_t localise ty =
805 let metasenv, subst, ty =
806 NCicUnification.sortfy (Failure "sortfy") metasenv subst context ty in
807 metasenv, subst, t, ty
810 let ty = NCicReduction.whd ~subst context ty in
811 try_coercions rdb ~localise metasenv subst context
812 t orig_t ty (NCic.Sort (NCic.Type
813 (match NCicEnvironment.get_universes () with
815 | _ -> assert false))) false
816 (Uncertain (lazy (localise orig_t,
817 "The type of " ^ NCicPp.ppterm ~metasenv ~subst ~context t ^
818 " is not a sort: " ^ NCicPp.ppterm ~metasenv ~subst ~context ty)))
821 localise metasenv subst context orig_s orig_t (name,s) t (t1, t2)
823 (* force to sort is done in the Prod case in typeof *)
825 | C.Sort _, C.Sort C.Prop -> metasenv, subst, s, t, t2
826 | C.Sort (C.Type u1), C.Sort (C.Type u2) ->
827 metasenv, subst, s, t, C.Sort (C.Type (NCicEnvironment.max u1 u2))
828 | C.Sort C.Prop,C.Sort (C.Type _) -> metasenv, subst, s, t, t2
830 | C.Meta _, C.Meta (_,(_,_))
831 | C.Sort _, C.Meta (_,(_,_)) -> metasenv, subst, s, t, t2
832 | x, (C.Sort _ | C.Meta _) | _, x ->
833 let y, context, orig =
834 if x == t1 then s, context, orig_s
835 else t, ((name,C.Decl s)::context), orig_t
837 raise (RefineFailure (lazy (localise orig,Printf.sprintf
838 "%s is expected to be a type, but its type is %s that is not a sort"
839 (NCicPp.ppterm ~subst ~metasenv ~context y)
840 (NCicPp.ppterm ~subst ~metasenv ~context x))))
842 and guess_name subst ctx ty =
843 let aux initial = "#" ^ String.make 1 initial in
845 | C.Const (NReference.Ref (u,_))
846 | C.Appl (C.Const (NReference.Ref (u,_)) :: _) ->
847 aux (String.sub (NUri.name_of_uri u) 0 1).[0]
848 | C.Prod _ -> aux 'f'
851 let _,_,t,_ = NCicUtils.lookup_subst n subst in
852 guess_name subst ctx (NCicSubstitution.subst_meta lc t)
853 with NCicUtils.Subst_not_found _ -> aux 'M')
856 and eat_prods rdb ~localise force_ty metasenv subst context expty orig_t orig_he he ty_he args =
857 (*D*)inside 'E'; try let rc =
858 let rec aux metasenv subst args_so_far he ty_he xxx =
859 (*D*)inside 'V'; try let rc =
862 let res = NCicUntrusted.mk_appl he (List.rev args_so_far) in
863 pp(lazy("FORCE FINAL APPL: " ^
864 NCicPp.ppterm ~metasenv ~subst ~context res ^
865 " of type " ^ NCicPp.ppterm ~metasenv ~subst ~context ty_he
866 ^ " to type " ^ match expty with None -> "None" | Some x ->
867 NCicPp.ppterm ~metasenv ~subst ~context x));
868 (* whatever the term is, we force the type. in case of ((Lambda..) ?...)
869 * the application may also be a lambda! *)
870 force_ty false false metasenv subst context orig_t res ty_he expty
871 | NCic.Implicit `Vector::tl ->
872 let has_some_more_pis x =
873 match NCicReduction.whd ~subst context x with
874 | NCic.Meta _ | NCic.Appl (NCic.Meta _::_) -> false
878 aux metasenv subst args_so_far he ty_he tl
881 | RefineFailure _ as exc when has_some_more_pis ty_he ->
883 aux metasenv subst args_so_far he ty_he
884 (NCic.Implicit `Term :: NCic.Implicit `Vector :: tl)
886 Uncertain msg | RefineFailure msg -> raise (wrap_exc msg exc))
887 | RefineFailure msg when not (has_some_more_pis ty_he) ->
888 (* instantiating the head could change the has_some_more_pis flag *)
889 raise (Uncertain msg))
891 match NCicReduction.whd ~subst context ty_he with
893 let metasenv, subst, arg, _ =
894 typeof rdb ~localise metasenv subst context arg (Some s) in
895 let t = NCicSubstitution.subst ~avoid_beta_redexes:true arg t in
896 aux metasenv subst (arg :: args_so_far) he t tl
898 | C.Appl (C.Meta _ :: _) as t ->
899 let metasenv, subst, arg, ty_arg =
900 typeof rdb ~localise metasenv subst context arg None in
901 let name = guess_name subst context ty_arg in
902 let metasenv, _, meta, _ =
903 NCicMetaSubst.mk_meta metasenv
904 ((name,C.Decl ty_arg) :: context) `IsType
906 let flex_prod = C.Prod (name, ty_arg, meta) in
907 (* next line grants that ty_args is a type *)
908 let metasenv,subst, flex_prod, _ =
909 typeof rdb ~localise metasenv subst context flex_prod None in
911 pp (lazy ( "UNIFICATION in CTX:\n"^
912 NCicPp.ppcontext ~metasenv ~subst context
914 NCicPp.ppterm ~metasenv ~subst ~context t ^ " === " ^
915 NCicPp.ppterm ~metasenv ~subst ~context flex_prod ^ "\n"));
917 let metasenv, subst =
918 try NCicUnification.unify rdb metasenv subst context t flex_prod
919 with exc -> raise (wrap_exc (lazy (localise orig_he, Printf.sprintf
920 ("The term %s has an inferred type %s, but is applied to the" ^^
921 " argument %s of type %s")
922 (NCicPp.ppterm ~metasenv ~subst ~context he)
923 (NCicPp.ppterm ~metasenv ~subst ~context t)
924 (NCicPp.ppterm ~metasenv ~subst ~context arg)
925 (NCicPp.ppterm ~metasenv ~subst ~context ty_arg)))
927 | NCicUnification.UnificationFailure m ->
928 NCicUnification.Uncertain m
930 (* XXX coerce to funclass *)
932 let meta = NCicSubstitution.subst ~avoid_beta_redexes:true arg meta in
933 aux metasenv subst (arg :: args_so_far) he meta tl
934 | C.Match (_,_,C.Meta _,_)
935 | C.Match (_,_,C.Appl (C.Meta _ :: _),_)
936 | C.Appl (C.Const (NReference.Ref (_, NReference.Fix _)) :: _) ->
937 raise (Uncertain (lazy (localise orig_he, Printf.sprintf
938 ("The term %s is here applied to %d arguments but expects " ^^
939 "only %d arguments") (NCicPp.ppterm ~metasenv ~subst ~context he)
940 (List.length args) (List.length args_so_far))))
942 let metasenv, subst, newhead, newheadty =
943 try_coercions rdb ~localise metasenv subst context
944 (NCicUntrusted.mk_appl he (List.rev args_so_far)) orig_he ty
945 (NCic.Prod ("_",NCic.Implicit `Term,NCic.Implicit `Term))
947 (RefineFailure (lazy (localise orig_he, Printf.sprintf
948 ("The term %s is here applied to %d arguments but expects " ^^
949 "only %d arguments") (NCicPp.ppterm ~metasenv ~subst ~context he)
950 (List.length args) (List.length args_so_far))))
952 aux metasenv subst [] newhead newheadty (arg :: tl)
953 (*D*)in outside true; rc with exc -> outside false; raise exc
955 (* We need to reverse the order of the new created metas since they
956 are pushed on top of the metasenv in the wrong order *)
957 let highest_meta = NCicMetaSubst.maxmeta () in
958 let metasenv, subst, newhead, newheadty =
959 aux metasenv subst [] he ty_he args in
960 let metasenv_old,metasenv_new =
961 List.partition (fun (i,_) -> i <= highest_meta) metasenv
963 (List.rev metasenv_new) @ metasenv_old, subst, newhead, newheadty
964 (*D*)in outside true; rc with exc -> outside false; raise exc
967 let rec first f l1 l2 =
969 | x1::tl1, x2::tl2 ->
970 (try f x1 x2 with Not_found -> first f tl1 tl2)
971 | _ -> raise Not_found
974 let rec find add dt t =
979 | C.Meta (_,(_,C.Ctx dl)), C.Meta (_,(_,C.Ctx l))
980 | C.Appl dl,C.Appl l -> dl,l
981 | C.Lambda (_,ds,dt), C.Lambda (_,s,t)
982 | C.Prod (_,ds,dt), C.Prod (_,s,t) -> [ds;dt],[s;t]
983 | C.LetIn (_,ds,db,dt), C.LetIn (_,s,b,t) -> [ds;db;dt],[s;b;t]
984 | C.Match (_,dot,dt,dl), C.Match (_,ot,t,l) -> (dot::dt::dl),(ot::t::l)
985 | _ -> raise Not_found
987 first (find add) dl l
990 let relocalise old_localise dt t add =
992 (try find add dt t with Not_found -> assert false)
995 let undebruijnate inductive ref t rev_fl =
996 let len = List.length rev_fl in
997 NCicSubstitution.psubst (fun x -> x)
999 (fun (_,_,rno,_,_,_) i ->
1000 let i = len - i - 1 in
1002 (if inductive then NReference.mk_fix i rno ref
1003 else NReference.mk_cofix i ref))
1010 rdb ?(localise=fun _ -> Stdpp.dummy_loc) (uri,height,metasenv,subst,obj)
1013 | C.Constant (relevance, name, bo, ty, attr) ->
1014 let metasenv, subst, ty =
1015 check_type rdb ~localise metasenv subst [] ty in
1016 let metasenv, subst, bo, ty, height =
1019 let metasenv, subst, bo, ty =
1020 typeof rdb ~localise metasenv subst [] bo (Some ty) in
1021 let height = (* XXX recalculate *) height in
1022 metasenv, subst, Some bo, ty, height
1023 | None -> metasenv, subst, None, ty, 0
1025 uri, height, metasenv, subst,
1026 C.Constant (relevance, name, bo, ty, attr)
1027 | C.Fixpoint (inductive, fl, attr) ->
1028 let len = List.length fl in
1029 let types, metasenv, subst, rev_fl =
1031 (fun (types, metasenv, subst, fl) (relevance,name,k,ty,bo) ->
1032 let metasenv, subst, ty =
1033 check_type rdb ~localise metasenv subst [] ty in
1034 let dbo = NCicTypeChecker.debruijn uri len [] ~subst bo in
1035 let localise = relocalise localise dbo bo in
1036 (name,C.Decl ty)::types,
1037 metasenv, subst, (relevance,name,k,ty,dbo,localise)::fl
1038 ) ([], metasenv, subst, []) fl (* XXX kl rimosso nel nucleo *)
1040 let metasenv, subst, fl =
1042 (fun (metasenv,subst,fl) (relevance,name,k,ty,dbo,localise) ->
1043 let metasenv, subst, dbo, ty =
1044 typeof rdb ~localise metasenv subst types dbo (Some ty)
1046 metasenv, subst, (relevance,name,k,ty,dbo)::fl)
1047 (metasenv, subst, []) rev_fl
1049 let height = (* XXX recalculate *) height in
1052 (fun (relevance,name,k,ty,dbo) ->
1054 undebruijnate inductive
1055 (NReference.reference_of_spec uri
1056 (if inductive then NReference.Fix (0,k,0)
1057 else NReference.CoFix 0)) dbo rev_fl
1059 relevance,name,k,ty,bo)
1062 uri, height, metasenv, subst,
1063 C.Fixpoint (inductive, fl, attr)
1064 | C.Inductive (ind, leftno, itl, attr) ->
1065 let len = List.length itl in
1066 let metasenv,subst,rev_itl,tys =
1068 (fun (metasenv,subst,res,ctx) (relevance,n,ty,cl) ->
1069 let metasenv, subst, ty =
1070 check_type rdb ~localise metasenv subst [] ty in
1071 metasenv,subst,(relevance,n,ty,cl)::res,(n,NCic.Decl ty)::ctx
1072 ) (metasenv,subst,[],[]) itl in
1073 let metasenv,subst,itl,_ =
1075 (fun (metasenv,subst,res,i) (it_relev,n,ty,cl) ->
1076 let context,ty_sort = NCicReduction.split_prods ~subst [] ~-1 ty in
1077 let sx_context_ty_rev,_= HExtlib.split_nth leftno (List.rev context) in
1078 let metasenv,subst,cl =
1080 (fun (k_relev,n,te) (metasenv,subst,res) ->
1082 try snd (HExtlib.split_nth leftno k_relev)
1083 with Failure _ -> k_relev in
1084 let te = NCicTypeChecker.debruijn uri len [] ~subst te in
1085 let metasenv, subst, te =
1086 check_type rdb ~localise metasenv subst tys te in
1087 let context,te = NCicReduction.split_prods ~subst tys leftno te in
1088 let _,chopped_context_rev =
1089 HExtlib.split_nth (List.length tys) (List.rev context) in
1090 let sx_context_te_rev,_ =
1091 HExtlib.split_nth leftno chopped_context_rev in
1092 let metasenv,subst,_ =
1095 (fun (metasenv,subst,context) item1 item2 ->
1096 let (metasenv,subst),convertible =
1098 match item1,item2 with
1099 (n1,C.Decl ty1),(n2,C.Decl ty2) ->
1101 NCicUnification.unify rdb ~test_eq_only:true metasenv
1102 subst context ty1 ty2,true
1104 (metasenv,subst),false
1105 | (n1,C.Def (bo1,ty1)),(n2,C.Def (bo2,ty2)) ->
1107 let metasenv,subst =
1108 NCicUnification.unify rdb ~test_eq_only:true metasenv
1109 subst context ty1 ty2
1111 NCicUnification.unify rdb ~test_eq_only:true metasenv
1112 subst context bo1 bo2,true
1114 (metasenv,subst),false
1115 | _,_ -> (metasenv,subst),false
1117 | NCicUnification.Uncertain _
1118 | NCicUnification.UnificationFailure _ ->
1119 (metasenv,subst),false
1124 | _,C.Def (b,_) -> b in
1125 if not convertible then
1126 raise (RefineFailure (lazy (localise term2,
1127 ("Mismatch between the left parameters of the constructor " ^
1128 "and those of its inductive type"))))
1130 metasenv,subst,item1::context
1131 ) (metasenv,subst,tys) sx_context_ty_rev sx_context_te_rev
1132 with Invalid_argument "List.fold_left2" -> assert false in
1133 let metasenv, subst =
1134 let rec aux context (metasenv,subst) = function
1135 | NCic.Meta _ -> metasenv, subst
1136 | NCic.Implicit _ -> metasenv, subst
1137 | NCic.Appl (NCic.Rel i :: args) as t
1138 when i > List.length context - len ->
1139 let lefts, _ = HExtlib.split_nth leftno args in
1140 let ctxlen = List.length context in
1141 let (metasenv, subst), _ =
1143 (fun ((metasenv, subst),l) arg ->
1144 NCicUnification.unify rdb
1145 ~test_eq_only:true metasenv subst context arg
1146 (NCic.Rel (ctxlen - len - l)), l+1
1148 ((metasenv, subst), 0) lefts
1151 | t -> NCicUtils.fold (fun e c -> e::c) context aux
1154 aux context (metasenv,subst) te
1156 let con_sort= NCicTypeChecker.typeof ~subst ~metasenv context te in
1158 NCicReduction.whd ~subst context con_sort,
1159 NCicReduction.whd ~subst [] ty_sort
1161 (C.Sort (C.Type u1) as s1), (C.Sort (C.Type u2) as s2) ->
1162 if not (NCicEnvironment.universe_leq u1 u2) then
1165 (lazy(localise te, "The type " ^
1166 NCicPp.ppterm ~metasenv ~subst ~context s1 ^
1167 " of the constructor is not included in the inductive"^
1169 NCicPp.ppterm ~metasenv ~subst ~context s2)))
1170 | C.Sort _, C.Sort C.Prop
1171 | C.Sort _, C.Sort C.Type _ -> ()
1176 "Wrong constructor or inductive arity shape"))));
1177 (* let's check also the positivity conditions *)
1180 (NCicTypeChecker.are_all_occurrences_positive
1181 ~subst context uri leftno (i+leftno) leftno (len+leftno) te)
1186 "Non positive occurence in " ^
1187 NCicPp.ppterm ~metasenv ~subst ~context te)))
1189 let relsno = List.length itl + leftno in
1191 NCicSubstitution.psubst
1196 NCic.Const (NReference.reference_of_spec uri
1197 (NReference.Ind (ind,relsno - i,leftno))))
1198 (HExtlib.list_seq 1 (relsno+1))
1202 (fun (name,decl) te ->
1204 NCic.Decl ty -> NCic.Prod (name,ty,te)
1205 | NCic.Def (bo,ty) -> NCic.LetIn (name,ty,bo,te)
1206 ) sx_context_te_rev te
1208 metasenv,subst,(k_relev,n,te)::res
1209 ) cl (metasenv,subst,[])
1211 metasenv,subst,(it_relev,n,ty,cl)::res,i+1
1212 ) (metasenv,subst,[],1) rev_itl
1214 uri, height, metasenv, subst, C.Inductive (ind, leftno, itl, attr)
1217 (* vim:set foldmethod=marker: *)