Skip to content

Commit 43dbc5c

Browse files
authored
Merge pull request #70 from math-comp/coq-elpi-1.4
port to coq-elpi 1.4
2 parents 8b95393 + f9368d9 commit 43dbc5c

File tree

5 files changed

+50
-106
lines changed

5 files changed

+50
-106
lines changed

.travis.yml

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,18 @@ branches:
77
env:
88
global:
99
- CONTRIB_NAME=hb
10-
- ELPI_810=coq-elpi.1.3.0
11-
- ELPI_811=coq-elpi.1.3.1
10+
- ELPI_811=coq-elpi.1.4.0
1211
- ELPI_DEV=https://github.com/LPCIC/coq-elpi.git#coq-master
1312

1413
jobs:
1514
include:
16-
- language: nix
17-
env:
18-
- COQ=8.10
19-
script:
20-
- nix-build --argstr coq-version "${COQ}"
2115

2216
- language: nix
2317
env:
2418
- COQ=8.11
2519
script:
2620
- nix-build --argstr coq-version "${COQ}"
2721

28-
- dist: bionic
29-
language: minimal
30-
services:
31-
- docker
32-
env:
33-
- COQ=8.10 ELPI="install ${ELPI_810}" CMD="make && make install"
34-
install:
35-
- ./.travis/docker-install.sh
36-
script:
37-
- ./.travis/docker-test.sh
38-
after_script:
39-
- docker stop COQ
40-
4122
- dist: bionic
4223
language: minimal
4324
services:

coq-hierarchy-builder.opam

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ dev-repo: "git+https://github.com/math-comp/hierarchy-builder"
1111
build: [ make ]
1212
install: [ make "install" "VFILES=structures.v" ]
1313
depends: [
14-
"coq" {>= "8.10.0" & < "8.12.0~" }
15-
"coq-elpi" {>= "1.3.0" & < "1.4.0~"}
14+
"coq" {>= "8.11.0" & < "8.12.0~" }
15+
"coq-elpi" {>= "1.4.0" & < "1.5.0~"}
1616
]
1717
synopsis: "Hierarchy Builder"
1818
description: """

default.nix

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,36 @@
11
{withEmacs ? false,
22
nixpkgs ? (fetchTarball {
3-
url = "https://github.com/NixOS/nixpkgs/archive/82b54d490663b6d87b7b34b9cfc0985df8b49c7d.tar.gz";
4-
sha256 = "12gpsif48g5b4ys45x36g4vdf0srgal4c96351m7gd2jsgvdllyf";
3+
url = "https://github.com/CohenCyril/nixpkgs/archive/8d04d29adb547353ed9fb5c5c4aa6d540e198366.tar.gz";
4+
sha256 = "1v4l37xkadpnkydpycnk9hrjgh6yc792k66yi7f6203zzr0phzx8";
55
}),
6-
coq-version ? "8.10",
6+
coq-version ? "8.11",
77
print-env ? false
88
}:
9-
with import nixpkgs {};
10-
let
11-
pgEmacs = emacsWithPackages (epkgs:
12-
with epkgs.melpaStablePackages; [proof-general]);
13-
myCoqPackages = {
14-
"8.10" = coqPackages_8_10;
15-
"8.11" = coqPackages_8_11;
16-
}."${coq-version}";
17-
coq = myCoqPackages.coq;
18-
coq-elpi = myCoqPackages.coq-elpi;
19-
in
20-
stdenv.mkDerivation {
9+
with import nixpkgs {
10+
overlays = [ (super: self: {
11+
coqPackages = { "8.11" = super.coqPackages_8_11; }."${coq-version}".overrideScope' (self: super: {
12+
## Coq package override example:
13+
# coq-elpi = super.coq-elpi.overrideAttrs (old: {
14+
# name = "coq8.11-elpi-v1.4.0";
15+
# src = fetchTarball https://github.com/LPCIC/coq-elpi/archive/v1.4.0.tar.gz;
16+
});
17+
coq = self.coqPackages.coq;
18+
})];
19+
};
20+
let pgEmacs = emacsWithPackages (epkgs: with epkgs.melpaStablePackages; [proof-general]); in
21+
coqPackages.hierarchy-builder.overrideAttrs (old: {
2122
name = "coq${coq.coq-version}-hierarchy-builder-dev";
22-
2323
src = ./.;
24-
25-
nativeBuildInputs = [ which ];
26-
buildInputs = [ coq coq.ocaml coq.ocamlPackages.elpi coq-elpi ];
27-
28-
installPhase = ''make -f Makefile.coq VFILES=structures.v COQLIB=$out/lib/coq/${coq.coq-version}/ install'';
29-
30-
meta = {
31-
description = "Coq plugin embedding ELPI.";
32-
maintainers = [ stdenv.lib.maintainers.cohencyril ];
33-
license = stdenv.lib.licenses.lgpl21;
34-
inherit (coq.meta) platforms;
35-
inherit (src.meta) homepage;
36-
};
37-
38-
passthru = {
39-
compatibleCoqVersions = stdenv.lib.flip builtins.hasAttr params;
40-
};
24+
buildInputs = old.buildInputs ++
25+
(if lib.trivial.inNixShell then lib.optional withEmacs pgEmacs
26+
else []);
4127
}
28+
// (if lib.trivial.inNixShell then {
29+
shellHook = ''
30+
nixEnv (){
31+
echo "Here is your work environement:"
32+
for x in $buildInputs; do printf " "; echo $x | cut -d "-" -f "2-"; done
33+
echo "you can pass option '--argstr coq-version \"x.y\"' to nix-shell to change coq versions"
34+
}
35+
'' + lib.optionalString print-env "nixEnv";
36+
} else {}))

hb.elpi

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
see phant-abbrev, used to talk about the non canonical name of Foo
3131
*/
3232

33+
shorten coq.{ term->gref, subst-fun, safe-dest-app, mk-app, mk-eta }.
34+
3335
%%%%%%%%% Elpi Utils %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3436
% This code could be moved in Elpi's standard library
3537

@@ -81,7 +83,7 @@ add-abbrev N NParams AbbrevT Global OnlyParse Abbrev :-
8183
% runs P in a context where Coq #[attributes] are parsed
8284
pred with-attributes i:prop.
8385
with-attributes P :-
84-
attributes A, parse-attributes A [att "verbose" bool] Opts, !,
86+
attributes A, coq.parse-attributes A [att "verbose" bool] Opts, !,
8587
Opts => P.
8688

8789
pred if-verbose i:prop.
@@ -125,14 +127,16 @@ name-of-asset-decl (asset-record X _ _ _) X.
125127
name-of-asset-decl (asset-alias X _) X.
126128

127129
pred argument->asset i:argument, o:asset-decl.
128-
argument->asset (indt-decl (parameter Name Ty I)) (asset-parameter "T" Ty A) :- % TODO, take the name
130+
argument->asset (indt-decl (parameter ID _ Ty I)) (asset-parameter ID Ty A) :-
131+
coq.string->name ID Name,
129132
@pi-decl Name Ty a\
130133
argument->asset (indt-decl (I a)) (A a).
131134
argument->asset (indt-decl (record Rid Ty Kid F)) (asset-record Rid Ty Kid F) :- !.
132-
argument->asset (const-decl Id (some (fun _ _ Bo)) (some (prod Name Src Ty))) (asset-parameter "T" Src A) :- !,
135+
argument->asset (const-decl Id (some (fun _ _ Bo)) (parameter ID _ Src Ty)) (asset-parameter ID Src A) :- !,
136+
coq.id->name ID Name,
133137
@pi-decl Name Src a\
134-
argument->asset (const-decl Id (some (Bo a)) (some (Ty a))) (A a).
135-
argument->asset (const-decl Id (some Bo) (some Ty)) (asset-alias Id Bo) :- !,
138+
argument->asset (const-decl Id (some (Bo a)) (Ty a)) (A a).
139+
argument->asset (const-decl Id (some Bo) (arity Ty)) (asset-alias Id Bo) :- !,
136140
std.assert! (var Ty) "Factories aliases should not be given a type".
137141
argument->asset X _ :- coq.error "Unsupported asset:" X.
138142

@@ -341,8 +345,9 @@ local-cs? TyTerm Struct :-
341345
pred get-canonical-mixins-of i:term, i:structure, o:list prop.
342346
get-canonical-mixins-of T S MSL :- std.do! [
343347
get-structure-sort-projection S Sort,
344-
coq.unify-eq T (app [Sort, ST]),
345-
coq.unify-eq ST (app [_, _, C]),
348+
std.assert-ok! (coq.unify-eq T (app [Sort, ST])) "HB: get-canonical-mixins-of: T = sort ST",
349+
% Hum, this unification problem is not super trivial. TODO replace by something simpler
350+
std.assert-ok! (coq.unify-eq ST (app [_, _, C])) "HB: get-canonical-mixins-of: ST = _ _ C",
346351
C = app [_, _ | MIL],
347352
std.map MIL (mixin-srcs T) MSLL,
348353
std.flatten MSLL MSL
@@ -966,7 +971,7 @@ declare-class ML (indt ClassName) Factories :- std.do! [
966971

967972
(@pi-decl `T` {{Type}} t\ synthesize-fields t ML (RDecl t)),
968973
ClassDeclaration =
969-
(parameter `T` {{ Type }} t\
974+
(parameter "T" explicit {{ Type }} t\
970975
record "axioms" {{ Type }} "Class" (RDecl t)),
971976
std.assert-ok! (coq.typecheck-indt-decl ClassDeclaration) "declare-class: illtyped",
972977
coq.env.add-indt ClassDeclaration ClassName,
@@ -1085,8 +1090,7 @@ main-begin-declare Module TName GRFS Decl :- std.do! [
10851090

10861091
if-verbose (coq.say "HB: postulate type" TName),
10871092

1088-
coq.univ.new [] U,
1089-
Ty = sort (typ U),
1093+
coq.fresh-type Ty,
10901094
coq.env.add-const TName _ Ty tt tt T, % no body, local -> a variable
10911095
main-declare-context (global (const T)) GRFS _,
10921096
acc current (clause _ _ (current-decl Decl))
@@ -1149,11 +1153,11 @@ declare-old-constant (some C) :-
11491153
declare-old-constant _ :- true.
11501154

11511155
pred main-begin-declare-builders i:context-decl.
1152-
main-begin-declare-builders (context-item _ _ none _\ context-item IDF _ (some _) _\ context-end) :-
1156+
main-begin-declare-builders (context-item _ _ _ none _\ context-item IDF _ _ (some _) _\ context-end) :-
11531157
coq.error "factories cannot be given a body:" IDF.
1154-
main-begin-declare-builders (context-item _ _ none _\ context-item ID1 _ none _\ context-item ID2 _ _ _) :-
1158+
main-begin-declare-builders (context-item _ _ _ none _\ context-item ID1 _ _ none _\ context-item ID2 _ _ _ _) :-
11551159
coq.error "only one factory is supported, got at least two" ID1 "and" ID2.
1156-
main-begin-declare-builders (context-item IDT T none t\ context-item IDF (F t) none _\ context-end) :- std.do! [
1160+
main-begin-declare-builders (context-item IDT _ T none t\ context-item IDF _ (F t) none _\ context-end) :- std.do! [
11571161
Name is "Builders_" ^ {term_to_string {new_int}}, % TODO
11581162
std.assert! (pi t\ F t = app[global GRA, t|_]) "a factory must be a name applied to the type variable",
11591163
factory-alias->gref GRA GRF,
@@ -1164,8 +1168,7 @@ main-begin-declare-builders (context-item IDT T none t\ context-item IDF (F t) n
11641168
coq.env.end-module _]) (true),
11651169
coq.env.begin-section Name,
11661170
std.assert! (T = sort (typ _)) "The first context item must be a type variable",
1167-
coq.univ.new [] U,
1168-
Ty = sort (typ U),
1171+
coq.fresh-type Ty,
11691172
coq.env.add-const IDT _ Ty tt tt C, % no body, local -> a variable
11701173
TheType = global (const C),
11711174
builders-postulate-factories IDF GRA GRF TheType [],
@@ -1223,8 +1226,7 @@ main-declare-asset (asset-parameter Name T Rest as R) D :- std.do! [
12231226
if-verbose (coq.say "HB: postulate type" Name),
12241227

12251228
std.assert! (T = sort (typ _)) "The first record parameter must be a type",
1226-
coq.univ.new [] U,
1227-
Ty = sort (typ U),
1229+
coq.fresh-type Ty,
12281230
coq.env.add-const Name _ Ty tt tt C, % no body, local -> a variable
12291231
TheType = global (const C),
12301232
collect-asset-parameters (Rest TheType) [] Module TheType D

shell.nix

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)