@@ -59,18 +59,23 @@ namespace tc {
5959 % This happens when the instance to be compiled comes from the context
6060 % Example: Goal exists (X : T1 -> T2), forall a, c (X a) -> ...
6161 % intros; eexists. (* In the context we have the instance `H: c (?X a)` *)
62- decompile-term-aux (tc.maybe-llam-tm (app[app[H | PF] | NPF]) S) A Z (pr XS' [NL | L3]) :- !,
63- var H _ Scope, !,
64- std.append Scope S S',
65- prune Z S',
66- tc.compile.goal.make-pairs [T] Pairs,
67- % We build on the fly the eta-links for T
68- Pairs =>
69- (tc.compile.goal.build-eta-links-of-vars [T] P,
70- tc.compile.goal.get-uva-pair-arity T PF Y),
71- std.fold-map NPF A decompile-term-aux Tl (pr XS' L2),
72- std.append P L2 L3,
73- NL = tc.link.llam Z (app [Y|Tl]).
62+ decompile-term-aux (tc.maybe-llam-tm (app[app[V | PF] | NPF] as T) S_) L G'' (pr XS' L'') :- !,
63+ var V _ Scope, !,
64+ std.fold-map NPF L decompile-term-aux NPF' (pr XS' L'),
65+ free-names T Names,
66+ coq.typecheck V Ty ok,
67+ tc.link.build-eta-llam-links V Scope Ty Names PF NPF' L' G' L'',
68+ prune G'' Names,
69+ var G'' G' Names.
70+
71+ % HO var when H is a hole appearing in the shelved goals
72+ decompile-term-aux (app [V|PF] as T) (pr XS' L') G'' (pr XS' L'') :-
73+ var V _ Scope, !,
74+ free-names T Names,
75+ coq.typecheck V Ty ok,
76+ tc.link.build-eta-llam-links V Scope Ty Names PF [] L' G' L'',
77+ prune G'' Names,
78+ var G'' G' Names.
7479
7580 decompile-term-aux (fun Name Ty Bo) (pr XS L) (fun Name Ty' Bo') (pr XS2 L3) :- !,
7681 (pi x\ is-name x => decompile-term-aux (Bo x) (pr XS []) (Bo' x) (pr XS1 (L1x x))),
@@ -96,21 +101,6 @@ namespace tc {
96101 std.assert! (name-pair H V Len) "[TC] name-pair not found",
97102 name R V L.
98103
99- % HO var when H is a hole appearing in the shelved goals
100- decompile-term-aux (app [T|L]) (pr A B) Z (pr A B') :-
101- var T _ Scope,
102- std.forall L is-name, % Not needed, since decompile for llam leaves only PF
103- distinct_names L, !, % Not needed, since decompile for llam leaves only PF
104- std.append Scope L Scope',
105- prune Z Scope',
106- tc.compile.goal.make-pairs [T] Pairs,
107- % We build on the fly the eta-links for `T`
108- Pairs =>
109- (tc.compile.goal.build-eta-links-of-vars [T] P,
110- tc.compile.goal.get-uva-pair-arity T L Y),
111- var Z Y Scope',
112- std.append P B B'.
113-
114104 decompile-term-aux (app L) PR (app L') PR' :- !,
115105 std.fold-map L PR decompile-term-aux L' PR'.
116106
@@ -174,10 +164,10 @@ namespace tc {
174164 o:prop, % Link : The new eta-link
175165 o:term, % Ty' : The cleaned version of the binder in Ty
176166 o:(term -> term). % Bo : the body of the type of A
177- make-eta-link-aux A (prod _ Ty Bo) (pr B Name ) L Link Ty' Bo :- !,
167+ make-eta-link-aux A (prod _ Ty Bo) (pr B Name_ ) L Link Ty' Bo :- !,
178168 clean-term Ty Ty',
179169 name A' A {std.rev L},
180- Link = tc.link.eta A' (fun Name Ty' B'),
170+ Link = tc.link.eta A' (fun `_` Ty' B'),
181171 pi x\ sigma L'\ std.rev [x|L] L', name (B' x) B L'.
182172 % Going under prod-range
183173 make-eta-link-aux A (tc.prod-range Prod _) BN L Link Ty' Bo :- !,
@@ -313,129 +303,5 @@ namespace tc {
313303 instance-gr InstGR Clause :-
314304 coq.env.typeof InstGR Ty,
315305 tc.compile.instance Ty (global InstGR) Clause.
316-
317- namespace goal {
318- % [uvar-pair V1 Ty V2] List of uvar for link-eta-dedup
319- % V1 has arity n and V2 has arity n+1
320- % If V1 has type A -> B, then A = Ty
321- pred uvar-pair i:term, o:term, o:term.
322-
323- % Type Var Cnt uvar-pair-list
324- pred make-pairs-aux i:term, i:term, o:list prop.
325- make-pairs-aux Ty (fun _ _ IBo) L' :- !,
326- pi x\ make-pairs-aux Ty (IBo x) (L x), close-prop-no-prune L L'.
327- make-pairs-aux (prod _ Ty Bo) V [pi x\ uvar-pair x Ty X' :- x == V, ! | L] :- !,
328- pi x\ make-pairs-aux (Bo x) X' L.
329- make-pairs-aux _ _ [].
330-
331- pred make-pairs i:list term, o:list prop.
332- make-pairs [] [] :- !.
333- make-pairs [X|Xs] L :- !,
334- coq.typecheck X Ty ok,
335- make-pairs-aux Ty X L',
336- make-pairs Xs L'',
337- std.append L' L'' L.
338-
339- pred get-uva-pair-arity i:term, i:list term, o:term.
340- get-uva-pair-arity X [] X :- !.
341- get-uva-pair-arity X [_|L] Z :- uvar-pair X _ Y, !,
342- get-uva-pair-arity Y L Z.
343-
344- pred decompile-problematic-term i:term, i:list prop, o:term, o:list prop.
345- % there is no need to decompile T since no precompilation is done inside coercions
346- decompile-problematic-term (tc.coercion T S) L1 Y [tc.link.cs Y T|L1] :- !,
347- prune Y S.
348- % there is no need to decompile T since no precompilation is done inside CS
349- decompile-problematic-term (tc.canonical-projection T S _) L1 Y [tc.link.cs Y T|L1] :- !,
350- prune Y S.
351-
352- decompile-problematic-term (tc.maybe-eta-tm T S) L V [tc.link.eta V T' | L2] :- !,
353- prune V S, decompile-problematic-term T L T' L2.
354-
355- decompile-problematic-term (tc.prod-range T _) A T' A' :- !,
356- decompile-problematic-term T A T' A'.
357-
358- decompile-problematic-term (tc.maybe-llam-tm (app [app[H|S] | NPF]) Sc) L Z [NL|L'] :- !,
359- prune Z Sc,
360- get-uva-pair-arity H S Y,
361- std.fold-map NPF L decompile-problematic-term Tl L',
362- NL = tc.link.llam Z (app[Y | Tl]).
363-
364- decompile-problematic-term (app[X|S]) L Z L :-
365- var X _ Scope,
366- std.append Scope S Scope',
367- distinct_names Scope', !,
368- get-uva-pair-arity X S Y,
369- prune Z Scope', var Z Y Scope'.
370-
371- decompile-problematic-term (fun N Ty Bo) L (fun N Ty' Bo') L3 :- !,
372- (pi x\ decompile-problematic-term (Bo x) [] (Bo' x) (Lx x)),
373- close-term-no-prune-ty Lx {tc.compile.instance.clean-term Ty} L1,
374- decompile-problematic-term Ty L Ty' L2,
375- std.append L2 L1 L3.
376-
377- decompile-problematic-term (prod N Ty Bo) L (prod N Ty' Bo') L3 :- !,
378- (pi x\ decompile-problematic-term (Bo x) [] (Bo' x) (Lx x)),
379- close-term-no-prune-ty Lx {tc.compile.instance.clean-term Ty} L1,
380- decompile-problematic-term Ty L Ty' L2,
381- std.append L2 L1 L3.
382-
383- decompile-problematic-term (global _ as C) A C A :- !.
384- decompile-problematic-term (pglobal _ _ as C) A C A :- !.
385- decompile-problematic-term (sort _ as C) A C A :- !.
386- decompile-problematic-term (let N T B F) A (let N T1 B1 F1) A3 :- !,
387- decompile-problematic-term T A T1 A1, decompile-problematic-term B A1 B1 A2, pi x\ decompile-problematic-term (F x) A2 (F1 x) A3.
388- decompile-problematic-term (app L) A (app L1) A1 :- !, std.fold-map L A decompile-problematic-term L1 A1.
389- decompile-problematic-term (fix N Rno Ty F) A (fix N Rno Ty1 F1) A2 :- !,
390- decompile-problematic-term Ty A Ty1 A1, pi x\ decompile-problematic-term (F x) A1 (F1 x) A2.
391- decompile-problematic-term (match T Rty B) A (match T1 Rty1 B1) A3 :- !,
392- decompile-problematic-term T A T1 A1, decompile-problematic-term Rty A1 Rty1 A2, std.fold-map B A2 decompile-problematic-term B1 A3.
393- decompile-problematic-term (primitive _ as C) A C A :- !.
394- decompile-problematic-term (uvar _ _ as V) A V A :- !.
395- decompile-problematic-term X A Y A :- name X, !, X = Y, !.
396-
397- pred compile i:term, i:list prop, o:term, o:list prop.
398- compile T L T' L' :- decompile-problematic-term T L T' L'.
399-
400- % Uva Binders LinkEta
401- pred build-eta-links-of-vars-aux i:term, i:list term, o:list prop.
402- build-eta-links-of-vars-aux Old L [Hd | Xs] :-
403- uvar-pair Old Ty Next, !,
404- prune OldScope L,
405- prune Name L,
406- var OldScope Old L,
407- Hd = tc.link.eta OldScope (fun Name Ty (x\ NextScope x)),
408- pi x\ sigma L'\
409- std.append L [x] L',
410- prune (NextScope x) L',
411- var (NextScope x) Next L',
412- build-eta-links-of-vars-aux Next L' (Ys x), !,
413- sigma Closed\ (close-term-no-prune-ty Ys Ty Closed),
414- Xs = Closed.
415- build-eta-links-of-vars-aux _ _ [].
416-
417- pred build-eta-links-of-vars i:list term, o:list prop.
418- build-eta-links-of-vars [] [].
419- build-eta-links-of-vars [V|Vars] L :-
420- var V Hd S,
421- build-eta-links-of-vars-aux Hd S L',
422- build-eta-links-of-vars Vars L'',
423- std.append L' L'' L.
424- build-eta-links-of-vars [fun _ Ty Bo|Vars] L :-
425- (pi x\ build-eta-links-of-vars [Bo x] (L' x), close-term-no-prune-ty L' Ty L''),
426- build-eta-links-of-vars Vars L''',
427- std.append L'' L''' L.
428- }
429-
430- % Goal Goal' Links
431- pred goal i:term, o:term, o:list prop.
432- :name "compile-goal"
433- goal Goal Goal' Links :-
434- tc.precomp.goal Goal GoalPrecomp Vars, !,
435- goal.make-pairs Vars Pairs,
436- Pairs => (
437- std.assert!(goal.build-eta-links-of-vars Vars EtaLinks) "[TC] cannot build eta-links",
438- std.assert!(goal.compile GoalPrecomp EtaLinks Goal' Links) "[TC] cannot compile goal"
439- ).
440306 }
441307}
0 commit comments