Skip to content

Commit f0e45ee

Browse files
committed
use primproj for class->mixin builders
1 parent 58f4e12 commit f0e45ee

10 files changed

+49
-21
lines changed

HB/about.elpi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ main-located S (loc-abbreviation A) :-
4141
coq.safe-dest-app T (global GR) _, !,
4242
main-located S (loc-gref GR).
4343

44-
main-located S (loc-gref GR) :- from Factory Mixin GR, !,
44+
main-located S (loc-gref GR) :- from Factory Mixin (gref GR), !,
4545
private.main-builder S Factory Mixin.
4646

4747
main-located S (loc-gref GR) :-

HB/builders.elpi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pred declare-1-builder i:builder, i:list prop, o:list prop.
7979
declare-1-builder (builder _ SrcFactory TgtMixin _) FromClauses FromClauses :- (FromClauses => from SrcFactory TgtMixin _), !,
8080
if-verbose (coq.say {header} "skipping duplicate builder from"
8181
{nice-gref->string SrcFactory} "to" {nice-gref->string TgtMixin}).
82-
declare-1-builder (builder _ SrcFactory TgtMixin B) FromClauses [from SrcFactory TgtMixin B|FromClauses] :-
82+
declare-1-builder (builder _ SrcFactory TgtMixin B) FromClauses [from SrcFactory TgtMixin (gref B)|FromClauses] :-
8383
if-verbose (coq.say {header} "declare builder from"
8484
{nice-gref->string SrcFactory} "to" {nice-gref->string TgtMixin}).
8585

HB/common/database.elpi

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ from_factory (from X _ _) X.
1111
pred from_mixin i:prop, o:mixinname.
1212
from_mixin (from _ X _) X.
1313

14-
pred from_builder i:prop, o:term.
15-
from_builder (from _ _ X) (global X).
14+
pred from_builder i:prop, o:gref-or-primitive.
15+
from_builder (from _ _ X) X.
1616

1717
pred mixin-src_mixin i:prop, o:mixinname.
1818
mixin-src_mixin (mixin-src _ M _) M.
@@ -97,12 +97,18 @@ factory-provides.base Factory Params T _RMLwP MLwP :- std.do! [
9797
std.map2 BL ML (factory-provides.one Params T) MLwP,
9898
].
9999

