Skip to content

Commit 92c1879

Browse files
authored
Merge pull request #656 from FissoreD/premise_with_solution
[TC] premise not run if rigid solution
2 parents ff14ff5 + 2e5ec9b commit 92c1879

File tree

2 files changed

+105
-13
lines changed

2 files changed

+105
-13
lines changed

apps/tc/elpi/tc_aux.elpi

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,23 +111,34 @@ namespace tc {
111111
get-mode ClassGR M :- tc.class ClassGR _ _ M, !.
112112
get-mode ClassGR _ :- coq.error "[TC]" ClassGR "is an unknown class".
113113

114-
pred make-tc.aux i:bool, i:prop, i:list prop, o:prop.
115-
make-tc.aux _ Head [] Head.
116-
make-tc.aux tt Head Body (Head :- Body).
117-
make-tc.aux ff Head Body (Body => Head).
114+
/*
115+
[make-tc.aux B Sol Head Body Rule] builds the rule with the given Head and body
116+
paying attention to the positivity of the
117+
clause
118+
Note: if the Rule being constructed is negative (B = ff), then Rules returns a
119+
solution Sol used inside the proof. If the solution is already given, we
120+
do not run the premise. This would ask Sol to be ground (ground_term S).
121+
Here, for performance issues, we simply check that the solution is not a
122+
flexible term
123+
*/
124+
pred make-tc.aux i:bool, i:term, i:prop, i:list prop, o:prop.
125+
make-tc.aux tt _ Head [] Head :- !.
126+
make-tc.aux ff Sol Head [] P :- !, P = if (var Sol) Head true.
127+
make-tc.aux tt _ Head Body (Head :- Body) :- !.
128+
make-tc.aux ff Sol Head Body P :- !, P = if (var Sol) (Body => Head) true.
118129

119130
pred make-tc i:term, i:term, i:list prop, i:bool, o:prop.
120-
make-tc Ty Inst Body IsPositive Clause :-
121-
coq.safe-dest-app Ty HD TL,
122-
get-TC-of-inst-type HD ClassGR,
131+
make-tc Goal Sol RuleBody IsPositive Rule :-
132+
coq.safe-dest-app Goal Class Args,
133+
get-TC-of-inst-type Class ClassGR,
123134
gref->pred-name ClassGR ClassStr,
124-
std.append TL [Inst] Args,
125-
coq.elpi.predicate ClassStr Args Head,
126-
make-tc.aux IsPositive Head Body Clause.
135+
std.append Args [Sol] ArgsSol,
136+
coq.elpi.predicate ClassStr ArgsSol RuleHead,
137+
make-tc.aux IsPositive Sol RuleHead RuleBody Rule.
127138

128-
pred unwrap-prio i:tc-priority, o:int.
129-
unwrap-prio (tc-priority-given Prio) Prio.
130-
unwrap-prio (tc-priority-computed Prio) Prio.
139+
pred unwrap-prio i:tc-priority, o:int.
140+
unwrap-prio (tc-priority-given Prio) Prio.
141+
unwrap-prio (tc-priority-computed Prio) Prio.
131142

132143
% returns the priority of an instance from the gref of an instance
133144
pred get-inst-prio i:gref, o:int.

apps/tc/tests/hyp_in_conl.v

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
From elpi.apps Require Import tc.
2+
3+
(*
4+
Here we want to test that if the solution of a premise is rigid
5+
then the premise is not run
6+
*)
7+
8+
Module M1.
9+
Structure ofe := Ofe { ofe_car : Type; }.
10+
11+
Class D (I : ofe).
12+
13+
Class C (X : ofe) (I : D X).
14+
15+
Definition ofe_nat : ofe := Ofe nat.
16+
17+
Instance c : forall (H : D (Ofe nat)), C ofe_nat H := {}.
18+
19+
Goal forall (H : D (Ofe nat)), True -> exists H, C (ofe_nat) H.
20+
intros.
21+
notypeclasses refine (ex_intro _ _ _ ).
22+
apply _.
23+
Qed.
24+
End M1.
25+
26+
Module M2.
27+
28+
Class A.
29+
Class B (I : A).
30+
Class C (A : A) (I : B A).
31+
32+
Instance c : forall (A : A) (B : B A), C A B := {}.
33+
34+
Goal forall (A : A) (B : B A), exists A B, C A B.
35+
intros.
36+
do 2 notypeclasses refine (ex_intro _ _ _ ).
37+
apply _.
38+
Qed.
39+
40+
End M2.
41+
42+
Module M3.
43+
44+
Class A.
45+
Class B (I : A).
46+
Class C (A : A) (I : B A).
47+
48+
Instance c : forall (A : A) (B : B A), C A B := {}.
49+
50+
Set Warnings "+elpi".
51+
52+
Section s.
53+
Elpi Accumulate TC.Solver lp:{{
54+
:before "0" tc-elpi.apps.tc.tests.hyp_in_conl.M3.tc-A _ :- coq.say "In tc-A", fail.
55+
:before "0" tc-elpi.apps.tc.tests.hyp_in_conl.M3.tc-B _ _ :- coq.say "In tc-B", fail.
56+
}}.
57+
Elpi Typecheck TC.Solver.
58+
Local Instance AX : A := {}.
59+
Local Instance BX : A -> (B AX) := {}.
60+
61+
Definition d : C AX (BX _) := _.
62+
Definition d' : C _ (BX _) := _.
63+
Definition d'' : C AX _ := _.
64+
65+
Check (c _ _) : C AX _.
66+
67+
(*
68+
Here we give the solver a partial solution with a hole in it. This hole
69+
correspond to the premise of the typeclass B (an instance of A). Due to
70+
the var condition on the resolution of rule's premises, the premise of
71+
`C`, that is, `B X` is not solved since we have the partial solution `BX
72+
_`. (see: [here](https://github.com/LPCIC/coq-elpi/blob/889bd3fc16c31f35c850edf5a0df2f70ea9c655a/apps/tc/elpi/tc_aux.elpi#L124))
73+
*)
74+
Elpi Query TC.Solver lp:{{
75+
S = {{c AX (BX _)}},
76+
tc.solve-aux1 [] {{C _ _}} S.
77+
}}.
78+
79+
End s.
80+
81+
End M3.

0 commit comments

Comments
 (0)