Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
57 changes: 39 additions & 18 deletions .nix/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
format = "1.0.0";
attribute = "hierarchy-builder";
no-rocq-yet = true;
default-bundle = "coq-8.20";
default-bundle = "coq-universes-clauses";
bundles = let
mcHBcommon = {
mathcomp.override.version = "master";
Expand All @@ -29,23 +29,44 @@
simple-io.override.version = "master";
QuickChick.override.version = "master";
# jasmin.override.version = "main";
jasmin.job = false; # currently broken
jasmin.job = false; # currently broken
};
in {
"coq-master" = { rocqPackages = {
rocq-core.override.version = "master";
stdlib.override.version = "master";
rocq-elpi.override.version = "master";
rocq-elpi.override.elpi-version = "2.0.7";
bignums.override.version = "master";
}; coqPackages = mcHBcommon // {
coq.override.version = "master";
stdlib.override.version = "master";
coq-elpi.override.version = "master";
coq-elpi.override.elpi-version = "2.0.7";
bignums.override.version = "master";
coquelicot.job = false;
}; };
"coq-universes-clauses" = {
rocqPackages = {
rocq-core.override.version = "mattam82:universes-clauses";
stdlib.override.version = "master";
rocq-elpi.override.version = "mattam82:universes-clauses";
rocq-elpi.override.elpi-version = "2.0.7";
bignums.override.version = "master";
};
coqPackages = mcHBcommon // {
coq.override.version = "mattam82:universes-clauses";
stdlib.override.version = "master";
coq-elpi.override.version = "mattam82:universes-clauses";
coq-elpi.override.elpi-version = "2.0.7";
bignums.override.version = "master";
coquelicot.job = false;
};
};

"coq-master" = {
rocqPackages = {
rocq-core.override.version = "master";
stdlib.override.version = "master";
rocq-elpi.override.version = "master";
rocq-elpi.override.elpi-version = "2.0.7";
bignums.override.version = "master";
};
coqPackages = mcHBcommon // {
coq.override.version = "master";
stdlib.override.version = "master";
coq-elpi.override.version = "master";
coq-elpi.override.elpi-version = "2.0.7";
bignums.override.version = "master";
coquelicot.job = false;
};
};

"coq-9.0".coqPackages = mcHBcommon // {
coq.override.version = "9.0";
Expand All @@ -61,8 +82,8 @@
};

};
cachix.coq = {};
cachix.coq-community = {};
cachix.coq = { };
cachix.coq-community = { };
cachix.math-comp.authToken = "CACHIX_AUTH_TOKEN";

}
10 changes: 5 additions & 5 deletions HB/about.elpi
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ main-located S (loc-abbreviation A) :- phant-abbrev GR PhB A, factory-constructo
main-located S (loc-abbreviation A) :-
coq.notation.abbreviation-body A NArgs _,
coq.notation.abbreviation A {coq.mk-n-holes NArgs} T,
coq.safe-dest-app T (global GR) _, !,
coq.safe-dest-global-app T GR _, !,
main-located S (loc-gref GR).

main-located S (loc-gref GR) :- from Factory Mixin GR, !,
Expand Down Expand Up @@ -143,19 +143,19 @@ main-canonical-projection S Proj CanonicalProjectionValues :-

pred pp-canonical-value i:cs-instance, o:coq.pp.
pp-canonical-value (cs-instance _Proj (cs-gref GR) _Sol) Pp :-
coq.term->pp (global GR) V,
coq.term->pp {coq.env.global GR} V,
Pp = box (hov 2) [ V , spc, {pp-loc-of GR} ].

pred main-coercion i:string, i:list coercion.
main-coercion S [coercion GR _ Src Tgt|_] :-
% format
if (class-def (class _ Src _) ; class-def (class Src _ _))
(Source = str {gref->modname_short Src "."})
(coq.term->pp (global Src) Source),
(coq.term->pp {coq.env.global Src} Source),
if2 (Tgt = grefclass TGR)
(if (class-def (class _ TGR _) ; class-def (class TGR _ _))
(Target = str {gref->modname_short TGR "."})
(coq.term->pp (global TGR) Target))
(coq.term->pp {coq.env.global TGR} Target))
(Tgt = sortclass)
(Target = str "Sortclass")
(Target = str "Funclass"),
Expand Down Expand Up @@ -291,7 +291,7 @@ compute-arg-type.fields [OP|Cs] NDeps Args [pr ID PPTy|Xs] [ID|FN] :-
(@pplevel! 200 => coq.term->pp TyArgsDepsRecord PPTy),
@pi-parameter ID TyArgsDepsRecord op\
(pi L L1 X\
copy (app[global(const OP)|L]) X :- std.drop ToDrop L L1, coq.mk-app op L1 X) =>
copy (app[{coq.env.global (const OP)}|L]) X :- std.drop ToDrop L L1, coq.mk-app op L1 X) =>
compute-arg-type.fields Cs NDeps Args Xs FN.

