Skip to content

Commit b4d1844

Browse files
committed
use primproj for class->mixin builders
1 parent b0c98e2 commit b4d1844

File tree

10 files changed

+49
-21
lines changed

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.
@@ -104,12 +104,18 @@ factory-provides.base Factory Params T _RMLwP MLwP :- std.do! [
104104
std.map2 BL ML (factory-provides.one Params T) MLwP,
105105
].
106106

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

114120
pred extract-conclusion-params i:term, i:term, o:list term.
115121
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
@@ -270,6 +270,11 @@ coq.term->gref (app [primitive (proj N J),T|_]) GR :- !, std.do! [
270270
std.map2-filter Ps PPs (x\y\gr\sigma c\x = some c, y = some (pr N J), gr = const c) [GR],
271271
].
272272

273+
%hack/ fixup API
274+
:before "subst-fun:fail"
275+
coq.subst-fun L (primitive (proj _ _) as F) (app[F|L]).
276+
277+
273278
pred cs-pattern->name i:cs-pattern, o:string.
274279
cs-pattern->name cs-prod "prod".
275280
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
@@ -406,7 +406,7 @@ optimize-class-body _ _ (app L) (app L) [].
406406
pred declare-mixin-name i:term, o:term, o:list prop.
407407
declare-mixin-name (global _ as T) T [].
408408
declare-mixin-name T (global GR) [] :- mixin-mem T GR.
409-
declare-mixin-name T T [] :- coq.safe-dest-app T (global GR) _, not (from _ _ GR), not (get-option "hnf" tt).
409+
declare-mixin-name T T [] :- coq.safe-dest-app T (global GR) _, not (from _ _ (gref GR)), not (get-option "hnf" tt).
410410
declare-mixin-name T (global (const C)) [mixin-mem T (const C)] :- std.do! [
411411
Name is "HB_unnamed_mixin_" ^ {std.any->string {new_int}},
412412
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
@@ -309,6 +309,11 @@ export-operations Structure ProjSort ProjClass MLwP EX1 EX2 MLToExport :- std.do
309309
std.map LMwPToExport w-params_1 MLToExport,
310310
].
311311

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

322327
list-w-params_list TMLwP TML,
323328
std.map TML (from FC) Builders,
324-
std.map Builders (x\r\mk-app (global x) Params r) BuildersP,
329+
std.map Builders (mk-app-builder Params T) BuildersP,
325330

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

330335
(pi c\ sigma Mixes\
331-
std.map BuildersP (builder\r\ r = app[builder, T, c]) Mixes,
336+
std.map BuildersP (builder\r\ r = app[builder, c]) Mixes,
332337
mk-app KCHoles [T | Mixes] (ClassCoercion c)),
333338

334339
CoeBody = {{ fun (c : lp:Class) => lp:(ClassCoercion c) }}
@@ -497,12 +502,12 @@ declare-class+structure MLwP Sort
497502
std.assert-ok! (coq.typecheck-indt-decl ClassDeclaration) "declare-class: illtyped",
498503
(@primitive! => log.coq.env.add-indt ClassDeclaration ClassInd),
499504

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

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

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)