Skip to content

Commit 7516a95

Browse files
authored
Merge pull request #181 from math-comp/no_section_discharge_for_factory_aliases
No section discharge for alias factories and builder mixins
2 parents 11d7c8a + 3e47afd commit 7516a95

File tree

7 files changed

+42
-18
lines changed

7 files changed

+42
-18
lines changed

HB/common/stdpp.elpi

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ coq.gref.list->set L S :-
138138
std.fold L {coq.gref.set.empty} coq.gref.set.add S.
139139

140140
% [coq.abstract-indt-decl Section I AbsI] abstracts I over the Section variables
141-
% which becomes parameter nodes if the indt-decl type
141+
% which becomes parameter nodes of the indt-decl type
142142
pred coq.abstract-indt-decl i:list constant, i:indt-decl, o:indt-decl.
143143
coq.abstract-indt-decl [] X X1 :- copy-indt-decl X X1.
144144
coq.abstract-indt-decl [C|CS] X (parameter ID explicit Ty1 X1) :-
@@ -149,6 +149,19 @@ coq.abstract-indt-decl [C|CS] X (parameter ID explicit Ty1 X1) :-
149149
(copy (global (const C)) x :- !) =>
150150
coq.abstract-indt-decl CS X (X1 x).
151151

152+
% [coq.abstract-const-decl Section I AbsI] abstracts I over the Section variables
153+
% which becomes fun nodes
154+
pred coq.abstract-const-decl i:list constant, i:pair term term, o:pair term term.
155+
coq.abstract-const-decl [] (pr X Y) (pr X1 Y1) :- copy X X1, copy Y Y1.
156+
coq.abstract-const-decl [C|CS] X (pr (fun Name Ty1 X1) (prod Name Ty1 X2)) :-
157+
coq.gref->string (const C) ID,
158+
coq.id->name ID Name,
159+
coq.env.typeof (const C) Ty,
160+
copy Ty Ty1,
161+
@pi-parameter ID Ty x\
162+
(copy (global (const C)) x :- !) =>
163+
coq.abstract-const-decl CS X (pr (X1 x) (X2 x)).
164+
152165
% [coq.copy-clauses-for-unfold CS CL] generates clauses for the copy predicate
153166
% to unfold all constants in CS
154167
pred coq.copy-clauses-for-unfold i:list constant, o:list prop.

HB/common/synthesis.elpi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pred infer-all-mixin-args i:list term, i:term, i:gref, o:term.
3131
infer-all-mixin-args Ps T GR X :- !, std.do! [
3232
std.assert! (gref-deps GR MLwP) "BUG: gref-deps should never fail",
3333
list-w-params_list MLwP ML,
34-
infer-mixin-args Ps T ML (global GR) X
34+
infer-mixin-args Ps T ML (global GR) X,
3535
].
3636

