@@ -67,8 +67,7 @@ namespace tc {
6767 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6868 namespace eta {
6969 pred eta-expand i:term, o:term.
70- eta-expand T1 (fun _ _ B) :- (name T1; is-coq-term T1), !, pi x\ coq.mk-app T1 [x] (B x).
71- eta-expand T1 (fun _ _ R) :- pi x\ name (R x) T1 [x].
70+ eta-expand T1 (fun _ _ B) :- pi x\ coq.mk-app T1 [x] (B x).
7271
7372 :index (_ _ 1)
7473 pred may-contract-to i:list term, i:term, i:term.
@@ -107,14 +106,12 @@ namespace tc {
107106 unify-left-right A A' :- A = A'.
108107
109108 pred progress-eta-left i:term, o:term.
110- progress-eta-left (uvar _) _ :- !, fail.
111- progress-eta-left (fun _ _ A) (fun _ _ A).
112- progress-eta-left A A' :- (name A; is-coq-term A), !, eta-expand A A'.
109+ progress-eta-left (fun _ _ _ as A) B :- !, A = B.
110+ progress-eta-left A B :- eta-expand A A', !, A' = B.
113111
114- pred progress-eta-right i:term, o:term.
115- progress-eta-right (fun _ _ B as T) T :- pi x\ var (B x), !, fail.
116- progress-eta-right A A' :- coq.reduction.eta-contract A A', not (A = A'), !.
117- progress-eta-right A A :- not (maybe-eta A), !.
112+ pred progress-eta-right? i:term, o:term.
113+ progress-eta-right? A A' :- coq.reduction.eta-contract A A', not (A = A'), !.
114+ progress-eta-right? A A :- not (maybe-eta A), !.
118115
119116 pred scope-check i:term, i:term.
120117 scope-check (uvar _ L) T :- prune A L, A = T, !.
@@ -140,8 +137,8 @@ namespace tc {
140137 pred eta i:term, i:term, i:list term.
141138 eta _ uvar _ :- coq.error "[TC] link.eta error, flexible rhs".
142139 eta A (fun _ _ B as T) _ :- not (var A), not (var B), !, unify-left-right A T.
143- eta A B _ :- progress-eta-right B B ', !, A = B '.
144- eta A B _ :- progress-eta-left A A' , !, A' = B.
140+ eta A (fun _ _ B as T) _ :- not (var (B _)), progress-eta-right? T T ', !, A = T '.
141+ eta A B _ :- not (var A) , !, progress-eta-left A B.
145142 eta (uvar _ as A) B Vars :-
146143 scope-check A B, std.filter Vars (x\ var x) Vars',
147144 declare_constraint (eta A B Vars') [_,A|Vars'].
@@ -199,10 +196,14 @@ namespace tc {
199196 tc.coercion-unify HD, !,
200197 get-vars T Vars, declare_constraint (cs V T) [_, V | Vars].
201198
202- cs (uvar _ as V) (app [HD | _ ] as T) :-
199+ cs (uvar _ as V) (app [HD | TL ] as T) :-
203200 if (HD = global (const Proj), tc.proj->record Proj Record)
204201 (reduce-cs V T Record Proj)
205- (coq.unify-eq V T ok), !.
202+ % Note: Below we cannot unify V and T since T may contain
203+ % deep projections which must be considered as problematic terms
204+ % To avoid the problem, we compile all subterms in TL, the probl
205+ % subterms are replaced with variables put into links
206+ (tc.compile.goal (app TL) (app TL') Links, do Links, V = app [HD|TL']), !.
206207 cs T1 T2 :- not (T2 = app _), !, coq.unify-eq T1 T2 ok.
207208
208209 pred unify-under-ctx i:list term, i:list term, i:term, i:term, i:term, i:term.
0 commit comments