Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
35dd241
[TC] primitive constructor for fold in instance (pre-)compilation
FissoreD Apr 8, 2025
4f60635
[TC] canonical proj solved with coq.unify-eq
FissoreD Jul 2, 2024
30de9b1
[TC] clean-term also for tc.canonical-projection
FissoreD Jul 3, 2024
caadc95
[TC] compilation of primitive projections to their compatibility cons…
FissoreD Jul 10, 2024
cdf26f9
Revert "[TC] compilation of primitive projections to their compatibil…
FissoreD Jul 10, 2024
de1dac5
[TC] put cnonical projection in tc namespace
FissoreD Jul 12, 2024
0ca09cd
remove reduntant calls to Elpi Typecheck
FissoreD Apr 8, 2025
8a5a53c
[TC] local binders in evar scope during precompile + link.cs
FissoreD Apr 8, 2025
ed1dda5
[TC] add TC.AddRecordFields command + better chr for canon struct
FissoreD Apr 8, 2025
b5ff427
[TC] mode ground with ground_term check + tc.link for coercions
FissoreD Aug 8, 2024
18eb74c
[TC] clean term in decompilation of goal
FissoreD Aug 8, 2024
1d67703
[TC] add file deps in tests/importOrder/sameOrderCommand.v
FissoreD Aug 8, 2024
f350695
[TC] perf: fold-map fully implemented in precompile goal
FissoreD Aug 8, 2024
ce0d03d
[TC] improve perf of goal compilation
FissoreD Aug 10, 2024
03f100f
[TC] remove goal precomp and goal compile (all is done in ycompile_go…
FissoreD Apr 8, 2025
bbb7fbb
[TC] refactor filenames + reorder import
FissoreD Aug 10, 2024
1b73a9a
[TC] refactor of build-eta-llam-links
FissoreD Aug 10, 2024
9f4894e
[TC] avoid a backtrack
FissoreD Aug 20, 2024
cbb7be1
[TC] clean compile-conclusion predicate
FissoreD Sep 19, 2024
9ed4495
[TC] link small refactor
FissoreD Aug 22, 2024
26e439d
[TC] clean link code + unification with cs links only after a call to…
FissoreD Sep 2, 2024
44c2565
add _opam to .gitignore
FissoreD Sep 3, 2024
dc2c915
[TC] clearn-term on pi-decl in decompile-term-aux
FissoreD Sep 3, 2024
a491a71
[TC] dummy clauses are local to sections
FissoreD Sep 19, 2024
9891625
[TC] add comment
FissoreD Sep 25, 2024
79c7251
[TC] move time-is-active and coercion-unify in db.v
FissoreD Sep 25, 2024
79ded6c
cleanup
gares Oct 2, 2024
17eb2bc
cleanup
gares Oct 2, 2024
37fd717
cleanup
gares Oct 2, 2024
5e19120
ci
gares Oct 2, 2024
cd6da58
[TC] fix
FissoreD Apr 8, 2025
363765f
[TC] base file loaded once
FissoreD Apr 8, 2025
733f3a2
[TC] add some doc to predicates
FissoreD Apr 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ on:
branches: [ master ]
pull_request:
branches: [ master ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
name: Build doc
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ on:
options:
- released
- extra-dev

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
OPAM_SUITE: ${{ inputs.suite }}

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,7 @@ rocq-elpi-tests.opam
rocq-elpi-tests.install
rocq-elpi.install
coq-elpi.install
_opam


theories-stdlib/dune
2 changes: 1 addition & 1 deletion apps/cs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The `cs` predicate lives in the database `cs.db`
pred cs i:goal-ctx, o:term, o:term.
```

By addings rules for this predicate one can recover from a CS instance search failure
By adding rules for this predicate one can recover from a CS instance search failure
error, that is when `Lhs` and `Rhs` are not unifiable using a canonical structure registered
by Coq.

Expand Down
131 changes: 0 additions & 131 deletions apps/tc/elpi/WIP/force_llam.elpi

This file was deleted.

44 changes: 0 additions & 44 deletions apps/tc/elpi/WIP/modes.elpi

This file was deleted.

42 changes: 17 additions & 25 deletions apps/tc/elpi/base.elpi
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,13 @@ split-at-not-fatal N [X|XS] [X|LN] LM :- !, N1 is N - 1,

pred undup-same i:list A, o:list A.
undup-same [] [].
undup-same [X|Xs] [X|Ys] :-
std.forall Xs (x\ not (x == X)), !,
undup-same Xs Ys.
undup-same [_|Xs] Ys :- undup-same Xs Ys.
undup-same [X|Xs] Ys :- std.exists Xs (x\ x == X), !, undup-same Xs Ys.
undup-same [X|Xs] [X|Ys] :- undup-same Xs Ys.

pred undup i:list A, o:list A.
undup [] [].
undup [X|Xs] Ys :- std.mem! Xs X, !, undup Xs Ys.
undup [X|Xs] [X|Ys] :- undup Xs Ys.

:index (1)
pred is-coq-term i:any.
Expand Down Expand Up @@ -142,24 +145,13 @@ pred count-prod i:term , o:nat.
count-prod (prod _ _ B) (s N) :- !, pi x\ count-prod (B x) N.
count-prod _ z.

pred close-prop i:(A -> list prop), o:list prop.
close-prop (x\ []) [] :- !.
close-prop (x\ [X | Xs x]) [X| Xs'] :- !, close-prop Xs Xs'.
close-prop (x\ [X x | Xs x]) [pi x\ X x | Xs'] :- !, close-prop Xs Xs'.

pred close-prop-no-prune i:(A -> list prop), o:list prop.
close-prop-no-prune (x\ []) [] :- !.
close-prop-no-prune (x\ [X x | Xs x]) [pi x\ X x | Xs'] :- !,
close-prop-no-prune Xs Xs'.

% [close-term-ty (x\ L) Ty R] Ty is the type of x
pred close-term-ty i:(term -> list prop), i:term, o:list prop.
close-term-ty (x\ []) _ [] :- !.
close-term-ty (x\ [X | Xs x]) Ty [X| Xs'] :- !, close-term-ty Xs Ty Xs'.
close-term-ty (x\ [X x | Xs x]) Ty [@pi-decl `x` Ty x\ X x | Xs'] :- !,
close-term-ty Xs Ty Xs'.

pred close-term-no-prune-ty i:(term -> list prop), i:term, o:list prop.
close-term-no-prune-ty (x\ []) _ [] :- !.
close-term-no-prune-ty (x\ [X x | Xs x]) Ty [@pi-decl `x` Ty x\ X x | Xs'] :- !,
close-term-no-prune-ty Xs Ty Xs'.
pred close-prop-no-prune-pi-decl i:(term -> list prop), i:term, o:list prop.
close-prop-no-prune-pi-decl (x\ []) _ [] :- !.
close-prop-no-prune-pi-decl (x\ [X x | Xs x]) Ty [@pi-decl `x` Ty x\ X x | Xs'] :- !,
close-prop-no-prune-pi-decl Xs Ty Xs'.

pred free-names i:term, o:list term.
free-names T L :-
names N,
(pi T L\ fold-map T L T [T|L] :- name T, std.mem! N T, !) => fold-map T [] _ L',
undup {std.rev L'} L.
122 changes: 122 additions & 0 deletions apps/tc/elpi/compile_goal.elpi
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
namespace tc {
namespace compile {
namespace goal {
:index (_ _ 1)
pred may-contract-to i:list term, i:term, i:term.
may-contract-to _ N N :- !.
% TODO: here we should do var V _ Scope and use scope: N can be in Scope but not in S
may-contract-to L N (app [V|S]) :- var V, !,
std.forall [N|L] (x\ exists! S (may-contract-to [] x)).
may-contract-to L N (app [N|A]) :-
std.length A {std.length L},
std.forall2 {std.rev L} A (may-contract-to []).
may-contract-to L N (fun _ _ B) :-
pi x\ may-contract-to [x|L] N (B x).

:index (_ 1)
pred occurs-rigidly i:term, i:term.
occurs-rigidly N N :- name N, !.
occurs-rigidly _ (app [N|_]) :- var N, !, fail.
occurs-rigidly N (app A) :- exists! A (occurs-rigidly N).
occurs-rigidly N (fun _ _ B) :- pi x\ occurs-rigidly N (B x).

pred maybe-eta-aux i:term, i:list term.
% TODO: here we should do var V _ Scope and use Scope: an elt in L can appear in Scope
maybe-eta-aux (app[V|S]) L :- var V, !,
std.forall L (x\ exists! S (y\ may-contract-to [] x y)).
maybe-eta-aux (app [_|A]) L :-
SplitLen is {std.length A} - {std.length L},
split-at-not-fatal SplitLen A HD TL,
std.forall L (x\ not (exists! HD (occurs-rigidly x))),
std.forall2 {std.rev L} TL (may-contract-to []).
maybe-eta-aux (fun _ _ B) L :-
pi x\ maybe-eta-aux (B x) [x|L].

pred maybe-eta i:term.
maybe-eta (fun _ _ B) :- pi x\ maybe-eta-aux (B x) [x].

pred used i:term, i:term.
used X (uvar _ S) :- std.mem! S X, !.
used X (fun _ _ Bo) :- pi x\ used X (Bo x).

pred close-term-prune-safe-fun i:(term -> list term), i:term, o:list term.
close-term-prune-safe-fun (x\ []) _ [] :- !.
close-term-prune-safe-fun (x\ [X x | Xs x]) Ty [fun _ _ X | Xs'] :-
pi x\ used x (X x), !, close-term-prune-safe-fun Xs Ty Xs'.
close-term-prune-safe-fun (x\ [X | Xs x]) Ty [X | Xs'] :-
close-term-prune-safe-fun Xs Ty Xs'.

pred compile-full-aux-close i:(term -> term), i:term, i:list prop, o:(term -> term), o:list prop.
compile-full-aux-close Bo Ty L Bo' L' :-
(pi x\ compile-full-aux (Bo x) [] (Bo' x) (BoL x)),
% TODO: maybe attach to the links the list of used binders, to simply make this check?
% Maybe L' is a pair list links and list binders per link, this way we can easily prune
close-prop-no-prune-pi-decl BoL Ty BoL',
std.append L BoL' L'.

pred compile-full-aux i:term, i:list prop, o:term, o:list prop.
compile-full-aux (global _ as G) L G L :- !.
compile-full-aux (pglobal _ _ as G) L G L :- !.
compile-full-aux (sort _ as G) L G L :- !.

% Link for coercion
compile-full-aux (app [HD|_] as G) L G' [tc.link.cs G' G | L] :- tc.coercion-unify HD, !.

% Link for canonical structure
compile-full-aux (app [global (const C) | _] as G) L G' [tc.link.cs G' G | L] :- coq.env.projection? C _, !.

% Link for primitive projection
compile-full-aux (app [primitive (proj P _) | _] as G) L G' [tc.link.cs G' G | L] :- coq.env.primitive-projection? P _ _, !.

% Link for eta-redex
compile-full-aux (fun Name_ Ty Bo as G) L G' [tc.link.eta G' (fun `_` Ty' Bo') | L'] :- maybe-eta G, !,
compile-full-aux Ty L Ty' LTy,
compile-full-aux-close Bo Ty LTy Bo' L'.

compile-full-aux (fun Name Ty Bo) L (fun Name Ty' Bo') L' :- !,
compile-full-aux Ty L Ty' LTy,
compile-full-aux-close Bo Ty LTy Bo' L'.

compile-full-aux (prod Name Ty Bo) L (prod Name Ty' Bo') L' :- !,
compile-full-aux Ty L Ty' LTy,
compile-full-aux-close Bo Ty LTy Bo' L'.

% TODO: to avoid too many chain for the same var, maybe pass a list into the fold
compile-full-aux (app [(uvar _ _ as V) | S]) L G' L'' :- !,
std.fold-map S L compile-full-aux S' L', % L' = Links built for S
tc.link.build-eta-llam-links (app [V|S']) L' G' L''.

compile-full-aux (app L) A (app L1) A1 :- !, std.fold-map L A compile-full-aux L1 A1.

compile-full-aux (let N T B F) A (let N T1 B1 F1) A3 :- !,
compile-full-aux T A T1 A1, compile-full-aux B A1 B1 A2,
compile-full-aux-close F T A2 F1 A3.

compile-full-aux (fix N Rno Ty F) A (fix N Rno Ty1 F1) A2 :- !,
compile-full-aux Ty A Ty1 A1,
compile-full-aux-close F Ty A1 F1 A2.

compile-full-aux (match T Rty B) A (match T1 Rty1 B1) A3 :- !,
compile-full-aux T A T1 A1,
compile-full-aux Rty A1 Rty1 A2,
std.fold-map B A2 compile-full-aux B1 A3.

compile-full-aux (uvar _ _ as X) A X A :- !.
compile-full-aux X A X A :- name X, !.

compile-full-aux A B _ _ :- coq.error "Fail to compile-full-aux" A B.

% takes a term t and returns a term t' and a list of links.
pred compile-full i:term, o:term, o:list prop.
compile-full Goal Goal' Links :- compile-full-aux Goal [] Goal' Links.
}

% [goal T T' L] takes a term T and returns a new term T' where problematic
% subterms (see this: https://dl.acm.org/doi/10.1145/3678232.3678233)
% are replaced with fresh variables. The list of links is L
pred goal i:term, o:term, o:list prop.
:name "compile-goal"
goal Goal Goal' Links :-
goal.compile-full-aux Goal [] Goal' Links.
}
}
Loading
Loading