]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/cic_unification/cicMetaSubst.ml
List.nth not guarded by try ... with. Fixed.
[helm.git] / helm / ocaml / cic_unification / cicMetaSubst.ml
1 (* Copyright (C) 2004, HELM Team.
2  * 
3  * This file is part of HELM, an Hypertextual, Electronic
4  * Library of Mathematics, developed at the Computer Science
5  * Department, University of Bologna, Italy.
6  * 
7  * HELM is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * 
12  * HELM is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with HELM; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://cs.unibo.it/helm/.
24  *)
25
26 open Printf
27
28 exception MetaSubstFailure of string
29 exception Uncertain of string
30 exception AssertFailure of string
31
32 let debug_print = prerr_endline
33
34 type substitution = (int * Cic.term) list
35
36 (*** Functions to apply a substitution ***)
37
38 let apply_subst_gen ~appl_fun subst term =
39  let rec um_aux =
40   let module C = Cic in
41   let module S = CicSubstitution in 
42    function
43       C.Rel _ as t -> t
44     | C.Var _  as t -> t
45     | C.Meta (i, l) -> 
46         (try
47           let t = List.assoc i subst in
48           um_aux (S.lift_meta l t)
49         with Not_found -> (* not constrained variable, i.e. free in subst*)
50           let l' =
51             List.map (function None -> None | Some t -> Some (um_aux t)) l
52           in
53            C.Meta (i,l'))
54     | C.Sort _ as t -> t
55     | C.Implicit _ -> assert false
56     | C.Cast (te,ty) -> C.Cast (um_aux te, um_aux ty)
57     | C.Prod (n,s,t) -> C.Prod (n, um_aux s, um_aux t)
58     | C.Lambda (n,s,t) -> C.Lambda (n, um_aux s, um_aux t)
59     | C.LetIn (n,s,t) -> C.LetIn (n, um_aux s, um_aux t)
60     | C.Appl (hd :: tl) -> appl_fun um_aux hd tl
61     | C.Appl _ -> assert false
62     | C.Const (uri,exp_named_subst) ->
63        let exp_named_subst' =
64          List.map (fun (uri, t) -> (uri, um_aux t)) exp_named_subst
65        in
66        C.Const (uri, exp_named_subst')
67     | C.MutInd (uri,typeno,exp_named_subst) ->
68        let exp_named_subst' =
69          List.map (fun (uri, t) -> (uri, um_aux t)) exp_named_subst
70        in
71        C.MutInd (uri,typeno,exp_named_subst')
72     | C.MutConstruct (uri,typeno,consno,exp_named_subst) ->
73        let exp_named_subst' =
74          List.map (fun (uri, t) -> (uri, um_aux t)) exp_named_subst
75        in
76        C.MutConstruct (uri,typeno,consno,exp_named_subst')
77     | C.MutCase (sp,i,outty,t,pl) ->
78        let pl' = List.map um_aux pl in
79        C.MutCase (sp, i, um_aux outty, um_aux t, pl')
80     | C.Fix (i, fl) ->
81        let fl' =
82          List.map (fun (name, i, ty, bo) -> (name, i, um_aux ty, um_aux bo)) fl
83        in
84        C.Fix (i, fl')
85     | C.CoFix (i, fl) ->
86        let fl' =
87          List.map (fun (name, ty, bo) -> (name, um_aux ty, um_aux bo)) fl
88        in
89        C.CoFix (i, fl')
90  in
91  um_aux term
92 ;;
93
94 let apply_subst =
95   let appl_fun um_aux he tl =
96     let tl' = List.map um_aux tl in
97       begin
98        match um_aux he with
99           Cic.Appl l -> Cic.Appl (l@tl')
100         | he' -> Cic.Appl (he'::tl')
101       end
102   in
103   apply_subst_gen ~appl_fun
104 ;;
105
106 (* apply_subst_reducing subst (Some (mtr,reductions_no)) t              *)
107 (* performs as (apply_subst subst t) until it finds an application of   *)
108 (* (META [meta_to_reduce]) that, once unwinding is performed, creates   *)
109 (* a new beta-redex; in this case up to [reductions_no] consecutive     *)
110 (* beta-reductions are performed.                                       *)
111 (* Hint: this function is usually called when [reductions_no]           *)
112 (*  eta-expansions have been performed and the head of the new          *)
113 (*  application has been unified with (META [meta_to_reduce]):          *)
114 (*  during the unwinding the eta-expansions are undone.                 *)
115
116 let apply_subst_reducing meta_to_reduce =
117   let appl_fun um_aux he tl =
118     let tl' = List.map um_aux tl in
119     let t' =
120      match um_aux he with
121         Cic.Appl l -> Cic.Appl (l@tl')
122       | he' -> Cic.Appl (he'::tl')
123     in
124      begin
125       match meta_to_reduce, he with
126          Some (mtr,reductions_no), Cic.Meta (m,_) when m = mtr ->
127           let rec beta_reduce =
128            function
129               (n,(Cic.Appl (Cic.Lambda (_,_,t)::he'::tl'))) when n > 0 ->
130                 let he'' = CicSubstitution.subst he' t in
131                  if tl' = [] then
132                   he''
133                  else
134                   beta_reduce (n-1,Cic.Appl(he''::tl'))
135             | (_,t) -> t
136           in
137            beta_reduce (reductions_no,t')
138        | _,_ -> t'
139      end
140   in
141   apply_subst_gen ~appl_fun
142
143 let rec apply_subst_context subst context =
144   List.fold_right
145     (fun item context ->
146       match item with
147       | Some (n, Cic.Decl t) ->
148           let t' = apply_subst subst t in
149           Some (n, Cic.Decl t') :: context
150       | Some (n, Cic.Def (t, ty)) ->
151           let ty' =
152             match ty with
153             | None -> None
154             | Some ty -> Some (apply_subst subst ty)
155           in
156           let t' = apply_subst subst t in
157           Some (n, Cic.Def (t', ty')) :: context
158       | None -> None :: context)
159     context []
160
161 let apply_subst_metasenv subst metasenv =
162   List.map
163     (fun (n, context, ty) ->
164       (n, apply_subst_context subst context, apply_subst subst ty))
165     (List.filter
166       (fun (i, _, _) -> not (List.exists (fun (j, _) -> (j = i)) subst))
167       metasenv)
168
169 (***** Pretty printing functions ******)
170
171 let ppsubst subst =
172   String.concat "\n"
173     (List.map
174       (fun (idx, term) -> Printf.sprintf "?%d := %s" idx (CicPp.ppterm term))
175       subst)
176 ;;
177
178 let ppterm subst term = CicPp.ppterm (apply_subst subst term)
179
180 let ppterm_in_context subst term name_context =
181  CicPp.pp (apply_subst subst term) name_context
182
183 let ppcontext' ?(sep = "\n") subst context =
184  let separate s = if s = "" then "" else s ^ sep in
185   List.fold_right 
186    (fun context_entry (i,name_context) ->
187      match context_entry with
188         Some (n,Cic.Decl t) ->
189          sprintf "%s%s : %s" (separate i) (CicPp.ppname n)
190           (ppterm_in_context subst t name_context), (Some n)::name_context
191       | Some (n,Cic.Def (bo,ty)) ->
192          sprintf "%s%s : %s := %s" (separate i) (CicPp.ppname n)
193           (match ty with
194               None -> "_"
195             | Some ty -> ppterm_in_context subst ty name_context)
196           (ppterm_in_context subst bo name_context), (Some n)::name_context
197        | None ->
198           sprintf "%s_ :? _" (separate i), None::name_context
199     ) context ("",[])
200
201 let ppcontext ?sep subst context = fst (ppcontext' ?sep subst context)
202
203 let ppmetasenv ?(sep = "\n") metasenv subst =
204   String.concat sep
205     (List.map
206       (fun (i, c, t) ->
207         let context,name_context = ppcontext' ~sep:"; " subst c in
208          sprintf "%s |- ?%d: %s" context i
209           (ppterm_in_context subst t name_context))
210       (List.filter
211         (fun (i, _, _) -> not (List.exists (fun (j, _) -> (j = i)) subst))
212         metasenv))
213
214 (* From now on we recreate a kernel abstraction where substitutions are part of
215  * the calculus *)
216
217 let lift subst n term =
218   let term = apply_subst subst term in
219   try
220     CicSubstitution.lift n term
221   with e ->
222     raise (MetaSubstFailure ("Lift failure: " ^ Printexc.to_string e))
223
224 let subst subst t1 t2 =
225   let t1 = apply_subst subst t1 in
226   let t2 = apply_subst subst t2 in
227   try
228     CicSubstitution.subst t1 t2
229   with e ->
230     raise (MetaSubstFailure ("Subst failure: " ^ Printexc.to_string e))
231
232 let whd subst context term =
233   let term = apply_subst subst term in
234   let context = apply_subst_context subst context in
235   try
236     CicReduction.whd context term
237   with e ->
238     raise (MetaSubstFailure ("Weak head reduction failure: " ^
239       Printexc.to_string e))
240
241 let are_convertible subst context t1 t2 =
242   let context = apply_subst_context subst context in
243   let t1 = apply_subst subst t1 in
244   let t2 = apply_subst subst t2 in
245   CicReduction.are_convertible context t1 t2
246
247 let tempi_type_of_aux_subst = ref 0.0;;
248 let tempi_type_of_aux = ref 0.0;;
249
250 let type_of_aux' metasenv subst context term =
251 let time1 = Unix.gettimeofday () in
252   let term = apply_subst subst term in
253   let context = apply_subst_context subst context in
254   let metasenv =
255     List.map
256       (fun (i, c, t) -> (i, apply_subst_context subst c, apply_subst subst t))
257       (List.filter
258         (fun (i, _, _) -> not (List.exists (fun (j, _) -> (j = i)) subst))
259         metasenv)
260   in
261 let time2 = Unix.gettimeofday () in
262 let res =
263   try
264     CicTypeChecker.type_of_aux' metasenv context term
265   with CicTypeChecker.TypeCheckerFailure msg ->
266     raise (MetaSubstFailure ("Type checker failure: " ^ msg))
267 in
268 let time3 = Unix.gettimeofday () in
269  tempi_type_of_aux_subst := !tempi_type_of_aux_subst +. time3 -. time1 ; 
270  tempi_type_of_aux := !tempi_type_of_aux +. time2 -. time1 ; 
271  res
272
273 (**** DELIFT ****)
274 (* the delift function takes in input a metavariable index, an ordered list of
275  * optional terms [t1,...,tn] and a term t, and substitutes every tk = Some
276  * (rel(nk)) with rel(k).  Typically, the list of optional terms is the explicit
277  * substitution that is applied to a metavariable occurrence and the result of
278  * the delift function is a term the implicit variable can be substituted with
279  * to make the term [t] unifiable with the metavariable occurrence.  In general,
280  * the problem is undecidable if we consider equivalence in place of alpha
281  * convertibility. Our implementation, though, is even weaker than alpha
282  * convertibility, since it replace the term [tk] if and only if [tk] is a Rel
283  * (missing all the other cases). Does this matter in practice?
284  * The metavariable index is the index of the metavariable that must not occur
285  * in the term (for occur check).
286  *)
287
288 exception NotInTheList;;
289
290 let position n =
291   let rec aux k =
292    function 
293        [] -> raise NotInTheList
294      | (Some (Cic.Rel m))::_ when m=n -> k
295      | _::tl -> aux (k+1) tl in
296   aux 1
297 ;;
298
299 exception Occur;;
300
301 let rec force_does_not_occur subst to_be_restricted t =
302  let module C = Cic in
303  let more_to_be_restricted = ref [] in
304  let rec aux k = function
305       C.Rel r when List.mem (r - k) to_be_restricted -> raise Occur
306     | C.Rel _
307     | C.Sort _ as t -> t
308     | C.Implicit _ -> assert false
309     | C.Meta (n, l) ->
310        (* we do not retrieve the term associated to ?n in subst since *)
311        (* in this way we can restrict if something goes wrong         *)
312        let l' =
313          let i = ref 0 in
314          List.map
315            (function t ->
316              incr i ;
317              match t with
318                 None -> None
319               | Some t ->
320                  try
321                    Some (aux k t)
322                  with Occur ->
323                    more_to_be_restricted := (n,!i) :: !more_to_be_restricted;
324                    None)
325            l
326        in
327         C.Meta (n, l')
328     | C.Cast (te,ty) -> C.Cast (aux k te, aux k ty)
329     | C.Prod (name,so,dest) -> C.Prod (name, aux k so, aux (k+1) dest)
330     | C.Lambda (name,so,dest) -> C.Lambda (name, aux k so, aux (k+1) dest)
331     | C.LetIn (name,so,dest) -> C.LetIn (name, aux k so, aux (k+1) dest)
332     | C.Appl l -> C.Appl (List.map (aux k) l)
333     | C.Var (uri,exp_named_subst) ->
334         let exp_named_subst' =
335           List.map (fun (uri,t) -> (uri, aux k t)) exp_named_subst
336         in
337         C.Var (uri, exp_named_subst')
338     | C.Const (uri, exp_named_subst) ->
339         let exp_named_subst' =
340           List.map (fun (uri,t) -> (uri, aux k t)) exp_named_subst
341         in
342         C.Const (uri, exp_named_subst')
343     | C.MutInd (uri,tyno,exp_named_subst) ->
344         let exp_named_subst' =
345           List.map (fun (uri,t) -> (uri, aux k t)) exp_named_subst
346         in
347         C.MutInd (uri, tyno, exp_named_subst')
348     | C.MutConstruct (uri,tyno,consno,exp_named_subst) ->
349         let exp_named_subst' =
350           List.map (fun (uri,t) -> (uri, aux k t)) exp_named_subst
351         in
352         C.MutConstruct (uri, tyno, consno, exp_named_subst')
353     | C.MutCase (uri,tyno,out,te,pl) ->
354         C.MutCase (uri, tyno, aux k out, aux k te, List.map (aux k) pl)
355     | C.Fix (i,fl) ->
356        let len = List.length fl in
357        let k_plus_len = k + len in
358        let fl' =
359          List.map
360           (fun (name,j,ty,bo) -> (name, j, aux k ty, aux k_plus_len bo)) fl
361        in
362        C.Fix (i, fl')
363     | C.CoFix (i,fl) ->
364        let len = List.length fl in
365        let k_plus_len = k + len in
366        let fl' =
367          List.map
368           (fun (name,ty,bo) -> (name, aux k ty, aux k_plus_len bo)) fl
369        in
370        C.CoFix (i, fl')
371  in
372  let res = aux 0 t in
373  (!more_to_be_restricted, res)
374  
375 let rec restrict subst to_be_restricted metasenv =
376   let names_of_context_indexes context indexes =
377     String.concat ", "
378       (List.map
379         (fun i ->
380           try
381            match List.nth context i with
382            | None -> assert false
383            | Some (n, _) -> CicPp.ppname n
384           with
385            Failure _ -> assert false
386         ) indexes)
387   in
388   let force_does_not_occur_in_context to_be_restricted = function
389     | None -> [], None
390     | Some (name, Cic.Decl t) ->
391         let (more_to_be_restricted, t') =
392           force_does_not_occur subst to_be_restricted t
393         in
394         more_to_be_restricted, Some (name, Cic.Decl t')
395     | Some (name, Cic.Def (bo, ty)) ->
396         let (more_to_be_restricted, bo') =
397           force_does_not_occur subst to_be_restricted bo
398         in
399         let more_to_be_restricted, ty' =
400           match ty with
401           | None ->  more_to_be_restricted, None
402           | Some ty ->
403               let more_to_be_restricted', ty' =
404                 force_does_not_occur subst to_be_restricted ty
405               in
406               more_to_be_restricted @ more_to_be_restricted',
407               Some ty'
408         in
409         more_to_be_restricted, Some (name, Cic.Def (bo', ty'))
410   in
411   let rec erase i to_be_restricted n = function
412     | [] -> [], to_be_restricted, []
413     | hd::tl ->
414         let more_to_be_restricted,restricted,tl' =
415          erase (i+1) to_be_restricted n tl
416         in
417         let restrict_me = List.mem i restricted in
418         if restrict_me then
419          more_to_be_restricted, restricted, None:: tl'
420         else
421           (try
422             let more_to_be_restricted', hd' =
423               let delifted_restricted =
424                let rec aux =
425                 function
426                    [] -> []
427                  | j::tl when j > i -> (j - i)::aux tl
428                  | _::tl -> aux tl
429                in
430                 aux restricted
431               in
432                force_does_not_occur_in_context delifted_restricted hd
433             in
434              more_to_be_restricted @ more_to_be_restricted',
435              restricted, hd' :: tl'
436           with Occur ->
437             more_to_be_restricted, (i :: restricted), None :: tl')
438   in
439   let (more_to_be_restricted, metasenv, subst) =
440     List.fold_right
441       (fun (n, context, t) (more, metasenv, subst) ->
442         let to_be_restricted =
443           List.map snd (List.filter (fun (m, _) -> m = n) to_be_restricted)
444         in
445         let (more_to_be_restricted, restricted, context') =
446          (* just an optimization *)
447          if to_be_restricted = [] then
448           [],[],context
449          else
450           erase 1 to_be_restricted n context
451         in
452         try
453           let more_to_be_restricted', t' =
454             force_does_not_occur subst restricted t
455           in
456           let metasenv' = (n, context', t') :: metasenv in
457           (try
458             let s = List.assoc n subst in
459             try
460               let more_to_be_restricted'', s' =
461                 force_does_not_occur subst restricted s
462               in
463               let subst' = (n, s') :: (List.remove_assoc n subst) in
464               let more =
465                 more @ more_to_be_restricted @ more_to_be_restricted' @
466                   more_to_be_restricted''
467               in
468               (more, metasenv', subst')
469             with Occur ->
470               raise (MetaSubstFailure (sprintf
471                 "Cannot restrict the context of the metavariable ?%d over the hypotheses %s since ?%d is already instantiated with %s and at least one of the hypotheses occurs in the substituted term"
472                 n (names_of_context_indexes context to_be_restricted) n
473                 (ppterm subst s)))
474            with Not_found -> (more @ more_to_be_restricted @ more_to_be_restricted', metasenv', subst))
475         with Occur ->
476           raise (MetaSubstFailure (sprintf
477             "Cannot restrict the context of the metavariable ?%d over the hypotheses %s since metavariable's type depends on at least one of them"
478             n (names_of_context_indexes context to_be_restricted))))
479       metasenv ([], [], subst)
480   in
481   match more_to_be_restricted with
482   | [] -> (metasenv, subst)
483   | _ -> restrict subst more_to_be_restricted metasenv
484 ;;
485
486 (*CSC: maybe we should rename delift in abstract, as I did in my dissertation *)
487 let delift n subst context metasenv l t =
488  let module S = CicSubstitution in
489   let l =
490    let (_, canonical_context, _) = CicUtil.lookup_meta n metasenv in
491    List.map2 (fun ct lt ->
492      match (ct, lt) with
493      | None, _ -> None
494      | Some _, _ -> lt)
495      canonical_context l
496   in
497   let to_be_restricted = ref [] in
498   let rec deliftaux k =
499    let module C = Cic in
500     function
501        C.Rel m -> 
502          if m <=k then
503           C.Rel m   (*CSC: che succede se c'e' un Def? Dovrebbe averlo gia' *)
504                     (*CSC: deliftato la regola per il LetIn                 *)
505                     (*CSC: FALSO! La regola per il LetIn non lo fa          *)
506          else
507           (try
508             match List.nth context (m-k-1) with
509                Some (_,C.Def (t,_)) ->
510                 (*CSC: Hmmm. This bit of reduction is not in the spirit of    *)
511                 (*CSC: first order unification. Does it help or does it harm? *)
512                 deliftaux k (S.lift m t)
513              | Some (_,C.Decl t) ->
514                 C.Rel ((position (m-k) l) + k)
515              | None -> raise (MetaSubstFailure "RelToHiddenHypothesis")
516            with
517             Failure _ ->
518              raise (MetaSubstFailure "Unbound variable found in deliftaux")
519           )
520      | C.Var (uri,exp_named_subst) ->
521         let exp_named_subst' =
522          List.map (function (uri,t) -> uri,deliftaux k t) exp_named_subst
523         in
524          C.Var (uri,exp_named_subst')
525      | C.Meta (i, l1) as t -> 
526         if i = n then
527           raise (MetaSubstFailure (sprintf
528             "Cannot unify the metavariable ?%d with a term that has as subterm %s in which the same metavariable occurs (occur check)"
529             i (ppterm subst t)))
530         else
531          (* I do not consider the term associated to ?i in subst since *)
532          (* in this way I can restrict if something goes wrong.        *)
533           let rec deliftl j =
534            function
535               [] -> []
536             | None::tl -> None::(deliftl (j+1) tl)
537             | (Some t)::tl ->
538                let l1' = (deliftl (j+1) tl) in
539                 try
540                  Some (deliftaux k t)::l1'
541                 with
542                    NotInTheList
543                  | MetaSubstFailure _ ->
544                     to_be_restricted := (i,j)::!to_be_restricted ; None::l1'
545           in
546            let l' = deliftl 1 l1 in
547             C.Meta(i,l')
548      | C.Sort _ as t -> t
549      | C.Implicit _ as t -> t
550      | C.Cast (te,ty) -> C.Cast (deliftaux k te, deliftaux k ty)
551      | C.Prod (n,s,t) -> C.Prod (n, deliftaux k s, deliftaux (k+1) t)
552      | C.Lambda (n,s,t) -> C.Lambda (n, deliftaux k s, deliftaux (k+1) t)
553      | C.LetIn (n,s,t) -> C.LetIn (n, deliftaux k s, deliftaux (k+1) t)
554      | C.Appl l -> C.Appl (List.map (deliftaux k) l)
555      | C.Const (uri,exp_named_subst) ->
556         let exp_named_subst' =
557          List.map (function (uri,t) -> uri,deliftaux k t) exp_named_subst
558         in
559          C.Const (uri,exp_named_subst')
560      | C.MutInd (uri,typeno,exp_named_subst) ->
561         let exp_named_subst' =
562          List.map (function (uri,t) -> uri,deliftaux k t) exp_named_subst
563         in
564          C.MutInd (uri,typeno,exp_named_subst')
565      | C.MutConstruct (uri,typeno,consno,exp_named_subst) ->
566         let exp_named_subst' =
567          List.map (function (uri,t) -> uri,deliftaux k t) exp_named_subst
568         in
569          C.MutConstruct (uri,typeno,consno,exp_named_subst')
570      | C.MutCase (sp,i,outty,t,pl) ->
571         C.MutCase (sp, i, deliftaux k outty, deliftaux k t,
572          List.map (deliftaux k) pl)
573      | C.Fix (i, fl) ->
574         let len = List.length fl in
575         let liftedfl =
576          List.map
577           (fun (name, i, ty, bo) ->
578            (name, i, deliftaux k ty, deliftaux (k+len) bo))
579            fl
580         in
581          C.Fix (i, liftedfl)
582      | C.CoFix (i, fl) ->
583         let len = List.length fl in
584         let liftedfl =
585          List.map
586           (fun (name, ty, bo) -> (name, deliftaux k ty, deliftaux (k+len) bo))
587            fl
588         in
589          C.CoFix (i, liftedfl)
590   in
591    let res =
592     try
593      deliftaux 0 t
594     with
595      NotInTheList ->
596       (* This is the case where we fail even first order unification. *)
597       (* The reason is that our delift function is weaker than first  *)
598       (* order (in the sense of alpha-conversion). See comment above  *)
599       (* related to the delift function.                              *)
600 debug_print "\n!!!!!!!!!!! First Order UnificationFailure, but maybe it could have been successful even in a first order setting (no conversion, only alpha convertibility)! Please, implement a better delift function !!!!!!!!!!!!!!!!" ;
601 print_string "\nCicMetaSubst: UNCERTAIN" ;
602       raise (Uncertain (sprintf
603         "Error trying to abstract %s over [%s]: the algorithm only tried to abstract over bound variables"
604         (ppterm subst t)
605         (String.concat "; "
606           (List.map
607             (function Some t -> ppterm subst t | None -> "_")
608             l))))
609    in
610    let (metasenv, subst) = restrict subst !to_be_restricted metasenv in
611     res, metasenv, subst
612 ;;
613
614 (**** END OF DELIFT ****)
615
616
617 (** {2 Format-like pretty printers} *)
618
619 let fpp_gen ppf s =
620   Format.pp_print_string ppf s;
621   Format.pp_print_newline ppf ();
622   Format.pp_print_flush ppf ()
623
624 let fppsubst ppf subst = fpp_gen ppf (ppsubst subst)
625 let fppterm ppf term = fpp_gen ppf (CicPp.ppterm term)
626 let fppmetasenv ppf metasenv = fpp_gen ppf (ppmetasenv metasenv [])
627