3737
% [assert!-infer-mixin TheType M Out] infers one mixin M on TheType and
@@ -109,7 +109,7 @@ namespace private {
109109
% the databases [mixin-src] and [from]
110110
pred mixin-for i:term, i:mixinname, o:term.
111111
mixin-for T M MICompressed :- mixin-src T M Tm, !, std.do! [
112-
if-verbose (coq.say "HB: Trying to infer mixin for" M),
112+
%if-verbose (coq.say "HB: Trying to infer mixin for" M),
113113
std.assert-ok! (coq.typecheck Tm Ty) "mixin-for: Tm illtyped",
114114

115115
factory? Ty (triple Factory Params _),
@@ -119,7 +119,7 @@ mixin-for T M MICompressed :- mixin-src T M Tm, !, std.do! [
119119
coq.subst-fun [Tm] B MI
120120
),
121121

122-
if-verbose (coq.say "HB: Trying to compress mixin for" {coq.term->string MI}),
122+
%if-verbose (coq.say "HB: Trying to compress mixin for" {coq.term->string MI}),
123123
compress-coercion-paths MI MICompressed,
124124
].
125125

HB/factory.elpi

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,22 +157,28 @@ process-asset-unnamed-parameters (asset-record _ Sort _ Fields) GRFS Module TheT
157157

158158
pred declare-factory-alias i:term, i:list-w-params factoryname, i:id, i:term, i:list term.
159159
declare-factory-alias Ty1Skel GRFSwP Module TheType TheParams :- std.do! [
160-
161160
% TODO maybe context.declare should just take GRFSwP and postulate
162161
% the parameters and the type
163-
context.declare TheType TheParams GRFSwP Hyps _,
162+
context.declare TheType TheParams GRFSwP MixinSrcClauses SectionCanonicalInstance,
163+
164+
if-verbose (coq.say "HB: declare constant axioms_"),
164165

165166
std.assert-ok! (coq.elaborate-ty-skeleton Ty1Skel _ Ty1) "Illtyped alias factory",
166-
log.coq.env.add-const-noimplicits "axioms_" Ty1 _ @transparent! C,
167+
168+
abstract-over-section TheParams TheType MixinSrcClauses SectionCanonicalInstance coq.abstract-const-decl (pr Ty1 _) (pr Ty1Closed _) Section,
169+
log.coq.env.add-const-noimplicits "axioms_" Ty1Closed _ @transparent! C,
167170

168171
std.assert! (safe-dest-app Ty1 (global PhF) _Args) "Argument must be a factory",
169172
std.assert! (factory-alias->gref PhF F) "BUG: Factory alias declaration missing",
170173
std.assert! (factory-constructor F FK) "BUG: Factory constructor missing",
171174

172-
Hyps => synthesis.infer-all-mixin-args TheParams TheType FK MFK,
175+
MixinSrcClauses => synthesis.infer-all-mixin-args TheParams TheType FK MFK,
173176
std.assert-ok! (coq.typecheck MFK MFKTy) "BUG: typecking of former factory constructor failed",
174-
(pi Args\ copy (app [global F|Args]) (global (const C))) => copy MFKTy MFKTyC,
175-
log.coq.env.add-const-noimplicits "Axioms_" MFK MFKTyC @transparent! CK,
177+
(pi Args\ copy (app[global F|Args]) (app[global (const C)|Section])) => copy MFKTy MFKTyC,
178+
179+
abstract-over-section TheParams TheType MixinSrcClauses SectionCanonicalInstance coq.abstract-const-decl (pr MFK MFKTyC) (pr MFKClosed MFKTyCClosed) _,
180+
log.coq.env.add-const-noimplicits "Axioms_" MFKClosed MFKTyCClosed @transparent! CK,
181+
176182
GRK = const CK,
177183

178184
log.coq.env.end-section-name Module,
@@ -224,16 +230,16 @@ build-deps-for-projections R MLwP CL :- std.do! [
224230
% variables that aoccur. We don't want that for mixin/factories, so we implement
225231
% our own discharging. Note that definitions (like canonical instance) have
226232
% to be abstracted too.
227-
pred abstract-indt-decl-over-section i:list term, i:term, i:list prop, i:list constant, i:indt-decl, o:indt-decl.
228-
abstract-indt-decl-over-section TheParams TheType MixinSrcClauses SectionCanonicalInstance RDecl RDeclClosed :-
233+
pred abstract-over-section i:list term, i:term, i:list prop, i:list constant, i:(list constant -> A -> A -> prop), i:A, o:A, o:list term.
234+
abstract-over-section TheParams TheType MixinSrcClauses SectionCanonicalInstance F X X1 Section :-
229235
% compute section variables to be used for discharging
230236
std.map MixinSrcClauses mixin-src_src Mixins,
231237
std.append TheParams [TheType|{std.rev Mixins}] Section,
232238
std.map Section (x\r\ x = global (const r)) SectionVars,
233239
% We discharge by hand the record declaration so that we can be sure all
234240
% parameters and mixins are abstracted (even if unused).
235241
coq.copy-clauses-for-unfold SectionCanonicalInstance CopyUnfold,
236-
CopyUnfold => coq.abstract-indt-decl SectionVars RDecl RDeclClosed.
242+
CopyUnfold => F SectionVars X X1.
237243

238244
pred declare-mixin-or-factory i:term, i:record-decl, i:list-w-params factoryname, i:id, i:term, i:asset, i:list term.
239245
declare-mixin-or-factory Sort1 Fields GRFSwP Module TheType D TheParams :- std.do! [
@@ -245,7 +251,7 @@ declare-mixin-or-factory Sort1 Fields GRFSwP Module TheType D TheParams :- std.d
245251
RDeclSkel = record "axioms_" Sort1 Kname Fields,
246252
std.assert-ok! (coq.elaborate-indt-decl-skeleton RDeclSkel RDecl) "record declaration illtyped",
247253

248-
abstract-indt-decl-over-section TheParams TheType MixinSrcClauses SectionCanonicalInstance RDecl RDeclClosed,
254+
abstract-over-section TheParams TheType MixinSrcClauses SectionCanonicalInstance coq.abstract-indt-decl RDecl RDeclClosed _,
249255

250256
log.coq.env.add-indt RDeclClosed R,
251257
log.coq.env.end-section-name Module, % We need to anyway declare the record inside the section

HB/instance.elpi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ declare-all T [class Class Struct MLwP|Rest] [pr Name CS|L] :-
8989
coq.gref->path TGR TPath,
9090
std.rev TPath [TMod|_],
9191
coq.gref->id TGR TID,
92-
Name is TMod ^ "_" ^ TID ^ "_canonical_" ^ {gref->modname Struct},
92+
if (TMod = TID)
93+
(Name is TID ^ "_canonical_" ^ {gref->modname Struct})
94+
(Name is TMod ^ "_" ^ TID ^ "_canonical_" ^ {gref->modname Struct}),
9395

9496
if-verbose (coq.say "HB: declare canonical structure instance" Name),
9597

examples/demo1/hierarchy_5.v

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,7 @@ Proof. by rewrite -addrA subrr addr0. Qed.
223223

224224
End Theory.
225225

226-
HB.graph "hierarchy_5.dot".
226+
HB.graph "hierarchy_5.dot".
227+
228+
(* we check the alias factory is abstracted over the whole section *)
229+
HB.check (SemiRing_of_AddComoid.axioms_ : forall A, forall m : AddMonoid_of_TYPE.axioms_ A, AddComoid_of_AddMonoid.axioms_ A m -> Type).

tests/compress_coe.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ HB.instance Definition prodD (D D' : D.type) :=
3434
hasD.Build (D * D')%type (d, d).
3535

3636
Set Printing Coercions.
37-
Print prod_prod_canonical_D.
37+
Print prod_canonical_D.

tests/compress_coe.v.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
prod_prod_canonical_D =
1+
prod_canonical_D =
22
fun D D' : D.type =>
33
{|
44
D.sort := D.sort D * D.sort D';

0 commit comments

Comments
 (0)