pred main-factory i:string, i:inductive.
Expand Down
10 changes: 5 additions & 5 deletions HB/builders.elpi
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ declare-shadowed-constant (some C) :-

pred declare-shadowed-located i:string, i:located.
declare-shadowed-located Id (loc-gref GR) :-
@global! => log.coq.notation.add-abbreviation Id 0 (global GR) ff _.
@global! => log.coq.notation.add-abbreviation Id 0 {coq.env.global GR} ff _.
declare-shadowed-located Id (loc-abbreviation Abbrev) :-
coq.notation.abbreviation-body Abbrev NArgs T,
@global! => log.coq.notation.add-abbreviation Id NArgs T ff _.
Expand All @@ -103,7 +103,7 @@ postulate-factory-abbrev TheType Params Name Falias TheFactory :- std.do! [
Msg is "Unable to declare factory " ^ Name,
std.assert-ok! (coq.typecheck-ty Package _) Msg,
log.coq.env.add-section-variable-noimplicits Name Package C,
TheFactory = global (const C),
coq.env.global (const C) TheFactory,
].

% Only record fields can be exported as operations.
Expand All @@ -121,14 +121,14 @@ define-factory-operation TheType Params TheFactory NHoles (some P) :-
coq.mk-n-holes NHoles Holes,
std.append Holes [TheFactory] Holes_Factory,
std.append Params [TheType|Holes_Factory] Args,
T = app[global (const P)|Args],
T = app[{coq.env.global (const P)}|Args],
std.assert-ok! (coq.typecheck T _) "Illtyped applied factory operation",
coq.gref->id (const P) Name,
@local! => log.coq.notation.add-abbreviation Name 0 T ff _.

pred factory i:context-decl, o:string, o:gref.
factory (context-item IDF _ T _ _\ context-end) IDF GR :- !,
coq.safe-dest-app T (global GR) _.
coq.safe-dest-global-app T GR _.
factory (context-item _ _ _ _ R) IDF GR :- !, pi x\ factory (R x) IDF GR.
factory _ _ _ :- !, coq.error "the last context item is not a factory".

Expand All @@ -146,4 +146,4 @@ postulate-factories ModName IDF CDecl :- std.do! [
acc-clause current (current-mode (builder-from FKey TheFactory GRF ModName)),
].

}
}
33 changes: 17 additions & 16 deletions HB/common/database.elpi
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pred from_mixin i:prop, o:mixinname.
from_mixin (from _ X _) X.

pred from_builder i:prop, o:term.
from_builder (from _ _ X) (global X).
from_builder (from _ _ GR) X :- coq.env.global GR X.

pred mixin-src_mixin i:prop, o:mixinname.
mixin-src_mixin (mixin-src _ M _) M.
Expand Down Expand Up @@ -59,7 +59,7 @@ instance-to-export_instance-nice (instance-to-export _ M _) M.
pred abbrev-to-export_name i:prop, o:id.
abbrev-to-export_name (abbrev-to-export _ N _) N.
pred abbrev-to-export_body i:prop, o:term.
abbrev-to-export_body (abbrev-to-export _ _ B) (global B).
abbrev-to-export_body (abbrev-to-export _ _ GR) B :- coq.env.global GR B.

