-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #522 from FissoreD/origin/master-tc
TC solver 1
- Loading branch information
Showing
33 changed files
with
406 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
open Elpi_plugin | ||
open Classes | ||
open Coq_elpi_arg_HOAS | ||
|
||
type qualified_name = Coq_elpi_utils.qualified_name | ||
|
||
type loc_name_atts = (Loc.t * qualified_name * Attributes.vernac_flags) | ||
|
||
let gref2elpi_term (gref: Names.GlobRef.t) : Cmd.raw = | ||
let gref_2_string gref = Pp.string_of_ppcmds (Names.GlobRef.print gref) in | ||
let normalize_string s = | ||
String.split_on_char '.' s |> List.rev |> List.hd |> | ||
String.split_on_char ',' |> List.hd in | ||
Cmd.Term (CAst.make @@ Constrexpr.CRef( | ||
Libnames.qualid_of_string @@ normalize_string @@ gref_2_string gref,None)) | ||
|
||
let observer_class (x : Typeclasses.typeclass) : Coq_elpi_arg_HOAS.Cmd.raw list = | ||
[gref2elpi_term x.cl_impl] | ||
|
||
(* | ||
The elpi arguments passed to the elpi program are [Inst, TC, Locality, Prio] where: | ||
- Inst : is the elpi Term for the current instance | ||
- TC : is the elpi Term for the type classes implemented by Inst | ||
- Locality : is the elpi String [Local|Global] depending on the locality of Inst | ||
- Prio : is the elpi Int X representing the priority of the instance | ||
in particular if the priority is defined by the user, X is that priority | ||
otherwise, X is -1 | ||
*) | ||
let observer_instance ({locality; instance; info; class_name} : instance) : Coq_elpi_arg_HOAS.Cmd.raw list = | ||
let locality2elpi_string loc = | ||
let hint2string = function | ||
| Hints.Local -> "Local" | ||
| Export -> "Export" | ||
| SuperGlobal -> "Global" in | ||
Cmd.String (hint2string loc) in | ||
let prio2elpi_int (prio: Typeclasses.hint_info) = | ||
Cmd.Int (Option.default (-1) prio.hint_priority) in | ||
[ | ||
gref2elpi_term instance; | ||
gref2elpi_term class_name; | ||
locality2elpi_string locality; | ||
prio2elpi_int info | ||
] | ||
|
||
let inObservation = | ||
Libobject.declare_object @@ | ||
Libobject.local_object "TC_HACK_OBSERVER2" | ||
~cache:(fun (run,inst) -> run @@ observer_instance inst) | ||
~discharge:(fun (_,inst as x) -> if inst.locality = Hints.Local then None else Some x) | ||
|
||
let observer_evt ((loc, name, atts) : loc_name_atts) (x : Event.t) = | ||
let open Coq_elpi_vernacular in | ||
let run_program e = run_program loc name ~atts e in | ||
match x with | ||
| Event.NewClass cl -> run_program @@ observer_class cl | ||
| Event.NewInstance inst -> Lib.add_leaf (inObservation (run_program,inst)) | ||
|
||
let inTakeover = | ||
let cache (loc, name, atts) = | ||
let observer1 = Classes.register_observer | ||
~name:(String.concat "." name) | ||
(observer_evt (loc, name, atts)) | ||
in | ||
Classes.activate_observer observer1 | ||
in | ||
Libobject.(declare_object | ||
(superglobal_object_nodischarge "TC_HACK_OBSERVER" ~cache ~subst:None)) | ||
|
||
let register_observer (x : loc_name_atts) = | ||
Lib.add_leaf (inTakeover x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
Coq_elpi_tc_register | ||
Coq_elpi_class_tactics_hacked | ||
Coq_elpi_tc_hook |
Oops, something went wrong.