Skip to content

Commit 0306ee9

Browse files
committed
HB.check
1 parent 0ab66cd commit 0306ee9

File tree

6 files changed

+42
-17
lines changed

6 files changed

+42
-17
lines changed

HB/common/log.compat.current.elpi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ log.private.log-vernac _.
3535

3636
shorten log.private.coq.vernac.{ begin-module , end-module , begin-section, end-section }.
3737
shorten log.private.coq.vernac.{ import-module , export-module }.
38-
shorten log.private.coq.vernac.{ definition , variable , comment }.
38+
shorten log.private.coq.vernac.{ definition , variable , comment , check }.
3939
shorten log.private.coq.{ vernac.inductive , vernac.implicit }.
4040
shorten log.private.coq.vernac.{ canonical , abbreviation , notation , coercion }.
4141
shorten log.private.{ coq.vernac }.
@@ -100,6 +100,8 @@ coq.vernac->pp1 (vernac.implicit Local Name [L]) (box h [Locality, str "Argument
100100
std.intersperse spc PP1 PP.
101101
coq.vernac->pp1 (comment A) (box (hov 2) [str"(*", str S, str"*)"]) :-
102102
std.any->string A S.
103+
coq.vernac->pp1 (check T) (box (hov 2) [str"Check", spc, PPT, str"."]) :-
104+
@holes! => coq.term->pp T PPT.
103105

104106
pred local->locality i:bool, o:coq.pp.
105107
local->locality tt (str "Local ").

HB/common/log.elpi

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ log.coq.env.accumulate S DB CL :- std.do! [
125125
if-verbose (log.private.log-vernac (log.private.coq.vernac.comment CL)),
126126
].
127127

128+
pred log.coq.check i:term, o:term, o:term.
129+
log.coq.check Skel Ty T :- std.do! [
130+
std.assert-ok! (coq.elaborate-skeleton Skel Ty T) "Check fails",
131+
log.private.log-vernac (log.private.coq.vernac.check Skel),
132+
].
133+
128134
namespace log.private {
129135

130136
%%%%% Logging Utils %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -160,6 +166,7 @@ type coq.vernac.coercion string -> gref -> class -> coq.vernac.
160166
type coq.vernac.canonical string -> coq.vernac.
161167
type coq.vernac.implicit bool -> string -> list (list implicit_kind) -> coq.vernac.
162168
type coq.vernac.comment A -> coq.vernac.
169+
type coq.vernac.check term -> coq.vernac.
163170

164171
}
165172

HB/common/stdpp.elpi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pred copy-constructor i:indc-decl, o:indc-decl.
133133
copy-constructor (constructor ID A) (constructor ID A1) :- copy-arity A A1.
134134

135135
% TODO: move to coq-elpi proper
136-
pred coq.gref.list->set i:list mixinname, o:coq.gref.set.
136+
pred coq.gref.list->set i:list gref, o:coq.gref.set.
137137
coq.gref.list->set L S :-
138138
std.fold L {coq.gref.set.empty} coq.gref.set.add S.
139139

HB/common/utils.elpi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ with-attributes P :-
3232
att "arg_sort" bool,
3333
att "log" bool,
3434
att "log.raw" bool,
35+
att "skip" string,
3536
] Opts, !,
3637
Opts => P.
3738

@@ -86,7 +87,7 @@ nice-gref->string X Mod :-
8687
nice-gref->string X S :-
8788
coq.term->string (global X) S.
8889

89-
pred gref->modname i:mixinname, o:id.
90+
pred gref->modname i:gref, o:id.
9091
gref->modname GR ModName :-
9192
coq.gref->path GR Path,
9293
if (std.rev Path [_,ModName|_]) true (coq.error "No enclosing module for " GR).

structures.v

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,33 @@ Elpi Typecheck.
599599
(* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *)
600600
(* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *)
601601

602+
(** [HB.check T] acts like [Check T] but supports the attribute [#[skip="rex"]]
603+
that skips the action on Coq version matches rex *)
604+
605+
Elpi Command HB.check.
606+
Elpi Accumulate Db hb.db.
607+
Elpi Accumulate File "HB/common/stdpp.elpi".
608+
Elpi Accumulate File "HB/common/utils.elpi".
609+
Elpi Accumulate File "HB/common/log.elpi".
610+
Elpi Accumulate lp:{{
611+
main [trm Skel] :- !, with-attributes (with-logging (check-or-not Skel)).
612+
main _ :- coq.error "usage: HB.check (term).".
613+
614+
pred check-or-not i:term.
615+
check-or-not Skel :-
616+
coq.version VersionString _ _ _,
617+
if (get-option "skip" R, rex_match R VersionString)
618+
(coq.warn "Skipping test on Coq" VersionString "as requested")
619+
(log.coq.check Skel Ty T,
620+
coq.say {coq.term->string T} ":" {coq.term->string Ty}).
621+
}}.
622+
Elpi Typecheck.
623+
Elpi Export HB.check.
624+
625+
(* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *)
626+
(* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *)
627+
(* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *)
628+
602629
(** Technical notations from /Canonical Structures for the working Coq user/ *)
603630
Notation "`Error_cannot_unify: t1 'with' t2" := (unify t1 t2 None)
604631
(at level 0, format "`Error_cannot_unify: t1 'with' t2", only printing) :

tests/funclass.v

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,6 @@ HB.mixin Record silly T := { xx : T }.
5353
#[infer(F = "_ -> _")]
5454
HB.structure Definition wp T (F : Monoid.type T) := { A of silly A }.
5555

56-
Elpi Command CheckUnelssCoqVersion.
57-
Elpi Accumulate lp:{{
58-
main [int CV, trm Skel] :-
59-
coq.version VersionString _ V _,
60-
if (CV = V)
61-
(coq.warn "Skipping test on Coq" VersionString)
62-
(std.assert-ok! (coq.elaborate-ty-skeleton Skel _ T) "Check fails",
63-
coq.say "Checked term:\n" {coq.term->string T}).
64-
}}.
65-
Elpi Typecheck.
66-
Elpi Export CheckUnelssCoqVersion.
67-
68-
69-
CheckUnelssCoqVersion 11 (forall w : wp.type _ mult, w = w).
56+
#[skip="8.11"]
57+
HB.check (forall w : wp.type _ mult, w = w).
7058

0 commit comments

Comments
 (0)