@@ -105,10 +105,14 @@ declare Module BSkel Sort :- std.do! [
105
105
%]),
106
106
107
107
if-verbose (coq.say {header} "making coercion from type to target"),
108
- synthesis.infer-coercion-tgt MLwP CoeClass,
109
- if-arg-sort (private.declare-sort-coercion CoeClass Structure
110
- (global (const ArgSortCst))),
111
- private.declare-sort-coercion CoeClass Structure SortProjection,
108
+ if (synthesis.infer-coercion-tgt MLwP CoeClass)
109
+ (if-arg-sort (private.declare-sort-coercion CoeClass Structure
110
+ (global (const ArgSortCst))),
111
+ private.declare-sort-coercion CoeClass Structure SortProjection)
112
+ (if-arg-sort (private.declare-sort-coercion-elpi (global Structure) (global (const ArgSortCst))),
113
+ private.declare-sort-coercion-elpi (global Structure) SortProjection),
114
+
115
+ private.declare-reverse-coercion-elpi Structure,
112
116
113
117
if-verbose (coq.say {header} "exporting unification hints"),
114
118
ClassAlias => Factories => GRDepsClauses =>
@@ -137,24 +141,26 @@ declare Module BSkel Sort :- std.do! [
137
141
138
142
log.coq.env.import-module "Exports" Exports,
139
143
140
- if-verbose (coq.say {header} "declaring on_ abbreviation"),
144
+ if (var CoeClass)
145
+ (if-verbose (coq.say {header} "could not declare the `on_`, `copy` and `on` abbreviations because the target of sort is not a coercion class"))
146
+ (if-verbose (coq.say {header} "declaring on_ abbreviation"),
141
147
142
- private.mk-infer-key CoeClass ClassProjection NilwP (global Structure) PhClass,
148
+ private.mk-infer-key CoeClass ClassProjection NilwP (global Structure) PhClass,
143
149
144
- phant.add-abbreviation "on_" PhClass _ ClassOfAbbrev,
145
- (pi c\ coq.notation.abbreviation ClassOfAbbrev [c] (ClassOfAbbrev_ c)),
150
+ phant.add-abbreviation "on_" PhClass _ ClassOfAbbrev,
151
+ (pi c\ coq.notation.abbreviation ClassOfAbbrev [c] (ClassOfAbbrev_ c)),
146
152
147
- if-verbose (coq.say {header} "declaring `copy` abbreviation"),
153
+ if-verbose (coq.say {header} "declaring `copy` abbreviation"),
148
154
149
- coq.mk-app (global ClassName) {params->holes NilwP} AppClassHoles,
150
- @global! => log.coq.notation.add-abbreviation "copy" 2
151
- {{fun T C => (lp:(ClassOfAbbrev_ C) : (lp:AppClassHoles T)) }} tt _,
155
+ coq.mk-app (global ClassName) {params->holes NilwP} AppClassHoles,
156
+ @global! => log.coq.notation.add-abbreviation "copy" 2
157
+ {{fun T C => (lp:(ClassOfAbbrev_ C) : (lp:AppClassHoles T)) }} tt _,
152
158
153
- if-verbose (coq.say {header} "declaring on abbreviation"),
159
+ if-verbose (coq.say {header} "declaring on abbreviation"),
154
160
155
- @global! => log.coq.notation.add-abbreviation "on" 1
156
- {{fun T => (lp:{{ ClassOfAbbrev_ {{_}} }} : (lp:AppClassHoles T)) }} tt
157
- _OnAbbrev,
161
+ @global! => log.coq.notation.add-abbreviation "on" 1
162
+ {{fun T => (lp:{{ ClassOfAbbrev_ {{_}} }} : (lp:AppClassHoles T)) }} tt
163
+ _OnAbbrev) ,
158
164
159
165
log.coq.env.end-module-name Module ModulePath,
160
166
@@ -276,6 +282,45 @@ export-operations Structure ProjSort ProjClass MLwP EX1 EX2 MLToExport :- std.do
276
282
std.map LMwPToExport w-params_1 MLToExport,
277
283
].
278
284
285
+ pred mk-sort-coercion-aux i:term, i:term, i:term, i:list term, o:prop.
286
+ mk-sort-coercion-aux (prod _N _T Body) Structure P Args Clause :-
287
+ Clause = (pi x\ C x),
288
+ pi x\ mk-sort-coercion-aux (Body x) Structure P [x | Args] (C x).
289
+
290
+ mk-sort-coercion-aux _ Structure P Args Clause :-
291
+ std.rev Args ArgsRev,
292
+ Clause =
293
+ (pi ctx v t e r argsAll w\ (coercion ctx v (app [Structure | ArgsRev]) e r :-
294
+ std.append ArgsRev [v] argsAll,
295
+ coq.mk-app P argsAll w,
296
+ coq.elaborate-skeleton w e r ok,
297
+ coq.ltac.collect-goals r [] [])).
298
+
299
+ pred mk-sort-coercion i:term, i:term, o:prop.
300
+ mk-sort-coercion Structure P Clause :-
301
+ coq.typecheck Structure T ok,
302
+ mk-sort-coercion-aux T Structure P [] Clause.
303
+
304
+ pred mk-reverse-coercion-aux i:term, i:term, i:term, i:list term, o:prop.
305
+ mk-reverse-coercion-aux (prod _N _T Body) Structure G Args Clause :-
306
+ Clause = (pi x\ C x),
307
+ pi x\ mk-reverse-coercion-aux (Body x) Structure G [x | Args] (C x).
308
+
309
+ mk-reverse-coercion-aux _ Structure G Args Clause :-
310
+ std.rev Args ArgsRev,
311
+ Clause =
312
+ (pi ctx v t e r c argsAll w\ (coercion ctx v t (app [Structure | ArgsRev]) r :-
313
+ std.append ArgsRev [v, c] argsAll,
314
+ coq.mk-app G argsAll w,
315
+ coq.elaborate-skeleton w e r ok,
316
+ coq.ltac.collect-goals r [] [])).
317
+
318
+ pred mk-reverse-coercion i:gref, o:prop.
319
+ mk-reverse-coercion Structure Clause :-
320
+ coq.typecheck (global Structure) T ok,
321
+ get-constructor Structure G,
322
+ mk-reverse-coercion-aux T (global Structure) (global G) [] Clause.
323
+
279
324
pred mk-coe-class-body
280
325
i:factoryname, % From class
281
326
i:factoryname, % To class
@@ -428,18 +473,23 @@ declare-unification-hints SortProj ClassProj CurrentClass NewJoins :- std.do! [
428
473
429
474
% For each mixin we declare a field and apply the mixin to its dependencies
430
475
% (that are previously declared fields recorded via field-for-mixin)
431
- pred synthesize-fields i:term, i:list (w-args mixinname), o:record-decl.
432
- synthesize-fields _T [] end-record.
433
- synthesize-fields T [triple M Args _|ML] (field _ Name MTy Fields) :- std.do! [
476
+ % Keeps track of whether every field is in Prop
477
+ pred synthesize-fields i:term, i:list (w-args mixinname), o:record-decl, o:bool.
478
+ synthesize-fields _T [] end-record tt.
479
+ synthesize-fields T [triple M Args V|ML] (field _ Name MTy Fields) B :- std.do! [
480
+ if (coq.typecheck {mk-app (global M) {std.append Args [V]} } {{ Prop }} ok)
481
+ (B = B2)
482
+ (B = ff),
434
483
Name is {gref->modname M 2 "_"} ^ "_mixin",
435
484
if-verbose (coq.say {header} "typing class field" M),
436
485
std.assert! (synthesis.infer-all-gref-deps Args T M MTy) "anomaly: a field type cannot be solved",
437
- @pi-decl `m` MTy m\ mixin-src T M m => synthesize-fields T ML (Fields m)
486
+ @pi-decl `m` MTy m\ mixin-src T M m => synthesize-fields T ML (Fields m) B2
438
487
].
439
488
440
489
pred synthesize-fields.body i:list term, i:term, i:list (w-args mixinname), o:indt-decl.
441
- synthesize-fields.body _Params T ML (record "axioms_" {{ Type }} "Class" FS) :-
442
- synthesize-fields T ML FS.
490
+ synthesize-fields.body _Params T ML (record "axioms_" Ty "Class" FS) :-
491
+ synthesize-fields T ML FS B,
492
+ if (B = tt) (Ty = {{ Prop }}) (Ty = {{ Type }}).
443
493
444
494
pred mk-record+sort-field i:sort, i:name, i:term, i:(term -> record-decl), o:indt-decl.
445
495
pred mk-record+sort-field i:universe, i:name, i:term, i:(term -> record-decl), o:indt-decl.
@@ -495,6 +545,27 @@ declare-sort-coercion CoeClass StructureName (global Proj) :-
495
545
496
546
log.coq.coercion.declare (coercion Proj 0 StructureName CoeClass).
497
547
548
+ % Declares "sort" as a Coercion in elpi's coercion db Proj : Structurename >-> CoeClass.
549
+ pred declare-sort-coercion-elpi i:term, i:term.
550
+ declare-sort-coercion-elpi Structure Proj :-
551
+
552
+ if-verbose (coq.say {header} "declare sort coercion in elpi"),
553
+
554
+ %TODO: log.coq.coercion-elpi.declare
555
+ mk-sort-coercion Structure Proj Clause,
556
+ coq.elpi.accumulate _ "coercion.db" (clause _ _ Clause).
557
+
558
+ % Declares a reverse coercion for the sort projection in elpi's coercion db
559
+ pred declare-reverse-coercion-elpi i:gref.
560
+ declare-reverse-coercion-elpi Structure :-
561
+
562
+ if-verbose (coq.say {header} "declare reverse coercion in elpi"),
563
+
564
+ %TODO: log.coq.coercion-elpi.declare
565
+ mk-reverse-coercion Structure Clause,
566
+ coq.elpi.accumulate _ "coercion.db" (clause _ _ Clause).
567
+
568
+
498
569
pred if-class-already-exists-error i:id, i:list class, i:list mixinname.
499
570
if-class-already-exists-error _ [] _.
500
571
if-class-already-exists-error N [class _ S ML1wP|CS] ML2 :-
0 commit comments