Skip to content

Commit 8a72aef

Browse files
authored
Merge pull request #414 from math-comp/saturate-filter
HB.saturate: take a cs pattern as a filter
2 parents e4bbc38 + f22f3bb commit 8a72aef

File tree

5 files changed

+37
-12
lines changed

5 files changed

+37
-12
lines changed

HB/common/database.elpi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ findall-builders LFIL :-
224224
std.map {std.findall (builder-decl B_)} extract-builder LFILunsorted,
225225
std.bubblesort LFILunsorted leq-builder LFIL.
226226

227-
pred findall-has-mixin-instance o:list prop.
228-
findall-has-mixin-instance CL :-
229-
std.findall (has-mixin-instance _ _ _) CL.
227+
pred findall-has-mixin-instance i:cs-pattern, o:list prop.
228+
findall-has-mixin-instance P CL :-
229+
std.findall (has-mixin-instance P _ _) CL.
230230

231231
pred has-mixin-instance_key i:prop, o:cs-pattern.
232232
has-mixin-instance_key (has-mixin-instance P _ _) P.

HB/instance.elpi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,10 @@ mk-factory-sort-factory AliasGR CSL :- std.do! [
241241
].
242242

243243
% create instances for all possible combinations of types and structure compatible
244-
pred saturate-instances.
245-
saturate-instances :- std.do! [
246-
findall-has-mixin-instance ClausesHas,
244+
pred saturate-instances i:cs-pattern.
245+
saturate-instances Filter :- std.do! [
246+
247+
findall-has-mixin-instance Filter ClausesHas,
247248

248249
std.map ClausesHas has-mixin-instance_key KL,
249250
undup-cs-patterns KL UKL,

_CoqProject.test-suite

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ tests/unit/close_hole_term.v
9595
tests/unit/struct.v
9696
tests/factory_when_notation.v
9797

98+
tests/saturate_on.v
99+
98100
-R tests HB.tests
99101
-R examples HB.examples
100102

structures.v

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,8 @@ pred mixin-class o:mixinname, o:classname.
193193
% Coq's CS database (which is just for structures).
194194
pred mixin-src o:term, o:mixinname, o:term.
195195

196-
% [has-mixin-instance P M G] states that G is a reference to an instance
197-
% which can be used to reconstruct an instance
198-
% of the form [M P …] with eventually some parameters for P.
196+
% [has-mixin-instance K M G] states that G is a reference to an instance
197+
% of mixin M for subject K
199198
pred has-mixin-instance o:cs-pattern, o:mixinname, o:gref.
200199

201200
%% database for HB.builders %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -690,7 +689,8 @@ Elpi Export HB.structure.
690689
(* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *)
691690
(* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *)
692691

693-
(* [HB.saturate] saturates all instances w.r.t. the current hierarchy.
692+
(* [HB.saturate [key]] saturates all instances (of all known keys, if key is not
693+
given) w.r.t. the current hierarchy.
694694
695695
When two (unrelated) files are imported it might be that the instances
696696
declared in one file are sufficient to instantiate structures declared
@@ -715,8 +715,11 @@ Elpi Accumulate File "HB/instance.elpi".
715715
Elpi Accumulate File "HB/context.elpi".
716716
Elpi Accumulate File "HB/factory.elpi".
717717
Elpi Accumulate lp:{{
718-
main [] :- !, with-attributes (with-logging (instance.saturate-instances)).
719-
main _ :- coq.error "Usage: HB.saturate".
718+
main [] :- !, with-attributes (with-logging (instance.saturate-instances _)).
719+
main [str "Type"] :- !, with-attributes (with-logging (instance.saturate-instances (cs-sort _))).
720+
main [str K] :- !, coq.locate K GR, with-attributes (with-logging (instance.saturate-instances (cs-gref GR))).
721+
main [trm T] :- !, term->cs-pattern T P, with-attributes (with-logging (instance.saturate-instances P)).
722+
main _ :- coq.error "Usage: HB.saturate [key]".
720723
}}.
721724
Elpi Typecheck.
722725
Elpi Export HB.saturate.

tests/saturate_on.v

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
From HB Require Import structures.
2+
3+
HB.mixin Record HasPoint T := { default : T }.
4+
5+
HB.instance Definition _ : HasPoint nat := HasPoint.Build nat 0.
6+
HB.instance Definition _ : HasPoint bool := HasPoint.Build bool false.
7+
HB.instance Definition _ A : HasPoint (list A) := HasPoint.Build (list A) nil.
8+
HB.instance Definition _ A : HasPoint Type := HasPoint.Build Type nat.
9+
10+
HB.structure Definition Pointed := { T of HasPoint T }.
11+
12+
HB.saturate (list _).
13+
14+
Fail Check nat : Pointed.type.
15+
Fail Check bool : Pointed.type.
16+
Check (list unit : Pointed.type).
17+
Fail Check Type : Pointed.type.
18+
19+

0 commit comments

Comments
 (0)