pred clause-to-export_clause i:prop, o:prop.
clause-to-export_clause (clause-to-export _ C) C.
Expand Down Expand Up @@ -110,11 +110,13 @@ factory-provides.one Params T B M (triple M PL T) :- std.do! [
pred extract-conclusion-params i:term, i:term, o:list term.
extract-conclusion-params TheType (prod _ S T) R :- !,
@pi-decl _ S x\ extract-conclusion-params TheType (T x) R.
extract-conclusion-params TheType (app [global GR|Args]) R :- !, std.do! [
extract-conclusion-params TheType Tm R :-
coq.safe-dest-global-app Tm GR Args, !, std.do! [
std.assert-ok! (factory-alias->gref GR Factory) "HB",
factory-nparams Factory NP,
std.map Args (copy-pack-holes TheType TheType) NewArgs,
std.take NP NewArgs R].
std.take NP NewArgs R
].
extract-conclusion-params TheType T R :- whd1 T T1, !, extract-conclusion-params TheType T1 R.


Expand Down Expand Up @@ -311,22 +313,23 @@ assert-good-coverage! MLSortedRev CNL :- std.do! [

% [get-structure-coercion S1 S2 F] finds the coecion F from the structure S1 to S2
pred get-structure-coercion i:structure, i:structure, o:term.
get-structure-coercion S T (global F) :-
get-structure-coercion S T Out :-
coq.coercion.db-for (grefclass S) (grefclass T) L,
if (L = [pr F _]) true (coq.error "No one step coercion from" S "to" T).
if (L = [pr F _]) true (coq.error "No one step coercion from" S "to" T),
coq.env.global F Out.

pred get-structure-sort-projection i:structure, o:term.
get-structure-sort-projection (indt S) Proj :- !,
coq.env.projections S L,
if (L = [some P, _]) true (coq.error "No canonical sort projection for" S),
Proj = global (const P).
coq.env.global (const P) Proj.
get-structure-sort-projection S _ :- coq.error "get-structure-sort-projection: not a structure" S.

pred get-structure-class-projection i:structure, o:term.
get-structure-class-projection (indt S) T :- !,
coq.env.projections S L,
if (L = [_, some P]) true (coq.error "No canonical class projection for" S),
T = global (const P).
coq.env.global (const P) T.
get-structure-class-projection S _ :- coq.error "get-structure-class-projection: not a structure" S.

pred get-constructor i:gref, o:gref.
Expand All @@ -350,18 +353,16 @@ has-cs-instance GTy (cs-instance _ (cs-gref GTy) _).


pred mixin-src->has-mixin-instance i:prop, o:prop.
mixin-src->has-mixin-instance (mixin-src (global GR) M I) (has-mixin-instance (cs-gref GR) M IHd) :-
term->gref I IHd.

mixin-src->has-mixin-instance (mixin-src (app [global GR|_] ) M I) (has-mixin-instance (cs-gref GR) M IHd) :-
term->gref I IHd.

mixin-src->has-mixin-instance (mixin-src (prod _ _ _ ) M I) (has-mixin-instance cs-prod M IHd):-
term->gref I IHd.

mixin-src->has-mixin-instance (mixin-src (sort U) M I) (has-mixin-instance (cs-sort U) M IHd):-
term->gref I IHd.

mixin-src->has-mixin-instance (mixin-src Src M I) (has-mixin-instance (cs-gref GR) M IHd) :- !,
coq.safe-dest-global-app Src GR _, !, term->gref I IHd.


% this auxiliary function iterates over the list of arguments of an application,
% and create the necessary unify condition for each arguments
% and at the end returns the mixin-src clause with all the conditions
Expand Down Expand Up @@ -402,7 +403,7 @@ mixin-instance-type->mixin-src (prod N_ _ F) M I Cond (pi a \ C a) :-

pred has-mixin-instance->mixin-src i:prop, o:prop.
has-mixin-instance->mixin-src (has-mixin-instance _ M IHd) C :- std.do![
T = global IHd,
coq.env.global IHd T,
coq.env.typeof IHd Ty,
mixin-instance-type->mixin-src Ty M T [] C,
].
Expand Down Expand Up @@ -437,7 +438,7 @@ structure-nparams Structure NParams :-
pred factory? i:term, o:w-args factoryname.
factory? S (triple F Params T) :-
not (var S), !,
safe-dest-app S (global GR) Args,
coq.safe-dest-global-app S GR Args,
factory-alias->gref GR F ok,
factory-nparams F NP, !,
std.split-at NP Args Params [T|_].
Expand Down
8 changes: 4 additions & 4 deletions HB/common/log.elpi
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ env.add-const-noimplicits Name Bo Ty Opaque C :- std.do! [
":" {coq.term->string Ty} ":=" {coq.term->string Bo})
true,
avoid-name-collision Name Name1,
coq.env.add-const Name1 Bo Ty Opaque C,
@univpoly! => coq.env.add-const Name1 Bo Ty Opaque C,
env.add-location (const C),
if (var Ty) (Ty? = none) (Ty? = some Ty),
log.private.log-vernac (log.private.coq.vernac.definition Name1 Ty? Bo),
Expand All @@ -49,7 +49,7 @@ env.add-const Name Bo Ty Opaque C :- std.do! [
":" {coq.term->string Ty} ":=" {coq.term->string Bo})
true,
avoid-name-collision Name Name1,
coq.env.add-const Name1 Bo Ty Opaque C,
@univpoly! => coq.env.add-const Name1 Bo Ty Opaque C,
env.add-location (const C),
if (var Ty) (Ty? = none) (Ty? = some Ty),
log.private.log-vernac (log.private.coq.vernac.definition Name1 Ty? Bo),
Expand All @@ -61,7 +61,7 @@ env.add-const-noimplicits-failondup Name Bo Ty Opaque C :- std.do! [
(coq.error "HB: cannot infer some information in" Name
":" {coq.term->string Ty} ":=" {coq.term->string Bo})
true,
coq.env.add-const Name Bo Ty Opaque C,
@univpoly! => coq.env.add-const Name Bo Ty Opaque C,
env.add-location (const C),
if (var Ty) (Ty? = none) (Ty? = some Ty),
log.private.log-vernac (log.private.coq.vernac.definition Name Ty? Bo),
Expand All @@ -79,7 +79,7 @@ env.add-indt Decl I :- std.do! [
if (not(coq.ground-indt-decl? Decl))
(coq.error "HB: cannot infer some information in" {coq.indt-decl->string Decl})
true,
coq.env.add-indt Decl I,
(@univpoly! => coq.env.add-indt Decl I),
(coq.env.record? I P ; P = ff),
log.private.log-vernac (log.private.coq.vernac.inductive Decl P),
env.add-location (indt I),
Expand Down
Loading
Loading