]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/cic_unification/cicUnification.ml
* Reindentation.
[helm.git] / helm / ocaml / cic_unification / cicUnification.ml
1 (* Copyright (C) 2000, 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 exception UnificationFailed;;
27 exception Free;;
28 exception OccurCheck;;
29 exception RelToHiddenHypothesis;;
30 exception OpenTerm;;
31
32 (**** DELIFT ****)
33
34 (* the delift function takes in input an ordered list of integers [n1,...,nk]
35    and a term t, and relocates rel(nk) to k. Typically, the list of integers 
36    is a parameter of a metavariable occurrence. *)
37
38 exception NotInTheList;;
39
40 let position n =
41   let rec aux k =
42    function 
43        [] -> raise NotInTheList
44      | (Some (Cic.Rel m))::_ when m=n -> k
45      | _::tl -> aux (k+1) tl in
46   aux 1
47 ;;
48  
49 let restrict to_be_restricted =
50   let rec erase i n = 
51     function
52         [] -> []
53       |        _::tl when List.mem (n,i) to_be_restricted ->
54           None::(erase (i+1) n tl) 
55       | he::tl -> he::(erase (i+1) n tl) in
56   let rec aux =
57     function 
58         [] -> []
59       |        (n,context,t)::tl -> (n,erase 1 n context,t)::(aux tl) in
60   aux
61 ;;
62
63
64 let delift context metasenv l t =
65  let module S = CicSubstitution in
66   let to_be_restricted = ref [] in
67   let rec deliftaux k =
68    let module C = Cic in
69     function
70        C.Rel m -> 
71          if m <=k then
72           C.Rel m   (*CSC: che succede se c'e' un Def? Dovrebbe averlo gia' *)
73                     (*CSC: deliftato la regola per il LetIn                 *)
74          else
75           (match List.nth context (m-k-1) with
76             Some (_,C.Def (t,_)) -> deliftaux k (S.lift m t)
77           | Some (_,C.Decl t) ->
78              (* It may augment to_be_restricted *)
79              ignore (deliftaux k (S.lift m t)) ;
80              C.Rel ((position (m-k) l) + k)
81           | None -> raise RelToHiddenHypothesis)
82      | C.Var (uri,exp_named_subst) ->
83         let exp_named_subst' =
84          List.map (function (uri,t) -> uri,deliftaux k t) exp_named_subst
85         in
86          C.Var (uri,exp_named_subst')
87      | C.Meta (i, l1) as t -> 
88         let rec deliftl j =
89          function
90             [] -> []
91           | None::tl -> None::(deliftl (j+1) tl)
92           | (Some t)::tl ->
93              let l1' = (deliftl (j+1) tl) in
94               try
95                Some (deliftaux k t)::l1'
96               with
97                  RelToHiddenHypothesis
98                | NotInTheList ->
99                   to_be_restricted := (i,j)::!to_be_restricted ; None::l1'
100         in
101          let l' = deliftl 1 l1 in
102           C.Meta(i,l')
103      | C.Sort _ as t -> t
104      | C.Implicit as t -> t
105      | C.Cast (te,ty) -> C.Cast (deliftaux k te, deliftaux k ty)
106      | C.Prod (n,s,t) -> C.Prod (n, deliftaux k s, deliftaux (k+1) t)
107      | C.Lambda (n,s,t) -> C.Lambda (n, deliftaux k s, deliftaux (k+1) t)
108      | C.LetIn (n,s,t) -> C.LetIn (n, deliftaux k s, deliftaux (k+1) t)
109      | C.Appl l -> C.Appl (List.map (deliftaux k) l)
110      | C.Const (uri,exp_named_subst) ->
111         let exp_named_subst' =
112          List.map (function (uri,t) -> uri,deliftaux k t) exp_named_subst
113         in
114          C.Const (uri,exp_named_subst')
115      | C.MutInd (uri,typeno,exp_named_subst) ->
116         let exp_named_subst' =
117          List.map (function (uri,t) -> uri,deliftaux k t) exp_named_subst
118         in
119          C.MutInd (uri,typeno,exp_named_subst')
120      | C.MutConstruct (uri,typeno,consno,exp_named_subst) ->
121         let exp_named_subst' =
122          List.map (function (uri,t) -> uri,deliftaux k t) exp_named_subst
123         in
124          C.MutConstruct (uri,typeno,consno,exp_named_subst')
125      | C.MutCase (sp,i,outty,t,pl) ->
126         C.MutCase (sp, i, deliftaux k outty, deliftaux k t,
127          List.map (deliftaux k) pl)
128      | C.Fix (i, fl) ->
129         let len = List.length fl in
130         let liftedfl =
131          List.map
132           (fun (name, i, ty, bo) ->
133            (name, i, deliftaux k ty, deliftaux (k+len) bo))
134            fl
135         in
136          C.Fix (i, liftedfl)
137      | C.CoFix (i, fl) ->
138         let len = List.length fl in
139         let liftedfl =
140          List.map
141           (fun (name, ty, bo) -> (name, deliftaux k ty, deliftaux (k+len) bo))
142            fl
143         in
144          C.CoFix (i, liftedfl)
145   in
146     let res = deliftaux 0 t in
147     res, restrict !to_be_restricted metasenv
148 ;;
149
150 (**** END OF DELIFT ****)
151
152 type substitution = (int * Cic.term) list
153
154 (* NUOVA UNIFICAZIONE *)
155 (* A substitution is a (int * Cic.term) list that associates a
156    metavariable i with its body.
157    A metaenv is a (int * Cic.term) list that associate a metavariable
158    i with is type. 
159    fo_unif_new takes a metasenv, a context, two terms t1 and t2 and gives back
160    a new substitution which is _NOT_ unwinded. It must be unwinded before
161    applying it. *)
162  
163 let rec fo_unif_subst subst context metasenv t1 t2 =  
164  let module C = Cic in
165  let module R = CicReduction in
166  let module S = CicSubstitution in
167   match (t1, t2) with
168      (C.Meta (n,ln), C.Meta (m,lm)) when n=m ->
169        let ok =
170         List.fold_left2
171          (fun b t1 t2 ->
172            b &&
173             match t1,t2 with
174                None,_
175              | _,None -> true
176              | Some t1', Some t2' ->
177                 (* First possibility:  restriction    *)
178                 (* Second possibility: unification    *)
179                 (* Third possibility:  convertibility *)
180                 R.are_convertible context t1' t2'
181          ) true ln lm
182        in
183         if ok then subst,metasenv else raise UnificationFailed
184    | (C.Meta (n,l), C.Meta (m,_)) when n>m ->
185        fo_unif_subst subst context metasenv t2 t1
186    | (C.Meta (n,l), t)   
187    | (t, C.Meta (n,l)) ->
188        let subst',metasenv' =
189         try
190          let oldt = (List.assoc n subst) in
191          let lifted_oldt = S.lift_meta l oldt in
192           fo_unif_subst subst context metasenv lifted_oldt t
193         with Not_found ->
194          let t',metasenv' = delift context metasenv l t in
195           (n, t')::subst, metasenv'
196        in
197         let (_,_,meta_type) = 
198          List.find (function (m,_,_) -> m=n) metasenv' in
199         let tyt = CicTypeChecker.type_of_aux' metasenv' context t in
200          fo_unif_subst subst' context metasenv' (S.lift_meta l meta_type) tyt
201    | (C.Var (uri1,exp_named_subst1),C.Var (uri2,exp_named_subst2))
202    | (C.Const (uri1,exp_named_subst1),C.Const (uri2,exp_named_subst2)) ->
203       if UriManager.eq uri1 uri2 then
204        fo_unif_subst_exp_named_subst subst context metasenv
205         exp_named_subst1 exp_named_subst2
206       else
207        raise UnificationFailed
208    | C.MutInd (uri1,i1,exp_named_subst1),C.MutInd (uri2,i2,exp_named_subst2) ->
209       if UriManager.eq uri1 uri2 && i1 = i2 then
210        fo_unif_subst_exp_named_subst subst context metasenv
211         exp_named_subst1 exp_named_subst2
212       else
213        raise UnificationFailed
214    | C.MutConstruct (uri1,i1,j1,exp_named_subst1),
215      C.MutConstruct (uri2,i2,j2,exp_named_subst2) ->
216       if UriManager.eq uri1 uri2 && i1 = i2 && j1 = j2 then
217        fo_unif_subst_exp_named_subst subst context metasenv
218         exp_named_subst1 exp_named_subst2
219       else
220        raise UnificationFailed
221    | (C.Rel _, _)
222    | (_,  C.Rel _) 
223    | (C.Sort _ ,_)
224    | (_, C.Sort _)
225    | (C.Implicit, _)
226    | (_, C.Implicit) -> 
227        if R.are_convertible context t1 t2 then
228         subst, metasenv
229        else
230         raise UnificationFailed
231    | (C.Cast (te,ty), t2) -> fo_unif_subst subst context metasenv te t2
232    | (t1, C.Cast (te,ty)) -> fo_unif_subst subst context metasenv t1 te
233    | (C.Prod (n1,s1,t1), C.Prod (_,s2,t2)) -> 
234        let subst',metasenv' = fo_unif_subst subst context metasenv s1 s2 in
235         fo_unif_subst subst' ((Some (n1,(C.Decl s1)))::context) metasenv' t1 t2
236    | (C.Lambda (n1,s1,t1), C.Lambda (_,s2,t2)) -> 
237        let subst',metasenv' = fo_unif_subst subst context metasenv s1 s2 in
238         fo_unif_subst subst' ((Some (n1,(C.Decl s1)))::context) metasenv' t1 t2
239    | (C.LetIn (_,s1,t1), t2)  
240    | (t2, C.LetIn (_,s1,t1)) -> 
241        fo_unif_subst subst context metasenv t2 (S.subst s1 t1)
242    | (C.Appl l1, C.Appl l2) -> 
243        let lr1 = List.rev l1 in
244        let lr2 = List.rev l2 in
245        let rec fo_unif_l subst metasenv =
246         function
247            [],_
248          | _,[] -> assert false
249          | ([h1],[h2]) ->
250              fo_unif_subst subst context metasenv h1 h2
251          | ([h],l) 
252          | (l,[h]) ->
253              fo_unif_subst subst context metasenv h (C.Appl (List.rev l))
254          | ((h1::l1),(h2::l2)) -> 
255             let subst', metasenv' = 
256              fo_unif_subst subst context metasenv h1 h2
257             in 
258              fo_unif_l subst' metasenv' (l1,l2)
259        in
260         fo_unif_l subst metasenv (lr1, lr2) 
261    | (C.Const _, _) 
262    | (_, C.Const _)
263    | (C.MutInd  _, _) 
264    | (_, C.MutInd _)
265    | (C.MutConstruct _, _)
266    | (_, C.MutConstruct _) -> 
267       if R.are_convertible context t1 t2 then
268        subst, metasenv
269       else
270        raise UnificationFailed
271    | (C.MutCase (_,_,outt1,t1,pl1), C.MutCase (_,_,outt2,t2,pl2))->
272        let subst', metasenv' = 
273         fo_unif_subst subst context metasenv outt1 outt2 in
274        let subst'',metasenv'' = 
275         fo_unif_subst subst' context metasenv' t1 t2 in
276        List.fold_left2 
277         (function (subst,metasenv) ->
278           fo_unif_subst subst context metasenv
279         ) (subst'',metasenv'') pl1 pl2 
280    | (C.Fix _, _)
281    | (_, C.Fix _) 
282    | (C.CoFix _, _)
283    | (_, C.CoFix _) -> 
284        if R.are_convertible context t1 t2 then
285         subst, metasenv
286        else
287         raise UnificationFailed
288    | (_,_) ->
289        if R.are_convertible context t1 t2 then
290         subst, metasenv
291        else
292         raise UnificationFailed
293
294 and fo_unif_subst_exp_named_subst subst context metasenv
295  exp_named_subst1 exp_named_subst2
296 =
297 try
298  List.fold_left2
299   (fun (subst,metasenv) (uri1,t1) (uri2,t2) ->
300     assert (uri1=uri2) ;
301     fo_unif_subst subst context metasenv t1 t2
302   ) (subst,metasenv) exp_named_subst1 exp_named_subst2
303 with
304 e ->
305 let uri = UriManager.uri_of_string "cic:/dummy.var" in
306 prerr_endline ("@@@: " ^ CicPp.ppterm (Cic.Var (uri,exp_named_subst1)) ^
307 " <==> " ^ CicPp.ppterm (Cic.Var (uri,exp_named_subst2))) ; raise e
308 ;;
309
310 let unwind metasenv subst unwinded t =
311  let unwinded = ref unwinded in
312  let frozen = ref [] in
313  let rec um_aux metasenv =
314   let module C = Cic in
315   let module S = CicSubstitution in 
316    function
317       C.Rel _ as t -> t,metasenv
318     | C.Var _  as t -> t,metasenv
319     | C.Meta (i,l) -> 
320         (try
321           S.lift_meta l (List.assoc i !unwinded), metasenv
322          with Not_found ->
323            if List.mem i !frozen then raise OccurCheck
324            else
325             let saved_frozen = !frozen in 
326             frozen := i::!frozen ;
327             let res =
328              try
329               let t = List.assoc i subst in
330               let t',metasenv' = um_aux metasenv t in
331               let _,metasenv'' =
332                let (_,canonical_context,_) = 
333                 List.find (function (m,_,_) -> m=i) metasenv
334                in
335                 delift canonical_context metasenv' l t'
336               in
337                unwinded := (i,t')::!unwinded ;
338                S.lift_meta l t', metasenv'
339              with
340               Not_found ->
341                (* not constrained variable, i.e. free in subst*)
342                let l',metasenv' =
343                 List.fold_right
344                  (fun t (tl,metasenv) ->
345                    match t with
346                       None -> None::tl,metasenv
347                     | Some t -> 
348                        let t',metasenv' = um_aux metasenv t in
349                         (Some t')::tl, metasenv'
350                  ) l ([],metasenv)
351                in
352                 C.Meta (i,l'), metasenv'
353             in
354             frozen := saved_frozen ;
355             res
356         ) 
357     | C.Sort _
358     | C.Implicit as t -> t,metasenv
359     | C.Cast (te,ty) ->
360        let te',metasenv' = um_aux metasenv te in
361        let ty',metasenv'' = um_aux metasenv' ty in
362        C.Cast (te',ty'),metasenv''
363     | C.Prod (n,s,t) ->
364        let s',metasenv' = um_aux metasenv s in
365        let t',metasenv'' = um_aux metasenv' t in
366        C.Prod (n, s', t'), metasenv''
367     | C.Lambda (n,s,t) ->
368        let s',metasenv' = um_aux metasenv s in
369        let t',metasenv'' = um_aux metasenv' t in
370        C.Lambda (n, s', t'), metasenv''
371     | C.LetIn (n,s,t) ->
372        let s',metasenv' = um_aux metasenv s in
373        let t',metasenv'' = um_aux metasenv' t in
374        C.LetIn (n, s', t'), metasenv''
375     | C.Appl (he::tl) ->
376        let tl',metasenv' =
377         List.fold_right
378          (fun t (tl,metasenv) ->
379            let t',metasenv' = um_aux metasenv t in
380             t'::tl, metasenv'
381          ) tl ([],metasenv)
382        in
383         begin
384          match um_aux metasenv' he with
385             (C.Appl l, metasenv'') -> C.Appl (l@tl'),metasenv''
386           | (he', metasenv'') -> C.Appl (he'::tl'),metasenv''
387         end
388     | C.Appl _ -> assert false
389     | C.Const (uri,exp_named_subst) ->
390        let exp_named_subst', metasenv' =
391         List.fold_right
392          (fun (uri,t) (tl,metasenv) ->
393            let t',metasenv' = um_aux metasenv t in
394             (uri,t')::tl, metasenv'
395          ) exp_named_subst ([],metasenv)
396        in
397         C.Const (uri,exp_named_subst'),metasenv'
398     | C.MutInd (uri,typeno,exp_named_subst) ->
399        let exp_named_subst', metasenv' =
400         List.fold_right
401          (fun (uri,t) (tl,metasenv) ->
402            let t',metasenv' = um_aux metasenv t in
403             (uri,t')::tl, metasenv'
404          ) exp_named_subst ([],metasenv)
405        in
406         C.MutInd (uri,typeno,exp_named_subst'),metasenv'
407     | C.MutConstruct (uri,typeno,consno,exp_named_subst) ->
408        let exp_named_subst', metasenv' =
409         List.fold_right
410          (fun (uri,t) (tl,metasenv) ->
411            let t',metasenv' = um_aux metasenv t in
412             (uri,t')::tl, metasenv'
413          ) exp_named_subst ([],metasenv)
414        in
415         C.MutConstruct (uri,typeno,consno,exp_named_subst'),metasenv'
416     | C.MutCase (sp,i,outty,t,pl) ->
417        let outty',metasenv' = um_aux metasenv outty in
418        let t',metasenv'' = um_aux metasenv' t in
419        let pl',metasenv''' =
420         List.fold_right
421          (fun p (pl,metasenv) ->
422            let p',metasenv' = um_aux metasenv p in
423             p'::pl, metasenv'
424          ) pl ([],metasenv'')
425        in
426         C.MutCase (sp, i, outty', t', pl'),metasenv'''
427     | C.Fix (i, fl) ->
428        let len = List.length fl in
429        let liftedfl,metasenv' =
430         List.fold_right
431          (fun (name, i, ty, bo) (fl,metasenv) ->
432            let ty',metasenv' = um_aux metasenv ty in
433            let bo',metasenv'' = um_aux metasenv' bo in
434             (name, i, ty', bo')::fl,metasenv''
435          ) fl ([],metasenv)
436        in
437         C.Fix (i, liftedfl),metasenv'
438     | C.CoFix (i, fl) ->
439        let len = List.length fl in
440        let liftedfl,metasenv' =
441         List.fold_right
442          (fun (name, ty, bo) (fl,metasenv) ->
443            let ty',metasenv' = um_aux metasenv ty in
444            let bo',metasenv'' = um_aux metasenv' bo in
445             (name, ty', bo')::fl,metasenv''
446          ) fl ([],metasenv)
447        in
448         C.CoFix (i, liftedfl),metasenv'
449  in
450   let t',metasenv' = um_aux metasenv t in
451    t',metasenv',!unwinded 
452 ;;
453
454 (* apply_subst_reducing subst (Some (mtr,reductions_no)) t              *)
455 (* performs as (apply_subst subst t) until it finds an application of   *)
456 (* (META [meta_to_reduce]) that, once unwinding is performed, creates   *)
457 (* a new beta-redex; in this case up to [reductions_no] consecutive     *)
458 (* beta-reductions are performed.                                       *)
459 (* Hint: this function is usually called when [reductions_no]           *)
460 (*  eta-expansions have been performed and the head of the new          *)
461 (*  application has been unified with (META [meta_to_reduce]):          *)
462 (*  during the unwinding the eta-expansions are undone.                 *)
463
464 let apply_subst_reducing subst meta_to_reduce t =
465  let unwinded = ref subst in
466  let rec um_aux =
467   let module C = Cic in
468   let module S = CicSubstitution in 
469    function
470       C.Rel _
471     | C.Var _  as t -> t
472     | C.Meta (i,l) as t ->
473        (try
474          S.lift_meta l (List.assoc i !unwinded)
475         with Not_found ->
476           C.Meta (i,l))
477     | C.Sort _ as t -> t
478     | C.Implicit as t -> t
479     | C.Cast (te,ty) -> C.Cast (um_aux te, um_aux ty)
480     | C.Prod (n,s,t) -> C.Prod (n, um_aux s, um_aux t)
481     | C.Lambda (n,s,t) -> C.Lambda (n, um_aux s, um_aux t)
482     | C.LetIn (n,s,t) -> C.LetIn (n, um_aux s, um_aux t)
483     | C.Appl (he::tl) ->
484        let tl' = List.map um_aux tl in
485         let t' =
486          match um_aux he with
487             C.Appl l -> C.Appl (l@tl')
488           | _ as he' -> C.Appl (he'::tl')
489         in
490          begin
491           match meta_to_reduce,he with
492              Some (mtr,reductions_no), C.Meta (m,_) when m = mtr ->
493               let rec beta_reduce =
494                function
495                   (n,(C.Appl (C.Lambda (_,_,t)::he'::tl'))) when n > 0 ->
496                     let he'' = CicSubstitution.subst he' t in
497                      if tl' = [] then
498                       he''
499                      else
500                       beta_reduce (n-1,C.Appl(he''::tl'))
501                 | (_,t) -> t
502               in
503                beta_reduce (reductions_no,t')
504            | _,_ -> t'
505          end
506     | C.Appl _ -> assert false
507     | C.Const (uri,exp_named_subst) ->
508        let exp_named_subst' =
509         List.map (function (uri,t) -> (uri,um_aux t)) exp_named_subst
510        in
511         C.Const (uri,exp_named_subst')
512     | C.MutInd (uri,typeno,exp_named_subst) ->
513        let exp_named_subst' =
514         List.map (function (uri,t) -> (uri,um_aux t)) exp_named_subst
515        in
516         C.MutInd (uri,typeno,exp_named_subst')
517     | C.MutConstruct (uri,typeno,consno,exp_named_subst) ->
518        let exp_named_subst' =
519         List.map (function (uri,t) -> (uri,um_aux t)) exp_named_subst
520        in
521         C.MutConstruct (uri,typeno,consno,exp_named_subst')
522     | C.MutCase (sp,i,outty,t,pl) ->
523        C.MutCase (sp, i, um_aux outty, um_aux t,
524         List.map um_aux pl)
525     | C.Fix (i, fl) ->
526        let len = List.length fl in
527        let liftedfl =
528         List.map
529          (fun (name, i, ty, bo) -> (name, i, um_aux ty, um_aux bo))
530           fl
531        in
532         C.Fix (i, liftedfl)
533     | C.CoFix (i, fl) ->
534        let len = List.length fl in
535        let liftedfl =
536         List.map
537          (fun (name, ty, bo) -> (name, um_aux ty, um_aux bo))
538           fl
539        in
540         C.CoFix (i, liftedfl)
541  in
542    um_aux t
543 ;;
544
545 (* UNWIND THE MGU INSIDE THE MGU *)
546 let unwind_subst metasenv subst =
547  let identity_relocation_list_for_metavariable i =
548   let (_,canonical_context,_) =
549    List.find (function (m,_,_) -> m=i) metasenv
550   in
551    let canonical_context_length = List.length canonical_context in
552     let rec aux =
553      function
554         n when n > canonical_context_length -> []
555       | n -> (Some (Cic.Rel n))::(aux (n+1))
556     in
557      aux 1
558  in
559   List.fold_left
560    (fun (unwinded,metasenv) (i,_) ->
561      let identity_relocation_list =
562       identity_relocation_list_for_metavariable i
563      in
564       let (_,metasenv',subst') =
565        unwind metasenv subst unwinded (Cic.Meta (i,identity_relocation_list))
566       in
567        subst',metasenv'
568    ) ([],metasenv) subst
569 ;;
570
571 let apply_subst subst t = 
572  (* metasenv will not be used nor modified. So, let's use a dummy empty one *)
573  let metasenv = [] in
574   let (t',_,_) = unwind metasenv [] subst t in
575    t'
576 ;;
577
578 (* A substitution is a (int * Cic.term) list that associates a               *)
579 (* metavariable i with its body.                                             *)
580 (* metasenv is of type Cic.metasenv                                          *)
581 (* fo_unif takes a metasenv, a context, two terms t1 and t2 and gives back   *)
582 (* a new substitution which is already unwinded and ready to be applied and  *)
583 (* a new metasenv in which some hypothesis in the contexts of the            *)
584 (* metavariables may have been restricted.                                   *)
585 let fo_unif metasenv context t1 t2 =
586  let subst_to_unwind,metasenv' = fo_unif_subst [] context metasenv t1 t2 in
587   unwind_subst metasenv' subst_to_unwind
588 ;;