Skip to content

Commit e8f2bc8

Browse files
authored
Merge pull request #296 from math-comp/fun_instances
Adding missing feature: instances on function spaces
2 parents 9e39faf + 5b2ca8a commit e8f2bc8

File tree

16 files changed

+203
-36
lines changed

16 files changed

+203
-36
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ jobs:
1717
fail-fast: false
1818
matrix:
1919
coq_version:
20-
- '8.13'
21-
- '8.14'
22-
- '8.15'
20+
- '8.16'
2321
ocaml_version:
24-
- '4.07-flambda'
22+
- '4.09-flambda'
2523
steps:
2624
- uses: actions/checkout@v2
2725
- uses: coq-community/docker-coq-action@v1
@@ -40,8 +38,8 @@ jobs:
4038
- uses: coq-community/docker-coq-action@v1
4139
with:
4240
opam_file: './coq-hierarchy-builder.opam'
43-
coq_version: '8.14'
44-
ocaml_version: '4.07-flambda'
41+
coq_version: '8.16'
42+
ocaml_version: '4.09-flambda'
4543
script: |
4644
mkdir /home/coq/workspace
4745
cp -ra . /home/coq/workspace

.github/workflows/nix-action-coq-mcHB-8.16.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,67 @@ jobs:
366366
name: Building/fetching current CI target
367367
run: NIXPKGS_ALLOW_UNFREE=1 nix-build --no-out-link --argstr bundle "coq-mcHB-8.16"
368368
--argstr job "mathcomp-algebra"
369+
mathcomp-analysis:
370+
needs:
371+
- coq
372+
- mathcomp-ssreflect
373+
- mathcomp-field
374+
- mathcomp-finmap
375+
- hierarchy-builder
376+
runs-on: ubuntu-latest
377+
steps:
378+
- name: Determine which commit to test
379+
run: "if [ ${{ github.event_name }} = \"push\" ]; then\n echo \"tested_commit=${{\
380+
\ github.sha }}\" >> $GITHUB_ENV\nelse\n merge_commit=$(git ls-remote ${{\
381+
\ github.event.repository.html_url }} refs/pull/${{ github.event.number }}/merge\
382+
\ | cut -f1)\n if [ -z \"$merge_commit\" ]; then\n echo \"tested_commit=${{\
383+
\ github.event.pull_request.head.sha }}\" >> $GITHUB_ENV\n else\n echo\
384+
\ \"tested_commit=$merge_commit\" >> $GITHUB_ENV\n fi\nfi\n"
385+
- name: Git checkout
386+
uses: actions/checkout@v2
387+
with:
388+
fetch-depth: 0
389+
ref: ${{ env.tested_commit }}
390+
- name: Cachix install
391+
uses: cachix/install-nix-action@v16
392+
with:
393+
nix_path: nixpkgs=channel:nixpkgs-unstable
394+
- name: Cachix setup math-comp
395+
uses: cachix/cachix-action@v10
396+
with:
397+
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
398+
extraPullNames: coq, coq-community
399+
name: math-comp
400+
- id: stepCheck
401+
name: Checking presence of CI target mathcomp-analysis
402+
run: "nb_dry_run=$(NIXPKGS_ALLOW_UNFREE=1 nix-build --no-out-link \\\n --argstr\
403+
\ bundle \"coq-mcHB-8.16\" --argstr job \"mathcomp-analysis\" \\\n --dry-run\
404+
\ 2>&1 > /dev/null)\necho $nb_dry_run\necho ::set-output name=status::$(echo\
405+
\ $nb_dry_run | grep \"built:\" | sed \"s/.*/built/\")\n"
406+
- if: steps.stepCheck.outputs.status == 'built'
407+
name: 'Building/fetching previous CI target: coq'
408+
run: NIXPKGS_ALLOW_UNFREE=1 nix-build --no-out-link --argstr bundle "coq-mcHB-8.16"
409+
--argstr job "coq"
410+
- if: steps.stepCheck.outputs.status == 'built'
411+
name: 'Building/fetching previous CI target: mathcomp-ssreflect'
412+
run: NIXPKGS_ALLOW_UNFREE=1 nix-build --no-out-link --argstr bundle "coq-mcHB-8.16"
413+
--argstr job "mathcomp-ssreflect"
414+
- if: steps.stepCheck.outputs.status == 'built'
415+
name: 'Building/fetching previous CI target: mathcomp-field'
416+
run: NIXPKGS_ALLOW_UNFREE=1 nix-build --no-out-link --argstr bundle "coq-mcHB-8.16"
417+
--argstr job "mathcomp-field"
418+
- if: steps.stepCheck.outputs.status == 'built'
419+
name: 'Building/fetching previous CI target: mathcomp-finmap'
420+
run: NIXPKGS_ALLOW_UNFREE=1 nix-build --no-out-link --argstr bundle "coq-mcHB-8.16"
421+
--argstr job "mathcomp-finmap"
422+
- if: steps.stepCheck.outputs.status == 'built'
423+
name: 'Building/fetching previous CI target: hierarchy-builder'
424+
run: NIXPKGS_ALLOW_UNFREE=1 nix-build --no-out-link --argstr bundle "coq-mcHB-8.16"
425+
--argstr job "hierarchy-builder"
426+
- if: steps.stepCheck.outputs.status == 'built'
427+
name: Building/fetching current CI target
428+
run: NIXPKGS_ALLOW_UNFREE=1 nix-build --no-out-link --argstr bundle "coq-mcHB-8.16"
429+
--argstr job "mathcomp-analysis"
369430
mathcomp-character:
370431
needs:
371432
- coq

.nix/config.nix

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@
1313
graph-theory.job = false;
1414
fourcolor.override.version = "master";
1515
odd-order.override.version = "hirarchy-builder";
16-
mathcomp-finmap.override.version = "#84";
16+
mathcomp-finmap.override.version = "proux01:hierarchy-builder";
1717
mathcomp.analyis.override.version = "#694";
1818
};
1919
in {
2020
"coq-mcHB-8.16".coqPackages = {
2121
coq.override.version = "8.16";
22-
coq-elpi.override.version = "master";
2322
mathcomp-analysis.override.version = "coq816";
2423
} // mcHBcommon;
2524

@@ -29,7 +28,6 @@
2928

3029
"coq-8.16".coqPackages = {
3130
coq.override.version = "8.16";
32-
coq-elpi.override.version = "master";
3331
mathcomp.override.version = "mathcomp-1.15.0";
3432
};
3533
"coq-8.15".coqPackages = {

.nix/coq-overlays/coq-elpi/default.nix

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ in mkCoqDerivation {
1515
owner = "LPCIC";
1616
inherit version;
1717
defaultVersion = lib.switch coq.coq-version [
18+
{ case = "8.16"; out = "1.15.3"; }
1819
{ case = "8.15"; out = "1.14.0"; }
1920
{ case = "8.14"; out = "1.11.2"; }
2021
{ case = "8.13"; out = "1.11.1"; }
2122
{ case = "8.12"; out = "1.8.3_8.12"; }
2223
{ case = "8.11"; out = "1.6.3_8.11"; }
2324
] null;
24-
release."1.14.0".sha256 = "sha256:1v2p5dlpviwzky2i14cj7gcgf8cr0j54bdm9fl5iz1ckx60j6nvp";
25+
release."1.15.3".sha256 = "0vsgpflvfbbpbri3xfdhkz24bc36gy90f0mh0nr9ml6pqyp0ygji";
26+
release."1.14.0".sha256 = "1v2p5dlpviwzky2i14cj7gcgf8cr0j54bdm9fl5iz1ckx60j6nvp";
2527
release."1.13.0".sha256 = "1j7s7dlnjbw222gnbrsjgmjck1yrx7h6hwm8zikcyxi0zys17w7n";
2628
release."1.12.1".sha256 = "sha256-4mO6/co7NcIQSGIQJyoO8lNWXr6dqz+bIYPO/G0cPkY=";
2729
release."1.11.2".sha256 = "0qk5cfh15y2zrja7267629dybd3irvxk1raz7z8qfir25a81ckd4";

HB/common/compat_815.elpi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pred compat.coercion.declare i:coercion.
2+
compat.coercion.declare C :- @global! => coq.coercion.declare C.

HB/common/compat_all.elpi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pred compat.coercion.declare i:coercion.
2+
compat.coercion.declare C :- @global! => @reversible! => coq.coercion.declare C.

HB/common/database.elpi

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -309,33 +309,39 @@ get-cs-instance (cs-instance _ _ (const Inst)) Inst.
309309
pred has-cs-instance i:gref, i:cs-instance.
310310
has-cs-instance GTy (cs-instance _ (cs-gref GTy) _).
311311

312+
pred term->cs-pattern i:term, o:cs-pattern.
313+
term->cs-pattern (prod _ _ _) cs-prod.
314+
term->cs-pattern (sort U) (cs-sort U).
315+
term->cs-pattern T (cs-gref GR) :- term->gref T GR.
316+
term->cs-pattern T _ :- coq.error T "HB database: is not a valid canonical key".
317+
318+
pred cs-pattern->name i:cs-pattern, o:string.
319+
cs-pattern->name cs-prod "prod".
320+
cs-pattern->name (cs-sort _) "sort".
321+
cs-pattern->name cs-default "default".
322+
cs-pattern->name (cs-gref GR) Name :- gref->modname-label GR 1 "_" Name.
323+
312324
pred get-canonical-structures i:term, o:list structure.
313325
get-canonical-structures TyTrm StructL :- std.do! [
314-
term->gref TyTrm CanonValue,
315-
if (coq.version _ _ N _, N > 12)
316-
(coq.CS.db-for _ (cs-gref CanonValue) DBGTyL)
317-
(std.filter {coq.CS.db} (has-cs-instance CanonValue) DBGTyL),
326+
term->cs-pattern TyTrm Pat, !,
327+
coq.CS.db-for _ Pat DBGTyL,
318328
std.map-filter DBGTyL get-cs-structure StructL,
319329
].
320330

321331
pred get-canonical-instances i:term, o:list constant.
322-
get-canonical-instances TyTrm CL :- std.do! [
323-
term->gref TyTrm CanonValue,
324-
if (coq.version _ _ N _, N > 12)
325-
(coq.CS.db-for _ (cs-gref CanonValue) DBGTyL)
326-
(std.filter {coq.CS.db} (has-cs-instance CanonValue) DBGTyL),
327-
std.map-filter DBGTyL get-cs-instance CL,
332+
get-canonical-instances TyTrm StructL :- std.do! [
333+
term->cs-pattern TyTrm Pat, !,
334+
coq.CS.db-for _ Pat DBGTyL,
335+
std.map-filter DBGTyL get-cs-instance StructL,
328336
].
329337

330338
pred has-CS-instance? i:term, i:structure.
331-
has-CS-instance? TyTerm (indt Struct) :- coq.version _ _ N _, N > 12, !,
332-
term->gref TyTerm Value,
339+
has-CS-instance? TyTerm (indt Struct) :- std.do! [
340+
term->cs-pattern TyTerm Pat,
333341
coq.env.projections Struct [some Proj, _],
334-
coq.CS.db-for (const Proj) (cs-gref Value) L,
335-
not(L = []).
336-
has-CS-instance? TyTerm Struct :-
337-
get-canonical-structures TyTerm StructL,
338-
std.mem! StructL Struct.
342+
coq.CS.db-for (const Proj) Pat L,
343+
not(L = [])
344+
].
339345

340346
pred structure-nparams i:structure, o:int.
341347
structure-nparams Structure NParams :-

HB/common/log.elpi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ env.import-module MPNice M :- std.do! [
159159

160160
pred coercion.declare i:coercion.
161161
coercion.declare C :- std.do! [
162-
@global! => coq.coercion.declare C,
162+
compat.coercion.declare C,
163163
C = coercion GR _ SRCGR TGTCL,
164164
coq.gref->id GR Name,
165165
log.private.log-vernac (log.private.coq.vernac.coercion Name SRCGR TGTCL),

HB/instance.elpi

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,15 @@ declare-all T [class Class Struct MLwP|Rest] [pr Name CS|L] :-
102102
fail,
103103

104104
!,
105-
coq.term->gref T TGR,
106-
Name is {gref->modname-label TGR 1 "_"} ^ "__canonical__" ^ {gref->modname Struct 2 "_"},
105+
106+
Name is {cs-pattern->name {term->cs-pattern T}}
107+
^ "__canonical__" ^ {gref->modname Struct 2 "_" },
107108

108109
if-verbose (coq.say {header} "declare canonical structure instance" Name),
109110

110111
get-constructor Struct KS,
111-
private.optimize-class-body TGR {std.length Params} KCApp KCAppNames Clauses,
112+
coq.safe-dest-app T THD _,
113+
private.optimize-class-body THD {std.length Params} KCApp KCAppNames Clauses,
112114
coq.mk-app (global KS) {std.append Params [T, KCAppNames]} S,
113115
if-verbose (coq.say {header} "structure instance for" Name "is" {coq.term->string S}),
114116
std.assert-ok! (coq.typecheck S STy) "declare-all: S illtyped",
@@ -329,12 +331,12 @@ pred hnf i:term, o:term.
329331
hnf X R :- get-option "hnf" tt, !, unwind {whd X []} R.
330332
hnf X X.
331333

332-
pred optimize-class-body i:gref, i:int, i:term, o:term, o:list prop.
333-
optimize-class-body TGR NParams (let _ _ MBo R) R1 Clauses :- std.do! [
334+
pred optimize-class-body i:term, i:int, i:term, o:term, o:list prop.
335+
optimize-class-body T NParams (let _ _ MBo R) R1 Clauses :- std.do! [
334336
declare-mixin-name {hnf MBo} MC CL1,
335-
if (TGR = indt _, MC = global (const C), not(coq.env.opaque? C))
337+
if (T = global (indt _), MC = global (const C), not(coq.env.opaque? C))
336338
(log.coq.strategy.set [C] (level 1000)) true, % opaque stops simpl
337-
optimize-class-body TGR NParams (R MC) R1 CL2,
339+
optimize-class-body T NParams (R MC) R1 CL2,
338340
std.append CL1 CL2 Clauses,
339341
].
340342
optimize-class-body _ _ (app L) (app L) [].

HB/structure.elpi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace structure {
55

66
% HB.structure Definition S P1 P2 := { T of F1 P1 T & F2 P1 (P2*P2) T }
77
% cons p1\ cons p2\ nil t\ [triple f1 [p1] t,triple f2 [p1, {{p1 * p2}}] t]
8+
pred declare i:string, i:term, i:sort.
89
pred declare i:string, i:term, i:universe.
910
declare Module BSkel Sort :- std.do! [
1011
disable-id-phant BSkel BSkelNoId,
@@ -495,6 +496,7 @@ pred synthesize-fields.body i:list term, i:term, i:list (w-args mixinname), o:in
495496
synthesize-fields.body _Params T ML (record "axioms_" {{ Type }} "Class" FS) :-
496497
synthesize-fields T ML FS.
497498

499+
pred mk-record+sort-field i:sort, i:name, i:term, i:(term -> record-decl), o:indt-decl.
498500
pred mk-record+sort-field i:universe, i:name, i:term, i:(term -> record-decl), o:indt-decl.
499501
mk-record+sort-field Sort _ T F (record RecordName (sort Sort) "Pack" (field _ "sort" T F)) :- !, std.do! [
500502
if (get-option "infer" _) (RecordName = "type_") (RecordName = "type")
@@ -505,6 +507,7 @@ mk-class-field ClassName Params T _ (field [canonical ff] "class" (app [global C
505507
std.append Params [T] Args.
506508

507509
% Builds the axioms record and the factories from this class to each mixin
510+
pred declare-class+structure i:mixins, i:sort, o:factoryname, o:structure, o:term, o:term, o:list prop, o:prop.
508511
pred declare-class+structure i:mixins, i:universe, o:factoryname, o:structure, o:term, o:term, o:list prop, o:prop.
509512
declare-class+structure MLwP Sort
510513
(indt ClassInd) (indt StructureInd) SortProjection ClassProjection AllFactories

0 commit comments

Comments
 (0)