Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[refactor] instance declaration #376

Open
wants to merge 147 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
147 commits
Select commit Hold shift + click to select a range
567cee2
[refactor] separate add-mixin and make-mixin-canonical
gares Aug 1, 2023
64525c7
[instance] declare-instance -> declare-mixins-from-factory + declare-…
gares Aug 2, 2023
e0f7895
document exported-op
gares Aug 2, 2023
8c4071c
[instance] test for structure op as subject
gares Aug 2, 2023
6128f44
comment
gares Aug 2, 2023
1f8ca63
add comment
gares Aug 3, 2023
2ce532b
wip-wrapping
gares Aug 3, 2023
f12d772
minor changes
ptorrx Aug 3, 2023
d3273a4
minor changes in instance.elpi
ptorrx Aug 3, 2023
894aff0
introduced derived instance check in instance.elpi (as a hack); still…
ptorrx Aug 3, 2023
1ecb634
fixed bugs in instance.elpi, compiles
ptorrx Aug 4, 2023
cb3d53a
minor changes
ptorrx Aug 4, 2023
2fc6662
added and updated cmon_enriched_cat.v - this file contains three exam…
ptorrx Aug 10, 2023
c002312
fixed bug in cmonoid_enriched_cat.v
ptorrx Aug 24, 2023
46d5932
revised tests/cmonoid_enriched_cat.v
ptorrx Aug 28, 2023
ed74a82
cleanup
gares Sep 25, 2023
3e040b4
eta expand wrapped mixing in context
gares Sep 25, 2023
19fd228
minimal test for parameters
gares Sep 26, 2023
2d94c60
plan for auto wrapping
gares Sep 26, 2023
df1d865
added enriched_cat_case1.v - problematic
ptorrx Oct 3, 2023
ffce0b9
added enriched_cat_case2.v - which works, but wraps without depencies…
ptorrx Oct 3, 2023
f6e4458
added enriched_cat_case4.v
ptorrx Oct 3, 2023
9aebc2b
updated examples
ptorrx Oct 3, 2023
3ef5a1f
updated enriched_cat_case1.v, there are still problems
ptorrx Oct 3, 2023
96a6113
updated enriched_cat_case4.v, not finished but less problematic
ptorrx Oct 3, 2023
1292d1e
fix generation of wrapper-mixin when the mixin has deps
gares Oct 4, 2023
457817c
add more tests
gares Oct 4, 2023
66eb897
cleanup
gares Oct 4, 2023
41da96e
added enriched_cat_case5.v with more cases
ptorrx Oct 4, 2023
30debed
completed enriched_cat_case4.v
ptorrx Oct 4, 2023
7d113d0
note
gares Oct 4, 2023
d3dce62
validate structure declaration and wrap is the wrapper already exists
gares Oct 4, 2023
cad4f20
a bit unsure about this, it looks too smart in some cases
gares Oct 4, 2023
4e80aff
added enriched_cat_case6.v
ptorrx Oct 4, 2023
353b3fd
wip
gares Oct 4, 2023
d343316
fix rebase
gares Oct 5, 2023
063ffc3
fix failsafe structure inference
gares Oct 5, 2023
1d18979
fix test for wrapping
gares Oct 5, 2023
8f2d47d
cleanup
gares Oct 5, 2023
7e41346
cleanup
gares Oct 5, 2023
fb93fbe
option wrapper=off to instance
gares Oct 6, 2023
4c2742c
demo should not break abstractions
gares Oct 4, 2023
bd83789
test
gares Oct 6, 2023
d1c8070
moving category theory to theories
CohenCyril Oct 6, 2023
b73828c
defining pullbacks
CohenCyril Oct 6, 2023
2e25e5c
fix Makefile
gares Oct 6, 2023
cb9cfb0
colors are proofs
gares Oct 6, 2023
feb9249
HB.tag
gares Oct 6, 2023
a180918
remove ELIM hack
gares Oct 6, 2023
450cf7e
cleanup
gares Oct 6, 2023
79aba6c
fix test
gares Oct 6, 2023
8ac8c9d
note
gares Oct 6, 2023
2a39460
fix HB.tag
gares Oct 6, 2023
a2bf6d4
FIX: toposort will always be buggy ;-)
gares Oct 6, 2023
922d6b9
better eta expansion for failsafe structure elab
gares Oct 6, 2023
7005440
CAT: use HB.tag for pb_terminal (the wrapper is not autogen, but coul…
gares Oct 6, 2023
e24e3a1
use subject-lifter instead of structure-op
gares Oct 6, 2023
81fe41f
document toposort bug
gares Oct 6, 2023
da52021
Enter HB.from (from factories)
gares Oct 6, 2023
8d40177
fix rebase
gares Oct 9, 2023
d7007d3
added theories/encat.v (formalization of enriched categories, in prog…
ptorrx Oct 18, 2023
09618b3
updated theories/encat.v
ptorrx Oct 19, 2023
edb0313
updated theories/encat.v; definitions of enriched category and (tenta…
ptorrx Oct 20, 2023
02b0fc5
updated theories/encat.v
ptorrx Oct 22, 2023
75d8bfe
encat.v: fixed the definition of enriched category (reversed dependen…
ptorrx Oct 24, 2023
b415e67
encat.v: basic update of double categories
ptorrx Oct 24, 2023
de22884
encat.v: minor changes in comment
ptorrx Oct 24, 2023
5531d11
encat.v: added Cyril's definition of double categories
ptorrx Oct 24, 2023
b3dd85d
encat.v: revised parametrisation in enriched categories; revised defi…
ptorrx Oct 25, 2023
00c66a9
encat.v: minor changes
ptorrx Oct 25, 2023
31843f2
encat.v: updates to dcat transposition
ptorrx Oct 25, 2023
73a9732
encat.v: minor changes
ptorrx Oct 26, 2023
995fef1
encat.v: fixed unit functor problem (by changing the definition of un…
ptorrx Oct 26, 2023
b1f88ea
encat.v: adding composition - however, it seems more problematic than…
ptorrx Oct 26, 2023
d0014ce
encat.v: adding horizontal cell composition (tough)
ptorrx Oct 27, 2023
5c9bac2
updated encav.v
ptorrx Nov 3, 2023
3fb6dde
updated encav.v; flat version with 4 functors (source, target, horizo…
ptorrx Nov 3, 2023
e2536bc
updated encav.v; still missing: associator; product category to be fixed
ptorrx Nov 6, 2023
9c092de
updated encav.v; nlab-style definition of double categories; still mi…
ptorrx Nov 7, 2023
d158ffc
updated encav.v
ptorrx Nov 7, 2023
5220df5
updated encav.v; improved some definitions
ptorrx Nov 7, 2023
f7a0d99
updated encav.v; version with transpose
ptorrx Nov 8, 2023
6074c78
updated encav.v; improved a definition
ptorrx Nov 8, 2023
0d19f51
updated encav.v; minor changes
ptorrx Nov 8, 2023
64d354c
updated encav.v; added (alternative definitions of) horizontal 2-cell…
ptorrx Nov 9, 2023
1da3981
added encatA.v, older version for experiments on instantiation. minor…
ptorrx Nov 9, 2023
6a942fb
updated encav.v; in progress
ptorrx Nov 9, 2023
429865c
updated encav.v; discharged product precategory assumptions (still to…
ptorrx Nov 10, 2023
7f79278
added encatB.v: complete formalization of double categories, without …
ptorrx Nov 14, 2023
c26463b
encatB.v: cleaned up the definition of strict double category; the de…
ptorrx Nov 15, 2023
5faa745
encatB.v: improving the proofs
ptorrx Nov 16, 2023
a5e0e21
encatB.v: improving the notation
ptorrx Nov 16, 2023
d2e0580
encatB.v: renamed definition to be consistent with slide presentation
ptorrx Nov 19, 2023
6fdcfb5
added encatD.v (starting with internal categories)
ptorrx Nov 24, 2023
5cb88f9
updated encatD.v
ptorrx Nov 27, 2023
7a60a01
updated encatD.v, added definition of internal category based on oper…
ptorrx Nov 28, 2023
45565f9
updated encatD.v, complete definition of internal category based on NLab
ptorrx Nov 29, 2023
0fcd38c
updated encatD.v, minor changes
ptorrx Nov 29, 2023
a2757c4
mono/epi code works now
CohenCyril Nov 20, 2023
d42cc3e
walking span
CohenCyril Nov 23, 2023
dc4548e
rephrasing adjunctions (needs wrapping)
CohenCyril Nov 30, 2023
b00a244
internal categories parametrized with the ambiant one
CohenCyril Nov 30, 2023
4151369
updated encatD.v
ptorrx Dec 7, 2023
fc63ca4
updated encatD.v
ptorrx Dec 8, 2023
f661ea2
updated encatD.v, added encatD1.v; open problems in both
ptorrx Dec 8, 2023
6284697
updated encatD.v
ptorrx Dec 12, 2023
9560c9f
updated encatD.v
ptorrx Dec 13, 2023
b0444ce
added encatI.v, which merges new version of cat.v with internal categ…
Dec 14, 2023
f1325d7
updated encatI.v
Dec 15, 2023
527dd0f
updated encatI.v
Dec 18, 2023
c820234
updated encatI.v
Dec 18, 2023
1e0aa1b
updated encatI.v
Dec 19, 2023
eb7d3eb
updated encatI.v
Dec 19, 2023
9974744
updated encatI.v
Dec 21, 2023
f81757d
updated encatI.v; added encatI0.v as experiment
Dec 22, 2023
ab63881
updated encatI.v
ptorrx Jan 9, 2024
3459991
updated encatI.v
Jan 10, 2024
ca8bffd
updated encatI.v
Jan 11, 2024
82e72d6
updated encatI.v
Jan 11, 2024
f1ab058
updated encatI.v; complete definition of double cat based on internal…
Jan 12, 2024
9ff3448
updated encatI.v; cleaning up
Jan 12, 2024
d9c6869
updated encatI.v; merged in the strict double category direct definit…
Jan 12, 2024
41ad7c1
updated comment in encatI.v
Jan 12, 2024
40f762b
updated comment in encatI.v
Jan 12, 2024
c4724d7
changes in encatI0.v
Jan 16, 2024
6570167
encatI.v and encatI0.v now depend on cat.v
Jan 16, 2024
deb0352
updated encatI.v
Jan 17, 2024
11e40e2
updated encatI.v
Jan 18, 2024
4292494
updated encatI.v
Jan 19, 2024
b21e282
updated encatI.v
Jan 19, 2024
2167b3d
restructuring
ptorrx Jan 18, 2024
a2cc722
restructuring
ptorrx Jan 18, 2024
e84c91f
updated encatI.v
Jan 19, 2024
3564fd6
updated dependencies
Jan 19, 2024
1ce5b11
updated dependencies
Jan 19, 2024
d94c19f
updated encatI.v
Jan 19, 2024
d88dd20
wip
gares Jan 29, 2024
b9cb11f
wip
gares Jan 29, 2024
f2590ab
unsafe(univ) option
gares Jan 31, 2024
e8a680c
wip
gares Jan 31, 2024
18ca7ba
wip
gares Feb 2, 2024
59af016
wip
gares Feb 2, 2024
e19ed85
wip
gares Mar 4, 2024
10b3fb0
wip
gares Mar 4, 2024
af2989f
wip
gares Mar 4, 2024
0cf1c4c
wip
gares Mar 4, 2024
e85441c
wip
gares Mar 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions HB/common/database.elpi
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,20 @@ toposort-proj Proj ES In Out :- !, toposort-proj.acc Proj ES [] In Out.
pred topo-find i:B, o:A.
pred toposort-proj.acc i:(A -> B -> prop), i:list (pair B B), i:list B, i:list A, o:list A.
toposort-proj.acc _ ES Acc [] Out :- !,
std.map {std.toposort ES Acc} topo-find Out.
std.map {std.toposort ES Acc} topo-find-all Out.
toposort-proj.acc Proj ES Acc [A|In] Out :- std.do![
Proj A B,
topo-find B A => toposort-proj.acc Proj ES [B|Acc] In Out
].

pred topo-find-all i:B, o:A.
topo-find-all B A :- std.do! [
std.findall (topo-find B C_) L,
% if there were dusplicates, we ensure we keep the most instantiated, eg
% (triple m [X,Y] t) v.s. (triple m [a,b] t)
std.assert! (std.forall L (x\ x = topo-find B A)) "topofind bad",
].

% Classes can be topologically sorted according to the subclass relation
pred toposort-classes.mk-class-edge i:prop, o:pair classname classname.
toposort-classes.mk-class-edge (sub-class C1 C2 _ _) (pr C2 C1).
Expand Down Expand Up @@ -438,11 +446,14 @@ structure-nparams Structure NParams :-
class-def (class Class Structure _),
factory-nparams Class NParams.

pred factory?-split i:term, o:factoryname, o:list term, o:term, o:list term.
factory?-split (app[global GR|Args]) F [global GR|Params] T Rest :-
factory-alias->gref GR F, factory-nparams F NP, !,
std.split-at NP Args Params [T|Rest].

pred factory? i:term, o:w-args factoryname.
factory? S (triple F Params T) :-
not (var S), !,
safe-dest-app S (global GR) Args, factory-alias->gref GR F, factory-nparams F NP, !,
std.split-at NP Args Params [T|_].
factory?-split S F [_|Params] T _.

% [find-max-classes Mixins Classes] states that Classes is a list of classes
% which contain all the mixins in Mixins.
Expand All @@ -462,3 +473,8 @@ find-max-classes [M|Mixins] [C|Classes] :-
].
find-max-classes [M|_] _ :- coq.error "HB: cannot find a class containing mixin" M.

pred is-subject-lifter i:term, o:int, o:classname.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong if the lifter is casted: (hom : T -> T -> Type) hides (let x : T -> T -> Type := hom in x)
and this code should cross/reduce the let

is-subject-lifter (global (const C)) N Class :- exported-op M _ C, wrapper-mixin _ (const C) _, factory-nparams M N, mixin-first-class M Class.
is-subject-lifter (app[global (const C)|_]) N Class :- exported-op M _ C, wrapper-mixin _ (const C) _, factory-nparams M N, mixin-first-class M Class.
is-subject-lifter (global GR) N Class :- tag GR Class N, wrapper-mixin _ GR _.
is-subject-lifter (app[global GR|_]) N Class :- tag GR Class N, wrapper-mixin _ GR _.
6 changes: 6 additions & 0 deletions HB/common/phant-abbreviation.elpi
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ add-abbreviation N (private.phant-term AL T1) C Abbrev :- std.do! [
private.build-abbreviation 0 (global (const C)) AL NParams AbbrevT,
@global! => log.coq.notation.add-abbreviation N NParams AbbrevT tt Abbrev,
].
pred add-abbreviation2 i:gref, i:string, i:phant-term, o:constant, o:abbreviation.
add-abbreviation2 GR N (private.phant-term _ _) C Abbrev :- std.do! [
NC is "phant_" ^ N,
log.coq.env.add-const-noimplicits NC (global GR) _ @transparent! C,
@global! => log.coq.notation.add-abbreviation N 0 (global (const C)) tt Abbrev,
].

% [of-gref WithCopy GR RealMixinArgs PT]
% builds a phant-term taking all parameters,
Expand Down
28 changes: 28 additions & 0 deletions HB/common/synthesis.elpi
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ infer-all-args-let Ps T GR X Diag :- std.do! [
private.instantiate-all-args-let FT T X Diag,
].

pred try-infer-all-args-let i:list term, i:term, i:gref, o:term.
try-infer-all-args-let Ps T GR X :- std.do! [
coq.env.typeof GR Ty,
coq.mk-eta (-1) Ty (global GR) EtaF,
coq.subst-fun {std.append Ps [T]} EtaF FT,
private.try-instantiate-all-args-let FT T X,
].

% [assert!-infer-mixin TheType M Out] infers one mixin M on TheType and
% aborts with an error message if the mixin cannot be inferred
Expand Down Expand Up @@ -103,6 +110,17 @@ under-mixin-src-from-factory.do! TheType TheFactory LP :- std.do! [
MLClauses => std.do! LP
].


% Given TheType makes the provided list of mixins and instances
% available for inference.
pred under-these-mixin-src.do! i:term, i:list mixinname, i:list constant, o:list prop, i:list prop.
under-these-mixin-src.do! TheType ML TheMixins ClausesHas LP :- std.do! [
std.map2 ML TheMixins (m\mi\c\ c = mixin-src TheType m (global (const mi))) MLClauses,
std.map-filter MLClauses mixin-src->has-mixin-instance ClausesHas,
MLClauses => std.do! LP
].


% Given TheType and a factory instance (on it), builds all the *new* mixins
% provided by the factory available for and passes them to the given
% continuation
Expand Down Expand Up @@ -242,6 +260,7 @@ instantiate-all-these-mixin-args (fun _ Tm F) T ML R :-
coq.safe-dest-app Tm (global TmGR) _,
factory-alias->gref TmGR M,
std.mem! ML M,
factory? Tm (triple _ _ Subj), Subj = T, % check the subject is T (do not pass T to factory?)
!,
mixin-for T M X, !,
instantiate-all-these-mixin-args (F X) T ML R.
Expand All @@ -261,6 +280,15 @@ instantiate-all-args-let (fun N Tm F) T (let N Tm X R) Diag :- !, std.do! [
].
instantiate-all-args-let F _ F ok.

pred try-instantiate-all-args-let i:term, i:term, o:term.
try-instantiate-all-args-let (fun N Tm F) T (let N Tm X R) :- !, std.do! [
coq.safe-dest-app Tm (global TmGR) _,
factory-alias->gref TmGR M,
(mixin-for T M X ; true),
(@pi-def N Tm X m\ try-instantiate-all-args-let (F m) T (R m)),
].
try-instantiate-all-args-let F _ F.

% [structure-instance->mixin-srcs TheType Structure] finds a CS instance for
% Structure on TheType (if any) and builds mixin-src clauses for all the mixins
% which can be candidates from that class instance. It finds instances which are
Expand Down
2 changes: 2 additions & 0 deletions HB/common/utils-synterp.elpi
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ with-attributes P :-
att "primitive" bool,
att "non_forgetful_inheritance" bool,
att "hnf" bool,
att "wrapper" bool,
att "unsafe.univ" bool,
] Opts, !,
Opts => (save-docstring, P).

Expand Down
53 changes: 51 additions & 2 deletions HB/common/utils.elpi
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ gref->modname GR NComp Sep ModName :-
std.length Path Len,
if (Len >= NComp) true (coq.error "Not enough enclosing modules for" {coq.gref->string GR}),
std.take NComp Mods L,
std.string.concat Sep {std.rev L} ModName.
std.string.concat Sep {std.rev [{std.any->string {new_int}}|L]} ModName.
pred gref->modname-label i:gref, i:int, i:string, o:string.
gref->modname-label GR NComp Sep ModName :-
coq.gref->path GR Path,
Expand Down Expand Up @@ -293,7 +293,7 @@ pack? (indc K) C :-
coq.env.indc K _ _ _ KTy, prod-last-gref KTy (indt I), % TODO: use new API
class-def (class C (indt I) _).

pred distribute-w-params i:list-w-params A, o:list (one-w-params A).
pred distribute-w-params i:w-params (list A), o:list (w-params A).
distribute-w-params (w-params.cons N T F) L :-
pi x\ distribute-w-params (F x) (L1 x), std.map (L1 x) (bind-cons N T x) L.
distribute-w-params (w-params.nil N T F) L :-
Expand All @@ -315,6 +315,46 @@ re-enable-id-phant T T1 :-
(pi f1 f2 t v\ copy {{lib:@hb.ignore_disabled lp:t lp:f1 lp:v lp:f2}} {{lib:@hb.ignore lp:t lp:v}} :- !) =>
copy T T1.

pred disable-id-phant-indt-decl i:indt-decl, o:indt-decl.
disable-id-phant-indt-decl D D1 :-
(pi fresh fresh1 t v\ copy {{lib:@hb.id lp:t lp:v}} {{lib:@hb.id_disabled lp:t lp:fresh lp:v lp:fresh1}} :- !) =>
(pi fresh fresh1 t v\ copy {{lib:@hb.ignore lp:t lp:v}} {{lib:@hb.ignore_disabled lp:t lp:fresh lp:v lp:fresh1}} :- !) =>
copy-indt-decl D D1.

pred re-enable-id-phant-indt-decl i:indt-decl, o:indt-decl.
re-enable-id-phant-indt-decl D D1 :-
(pi f1 f2 t v\ copy {{lib:@hb.id_disabled lp:t lp:f1 lp:v lp:f2}} {{lib:@hb.id lp:t lp:v}} :- !) =>
(pi f1 f2 t v\ copy {{lib:@hb.ignore_disabled lp:t lp:f1 lp:v lp:f2}} {{lib:@hb.ignore lp:t lp:v}} :- !) =>
copy-indt-decl D D1.


pred failsafe-structure-inference i:term, o:term.
failsafe-structure-inference T T1 :-
(pi T T2 F_Params F_Params1 Args Args1 Subject Subject1 NP ArgsOp ArgsOp1 OP S\
copy T T2 :-
factory?-split T _ F_Params Subject Args,
std.map F_Params copy F_Params1,
std.map Args copy Args1,
is-subject-lifter Subject NP Class,
coq.safe-dest-app Subject OP ArgsOp,
std.nth NP ArgsOp S,
(var S ; name S), % TODO: should be the subject of the structure, not a random name
!,
eta-structure-record S NP Class ArgsOp ArgsOp1,
coq.mk-app OP ArgsOp1 Subject1,
coq.mk-app (app F_Params1) [Subject1|Args1] T2) =>
copy T T1.

pred eta-structure-record i:term, i:int, i:classname, i:list term, o:list term.
eta-structure-record S NP Class L L1 :-
std.split-at NP L Params [_|Rest],
class-def (class Class Structure _),
get-constructor Structure K,
std.map Params copy Params1,
std.map Rest copy Rest1,
coq.mk-app {coq.env.global K} {std.append Params1 [S,_]} EtaS,
std.append Params1 [EtaS|Rest1] L1.

pred prod-last i:term, o:term.
prod-last (prod N S X) Y :- !, @pi-decl N S x\ prod-last (X x) Y.
prod-last X X :- !.
Expand All @@ -329,3 +369,12 @@ saturate-type-constructor T ET :-
coq.typecheck T TH ok,
coq.count-prods TH N,
coq.mk-app T {coq.mk-n-holes N} ET.

pred with-unsafe-univ i:prop.
with-unsafe-univ P :- get-option "unsafe.univ" tt, !,
coq.option.get ["Universe","Checking"] Old,
coq.option.set ["Universe","Checking"] (coq.option.bool ff),
P,
coq.option.set ["Universe","Checking"] Old.
with-unsafe-univ P :- P.

46 changes: 44 additions & 2 deletions HB/context.elpi
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,38 @@ namespace private {
% to the corresponding mixin using mixin-for
pred postulate-mixin i:term, i:w-args mixinname, i:triple (list constant) (list prop) (list (w-args mixinname)),
o:triple (list constant) (list prop) (list (w-args mixinname)).
postulate-mixin TheType (triple M Ps T) (triple CL MSL MLwP) (triple OutCL [MC|MSL] [NewMwP|MLwP]) :- wrapper-mixin M _ _, !, MSL => std.do! [
NameVar is "local_mixin_private_" ^ {gref->modname M 2 "_"},
NameMixin is "local_mixin_" ^ {gref->modname M 2 "_"},

if-verbose (coq.say "HB: postulate and wrap" NameVar "on" {coq.term->string T}),

synthesis.infer-all-gref-deps Ps T M TySkel,
% was synthesis.infer-all-mixin-args Ps T M TySkel,
% if-verbose (coq.say "HB: postulate-mixin checking" TySkel),
% std.assert-ok! (coq.typecheck Ty _) "postulate-mixin: Ty illtyped",
std.assert-ok! (coq.elaborate-ty-skeleton TySkel _ Ty)
"postulate-mixin: Ty illtyped",

Ty = app[global M|Args],
factory-constructor M K,
coq.mk-app (global K) Args KArgs,
std.assert-ok! (coq.typecheck KArgs {{ lp:VarTy -> _ }}) "brrr",

log.coq.env.add-section-variable-noimplicits NameVar VarTy V,

coq.mk-app KArgs [global (const V)] TheMixin,

log.coq.env.add-const-noimplicits NameMixin TheMixin Ty @transparent! C,

factory? Ty NewMwP,

declare-instances-from-postulated-mixin TheType M T C MC NewCL,

std.append CL NewCL OutCL,

].

postulate-mixin TheType (triple M Ps T) (triple CL MSL MLwP) (triple OutCL [MC|MSL] [NewMwP|MLwP]) :- MSL => std.do! [
Name is "local_mixin_" ^ {gref->modname M 2 "_"},

Expand All @@ -69,12 +101,22 @@ postulate-mixin TheType (triple M Ps T) (triple CL MSL MLwP) (triple OutCL [MC|M
std.assert-ok! (coq.elaborate-ty-skeleton TySkel _ Ty)
"postulate-mixin: Ty illtyped",
log.coq.env.add-section-variable-noimplicits Name Ty C,

factory? Ty NewMwP,

declare-instances-from-postulated-mixin TheType M T C MC NewCL,

std.append CL NewCL OutCL,

].

pred declare-instances-from-postulated-mixin i:term, i:mixinname, i:term, i:constant, o:prop, o:(list constant).
declare-instances-from-postulated-mixin TheType M T C MC NewCL :- std.do! [

MC = mixin-src T M (global (const C)),
MC => get-option "local" tt =>
instance.declare-all TheType {findall-classes-for [M]} NewCSL,
std.map NewCSL snd NewCL,
std.append CL NewCL OutCL
].
].

}}
57 changes: 56 additions & 1 deletion HB/factory.elpi
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,53 @@ declare-asset Arg AssetKind :- std.do! [
)
].

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% auxiliary code for wrapper-mixin

pred extract_from_record_decl i: (term -> gref -> prop), i:indt-decl, o:gref.
extract_from_record_decl P (parameter ID _ Ty R) Out :-
@pi-parameter ID Ty p\
extract_from_record_decl P (R p) Out.
extract_from_record_decl P (record _ _ _ (field _ _ Ty (x\end-record))) GR0 :-
P Ty GR0.

pred extract_from_rtty i: (term -> gref -> prop), i: term, o:gref.
extract_from_rtty P (prod N Ty TF) Out1 :-
@pi-decl N Ty p\
extract_from_rtty P (TF p) Out1.
extract_from_rtty P Ty Gr :- P Ty Gr.

pred xtr_fst_op i:term, o:gref.
xtr_fst_op Ty Gr1 :-
Ty = (app [global Gr0| _]),
factory-alias->gref Gr0 Gr1.

pred xtr_snd_op i:term, o:gref.
xtr_snd_op Ty Gr :-
% TODO: use factory? from database.elpi
Ty = (app [global Gr0| Args]),
factory-alias->gref Gr0 Gr1,
factory-nparams Gr1 N,
std.nth N Args (app [global Gr| _]).

pred extract_wrapped i:indt-decl, o:gref.
extract_wrapped In Out :-
extract_from_record_decl (extract_from_rtty xtr_fst_op) In Out.

pred extract_subject i:indt-decl, o:gref.
extract_subject In Out :-
extract_from_record_decl (extract_from_rtty xtr_snd_op) In Out.

pred wrapper_mixin_aux i:gref, o:gref, o:gref.
wrapper_mixin_aux XX Gr1 Gr2 :-
XX = (indt I),
coq.env.indt-decl I D,
extract_subject D Gr1,
extract_wrapped D Gr2.

%%% end auxiliary code for wrapper-mixin
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

pred declare-mixin-or-factory i:list prop, i:list constant, i:list term, i:term,
i:term, i:record-decl, i:list-w-params factoryname, i:id, i:asset.
declare-mixin-or-factory MixinSrcClauses SectionCanonicalInstance
Expand All @@ -229,6 +276,8 @@ declare-mixin-or-factory MixinSrcClauses SectionCanonicalInstance
RDeclSkel = record "axioms_" Sort1 Kname Fields,
std.assert-ok! (coq.elaborate-indt-decl-skeleton RDeclSkel RDecl) "record declaration illtyped",

% scheck-no-mixin-or-factory-occurs RDecl,

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


Expand All @@ -255,6 +304,12 @@ declare-mixin-or-factory MixinSrcClauses SectionCanonicalInstance

% TODO: should this be in the Exports module?

% if the wrapper option is on, build the wrapper clause
if (get-option "wrapper" tt)
((wrapper_mixin_aux (indt R) NSbj WMxn),
(WrapperClauses = [wrapper-mixin (indt R) NSbj WMxn]))
(WrapperClauses = []),

if-verbose (coq.say {header} "declare notation Build"),

GRDepsClauses => phant.of-gref ff GRK [] PhGRK,
Expand All @@ -271,7 +326,7 @@ declare-mixin-or-factory MixinSrcClauses SectionCanonicalInstance
if-verbose (coq.say {header} "start module Exports"),

log.coq.env.begin-module "Exports" none,
std.flatten [Clauses, GRDepsClauses, [
std.flatten [Clauses, GRDepsClauses, WrapperClauses, [
factory-constructor (indt R) GRK,
factory-nparams (indt R) NParams,
factory-builder-nparams BuildConst NParams,
Expand Down
Loading
Loading