Skip to content

Commit a306617

Browse files
committed
[TC] clean compile-conclusion predicate
1 parent dff0808 commit a306617

File tree

7 files changed

+31
-32
lines changed

7 files changed

+31
-32
lines changed

_opam

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/home/dfissore/Documents/github/COQ_ELPI_DEV/_opam

apps/tc/elpi/compile_instance.elpi

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,10 @@ namespace tc {
371371
pi x y\ name-pair P x (s N) => is-uvar x => add-link-eta-dedup F (r-ar M N) P PTy [pr x y|Acc] PremR (Clause x y).
372372
add-link-eta-dedup _ Ar P PTy _ _ _ :- coq.error "[TC] add-link-eta-dedup error" Ar P PTy.
373373

374+
pred deterministic-prem i:gref, i:prop, o:prop.
375+
deterministic-prem TC P (do-once P) :- tc.class TC _ tc.deterministic _, !.
376+
deterministic-prem _ P P.
377+
374378
pred compile-premise
375379
i:list term,
376380
o:list term,
@@ -382,16 +386,14 @@ namespace tc {
382386
i:list term,
383387
i:list prop,
384388
o:prop.
385-
compile-premise L L2 P PTy ProofHd IsPositive ITy ProofTlR PremR Clause :-
389+
compile-premise L L2 P PTy ProofHd IsPositive ITy ProofArgsR PremR Clause :-
386390
(pi a b c\ tc.get-TC-of-inst-type (tc.prod-range a c) b :- tc.get-TC-of-inst-type a b) =>
387391
tc.get-TC-of-inst-type PTy TC, !,
388392
compile-ty L L1 P {neg IsPositive} PTy [] [] NewPrem,
389-
if (tc.class TC _ tc.deterministic _)
390-
(NewPrem' = do-once NewPrem)
391-
(NewPrem' = NewPrem),
392-
compile-ty L1 L2 ProofHd IsPositive ITy ProofTlR [NewPrem' | PremR] Clause.
393-
compile-premise L L1 _ _ ProofHd IsPositive ITy ProofTlR PremR Clause :-
394-
compile-ty L L1 ProofHd IsPositive ITy ProofTlR PremR Clause.
393+
deterministic-prem TC NewPrem NewPrem',
394+
compile-ty L1 L2 ProofHd IsPositive ITy ProofArgsR [NewPrem' | PremR] Clause.
395+
compile-premise L L1 _ _ ProofHd IsPositive ITy ProofArgsR PremR Clause :-
396+
compile-ty L L1 ProofHd IsPositive ITy ProofArgsR PremR Clause.
395397

396398
pred compile-ty
397399
i:list term,
@@ -402,39 +404,38 @@ namespace tc {
402404
i:list term,
403405
i:list prop,
404406
o:prop.
405-
compile-ty L L1 ProofHd IsPositive (tc.prod-range (prod N Ty Bo) Arity) ProofTlR PremR Clause :- !,
407+
compile-ty L L1 ProofHd IsPositive (tc.prod-range (prod N Ty Bo) Arity) ProofArgsR PremR Clause :- !,
406408
std.do![
407409
if (IsPositive = tt)
408410
(Clause = (pi x\ C x), E = is-uvar)
409411
(clean-term Ty Ty', Clause = (pi x\ decl x N Ty' => C x), E = is-name),
410412
pi p\ sigma F\
411-
F = compile-premise L L1 p Ty ProofHd IsPositive (Bo p) [p|ProofTlR],
413+
F = compile-premise L L1 p Ty ProofHd IsPositive (Bo p) [p|ProofArgsR],
412414
decl p N Ty' =>
413415
name-pair p p z => E p => add-link-eta-dedup F Arity p Ty [] PremR (C p)
414416
].
415-
compile-ty L L2 ProofHd IsPositive Goal ProofTlR PremR Clause :-
417+
compile-ty L L2 ProofHd IsPositive Goal ProofArgsR PremR Clause :-
416418
std.do![
417-
coq.mk-app ProofHd {std.rev ProofTlR} Proof,
418-
decompile.decompile-term L L1 Proof Proof' Prem1,
419-
decompile.decompile-term L1 L2 Goal Goal' Prem2,
420-
compile-conclusion IsPositive Goal' Proof' Prem2 Prem1 {std.rev PremR} Clause
419+
coq.mk-app ProofHd {std.rev ProofArgsR} Proof,
420+
decompile.decompile-term L L1 Proof Proof' EmptyLinks,
421+
std.assert! (EmptyLinks = []) "[TC] should be empty",
422+
decompile.decompile-term L1 L2 Goal Goal' Links,
423+
compile-conclusion IsPositive Goal' Proof' Links {std.rev PremR} Clause
421424
].
422425

423426
pred compile-conclusion
424427
i:bool, % tt if the term is in positive position
425428
i:term, % the goal (invariant: it is a constant or a application)
426429
i:term, % the proof
427-
i:list prop, % the list of HOPremises in input mode
428-
i:list prop, % the list of HOPremises in output mode
430+
i:list prop, % the list of links
429431
i:list prop, % the premises
430432
o:prop. % the compiled clause for the instance
431433

432-
compile-conclusion tt Goal Proof HOPremisesIn HOPremisesOut Premises Clause :-
433-
std.append {std.append HOPremisesIn Premises} HOPremisesOut AllPremises,
434+
compile-conclusion tt Goal Proof Links Premises Clause :-
435+
std.append Links Premises AllPremises,
434436
tc.make-tc Goal Proof AllPremises tt Clause.
435-
compile-conclusion ff Goal Proof HOPremisesIn HOPremisesOut Premises Clause :-
436-
tc.make-tc Goal Proof Premises ff Clause1,
437-
Clause = (do HOPremisesIn, Clause1, do HOPremisesOut).
437+
compile-conclusion ff Goal Proof Links Premises (do Links, Clause) :-
438+
tc.make-tc Goal Proof Premises ff Clause.
438439

439440
pred context i:goal-ctx, o:list prop.
440441
context [] [].
@@ -465,9 +466,9 @@ namespace tc {
465466
% If the instance is polymorphic, we wrap its gref into the pglobal constructor
466467
instance-gr InstGR (pi x\ Clause x) :- coq.env.univpoly? InstGR _, !,
467468
coq.env.typeof InstGR Ty,
468-
pi x\ tc.compile.instance Ty (pglobal InstGR x) (Clause x).
469+
pi x\ instance Ty (pglobal InstGR x) (Clause x).
469470
instance-gr InstGR Clause :-
470471
coq.env.typeof InstGR Ty,
471-
tc.compile.instance Ty (global InstGR) Clause.
472+
instance Ty (global InstGR) Clause.
472473
}
473474
}

apps/tc/tests/test.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ Module test_link_eta_generation.
1717
Class d (T : Type) (T : Type -> Type -> Type -> Type).
1818
Elpi Accumulate TC.Solver lp:{{
1919
:after "0"
20-
tc.compile.instance.compile-conclusion _ (app [H|_]) _ _ _ Premises _ :-
20+
tc.compile.instance.compile-conclusion _ (app [H|_]) _ _ Premises _ :-
2121
H = {{test_link_eta_generation.c}}, !,
2222
std.assert! (Premises = [do [tc.link.eta _ _] | _]) "[TC] Wrong number of eta links",
2323
coq.say "Good padding from here",
2424
fail.
2525
}}.
2626
Elpi Query TC.Solver lp:{{
2727
ToCompile = {{forall (T : Type -> Type -> Type -> Type), (forall (a: Type), d a T) -> c T}},
28-
not (tc.compile.instance ToCompile _ _).
28+
pi x\ not (tc.compile.instance ToCompile x _).
2929
}}.
3030
End test_link_eta_generation.
3131

apps/tc/tests/test_HO.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ Module HO_PF1.
200200
Proof.
201201
eexists; intros.
202202
Elpi Bound Steps 30000.
203-
Set Typeclasses Debug.
203+
(* Set Typeclasses Debug. *)
204204
apply _.
205205
Unshelve.
206206
auto.
@@ -321,7 +321,7 @@ Module F.
321321

322322
Goal forall (T : Type -> Type) (H : forall x, T x), C1 T H -> D.
323323
intros.
324-
Set Typeclasses Debug.
324+
(* Set Typeclasses Debug. *)
325325
Set Debug "tactic-unification".
326326
Elpi TC Solver Override TC.Solver None.
327327
Fail apply _. (* Here coq's unfication algorithm fails:

apps/tc/tests/test_backtrack_several_goals.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Module M.
1212

1313
Goal exists i, C i.
1414
eexists.
15-
Set Typeclasses Debug.
15+
(* Set Typeclasses Debug. *)
1616
(* Here backtracking is done *)
1717
apply m.
1818
Qed.
@@ -32,7 +32,7 @@ Module M1.
3232

3333
Goal exists i, C i.
3434
eexists.
35-
Set Typeclasses Debug.
35+
(* Set Typeclasses Debug. *)
3636
apply m.
3737
(*
3838
Note: in coq the following command fails since apply is a single entry

apps/tc/tests/test_scope.v

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ Goal C Q -> exists (T : Type -> Type), forall R, C R -> C (T).
1010
intros.
1111
Set Printing Existential Instances.
1212
assert (C Q) by auto.
13-
Elpi Trace Browser.
1413
apply _.
1514
Show Proof.
1615
Abort.

apps/tc/tests/test_tc.v

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
From elpi.apps Require Import tc.
22

3-
Elpi TC Solver Override TC.Solver All.
4-
53
Class a (N: nat).
64
Instance b : a 3. Qed.
75
Instance c : a 4. Qed.

0 commit comments

Comments
 (0)