-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add synterp phase support for derive plugins. #597
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* Entry point for all derivations */ | ||
/* license: GNU Lesser General Public License Version 2.1 or later */ | ||
/* ------------------------------------------------------------------------- */ | ||
|
||
namespace derive { | ||
|
||
pred dep o:string, o:string. | ||
dep X Y :- dep1 X Y. | ||
dep X Y :- dep1 X Z, dep Z Y. | ||
|
||
pred selected i:string. | ||
selected Name :- get-option "only" Map, !, | ||
Map => (get-option Name _; (get-option X _, dep X Name)). | ||
selected _. | ||
|
||
pred chain i:string, i:list derive. | ||
chain _ []. | ||
chain T [derive Name _ _|FS] :- not(selected Name), !, | ||
chain T FS. | ||
chain T [derive _ _ AlreadyDone|FS] :- (pi x\ stop x :- !, fail) => AlreadyDone, !, | ||
chain T FS. | ||
chain T [derive _ F _|FS] :- get-option "only" _, !, % request this one | ||
F _, | ||
chain T FS. | ||
chain T [derive _ F _|FS] :- % all are selected, we can fail | ||
(pi x\ stop x :- !, fail) => F _, !, | ||
chain T FS. | ||
chain T [derive _ _ _|FS] :- | ||
chain T FS. | ||
|
||
pred toposort i:list derive, o:list derive. | ||
toposort L SL :- | ||
std.findall (dep1 _ _) Deps, | ||
topo L Deps SL. | ||
|
||
pred std.partition i:list A, i:(A -> prop), o:list A, o:list A. | ||
std.partition [] _ [] []. | ||
std.partition [X|XS] P [X|R] L :- P X, !, std.partition XS P R L. | ||
std.partition [X|XS] P R [X|L] :- std.partition XS P R L. | ||
|
||
pred not-a-src i:list prop, i:derive. | ||
not-a-src Deps (derive A _ _) :- not(std.mem! Deps (dep1 A _)). | ||
|
||
pred tgt-is-not-in i:list derive, i:prop. | ||
tgt-is-not-in [] _. | ||
tgt-is-not-in [derive Tgt _ _|_] (dep1 _ Tgt) :- !, fail. | ||
tgt-is-not-in [_|L] D :- tgt-is-not-in L D. | ||
|
||
pred topo i:list derive, i:list prop, o:list derive. | ||
topo [] _ [] :- !. | ||
topo L Deps SL :- | ||
std.partition L (not-a-src Deps) LNoDeps Other, | ||
if (LNoDeps = []) (coq.error "derive: no topological order:" L Deps) true, | ||
std.filter Deps (tgt-is-not-in LNoDeps) NewDeps, | ||
topo Other NewDeps SOther, | ||
std.append LNoDeps SOther SL. | ||
|
||
pred main i:string. | ||
main TypeName :- get-option "module" M, !, | ||
if (M = "") (Mod = TypeName) (Mod = M), | ||
coq.env.begin-module Mod none, | ||
main-derive TypeName tt, | ||
coq.env.end-module _. | ||
main TypeName :- | ||
main-derive TypeName ff. | ||
|
||
pred main-derive i:string, i:bool. | ||
main-derive TypeName InModule :- main1 TypeName InModule. | ||
|
||
pred main1 i:string, i:bool. | ||
main1 TypeName InModule :- | ||
if (get-option "prefix" PFX) | ||
(Prefix = PFX) | ||
(if (InModule is ff) (Prefix is TypeName ^ "_") (Prefix = "")), | ||
std.findall (derivation TypeName Prefix _) L, | ||
std.map L (x\r\ x = derivation _ _ r) DL, | ||
toposort DL SortedDL, | ||
chain TypeName SortedDL. | ||
|
||
} |
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,9 @@ | ||
/* Entry point for derive extensions */ | ||
/* license: GNU Lesser General Public License Version 2.1 or later */ | ||
/* ------------------------------------------------------------------------- */ | ||
|
||
pred derivation i:string, i:string, o:derive. | ||
pred export i:modpath. | ||
pred dep1 o:string, o:string. | ||
kind derive type. | ||
type derive string -> (list prop -> prop) -> prop -> derive. |
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,29 +1,27 @@ | ||
(* README *) | ||
(* README *) | ||
From elpi.apps Require Import derive.std. | ||
|
||
derive Inductive peano := Zero | Succ (p : peano). | ||
|
||
(* Bug 8.16: About peano.peano.*) | ||
(* Notation peano := peano.peano *) | ||
#[module] derive Inductive peano := Zero | Succ (p : peano). | ||
|
||
Print peano.peano. | ||
(* Inductive peano : Type := Zero : peano | Succ : peano -> peano *) | ||
(* Inductive peano : Set := Zero : peano | Succ : peano -> peano. *) | ||
|
||
Eval compute in peano.eqb Zero (Succ Zero). | ||
(* = false : bool *) | ||
|
||
About peano.eqb_OK. | ||
(* | ||
peano.eqb_OK : forall x1 x2 : peano, Bool.reflect (x1 = x2) (peano.eqb x1 x2) | ||
peano.eqb_OK : forall x1 x2 : peano, reflect (x1 = x2) (peano.eqb x1 x2) | ||
|
||
peano.eqb_OK is not universe polymorphic | ||
Arguments peano.eqb_OK x1 x2 | ||
peano.eqb_OK is opaque | ||
Expands to: Constant elpi.apps.derive.examples.readme.peano.eqb_OK | ||
*) | ||
|
||
#[verbose] derive Nat.add. | ||
Check is_add. (* | ||
: forall n : nat, is_nat n -> | ||
forall m : nat, is_nat m -> | ||
is_nat (n + m) | ||
*) | ||
*) |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO (for me): there is a coq.elpi.toposort but for a full graph. Fix/adapt to this use case.