-
Notifications
You must be signed in to change notification settings - Fork 30
Interactive mode to complete instances in tactics mode #595
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
base: master
Are you sure you want to change the base?
Changes from 12 commits
02f9da5
3b7e34b
48c6bc6
58fb68f
1930279
b1b0c17
e75473d
6b54131
bccd67e
f52ca78
97926f2
1b1bdca
9bcd79d
1b1e976
9795697
a241306
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| Set Warnings "-elpi.flex-clause". | ||
|
|
||
| (* Support constants, to be kept in sync with shim/structures.v *) | ||
| From Corelib Require Import ssreflect ssrfun. | ||
|
|
||
|
|
@@ -771,6 +773,7 @@ HB.instance Definition N Params := Factory.Build Params T … | |
| - [#[verbose]] for a verbose output. | ||
| - [#[hnf] to compute the head normal form of CS instances before declaring | ||
| them | ||
| - [#[interactive]] to provide part of the instance in tactics mode. | ||
| *) | ||
|
|
||
| #[arguments(raw)] Elpi Command HB.instance. | ||
|
|
@@ -792,23 +795,95 @@ main [const-decl Name (some BodySkel) TyWPSkel] :- !, | |
| main [T0, F0] :- !, | ||
| coq.warning "HB" "HB.deprecated" "The syntax \"HB.instance Key FactoryInstance\" is deprecated, use \"HB.instance Definition\" instead", | ||
| with-attributes (with-logging (instance.declare-existing T0 F0)). | ||
|
|
||
| main-interp-proof [const-decl Name (some BodySkel) TyWPSkel] _ Body AllGoals (const-decl Name (some Body) TyWP) :- | ||
| std.assert-ok! (coq.elaborate-arity-skeleton TyWPSkel _ TyWP) "Definition type illtyped", | ||
| coq.arity->term TyWP Ty, | ||
| std.assert-ok! (coq.elaborate-skeleton BodySkel Ty Body) "Definition illtyped", | ||
| coq.ltac.collect-goals Body Goal Shelved, | ||
| std.append Shelved Goal AllGoals. | ||
| }}. | ||
|
|
||
| #[synterp] Elpi Accumulate lp:{{ | ||
|
|
||
| shorten coq.env.{ begin-section, end-section }. | ||
|
|
||
| main [const-decl _ _ (arity _)] :- !. | ||
| main [const-decl _ _ (parameter _ _ _ _)] :- !, | ||
| SectionName is "hb_instance_" ^ {std.any->string {new_int} }, | ||
| begin-section SectionName, end-section. | ||
| main [_, _] :- !. | ||
| pred interactive-in-attributes i:list attribute. | ||
| interactive-in-attributes [attribute "interactive" (leaf-str "") | _]. | ||
| interactive-in-attributes [_ | Atts] :- interactive-in-attributes Atts. | ||
|
|
||
| main _ :- coq.error "Usage: HB.instance Definition <Name> := <Builder> T ...". | ||
| main _ :- | ||
| attributes A, | ||
| if (interactive-in-attributes A) | ||
| (true) | ||
| (SectionName is "hb_instance_" ^ {std.any->string {new_int} }, | ||
| begin-section SectionName, end-section). | ||
| }}. | ||
|
|
||
| Elpi Typecheck. | ||
| #[proof(begin_if="interactive")] | ||
| Elpi Export HB.instance. | ||
|
|
||
|
|
||
|
|
||
| #[arguments(raw)] Elpi Command HB.endinstance. | ||
| Elpi Accumulate Db hb.db. | ||
| Elpi Accumulate File "HB/common/stdpp.elpi". | ||
| Elpi Accumulate File "HB/common/database.elpi". | ||
| Elpi Accumulate File "HB/common/compat_acc_clauses_all.elpi". | ||
| Elpi Accumulate File "HB/common/compat_add_secvar_all.elpi". | ||
| Elpi Accumulate File "HB/common/utils.elpi". | ||
| Elpi Accumulate File "HB/common/log.elpi". | ||
| Elpi Accumulate File "HB/common/synthesis.elpi". | ||
| Elpi Accumulate File "HB/context.elpi". | ||
| Elpi Accumulate File "HB/instance.elpi". | ||
| Elpi Accumulate lp:{{ | ||
| func under term, list (pair term term) -> term. | ||
| under (fun N Ty F) Acc (fun N Ty F') :- | ||
| @pi-decl N Ty x\ | ||
| under (F x) [(pr x Ty)|Acc] (F' x). | ||
| under (app L) Acc (app L') :- | ||
| aux Acc L L'. | ||
|
|
||
| func aux list (pair term term), list term -> list term. | ||
| aux _ [] []. | ||
| aux Acc [T|TS] [T|TS'] :- | ||
| coq.typecheck T Ty ok, | ||
| coq.typecheck Ty TyTy ok, | ||
| %coq.typecheck-ty does not make coercions | ||
| (not (TyTy = {{Prop}}); T = global _), !, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if T is |
||
| aux Acc TS TS'. | ||
| aux Acc [T|TS] [T'|TS'] :- | ||
| std.spy! (abstract Acc T TA), | ||
| log.coq.env.add-const _ TA _ @opaque! C, | ||
| T' = app [(global (const C))|{std.map Acc fst}], | ||
| aux Acc TS TS'. | ||
|
|
||
| func abstract list (pair term term), term -> term. | ||
| abstract [] T T' :- | ||
| copy T T'. | ||
| abstract [(pr V Ty) | A] T (fun `x` Ty F) :- | ||
| pi w\ (copy V w :- !) => abstract A T (F w). | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this code should go to utils, maybe in a namespace Related design question for @CohenCyril is how configurable this should be, i.e. instead of using
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I think it is better if configurable. But reasonable choices are essentially
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An issue with moving that code to utils is that it uses "log.coq.env.add-const" which is in log and which in turns uses some code from utils (eg "avoid-name-collision)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ignore |
||
| main-interp-qed _ _ P _GL (const-decl Name (some _Body) TyWP) :- | ||
| under P [] P', | ||
| with-attributes (with-logging (instance.declare-const Name P' TyWP _ _)). | ||
| }}. | ||
|
|
||
| #[synterp] Elpi Accumulate lp:{{ | ||
|
|
||
| shorten coq.env.{ begin-section, end-section }. | ||
|
|
||
| main _ :- | ||
| SectionName is "hb_instance_" ^ {std.any->string {new_int} }, | ||
| begin-section SectionName, end-section. | ||
| }}. | ||
|
|
||
| #[proof="end"] | ||
| Elpi Export HB.endinstance. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done :) |
||
|
|
||
|
|
||
|
|
||
|
|
||
| (* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *) | ||
| (* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *) | ||
| (* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *) | ||
|
|
||
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.
It may make sense to have a
triplehere and also storeN, and use thatNinabstractin place of`x`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.
yes, done ! the name of the parameter is used in the abstraction