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
8284pred with-attributes i:prop.
8385with-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
8789pred if-verbose i:prop.
@@ -125,14 +127,16 @@ name-of-asset-decl (asset-record X _ _ _) X.
125127name-of-asset-decl (asset-alias X _) X.
126128
127129pred 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).
131134argument->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".
137141argument->asset X _ :- coq.error "Unsupported asset:" X.
138142
@@ -341,8 +345,9 @@ local-cs? TyTerm Struct :-
341345pred get-canonical-mixins-of i:term, i:structure, o:list prop.
342346get-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) :-
11491153declare-old-constant _ :- true.
11501154
11511155pred 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
0 commit comments