| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
kind implicit_kind type. |
| 5 |
kind field-attribute type. |
| 6 |
kind upoly-decl type. |
| 7 |
kind upoly-decl-cumul type. |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
% -- Misc --------------------------------------------------------- |
| 12 |
|
| 13 |
% [coq.info ...] Prints an info message |
| 14 |
external type coq.info variadic any (func). |
| 15 |
|
| 16 |
% [coq.notice ...] Prints a notice message |
| 17 |
external type coq.notice variadic any (func). |
| 18 |
|
| 19 |
% [coq.say ...] Prints a notice message |
| 20 |
external type coq.say variadic any (func). |
| 21 |
|
| 22 |
% [coq.debug ...] Prints a debug message |
| 23 |
external type coq.debug variadic any (func). |
| 24 |
|
| 25 |
% [coq.warn ...] Prints a generic warning message |
| 26 |
external type coq.warn variadic any (func). |
| 27 |
|
| 28 |
% [coq.warning Category Name ...] |
| 29 |
% Prints a warning message with a Name and Category which can be used |
| 30 |
% to silence this warning or turn it into an error. See coqc -w command |
| 31 |
% line option |
| 32 |
external type coq.warning string -> string -> variadic any (func). |
| 33 |
|
| 34 |
% [coq.error ...] Prints and *aborts* the program. It is a fatal error for |
| 35 |
% Elpi and Ltac |
| 36 |
external type coq.error variadic any (func). |
| 37 |
|
| 38 |
% [coq.version VersionString Major Minor Patch] Fetches the version of Coq, |
| 39 |
% as a string and as 3 numbers |
| 40 |
external func coq.version -> string, int, int, int. |
| 41 |
|
| 42 |
|
| 43 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 44 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%% coq-arg-HOAS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 45 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 46 |
|
| 47 |
% This section contains the low level data types linking Coq and elpi. |
| 48 |
% In particular the entry points for commands |
| 49 |
|
| 50 |
|
| 51 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 52 |
% Entry points |
| 53 |
% |
| 54 |
% Command and tactic invocation |
| 55 |
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 56 |
|
| 57 |
% Entry point for commands. Eg. "#[att=true] Elpi mycommand foo 3 (f x)." becomes |
| 58 |
% main [str "foo", int 3, trm (app[f,x])] |
| 59 |
% in a context where |
| 60 |
% attributes [attribute "att" (leaf "true")] |
| 61 |
% holds. The encoding of terms is described below. |
| 62 |
% See also the coq.parse-attributes utility. |
| 63 |
external pred main i:list argument. |
| 64 |
|
| 65 |
% Commands with a non-trivial parsing phase can thread data between |
| 66 |
% from the parsing phase to the interp one in an untyped way using the |
| 67 |
% following two entrypoints |
| 68 |
external pred main-interp i:list argument, i:any. |
| 69 |
external pred main-synterp i:list argument, o:any. |
| 70 |
|
| 71 |
% Commands starting/closing proofs have to use the following entrypoints. |
| 72 |
% The minimal working snippet is: |
| 73 |
% |
| 74 |
% main-interp-proof [trm P] _ P GL _ :- |
| 75 |
% coq.typecheck P _ ok, coq.ltac.collect-goals P GL _. |
| 76 |
% main-interp-qed _ _ P _GL _ :- |
| 77 |
% coq.env.add-const "it" P _ _ _. |
| 78 |
% |
| 79 |
% Where GL are the goals to prove, and _GL (unused here) are the same goals |
| 80 |
% with their current proof. The term P can be used as the root proof term, |
| 81 |
% where GL are missing pieces. One is not obliged to use P as is, i.e. he |
| 82 |
% can inspect _GL and declare each proof independenlty, or combine these proofs |
| 83 |
% as he likes and ignore P completely. When a main-interp-qed is used to end |
| 84 |
% a proof stated by a standard Rocq Lemma/Definition statement, the data from |
| 85 |
% the proof opening command is the lemma name, _GL is the empty list and P the |
| 86 |
% proof term. |
| 87 |
external pred main-interp-proof |
| 88 |
i:list argument, % arguments passed to the command |
| 89 |
i:any, % data from the parsing phase (defaults to _) |
| 90 |
o:term, % proof data for the corresponding proof-closing command |
| 91 |
o:list sealed-goal, % the sequents to prove |
| 92 |
o:any. % any data for the corresponding proof-closing command |
| 93 |
external pred main-interp-qed |
| 94 |
i:list argument, % arguments passed to the command |
| 95 |
i:any, % data from the parsing phase (defaults to _) |
| 96 |
i:term, % proof data from the corresponding proof-opening command |
| 97 |
i:list sealed-goal, % the sequents from the corresponding proof-opening command, but with proofs |
| 98 |
i:any. % any data from the corresponding proof-opening command |
| 99 |
|
| 100 |
pred usage. |
| 101 |
external func attributes -> list attribute. |
| 102 |
|
| 103 |
% see coq-lib.elpi for coq.parse-attributes generating the options below |
| 104 |
external pred get-option o:string, o:A. |
| 105 |
|
| 106 |
% The data type of arguments (for commands or tactics) |
| 107 |
kind argument type. |
| 108 |
external symbol int : int -> argument. % Eg. 1 -2. |
| 109 |
external symbol str : string -> argument. % Eg. x "y" z.w. or any Coq keyword/symbol |
| 110 |
external symbol trm : term -> argument. % Eg. (t). |
| 111 |
external symbol open-trm : int -> term -> argument. |
| 112 |
|
| 113 |
% Extra arguments for commands. [Definition], [Axiom], [Record] and [Context] |
| 114 |
% take precedence over the [str] argument above (when not "quoted"). |
| 115 |
% |
| 116 |
% Eg. Record or Inductive |
| 117 |
external symbol indt-decl : indt-decl -> argument. |
| 118 |
% Eg. #[universes(polymorphic,...)] Record or Inductive |
| 119 |
external symbol upoly-indt-decl : indt-decl -> upoly-decl -> argument. |
| 120 |
% Eg. Definition or Axiom (when the body is none) |
| 121 |
external symbol const-decl : id -> option term -> arity -> argument. |
| 122 |
% Eg. #[universes(polymorphic,...)] Definition or Axiom |
| 123 |
external symbol upoly-const-decl : id -> option term -> arity -> upoly-decl -> argument. |
| 124 |
% Eg. Context A (b : A). |
| 125 |
external symbol ctx-decl : context-decl -> argument. |
| 126 |
|
| 127 |
% Declaration of inductive types %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 128 |
|
| 129 |
kind indt-decl type. |
| 130 |
kind indc-decl type. |
| 131 |
kind record-decl type. |
| 132 |
|
| 133 |
% An arity is written, in Coq syntax, as: |
| 134 |
% (x : T1) .. (xn : Tn) : S1 -> ... -> Sn -> U |
| 135 |
% This syntax is used, for example, in the type of an inductive type or |
| 136 |
% in the type of constructors. We call the abstractions on the left of ":" |
| 137 |
% "parameters" while we call the type following the ":" (proper) arity. |
| 138 |
|
| 139 |
% Note: in some contexts, like the type of an inductive type constructor, |
| 140 |
% Coq makes no distinction between these two writings |
| 141 |
% (xn : Tn) : forall y1 : S1, ... and (xn : Tn) (y1 : S1) : ... |
| 142 |
% while Elpi is a bit more restrictive, since it understands user directives |
| 143 |
% such as the implicit status of an arguments (eg, using {} instead of () around |
| 144 |
% the binder), only on parameters. |
| 145 |
% Moreover parameters carry the name given by the user as an "id", while binders |
| 146 |
% in terms only carry it as a "name", an irrelevant pretty pringintg hint (see |
| 147 |
% also the HOAS of terms). A user command can hence only use the names of |
| 148 |
% parameters, and not the names of "forall" quantified variables in the arity. |
| 149 |
% |
| 150 |
% See also the arity->term predicate in coq-lib.elpi |
| 151 |
|
| 152 |
kind arity type. |
| 153 |
external symbol parameter : id -> implicit_kind -> term -> (term -> arity) -> arity = "1". |
| 154 |
external symbol arity : term -> arity. |
| 155 |
|
| 156 |
external symbol parameter : id -> implicit_kind -> term -> (term -> indt-decl) -> indt-decl = "2". |
| 157 |
external symbol inductive : id -> bool -> arity -> (term -> list indc-decl) -> indt-decl. % tt means inductive, ff coinductive |
| 158 |
external symbol minductive : id -> bool -> arity -> (term -> indt-decl) -> indt-decl. % one type of a mutual block |
| 159 |
external symbol mblock : list (list indc-decl) -> indt-decl. % constructor blocks for minductive declarations |
| 160 |
external symbol record : id -> term -> id -> record-decl -> indt-decl. |
| 161 |
|
| 162 |
external symbol constructor : id -> arity -> indc-decl. |
| 163 |
|
| 164 |
external symbol field : field-attributes -> id -> term -> (term -> record-decl) -> record-decl. |
| 165 |
external symbol end-record : record-decl. |
| 166 |
|
| 167 |
% Example. |
| 168 |
% Remark that A is a regular parameter; y is a non-uniform parameter and t |
| 169 |
% also features an index of type bool. |
| 170 |
% |
| 171 |
% Inductive t (A : Type) | (y : nat) : bool -> Type := |
| 172 |
% | K1 (x : A) {n : nat} : S n = y -> t A n true -> t A y true |
| 173 |
% | K2 : t A y false |
| 174 |
% |
| 175 |
% is written |
| 176 |
% |
| 177 |
% (parameter "A" explicit {{ Type }} a\ |
| 178 |
% inductive "t" tt (parameter "y" explicit {{ nat }} _\ |
| 179 |
% arity {{ bool -> Type }}) |
| 180 |
% t\ |
| 181 |
% [ constructor "K1" |
| 182 |
% (parameter "y" explicit {{ nat }} y\ |
| 183 |
% (parameter "x" explicit a x\ |
| 184 |
% (parameter "n" maximal {{ nat }} n\ |
| 185 |
% arity {{ S lp:n = lp:y -> lp:t lp:n true -> lp:t lp:y true }}))) |
| 186 |
% , constructor "K2" |
| 187 |
% (parameter "y" explicit {{ nat }} y\ |
| 188 |
% arity {{ lp:t lp:y false }}) ]) |
| 189 |
% |
| 190 |
% Remark that the uniform parameters are not passed to occurrences of t, since |
| 191 |
% they never change, while non-uniform parameters are both abstracted |
| 192 |
% in each constructor type and passed as arguments to t. |
| 193 |
% |
| 194 |
% The coq.typecheck-indt-decl API can be used to fill in implicit arguments |
| 195 |
% an infer universe constraints in the declaration above (e.g. the hidden |
| 196 |
% argument of "=" in the arity of K1). |
| 197 |
% |
| 198 |
% Note: when and inductive type declaration is passed as an argument to an |
| 199 |
% Elpi command non uniform parameters must be separated from the uniform ones |
| 200 |
% with a | (a syntax introduced in Coq 8.12 and accepted by rocq-elpi since |
| 201 |
% version 1.4, in Coq this separator is optional, but not in Elpi). |
| 202 |
|
| 203 |
% Context declaration (used as an argument to Elpi commands) |
| 204 |
kind context-decl type. |
| 205 |
% Eg. (x : T) or (x := B), body is optional, type may be a variable |
| 206 |
external symbol context-item : id -> implicit_kind -> term -> option term -> (term -> context-decl) -> context-decl. |
| 207 |
external symbol context-end : context-decl. |
| 208 |
|
| 209 |
typeabbrev field-attributes (list field-attribute). |
| 210 |
|
| 211 |
macro @global! :- get-option "coq:locality" "global". |
| 212 |
macro @local! :- get-option "coq:locality" "local". |
| 213 |
|
| 214 |
|
| 215 |
% Coq terms are not visible at synterp time, they are always holes |
| 216 |
|
| 217 |
kind term type. |
| 218 |
|
| 219 |
kind sealed-goal type. |
| 220 |
|
| 221 |
kind gref type. |
| 222 |
|
| 223 |
kind abbreviation type. |
| 224 |
|
| 225 |
% -- Parsing time APIs |
| 226 |
% ---------------------------------------------------- |
| 227 |
|
| 228 |
% [id] is a name that matters, we piggy back on Elpi's strings. |
| 229 |
% Note: [name] is a name that does not matter. |
| 230 |
typeabbrev id string. |
| 231 |
|
| 232 |
|
| 233 |
% Name of a module /*E*/ |
| 234 |
kind modpath type. |
| 235 |
|
| 236 |
|
| 237 |
% Name of a module type /*E*/ |
| 238 |
kind modtypath type. |
| 239 |
|
| 240 |
|
| 241 |
% [coq.locate-module ModName ModPath] locates a module. It's a fatal error |
| 242 |
% if ModName cannot be located. *E* |
| 243 |
external func coq.locate-module id -> modpath. |
| 244 |
|
| 245 |
% [coq.locate-module-type ModName ModPath] locates a module. It's a fatal |
| 246 |
% error if ModName cannot be located. *E* |
| 247 |
external func coq.locate-module-type id -> modtypath. |
| 248 |
|
| 249 |
% Result of coq.locate-all |
| 250 |
kind located type. |
| 251 |
external symbol loc-gref : gref -> located = "1". |
| 252 |
external symbol loc-modpath : modpath -> located = "1". |
| 253 |
external symbol loc-modtypath : modtypath -> located = "1". |
| 254 |
external symbol loc-abbreviation : abbreviation -> located = "1". |
| 255 |
|
| 256 |
% [coq.locate-all Name Located] finds all possible meanings of a string. |
| 257 |
% Does not fail. |
| 258 |
external func coq.locate-all id -> list located. |
| 259 |
|
| 260 |
% Coq Module inline directive |
| 261 |
kind coq.inline type. |
| 262 |
external symbol coq.inline.no : coq.inline = "1". % Coq's [no inline] (aka !) |
| 263 |
external symbol coq.inline.default : coq.inline = "1". % The default, can be omitted |
| 264 |
external symbol coq.inline.at : int -> coq.inline = "1". % Coq's [inline at <num>] |
| 265 |
|
| 266 |
external func coq.env.begin-module-functor % Starts a functor *E* |
| 267 |
id, % The name of the functor |
| 268 |
option modtypath, % Its module type |
| 269 |
list (pair id modtypath). % Parameters of the functor |
| 270 |
|
| 271 |
|
| 272 |
func coq.env.begin-module id, option modtypath -> . |
| 273 |
coq.env.begin-module Name MP :- |
| 274 |
coq.env.begin-module-functor Name MP []. |
| 275 |
|
| 276 |
|
| 277 |
% [coq.env.end-module ModPath] end the current module that becomes known as |
| 278 |
% ModPath *E* |
| 279 |
external func coq.env.end-module -> modpath. |
| 280 |
|
| 281 |
external func coq.env.begin-module-type-functor % Starts a module type functor *E* |
| 282 |
id, % The name of the functor |
| 283 |
list (pair id modtypath). % The parameters of the functor |
| 284 |
|
| 285 |
|
| 286 |
func coq.env.begin-module-type id ->. |
| 287 |
coq.env.begin-module-type Name :- |
| 288 |
coq.env.begin-module-type-functor Name []. |
| 289 |
|
| 290 |
|
| 291 |
% [coq.env.end-module-type ModTyPath] end the current module type that |
| 292 |
% becomes known as ModPath *E* |
| 293 |
external func coq.env.end-module-type -> modtypath. |
| 294 |
|
| 295 |
external func coq.env.apply-module-functor % Applies a functor *E* |
| 296 |
id, % The name of the new module |
| 297 |
option modtypath, % Its module type |
| 298 |
modpath, % The functor being applied |
| 299 |
list modpath, % Its arguments |
| 300 |
coq.inline % Arguments inlining |
| 301 |
-> modpath. % The modpath of the new module |
| 302 |
|
| 303 |
external func coq.env.apply-module-type-functor % Applies a type functor *E* |
| 304 |
id, % The name of the new module type |
| 305 |
modtypath, % The functor |
| 306 |
list modpath, % Its arguments |
| 307 |
coq.inline % Arguments inlining |
| 308 |
-> modtypath. % The modtypath of the new module type |
| 309 |
|
| 310 |
% [coq.env.include-module ModPath Inline] is like the vernacular Include, |
| 311 |
% Inline can be omitted *E* |
| 312 |
external func coq.env.include-module modpath, coq.inline. |
| 313 |
|
| 314 |
% [coq.env.include-module-type ModTyPath Inline] is like the vernacular |
| 315 |
% Include Type, Inline can be omitted *E* |
| 316 |
external func coq.env.include-module-type modtypath, coq.inline. |
| 317 |
|
| 318 |
% [coq.env.import-module ModPath] is like the vernacular Import *E* |
| 319 |
external func coq.env.import-module modpath. |
| 320 |
|
| 321 |
% [coq.env.export-module ModPath] is like the vernacular Export *E* |
| 322 |
external func coq.env.export-module modpath. |
| 323 |
|
| 324 |
% [coq.env.begin-section Name] starts a section named Name *E* |
| 325 |
external func coq.env.begin-section id. |
| 326 |
|
| 327 |
% [coq.env.end-section] end the current section *E* |
| 328 |
external func coq.env.end-section. |
| 329 |
|
| 330 |
% [coq.modpath->path MP FullPath] extract the full kernel name, each |
| 331 |
% component is a separate list item |
| 332 |
external func coq.modpath->path modpath -> list string. |
| 333 |
|
| 334 |
% [coq.modtypath->path MTP FullPath] extract the full kernel name, each |
| 335 |
% component is a separate list item |
| 336 |
external func coq.modtypath->path modtypath -> list string. |
| 337 |
|
| 338 |
% [coq.modpath->library MP LibraryPath] extract the enclosing module which |
| 339 |
% can be Required |
| 340 |
external func coq.modpath->library modpath -> modpath. |
| 341 |
|
| 342 |
% [coq.modtypath->library MTP LibraryPath] extract the enclosing module |
| 343 |
% which can be Required |
| 344 |
external func coq.modtypath->library modtypath -> modpath. |
| 345 |
|
| 346 |
% [coq.env.current-path Path] lists the current module path |
| 347 |
external func coq.env.current-path -> list string. |
| 348 |
|
| 349 |
% [coq.env.current-section-path Path] lists the current section path |
| 350 |
external func coq.env.current-section-path -> list string. |
| 351 |
|
| 352 |
% clauses |
| 353 |
% |
| 354 |
% A clause like |
| 355 |
% :name "foo" :before "bar" foo X Y :- bar X Z, baz Z Y |
| 356 |
% is represented as |
| 357 |
% clause "foo" (before "bar") (pi x y z\ foo x y :- bar x z, baz z y) |
| 358 |
% that is exactly what one would load in the context using =>. |
| 359 |
% |
| 360 |
% The name and the grafting specification can be left unspecified. |
| 361 |
kind clause type. |
| 362 |
external symbol clause : id -> grafting -> prop -> clause = "1". |
| 363 |
|
| 364 |
% Specify if the clause has to be grafted before, grafted after or replace |
| 365 |
% a named clause |
| 366 |
kind grafting type. |
| 367 |
external symbol before : id -> grafting = "1". |
| 368 |
external symbol after : id -> grafting = "1". |
| 369 |
external symbol remove : id -> grafting = "1". |
| 370 |
external symbol replace : id -> grafting = "1". |
| 371 |
|
| 372 |
% Specify to which module the clause should be attached to |
| 373 |
kind scope type. |
| 374 |
external symbol execution-site : scope = "1". % The module inside which the Elpi program is run |
| 375 |
external symbol current : scope = "1". % The module being defined (see begin/end-module) |
| 376 |
external symbol library : scope = "1". % The outermost module (carrying the file name) |
| 377 |
|
| 378 |
|
| 379 |
% see coq.elpi.accumulate-clauses |
| 380 |
func coq.elpi.accumulate scope, id, clause ->. |
| 381 |
coq.elpi.accumulate S N C :- coq.elpi.accumulate-clauses S N [C]. |
| 382 |
|
| 383 |
|
| 384 |
% [coq.elpi.accumulate-clauses Scope DbName Clauses] |
| 385 |
% Declare that, once the program is over, the given clauses has to be |
| 386 |
% added to the given db (see Elpi Db). |
| 387 |
% Clauses usually belong to Coq modules: the Scope argument lets one |
| 388 |
% select which module: |
| 389 |
% - execution site (default) is the module in which the pogram is |
| 390 |
% invoked |
| 391 |
% - current is the module currently being constructed (see |
| 392 |
% begin/end-module) |
| 393 |
% - library is the current file (the module that is named after the file) |
| 394 |
% The clauses are visible as soon as the enclosing module is |
| 395 |
% Imported. |
| 396 |
% Clauses cannot be accumulated inside functors. |
| 397 |
% Supported attributes: |
| 398 |
% - @local! (default: false, discard at the end of section or module) |
| 399 |
% - @global! (default: false, always active, only if Scope is |
| 400 |
% execution-site, discouraged) |
| 401 |
external func coq.elpi.accumulate-clauses scope, id, list clause. |
| 402 |
|
| 403 |
% Action executed during the parsing phase (aka synterp) |
| 404 |
kind synterp-action type. |
| 405 |
external symbol begin-module : id -> synterp-action = "1". |
| 406 |
external symbol begin-module-type : id -> synterp-action = "1". |
| 407 |
external symbol begin-section : id -> synterp-action = "1". |
| 408 |
external symbol end-module : modpath -> synterp-action = "1". |
| 409 |
external symbol end-module-type : modtypath -> synterp-action = "1". |
| 410 |
external symbol end-section : synterp-action = "1". |
| 411 |
external symbol apply-module-functor : id -> synterp-action = "1". |
| 412 |
external symbol apply-module-type-functor : id -> synterp-action = "1". |
| 413 |
external symbol include-module : modpath -> synterp-action = "1". |
| 414 |
external symbol include-module-type : modtypath -> synterp-action = "1". |
| 415 |
external symbol import-module : modpath -> synterp-action = "1". |
| 416 |
external symbol export-module : modpath -> synterp-action = "1". |
| 417 |
|
| 418 |
% Synterp action group |
| 419 |
kind group type. |
| 420 |
|
| 421 |
|
| 422 |
% [coq.synterp-actions A] Get the list of actions performed during the |
| 423 |
% parsing phase (aka synterp) up to now. |
| 424 |
external func coq.synterp-actions -> list synterp-action. |
| 425 |
|
| 426 |
% [coq.begin-synterp-group ID Group] Create and open a new synterp action |
| 427 |
% group with the given name. |
| 428 |
external func coq.begin-synterp-group id -> group. |
| 429 |
|
| 430 |
% [coq.end-synterp-group Group] End the synterp action group Group. Group |
| 431 |
% must refer to the most recently openned group. |
| 432 |
external func coq.end-synterp-group group. |
| 433 |
|
| 434 |
% Generic attribute value |
| 435 |
kind attribute-value type. |
| 436 |
external symbol leaf-str : string -> attribute-value = "1". |
| 437 |
external symbol leaf-loc : loc -> attribute-value = "1". |
| 438 |
external symbol node : list attribute -> attribute-value = "1". |
| 439 |
|
| 440 |
% Generic attribute |
| 441 |
kind attribute type. |
| 442 |
external symbol attribute : string -> attribute-value -> attribute = "1". |
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|