Skip to content

Commit

Permalink
auto_compiler in tc.v
Browse files Browse the repository at this point in the history
  • Loading branch information
FissoreD committed Oct 26, 2023
1 parent 4af2a2e commit 6905031
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 56 deletions.
14 changes: 3 additions & 11 deletions apps/tc/elpi/compiler.elpi
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,6 @@ has-context-deps GR :-
pred is-local.
is-local :- std.mem {attributes} (attribute "local" _).

pred make-inst-graft i:gref, i:bool, o:grafting.
make-inst-graft Inst _NoPremises (after Grafting) :-
RawGrafting is int_to_string {get-inst-prio Inst},
% if (NoPremises = tt) (Grafting = RawGrafting) (Grafting is RawGrafting ^ "_complex").
Grafting = RawGrafting.

pred get-locality i:string, o:list prop.
get-locality "Local" [@local!].
get-locality _ [@local!] :- coq.env.current-section-path [_ | _].
Expand All @@ -166,9 +160,7 @@ add-inst Inst TC Locality Prio :-
compile Inst _ TC Clause,
% TODO: a clause is flexible if an instance is polimorphic (pglobal)
not (var Clause),
if (Prio = -1)
(get-inst-prio Inst Prio1)
(Prio1 = Prio),
if (Prio = -1) (get-inst-prio Inst Prio1) (Prio1 = Prio),
Graft is after (int_to_string Prio1),
get-full-path Inst ClauseName,
get-locality Locality LocalityProp,
Expand All @@ -188,10 +180,10 @@ add-inst->db IgnoreClassDepL ForceAdd Inst :-
if ((ForceAdd = tt; not (instance _ Inst _)),
not (std.exists Dep (std.mem IgnoreClassDepL)), not (banned Inst))
(
compile Inst IsLeaf TC-of-Inst Clause,
compile Inst _IsLeaf TC-of-Inst Clause,
% TODO: a clause is flexible if an instance is polimorphic (pglobal)
not (var Clause),
make-inst-graft Inst IsLeaf Graft,
Graft is after (int_to_string {get-inst-prio Inst}),
get-full-path Inst ClauseName,
if (is-local) (Visibility = [@local!])
(if (has-context-deps Inst)
Expand Down
2 changes: 1 addition & 1 deletion apps/tc/src/coq_elpi_tc_hook.mlg
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ VERNAC COMMAND EXTEND ElpiTypeclasses CLASSIFIED AS SIDEFF
let () = ignore_unknown_attributes atts in
takeover_rm cs }

| #[ atts = any_attribute ] [ "Elpi" "Override" "Register" qualified_name(p) ] -> {
| #[ atts = any_attribute ] [ "Elpi" "Override" "TC_Register" qualified_name(p) ] -> {
let () = ignore_unknown_attributes atts in
register_observer (fst p, snd p, atts) }

Expand Down
22 changes: 1 addition & 21 deletions apps/tc/tests/auto_compile.v
Original file line number Diff line number Diff line change
@@ -1,25 +1,6 @@
From elpi.apps Require Import tc.

From elpi.apps.tc Extra Dependency "base.elpi" as base.
From elpi.apps.tc Extra Dependency "compiler.elpi" as compiler.
From elpi.apps.tc Extra Dependency "tc_aux.elpi" as tc_aux.
From elpi.apps.tc Extra Dependency "create_tc_predicate.elpi" as create_tc_predicate.

Elpi Command add_instance.
Elpi Accumulate File base.
Elpi Accumulate File tc_aux.
Elpi Accumulate Db tc.db.
Elpi Accumulate File create_tc_predicate.
Elpi Accumulate File compiler.
Elpi Accumulate lp:{{
main [trm (global Inst), trm (global TC), str Locality, int Prio] :-
add-inst Inst TC Locality Prio.

main [trm (global GR)] :-
add-class-gr classic GR.
}}.
Elpi Typecheck.
Elpi Override Register add_instance.
Elpi Override TC_Register auto_compiler.
Elpi Override TC TC_solver All.

Require Import Bool.
Expand All @@ -36,7 +17,6 @@ Elpi Accumulate TC_solver lp:{{
:after "firstHook"
solve _ _ :- coq.say "Solving in ELPI!", fail.
}}.
Elpi Typecheck.

Goal A (nat * (nat * bool)). apply _. Qed.

Expand Down
27 changes: 4 additions & 23 deletions apps/tc/tests/importOrder/sameOrderCommand.v
Original file line number Diff line number Diff line change
@@ -1,32 +1,13 @@
From elpi Require Export tc.
From elpi.apps Require Export tc.

From elpi.apps.tc Extra Dependency "base.elpi" as base.
From elpi.apps.tc Extra Dependency "compiler.elpi" as compiler.
From elpi.apps.tc Extra Dependency "tc_aux.elpi" as tc_aux.
From elpi.apps.tc Extra Dependency "create_tc_predicate.elpi" as create_tc_predicate.

Elpi Command add_instance.
Elpi Accumulate File base.
Elpi Accumulate File tc_aux.
Elpi Accumulate Db tc.db.
Elpi Accumulate File create_tc_predicate.
Elpi Accumulate File compiler.
Elpi Accumulate lp:{{
main [trm (global Inst), trm (global TC), str Locality, int Prio] :-
add-inst Inst TC Locality Prio.

main [trm (global GR)] :-
add-class-gr classic GR.
}}.
Elpi Typecheck.
Elpi Override Register add_instance.
Elpi Override TC TC_solver All.


From elpi.apps.tc.tests.importOrder Extra Dependency "tc_same_order.elpi" as tc_same_order.

Elpi Command SameOrderImport.
Elpi Accumulate Db tc.db.
Elpi Accumulate File base.
Elpi Accumulate File tc_same_order.
Elpi Typecheck.

Elpi Override TC_Register auto_compiler.
Elpi Override TC TC_solver All.
15 changes: 15 additions & 0 deletions apps/tc/theories/tc.v
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,18 @@ Elpi Export MySectionEnd.

Elpi AddAllClasses.
Elpi AddAllInstances.

Elpi Command auto_compiler.
Elpi Accumulate File base.
Elpi Accumulate File tc_aux.
Elpi Accumulate Db tc.db.
Elpi Accumulate File create_tc_predicate.
Elpi Accumulate File compiler.
Elpi Accumulate lp:{{
main [trm (global Inst), trm (global TC), str Locality, int Prio] :-
add-inst Inst TC Locality Prio.

main [trm (global GR)] :-
add-class-gr classic GR.
}}.
Elpi Typecheck.

0 comments on commit 6905031

Please sign in to comment.