e: B.lenv; (* environment *)
s: (B.lenv * B.term) list; (* stack *)
l: int; (* level *)
- d: int; (* inferred type iterations *)
n: int option; (* expected type iterations *)
}
aux_bind f (b1, b2)
| _ -> err ()
and aux_bind f = function
- | B.Abbr v1, B.Abbr v2 -> aux f (v1, v2)
- | B.Abst (n1, v1), B.Abst (n2, v2) when n1 = n2 -> aux f (v1, v2)
- | B.Void, B.Void -> f ()
- | _ -> err ()
+ | B.Abbr v1, B.Abbr v2 -> aux f (v1, v2)
+ | B.Abst (x1, n1, v1), B.Abst (x2, n2, v2) when x1 = x2 && n1 = n2 -> aux f (v1, v2)
+ | B.Void, B.Void -> f ()
+ | _ -> err ()
in
if S.eq t1 t2 then f () else aux f (t1, t2)
let assert_tstep m vo = match m.n with
- | Some n -> n > m.d
+ | Some n -> n > 0
| None -> vo
-let tstep m = {m with d = succ m.d}
+let tstep m = match m.n with
+ | Some n -> {m with n = Some (pred n)}
+ | None -> m
let tsteps m = match m.n with
- | Some n when n > m.d -> n - m.d
- | _ -> 0
+ | Some n -> n
+ | None -> 0
let get m i =
let _, c, a, b = B.get m.e i in c, a, b
(* to share *)
-let rec step st m x =
+let rec step st m r =
if !G.trace >= sublevel then
- log1 st (Printf.sprintf "entering R.step: l:%u d:%i n:%s" m.l m.d (match m.n with Some n -> string_of_int n | None -> "infinite")) m.e x;
- match x with
- | B.Sort (a, h) ->
+ log1 st (Printf.sprintf "entering R.step: l:%u n:%s" m.l (match m.n with Some n -> string_of_int n | None -> "infinite")) m.e r;
+ match r with
+ | B.Sort (a, h) ->
if assert_tstep m false then
step st (tstep m) (B.Sort (a, H.apply h))
- else m, x, None
- | B.GRef (_, uri) ->
+ else m, r, None
+ | B.GRef (_, uri) ->
begin match BE.get_entity uri with
| _, _, _, E.Abbr v ->
if m.n = None || !G.expand then begin
if !G.summary then O.add ~gdelta:1 ();
step st m v
end else
- m, x, Some v
+ m, r, Some v
| _, _, _, E.Abst w ->
if assert_tstep m true then begin
if !G.summary then O.add ~grt:1 ();
step st (tstep m) w
end else
- m, x, None
+ m, r, None
| _, _, _, E.Void ->
assert false
end
- | B.LRef (_, i) ->
+ | B.LRef (_, i) ->
begin match get m i with
- | c, _, B.Abbr v ->
+ | c, _, B.Abbr v ->
if !G.summary then O.add ~ldelta:1 ();
step st {m with e = c} v
- | c, a, B.Abst (_, w) ->
+ | c, a, B.Abst (_, _, w) ->
if assert_tstep m true then begin
if !G.summary then O.add ~lrt:1 ();
step st {(tstep m) with e = c} w
end else
m, B.LRef (a, i), None
- | _, _, B.Void ->
+ | _, _, B.Void ->
assert false
end
- | B.Cast (_, u, t) ->
+ | B.Cast (_, u, t) ->
if assert_tstep m false then begin
if !G.summary then O.add ~e:1 ();
step st (tstep m) u
if !G.summary then O.add ~epsilon:1 ();
step st m t
end
- | B.Appl (_, v, t) ->
+ | B.Appl (_, v, t) ->
step st {m with s = (m.e, v) :: m.s} t
- | B.Bind (a, B.Abst (n, w), t) ->
+ | B.Bind (a, B.Abst (false, n, w), t) ->
let i = tsteps m in
+ if !G.summary then O.add ~x:i ();
let n = if i = 0 then n else N.minus st n i in
+ let r = B.Bind (a, B.Abst (true, n, w), t) in
+ step st m r
+ | B.Bind (a, B.Abst (true, n, w), t) ->
if !G.si || N.is_not_zero st n then begin match m.s with
| [] ->
- if i = 0 then m, x, None else
- m, B.Bind (a, B.Abst (n, w), t), None
+ m, B.Bind (a, B.Abst (true, n, w), t), None
| (c, v) :: s ->
+(*
if !G.cc && not (N.assert_not_zero st n) then assert false;
+*)
if !G.summary then O.add ~beta:1 ~theta:(List.length s) ();
- let v = if assert_tstep m false then B.Cast (E.empty_node, w, v) else v in
+ let v = B.Cast (E.empty_node, w, v) in
let e = B.push m.e c a (B.abbr v) in
step st {m with e = e; s = s} t
end else begin
if !G.summary then O.add ~upsilon:1 ();
- let e = B.push m.e m.e a B.Void in
+ let e = B.push m.e m.e a B.Void in (**) (* this is wrong in general *)
step st {m with e = e} t
end
| B.Bind (a, b, t) ->
let e = B.push m.e m.e a b in
step st {m with e = e} t
-let reset m ?(e=m.e) n =
- {m with e = e; n = n; s = []; d = 0}
+let assert_iterations m1 m2 =
+ m1.n = m2.n
-let assert_iterations m1 m2 = match m1.n, m2.n with
- | Some n1, Some n2 -> n1 - m1.d = n2 - m2.d
- | _ -> false
+let reset m ?(e=m.e) n =
+ {m with e = e; n = n; s = []}
let push m a b =
let a, l = match b with
let rec ac_nfs st (m1, t1, r1) (m2, t2, r2) =
if !G.trace >= level then log2 st "Now converting nfs" m1.e t1 m2.e t2;
match t1, r1, t2, r2 with
- | B.Sort (_, h1), _, B.Sort (_, h2), _ ->
+ | B.Sort (_, h1), _, B.Sort (_, h2), _ ->
h1 = h2
| B.LRef ({E.n_apix = e1}, _), _,
- B.LRef ({E.n_apix = e2}, _), _ ->
+ B.LRef ({E.n_apix = e2}, _), _ ->
if e1 = e2 then ac_stacks st m1 m2 else false
| B.GRef (_, u1), None, B.GRef (_, u2), None ->
if U.eq u1 u2 && assert_iterations m1 m2 then ac_stacks st m1 m2 else false
| B.GRef ({E.n_apix = e1}, u1), Some v1,
- B.GRef ({E.n_apix = e2}, u2), Some v2 ->
+ B.GRef ({E.n_apix = e2}, u2), Some v2 ->
if e1 < e2 then begin
if !G.summary then O.add ~gdelta:1 ();
ac_nfs st (m1, t1, r1) (step st m2 v2)
if !G.summary then O.add ~gdelta:2 ();
ac st m1 v1 m2 v2
end
- | _, _, B.GRef _, Some v2 ->
+ | _, _, B.GRef _, Some v2 ->
if !G.summary then O.add ~gdelta:1 ();
ac_nfs st (m1, t1, r1) (step st m2 v2)
- | B.GRef _, Some v1, _, _ ->
+ | B.GRef _, Some v1, _, _ ->
if !G.summary then O.add ~gdelta:1 ();
ac_nfs st (step st m1 v1) (m2, t2, r2)
- | B.Bind (a1, (B.Abst (n1, w1) as b1), t1), _,
- B.Bind (a2, (B.Abst (n2, w2) as b2), t2), _ ->
+ | B.Bind (a1, (B.Abst (true, n1, w1) as b1), t1), _,
+ B.Bind (a2, (B.Abst (true, n2, w2) as b2), t2), _ ->
if ((!G.cc && N.assert_equal st n1 n2) || N.are_equal st n1 n2) &&
ac st (reset m1 zero) w1 (reset m2 zero) w2
then ac st (push m1 a1 b1) t1 (push m2 a2 b2) t2
else false
- | B.Sort _, _, B.Bind (a, B.Abst (n, _), t), _ ->
+ | B.Sort _, _, B.Bind (a, B.Abst (true, n, _), t), _ ->
if !G.si then
if !G.cc && not (N.assert_zero st n) then false else begin
if !G.summary then O.add ~upsilon:1 ();
ac st (push m1 a B.Void) t1 (push m2 a B.Void) t end
else false
- | _ -> false
+ | _ -> false
and ac st m1 t1 m2 t2 =
(* L.warn "entering R.are_convertible"; *)
(* Interface functions ******************************************************)
let empty_rtm = {
- e = B.empty; s = []; l = 0; d = 0; n = None
+ e = B.empty; s = []; l = 0; n = None
}
let get m i =