100-
pred factory-provides.one i:list term, i:term, i:term, i:mixinname, o:w-args mixinname.
101-
factory-provides.one Params T B M (triple M PL T) :- std.do! [
102-
std.assert-ok! (coq.typecheck B Ty) "Builder illtyped",
100+
pred factory-provides.one i:list term, i:term, i:gref-or-primitive, i:mixinname, o:w-args mixinname.
101+
factory-provides.one Params T (gref B) M (triple M PL T) :- std.do! [
102+
coq.env.typeof B Ty,
103103
subst-prod [T] {subst-prod Params Ty} TyParams,
104104
std.assert! (extract-conclusion-params T TyParams PL) "The conclusion of a builder is a mixin whose parameters depend on other mixins",
105105
].
106+
factory-provides.one Params T (primitive (pr P N)) M (triple M PL T) :- std.do! [
107+
coq.mk-app {coq.mk-app (global M) Params} [T] TyM, % fine since M is the class hence no extra arg needed
108+
std.assert-ok! (d\@pi-decl `m` TyM m\coq.typecheck (app[primitive(proj P N),m]) (TyParams m) d) "Builder illtyped",
109+
@pi-decl `m` TyM m\
110+
std.assert! (extract-conclusion-params T (TyParams m) PL) "The conclusion of a primitive projection is a mixin whose parameters depend on other mixins"
111+
].
106112

107113
pred extract-conclusion-params i:term, i:term, o:list term.
108114
extract-conclusion-params TheType (prod _ S T) R :- !,

HB/common/stdpp.elpi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,11 @@ coq.term->gref (app [primitive (proj N J),T|_]) GR :- !, std.do! [
302302
std.map2-filter Ps PPs (x\y\gr\sigma c\x = some c, y = some (pr N J), gr = const c) [GR],
303303
].
304304

305+
%hack/ fixup API
306+
:before "subst-fun:fail"
307+
coq.subst-fun L (primitive (proj _ _) as F) (app[F|L]).
308+
309+
305310
pred cs-pattern->name i:cs-pattern, o:string.
306311
cs-pattern->name cs-prod "prod".
307312
cs-pattern->name (cs-sort _) "sort".

HB/common/synthesis.elpi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,15 @@ mixin-for_mixin-builder (mixin-for _ _ B) B.
223223
% and fills in all the mixins required by the builder using mixin-src, obtaining
224224
% a function (MF = Builder Params TheType InferredStuff : Src -> Tgt)
225225
pred builder->term i:list term, i:term, i:factoryname, i:mixinname, o:term.
226-
builder->term Ps T Src Tgt B :- !, std.do! [
227-
from Src Tgt FGR,
226+
builder->term Ps T Src Tgt B :- from Src Tgt (gref FGR), !, std.do! [
228227
F = global FGR,
229228
gref-deps Src MLwP,
230229
list-w-params_list MLwP ML,
231230
infer-all-these-mixin-args Ps T ML F B,
232231
].
232+
builder->term _ _ Src Tgt (primitive (proj P N)) :-
233+
% no deps, Src is a class
234+
from Src Tgt (primitive (pr P N)).
233235

234236
% [instantiate-all-these-mixin-args T F M_i TFX] where mixin-for T M_i X_i states that
235237
% if F ~ fun xs (m_0 : M_0 T) .. (m_n : M_n T ..) ys

HB/factory.elpi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ cdecl->w-mixins.mixins (context-item ID _ TySkel none Rest) Out :- !,
165165

166166
% The identity builder
167167
pred declare-id-builder i:factoryname, o:prop.
168-
declare-id-builder GR (from GR GR (const C)) :- std.do! [
168+
declare-id-builder GR (from GR GR (gref (const C))) :- std.do! [
169169
gref-deps GR GRD,
170170
synthesis.mixins-w-params.fun GRD (declare-id-builder.aux GR) IDBodySkel,
171171
std.assert-ok! (coq.elaborate-skeleton IDBodySkel IDType IDBody) "identity builder illtyped",

HB/instance.elpi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ optimize-class-body _ _ (app L) (app L) [].
424424
pred declare-mixin-name i:term, o:term, o:list prop.
425425
declare-mixin-name (global _ as T) T [].
426426
declare-mixin-name T (global GR) [] :- mixin-mem T GR.
427-
declare-mixin-name T T [] :- coq.safe-dest-app T (global GR) _, not (from _ _ GR), not (get-option "hnf" tt).
427+
declare-mixin-name T T [] :- coq.safe-dest-app T (global GR) _, not (from _ _ (gref GR)), not (get-option "hnf" tt).
428428
declare-mixin-name T (global (const C)) [mixin-mem T (const C)] :- std.do! [
429429
Name is "HB_unnamed_mixin_" ^ {std.any->string {new_int}},
430430
if-verbose (coq.say {header} "Giving name" Name "to mixin instance" {coq.term->string T}),

HB/status.elpi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,14 @@ print-hierarchy :- std.do! [
4343
namespace private {
4444

4545
pred pp-from i:prop.
46-
pp-from (from F M T) :-
46+
pp-from (from F M (gref T)) :-
4747
coq.say "From" {coq.term->string (global F)} "to" {coq.term->string (global M)},
4848
coq.say " " {coq.term->string (global T)},
4949
coq.say "".
50+
pp-from (from F M (primitive (pr P N))) :-
51+
coq.say "From" {coq.term->string (global F)} "to" {coq.term->string (global M)},
52+
coq.say " " P " (" N "th field)",
53+
coq.say "".
5054

5155
pred pp-list-w-params i:mixins, i:term.
5256
pred pp-list-w-params.list-triple i:list (w-args mixinname), i:term.

HB/structure.elpi

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,11 @@ export-operations Structure ProjSort ProjClass MLwP EX1 EX2 MLToExport :- std.do
308308
std.map LMwPToExport w-params_1 MLToExport,
309309
].
310310

311+
pred mk-app-builder i:list term, i:term, i:gref-or-primitive, o:term.
312+
mk-app-builder Params TheType (gref B) T :-
313+
coq.mk-app {coq.env.global B} {std.append Params [TheType]} T.
314+
mk-app-builder _ _ (primitive (pr P N)) (primitive(proj P N)).
315+
311316
pred mk-coe-class-body
312317
i:factoryname, % From class
313318
i:factoryname, % To class
@@ -320,14 +325,14 @@ mk-coe-class-body FC TC TMLwP Params T _ CoeBody :- std.do! [
320325

321326
list-w-params_list TMLwP TML,
322327
std.map TML (from FC) Builders,
323-
std.map Builders (x\r\mk-app (global x) Params r) BuildersP,
328+
std.map Builders (mk-app-builder Params T) BuildersP,
324329

325330
factory-nparams TC TCNP,
326331
mk-app (global {get-constructor TC})
327332
{coq.mk-n-holes TCNP} KCHoles,
328333

329334
(pi c\ sigma Mixes\
330-
std.map BuildersP (builder\r\ r = app[builder, T, c]) Mixes,
335+
std.map BuildersP (builder\r\ r = app[builder, c]) Mixes,
331336
mk-app KCHoles [T | Mixes] (ClassCoercion c)),
332337

333338
CoeBody = {{ fun (c : lp:Class) => lp:(ClassCoercion c) }}
@@ -494,12 +499,12 @@ declare-class+structure MLwP Sort
494499
std.assert-ok! (coq.typecheck-indt-decl ClassDeclaration) "declare-class: illtyped",
495500
(@primitive! => log.coq.env.add-indt ClassDeclaration ClassInd),
496501

497-
coq.env.projections ClassInd Projs,
502+
coq.env.primitive-projections ClassInd Projs,
498503
% TODO: put this code in a named clause
499504
w-params.nparams MLwP NParams,
500505
std.map2 {list-w-params_list MLwP} Projs (m\ p\ r\ sigma P\
501506
std.assert! (p = some P) "BUG: we build a class with an anonymous field",
502-
r = from (indt ClassInd) m (const P)) Factories,
507+
r = from (indt ClassInd) m (primitive P)) Factories,
503508
AllFactories = [factory-nparams (indt ClassInd) NParams | Factories],
504509

505510
if-verbose (coq.say {header} "declare type record"),

HB/structures.v

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,19 @@ pred class-def o:class.
109109

110110
%%%%% Builders %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111111

112-
% [from FN MN F] invariant:
113-
% "F : forall p1 .. pn T LMN, FN p1 .. pn T LMN1 -> MN c1 .. cm T LMN2" where
114-
% - LMN1 and LMN2 are sub lists of LMN
115-
% - c1 .. cm are terms built using p1 .. pn and T
112+
% [from FN MN B] invariant:
113+
% - B = gref F
114+
% "F : forall p1 .. pn T LMN, FN p1 .. pn T LMN1 -> MN c1 .. cm T LMN2" where
115+
% - LMN1 and LMN2 are sub lists of LMN
116+
% - c1 .. cm are terms built using p1 .. pn and T
117+
% - B = primitive (pr P N)
118+
% - as above but no parameters
116119
% - [factory-requires FN LMN]
117120
% [from _ M _] tests whether M is a declared mixin.
118-
pred from o:factoryname, o:mixinname, o:gref.
121+
kind gref-or-primitive type.
122+
type gref gref -> gref-or-primitive.
123+
type primitive pair projection int -> gref-or-primitive.
124+
pred from o:factoryname, o:mixinname, o:gref-or-primitive.
119125

120126
%%%%% Abbreviations %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121127

0 commit comments

Comments
 (0)