aux k ms (NCicSubstitution.lift n bo))
| _,NCic.Decl _ -> ms, NCic.Rel ((position (n-k) l) + k)
with Failure _ -> assert false) (*Unbound variable found in delift*)
+ | NCic.Meta (_,(_,(NCic.Irl 0| NCic.Ctx []))) as orig -> ms, orig
| NCic.Meta (i,l1) as orig ->
(try
let _,_,t,_ = NCicUtils.lookup_subst i subst in
else
let shift1,lc1 = l1 in
let shift,lc = l in
+ let shift = shift + k in
+ let _ = prerr_endline ("XXX restringo " ^ string_of_int i) in
match lc, lc1 with
| NCic.Irl len, NCic.Irl len1
- when shift1 - k < shift || len1 + shift1 - k > len + shift ->
- let low_gap = max 0 (shift - (shift1 - k)) in
- let high_gap = max 0 (shift1 + len1 - k - (shift + len)) in
+ when shift1 + len1 < shift || shift1 > shift + len ->
+ prerr_endline "WWW 1";
+ let restrictions = HExtlib.list_seq 1 (len1 + 1) in
+ let metasenv, subst, newmeta =
+ restrict metasenv subst i restrictions
+ in
+ (metasenv, subst),
+ NCic.Meta (newmeta, (0,NCic.Irl (max 0 (k-shift1))))
+ | NCic.Irl len, NCic.Irl len1
+ when shift1 < shift || len1 + shift1 > len + shift ->
+ (* C. Hoare. Premature optimization is the root of all evil*)
+ prerr_endline ("WWW 2 : " ^ string_of_int i);
+ let stop = shift + len in
+ let stop1 = shift1 + len1 in
+ let low_gap = max 0 (shift - shift1) in
+ let high_gap = max 0 (stop1 - stop) in
let restrictions =
- HExtlib.list_seq 1 (low_gap+1) @
- HExtlib.list_seq (len1-high_gap) len1
+ HExtlib.list_seq (k+1-shift1) (low_gap + 1) @
+ HExtlib.list_seq (len1 - high_gap + 1) (len1 + 1)
in
-(*
+ let metasenv, subst, newmeta =
+ restrict metasenv subst i restrictions
+ in
prerr_endline ("RESTRICTIONS FOR: " ^
- NCicPp.ppterm ~metasenv ~subst ~context:[]
+ NCicPp.ppterm ~metasenv ~subst ~context:[]
(NCic.Meta (i,l1)) ^
" that was part of a term unified with " ^
NCicPp.ppterm ~metasenv ~subst ~context:[]
(NCic.Meta (n,l)) ^ " ====> " ^
- String.concat "," (List.map string_of_int restrictions));
-*)
- let metasenv, subst, newmeta =
- restrict metasenv subst i restrictions
- in
+ String.concat "," (List.map string_of_int restrictions)
+ ^ "\nMENV:\n" ^ NCicPp.ppmetasenv ~subst metasenv
+ ^ "\nSUBST:\n" ^ NCicPp.ppsubst subst ~metasenv
+ );
+ let newlc =
+ assert (if shift1 > k then shift1 + low_gap - shift = 0 else
+ true);
+ NCic.Irl (len1 - low_gap - high_gap + max 0 (k - shift1)) in
let meta =
- NCic.Meta(newmeta,(k,NCic.Irl (len - low_gap - high_gap)))
+ NCic.Meta(newmeta,(shift1 + low_gap - shift, newlc))
in
- (metasenv, subst), meta
+ (metasenv, subst), meta
| NCic.Irl _, NCic.Irl _ when shift = 0 -> ms, orig
| NCic.Irl _, NCic.Irl _ ->
- ms, NCic.Meta (i, (shift1 - shift, lc1))
- | _ ->
+ ms, NCic.Meta (i, (max 0 (shift1 - shift), lc1))
+ | _ ->
let lc1 = NCicUtils.expand_local_context lc1 in
let rec deliftl tbr j ms = function
| [] -> ms, tbr, []