Skip to content

Commit 6f9fb6d

Browse files
authored
Merge pull request #823 from LPCIC/lettify-master
Lettify master
2 parents 8d7bf06 + 9c5b6b5 commit 6f9fb6d

File tree

11 files changed

+1851
-1342
lines changed

11 files changed

+1851
-1342
lines changed

.github/workflows/nix-action-coq-8.20.yml

Lines changed: 600 additions & 491 deletions
Large diffs are not rendered by default.

.github/workflows/nix-action-coq-master.yml

Lines changed: 624 additions & 407 deletions
Large diffs are not rendered by default.

.github/workflows/nix-action-rocq-9.0.yml

Lines changed: 548 additions & 442 deletions
Large diffs are not rendered by default.

.nix/coq-nix-toolbox.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"b598891e5323d9e68fcb1c2483c2e0a046e6de54"
1+
"0d640bae117cd64fd202e1453613d614b6e29aea"

apps/tc/elpi/ho_compile.elpi

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ namespace tc {
104104
decompile-term-aux (app L) PR (app L') PR' :- !,
105105
std.fold-map L PR decompile-term-aux L' PR'.
106106

107+
decompile-term-aux (let N T Ty Bo) PR (let N T' Ty' Bo') PR3 :- !,
108+
decompile-term-aux T PR T' PR1,
109+
decompile-term-aux Ty PR1 Ty' PR2,
110+
(pi x\ is-name x => decompile-term-aux (Bo x) PR2 (Bo' x) PR3).
111+
107112
decompile-term-aux A B _ _ :- coq.error "[TC] cannot decompile-term-aux of" A B.
108113

109114
pred decompile-term i:list term, o:list term, i:term, o:term, o:list prop.
@@ -244,6 +249,16 @@ namespace tc {
244249
decl p N Ty' =>
245250
name-pair p p z => E p => add-link-eta-dedup F Arity p Ty [] PremR (C p)
246251
].
252+
compile-ty L L1 ProofHd IsPositive (let _ Ty T Bo) ProofTlR PremR Clause :- !,
253+
if (IsPositive = tt)
254+
(Clause = (pi x\ C x), E = is-uvar)
255+
(clean-term Ty Ty', Clause = (pi x\ decl x N Ty' => C x), E = is-name),
256+
pi p\ sigma F NewPrem\
257+
(decl p N Ty' :- !) => (E p :- !) => (
258+
NewPrem = tc.link.unif-eq T p,
259+
compile-premise L L1 p Ty ProofHd IsPositive (Bo p) ProofTlR [NewPrem | PremR] (C p)
260+
).
261+
247262
compile-ty L L2 ProofHd IsPositive Goal ProofTlR PremR Clause :-
248263
std.do![
249264
coq.mk-app ProofHd {std.rev ProofTlR} Proof,

apps/tc/elpi/ho_link.elpi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ namespace tc {
130130
}
131131
}
132132

133+
namespace unif-eq {
134+
pred unif-eq i:term, i:term.
135+
unif-eq T1 (uvar as T2) :- !, declare_constraint (unif-eq T1 T2) [_,T2].
136+
unif-eq T1 T2 :- !, coq.unify-eq T1 T2 ok.
137+
}
138+
139+
pred unif-eq i:term, i:term.
140+
unif-eq T1 T2 :- unif-eq.unif-eq T1 T2.
141+
142+
133143
pred eta i:term, i:term.
134144
eta A B :- eta.eta A B.
135145

apps/tc/elpi/ho_precompile.elpi

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ namespace tc {
9494
get-range-arity-aux _ uvar @max-min :- !.
9595
get-range-arity-aux _ (sort _) @max-min :- !.
9696
get-range-arity-aux _ (pglobal _ _) @max-min :- !.
97+
get-range-arity-aux X (let _ T Ty B) R4 :- !,
98+
get-range-arity-aux X Ty R1,
99+
get-range-arity-aux X T R2,
100+
(pi x\ get-range-arity-aux T (B x) R3),
101+
min-max-nat R1 R2 R12,
102+
min-max-nat R12 R3 R4.
97103
get-range-arity-aux A B _ :- coq.error "Count maximal arity failure" A B.
98104

99105
pred get-range-arity i:term, i:term, i:term, o:range-arity.
@@ -130,11 +136,17 @@ namespace tc {
130136

131137
% Working with fun
132138
precompile-aux _ (fun N T F) A (fun N T1 F1) A2 :- !,
133-
precompile-aux _ T A T1 A1, pi x\ is-name x => precompile-aux is_neg_fix (F x) A1 (F1 x) A2.
139+
precompile-aux is_neg_fix T A T1 A1, pi x\ is-name x => precompile-aux is_neg_fix (F x) A1 (F1 x) A2.
134140

135141
precompile-aux _ (app L) A (app L1) A1 :- !, std.fold-map L A (precompile-aux is_neg_fix) L1 A1.
136142
precompile-aux _ X A X A :- var X, !.
137143

144+
precompile-aux _ (let N T Ty Bo) A (let N T' Ty' Bo') A3 :- !,
145+
precompile-aux is_neg_fix T A T' A1,
146+
precompile-aux is_neg_fix Ty A1 Ty' A2,
147+
pi x\ is-name x => precompile-aux is_neg_fix (Bo x) A2 (Bo' x) A3.
148+
149+
138150
% TODO: what about the following constructors?
139151
% precompile-aux IsP (let N T B F) A (let N T1 B1 F1) A3 :- !,
140152
% precompile-aux IsP T A T1 A1, precompile-aux IsP B A1 B1 A2, pi x\ is-name x => precompile-aux IsP (F x) A2 (F1 x) A3.

apps/tc/elpi/tc_aux.elpi

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,29 @@
33

44
namespace tc {
55

6+
namespace lettify {
7+
func replace-args term, list term, list term, (func term -> term) -> term.
8+
replace-args Hd [] L K R :- std.rev L L1, K (app [Hd|L1]) R.
9+
replace-args Hd [X|Xs] L K (let `_` Ty X T') :-
10+
coq.typecheck X Ty ok,
11+
pi x\ replace-args Hd Xs [x|L] K (T' x).
12+
13+
func replace-top-level list term, term, list term -> term.
14+
replace-top-level [] Hd L (app [Hd | L']) :- std.rev L L'.
15+
replace-top-level [app[X|Xs]|As] Hd L R :-
16+
replace-args X Xs [] (x\ replace-top-level As Hd [x|L]) R.
17+
replace-top-level [(fun _ _ _ as A)|As] Hd L (let `_` Ty A T') :-
18+
coq.typecheck A Ty ok,
19+
pi x\ replace-top-level As Hd [x|L] (T' x).
20+
21+
func main term -> term.
22+
main (prod N Ty Bo) (prod N Ty Bo') :- !,
23+
pi x\ main (Bo x) (Bo' x).
24+
main (app [X|Xs]) T :- is-instance-term X, !,
25+
replace-top-level Xs X [] T.
26+
main T T.
27+
}
28+
629
% return if a gref is an existsing instance
730
% TODO: this could be replaced with an API
831
% coq.TC.get-class-of-inst i:gref, o:gref
@@ -29,6 +52,8 @@ namespace tc {
2952
pred get-TC-of-inst-type i:term, o:gref.
3053
get-TC-of-inst-type (prod _ _ A) ClassGR:- !,
3154
pi x\ get-TC-of-inst-type (A x) ClassGR.
55+
get-TC-of-inst-type (let _ _ _ A) ClassGR:- !,
56+
pi x\ get-TC-of-inst-type (A x) ClassGR.
3257
get-TC-of-inst-type T ClassGR :-
3358
coq.safe-dest-app T HD _,
3459
not (var HD), class-gref HD ClassGR.

apps/tc/tests/multi_var.v

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
From elpi Require Import elpi tc.
2+
3+
Class C (T : Type) : Type := {}.
4+
Axiom t : forall n m : nat, Type.
5+
6+
Instance tC (n : nat) : C (t n n). Qed.
7+
Set Printing All.
8+
Goal C (t 0 0). apply _. Qed.
9+
10+
Instance tC1 (n : nat) : let n' := n in C (t n n'). Qed.
11+
12+
Goal C (t 0 (id 0)). apply _. Qed.
13+
14+
(* Elpi Print TC.Solver "elpi.apps.tc.examples/TC.Solver". *)

apps/tc/tests/out/out.v

Whitespace-only changes.

0 commit comments

Comments
 (0)