@@ -204,9 +204,6 @@ gref->modname GR ModName :-
204
204
coq.gref->path GR Path,
205
205
if (std.rev Path [_,ModName|_]) true (coq.error "No enclosing module for " GR).
206
206
207
- pred term->modname i:structure, o:id.
208
- term->modname T ModName :- gref->modname {term->gref T} ModName.
209
-
210
207
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
211
208
% function to predicate generic constructions %
212
209
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -375,6 +372,14 @@ pred mixin-src_src i:prop, o:term.
375
372
mixin-src_src (mixin-src _ _ S) S.
376
373
mixin-src_src (pi c\ mixin-src _ _ c :- F c) T :- F T. % this is a bit pulp...
377
374
375
+ pred class_name i:class, o:classname.
376
+ class_name (class N _ _) N.
377
+
378
+ pred class-def_name i:prop, o:classname.
379
+ class-def_name (class-def (class N _ _)) N.
380
+
381
+ pred classname->def i:classname, o:class.
382
+ classname->def CN (class CN S ML) :- class-def (class CN S ML), !.
378
383
379
384
pred extract-builder i:prop, o:builder.
380
385
extract-builder (builder-decl B) B.
@@ -466,20 +471,21 @@ toposort-proj.acc Proj ES Acc [A|In] Out :- std.do![
466
471
].
467
472
468
473
% Classes can be topologically sorted according to the subclass relation
469
- pred toposort-classes.mk-class-edge i:prop, o:pair class class .
474
+ pred toposort-classes.mk-class-edge i:prop, o:pair classname classname .
470
475
toposort-classes.mk-class-edge (sub-class C1 C2) (pr C2 C1).
471
- pred toposort-classes i:list class , o:list class .
476
+ pred toposort-classes i:list classname , o:list classname .
472
477
toposort-classes In Out :- std.do! [
473
478
std.findall (sub-class C1_ C2_) SubClasses,
474
479
std.map SubClasses toposort-classes.mk-class-edge ES,
475
480
toposort ES In Out,
476
481
].
477
482
478
483
pred findall-classes o:list class.
479
- findall-classes CLSorted :- std.do! [
484
+ findall-classes CLSortedDef :- std.do! [
480
485
std.findall (class-def C_) All,
481
- std.map All (x\r\ x = class-def r) CL,
482
- toposort-classes CL CLSorted
486
+ std.map All class-def_name CL,
487
+ toposort-classes CL CLSorted,
488
+ std.map CLSorted classname->def CLSortedDef,
483
489
].
484
490
485
491
pred findall-builders o:list builder.
@@ -534,55 +540,54 @@ findall-newjoins CurrentClass AllSuper TodoJoins :-
534
540
535
541
% [get-structure-coercion S1 S2 F] finds the coecion F from the structure S1 to S2
536
542
pred get-structure-coercion i:structure, i:structure, o:term.
537
- get-structure-coercion (global S _) (global T _) FU :-
543
+ get-structure-coercion S T FU :-
538
544
coq.coercion.db-for (grefclass S) (grefclass T) L,
539
545
if (L = [pr F _]) true (coq.error "No one step coercion from" S "to" T),
540
546
coq.env.global F FU.
541
547
542
- % TODO
543
548
pred get-structure-sort-projection i:structure, o:term.
544
- get-structure-sort-projection T Proj :-
545
- safe-dest-app T (global (indt S) _) Params,
549
+ get-structure-sort-projection (indt S) Proj :- !,
546
550
coq.CS.canonical-projections S L,
547
551
if (L = [some P, _]) true (coq.error "No canonical sort projection for" S),
548
- mk-app {coq.env.global (const P)} Params Proj.
552
+ coq.env.global (const P) Proj.
553
+ get-structure-sort-projection S _ :- coq.error "get-structure-sort-projection: not a structure" S.
549
554
550
555
pred get-structure-class-projection i:structure, o:term.
551
- get-structure-class-projection (global ( indt S) _) T :-
556
+ get-structure-class-projection (indt S) T :- !,
552
557
coq.CS.canonical-projections S L,
553
558
if (L = [_, some P]) true (coq.error "No canonical class projection for" S),
554
559
coq.env.global (const P) T.
560
+ get-structure-class-projection S _ :- coq.error "get-structure-class-projection: not a structure" S.
555
561
556
- pred get-constructor i:term, o:gref.
557
- get-constructor (global (indt R) UI as S) (indc K) :- !,
558
- if (coq.env.indt R UI _ _ _ _ [K] _) true (coq.error "Not a record" S).
562
+ pred get-constructor i:gref, o:gref.
563
+ get-constructor (indt R) (indc K) :- !,
564
+ if (coq.env.indt R _ _ _ _ _ [K] _) true (coq.error "Not a record" R).
565
+ get-constructor I _ :- coq.error "get-constructor: not an inductive" I.
559
566
560
- pred safe-head i:term, o:term.
561
- safe-head (prod N T Body) Hd :-
562
- @pi-decl N T x\
563
- safe-head (Body x) (Hd' x),
564
- std.assert! (Hd' x = Hd) "safe-head: the head symbol is a bound variable".
565
- safe-head T Hd :- whd1 T T', safe-head T' Hd.
566
- safe-head T Hd :- safe-dest-app T Hd _.
567
+ pred head-gref-under-prods i:term, o:gref.
568
+ head-gref-under-prods (prod N T Body) Hd :-
569
+ @pi-decl N T x\ head-gref-under-prods (Body x) Hd.
570
+ head-gref-under-prods T Hd :- whd1 T T', head-gref-under-prods T' Hd.
571
+ head-gref-under-prods T Hd :- safe-dest-app T (global Hd _) _.
567
572
568
573
%% finding for locally defined structures
569
- pred get-cs-structure i:cs-instance, o:term .
570
- get-cs-structure (cs-instance _ _ (global Inst UI) ) Struct :- std.do! [
571
- coq.env.typeof Inst UI InstTy,
572
- safe- head InstTy Struct
574
+ pred get-cs-structure i:cs-instance, o:structure .
575
+ get-cs-structure (cs-instance _ _ Inst) Struct :- std.do! [
576
+ coq.env.typeof Inst _ InstTy,
577
+ head-gref-under-prods InstTy Struct
573
578
].
574
579
575
580
pred has-cs-instance i:gref, i:cs-instance.
576
581
has-cs-instance GTy (cs-instance _ (cs-gref GTy) _).
577
582
578
- pred get-local-structures i:term, o:list term .
583
+ pred get-local-structures i:term, o:list structure .
579
584
get-local-structures TyTrm StructL :- std.do! [
580
585
std.filter {coq.CS.db} (has-cs-instance {term->gref TyTrm}) DBGTyL,
581
586
std.map DBGTyL get-cs-structure RecL,
582
587
std.filter RecL is-structure StructL
583
588
].
584
589
585
- pred local-cs? i:term, i:term .
590
+ pred local-cs? i:term, i:structure .
586
591
local-cs? TyTerm Struct :-
587
592
get-local-structures TyTerm StructL,
588
593
std.mem! StructL Struct.
@@ -679,16 +684,17 @@ phant-fun-unify-mixin T N Ty PF Out :- !, std.do! [
679
684
phant-fun-implicit N Ty PFM Out
680
685
].
681
686
682
- % [phant-fun-struct T SI PF PSF] states that PSF is a phant-term
687
+ % [phant-fun-struct T SI SIParams PF PSF] states that PSF is a phant-term
683
688
% which postulate a structure [s : SI] such that [T = sort s]
684
689
% and then outputs [PF s]
685
- pred phant-fun-struct i:term, i:name, i:term, i:(term -> phant-term), o:phant-term.
686
- phant-fun-struct T Name SI PF Out :- std.do! [
690
+ pred phant-fun-struct i:term, i:name, i:structure, i:list term, i:(term -> phant-term), o:phant-term.
691
+ phant-fun-struct T Name SI Params PF Out :- std.do! [
687
692
get-structure-sort-projection SI Sort,
693
+ mk-app {coq.env.global SI} Params SITerm,
688
694
% Msg = {{lib:hb.nomsg}},
689
- Msg = {{lib:hb.some (lib:hb.pair "is not canonically a"%string lp:SI )}},
690
- (@pi-decl Name SI s\ phant-fun-unify Msg T {mk-app Sort [s]} (PF s) (UnifSI s)),
691
- phant-fun-implicit Name SI UnifSI Out
695
+ Msg = {{lib:hb.some (lib:hb.pair "is not canonically a"%string lp:SITerm )}},
696
+ (@pi-decl Name SITerm s\ phant-fun-unify Msg T {mk-app Sort [s]} (PF s) (UnifSI s)),
697
+ phant-fun-implicit Name SITerm UnifSI Out
692
698
].
693
699
694
700
% [builder->term Params T Src Tgt MF] provides a term which is
@@ -977,7 +983,7 @@ pred mk-phant-term.mixins i:term, i:classname, i:phant-term,
977
983
i:list term, i:name, i:term, i:(term -> list (w-args mixinname)), o:phant-term.
978
984
mk-phant-term.mixins T CN PF Params N Ty MLwA Out :- std.do! [
979
985
class-def (class CN SI _),
980
- mk-app SI Params SIParams,
986
+ mk-app {coq.env.global SI} Params SIParams,
981
987
NoMsg = {{lib:hb.nomsg}},
982
988
coq.name-suffix N "local" Nlocal,
983
989
(@pi-decl Nlocal Ty t\ sigma SK KC ML\ std.do! [
@@ -989,12 +995,12 @@ mk-phant-term.mixins T CN PF Params N Ty MLwA Out :- std.do! [
989
995
under-mixins.then (MLwA t) (phant-fun-unify-mixin T) (mk-phant-term.mixins.aux t Params c CN PF) PF2,
990
996
phant-fun-unify NoMsg s {mk-app SKPT [c]} PF2 (PFU t s c)])
991
997
]),
992
- Out = {phant-fun-struct T `s` SIParams s\
998
+ Out = {phant-fun-struct T `s` SI Params s\
993
999
{phant-fun-implicit `c` ClassTy (PFU T s)}}
994
1000
].
995
1001
996
1002
mk-phant-term.mixins.aux T Params C CN PF X :- std.do![
997
- get-constructor {coq.env.global CN} KC,
1003
+ get-constructor CN KC,
998
1004
mgref->term Params T KC KCM,
999
1005
phant-fun-unify {{lib:hb.nomsg}} KCM C PF X,
1000
1006
].
@@ -1100,24 +1106,24 @@ params->holes (w-params.cons _ _ F) [_|PS] :- pi x\ params->holes (F x) PS.
1100
1106
pred declare-instances i:term, i:list class.
1101
1107
declare-instances T [class Class Struct MLwP|Rest] :-
1102
1108
params->holes MLwP Params,
1103
- get-constructor {coq.env.global Class} KC,
1109
+ get-constructor Class KC,
1104
1110
1105
1111
if (not(local-cs? T Struct))
1106
1112
true % we build it
1107
1113
(if-verbose (coq.say "HB: skipping alreay existing"
1108
- {coq.term ->string Struct} "instance on"
1114
+ {nice-gref ->string Struct} "instance on"
1109
1115
{coq.term->string T}),
1110
1116
fail),
1111
1117
1112
1118
if (mgref->term Params T KC KCApp)
1113
- (if-verbose (coq.say "HB: we can build a" {coq.term ->string Struct} "on"
1119
+ (if-verbose (coq.say "HB: we can build a" {nice-gref ->string Struct} "on"
1114
1120
{coq.term->string T}))
1115
1121
fail,
1116
1122
1117
1123
!,
1118
1124
term->gref T TGR,
1119
1125
coq.gref->id TGR TID,
1120
- Name is TID ^ "_is_a_" ^ {term ->modname Struct},
1126
+ Name is TID ^ "_is_a_" ^ {gref ->modname Struct},
1121
1127
1122
1128
if-verbose (coq.say "HB: declare canonical structure instance" Name),
1123
1129
@@ -1261,10 +1267,10 @@ clean-op-ty [exported-op _ Po C|Ops] S T1 T2 :-
1261
1267
1262
1268
clean-op-ty Ops S T1 T2.
1263
1269
1264
- pred operation-body-and-ty i:list prop, i:constant, i:term , i:term, i:term,
1270
+ pred operation-body-and-ty i:list prop, i:constant, i:structure , i:term, i:term,
1265
1271
i:list term, i:term, i:w-args A, o:pair term term.
1266
1272
operation-body-and-ty EXI Poperation Struct Psort Pclass Params _T (triple _ Params _) (pr Bo Ty) :- std.do! [
1267
- mk-app Struct Params StructType,
1273
+ mk-app {coq.env.global Struct} Params StructType,
1268
1274
mk-app Psort Params PsortP,
1269
1275
mk-app Pclass Params PclassP,
1270
1276
Bo = fun `s` StructType Body,
@@ -1285,7 +1291,7 @@ operation-body-and-ty EXI Poperation Struct Psort Pclass Params _T (triple _ Par
1285
1291
% same operation out of the package structure (out of the class field of the
1286
1292
% structure). We also provide all the other mixin dependencies (other misins)
1287
1293
% of the package structure.
1288
- pred export-1-operation i:mixinname, i:term , i:term, i:term, i:one-w-params mixinname, i:option constant, i:list prop, o:list prop.
1294
+ pred export-1-operation i:mixinname, i:structure , i:term, i:term, i:one-w-params mixinname, i:option constant, i:list prop, o:list prop.
1289
1295
export-1-operation _ _ _ _ _ none EX EX :- !. % not a projection, no operation
1290
1296
export-1-operation M Struct Psort Pclass MwP (some Poperation) EXI EXO :- !, std.do! [
1291
1297
coq.gref->id (const Poperation) Name,
@@ -1304,7 +1310,7 @@ export-1-operation M Struct Psort Pclass MwP (some Poperation) EXI EXO :- !, std
1304
1310
].
1305
1311
1306
1312
% Given a list of mixins, it exports all operations in there
1307
- pred export-operations.aux i:term , i:term, i:term, i:one-w-params mixinname, i:list prop, o:list prop.
1313
+ pred export-operations.aux i:structure , i:term, i:term, i:one-w-params mixinname, i:list prop, o:list prop.
1308
1314
export-operations.aux Struct ProjSort ProjClass MwP EX1 EX2 :- !, std.do! [
1309
1315
w-params_1 MwP (indt M),
1310
1316
coq.CS.canonical-projections M Poperations,
@@ -1315,7 +1321,7 @@ pred mixin-not-already-declared i:one-w-params mixinname.
1315
1321
mixin-not-already-declared MwP :-
1316
1322
w-params_1 MwP M, not(mixin-first-class M _), M = indt _.
1317
1323
1318
- pred export-operations i:term , i:term, i:term, i:list-w-params mixinname, i:list prop, o:list prop, o:list mixinname.
1324
+ pred export-operations i:structure , i:term, i:term, i:list-w-params mixinname, i:list prop, o:list prop, o:list mixinname.
1319
1325
export-operations Structure ProjSort ProjClass MLwP EX1 EX2 MLToExport :- std.do! [
1320
1326
distribute-w-params MLwP LMwP,
1321
1327
std.filter LMwP mixin-not-already-declared LMwPToExport,
@@ -1337,7 +1343,7 @@ mk-coe-class-body FC TC TMLwP Params T _ CoeBody :- std.do! [
1337
1343
std.map TML (from FC) Builders,
1338
1344
std.map Builders (x\r\sigma t\ coq.env.global x t, mk-app t Params r) BuildersP,
1339
1345
1340
- mk-app {coq.env.global {get-constructor {coq.env.global TC} }}
1346
+ mk-app {coq.env.global {get-constructor TC }}
1341
1347
{coq.mk-n-holes {factory-nparams TC}} KCHoles,
1342
1348
1343
1349
(pi c\ sigma Mixes\
@@ -1360,10 +1366,10 @@ pred mk-coe-structure-body
1360
1366
mk-coe-structure-body StructureF StructureT TC Coercion SortProjection ClassProjection
1361
1367
Params _T _ SCoeBody :- std.do! [
1362
1368
1363
- mk-app StructureF Params StructureP,
1364
- mk-app SortProjection Params SortP,
1365
- mk-app ClassProjection Params ClassP,
1366
- mk-app Coercion Params CoercionP,
1369
+ mk-app {coq.env.global StructureF} Params StructureP,
1370
+ mk-app SortProjection Params SortP,
1371
+ mk-app ClassProjection Params ClassP,
1372
+ mk-app Coercion Params CoercionP,
1367
1373
1368
1374
mk-app {coq.env.global {get-constructor StructureT}}
1369
1375
{coq.mk-n-holes {factory-nparams TC}} PackPH,
@@ -1377,12 +1383,12 @@ mk-coe-structure-body StructureF StructureT TC Coercion SortProjection ClassProj
1377
1383
% from C1 to C2 given P1 P2 the two projections from the structure of C1
1378
1384
pred declare-coercion i:term, i:term, i:class, i:class.
1379
1385
declare-coercion SortProjection ClassProjection
1380
- (class FC StructureF FMLwP as FCDef ) (class TC StructureT TMLwP as TCDef ) :- std.do! [
1386
+ (class FC StructureF FMLwP) (class TC StructureT TMLwP) :- std.do! [
1381
1387
1382
- acc current (clause _ _ (sub-class FCDef TCDef )),
1388
+ acc current (clause _ _ (sub-class FC TC )),
1383
1389
1384
- term ->modname StructureF ModNameF,
1385
- term ->modname StructureT ModNameT,
1390
+ gref ->modname StructureF ModNameF,
1391
+ gref ->modname StructureT ModNameT,
1386
1392
CName is ModNameF ^ "_class_to_" ^ ModNameT ^ "_class",
1387
1393
SName is ModNameF ^ "_to_" ^ ModNameT,
1388
1394
@@ -1408,15 +1414,15 @@ declare-coercion SortProjection ClassProjection
1408
1414
if-verbose (coq.say "HB: declare unification hint" SName),
1409
1415
1410
1416
hb-add-const SName SCoeBody STy @transparent! SC,
1411
- @global! => coq.coercion.declare (coercion (const SC) 0 {term->gref StructureF} (grefclass {term->gref StructureT} )),
1417
+ @global! => coq.coercion.declare (coercion (const SC) 0 StructureF (grefclass StructureT)),
1412
1418
coq.CS.declare-instance (const SC), % TODO: API in Elpi, take a @constant instead of gref
1413
1419
].
1414
1420
1415
- pred join-body i:int, i:int, i:term , i:term, i:term, i:term, i:term, i:term,
1421
+ pred join-body i:int, i:int, i:structure , i:term, i:term, i:term, i:term, i:term,
1416
1422
i:list term, i:name, i:term, i:(term -> A), o:term.
1417
1423
join-body N1 N2 S3 S2_Pack S1_sort S3_to_S1 S2_class S3_to_S2
1418
1424
P N _Ty _F (fun N S3P Pack) :- !,
1419
- mk-app S3 P S3P, !,
1425
+ mk-app {coq.env.global S3} P S3P, !,
1420
1426
coq.mk-n-holes N2 Holes2, !,
1421
1427
coq.mk-n-holes N1 Holes1, !,
1422
1428
@pi-decl N S3P s\
@@ -1430,8 +1436,8 @@ join-body N1 N2 S3 S2_Pack S1_sort S3_to_S1 S2_class S3_to_S2
1430
1436
1431
1437
pred declare-join i:class, i:pair class class, o:prop.
1432
1438
declare-join (class C3 S3 MLwP3) (pr (class C1 S1 _) (class C2 S2 _)) (join C1 C2 C3) :-
1433
- Name is "join_" ^ {term ->modname S3} ^
1434
- "_between_" ^ {term ->modname S1} ^ "_and_" ^ {term ->modname S2},
1439
+ Name is "join_" ^ {gref ->modname S3} ^
1440
+ "_between_" ^ {gref ->modname S1} ^ "_and_" ^ {gref ->modname S2},
1435
1441
1436
1442
get-structure-coercion S3 S2 S3_to_S2,
1437
1443
get-structure-coercion S3 S1 S3_to_S1,
@@ -1493,8 +1499,8 @@ mk-class-field ClassName Params T _ (field _ "class" (app [C|Args]) _\end-record
1493
1499
1494
1500
% Builds the axioms record and the factories from this class to each mixin
1495
1501
% TODO params
1496
- pred declare-class+structure i:list-w-params mixinname, o:factoryname, o:term , o:term, o:term, o:list prop.
1497
- declare-class+structure MLwP (indt ClassInd) Structure SortProjection ClassProjection AllFactories :- std.do! [
1502
+ pred declare-class+structure i:list-w-params mixinname, o:factoryname, o:structure , o:term, o:term, o:list prop.
1503
+ declare-class+structure MLwP (indt ClassInd) (indt StructureInd) SortProjection ClassProjection AllFactories :- std.do! [
1498
1504
1499
1505
if-verbose (coq.say "HB: declare axioms record"),
1500
1506
@@ -1517,17 +1523,16 @@ declare-class+structure MLwP (indt ClassInd) Structure SortProjection ClassProje
1517
1523
(mk-class-field (indt ClassInd)) StructureDeclaration,
1518
1524
1519
1525
std.assert-ok! (coq.typecheck-indt-decl StructureDeclaration) "declare-structure: illtyped",
1520
- coq.env. add-indt StructureDeclaration StructureName ,
1526
+ hb- add-indt StructureDeclaration StructureInd ,
1521
1527
1522
- coq.CS.canonical-projections StructureName [some SortP, some ClassP],
1523
- coq.env.global (indt StructureName) Structure,
1528
+ coq.CS.canonical-projections StructureInd [some SortP, some ClassP],
1524
1529
coq.env.global (const SortP) SortProjection,
1525
1530
coq.env.global (const ClassP) ClassProjection,
1526
1531
].
1527
1532
1528
1533
% Declares "sort" as a coercion Structurename >-> Sortclass
1529
- pred declare-sort-coercion i:term , i:term.
1530
- declare-sort-coercion (global StructureName _) (global Proj _) :-
1534
+ pred declare-sort-coercion i:structure , i:term.
1535
+ declare-sort-coercion StructureName (global Proj _) :-
1531
1536
1532
1537
if-verbose (coq.say "HB: declare sort coercion"),
1533
1538
@@ -1538,15 +1543,14 @@ if-class-already-exists-error _ [] _.
1538
1543
if-class-already-exists-error N [class _ S ML1wP|CS] ML2 :-
1539
1544
list-w-params_list ML1wP ML1,
1540
1545
if (list-eq-set ML1 ML2)
1541
- (coq.error "Structure" {coq.term ->string S} "contains the same mixins of" N)
1546
+ (coq.error "Structure" {nice-gref ->string S} "contains the same mixins of" N)
1542
1547
(if-class-already-exists-error N CS ML2).
1543
1548
1544
1549
pred export-mixin-coercion i:classname, i:option constant.
1545
1550
export-mixin-coercion _ none.
1546
1551
export-mixin-coercion ClassName (some C) :-
1547
1552
coq.env.typeof (const C) _ CTy,
1548
- safe-dest-app {safe-head CTy} Mixin _,
1549
- coq.term->gref Mixin MixinGR,
1553
+ head-gref-under-prods CTy MixinGR,
1550
1554
if-verbose (coq.say "HB: export class to mixin coercion for mixin" {nice-gref->string MixinGR}),
1551
1555
@global! =>
1552
1556
coq.coercion.declare (coercion (const C) _ ClassName (grefclass MixinGR)).
0 commit comments