aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--.gitattributes3
-rw-r--r--.github/CODEOWNERS19
-rw-r--r--.gitlab-ci.yml13
-rw-r--r--CHANGES12
-rw-r--r--CONTRIBUTING.md10
-rw-r--r--INSTALL27
-rw-r--r--META.coq2
-rw-r--r--Makefile.doc8
-rw-r--r--clib/cArray.ml12
-rw-r--r--clib/cArray.mli2
-rwxr-xr-xdev/build/osx/make-macos-dmg.sh12
-rwxr-xr-xdev/build/windows/MakeCoq_88git_installer.bat27
-rw-r--r--dev/build/windows/MakeCoq_MinGW.bat3
-rw-r--r--dev/build/windows/configure_profile.sh24
-rw-r--r--dev/build/windows/difftar-folder.sh22
-rw-r--r--dev/build/windows/makecoq_mingw.sh273
-rw-r--r--dev/ci/appveyor.sh4
-rwxr-xr-xdev/ci/ci-bignums.sh8
-rwxr-xr-xdev/ci/ci-color.sh6
-rw-r--r--dev/ci/ci-common.sh9
-rwxr-xr-xdev/ci/ci-compcert.sh8
-rwxr-xr-xdev/ci/ci-coq-dpdgraph.sh8
-rwxr-xr-xdev/ci/ci-coquelicot.sh8
-rwxr-xr-xdev/ci/ci-corn.sh8
-rwxr-xr-xdev/ci/ci-cpdt.sh3
-rwxr-xr-xdev/ci/ci-elpi.sh8
-rwxr-xr-xdev/ci/ci-equations.sh8
-rwxr-xr-xdev/ci/ci-fiat-crypto.sh10
-rwxr-xr-xdev/ci/ci-fiat-parsers.sh8
-rwxr-xr-xdev/ci/ci-flocq.sh8
-rwxr-xr-xdev/ci/ci-formal-topology.sh8
-rwxr-xr-xdev/ci/ci-geocoq.sh8
-rwxr-xr-xdev/ci/ci-hott.sh8
-rwxr-xr-xdev/ci/ci-iris-lambda-rust.sh32
-rwxr-xr-xdev/ci/ci-ltac2.sh8
-rwxr-xr-xdev/ci/ci-math-classes.sh8
-rwxr-xr-xdev/ci/ci-math-comp.sh8
-rwxr-xr-xdev/ci/ci-metacoq.sh10
-rwxr-xr-xdev/ci/ci-sf.sh29
-rwxr-xr-xdev/ci/ci-template.sh8
-rwxr-xr-xdev/ci/ci-tlc.sh8
-rwxr-xr-xdev/ci/ci-unimath.sh9
-rwxr-xr-xdev/ci/ci-vst.sh8
-rw-r--r--dev/ci/user-overlays/00669-maximedenes-ssr-merge.sh2
-rw-r--r--dev/ci/user-overlays/06405-maximedenes-rm-local-polymorphic-flag.sh4
-rw-r--r--dev/ci/user-overlays/06482-ppedrot-check-poly-effects.sh4
-rw-r--r--dev/ci/user-overlays/06493-gares-API-remove-big-file.sh8
-rw-r--r--dev/ci/user-overlays/06511-ejgallego-econstr+more_fix.sh7
-rw-r--r--dev/ci/user-overlays/06535-fix-push-rel-to-named.sh4
-rw-r--r--dev/ci/user-overlays/06676-gares-proofview-goals-come-with-a-state.sh6
-rw-r--r--dev/ci/user-overlays/06686-ccnv-no-proj.sh4
-rw-r--r--dev/ci/user-overlays/06745-ejgallego-located+vernac.sh13
-rw-r--r--dev/ci/user-overlays/06775-univ-cumul-weak.sh4
-rw-r--r--dev/ci/user-overlays/06831-ejgallego-located+vernac_2.sh14
-rw-r--r--dev/ci/user-overlays/06837-ejgallego-located+libnames.sh15
-rw-r--r--dev/ci/user-overlays/06869-ejgallego-ssr+correct_packing.sh12
-rw-r--r--dev/ci/user-overlays/06923-ppedrot-export-options.sh7
-rw-r--r--dev/ci/user-overlays/06960-ejgallego-ltac+tacdepr.sh12
-rw-r--r--dev/ci/user-overlays/README.md2
-rw-r--r--dev/doc/MERGING.md50
-rwxr-xr-xdev/lint-repository.sh2
-rwxr-xr-xdev/tools/backport-pr.sh10
-rwxr-xr-xdev/tools/check-overlays.sh11
-rwxr-xr-xdev/tools/merge-pr.sh22
-rwxr-xr-xdev/tools/pre-commit2
-rw-r--r--doc/refman/AsyncProofs.tex221
-rw-r--r--doc/refman/Classes.tex578
-rw-r--r--doc/refman/Coercion.tex563
-rw-r--r--doc/refman/Extraction.tex620
-rw-r--r--doc/refman/Misc.tex63
-rw-r--r--doc/refman/Nsatz.tex102
-rw-r--r--doc/refman/Polynom.tex736
-rw-r--r--doc/refman/Program.tex329
-rw-r--r--doc/refman/Reference-Manual.tex9
-rw-r--r--doc/refman/Setoid.tex842
-rw-r--r--doc/sphinx/addendum/extraction.rst586
-rw-r--r--doc/sphinx/addendum/generalized-rewriting.rst845
-rw-r--r--doc/sphinx/addendum/implicit-coercions.rst469
-rw-r--r--doc/sphinx/addendum/miscellaneous-extensions.rst67
-rw-r--r--doc/sphinx/addendum/nsatz.rst101
-rw-r--r--doc/sphinx/addendum/parallel-proof-processing.rst229
-rw-r--r--doc/sphinx/addendum/program.rst381
-rw-r--r--doc/sphinx/addendum/ring.rst770
-rw-r--r--doc/sphinx/addendum/type-classes.rst587
-rw-r--r--doc/sphinx/credits.rst4
-rw-r--r--doc/sphinx/index.rst9
-rw-r--r--doc/sphinx/language/gallina-extensions.rst9
-rw-r--r--doc/sphinx/replaces.rst8
-rw-r--r--engine/evarutil.ml6
-rw-r--r--engine/evarutil.mli2
-rw-r--r--engine/proofview.ml12
-rw-r--r--engine/proofview.mli9
-rw-r--r--engine/termops.ml8
-rwxr-xr-xide/MacOS/relatify_with-respect-to_.sh15
-rw-r--r--interp/constrextern.ml45
-rw-r--r--interp/impargs.ml294
-rw-r--r--interp/implicit_quantifiers.ml36
-rw-r--r--intf/evar_kinds.ml4
-rw-r--r--intf/misctypes.ml13
-rw-r--r--intf/pattern.ml5
-rw-r--r--intf/vernacexpr.ml20
-rw-r--r--parsing/g_vernac.ml445
-rw-r--r--plugins/funind/glob_term_to_relation.ml4
-rw-r--r--plugins/funind/invfun.ml2
-rw-r--r--plugins/ltac/pltac.mli2
-rw-r--r--plugins/ltac/pptactic.mli2
-rw-r--r--plugins/ltac/tacarg.mli6
-rw-r--r--plugins/ltac/tacexpr.ml18
-rw-r--r--plugins/ltac/tacexpr.mli18
-rw-r--r--plugins/ltac/tactic_debug.ml7
-rw-r--r--plugins/micromega/Tauto.v4
-rw-r--r--plugins/ssr/ssripats.ml10
-rw-r--r--plugins/ssr/ssrparser.ml413
-rw-r--r--pretyping/cases.ml2
-rw-r--r--pretyping/constr_matching.ml49
-rw-r--r--pretyping/detyping.ml163
-rw-r--r--pretyping/detyping.mli7
-rw-r--r--pretyping/evardefine.ml9
-rw-r--r--pretyping/glob_ops.ml2
-rw-r--r--pretyping/patternops.ml132
-rw-r--r--printing/ppvernac.ml36
-rw-r--r--stm/stm.ml91
-rw-r--r--stm/stm.mli36
-rw-r--r--stm/vernac_classifier.ml14
-rw-r--r--tactics/equality.mli10
-rw-r--r--tactics/inv.ml5
-rw-r--r--tactics/inv.mli5
-rw-r--r--tactics/tacticals.ml27
-rw-r--r--tactics/tacticals.mli2
-rw-r--r--tactics/tactics.ml29
-rw-r--r--tactics/tactics.mli8
-rw-r--r--test-suite/bugs/closed/1341.v2
-rw-r--r--test-suite/bugs/closed/1844.v2
-rw-r--r--test-suite/bugs/closed/1891.v2
-rw-r--r--test-suite/bugs/closed/1951.v2
-rw-r--r--test-suite/bugs/closed/1981.v2
-rw-r--r--test-suite/bugs/closed/2362.v2
-rw-r--r--test-suite/bugs/closed/2378.v6
-rw-r--r--test-suite/bugs/closed/2404.v4
-rw-r--r--test-suite/bugs/closed/2584.v2
-rw-r--r--test-suite/bugs/closed/2667.v4
-rw-r--r--test-suite/bugs/closed/2729.v4
-rw-r--r--test-suite/bugs/closed/2830.v10
-rw-r--r--test-suite/bugs/closed/3068.v2
-rw-r--r--test-suite/bugs/closed/3513.v2
-rw-r--r--test-suite/bugs/closed/3647.v6
-rw-r--r--test-suite/bugs/closed/3732.v2
-rw-r--r--test-suite/bugs/closed/4095.v2
-rw-r--r--test-suite/bugs/closed/4865.v2
-rw-r--r--test-suite/bugs/closed/6631.v7
-rw-r--r--test-suite/bugs/closed/7092.v70
-rw-r--r--test-suite/bugs/opened/2456.v2
-rw-r--r--test-suite/bugs/opened/3295.v4
-rw-r--r--test-suite/complexity/injection.v2
-rwxr-xr-xtest-suite/coq-makefile/coqdoc1/run.sh10
-rwxr-xr-xtest-suite/coq-makefile/coqdoc2/run.sh8
-rwxr-xr-xtest-suite/coq-makefile/findlib-package/run.sh3
-rwxr-xr-xtest-suite/coq-makefile/mlpack1/run.sh2
-rwxr-xr-xtest-suite/coq-makefile/mlpack2/run.sh2
-rwxr-xr-xtest-suite/coq-makefile/multiroot/run.sh7
-rwxr-xr-xtest-suite/coq-makefile/native1/run.sh8
-rwxr-xr-xtest-suite/coq-makefile/plugin1/run.sh2
-rwxr-xr-xtest-suite/coq-makefile/plugin2/run.sh2
-rwxr-xr-xtest-suite/coq-makefile/plugin3/run.sh2
-rwxr-xr-xtest-suite/coq-makefile/quick2vo/run.sh4
-rwxr-xr-xtest-suite/coq-makefile/template/init.sh3
-rwxr-xr-xtest-suite/coq-makefile/template/path-init.sh1
-rwxr-xr-xtest-suite/coq-makefile/timing/precomputed-time-tests/run.sh7
-rwxr-xr-xtest-suite/coq-makefile/timing/run.sh29
-rwxr-xr-xtest-suite/coq-makefile/uninstall1/run.sh7
-rwxr-xr-xtest-suite/coq-makefile/uninstall2/run.sh7
-rwxr-xr-xtest-suite/coq-makefile/vio2vo/run.sh4
-rw-r--r--test-suite/failure/check.v2
-rw-r--r--test-suite/ide/bug7088.fake13
-rw-r--r--test-suite/ide/load.fake11
-rwxr-xr-xtest-suite/misc/deps-checksum.sh1
-rwxr-xr-xtest-suite/misc/deps-order.sh9
-rwxr-xr-xtest-suite/misc/deps-utf8.sh9
-rwxr-xr-xtest-suite/misc/exitstatus.sh7
-rwxr-xr-xtest-suite/misc/printers.sh5
-rwxr-xr-xtest-suite/misc/universes.sh5
-rw-r--r--test-suite/modules/PO.v4
-rw-r--r--test-suite/modules/Przyklad.v2
-rw-r--r--test-suite/output/Errors.out8
-rw-r--r--test-suite/output/Errors.v6
-rw-r--r--test-suite/output/Projections.out2
-rw-r--r--test-suite/output/Projections.v11
-rw-r--r--test-suite/output/bug5778.out4
-rw-r--r--test-suite/output/bug6404.out4
-rw-r--r--test-suite/output/bug6404.v7
-rw-r--r--test-suite/output/ssr_clear.out3
-rw-r--r--test-suite/output/ssr_clear.v6
-rw-r--r--test-suite/prerequisite/make_local.v3
-rw-r--r--test-suite/success/AdvancedTypeClasses.v4
-rw-r--r--test-suite/success/ImplicitArguments.v2
-rw-r--r--test-suite/success/Inductive.v2
-rw-r--r--test-suite/success/Inversion.v2
-rw-r--r--test-suite/success/RecTutorial.v12
-rw-r--r--test-suite/success/Record.v2
-rw-r--r--test-suite/success/Scopes.v2
-rw-r--r--test-suite/success/Typeclasses.v4
-rw-r--r--test-suite/success/apply.v2
-rw-r--r--test-suite/success/dependentind.v2
-rw-r--r--test-suite/success/evars.v2
-rw-r--r--test-suite/success/implicit.v12
-rw-r--r--tools/gallina-syntax.el1
-rw-r--r--toplevel/coqloop.ml30
-rw-r--r--toplevel/coqtop.ml25
-rw-r--r--toplevel/g_toplevel.ml44
-rw-r--r--vernac/himsg.ml10
-rw-r--r--vernac/vernacentries.ml27
-rw-r--r--vernac/vernacprop.ml1
212 files changed, 5590 insertions, 5224 deletions
diff --git a/.gitattributes b/.gitattributes
index db179c8d2..e087e1737 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -19,6 +19,7 @@ tools/CoqMakefile.in whitespace=trailing-space
*.css whitespace=trailing-space,tab-in-indent
*.dtd whitespace=trailing-space,tab-in-indent
*.el whitespace=trailing-space,tab-in-indent
+*.g whitespace=trailing-space,tab-in-indent
*.h whitespace=trailing-space,tab-in-indent
*.html whitespace=trailing-space,tab-in-indent
*.hva whitespace=trailing-space,tab-in-indent
@@ -37,9 +38,11 @@ tools/CoqMakefile.in whitespace=trailing-space
*.nsh whitespace=trailing-space,tab-in-indent
*.nsi whitespace=trailing-space,tab-in-indent
*.py whitespace=trailing-space,tab-in-indent
+*.rst whitespace=trailing-space,tab-in-indent
*.sh whitespace=trailing-space,tab-in-indent
*.sty whitespace=trailing-space,tab-in-indent
*.tex whitespace=trailing-space,tab-in-indent
+*.tokens whitespace=trailing-space,tab-in-indent
*.txt whitespace=trailing-space,tab-in-indent
*.v whitespace=trailing-space,tab-in-indent
*.xml whitespace=trailing-space,tab-in-indent
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index fea50c58c..f344c5cf5 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -37,6 +37,10 @@
/dev/doc/ @Zimmi48
# Secondary maintainer @maximedenes
+/dev/doc/changes.md @ghost
+# Trick to avoid getting review requests
+# each time someone modifies the dev changelog
+
/doc/ @maximedenes
# Secondary maintainer @silene
@@ -104,8 +108,8 @@
/plugins/btauto/ @ppedrot
# Secondary maintainer @herbelin
-# I don't know Pierre Corbineau's GitHub nickname
-/plugins/cc/ @herbelin
+/plugins/cc/ @PierreCorbineau
+# Secondary maintainer @herbelin
/plugins/derive/ @aspiwack
# Secondary maintainer @ppedrot
@@ -113,8 +117,8 @@
/plugins/extraction/ @letouzey
# Secondary maintainer @maximedenes
-# I don't know Pierre Corbineau's GitHub nickname
-/plugins/firstorder/ @herbelin
+/plugins/firstorder/ @PierreCorbineau
+# Secondary maintainer @herbelin
/plugins/fourier/ @herbelin
# Secondary maintainer @gares
@@ -149,8 +153,8 @@
/plugins/quote/ @herbelin
-# Should be Pierre Corbineau too
-/plugins/rtauto/ @herbelin
+/plugins/rtauto/ @PierreCorbineau
+# Secondary maintainer @herbelin
########## Pretyper ##########
@@ -294,6 +298,9 @@
/META.coq @ejgallego
# Secondary maintainer @letouzey
+/dev/build/windows @MSoegtropIMC
+# Secondary maintainer @maximedenes
+
########## Developer tools ##########
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 03e001f4a..f0d7463fc 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -85,10 +85,6 @@ before_script:
- echo 'end:coq.install'
- set +e
- variables: &build-variables
- EXTRA_CONF: "-native-compiler yes -coqide opt"
- EXTRA_PACKAGES: "$COQIDE_PACKAGES"
- EXTRA_OPAM: "$COQIDE_OPAM"
.warnings-template: &warnings-template
# keep warnings in test stage so we can test things even when warnings occur
@@ -151,9 +147,9 @@ before_script:
build:
<<: *build-template
variables:
- EXTRA_CONF: "-with-doc yes"
- EXTRA_PACKAGES: "$COQDOC_PACKAGES"
- EXTRA_OPAM: "$COQDOC_OPAM"
+ EXTRA_CONF: "-native-compiler yes -coqide opt -with-doc yes"
+ EXTRA_PACKAGES: "$COQIDE_PACKAGES $COQDOC_PACKAGES"
+ EXTRA_OPAM: "$COQIDE_OPAM $COQDOC_OPAM"
PIP_PACKAGES: "$SPHINX_PACKAGES"
# no coqide for 32bit: libgtk installation problems
@@ -167,9 +163,10 @@ build:32bit:
build:bleeding-edge:
<<: *build-template
variables:
- <<: *build-variables
+ EXTRA_CONF: "-native-compiler yes -coqide opt"
COMPILER: "$COMPILER_BLEEDING_EDGE"
CAMLP5_VER: "$CAMLP5_VER_BLEEDING_EDGE"
+ EXTRA_PACKAGES: "$COQIDE_PACKAGES"
EXTRA_OPAM: "$COQIDE_OPAM_BE"
warnings:
diff --git a/CHANGES b/CHANGES
index 24c4cfec0..3994caef6 100644
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,18 @@ Tools
- Coq_makefile lets one override or extend the following variables from
the command line: COQFLAGS, COQCHKFLAGS, COQDOCFLAGS.
+Vernacular Commands
+
+- Removed deprecated commands Arguments Scope and Implicit Arguments
+ (not the option). Use the Arguments command instead.
+
+Tactic language
+
+- Support for fix/cofix added in Ltac "match" and "lazymatch".
+
+- Ltac backtraces now contain include trace information about tactics
+ called by OCaml-defined tactics.
+
Changes from 8.7.2 to 8.8+beta1
===============================
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 213b87735..1a3c99369 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -38,13 +38,11 @@ Whitespace discipline (do not indent using tabs, no trailing spaces, text files
Here are a few tags Coq developers may add to your PR and what they mean. In general feedback and requests for you as the pull request author will be in the comments and tags are only used to organize pull requests.
-- [needs: rebase](https://github.com/coq/coq/pulls?utf8=%E2%9C%93&q=is%3Aopen%20is%3Apr%20label%3A%22needs%3A%20rebase%22%20) indicates the PR should be rebased on top of the latest `master` branch. See the [GitHub documentation](https://help.github.com/articles/about-git-rebase/) for a brief introduction to using `git rebase`.
+- [needs: rebase](https://github.com/coq/coq/pulls?utf8=%E2%9C%93&q=is%3Aopen%20is%3Apr%20label%3A%22needs%3A%20rebase%22) indicates the PR should be rebased on top of the latest `master` branch. See the [GitHub documentation](https://help.github.com/articles/about-git-rebase/) for a brief introduction to using `git rebase`.
- [needs: fixing](https://github.com/coq/coq/pulls?q=is%3Aopen+is%3Apr+label%3A%22needs%3A+fixing%22) indicates the PR needs a fix, as discussed in the comments.
-- [needs: testing](https://github.com/coq/coq/pulls?q=is%3Aopen+is%3Apr+label%3A%22needs%3A+testing%22) indicates the PR needs testing. This is often used when testing beyond what the test suite can handle is required. For example, performance benchmarking is currently performed with a different infrastructure. Unless some followup is specifically requested you aren't expected to do this additional testing.
+- [needs: benchmarking](https://github.com/coq/coq/pulls?q=is%3Aopen+is%3Apr+label%3A%22needs%3A+benchmarking%22) and [needs: testing](https://github.com/coq/coq/pulls?q=is%3Aopen+is%3Apr+label%3A%22needs%3A+testing%22) indicate the PR needs testing beyond what the test suite can handle. For example, performance benchmarking is currently performed with a different infrastructure. Unless some followup is specifically requested you aren't expected to do this additional testing.
-The release manager uses the following filter to know which PRs seem ready for merge. If you are waiting for a PR to be merged, make sure it appears in this list:
-
-- [Pull requests ready for merge](https://github.com/coq/coq/pulls?utf8=%E2%9C%93&q=is%3Apr%20is%3Aopen%20-label%3A%22needs%3A%20discussion%22%20-label%3A%22needs%3A%20testing%22%20-label%3A%22needs%3A%20fixing%22%20-label%3A%22needs%3A%20progress%22%20-label%3A%22needs%3A%20rebase%22%20-label%3A%22needs%3A%20review%22%20-label%3A%22needs%3A%20help%22%20-label%3A%22needs%3A%20independent%20fix%22%20-label%3A%22needs%3A%20feedback%22%20-label%3A%22help%20wanted%22%20-review%3Achanges_requested%20-status%3Apending%20base%3Amaster%20sort%3Aupdated-asc%20-label%3A%22needs%3A%20squashing%22%20)
+To learn more about the merging process, you can read the [merging documentation for Coq maintainers](/dev/doc/MERGING.md).
## Documentation
@@ -52,7 +50,7 @@ Currently the process for contributing to the documentation is the same as for c
Our issue tracker includes a flag to mark bugs related to documentation. You can view a list of documentation-related bugs using a [GitHub issue search](https://github.com/coq/coq/issues?q=is%3Aopen+is%3Aissue+label%3A%22kind%3A+documentation%22). Many of these bugs can be fixed by contributing writing, without knowledge of Coq's OCaml source code.
-The sources for the [Coq reference manual](https://coq.inria.fr/distrib/current/refman/) are at [`doc/refman`](/doc/refman). These are written in LaTeX and compiled to HTML with [HeVeA](http://hevea.inria.fr/).
+The sources for the [Coq reference manual](https://coq.inria.fr/distrib/current/refman/) are at [`doc/sphinx`](/doc/sphinx). These are written in reStructuredText and compiled to HTML and PDF with [Sphinx](http://www.sphinx-doc.org/).
You may also contribute to the informal documentation available in [Cocorico](https://github.com/coq/coq/wiki) (the Coq wiki), and the [Coq FAQ](https://github.com/coq/coq/wiki/The-Coq-FAQ). Both of these are editable by anyone with a GitHub account.
diff --git a/INSTALL b/INSTALL
index 3b3fd8b83..984b8e290 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,5 +1,5 @@
- INSTALLATION PROCEDURES FOR THE COQ V8.7 SYSTEM
+ INSTALLATION PROCEDURES FOR THE COQ V8.8 SYSTEM
-----------------------------------------------
@@ -27,7 +27,7 @@ WHAT DO YOU NEED ?
port install coq
- To compile Coq V8.7 yourself, you need:
+ To compile Coq V8.8 yourself, you need:
- OCaml version 4.02.3 or later
(available at https://ocaml.org/)
@@ -45,6 +45,10 @@ WHAT DO YOU NEED ?
- for Coqide, the Lablgtk development files, and the GTK libraries
including gtksourceview, see INSTALL.ide for more details
+ Note that camlp5 and lablgtk should be properly registered with
+ findlib/ocamlfind as Coq's makefile will use it to locate the
+ libraries during the build.
+
Opam (https://opam.ocaml.org/) is recommended to install ocaml and
the corresponding packages.
@@ -52,6 +56,16 @@ WHAT DO YOU NEED ?
should get you a reasonable OCaml environment to compile Coq.
+ Advanced users may want to experiment with the OCaml Flambda
+ compiler as way to improve the performance of Coq. In order to
+ profit from Flambda, a special build of the OCaml compiler that has
+ the Flambda optimizer enabled must be installed. For OPAM users,
+ this amounts to installing a compiler switch ending in `+flambda`,
+ such as `4.06.1+flambda`. For other users, YMMV. Once `ocamlopt
+ -config` reports that Flambda is available, some further
+ optimization options can be used; see the entry about -flambda-opts
+ below for more details.
+
QUICK INSTALLATION PROCEDURE.
=============================
@@ -66,7 +80,7 @@ INSTALLATION PROCEDURE IN DETAILS (NORMAL USERS).
computer and that "ocamlc" (or, better, its native code version
"ocamlc.opt") lies in a directory which is present in your $PATH
environment variable. At the time of writing this sentence, all
- versions of Objective Caml later or equal to 4.02.1 are
+ versions of Objective Caml later or equal to 4.02.3 are
supported.
To get Coq in native-code, (it runs 4 to 10 times faster than
@@ -129,9 +143,10 @@ INSTALLATION PROCEDURE IN DETAILS (NORMAL USERS).
and will be replaced by the URL.
-flambda-opts <flags>
- This experimental option will pass specific user flags to the
+ This experimental option will pass specific user flags to the
OCaml optimizing compiler. In most cases, this option is used
- to tweak the flambda backend; we recommend using
+ to tweak the flambda backend; for maximum performance we
+ recommend using
-flambda-opts `-O3 -unbox-closures`
@@ -144,7 +159,7 @@ INSTALLATION PROCEDURE IN DETAILS (NORMAL USERS).
a large amount of RAM (>= 10GiB) in some particular files.
We recommend disabling native compilation (`-native-compiler no`)
- with flambda unless you use a modern (>= 4.06.0) OCaml.
+ with flambda unless you use OCaml >= 4.07.0.
c.f. https://caml.inria.fr/mantis/view.php?id=7630
diff --git a/META.coq b/META.coq
index 4e53098c7..30bfdd67a 100644
--- a/META.coq
+++ b/META.coq
@@ -20,7 +20,7 @@ package "clib" (
version = "8.8"
directory = "clib"
- requires = "str, unix, threads"
+ requires = "num, str, unix, threads"
archive(byte) = "clib.cma"
archive(native) = "clib.cmxa"
diff --git a/Makefile.doc b/Makefile.doc
index 4a247f1d9..fc791ce1c 100644
--- a/Makefile.doc
+++ b/Makefile.doc
@@ -60,15 +60,11 @@ REFMANCOQTEXFILES:=$(addprefix doc/refman/, \
RefMan-gal.v.tex \
RefMan-oth.v.tex RefMan-ltac.v.tex \
RefMan-pro.v.tex \
- Coercion.v.tex Extraction.v.tex \
- Program.v.tex Polynom.v.tex Nsatz.v.tex \
- Setoid.v.tex Classes.v.tex Universes.v.tex \
- Misc.v.tex)
+ Universes.v.tex)
REFMANTEXFILES:=$(addprefix doc/refman/, \
headers.sty Reference-Manual.tex \
- RefMan-uti.tex \
- AsyncProofs.tex) \
+ RefMan-uti.tex) \
$(REFMANCOQTEXFILES) \
REFMANEPSFILES:=doc/refman/coqide.eps doc/refman/coqide-queries.eps
diff --git a/clib/cArray.ml b/clib/cArray.ml
index b6c033f6d..5eb20bc16 100644
--- a/clib/cArray.ml
+++ b/clib/cArray.ml
@@ -41,6 +41,8 @@ sig
('a -> 'b -> 'c -> 'a) -> 'a -> 'b array -> 'c array -> 'a
val fold_left3 :
('a -> 'b -> 'c -> 'd -> 'a) -> 'a -> 'b array -> 'c array -> 'd array -> 'a
+ val fold_left4 :
+ ('a -> 'b -> 'c -> 'd -> 'e -> 'a) -> 'a -> 'b array -> 'c array -> 'd array -> 'e array -> 'a
val fold_left2_i :
(int -> 'a -> 'b -> 'c -> 'a) -> 'a -> 'b array -> 'c array -> 'a
val fold_left_from : int -> ('a -> 'b -> 'a) -> 'a -> 'b array -> 'a
@@ -267,6 +269,16 @@ let fold_left3 f a v1 v2 v3 =
invalid_arg "Array.fold_left2";
fold a 0
+let fold_left4 f a v1 v2 v3 v4 =
+ let lv1 = Array.length v1 in
+ let rec fold a n =
+ if n >= lv1 then a
+ else fold (f a (uget v1 n) (uget v2 n) (uget v3 n) (uget v4 n)) (succ n)
+ in
+ if Array.length v2 <> lv1 || Array.length v3 <> lv1 || Array.length v4 <> lv1 then
+ invalid_arg "Array.fold_left4";
+ fold a 0
+
let fold_left_from n f a v =
let len = Array.length v in
let () = if n < 0 then invalid_arg "Array.fold_left_from" in
diff --git a/clib/cArray.mli b/clib/cArray.mli
index 97038b0ac..f4f60f8aa 100644
--- a/clib/cArray.mli
+++ b/clib/cArray.mli
@@ -66,6 +66,8 @@ sig
('a -> 'b -> 'c -> 'a) -> 'a -> 'b array -> 'c array -> 'a
val fold_left3 :
('a -> 'b -> 'c -> 'd -> 'a) -> 'a -> 'b array -> 'c array -> 'd array -> 'a
+ val fold_left4 :
+ ('a -> 'b -> 'c -> 'd -> 'e -> 'a) -> 'a -> 'b array -> 'c array -> 'd array -> 'e array -> 'a
val fold_left2_i :
(int -> 'a -> 'b -> 'c -> 'a) -> 'a -> 'b array -> 'c array -> 'a
val fold_left_from : int -> ('a -> 'b -> 'a) -> 'a -> 'b array -> 'a
diff --git a/dev/build/osx/make-macos-dmg.sh b/dev/build/osx/make-macos-dmg.sh
index dc33838f1..c450e8157 100755
--- a/dev/build/osx/make-macos-dmg.sh
+++ b/dev/build/osx/make-macos-dmg.sh
@@ -10,19 +10,19 @@ VERSION=$(sed -n -e '/^let coq_version/ s/^[^"]*"\([^"]*\)"$/\1/p' configure.ml)
APP=bin/CoqIDE_${VERSION}.app
# Create a .app file with CoqIDE, without signing it
-make PRIVATEBINARIES=$APP -j $NJOBS -l2 $APP
+make PRIVATEBINARIES="$APP" -j "$NJOBS" -l2 "$APP"
# Add Coq to the .app file
-make OLDROOT=$OUTDIR COQINSTALLPREFIX=$APP/Contents/Resources/ install-coq install-ide-toploop
+make OLDROOT="$OUTDIR" COQINSTALLPREFIX="$APP/Contents/Resources/" install-coq install-ide-toploop
# Create the dmg bundle
-mkdir -p $DMGDIR
-ln -sf /Applications $DMGDIR/Applications
-cp -r $APP $DMGDIR
+mkdir -p "$DMGDIR"
+ln -sf /Applications "$DMGDIR/Applications"
+cp -r "$APP" "$DMGDIR"
mkdir -p _build
# Temporary countermeasure to hdiutil error 5341
# head -c9703424 /dev/urandom > $DMGDIR/.padding
-hdiutil create -imagekey zlib-level=9 -volname coq-$VERSION-installer-macos -srcfolder $DMGDIR -ov -format UDZO _build/coq-$VERSION-installer-macos.dmg
+hdiutil create -imagekey zlib-level=9 -volname "coq-$VERSION-installer-macos" -srcfolder "$DMGDIR" -ov -format UDZO "_build/coq-$VERSION-installer-macos.dmg"
diff --git a/dev/build/windows/MakeCoq_88git_installer.bat b/dev/build/windows/MakeCoq_88git_installer.bat
new file mode 100755
index 000000000..b016fb389
--- /dev/null
+++ b/dev/build/windows/MakeCoq_88git_installer.bat
@@ -0,0 +1,27 @@
+@ECHO OFF
+
+REM ========== COPYRIGHT/COPYLEFT ==========
+
+REM (C) 2016 Intel Deutschland GmbH
+REM Author: Michael Soegtrop
+
+REM Released to the public by Intel under the
+REM GNU Lesser General Public License Version 2.1 or later
+REM See https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
+
+REM ========== BUILD COQ ==========
+
+call MakeCoq_SetRootPath
+
+call MakeCoq_MinGW.bat ^
+ -arch=64 ^
+ -installer=Y ^
+ -coqver=git-v8.8 ^
+ -destcyg=%ROOTPATH%\cygwin_coq64_88_inst ^
+ -destcoq=%ROOTPATH%\coq64_88_inst ^
+ -addon=bignums
+
+IF %ERRORLEVEL% NEQ 0 (
+ ECHO MakeCoq_88git_installer.bat failed with error code %ERRORLEVEL%
+ EXIT /b %ERRORLEVEL%
+)
diff --git a/dev/build/windows/MakeCoq_MinGW.bat b/dev/build/windows/MakeCoq_MinGW.bat
index ccf22cc86..f960ff008 100644
--- a/dev/build/windows/MakeCoq_MinGW.bat
+++ b/dev/build/windows/MakeCoq_MinGW.bat
@@ -34,7 +34,7 @@ REM see -ocaml in ReadMe.txt
SET INSTALLOCAML=N
REM see -make in ReadMe.txt
-SET INSTALLMAKE=Y
+SET INSTALLMAKE=N
REM see -destcyg in ReadMe.txt
SET DESTCYG=C:\bin\cygwin_coq
@@ -267,7 +267,6 @@ IF "%INSTALLMODE%" == "mingwincygwin" (
IF "%MAKEINSTALLER%" == "Y" (
SET INSTALLMODE=relocatable
SET INSTALLOCAML=Y
- SET INSTALLMAKE=Y
)
REM ========== CONFIRM PARAMETERS ==========
diff --git a/dev/build/windows/configure_profile.sh b/dev/build/windows/configure_profile.sh
index 16c972e80..7e606b554 100644
--- a/dev/build/windows/configure_profile.sh
+++ b/dev/build/windows/configure_profile.sh
@@ -14,30 +14,30 @@
rcfile=~/.bash_profile
donefile=~/.bash_profile.upated
+# to learn about `exec >> $file`, see https://www.tldp.org/LDP/abs/html/x17974.html
+exec >> $rcfile
+
if [ ! -f $donefile ] ; then
- echo >> $rcfile
-
- if [ "$1" != "" -a "$1" != " " ]; then
- echo export http_proxy="http://$1" >> $rcfile
- echo export https_proxy="http://$1" >> $rcfile
- echo export ftp_proxy="http://$1" >> $rcfile
+ if [ "$1" != "" ] && [ "$1" != " " ]; then
+ echo export http_proxy="http://$1"
+ echo export https_proxy="http://$1"
+ echo export ftp_proxy="http://$1"
fi
-
- mkdir -p $RESULT_INSTALLDIR_CFMT/bin
+
+ mkdir -p "$RESULT_INSTALLDIR_CFMT/bin"
# A tightly controlled path helps to avoid issues
# Note: the order is important: first have the cygwin binaries, then the mingw binaries in the path!
# Note: /bin is mounted at /usr/bin and /lib at /usr/lib and it is common to use /usr/bin in PATH
# See cat /proc/mounts
- echo "export PATH=/usr/local/bin:/usr/bin:$RESULT_INSTALLDIR_CFMT/bin:/usr/$TARGET_ARCH/sys-root/mingw/bin:/cygdrive/c/Windows/system32:/cygdrive/c/Windows" >> $rcfile
+ echo "export PATH=/usr/local/bin:/usr/bin:$RESULT_INSTALLDIR_CFMT/bin:/usr/$TARGET_ARCH/sys-root/mingw/bin:/cygdrive/c/Windows/system32:/cygdrive/c/Windows"
# find and xargs complain if the environment is larger than (I think) 8k.
# ORIGINAL_PATH (set by cygwin) can be a few k and exceed the limit
- echo unset ORIGINAL_PATH >> $rcfile
-
+ echo unset ORIGINAL_PATH
# Other installations of OCaml will mess up things
- echo unset OCAMLLIB >> $rcfile
+ echo unset OCAMLLIB
touch $donefile
fi
diff --git a/dev/build/windows/difftar-folder.sh b/dev/build/windows/difftar-folder.sh
index cbcf14ec2..3bba451ec 100644
--- a/dev/build/windows/difftar-folder.sh
+++ b/dev/build/windows/difftar-folder.sh
@@ -42,7 +42,7 @@ fi
if [ "$strip" -gt 0 ] ; then
# Get the path/name of the first file from teh tar and extract the first $strip path components
# This assumes that the first file in the tar file has at least $strip many path components
- prefix=$(tar -t -f $tarfile | head -1 | cut -d / -f -$strip)/
+ prefix=$(tar -t -f "$tarfile" | head -1 | cut -d / -f -$strip)/
else
prefix=
fi
@@ -60,13 +60,13 @@ mkdir -p "$empty"
# Print information (this is ignored by patch)
-echo diff/patch file created on $(date) with:
-echo difftar-folder.sh $@
-echo TARFILE= $tarfile
-echo FOLDER= $folder
-echo TARSTRIP= $strip
-echo TARPREFIX= $prefix
-echo ORIGFOLDER= $orig
+echo diff/patch file created on "$(date)" with:
+echo difftar-folder.sh "$@"
+echo TARFILE= "$tarfile"
+echo FOLDER= "$folder"
+echo TARSTRIP= "$strip"
+echo TARPREFIX= "$prefix"
+echo ORIGFOLDER= "$orig"
# Make sure tar uses english output (for Mod time differs)
export LC_ALL=C
@@ -76,14 +76,14 @@ tar --diff -a -f "$tarfile" --strip $strip --directory "$folder" | grep "Mod tim
# Substitute ': Mod time differs' with nothing
file=${file/: Mod time differs/}
# Check if file exists
- if [ -f "$folder/$file" ] ; then
+ if [ -f "$folder/$file" ] ; then
# Extract original file
tar -x -a -f "$tarfile" --strip $strip --directory "$orig" "$prefix$file"
# Compute diff
- diff -u "$orig/$file" "$folder/$file"
+ diff -u "$orig/$file" "$folder/$file"
fi
done
if [ -d "$new" ] ; then
- diff -u -r --unidirectional-new-file $empty $new
+ diff -u -r --unidirectional-new-file "$empty" "$new"
fi
diff --git a/dev/build/windows/makecoq_mingw.sh b/dev/build/windows/makecoq_mingw.sh
index 8e0d2341d..18f1a2f16 100644
--- a/dev/build/windows/makecoq_mingw.sh
+++ b/dev/build/windows/makecoq_mingw.sh
@@ -67,7 +67,7 @@ RMDIR_BEFORE_BUILD=1
###################### ARCHITECTURES #####################
# The OS on which the build of the tool/lib runs
-BUILD=`gcc -dumpmachine`
+BUILD=$(gcc -dumpmachine)
# The OS on which the tool runs
# "`find /bin -name "*mingw32-gcc.exe"`" -dumpmachine
@@ -132,34 +132,38 @@ CYGWIN_REPO_FOLDER=${CYGWIN_REPO_FOLDER//\//%2f}
# Copy files
cp "$CYGWIN_LOCAL_CACHE_WFMT/$CYGWIN_REPO_FOLDER/$CYGWINARCH/setup.ini" $TARBALLS
cp /etc/setup/installed.db $TARBALLS
-
+
###################### LOGGING #####################
# The folder which receives log files
mkdir -p buildlogs
-LOGS=`pwd`/buildlogs
+LOGS=$(pwd)/buildlogs
# The current log target (first part of the log file name)
LOGTARGET=other
+# Log command output - take log target name from command name (like log1 make => log target is "<module>-make")
log1() {
- "$@" > $LOGS/$LOGTARGET-$1.log 2> $LOGS/$LOGTARGET-$1.err
+ "$@" > "$LOGS/$LOGTARGET-$1.log" 2> "$LOGS/$LOGTARGET-$1.err"
}
+# Log command output - take log target name from command name and first argument (like log2 make install => log target is "<module>-make-install")
log2() {
- "$@" > $LOGS/$LOGTARGET-$1-$2.log 2> $LOGS/$LOGTARGET-$1-$2.err
+ "$@" > "$LOGS/$LOGTARGET-$1-$2.log" 2> "$LOGS/$LOGTARGET-$1-$2.err"
}
+# Log command output - take log target name from command name and second argument (like log_1_3 ocaml setup.ml -configure => log target is "<module>-ocaml--configure")
log_1_3() {
- "$@" > $LOGS/$LOGTARGET-$1-$3.log 2> $LOGS/$LOGTARGET-$1-$3.err
+ "$@" > "$LOGS/$LOGTARGET-$1-$3.log" 2> "$LOGS/$LOGTARGET-$1-$3.err"
}
+# Log command output - log target name is first argument (like logn untar tar xvaf ... => log target is "<module>-untar")
logn() {
LOGTARGETEX=$1
shift
- "$@" > $LOGS/$LOGTARGET-$LOGTARGETEX.log 2> $LOGS/$LOGTARGET-$LOGTARGETEX.err
+ "$@" > "$LOGS/$LOGTARGET-$LOGTARGETEX.log" 2> "$LOGS/$LOGTARGET-$LOGTARGETEX.err"
}
-
+
###################### 'UNFIX' SED #####################
# In Cygwin SED used to do CR-LF to LF conversion, but since sed 4.4-1 this was changed
@@ -183,7 +187,7 @@ logn() {
# - create build folder
# - extract source archive
# - patch source file if patch exists
-#
+#
# Parameters
# $1 file server name including protocol prefix
# $2 file name (without extension)
@@ -206,68 +210,68 @@ function get_expand_source_tar {
else
name=$2
fi
-
+
if [ "$#" -ge 6 ] ; then
folder=$6
else
folder=$name
fi
-
+
# Set logging target
logtargetold=$LOGTARGET
LOGTARGET=$name
-
+
# Get the source archive either from the source cache or online
- if [ ! -f $TARBALLS/$name.$3 ] ; then
+ if [ ! -f "$TARBALLS/$name.$3" ] ; then
if [ -f "$SOURCE_LOCAL_CACHE_CFMT/$name.$3" ] ; then
- cp "$SOURCE_LOCAL_CACHE_CFMT/$name.$3" $TARBALLS
+ cp "$SOURCE_LOCAL_CACHE_CFMT/$name.$3" "$TARBALLS"
else
- wget $1/$2.$3
- if file -i $2.$3 | grep text/html; then
- echo Download failed: $1/$2.$3
+ wget "$1/$2.$3"
+ if file -i "$2.$3" | grep text/html; then
+ echo Download failed: "$1/$2.$3"
echo The file wget downloaded is an html file:
- cat $2.$3
+ cat "$2.$3"
exit 1
fi
if [ ! "$2.$3" == "$name.$3" ] ; then
- mv $2.$3 $name.$3
+ mv "$2.$3" "$name.$3"
fi
- mv $name.$3 $TARBALLS
+ mv "$name.$3" "$TARBALLS"
# Save the source archive in the source cache
if [ -d "$SOURCE_LOCAL_CACHE_CFMT" ] ; then
- cp $TARBALLS/$name.$3 "$SOURCE_LOCAL_CACHE_CFMT"
+ cp "$TARBALLS/$name.$3" "$SOURCE_LOCAL_CACHE_CFMT"
fi
fi
fi
-
+
# Remove build directory (clean build)
if [ $RMDIR_BEFORE_BUILD -eq 1 ] ; then
- rm -f -r $folder
+ rm -f -r "$folder"
fi
-
+
# Create build directory and cd
- mkdir -p $folder
- cd $folder
-
+ mkdir -p "$folder"
+ cd "$folder"
+
# Extract source archive
if [ "$3" == "zip" ] ; then
- log1 unzip $TARBALLS/$name.$3
+ log1 unzip "$TARBALLS/$name.$3"
if [ "$strip" == "1" ] ; then
# Ok, this is dirty, but it works and it fails if there are name clashes
- mv */* .
+ mv -- */* .
else
echo "Unzip strip count not supported"
return 1
fi
else
- logn untar tar xvaf $TARBALLS/$name.$3 --strip $strip
+ logn untar tar xvaf "$TARBALLS/$name.$3" --strip $strip
fi
-
+
# Patch if patch file exists
- if [ -f $PATCHES/$name.patch ] ; then
- log1 patch -p1 -i $PATCHES/$name.patch
+ if [ -f "$PATCHES/$name.patch" ] ; then
+ log1 patch -p1 -i "$PATCHES/$name.patch"
fi
-
+
# Go back to base folder
cd ..
@@ -283,7 +287,7 @@ function get_expand_source_tar {
# - cd to build folder and extract source archive
# - create bin_special subfolder and add it to $PATH
# - remember things for build_post
-#
+#
# Parameters
# $1 file server name including protocol prefix
# $2 file name (without extension)
@@ -305,27 +309,27 @@ function build_prep {
else
name=$2
fi
-
+
# Check if build is already done
- if [ ! -f flagfiles/$name.finished ] ; then
+ if [ ! -f "flagfiles/$name.finished" ] ; then
BUILD_PACKAGE_NAME=$name
BUILD_OLDPATH=$PATH
- BUILD_OLDPWD=`pwd`
+ BUILD_OLDPWD=$(pwd)
LOGTARGET=$name
- touch flagfiles/$name.started
-
- get_expand_source_tar $1 $2 $3 $strip $name
-
- cd $name
-
+ touch "flagfiles/$name.started"
+
+ get_expand_source_tar "$1" "$2" "$3" "$strip" "$name"
+
+ cd "$name"
+
# Create a folder and add it to path, where we can put special binaries
# The path is restored in build_post
mkdir bin_special
- PATH=`pwd`/bin_special:$PATH
-
+ PATH=$(pwd)/bin_special:$PATH
+
return 0
- else
+ else
return 1
fi
}
@@ -337,9 +341,9 @@ function build_prep {
# ------------------------------------------------------------------------------
function build_post {
- if [ ! -f flagfiles/$BUILD_PACKAGE_NAME.finished ]; then
- cd $BUILD_OLDPWD
- touch flagfiles/$BUILD_PACKAGE_NAME.finished
+ if [ ! -f "flagfiles/$BUILD_PACKAGE_NAME.finished" ]; then
+ cd "$BUILD_OLDPWD"
+ touch "flagfiles/$BUILD_PACKAGE_NAME.finished"
PATH=$BUILD_OLDPATH
LOGTARGET=other
fi
@@ -362,9 +366,10 @@ function build_post {
# ------------------------------------------------------------------------------
function build_conf_make_inst {
- if build_prep $1 $2 $3 ; then
+ if build_prep "$1" "$2" "$3" ; then
$4
- logn configure ./configure --build=$BUILD --host=$HOST --target=$TARGET --prefix="$PREFIX" "${@:5}"
+ logn configure ./configure --build="$BUILD" --host="$HOST" --target="$TARGET" --prefix="$PREFIX" "${@:5}"
+ # shellcheck disable=SC2086
log1 make $MAKE_OPT
log2 make install
log2 make clean
@@ -383,6 +388,7 @@ function build_conf_make_inst {
function install_glob {
# Check if any files matching the pattern exist
if [ "$(echo $1)" != "$1" ] ; then
+ # shellcheck disable=SC2086
install -D -t $2 $1
fi
}
@@ -398,7 +404,7 @@ function install_glob {
# ------------------------------------------------------------------------------
function install_rec {
- ( cd $1 && find -type f -name "$2" -exec install -D -T $1/{} $3/{} \; )
+ ( cd "$1" && find . -type f -name "$2" -exec install -D -T "$1"/{} "$3"/{} \; )
}
# ------------------------------------------------------------------------------
@@ -411,7 +417,7 @@ function install_rec {
function list_files {
if [ ! -e "/build/filelists/$1" ] ; then
- ( cd "$PREFIXCOQ" && find -type f | sort > /build/filelists/$1 )
+ ( cd "$PREFIXCOQ" && find . -type f | sort > /build/filelists/"$1" )
fi
}
@@ -439,7 +445,7 @@ function diff_files {
# ------------------------------------------------------------------------------
function filter_files {
- egrep "$3" "/build/filelists/$2" > "/build/filelists/$1"
+ grep -E "$3" "/build/filelists/$2" > "/build/filelists/$1"
}
# ------------------------------------------------------------------------------
@@ -453,7 +459,7 @@ function files_to_nsis {
# Split the path in the file list into path and filename and create SetOutPath and File instructions
# Note: File /oname cannot be used, because it does not create the paths as SetOutPath does
# Note: I didn't check if the redundant SetOutPath instructions have a bad impact on installer size or install time
- cat "/build/filelists/$1" | tr '/' '\\' | sed -r 's/^\.(.*)\\([^\\]+)$/SetOutPath $INSTDIR\\\1\nFile ${COQ_SRC_PATH}\\\1\\\2/' > "/build/filelists/$1.nsh"
+ tr '/' '\\' < "/build/filelists/$1" | sed -r 's/^\.(.*)\\([^\\]+)$/SetOutPath $INSTDIR\\\1\nFile ${COQ_SRC_PATH}\\\1\\\2/' > "/build/filelists/$1.nsh"
}
@@ -501,7 +507,7 @@ function make_fontconfig {
make_freetype
make_expat
# CONFIGURE PARAMETERS
- # build/install fails without --disable-docs
+ # build/install fails without --disable-docs
build_conf_make_inst http://www.freedesktop.org/software/fontconfig/release fontconfig-2.11.94 tar.gz true --disable-docs
}
@@ -532,7 +538,7 @@ function make_ncurses {
#
# CONFIGURE PARAMETERS
# --enable-term-driver --enable-sp-funcs is rewuired for mingw (see README.MinGW)
- # additional changes
+ # additional changes
# ADD --with-pkg-config
# ADD --enable-pc-files
# ADD --without-manpages
@@ -604,7 +610,7 @@ function make_gdk-pixbuf {
# CONFIGURE PARAMETERS
# --with-included-loaders=yes statically links the image file format handlers
# This avoids "Cannot open pixbuf loader module file '/usr/x86_64-w64-mingw32/sys-root/mingw/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache': No such file or directory"
- build_conf_make_inst http://ftp.gnome.org/pub/GNOME/sources/gdk-pixbuf/2.32 gdk-pixbuf-2.32.1 tar.xz true --with-included-loaders=yes
+ build_conf_make_inst http://ftp.gnome.org/pub/GNOME/sources/gdk-pixbuf/2.32 gdk-pixbuf-2.32.1 tar.xz true --with-included-loaders=yes
}
##### CAIRO #####
@@ -657,8 +663,8 @@ function make_gtk3 {
build_conf_make_inst http://ftp.gnome.org/pub/gnome/sources/gtk+/3.16 gtk+-3.16.7 tar.xz true
# make all incl. tests and examples runs through fine
- # make install fails with issue with
- #
+ # make install fails with issue with
+ #
# make[5]: Entering directory '/home/soegtrop/GTK/gtk+-3.16.7/demos/gtk-demo'
# test -n "" || ../../gtk/gtk-update-icon-cache --ignore-theme-index --force "/usr/x86_64-w64-mingw32/sys-root/mingw/share/icons/hicolor"
# gtk-update-icon-cache.exe: Failed to open file /usr/x86_64-w64-mingw32/sys-root/mingw/share/icons/hicolor/.icon-theme.cache : No such file or directory
@@ -676,7 +682,8 @@ function make_libxml2 {
if build_prep https://git.gnome.org/browse/libxml2/snapshot libxml2-2.9.1 tar.xz ; then
# ./autogen.sh --build=$BUILD --host=$HOST --target=$TARGET --prefix="$PREFIX" --disable-shared --without-python
# shared library required by gtksourceview
- ./autogen.sh --build=$BUILD --host=$HOST --target=$TARGET --prefix="$PREFIX" --without-python
+ ./autogen.sh --build="$BUILD" --host="$HOST" --target="$TARGET" --prefix="$PREFIX" --without-python
+ # shellcheck disable=SC2086
log1 make $MAKE_OPT all
log2 make install
log2 make clean
@@ -708,12 +715,12 @@ function make_gtk_sourceview2 {
# Install flexdll objects
function install_flexdll {
- cp flexdll.h /usr/$TARGET_ARCH/sys-root/mingw/include
+ cp flexdll.h "/usr/$TARGET_ARCH/sys-root/mingw/include"
if [ "$TARGET_ARCH" == "i686-w64-mingw32" ]; then
- cp flexdll*_mingw.o /usr/$TARGET_ARCH/bin
+ cp flexdll*_mingw.o "/usr/$TARGET_ARCH/bin"
cp flexdll*_mingw.o "$PREFIXOCAML/bin"
elif [ "$TARGET_ARCH" == "x86_64-w64-mingw32" ]; then
- cp flexdll*_mingw64.o /usr/$TARGET_ARCH/bin
+ cp flexdll*_mingw64.o "/usr/$TARGET_ARCH/bin"
cp flexdll*_mingw64.o "$PREFIXOCAML/bin"
else
echo "Unknown target architecture"
@@ -724,8 +731,8 @@ function install_flexdll {
# Install flexlink
function install_flexlink {
- cp flexlink.exe /usr/$TARGET_ARCH/bin
-
+ cp flexlink.exe "/usr/$TARGET_ARCH/bin"
+
cp flexlink.exe "$PREFIXOCAML/bin"
}
@@ -745,8 +752,10 @@ function get_flex_dll_link_bin {
function make_flex_dll_link {
if build_prep http://alain.frisch.fr/flexdll flexdll-0.34 tar.gz ; then
if [ "$TARGET_ARCH" == "i686-w64-mingw32" ]; then
+ # shellcheck disable=SC2086
log1 make $MAKE_OPT build_mingw flexlink.exe
elif [ "$TARGET_ARCH" == "x86_64-w64-mingw32" ]; then
+ # shellcheck disable=SC2086
log1 make $MAKE_OPT build_mingw64 flexlink.exe
else
echo "Unknown target architecture"
@@ -769,11 +778,11 @@ function make_ln {
if [ ! -f flagfiles/myln.finished ] ; then
touch flagfiles/myln.started
mkdir -p myln
- cd myln
+ ( cd myln
cp $PATCHES/ln.c .
- $TARGET_ARCH-gcc -DUNICODE -D_UNICODE -DIGNORE_SYMBOLIC -mconsole -o ln.exe ln.c
+ "$TARGET_ARCH-gcc" -DUNICODE -D_UNICODE -DIGNORE_SYMBOLIC -mconsole -o ln.exe ln.c
install -D ln.exe "$PREFIXCOQ/bin/ln.exe"
- cd ..
+ )
touch flagfiles/myln.finished
fi
}
@@ -799,14 +808,14 @@ function make_ocaml {
# Prefix is fixed in make file - replace it with the real one
# TODO: this might not work if PREFIX contains spaces
sed -i "s|^PREFIX=.*|PREFIX=$PREFIXOCAML|" config/Makefile
-
+
# We don't want to mess up Coq's directory structure so put the OCaml library in a separate folder
# If we refer to the make variable ${PREFIX} below, camlp5 ends up having the wrong path:
# D:\bin\coq64_buildtest_abs_ocaml4\bin>ocamlc -where => D:/bin/coq64_buildtest_abs_ocaml4/libocaml
# D:\bin\coq64_buildtest_abs_ocaml4\bin>camlp4 -where => ${PREFIX}/libocaml\camlp4
# So we put an explicit path in there
sed -i "s|^LIBDIR=.*|LIBDIR=$PREFIXOCAML/libocaml|" config/Makefile
-
+
# Note: ocaml doesn't support -j 8, so don't pass MAKE_OPT
# I verified that 4.02.3 still doesn't support parallel build
log2 make world -f Makefile.nt
@@ -815,12 +824,12 @@ function make_ocaml {
log2 make opt.opt -f Makefile.nt
log2 make install -f Makefile.nt
# TODO log2 make clean -f Makefile.nt Temporarily disabled for ocamlbuild development
-
+
# Move license files and other into into special folder
if [ "$INSTALLMODE" == "absolute" ] || [ "$INSTALLMODE" == "relocatable" ]; then
mkdir -p "$PREFIXOCAML/license_readme/ocaml"
# 4.01 installs these files, 4.02 doesn't. So delete them and copy them from the sources.
- rm -f *.txt
+ rm -f ./*.txt
cp LICENSE "$PREFIXOCAML/license_readme/ocaml/License.txt"
cp INSTALL "$PREFIXOCAML/license_readme/ocaml/Install.txt"
cp README "$PREFIXOCAML/license_readme/ocaml/ReadMe.txt"
@@ -909,9 +918,10 @@ function make_camlp5 {
make_ocaml
make_findlib
if build_prep http://camlp5.gforge.inria.fr/distrib/src camlp5-6.14 tgz 1 ; then
- logn configure ./configure
+ logn configure ./configure
# Somehow my virus scanner has the boot.new/SAVED directory locked after the move for a second => repeat until success
sed -i 's/mv boot.new boot/until mv boot.new boot; do sleep 1; done/' Makefile
+ # shellcheck disable=SC2086
log1 make world.opt $MAKE_OPT
log2 make install
# For some reason gramlib.a is not copied, but it is required by Coq
@@ -939,15 +949,15 @@ function make_lablgtk {
make_gtk_sourceview2
if build_prep https://forge.ocamlcore.org/frs/download.php/1479 lablgtk-2.18.3 tar.gz 1 ; then
# configure should be fixed to search for $TARGET_ARCH-pkg-config.exe
- cp /bin/$TARGET_ARCH-pkg-config.exe bin_special/pkg-config.exe
- logn configure ./configure --build=$BUILD --host=$HOST --target=$TARGET --prefix="$PREFIXOCAML"
-
+ cp "/bin/$TARGET_ARCH-pkg-config.exe" bin_special/pkg-config.exe
+ logn configure ./configure --build="$BUILD" --host="$HOST" --target="$TARGET" --prefix="$PREFIXOCAML"
+
# lablgtk shows occasional errors with -j, so don't pass $MAKE_OPT
-
+
# See https://sympa.inria.fr/sympa/arc/caml-list/2015-10/msg00204.html for the make || true + strip
logn make-world-pre make world || true
- $TARGET_ARCH-strip.exe --strip-unneeded src/dlllablgtk2.dll
-
+ "$TARGET_ARCH-strip.exe" --strip-unneeded src/dlllablgtk2.dll
+
log2 make world
log2 make install
log2 make clean
@@ -978,7 +988,7 @@ function make_stdint {
function copy_coq_dll {
if [ "$INSTALLMODE" == "absolute" ] || [ "$INSTALLMODE" == "relocatable" ]; then
- cp /usr/${ARCH}-w64-mingw32/sys-root/mingw/bin/$1 "$PREFIXCOQ/bin/$1"
+ cp "/usr/${ARCH}-w64-mingw32/sys-root/mingw/bin/$1" "$PREFIXCOQ/bin/$1"
fi
}
@@ -994,7 +1004,7 @@ function copy_coq_dlls {
# Do this recursively until there are no further missing DLLs (File close + reopen)
# For running this quickly, just do "cd coq-<ver> ; call copy_coq_dlls ; cd .." at the end of this script.
# Do the same for coqc and ocamlc (usually doesn't result in additional files)
-
+
copy_coq_dll LIBATK-1.0-0.DLL
copy_coq_dll LIBCAIRO-2.DLL
copy_coq_dll LIBEXPAT-1.DLL
@@ -1018,7 +1028,7 @@ function copy_coq_dlls {
copy_coq_dll LIBXML2-2.DLL
copy_coq_dll ZLIB1.DLL
- # Depends on if GTK is built from sources
+ # Depends on if GTK is built from sources
if [ "$GTK_FROM_SOURCES" == "Y" ]; then
copy_coq_dll libiconv-2.dll
else
@@ -1036,21 +1046,21 @@ function copy_coq_dlls {
i686) copy_coq_dll LIBGCC_S_SJLJ-1.DLL ;;
*) false ;;
esac
-
+
# Win pthread version change
copy_coq_dll LIBWINPTHREAD-1.DLL
}
function copy_coq_objects {
# copy objects only from folders which exist in the target lib directory
- find . -type d | while read FOLDER ; do
+ find . -type d | while read -r FOLDER ; do
if [ -e "$PREFIXCOQ/lib/$FOLDER" ] ; then
- install_glob $FOLDER/'*.cmxa' "$PREFIXCOQ/lib/$FOLDER"
- install_glob $FOLDER/'*.cmi' "$PREFIXCOQ/lib/$FOLDER"
- install_glob $FOLDER/'*.cma' "$PREFIXCOQ/lib/$FOLDER"
- install_glob $FOLDER/'*.cmo' "$PREFIXCOQ/lib/$FOLDER"
- install_glob $FOLDER/'*.a' "$PREFIXCOQ/lib/$FOLDER"
- install_glob $FOLDER/'*.o' "$PREFIXCOQ/lib/$FOLDER"
+ install_glob "$FOLDER"/'*.cmxa' "$PREFIXCOQ/lib/$FOLDER"
+ install_glob "$FOLDER"/'*.cmi' "$PREFIXCOQ/lib/$FOLDER"
+ install_glob "$FOLDER"/'*.cma' "$PREFIXCOQ/lib/$FOLDER"
+ install_glob "$FOLDER"/'*.cmo' "$PREFIXCOQ/lib/$FOLDER"
+ install_glob "$FOLDER"/'*.a' "$PREFIXCOQ/lib/$FOLDER"
+ install_glob "$FOLDER"/'*.o' "$PREFIXCOQ/lib/$FOLDER"
fi
done
}
@@ -1066,7 +1076,7 @@ function copq_coq_gtk {
install_glob "$PREFIX/share/gtksourceview-2.0/language-specs/"'*' "$PREFIXCOQ/share/gtksourceview-2.0/language-specs"
install_glob "$PREFIX/share/gtksourceview-2.0/styles/"'*' "$PREFIXCOQ/share/gtksourceview-2.0/styles"
install_rec "$PREFIX/share/themes/" '*' "$PREFIXCOQ/share/themes"
-
+
# This below item look like a bug in make install
if [ -d "$PREFIXCOQ/share/coq/" ] ; then
COQSHARE="$PREFIXCOQ/share/coq/"
@@ -1111,11 +1121,11 @@ function make_coq {
case $COQ_VERSION in
# e.g. git-v8.6 => download from https://github.com/coq/coq/archive/v8.6.zip
# e.g. git-trunk => download from https://github.com/coq/coq/archive/trunk.zip
- git-*)
+ git-*)
COQ_BUILD_PATH=/build/coq-${COQ_VERSION}
- build_prep https://github.com/coq/coq/archive ${COQ_VERSION##git-} zip 1 coq-${COQ_VERSION}
+ build_prep https://github.com/coq/coq/archive "${COQ_VERSION##git-}" zip 1 "coq-${COQ_VERSION}"
;;
-
+
# e.g. /cygdrive/d/coqgit
/*)
# Todo: --exclude-vcs-ignores doesn't work because tools/coqdoc/coqdoc.sty is excluded => fix .gitignore
@@ -1124,11 +1134,11 @@ function make_coq {
tar -zcf $TARBALLS/coq-local.tar.gz --exclude-vcs -C "${COQ_VERSION%/*}" "${COQ_VERSION##*/}"
build_prep NEVER-DOWNLOADED coq-local tar.gz
;;
-
+
# e.g. 8.6 => https://coq.inria.fr/distrib/8.6/files/coq-8.6.tar.gz
*)
COQ_BUILD_PATH=/build/coq-$COQ_VERSION
- build_prep https://coq.inria.fr/distrib/V$COQ_VERSION/files coq-$COQ_VERSION tar.gz
+ build_prep "https://coq.inria.fr/distrib/V$COQ_VERSION/files" "coq-$COQ_VERSION" tar.gz
;;
esac
then
@@ -1142,16 +1152,17 @@ function make_coq {
fi
# The windows resource compiler binary name is hard coded
- sed -i "s/i686-w64-mingw32-windres/$TARGET_ARCH-windres/" Makefile.build
+ sed -i "s/i686-w64-mingw32-windres/$TARGET_ARCH-windres/" Makefile.build
sed -i "s/i686-w64-mingw32-windres/$TARGET_ARCH-windres/" Makefile.ide || true
# 8.4x doesn't support parallel make
if [[ $COQ_VERSION == 8.4* ]] ; then
log1 make
else
+ # shellcheck disable=SC2086
make $MAKE_OPT
fi
-
+
if [ "$INSTALLMODE" == "relocatable" ]; then
./configure -with-doc no -prefix "$PREFIXCOQ" -libdir "$PREFIXCOQ/lib" -mandir "$PREFIXCOQ/man"
fi
@@ -1161,7 +1172,7 @@ function make_coq {
if [ "$INSTALLOCAML" == "Y" ]; then
copy_coq_objects
fi
-
+
copq_coq_gtk
copy_coq_license
@@ -1169,7 +1180,7 @@ function make_coq {
# 1.) find | xargs fails on cygwin, can be fixed by sed -i 's|\| xargs rm -f|-exec rm -fv \{\} \+|' Makefile
# 2.) clean of test suites fails with "cannot run complexity tests (no bogomips found)"
# make clean
-
+
build_post
fi
}
@@ -1180,7 +1191,7 @@ function make_mingw_make {
if build_prep http://ftp.gnu.org/gnu/make make-4.2 tar.bz2 ; then
# The config.h.win32 file is fine - don't edit it
# We need to copy the mingw gcc here as "gcc" - then the batch file will use it
- cp /usr/bin/${ARCH}-w64-mingw32-gcc-6.4.0.exe ./gcc.exe
+ cp "/usr/bin/${ARCH}-w64-mingw32-gcc-6.4.0.exe" ./gcc.exe
# By some magic cygwin bash can run batch files
logn build ./build_w32.bat gcc
# Copy make to Coq folder
@@ -1193,7 +1204,8 @@ function make_mingw_make {
function make_binutils {
if build_prep http://ftp.gnu.org/gnu/binutils binutils-2.27 tar.gz ; then
- logn configure ./configure --build=$BUILD --host=$HOST --target=$TARGET --prefix="$PREFIXCOQ" --program-prefix=$TARGET-
+ logn configure ./configure --build="$BUILD" --host="$HOST" --target="$TARGET" --prefix="$PREFIXCOQ" --program-prefix="$TARGET-"
+ # shellcheck disable=SC2086
log1 make $MAKE_OPT
log2 make install
# log2 make clean
@@ -1219,12 +1231,13 @@ function make_gcc {
mkdir -p "$PREFIXCOQ/mingw/include"
# See https://gcc.gnu.org/install/configure.html
- logn configure ./configure --build=$BUILD --host=$HOST --target=$TARGET \
- --prefix="$PREFIXCOQ" --program-prefix=$TARGET- --disable-win32-registry --with-sysroot="$PREFIXCOQ" \
+ logn configure ./configure --build="$BUILD" --host="$HOST" --target="$TARGET" \
+ --prefix="$PREFIXCOQ" --program-prefix="$TARGET-" --disable-win32-registry --with-sysroot="$PREFIXCOQ" \
--enable-languages=c --disable-nls \
--disable-libsanitizer --disable-libssp --disable-libquadmath --disable-libgomp --disable-libvtv --disable-lto
# --disable-decimal-float seems to be required
# --with-sysroot="$PREFIX" results in configure error that this is not an absolute path
+ # shellcheck disable=SC2086
log1 make $MAKE_OPT
log2 make install
# log2 make clean
@@ -1252,21 +1265,22 @@ function get_cygwin_mingw_sources {
# Take the 2nd field of the last line => ${SOURCE} = x86_64/release/mingw64-x86_64-gcc/mingw64-x86_64-gcc-5.4.0-2-src.tar.xz
# Remove that path part => ${SOURCEFILE} = mingw64-x86_64-gcc-5.4.0-2-src.tar.xz
- grep "mingw" /etc/setup/installed.db | sed 's/\.tar\.bz2 [0-1]$//' | sed 's/ /\//' | while read ARCHIVE ; do
+ grep "mingw" /etc/setup/installed.db | sed 's/\.tar\.bz2 [0-1]$//' | sed 's/ /\//' | while read -r ARCHIVE ; do
local ARCHIVEESC=${ARCHIVE//+/\\+}
- local SOURCE=`egrep -A 1 "install: ($CYGWINARCH|noarch)/release/[-+_/a-z0-9]*$ARCHIVEESC" $TARBALLS/setup.ini | tail -1 | cut -d " " -f 2`
+ local SOURCE
+ SOURCE=$(grep -E -A 1 "install: ($CYGWINARCH|noarch)/release/[-+_/a-z0-9]*$ARCHIVEESC" $TARBALLS/setup.ini | tail -1 | cut -d " " -f 2)
local SOURCEFILE=${SOURCE##*/}
# Get the source file (either from the source cache or online)
- if [ ! -f $TARBALLS/$SOURCEFILE ] ; then
+ if [ ! -f "$TARBALLS/$SOURCEFILE" ] ; then
if [ -f "$SOURCE_LOCAL_CACHE_CFMT/$SOURCEFILE" ] ; then
cp "$SOURCE_LOCAL_CACHE_CFMT/$SOURCEFILE" $TARBALLS
else
wget "$CYGWIN_REPOSITORY/$SOURCE"
- mv $SOURCEFILE $TARBALLS
+ mv "$SOURCEFILE" "$TARBALLS"
# Save the source archive in the source cache
if [ -d "$SOURCE_LOCAL_CACHE_CFMT" ] ; then
- cp $TARBALLS/$SOURCEFILE "$SOURCE_LOCAL_CACHE_CFMT"
+ cp "$TARBALLS/$SOURCEFILE" "$SOURCE_LOCAL_CACHE_CFMT"
fi
fi
fi
@@ -1281,26 +1295,25 @@ function get_cygwin_mingw_sources {
function make_coq_installer {
make_coq
- make_mingw_make
get_cygwin_mingw_sources
# Prepare the file lists for the installer. We created to file list dumps of the target folder during the build:
# ocaml: ocaml + menhir + camlp5 + findlib
# ocaml_coq: as above + coq
# ocaml_coq_addons: as above + lib/user-contrib/*
-
+
# Create coq file list as ocaml_coq / ocaml
diff_files coq ocaml_coq ocaml
-
+
# Filter out object files
- filter_files coq_objects coq '\.(cmxa|cmi|cma|cmo|a|o)$'
-
+ filter_files coq_objects coq '\.(cmxa|cmi|cma|cmo|a|o)$'
+
# Filter out plugin object files
filter_files coq_objects_plugins coq_objects '/lib/plugins/.*\.(cmxa|cmi|cma|cmo|a|o)$'
-
+
# Coq objects objects required for plugin development = coq objects except those for pre installed plugins
diff_files coq_plugindev coq_objects coq_objects_plugins
-
+
# Addons (TODO: including objects that could go to the plugindev thing, but
# then one would have to make that package depend on this one, so not
# implemented yet)
@@ -1308,45 +1321,46 @@ function make_coq_installer {
# Coq files, except objects needed only for plugin development
diff_files coq_base coq coq_plugindev
-
+
# Convert section files to NSIS format
files_to_nsis coq_base
files_to_nsis coq_addons
files_to_nsis coq_plugindev
files_to_nsis ocaml
-
+
# Get and extract NSIS Binaries
if build_prep http://downloads.sourceforge.net/project/nsis/NSIS%202/2.51 nsis-2.51 zip ; then
- NSIS=`pwd`/makensis.exe
+ NSIS=$(pwd)/makensis.exe
chmod u+x "$NSIS"
# Change to Coq folder
- cd $COQ_BUILD_PATH
+ cd "$COQ_BUILD_PATH"
# Copy patched nsi file
cp ../patches/coq_new.nsi dev/nsis
cp ../patches/StrRep.nsh dev/nsis
cp ../patches/ReplaceInFile.nsh dev/nsis
- VERSION=`grep '^VERSION=' config/Makefile | cut -d = -f 2 | tr -d '\r'`
+ VERSION=$(grep '^VERSION=' config/Makefile | cut -d = -f 2 | tr -d '\r')
cd dev/nsis
- logn nsis-installer "$NSIS" -DVERSION=$VERSION -DARCH=$ARCH -DCOQ_SRC_PATH="$PREFIXCOQ" -DCOQ_ICON=..\\..\\ide\\coq.ico -DCOQ_ADDONS="$COQ_ADDONS" coq_new.nsi
-
+ logn nsis-installer "$NSIS" -DVERSION="$VERSION" -DARCH="$ARCH" -DCOQ_SRC_PATH="$PREFIXCOQ" -DCOQ_ICON=..\\..\\ide\\coq.ico -DCOQ_ADDONS="$COQ_ADDONS" coq_new.nsi
+
build_post
fi
}
###################### ADDONS #####################
+
function make_addon_bignums {
- if build_prep https://github.com/coq/bignums/archive/ V8.8+beta1 zip 1; then
+ if build_prep https://github.com/coq/bignums/archive/ V8.8+beta1 zip 1 bignums-8.8+beta1; then
# To make command lines shorter :-(
echo 'COQ_SRC_SUBDIRS:=$(filter-out plugins/%,$(COQ_SRC_SUBDIRS)) plugins/syntax' >> Makefile.coq.local
- logn make make all
- logn make-install make install
+ log1 make all
+ log2 make install
build_post
fi
}
function make_addons {
for addon in $COQ_ADDONS; do
- make_addon_$addon
+ "make_addon_$addon"
done
}
@@ -1374,4 +1388,3 @@ list_files ocaml_coq_addons
if [ "$MAKEINSTALLER" == "Y" ] ; then
make_coq_installer
fi
-
diff --git a/dev/ci/appveyor.sh b/dev/ci/appveyor.sh
index 524a55a42..93e7bd99a 100644
--- a/dev/ci/appveyor.sh
+++ b/dev/ci/appveyor.sh
@@ -4,6 +4,6 @@ wget https://github.com/fdopen/opam-repository-mingw/releases/download/0.0.0.1/o
tar -xf opam64.tar.xz
bash opam64/install.sh
opam init -a mingw https://github.com/fdopen/opam-repository-mingw.git --comp 4.02.3+mingw64c --switch 4.02.3+mingw64c
-eval $(opam config env)
+eval "$(opam config env)"
opam install -y ocamlfind camlp5
-cd $APPVEYOR_BUILD_FOLDER && ./configure -local && make && make byte && make -C test-suite all INTERACTIVE= && make validate
+cd "$APPVEYOR_BUILD_FOLDER" && ./configure -local && make && make byte && make -C test-suite all INTERACTIVE= && make validate
diff --git a/dev/ci/ci-bignums.sh b/dev/ci/ci-bignums.sh
index c90e516ae..008291967 100755
--- a/dev/ci/ci-bignums.sh
+++ b/dev/ci/ci-bignums.sh
@@ -6,11 +6,11 @@ ci_dir="$(dirname "$0")"
# Let's avoid to source ci-common twice in this case
if [ -z "${CI_BUILD_DIR}" ];
then
- source ${ci_dir}/ci-common.sh
+ . "${ci_dir}/ci-common.sh"
fi
-bignums_CI_DIR=${CI_BUILD_DIR}/Bignums
+bignums_CI_DIR="${CI_BUILD_DIR}/Bignums"
-git_checkout ${bignums_CI_BRANCH} ${bignums_CI_GITURL} ${bignums_CI_DIR}
+git_checkout "${bignums_CI_BRANCH}" "${bignums_CI_GITURL}" "${bignums_CI_DIR}"
-( cd ${bignums_CI_DIR} && make && make install)
+( cd "${bignums_CI_DIR}" && make && make install)
diff --git a/dev/ci/ci-color.sh b/dev/ci/ci-color.sh
index 558e8cbb8..8ce5f2418 100755
--- a/dev/ci/ci-color.sh
+++ b/dev/ci/ci-color.sh
@@ -1,10 +1,10 @@
#!/usr/bin/env bash
ci_dir="$(dirname "$0")"
-source ${ci_dir}/ci-common.sh
+. "${ci_dir}/ci-common.sh"
CoLoR_CI_DIR=${CI_BUILD_DIR}/color
# Compile CoLoR
-git_checkout ${CoLoR_CI_BRANCH} ${CoLoR_CI_GITURL} ${CoLoR_CI_DIR}
-( cd ${CoLoR_CI_DIR} && make )
+git_checkout "${CoLoR_CI_BRANCH}" "${CoLoR_CI_GITURL}" "${CoLoR_CI_DIR}"
+( cd "${CoLoR_CI_DIR}" && make )
diff --git a/dev/ci/ci-common.sh b/dev/ci/ci-common.sh
index d7a356930..189734a0b 100644
--- a/dev/ci/ci-common.sh
+++ b/dev/ci/ci-common.sh
@@ -20,7 +20,8 @@ else
export CI_PULL_REQUEST="$CIRCLE_PR_NUMBER"
export CI_BRANCH="$CIRCLE_BRANCH"
else # assume local
- export CI_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
+ CI_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
+ export CI_BRANCH
fi
export COQBIN="$PWD/bin"
fi
@@ -35,10 +36,10 @@ ls "$COQBIN"
CI_BUILD_DIR="$PWD/_build_ci"
# shellcheck source=ci-basic-overlay.sh
-source "${ci_dir}/ci-basic-overlay.sh"
+. "${ci_dir}/ci-basic-overlay.sh"
for overlay in "${ci_dir}"/user-overlays/*.sh; do
# shellcheck source=/dev/null
- source "${overlay}"
+ . "${overlay}"
done
mathcomp_CI_DIR="${CI_BUILD_DIR}/math-comp"
@@ -68,7 +69,7 @@ git_checkout()
checkout_mathcomp()
{
- git_checkout ${mathcomp_CI_BRANCH} ${mathcomp_CI_GITURL} ${1}
+ git_checkout "${mathcomp_CI_BRANCH}" "${mathcomp_CI_GITURL}" "${1}"
}
make()
diff --git a/dev/ci/ci-compcert.sh b/dev/ci/ci-compcert.sh
index 6a0ce2aef..fbdeff20c 100755
--- a/dev/ci/ci-compcert.sh
+++ b/dev/ci/ci-compcert.sh
@@ -1,11 +1,11 @@
#!/usr/bin/env bash
ci_dir="$(dirname "$0")"
-source ${ci_dir}/ci-common.sh
+. "${ci_dir}/ci-common.sh"
-CompCert_CI_DIR=${CI_BUILD_DIR}/CompCert
+CompCert_CI_DIR="${CI_BUILD_DIR}/CompCert"
opam install -j "$NJOBS" -y menhir
-git_checkout ${CompCert_CI_BRANCH} ${CompCert_CI_GITURL} ${CompCert_CI_DIR}
+git_checkout "${CompCert_CI_BRANCH}" "${CompCert_CI_GITURL}" "${CompCert_CI_DIR}"
-( cd ${CompCert_CI_DIR} && ./configure -ignore-coq-version x86_32-linux && make && make check-proof )
+( cd "${CompCert_CI_DIR}" && ./configure -ignore-coq-version x86_32-linux && make && make check-proof )
diff --git a/dev/ci/ci-coq-dpdgraph.sh b/dev/ci/ci-coq-dpdgraph.sh
index 5d6bd6a36..5d57fce1c 100755
--- a/dev/ci/ci-coq-dpdgraph.sh
+++ b/dev/ci/ci-coq-dpdgraph.sh
@@ -1,10 +1,10 @@
#!/usr/bin/env bash
ci_dir="$(dirname "$0")"
-source ${ci_dir}/ci-common.sh
+. "${ci_dir}/ci-common.sh"
-coq_dpdgraph_CI_DIR=${CI_BUILD_DIR}/coq-dpdgraph
+coq_dpdgraph_CI_DIR="${CI_BUILD_DIR}/coq-dpdgraph"
-git_checkout ${coq_dpdgraph_CI_BRANCH} ${coq_dpdgraph_CI_GITURL} ${coq_dpdgraph_CI_DIR}
+git_checkout "${coq_dpdgraph_CI_BRANCH}" "${coq_dpdgraph_CI_GITURL}" "${coq_dpdgraph_CI_DIR}"
-( cd ${coq_dpdgraph_CI_DIR} && autoconf && ./configure && make && make test-suite )
+( cd "${coq_dpdgraph_CI_DIR}" && autoconf && ./configure && make && make test-suite )
diff --git a/dev/ci/ci-coquelicot.sh b/dev/ci/ci-coquelicot.sh
index 40eff03b7..d86d61ef6 100755
--- a/dev/ci/ci-coquelicot.sh
+++ b/dev/ci/ci-coquelicot.sh
@@ -1,12 +1,12 @@
#!/usr/bin/env bash
ci_dir="$(dirname "$0")"
-source ${ci_dir}/ci-common.sh
+. "${ci_dir}/ci-common.sh"
-Coquelicot_CI_DIR=${CI_BUILD_DIR}/coquelicot
+Coquelicot_CI_DIR="${CI_BUILD_DIR}/coquelicot"
install_ssreflect
-git_checkout ${Coquelicot_CI_BRANCH} ${Coquelicot_CI_GITURL} ${Coquelicot_CI_DIR}
+git_checkout "${Coquelicot_CI_BRANCH}" "${Coquelicot_CI_GITURL}" "${Coquelicot_CI_DIR}"
-( cd ${Coquelicot_CI_DIR} && ./autogen.sh && ./configure && ./remake -j${NJOBS} )
+( cd "${Coquelicot_CI_DIR}" && ./autogen.sh && ./configure && ./remake "-j${NJOBS}" )
diff --git a/dev/ci/ci-corn.sh b/dev/ci/ci-corn.sh
index 54cad5df4..9298fc70a 100755
--- a/dev/ci/ci-corn.sh
+++ b/dev/ci/ci-corn.sh
@@ -1,10 +1,10 @@
#!/usr/bin/env bash
ci_dir="$(dirname "$0")"
-source ${ci_dir}/ci-common.sh
+. "${ci_dir}/ci-common.sh"
-Corn_CI_DIR=${CI_BUILD_DIR}/corn
+Corn_CI_DIR="${CI_BUILD_DIR}/corn"
-git_checkout ${Corn_CI_BRANCH} ${Corn_CI_GITURL} ${Corn_CI_DIR}
+git_checkout "${Corn_CI_BRANCH}" "${Corn_CI_GITURL}" "${Corn_CI_DIR}"
-( cd ${Corn_CI_DIR} && make && make install )
+( cd "${Corn_CI_DIR}" && make && make install )
diff --git a/dev/ci/ci-cpdt.sh b/dev/ci/ci-cpdt.sh
index 8b725f6fe..ca759c7b3 100755
--- a/dev/ci/ci-cpdt.sh
+++ b/dev/ci/ci-cpdt.sh
@@ -1,10 +1,9 @@
#!/usr/bin/env bash
ci_dir="$(dirname "$0")"
-source ${ci_dir}/ci-common.sh
+. "${ci_dir}/ci-common.sh"
wget http://adam.chlipala.net/cpdt/cpdt.tgz
tar xvfz cpdt.tgz
( cd cpdt && make clean && make )
-
diff --git a/dev/ci/ci-elpi.sh b/dev/ci/ci-elpi.sh
index c44e0a655..9c58034be 100755
--- a/dev/ci/ci-elpi.sh
+++ b/dev/ci/ci-elpi.sh
@@ -1,10 +1,10 @@
#!/usr/bin/env bash
ci_dir="$(dirname "$0")"
-source ${ci_dir}/ci-common.sh
+. "${ci_dir}/ci-common.sh"
-Elpi_CI_DIR=${CI_BUILD_DIR}/elpi
+Elpi_CI_DIR="${CI_BUILD_DIR}/elpi"
-git_checkout ${Elpi_CI_BRANCH} ${Elpi_CI_GITURL} ${Elpi_CI_DIR}
+git_checkout "${Elpi_CI_BRANCH}" "${Elpi_CI_GITURL}" "${Elpi_CI_DIR}"
-( cd ${Elpi_CI_DIR} && make && make install )
+( cd "${Elpi_CI_DIR}" && make && make install )
diff --git a/dev/ci/ci-equations.sh b/dev/ci/ci-equations.sh
index 62854afac..98735b4ec 100755
--- a/dev/ci/ci-equations.sh
+++ b/dev/ci/ci-equations.sh
@@ -1,10 +1,10 @@
#!/usr/bin/env bash
ci_dir="$(dirname "$0")"
-source ${ci_dir}/ci-common.sh
+. "${ci_dir}/ci-common.sh"
-Equations_CI_DIR=${CI_BUILD_DIR}/Equations
+Equations_CI_DIR="${CI_BUILD_DIR}/Equations"
-git_checkout ${Equations_CI_BRANCH} ${Equations_CI_GITURL} ${Equations_CI_DIR}
+git_checkout "${Equations_CI_BRANCH}" "${Equations_CI_GITURL}" "${Equations_CI_DIR}"
-( cd ${Equations_CI_DIR} && coq_makefile -f _CoqProject -o Makefile && make && make test-suite && make examples && make install)
+( cd "${Equations_CI_DIR}" && coq_makefile -f _CoqProject -o Makefile && make && make test-suite && make examples && make install)
diff --git a/dev/ci/ci-fiat-crypto.sh b/dev/ci/ci-fiat-crypto.sh
index 5ca3ac47f..6c8dce5bd 100755
--- a/dev/ci/ci-fiat-crypto.sh
+++ b/dev/ci/ci-fiat-crypto.sh
@@ -1,11 +1,11 @@
#!/usr/bin/env bash
ci_dir="$(dirname "$0")"
-source ${ci_dir}/ci-common.sh
+. "${ci_dir}/ci-common.sh"
-fiat_crypto_CI_DIR=${CI_BUILD_DIR}/fiat-crypto
+fiat_crypto_CI_DIR="${CI_BUILD_DIR}/fiat-crypto"
-git_checkout ${fiat_crypto_CI_BRANCH} ${fiat_crypto_CI_GITURL} ${fiat_crypto_CI_DIR}
-( cd ${fiat_crypto_CI_DIR} && git submodule update --init --recursive )
+git_checkout "${fiat_crypto_CI_BRANCH}" "${fiat_crypto_CI_GITURL}" "${fiat_crypto_CI_DIR}"
+( cd "${fiat_crypto_CI_DIR}" && git submodule update --init --recursive )
-( cd ${fiat_crypto_CI_DIR} && make lite )
+( cd "${fiat_crypto_CI_DIR}" && make lite )
diff --git a/dev/ci/ci-fiat-parsers.sh b/dev/ci/ci-fiat-parsers.sh
index 292331b81..35c228405 100755
--- a/dev/ci/ci-fiat-parsers.sh
+++ b/dev/ci/ci-fiat-parsers.sh
@@ -1,10 +1,10 @@
#!/usr/bin/env bash
ci_dir="$(dirname "$0")"
-source ${ci_dir}/ci-common.sh
+. "${ci_dir}/ci-common.sh"
-fiat_parsers_CI_DIR=${CI_BUILD_DIR}/fiat
+fiat_parsers_CI_DIR="${CI_BUILD_DIR}/fiat"
-git_checkout ${fiat_parsers_CI_BRANCH} ${fiat_parsers_CI_GITURL} ${fiat_parsers_CI_DIR}
+git_checkout "${fiat_parsers_CI_BRANCH}" "${fiat_parsers_CI_GITURL}" "${fiat_parsers_CI_DIR}"
-( cd ${fiat_parsers_CI_DIR} && make parsers parsers-examples && make fiat-core )
+( cd "${fiat_parsers_CI_DIR}" && make parsers parsers-examples && make fiat-core )
diff --git a/dev/ci/ci-flocq.sh b/dev/ci/ci-flocq.sh
index ec19bd993..8599e4d50 100755
--- a/dev/ci/ci-flocq.sh
+++ b/dev/ci/ci-flocq.sh
@@ -1,10 +1,10 @@
#!/usr/bin/env bash
ci_dir="$(dirname "$0")"
-source ${ci_dir}/ci-common.sh
+. "${ci_dir}/ci-common.sh"
-Flocq_CI_DIR=${CI_BUILD_DIR}/flocq
+Flocq_CI_DIR="${CI_BUILD_DIR}/flocq"
-git_checkout ${Flocq_CI_BRANCH} ${Flocq_CI_GITURL} ${Flocq_CI_DIR}
+git_checkout "${Flocq_CI_BRANCH}" "${Flocq_CI_GITURL}" "${Flocq_CI_DIR}"
-( cd ${Flocq_CI_DIR} && ./autogen.sh && ./configure && ./remake -j${NJOBS} )
+( cd "${Flocq_CI_DIR}" && ./autogen.sh && ./configure && ./remake "-j${NJOBS}" )
diff --git a/dev/ci/ci-formal-topology.sh b/dev/ci/ci-formal-topology.sh
index 53eb55fc4..118d15150 100755
--- a/dev/ci/ci-formal-topology.sh
+++ b/dev/ci/ci-formal-topology.sh
@@ -1,10 +1,10 @@
#!/usr/bin/env bash
ci_dir="$(dirname "$0")"
-source ${ci_dir}/ci-common.sh
+. "${ci_dir}/ci-common.sh"
-formal_topology_CI_DIR=${CI_BUILD_DIR}/formal-topology
+formal_topology_CI_DIR="${CI_BUILD_DIR}/formal-topology"
-git_checkout ${formal_topology_CI_BRANCH} ${formal_topology_CI_GITURL} ${formal_topology_CI_DIR}
+git_checkout "${formal_topology_CI_BRANCH}" "${formal_topology_CI_GITURL}" "${formal_topology_CI_DIR}"
-( cd ${formal_topology_CI_DIR} && make )
+( cd "${formal_topology_CI_DIR}" && make )
diff --git a/dev/ci/ci-geocoq.sh b/dev/ci/ci-geocoq.sh
index 8e6448e76..bd1d88993 100755
--- a/dev/ci/ci-geocoq.sh
+++ b/dev/ci/ci-geocoq.sh
@@ -1,12 +1,12 @@
#!/usr/bin/env bash
ci_dir="$(dirname "$0")"
-source ${ci_dir}/ci-common.sh
+. "${ci_dir}/ci-common.sh"
-GeoCoq_CI_DIR=${CI_BUILD_DIR}/GeoCoq
+GeoCoq_CI_DIR="${CI_BUILD_DIR}/GeoCoq"
-git_checkout ${GeoCoq_CI_BRANCH} ${GeoCoq_CI_GITURL} ${GeoCoq_CI_DIR}
+git_checkout "${GeoCoq_CI_BRANCH}" "${GeoCoq_CI_GITURL}" "${GeoCoq_CI_DIR}"
-( cd ${GeoCoq_CI_DIR} && \
+( cd "${GeoCoq_CI_DIR}" && \
./configure-ci.sh && \
make )
diff --git a/dev/ci/ci-hott.sh b/dev/ci/ci-hott.sh
index 693135a4c..6ded97984 100755
--- a/dev/ci/ci-hott.sh
+++ b/dev/ci/ci-hott.sh
@@ -1,10 +1,10 @@
#!/usr/bin/env bash
ci_dir="$(dirname "$0")"
-source ${ci_dir}/ci-common.sh
+. "${ci_dir}/ci-common.sh"
-HoTT_CI_DIR=${CI_BUILD_DIR}/HoTT
+HoTT_CI_DIR="${CI_BUILD_DIR}"/HoTT
-git_checkout ${HoTT_CI_BRANCH} ${HoTT_CI_GITURL} ${HoTT_CI_DIR}
+git_checkout "${HoTT_CI_BRANCH}" "${HoTT_CI_GITURL}" "${HoTT_CI_DIR}"
-( cd ${HoTT_CI_DIR} && ./autogen.sh && ./configure && make )
+( cd "${HoTT_CI_DIR}" && ./autogen.sh && ./configure && make )
diff --git a/dev/ci/ci-iris-lambda-rust.sh b/dev/ci/ci-iris-lambda-rust.sh
index 267e13359..b019fa059 100755
--- a/dev/ci/ci-iris-lambda-rust.sh
+++ b/dev/ci/ci-iris-lambda-rust.sh
@@ -1,11 +1,11 @@
#!/usr/bin/env bash
ci_dir="$(dirname "$0")"
-source ${ci_dir}/ci-common.sh
+. "${ci_dir}/ci-common.sh"
-stdpp_CI_DIR=${CI_BUILD_DIR}/coq-stdpp
-Iris_CI_DIR=${CI_BUILD_DIR}/iris-coq
-lambdaRust_CI_DIR=${CI_BUILD_DIR}/lambdaRust
+stdpp_CI_DIR="${CI_BUILD_DIR}/coq-stdpp"
+Iris_CI_DIR="${CI_BUILD_DIR}/iris-coq"
+lambdaRust_CI_DIR="${CI_BUILD_DIR}/lambdaRust"
install_ssreflect
@@ -13,29 +13,29 @@ install_ssreflect
opam repo add iris-dev https://gitlab.mpi-sws.org/FP/opam-dev.git -p 0 || opam update iris-dev
# Setup lambdaRust first
-git_checkout ${lambdaRust_CI_BRANCH} ${lambdaRust_CI_GITURL} ${lambdaRust_CI_DIR}
+git_checkout "${lambdaRust_CI_BRANCH}" "${lambdaRust_CI_GITURL}" "${lambdaRust_CI_DIR}"
# Extract required version of Iris
-Iris_VERSION=$(cat ${lambdaRust_CI_DIR}/opam | fgrep coq-iris | egrep 'dev\.([0-9.-]+)' -o)
-Iris_URL=$(opam show coq-iris.$Iris_VERSION -f upstream-url)
-read -a Iris_URL_PARTS <<< $(echo $Iris_URL | tr '#' ' ')
+Iris_VERSION=$(grep -F coq-iris < "${lambdaRust_CI_DIR}/opam" | grep -E 'dev\.([0-9.-]+)' -o)
+Iris_URL=$(opam show "coq-iris.$Iris_VERSION" -f upstream-url)
+read -r -a Iris_URL_PARTS <<< "$(echo "$Iris_URL" | tr '#' ' ')"
# Setup Iris
-git_checkout ${Iris_CI_BRANCH} ${Iris_URL_PARTS[0]} ${Iris_CI_DIR} ${Iris_URL_PARTS[1]}
+git_checkout "${Iris_CI_BRANCH}" "${Iris_URL_PARTS[0]}" "${Iris_CI_DIR}" "${Iris_URL_PARTS[1]}"
# Extract required version of std++
-stdpp_VERSION=$(cat ${Iris_CI_DIR}/opam | fgrep coq-stdpp | egrep 'dev\.([0-9.-]+)' -o)
-stdpp_URL=$(opam show coq-stdpp.$stdpp_VERSION -f upstream-url)
-read -a stdpp_URL_PARTS <<< $(echo $stdpp_URL | tr '#' ' ')
+stdpp_VERSION=$(grep -F coq-stdpp < "${Iris_CI_DIR}/opam" | grep -E 'dev\.([0-9.-]+)' -o)
+stdpp_URL=$(opam show "coq-stdpp.$stdpp_VERSION" -f upstream-url)
+read -r -a stdpp_URL_PARTS <<< "$(echo "$stdpp_URL" | tr '#' ' ')"
# Setup std++
-git_checkout ${stdpp_CI_BRANCH} ${stdpp_URL_PARTS[0]} ${stdpp_CI_DIR} ${stdpp_URL_PARTS[1]}
+git_checkout "${stdpp_CI_BRANCH}" "${stdpp_URL_PARTS[0]}" "${stdpp_CI_DIR}" "${stdpp_URL_PARTS[1]}"
# Build std++
-( cd ${stdpp_CI_DIR} && make && make install )
+( cd "${stdpp_CI_DIR}" && make && make install )
# Build and validate (except on Travis, i.e., skip if TRAVIS is non-empty) Iris
-( cd ${Iris_CI_DIR} && make && (test -n "${TRAVIS}" || make validate) && make install )
+( cd "${Iris_CI_DIR}" && make && (test -n "${TRAVIS}" || make validate) && make install )
# Build lambdaRust
-( cd ${lambdaRust_CI_DIR} && make && make install )
+( cd "${lambdaRust_CI_DIR}" && make && make install )
diff --git a/dev/ci/ci-ltac2.sh b/dev/ci/ci-ltac2.sh
index 820ff89ee..5981aaaae 100755
--- a/dev/ci/ci-ltac2.sh
+++ b/dev/ci/ci-ltac2.sh
@@ -1,10 +1,10 @@
#!/usr/bin/env bash
ci_dir="$(dirname "$0")"
-source ${ci_dir}/ci-common.sh
+. "${ci_dir}/ci-common.sh"
-ltac2_CI_DIR=${CI_BUILD_DIR}/ltac2
+ltac2_CI_DIR="${CI_BUILD_DIR}/ltac2"
-git_checkout ${ltac2_CI_BRANCH} ${ltac2_CI_GITURL} ${ltac2_CI_DIR}
+git_checkout "${ltac2_CI_BRANCH}" "${ltac2_CI_GITURL}" "${ltac2_CI_DIR}"
-( cd ${ltac2_CI_DIR} && make && make tests && make install )
+( cd "${ltac2_CI_DIR}" && make && make tests && make install )
diff --git a/dev/ci/ci-math-classes.sh b/dev/ci/ci-math-classes.sh
index db4a31e54..4fc06e895 100755
--- a/dev/ci/ci-math-classes.sh
+++ b/dev/ci/ci-math-classes.sh
@@ -1,10 +1,10 @@
#!/usr/bin/env bash
ci_dir="$(dirname "$0")"
-source ${ci_dir}/ci-common.sh
+. "${ci_dir}/ci-common.sh"
-math_classes_CI_DIR=${CI_BUILD_DIR}/math-classes
+math_classes_CI_DIR="${CI_BUILD_DIR}/math-classes"
-git_checkout ${math_classes_CI_BRANCH} ${math_classes_CI_GITURL} ${math_classes_CI_DIR}
+git_checkout "${math_classes_CI_BRANCH}" "${math_classes_CI_GITURL}" "${math_classes_CI_DIR}"
-( cd ${math_classes_CI_DIR} && make && make install )
+( cd "${math_classes_CI_DIR}" && make && make install )
diff --git a/dev/ci/ci-math-comp.sh b/dev/ci/ci-math-comp.sh
index 701403f2c..8c6b910bb 100755
--- a/dev/ci/ci-math-comp.sh
+++ b/dev/ci/ci-math-comp.sh
@@ -2,14 +2,14 @@
# $0 is not the safest way, but...
ci_dir="$(dirname "$0")"
-source ${ci_dir}/ci-common.sh
+. "${ci_dir}/ci-common.sh"
-mathcomp_CI_DIR=${CI_BUILD_DIR}/math-comp
+mathcomp_CI_DIR="${CI_BUILD_DIR}/math-comp"
-checkout_mathcomp ${mathcomp_CI_DIR}
+checkout_mathcomp "${mathcomp_CI_DIR}"
# odd_order takes too much time for travis.
-( cd ${mathcomp_CI_DIR}/mathcomp && \
+( cd "${mathcomp_CI_DIR}/mathcomp" && \
sed -i.bak '/PFsection/d' Make && \
sed -i.bak '/stripped_odd_order_theorem/d' Make && \
make Makefile.coq && make -f Makefile.coq all )
diff --git a/dev/ci/ci-metacoq.sh b/dev/ci/ci-metacoq.sh
index c813b1fe9..a66dc1e76 100755
--- a/dev/ci/ci-metacoq.sh
+++ b/dev/ci/ci-metacoq.sh
@@ -1,19 +1,19 @@
#!/usr/bin/env bash
ci_dir="$(dirname "$0")"
-source ${ci_dir}/ci-common.sh
+. "${ci_dir}/ci-common.sh"
unicoq_CI_DIR=${CI_BUILD_DIR}/unicoq
metacoq_CI_DIR=${CI_BUILD_DIR}/MetaCoq
# Setup UniCoq
-git_checkout ${unicoq_CI_BRANCH} ${unicoq_CI_GITURL} ${unicoq_CI_DIR}
+git_checkout "${unicoq_CI_BRANCH}" "${unicoq_CI_GITURL}" "${unicoq_CI_DIR}"
-( cd ${unicoq_CI_DIR} && coq_makefile -f Make -o Makefile && make && make install )
+( cd "${unicoq_CI_DIR}" && coq_makefile -f Make -o Makefile && make && make install )
# Setup MetaCoq
-git_checkout ${metacoq_CI_BRANCH} ${metacoq_CI_GITURL} ${metacoq_CI_DIR}
+git_checkout "${metacoq_CI_BRANCH}" "${metacoq_CI_GITURL}" "${metacoq_CI_DIR}"
-( cd ${metacoq_CI_DIR} && coq_makefile -f _CoqProject -o Makefile && make )
+( cd "${metacoq_CI_DIR}" && coq_makefile -f _CoqProject -o Makefile && make )
diff --git a/dev/ci/ci-sf.sh b/dev/ci/ci-sf.sh
index 4e8c7e145..58bbb7229 100755
--- a/dev/ci/ci-sf.sh
+++ b/dev/ci/ci-sf.sh
@@ -1,35 +1,16 @@
#!/usr/bin/env bash
ci_dir="$(dirname "$0")"
-source ${ci_dir}/ci-common.sh
+. "${ci_dir}/ci-common.sh"
-mkdir -p ${CI_BUILD_DIR} && cd ${CI_BUILD_DIR}
-wget -qO- ${sf_lf_CI_TARURL} | tar xvz
-wget -qO- ${sf_plf_CI_TARURL} | tar xvz
-wget -qO- ${sf_vfa_CI_TARURL} | tar xvz
+mkdir -p "${CI_BUILD_DIR}" && cd "${CI_BUILD_DIR}" || exit 1
+wget -qO- "${sf_lf_CI_TARURL}" | tar xvz
+wget -qO- "${sf_plf_CI_TARURL}" | tar xvz
+wget -qO- "${sf_vfa_CI_TARURL}" | tar xvz
sed -i.bak '1i From Coq Require Extraction.' lf/Extraction.v
sed -i.bak '1i From Coq Require Extraction.' vfa/Extract.v
-# Delete useless calls to try omega; unfold
-patch vfa/SearchTree.v <<EOF
-*** SearchTree.v.bak 2017-09-06 19:12:59.000000000 +0200
---- SearchTree.v 2017-11-21 16:34:41.000000000 +0100
-***************
-*** 674,683 ****
- forall i j : key, ~ (i > j) -> ~ (i < j) -> i=j.
- Proof.
- intros.
-- try omega. (* Oops! [omega] cannot solve this one.
-- The problem is that [i] and [j] have type [key] instead of type [nat].
-- The solution is easy enough: *)
-- unfold key in *.
- omega.
-
- (** So, if you get stuck on an [omega] that ought to work,
---- 674,679 ----
-EOF
-
( cd lf && make clean && make )
( cd plf && sed -i.bak 's/(K,N)/((K,N))/' LibTactics.v && make clean && make )
diff --git a/dev/ci/ci-template.sh b/dev/ci/ci-template.sh
index 25da01a82..e77a55304 100755
--- a/dev/ci/ci-template.sh
+++ b/dev/ci/ci-template.sh
@@ -1,12 +1,12 @@
#!/usr/bin/env bash
ci_dir="$(dirname "$0")"
-source ${ci_dir}/ci-common.sh
+. "${ci_dir}/ci-common.sh"
Template_CI_BRANCH=master
Template_CI_GITURL=https://github.com/Template/Template
-Template_CI_DIR=${CI_BUILD_DIR}/Template
+Template_CI_DIR="${CI_BUILD_DIR}/Template"
-git_checkout ${Template_CI_BRANCH} ${Template_CI_GITURL} ${Template_CI_DIR}
+git_checkout "${Template_CI_BRANCH}" "${Template_CI_GITURL}" "${Template_CI_DIR}"
-( cd ${Template_CI_DIR} && make )
+( cd "${Template_CI_DIR}" && make )
diff --git a/dev/ci/ci-tlc.sh b/dev/ci/ci-tlc.sh
index 8ecd8c441..31387c8dd 100755
--- a/dev/ci/ci-tlc.sh
+++ b/dev/ci/ci-tlc.sh
@@ -1,10 +1,10 @@
#!/usr/bin/env bash
ci_dir="$(dirname "$0")"
-source ${ci_dir}/ci-common.sh
+. "${ci_dir}/ci-common.sh"
-tlc_CI_DIR=${CI_BUILD_DIR}/tlc
+tlc_CI_DIR="${CI_BUILD_DIR}/tlc"
-git_checkout ${tlc_CI_BRANCH} ${tlc_CI_GITURL} ${tlc_CI_DIR}
+git_checkout "${tlc_CI_BRANCH}" "${tlc_CI_GITURL}" "${tlc_CI_DIR}"
-( cd ${tlc_CI_DIR} && make )
+( cd "${tlc_CI_DIR}" && make )
diff --git a/dev/ci/ci-unimath.sh b/dev/ci/ci-unimath.sh
index 66b56add7..62a949f59 100755
--- a/dev/ci/ci-unimath.sh
+++ b/dev/ci/ci-unimath.sh
@@ -1,14 +1,13 @@
#!/usr/bin/env bash
ci_dir="$(dirname "$0")"
-source ${ci_dir}/ci-common.sh
+. "${ci_dir}/ci-common.sh"
-UniMath_CI_DIR=${CI_BUILD_DIR}/UniMath
+UniMath_CI_DIR="${CI_BUILD_DIR}/UniMath"
-git_checkout ${UniMath_CI_BRANCH} ${UniMath_CI_GITURL} ${UniMath_CI_DIR}
+git_checkout "${UniMath_CI_BRANCH}" "${UniMath_CI_GITURL}" "${UniMath_CI_DIR}"
-( cd ${UniMath_CI_DIR} && \
+( cd "${UniMath_CI_DIR}" && \
sed -i.bak '/Folds/d' Makefile && \
sed -i.bak '/HomologicalAlgebra/d' Makefile && \
make BUILD_COQ=no )
-
diff --git a/dev/ci/ci-vst.sh b/dev/ci/ci-vst.sh
index 5760fbafb..3c0044bfe 100755
--- a/dev/ci/ci-vst.sh
+++ b/dev/ci/ci-vst.sh
@@ -1,13 +1,13 @@
#!/usr/bin/env bash
ci_dir="$(dirname "$0")"
-source ${ci_dir}/ci-common.sh
+. "${ci_dir}/ci-common.sh"
-VST_CI_DIR=${CI_BUILD_DIR}/VST
+VST_CI_DIR="${CI_BUILD_DIR}/VST"
# opam install -j ${NJOBS} -y menhir
-git_checkout ${VST_CI_BRANCH} ${VST_CI_GITURL} ${VST_CI_DIR}
+git_checkout "${VST_CI_BRANCH}" "${VST_CI_GITURL}" "${VST_CI_DIR}"
# Targets are: msl veric floyd progs , we remove progs to save time
# Patch to avoid the upper version limit
-( cd ${VST_CI_DIR} && make IGNORECOQVERSION=true .loadpath version.vo msl veric floyd )
+( cd "${VST_CI_DIR}" && make IGNORECOQVERSION=true .loadpath version.vo msl veric floyd )
diff --git a/dev/ci/user-overlays/00669-maximedenes-ssr-merge.sh b/dev/ci/user-overlays/00669-maximedenes-ssr-merge.sh
index 7716bcb59..e9ba11414 100644
--- a/dev/ci/user-overlays/00669-maximedenes-ssr-merge.sh
+++ b/dev/ci/user-overlays/00669-maximedenes-ssr-merge.sh
@@ -1,3 +1,5 @@
+#!/bin/sh
+
if [ "$CI_PULL_REQUEST" = "669" ] || [ "$CI_BRANCH" = "ssr-merge" ]; then
mathcomp_CI_BRANCH=ssr-merge
mathcomp_CI_GITURL=https://github.com/maximedenes/math-comp.git
diff --git a/dev/ci/user-overlays/06405-maximedenes-rm-local-polymorphic-flag.sh b/dev/ci/user-overlays/06405-maximedenes-rm-local-polymorphic-flag.sh
deleted file mode 100644
index c2e367038..000000000
--- a/dev/ci/user-overlays/06405-maximedenes-rm-local-polymorphic-flag.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "6405" ] || [ "$CI_BRANCH" = "rm-local-polymorphic-flag" ]; then
- Equations_CI_BRANCH=rm-local-polymorphic-flag
- Equations_CI_GITURL=https://github.com/maximedenes/Coq-Equations
-fi
diff --git a/dev/ci/user-overlays/06482-ppedrot-check-poly-effects.sh b/dev/ci/user-overlays/06482-ppedrot-check-poly-effects.sh
deleted file mode 100644
index 78789a6fc..000000000
--- a/dev/ci/user-overlays/06482-ppedrot-check-poly-effects.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-if [ "$TRAVIS_PULL_REQUEST" = "6483" ] || [ "$TRAVIS_BRANCH" = "check-poly-effects" ]; then
- HoTT_CI_BRANCH=check-poly-effects
- HoTT_CI_GITURL=https://github.com/ppedrot/HoTT.git
-fi
diff --git a/dev/ci/user-overlays/06493-gares-API-remove-big-file.sh b/dev/ci/user-overlays/06493-gares-API-remove-big-file.sh
deleted file mode 100644
index 9677b3525..000000000
--- a/dev/ci/user-overlays/06493-gares-API-remove-big-file.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "6493" ] || [ "$CI_BRANCH" = "API/remove-big-file" ]; then
- Equations_CI_BRANCH=API-removal
- Equations_CI_GITURL=https://github.com/gares/Coq-Equations.git
- coq_dpdgraph_CI_BRANCH=API-removal
- coq_dpdgraph_CI_GITURL=https://github.com/gares/coq-dpdgraph.git
- ltac2_CI_BRANCH=API-removal
- ltac2_CI_GITURL=https://github.com/gares/ltac2.git
-fi
diff --git a/dev/ci/user-overlays/06511-ejgallego-econstr+more_fix.sh b/dev/ci/user-overlays/06511-ejgallego-econstr+more_fix.sh
deleted file mode 100644
index 4b681909d..000000000
--- a/dev/ci/user-overlays/06511-ejgallego-econstr+more_fix.sh
+++ /dev/null
@@ -1,7 +0,0 @@
- if [ "$CI_PULL_REQUEST" = "6511" ] || [ "$CI_BRANCH" = "econstr+more_fix" ]; then
- ltac2_CI_BRANCH=econstr+more_fix
- ltac2_CI_GITURL=https://github.com/ejgallego/ltac2
-
- Equations_CI_BRANCH=econstr+more_fix
- Equations_CI_GITURL=https://github.com/ejgallego/Coq-Equations
-fi
diff --git a/dev/ci/user-overlays/06535-fix-push-rel-to-named.sh b/dev/ci/user-overlays/06535-fix-push-rel-to-named.sh
deleted file mode 100644
index 8a50fb111..000000000
--- a/dev/ci/user-overlays/06535-fix-push-rel-to-named.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "6535" ] || [ "$CI_BRANCH" = "fix-push-rel-to-named" ]; then
- Equations_CI_BRANCH=fix-6535
- Equations_CI_GITURL=https://github.com/ppedrot/Coq-Equations
-fi
diff --git a/dev/ci/user-overlays/06676-gares-proofview-goals-come-with-a-state.sh b/dev/ci/user-overlays/06676-gares-proofview-goals-come-with-a-state.sh
deleted file mode 100644
index 2451657d4..000000000
--- a/dev/ci/user-overlays/06676-gares-proofview-goals-come-with-a-state.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "6676" ] || [ "$CI_BRANCH" = "proofview/goal-w-state" ]; then
- ltac2_CI_BRANCH=fix-for/6676
- ltac2_CI_GITURL=https://github.com/gares/ltac2.git
- Equations_CI_BRANCH=fix-for/6676
- Equations_CI_GITURL=https://github.com/gares/Coq-Equations.git
-fi
diff --git a/dev/ci/user-overlays/06686-ccnv-no-proj.sh b/dev/ci/user-overlays/06686-ccnv-no-proj.sh
deleted file mode 100644
index 3a3ab44e0..000000000
--- a/dev/ci/user-overlays/06686-ccnv-no-proj.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "6686" ] || [ "$CI_BRANCH" = "ccnv-no-proj" ]; then
- Equations_CI_BRANCH=ccnv-fixes
- Equations_CI_GITURL=https://github.com/SkySkimmer/Coq-Equations
-fi
diff --git a/dev/ci/user-overlays/06745-ejgallego-located+vernac.sh b/dev/ci/user-overlays/06745-ejgallego-located+vernac.sh
deleted file mode 100644
index d1d61fec2..000000000
--- a/dev/ci/user-overlays/06745-ejgallego-located+vernac.sh
+++ /dev/null
@@ -1,13 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "6745" ] || [ "$CI_BRANCH" = "located+vernac" ]; then
- ltac2_CI_BRANCH=located+vernac
- ltac2_CI_GITURL=https://github.com/ejgallego/ltac2
-
- Equations_CI_BRANCH=located+vernac
- Equations_CI_GITURL=https://github.com/ejgallego/Coq-Equations
-
- fiat_parsers_CI_BRANCH=located+vernac
- fiat_parsers_CI_GITURL=https://github.com/ejgallego/fiat
-
- Elpi_CI_BRANCH=located+vernac
- Elpi_CI_GITURL=https://github.com/ejgallego/coq-elpi.git
-fi
diff --git a/dev/ci/user-overlays/06775-univ-cumul-weak.sh b/dev/ci/user-overlays/06775-univ-cumul-weak.sh
deleted file mode 100644
index 8afcbf78a..000000000
--- a/dev/ci/user-overlays/06775-univ-cumul-weak.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "6775" ] || [ "$CI_BRANCH" = "univ-cumul" ]; then
- Elpi_CI_BRANCH=coq-master
- Elpi_CI_GITURL=https://github.com/SkySkimmer/coq-elpi.git
-fi
diff --git a/dev/ci/user-overlays/06831-ejgallego-located+vernac_2.sh b/dev/ci/user-overlays/06831-ejgallego-located+vernac_2.sh
deleted file mode 100644
index df3e9cef2..000000000
--- a/dev/ci/user-overlays/06831-ejgallego-located+vernac_2.sh
+++ /dev/null
@@ -1,14 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "6831" ] || [ "$CI_BRANCH" = "located+vernac_2" ]; then
-
- ltac2_CI_BRANCH=located+vernac_2
- ltac2_CI_GITURL=https://github.com/ejgallego/ltac2
-
- Equations_CI_BRANCH=located+vernac_2
- Equations_CI_GITURL=https://github.com/ejgallego/Coq-Equations
-
- # fiat_parsers_CI_BRANCH=located+vernac
- # fiat_parsers_CI_GITURL=https://github.com/ejgallego/fiat
-
- Elpi_CI_BRANCH=located+vernac_2
- Elpi_CI_GITURL=https://github.com/ejgallego/coq-elpi.git
-fi
diff --git a/dev/ci/user-overlays/06837-ejgallego-located+libnames.sh b/dev/ci/user-overlays/06837-ejgallego-located+libnames.sh
deleted file mode 100644
index a785290e7..000000000
--- a/dev/ci/user-overlays/06837-ejgallego-located+libnames.sh
+++ /dev/null
@@ -1,15 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "6837" ] || [ "$CI_BRANCH" = "located+libnames" ]; then
-
- ltac2_CI_BRANCH=located+libnames
- ltac2_CI_GITURL=https://github.com/ejgallego/ltac2
-
- Equations_CI_BRANCH=located+libnames
- Equations_CI_GITURL=https://github.com/ejgallego/Coq-Equations
-
- Elpi_CI_BRANCH=located+libnames
- Elpi_CI_GITURL=https://github.com/ejgallego/coq-elpi.git
-
- coq_dpdgraph_CI_BRANCH=located+libnames
- coq_dpdgraph_CI_GITURL=https://github.com/ejgallego/coq-dpdgraph.git
-
-fi
diff --git a/dev/ci/user-overlays/06869-ejgallego-ssr+correct_packing.sh b/dev/ci/user-overlays/06869-ejgallego-ssr+correct_packing.sh
deleted file mode 100644
index 5dedca0ca..000000000
--- a/dev/ci/user-overlays/06869-ejgallego-ssr+correct_packing.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "6869" ] || [ "$CI_BRANCH" = "ssr+correct_packing" ]; then
-
- Equations_CI_BRANCH=ssr+correct_packing
- Equations_CI_GITURL=https://github.com/ejgallego/Coq-Equations
-
- ltac2_CI_BRANCH=ssr+correct_packing
- ltac2_CI_GITURL=https://github.com/ejgallego/ltac2
-
- Elpi_CI_BRANCH=ssr+correct_packing
- Elpi_CI_GITURL=https://github.com/ejgallego/coq-elpi.git
-
-fi
diff --git a/dev/ci/user-overlays/06923-ppedrot-export-options.sh b/dev/ci/user-overlays/06923-ppedrot-export-options.sh
deleted file mode 100644
index 333a9e84b..000000000
--- a/dev/ci/user-overlays/06923-ppedrot-export-options.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-if [ "$CI_PULL_REQUEST" = "6923" ] || [ "$CI_BRANCH" = "export-options" ]; then
- ltac2_CI_BRANCH=export-options
- ltac2_CI_GITURL=https://github.com/ppedrot/ltac2
-
- Equations_CI_BRANCH=export-options
- Equations_CI_GITURL=https://github.com/ppedrot/Coq-Equations
-fi
diff --git a/dev/ci/user-overlays/06960-ejgallego-ltac+tacdepr.sh b/dev/ci/user-overlays/06960-ejgallego-ltac+tacdepr.sh
new file mode 100644
index 000000000..cf2af9ae9
--- /dev/null
+++ b/dev/ci/user-overlays/06960-ejgallego-ltac+tacdepr.sh
@@ -0,0 +1,12 @@
+if [ "$CI_PULL_REQUEST" = "6960" ] || [ "$CI_BRANCH" = "ltac+tacdepr" ]; then
+
+ # Equations_CI_BRANCH=ssr+correct_packing
+ # Equations_CI_GITURL=https://github.com/ejgallego/Coq-Equations
+
+ ltac2_CI_BRANCH=ltac+tacdepr
+ ltac2_CI_GITURL=https://github.com/ejgallego/ltac2
+
+ # Elpi_CI_BRANCH=ssr+correct_packing
+ # Elpi_CI_GITURL=https://github.com/ejgallego/coq-elpi.git
+
+fi
diff --git a/dev/ci/user-overlays/README.md b/dev/ci/user-overlays/README.md
index 9f0377cee..a7474e324 100644
--- a/dev/ci/user-overlays/README.md
+++ b/dev/ci/user-overlays/README.md
@@ -7,6 +7,8 @@ The name of your overlay file should be of the form `five_digit_PR_number-GitHub
Example: `00669-maximedenes-ssr-merge.sh` containing
```
+#!/bin/sh
+
if [ "$CI_PULL_REQUEST" = "669" ] || [ "$CI_BRANCH" = "ssr-merge" ]; then
mathcomp_CI_BRANCH=ssr-merge
mathcomp_CI_GITURL=https://github.com/maximedenes/math-comp.git
diff --git a/dev/doc/MERGING.md b/dev/doc/MERGING.md
index 71fc39608..3a2df6a81 100644
--- a/dev/doc/MERGING.md
+++ b/dev/doc/MERGING.md
@@ -1,6 +1,7 @@
# Merging changes in Coq
-This document describes how patches (submitted as Pull Requests) should be
+This document describes how patches (submitted as pull requests
+on the `master` branch) should be
merged into the main repository (https://github.com/coq/coq).
## Code owners
@@ -65,14 +66,57 @@ In some rare cases (e.g. the conflicts are in the CHANGES file), it is ok to fix
the conflicts in the merge commit (following the same steps as below), and push
to `master` directly. Don't use the GitHub interface to fix these conflicts.
-The command to be used is:
+To merge the PR proceed in the following way
```
+$ git checkout master
+$ git pull
$ dev/tools/merge-pr XXXX
+$ git push upstream
```
-where `XXXX` is the number of the PR to be merged. This operation should be followed by a push.
+where `XXXX` is the number of the PR to be merged and `upstream` is the name
+of your remote pointing to `git@github.com:coq/coq.git`.
+Note that you are only supposed to merge PRs into `master`. PRs should rarely
+target the stable branch, but when it is the case they are the responsibility
+of the release manager.
+
+This script conducts various checks before proceeding to merge. Don't bypass them
+without a good reason to, and in that case, write a comment in the PR thread to
+explain the reason.
Maintainers MUST NOT merge their own patches.
DON'T USE the GitHub interface for merging, since it will prevent the automated
backport script from operating properly, generates bad commit messages, and a
messy history when there are conflicts.
+
+### What to do if the PR has overlays
+
+If the PR breaks compatibility of some developments in CI, then the author must
+have prepared overlays for these developments (see [`dev/ci/README.md`](/dev/ci/README.md))
+and the PR must absolutely update the `CHANGES` file.
+
+There are two cases to consider:
+
+- If the patch is backward compatible (best scenario), then you should get
+ upstream maintainers to integrate it before merging the PR.
+- If the patch is not backward compatible (which is often the case when
+ patching plugins after an update to the Coq API), then you can proceed to
+ merge the PR and then notify upstream they can merge the patch. This is a
+ less preferable scenario because it is probably going to create
+ spurious CI failures for unrelated PRs.
+
+### Merge script dependencies
+
+The merge script passes option `-S` to `git merge` to ensure merge commits
+are signed. Consequently, it depends on the GnuPG command utility being
+installed and a GPG key being available. Here is a short tutorial to
+creating your own GPG key:
+<https://ekaia.org/blog/2009/05/10/creating-new-gpgkey/>
+
+The script depends on a few other utilities. If you are a Nix user, the
+simplest way of getting them is to run `nix-shell` first.
+
+**Note for homebrew (MacOS) users:** it has been reported that installing GnuPG
+is not out of the box. Installing explicitly "pinentry-mac" seems important for
+typing of passphrase to work correctly (see also this
+[Stack Overflow Q-and-A](https://stackoverflow.com/questions/39494631/gpg-failed-to-sign-the-data-fatal-failed-to-write-commit-object-git-2-10-0)).
diff --git a/dev/lint-repository.sh b/dev/lint-repository.sh
index ee9c8777a..cd09b6d30 100755
--- a/dev/lint-repository.sh
+++ b/dev/lint-repository.sh
@@ -31,4 +31,6 @@ fi
find . "(" -path ./.git -prune ")" -o -type f -print0 |
xargs -0 dev/tools/check-eof-newline.sh || CODE=1
+dev/tools/check-overlays.sh || CODE=1
+
exit $CODE
diff --git a/dev/tools/backport-pr.sh b/dev/tools/backport-pr.sh
index e4359f703..5205350a6 100755
--- a/dev/tools/backport-pr.sh
+++ b/dev/tools/backport-pr.sh
@@ -27,9 +27,9 @@ BRANCH=backport-pr-${PRNUM}
RANGE=$(git log master --grep "Merge PR #${PRNUM}" --format="%P" | sed 's/ /../')
MESSAGE=$(git log master --grep "Merge PR #${PRNUM}" --format="%s" | sed 's/Merge/Backport/')
-if git checkout -b ${BRANCH}; then
+if git checkout -b "${BRANCH}"; then
- if ! git cherry-pick -x ${RANGE}; then
+ if ! git cherry-pick -x "${RANGE}"; then
echo "Please fix the conflicts, then exit."
bash
while ! git cherry-pick --continue; do
@@ -50,7 +50,7 @@ else
fi
-if ! git diff --exit-code HEAD ${BRANCH} -- "*.mli"; then
+if ! git diff --exit-code HEAD "${BRANCH}" -- "*.mli"; then
echo
read -p "Some mli files are modified. Bypass? [y/N] " -n 1 -r
echo
@@ -63,8 +63,8 @@ if [[ "${OPTION}" == "--stop-before-merging" ]]; then
exit 0
fi
-git merge -S --no-ff ${BRANCH} -m "${MESSAGE}"
-git branch -d ${BRANCH}
+git merge -S --no-ff "${BRANCH}" -m "${MESSAGE}"
+git branch -d "${BRANCH}"
# To-Do:
# - Support for backporting a PR before it is merged
diff --git a/dev/tools/check-overlays.sh b/dev/tools/check-overlays.sh
new file mode 100755
index 000000000..f7e05b51c
--- /dev/null
+++ b/dev/tools/check-overlays.sh
@@ -0,0 +1,11 @@
+#!/usr/bin/env bash
+
+for f in dev/ci/user-overlays/*
+do
+ if ! ([[ $f = dev/ci/user-overlays/README.md ]] || [[ $f == *.sh ]])
+ then
+ >&2 echo "Bad overlay '$f'."
+ >&2 echo "User overlays need to have extension .sh to be picked up!"
+ exit 1
+ fi
+done
diff --git a/dev/tools/merge-pr.sh b/dev/tools/merge-pr.sh
index 2f6f1af54..20612eeb8 100755
--- a/dev/tools/merge-pr.sh
+++ b/dev/tools/merge-pr.sh
@@ -61,10 +61,12 @@ fi
# Fetching PR metadata
-TITLE=$(curl -s "$API/pulls/$PR" | jq -r '.title')
+PRDATA=$(curl -s "$API/pulls/$PR")
+
+TITLE=$(echo "$PRDATA" | jq -r '.title')
info "title for PR $PR is ${BLUE}$TITLE"
-BASE_BRANCH=$(curl -s "$API/pulls/$PR" | jq -r '.base.label')
+BASE_BRANCH=$(echo "$PRDATA" | jq -r '.base.label')
info "PR $PR targets branch ${BLUE}$BASE_BRANCH"
CURRENT_LOCAL_BRANCH=$(git rev-parse --abbrev-ref HEAD)
@@ -78,8 +80,8 @@ if [ -z "$REMOTE" ]; then
exit 1
fi
REMOTE_URL=$(git remote get-url "$REMOTE" --push)
-if [ "$REMOTE_URL" != "$OFFICIAL_REMOTE_URL" -a \
- "$REMOTE_URL" != "$OFFICIAL_REMOTE_URL.git" ]; then
+if [ "$REMOTE_URL" != "$OFFICIAL_REMOTE_URL" ] && \
+ [ "$REMOTE_URL" != "$OFFICIAL_REMOTE_URL.git" ]; then
error "remote ${BLUE}$REMOTE${RESET} does not point to the official Coq repo"
error "that is ${BLUE}$OFFICIAL_REMOTE_URL"
error "it points to ${BLUE}$REMOTE_URL${RESET} instead"
@@ -107,17 +109,17 @@ fi;
# Sanity check: CI failed
-STATUS=$(curl -s "$API/commits/$COMMIT/status" | jq -r '.state')
+STATUS=$(curl -s "$API/commits/$COMMIT/status")
-if [ "$STATUS" != "success" ]; then
- error "CI unsuccessful on ${BLUE}$(curl -s "$API/commits/$COMMIT/status" |
+if [ "$(echo "$STATUS" | jq -r '.state')" != "success" ]; then
+ error "CI unsuccessful on ${BLUE}$(echo "$STATUS" |
jq -r -c '.statuses|map(select(.state != "success"))|map(.context)')"
ask_confirmation
fi;
# Sanity check: has labels named "needs:"
-NEEDS_LABELS=$(curl -s "$API/pulls/$PR" | jq -rc '.labels | map(select(.name | match("needs:"))) | map(.name)')
+NEEDS_LABELS=$(echo "$PRDATA" | jq -rc '.labels | map(select(.name | match("needs:"))) | map(.name)')
if [ "$NEEDS_LABELS" != "[]" ]; then
error "needs:something labels still present: ${BLUE}$NEEDS_LABELS"
ask_confirmation
@@ -125,7 +127,7 @@ fi
# Sanity check: has milestone
-MILESTONE=$(curl -s "$API/pulls/$PR" | jq -rc '.milestone.title')
+MILESTONE=$(echo "$PRDATA" | jq -rc '.milestone.title')
if [ "$MILESTONE" = "null" ]; then
error "no milestone set, please set one"
ask_confirmation
@@ -133,7 +135,7 @@ fi
# Sanity check: has kind
-KIND=$(curl -s "$API/pulls/$PR" | jq -rc '.labels | map(select(.name | match("kind:"))) | map(.name)')
+KIND=$(echo "$PRDATA" | jq -rc '.labels | map(select(.name | match("kind:"))) | map(.name)')
if [ "$KIND" = "[]" ]; then
error "no kind:something label set, please set one"
ask_confirmation
diff --git a/dev/tools/pre-commit b/dev/tools/pre-commit
index c9cdee84a..a514b8866 100755
--- a/dev/tools/pre-commit
+++ b/dev/tools/pre-commit
@@ -5,6 +5,8 @@
set -e
+dev/tools/check-overlays.sh
+
if ! git diff --cached --name-only -z | xargs -0 dev/tools/check-eof-newline.sh ||
! git diff-index --check --cached HEAD >/dev/null 2>&1 ;
then
diff --git a/doc/refman/AsyncProofs.tex b/doc/refman/AsyncProofs.tex
deleted file mode 100644
index 8f9d876cb..000000000
--- a/doc/refman/AsyncProofs.tex
+++ /dev/null
@@ -1,221 +0,0 @@
-\achapter{Asynchronous and Parallel Proof Processing\label{Asyncprocessing}}
-%HEVEA\cutname{async-proofs.html}
-\aauthor{Enrico Tassi}
-
-\label{pralitp}
-\index{Asynchronous and Parallel Proof Processing!presentation}
-
-This chapter explains how proofs can be asynchronously processed by Coq.
-This feature improves the reactivity of the system when used in interactive
-mode via CoqIDE. In addition, it allows Coq to take advantage of
-parallel hardware when used as a batch compiler by decoupling the checking
-of statements and definitions from the construction and checking of proofs
-objects.
-
-This feature is designed to help dealing with huge libraries of theorems
-characterized by long proofs. In the current state, it may not be beneficial
-on small sets of short files.
-
-This feature has some technical limitations that may make it unsuitable for
-some use cases.
-
-For example, in interactive mode, some errors coming from the kernel of Coq
-are signaled late. The type of errors belonging to this category
-are universe inconsistencies.
-
-At the time of writing, only opaque proofs (ending with \texttt{Qed} or \texttt{Admitted}) can be processed asynchronously.
-
-Finally, asynchronous processing is disabled when running CoqIDE in Windows. The
-current implementation of the feature is not stable on Windows. It can be
-enabled, as described below at \ref{interactivecaveats}, though doing so is not
-recommended.
-
-\section{Proof annotations}
-
-To process a proof asynchronously Coq needs to know the precise statement
-of the theorem without looking at the proof. This requires some annotations
-if the theorem is proved inside a \texttt{Section} (see Section~\ref{Section}).
-
-When a section ends, Coq looks at the proof object to decide which
-section variables are actually used and hence have to be quantified in the
-statement of the theorem. To avoid making the construction of proofs
-mandatory when ending a section, one can start each proof with the
-\texttt{Proof using} command (Section~\ref{ProofUsing}) that declares which
-section variables the theorem uses.
-
-The presence of \texttt{Proof using} is needed to process proofs
-asynchronously in interactive mode.
-
-It is not strictly mandatory in batch mode if it is not the first time
-the file is compiled and if the file itself did not change. When the
-proof does not begin with \texttt{Proof using}, the system records in an
-auxiliary file, produced along with the \texttt{.vo} file, the list of
-section variables used.
-
-\subsubsection{Automatic suggestion of proof annotations}
-
-The command \texttt{Set Suggest Proof Using} makes Coq suggest, when a
-\texttt{Qed} command is processed, a correct proof annotation. It is up
-to the user to modify the proof script accordingly.
-
-\section{Proof blocks and error resilience}
-
-Coq 8.6 introduces a mechanism for error resiliency: in interactive mode Coq
-is able to completely check a document containing errors instead of bailing
-out at the first failure.
-
-Two kind of errors are supported: errors occurring in vernacular commands and
-errors occurring in proofs.
-
-To properly recover from a failing tactic, Coq needs to recognize the structure of
-the proof in order to confine the error to a sub proof. Proof block detection
-is performed by looking at the syntax of the proof script (i.e. also looking at indentation).
-Coq comes with four kind of proof blocks, and an ML API to add new ones.
-
-\begin{description}
-\item[curly] blocks are delimited by \texttt{\{} and \texttt{\}}, see \ref{Proof-handling}
-\item[par] blocks are atomic, i.e. just one tactic introduced by the \texttt{par:} goal selector
-\item[indent] blocks end with a tactic indented less than the previous one
-\item[bullet] blocks are delimited by two equal bullet signs at the same indentation level
-\end{description}
-
-\subsection{Caveats}
-
-When a vernacular command fails the subsequent error messages may be bogus, i.e. caused by
-the first error. Error resiliency for vernacular commands can be switched off passing
-\texttt{-async-proofs-command-error-resilience off} to CoqIDE.
-
-An incorrect proof block detection can result into an incorrect error recovery and
-hence in bogus errors. Proof block detection cannot be precise for bullets or
-any other non well parenthesized proof structure. Error resiliency can be
-turned off or selectively activated for any set of block kind passing to
-CoqIDE one of the following options:
-\texttt{-async-proofs-tactic-error-resilience off},
-\texttt{-async-proofs-tactic-error-resilience all},
-\texttt{-async-proofs-tactic-error-resilience $blocktype_1$,..., $blocktype_n$}.
-Valid proof block types are: ``curly'', ``par'', ``indent'', ``bullet''.
-
-\section{Interactive mode}
-
-At the time of writing the only user interface supporting asynchronous proof
-processing is CoqIDE.
-
-When CoqIDE is started, two Coq processes are created. The master one follows
-the user, giving feedback as soon as possible by skipping proofs, which are
-delegated to the worker process. The worker process, whose state can be seen
-by clicking on the button in the lower right corner of the main CoqIDE window,
-asynchronously processes the proofs. If a proof contains an error, it is
-reported in red in the label of the very same button, that can also be used to
-see the list of errors and jump to the corresponding line.
-
-If a proof is processed asynchronously the corresponding \texttt{Qed} command
-is colored using a lighter color that usual. This signals that
-the proof has been delegated to a worker process (or will be processed
-lazily if the \texttt{-async-proofs lazy} option is used). Once finished, the
-worker process will provide the proof object, but this will not be
-automatically checked by the kernel of the main process. To force
-the kernel to check all the proof objects, one has to click the button
-with the gears. Only then are all the universe constraints checked.
-
-\subsubsection{Caveats}
-\label{interactivecaveats}
-
-The number of worker processes can be increased by passing CoqIDE the
-\texttt{-async-proofs-j $n$} flag. Note that the memory consumption
-increases too, since each worker requires the same amount of memory as
-the master process. Also note that increasing the number of workers may
-reduce the reactivity of the master process to user commands.
-
-To disable this feature, one can pass the \texttt{-async-proofs off} flag to
-CoqIDE. Conversely, on Windows, where the feature is disabled by default,
-pass the \texttt{-async-proofs on} flag to enable it.
-
-Proofs that are known to take little time to process are not delegated to a
-worker process. The threshold can be configure with \texttt{-async-proofs-delegation-threshold}. Default is 0.03 seconds.
-
-\section{Batch mode}
-
-When Coq is used as a batch compiler by running \texttt{coqc} or
-\texttt{coqtop -compile}, it produces a \texttt{.vo} file for each
-\texttt{.v} file. A \texttt{.vo} file contains, among other things,
-theorems statements and proofs. Hence to produce a \texttt{.vo} Coq need
-to process all the proofs of the \texttt{.v} file.
-
-The asynchronous processing of proofs can decouple the generation of a
-compiled file (like the \texttt{.vo} one) that can be loaded by
-\texttt{Require} from the generation and checking of the proof objects.
-The \texttt{-quick} flag can be passed to \texttt{coqc} or
-\texttt{coqtop} to produce, quickly, \texttt{.vio} files. Alternatively,
-when using a \texttt{Makefile} produced by \texttt{coq\_makefile}, the
-\texttt{quick} target can be used to compile all files using the
-\texttt{-quick} flag.
-
-A \texttt{.vio} file can be loaded using \texttt{Require} exactly as a
-\texttt{.vo} file but proofs will not be available (the \texttt{Print}
-command produces an error). Moreover, some universe constraints might be
-missing, so universes inconsistencies might go unnoticed. A
-\texttt{.vio} file does not contain proof objects, but proof tasks,
-i.e. what a worker process can transform into a proof object.
-
-Compiling a set of files with the \texttt{-quick} flag allows one to work,
-interactively, on any file without waiting for all the proofs to be checked.
-
-When working interactively, one can fully check all the \texttt{.v} files by
-running \texttt{coqc} as usual.
-
-Alternatively one can turn each \texttt{.vio} into the corresponding
-\texttt{.vo}. All \texttt{.vio} files can be processed in parallel,
-hence this alternative might be faster. The command \texttt{coqtop
- -schedule-vio2vo 2 a b c} can be used to obtain a good scheduling for 2
-workers to produce \texttt{a.vo}, \texttt{b.vo}, and \texttt{c.vo}. When
-using a \texttt{Makefile} produced by \texttt{coq\_makefile}, the
-\texttt{vio2vo} target can be used for that purpose. Variable \texttt{J}
-should be set to the number of workers, e.g. \texttt{make vio2vo J=2}.
-The only caveat is that, while the \texttt{.vo} files obtained from
-\texttt{.vio} files are complete (they contain all proof terms and
-universe constraints), the satisfiability of all universe constraints has
-not been checked globally (they are checked to be consistent for every
-single proof). Constraints will be checked when these \texttt{.vo} files
-are (recursively) loaded with \texttt{Require}.
-
-There is an extra, possibly even faster, alternative: just check the
-proof tasks stored in \texttt{.vio} files without producing the
-\texttt{.vo} files. This is possibly faster because all the proof tasks
-are independent, hence one can further partition the job to be done
-between workers. The \texttt{coqtop -schedule-vio-checking 6 a b c}
-command can be used to obtain a good scheduling for 6 workers to check
-all the proof tasks of \texttt{a.vio}, \texttt{b.vio}, and
-\texttt{c.vio}. Auxiliary files are used to predict how long a proof task
-will take, assuming it will take the same amount of time it took last
-time. When using a \texttt{Makefile} produced by \texttt{coq\_makefile},
-the \texttt{checkproofs} target can be used to check all \texttt{.vio}
-files. Variable \texttt{J} should be set to the number of workers,
-e.g. \texttt{make checkproofs J=6}. As when converting \texttt{.vio}
-files to \texttt{.vo} files, universe constraints are not checked to be
-globally consistent. Hence this compilation mode is only useful for quick
-regression testing and on developments not making heavy use of the $Type$
-hierarchy.
-
-\section{Limiting the number of parallel workers}
-\label{coqworkmgr}
-
-Many Coq processes may run on the same computer, and each of them may start
-many additional worker processes.
-The \texttt{coqworkmgr} utility lets one limit the number of workers, globally.
-
-The utility accepts the \texttt{-j} argument to specify the maximum number of
-workers (defaults to 2). \texttt{coqworkmgr} automatically starts in the
-background and prints an environment variable assignment like
-\texttt{COQWORKMGR\_SOCKET=localhost:45634}. The user must set this variable in
-all the shells from which Coq processes will be started. If one uses just
-one terminal running the bash shell, then \texttt{export `coqworkmgr -j 4`} will
-do the job.
-
-After that, all Coq processes, e.g. \texttt{coqide} and \texttt{coqc},
-will honor the limit, globally.
-
-
-%%% Local Variables:
-%%% mode: latex
-%%% TeX-master: "Reference-Manual"
-%%% End:
diff --git a/doc/refman/Classes.tex b/doc/refman/Classes.tex
deleted file mode 100644
index da798a238..000000000
--- a/doc/refman/Classes.tex
+++ /dev/null
@@ -1,578 +0,0 @@
-\def\Haskell{\textsc{Haskell}\xspace}
-\def\eol{\setlength\parskip{0pt}\par}
-\def\indent#1{\noindent\kern#1}
-\def\cst#1{\textsf{#1}}
-
-\newcommand\tele[1]{\overrightarrow{#1}}
-
-\achapter{\protect{Type Classes}}
-%HEVEA\cutname{type-classes.html}
-\aauthor{Matthieu Sozeau}
-\label{typeclasses}
-
-This chapter presents a quick reference of the commands related to type
-classes. For an actual introduction to type classes, there is a
-description of the system \cite{sozeau08} and the literature on type
-classes in \Haskell which also applies.
-
-\asection{Class and Instance declarations}
-\label{ClassesInstances}
-
-The syntax for class and instance declarations is the same as
-record syntax of \Coq:
-\def\kw{\texttt}
-\def\classid{\texttt}
-
-\begin{center}
-\[\begin{array}{l}
-\kw{Class}~\classid{Id}~(\alpha_1 : \tau_1) \cdots (\alpha_n : \tau_n)
-[: \sort] := \{\\
-\begin{array}{p{0em}lcl}
- & \cst{f}_1 & : & \type_1 ; \\
- & \vdots & & \\
- & \cst{f}_m & : & \type_m \}.
-\end{array}\end{array}\]
-\end{center}
-\begin{center}
-\[\begin{array}{l}
-\kw{Instance}~\ident~:~\classid{Id}~\term_1 \cdots \term_n := \{\\
-\begin{array}{p{0em}lcl}
- & \cst{f}_1 & := & \term_{f_1} ; \\
- & \vdots & & \\
- & \cst{f}_m & := & \term_{f_m} \}.
-\end{array}\end{array}\]
-\end{center}
-\begin{coq_eval}
- Reset Initial.
- Generalizable All Variables.
-\end{coq_eval}
-
-The $\tele{\alpha_i : \tau_i}$ variables are called the \emph{parameters}
-of the class and the $\tele{f_k : \type_k}$ are called the
-\emph{methods}. Each class definition gives rise to a corresponding
-record declaration and each instance is a regular definition whose name
-is given by $\ident$ and type is an instantiation of the record type.
-
-We'll use the following example class in the rest of the chapter:
-
-\begin{coq_example*}
-Class EqDec (A : Type) := {
- eqb : A -> A -> bool ;
- eqb_leibniz : forall x y, eqb x y = true -> x = y }.
-\end{coq_example*}
-
-This class implements a boolean equality test which is compatible with
-Leibniz equality on some type. An example implementation is:
-
-\begin{coq_example*}
-Instance unit_EqDec : EqDec unit :=
-{ eqb x y := true ;
- eqb_leibniz x y H :=
- match x, y return x = y with tt, tt => eq_refl tt end }.
-\end{coq_example*}
-
-If one does not give all the members in the \texttt{Instance}
-declaration, Coq enters the proof-mode and the user is asked to build
-inhabitants of the remaining fields, e.g.:
-
-\begin{coq_example*}
-Instance eq_bool : EqDec bool :=
-{ eqb x y := if x then y else negb y }.
-\end{coq_example*}
-\begin{coq_example}
-Proof. intros x y H.
- destruct x ; destruct y ; (discriminate || reflexivity).
-Defined.
-\end{coq_example}
-
-One has to take care that the transparency of every field is determined
-by the transparency of the \texttt{Instance} proof. One can use
-alternatively the \texttt{Program} \texttt{Instance} \comindex{Program Instance} variant which has
-richer facilities for dealing with obligations.
-
-\asection{Binding classes}
-
-Once a type class is declared, one can use it in class binders:
-\begin{coq_example}
-Definition neqb {A} {eqa : EqDec A} (x y : A) := negb (eqb x y).
-\end{coq_example}
-
-When one calls a class method, a constraint is generated that is
-satisfied only in contexts where the appropriate instances can be
-found. In the example above, a constraint \texttt{EqDec A} is generated and
-satisfied by \texttt{{eqa : EqDec A}}. In case no satisfying constraint can be
-found, an error is raised:
-
-\begin{coq_example}
-Fail Definition neqb' (A : Type) (x y : A) := negb (eqb x y).
-\end{coq_example}
-
-The algorithm used to solve constraints is a variant of the eauto tactic
-that does proof search with a set of lemmas (the instances). It will use
-local hypotheses as well as declared lemmas in the
-\texttt{typeclass\_instances} database. Hence the example can also be
-written:
-
-\begin{coq_example}
-Definition neqb' A (eqa : EqDec A) (x y : A) := negb (eqb x y).
-\end{coq_example}
-
-However, the generalizing binders should be used instead as they have
-particular support for type classes:
-\begin{itemize}
-\item They automatically set the maximally implicit status for type
- class arguments, making derived functions as easy to use as class
- methods. In the example above, \texttt{A} and \texttt{eqa} should be
- set maximally implicit.
-\item They support implicit quantification on partially applied type
- classes (\S \ref{implicit-generalization}).
- Any argument not given as part of a type class binder will be
- automatically generalized.
-\item They also support implicit quantification on superclasses
- (\S \ref{classes:superclasses})
-\end{itemize}
-
-Following the previous example, one can write:
-\begin{coq_example}
-Definition neqb_impl `{eqa : EqDec A} (x y : A) := negb (eqb x y).
-\end{coq_example}
-
-Here \texttt{A} is implicitly generalized, and the resulting function
-is equivalent to the one above.
-
-\asection{Parameterized Instances}
-
-One can declare parameterized instances as in \Haskell simply by giving
-the constraints as a binding context before the instance, e.g.:
-
-\begin{coq_example}
-Instance prod_eqb `(EA : EqDec A, EB : EqDec B) : EqDec (A * B) :=
-{ eqb x y := match x, y with
- | (la, ra), (lb, rb) => andb (eqb la lb) (eqb ra rb)
- end }.
-\end{coq_example}
-\begin{coq_eval}
-Admitted.
-\end{coq_eval}
-
-These instances are used just as well as lemmas in the instance hint database.
-
-\asection{Sections and contexts}
-\label{SectionContext}
-To ease the parametrization of developments by type classes, we provide
-a new way to introduce variables into section contexts, compatible with
-the implicit argument mechanism.
-The new command works similarly to the \texttt{Variables} vernacular
-(see \ref{Variable}), except it accepts any binding context as argument.
-For example:
-
-\begin{coq_example}
-Section EqDec_defs.
- Context `{EA : EqDec A}.
-\end{coq_example}
-
-\begin{coq_example*}
- Global Instance option_eqb : EqDec (option A) :=
- { eqb x y := match x, y with
- | Some x, Some y => eqb x y
- | None, None => true
- | _, _ => false
- end }.
-\end{coq_example*}
-\begin{coq_eval}
-Proof.
-intros x y ; destruct x ; destruct y ; intros H ;
-try discriminate ; try apply eqb_leibniz in H ;
-subst ; auto.
-Defined.
-\end{coq_eval}
-
-\begin{coq_example}
-End EqDec_defs.
-About option_eqb.
-\end{coq_example}
-
-Here the \texttt{Global} modifier redeclares the instance at the end of
-the section, once it has been generalized by the context variables it uses.
-
-\asection{Building hierarchies}
-
-\subsection{Superclasses}
-\label{classes:superclasses}
-One can also parameterize classes by other classes, generating a
-hierarchy of classes and superclasses. In the same way, we give the
-superclasses as a binding context:
-
-\begin{coq_example*}
-Class Ord `(E : EqDec A) :=
- { le : A -> A -> bool }.
-\end{coq_example*}
-
-Contrary to \Haskell, we have no special syntax for superclasses, but
-this declaration is morally equivalent to:
-\begin{verbatim}
-Class `(E : EqDec A) => Ord A :=
- { le : A -> A -> bool }.
-\end{verbatim}
-
-This declaration means that any instance of the \texttt{Ord} class must
-have an instance of \texttt{EqDec}. The parameters of the subclass contain
-at least all the parameters of its superclasses in their order of
-appearance (here \texttt{A} is the only one).
-As we have seen, \texttt{Ord} is encoded as a record type with two parameters:
-a type \texttt{A} and an \texttt{E} of type \texttt{EqDec A}. However, one can
-still use it as if it had a single parameter inside generalizing binders: the
-generalization of superclasses will be done automatically.
-\begin{coq_example*}
-Definition le_eqb `{Ord A} (x y : A) := andb (le x y) (le y x).
-\end{coq_example*}
-
-In some cases, to be able to specify sharing of structures, one may want to give
-explicitly the superclasses. It is is possible to do it directly in regular
-binders, and using the \texttt{!} modifier in class binders. For
-example:
-\begin{coq_example*}
-Definition lt `{eqa : EqDec A, ! Ord eqa} (x y : A) :=
- andb (le x y) (neqb x y).
-\end{coq_example*}
-
-The \texttt{!} modifier switches the way a binder is parsed back to the
-regular interpretation of Coq. In particular, it uses the implicit
-arguments mechanism if available, as shown in the example.
-
-\subsection{Substructures}
-
-Substructures are components of a class which are instances of a class
-themselves. They often arise when using classes for logical properties,
-e.g.:
-
-\begin{coq_eval}
-Require Import Relations.
-\end{coq_eval}
-\begin{coq_example*}
-Class Reflexive (A : Type) (R : relation A) :=
- reflexivity : forall x, R x x.
-Class Transitive (A : Type) (R : relation A) :=
- transitivity : forall x y z, R x y -> R y z -> R x z.
-\end{coq_example*}
-
-This declares singleton classes for reflexive and transitive relations,
-(see \ref{SingletonClass} for an explanation).
-These may be used as part of other classes:
-
-\begin{coq_example*}
-Class PreOrder (A : Type) (R : relation A) :=
-{ PreOrder_Reflexive :> Reflexive A R ;
- PreOrder_Transitive :> Transitive A R }.
-\end{coq_example*}
-
-The syntax \texttt{:>} indicates that each \texttt{PreOrder} can be seen
-as a \texttt{Reflexive} relation. So each time a reflexive relation is
-needed, a preorder can be used instead. This is very similar to the
-coercion mechanism of \texttt{Structure} declarations.
-The implementation simply declares each projection as an instance.
-
-One can also declare existing objects or structure
-projections using the \texttt{Existing Instance} command to achieve the
-same effect.
-
-\section{Summary of the commands
-\label{TypeClassCommands}}
-
-\subsection{\tt Class {\ident} {\binder$_1$ \ldots~\binder$_n$}
- : \sort := \{ field$_1$ ; \ldots ; field$_k$ \}.}
-\comindex{Class}
-\label{Class}
-
-The \texttt{Class} command is used to declare a type class with
-parameters {\binder$_1$} to {\binder$_n$} and fields {\tt field$_1$} to
-{\tt field$_k$}.
-
-\begin{Variants}
-\item \label{SingletonClass} {\tt Class {\ident} {\binder$_1$ \ldots \binder$_n$}
- : \sort := \ident$_1$ : \type$_1$.}
- This variant declares a \emph{singleton} class whose only method is
- {\tt \ident$_1$}. This singleton class is a so-called definitional
- class, represented simply as a definition
- {\tt {\ident} \binder$_1$ \ldots \binder$_n$ := \type$_1$} and whose
- instances are themselves objects of this type. Definitional classes
- are not wrapped inside records, and the trivial projection of an
- instance of such a class is convertible to the instance itself. This can
- be useful to make instances of existing objects easily and to reduce
- proof size by not inserting useless projections. The class
- constant itself is declared rigid during resolution so that the class
- abstraction is maintained.
-
-\item \label{ExistingClass} {\tt Existing Class {\ident}.\comindex{Existing Class}}
- This variant declares a class a posteriori from a constant or
- inductive definition. No methods or instances are defined.
-\end{Variants}
-
-\subsection{\tt Instance {\ident} {\binder$_1$ \ldots \binder$_n$} :
- {Class} {t$_1$ \ldots t$_n$} [| \textit{priority}]
- := \{ field$_1$ := b$_1$ ; \ldots ; field$_i$ := b$_i$ \}}
-\comindex{Instance}
-\label{Instance}
-
-The \texttt{Instance} command is used to declare a type class instance
-named {\ident} of the class \emph{Class} with parameters {t$_1$} to {t$_n$} and
-fields {\tt b$_1$} to {\tt b$_i$}, where each field must be a declared
-field of the class. Missing fields must be filled in interactive proof mode.
-
-An arbitrary context of the form {\tt \binder$_1$ \ldots \binder$_n$}
-can be put after the name of the instance and before the colon to
-declare a parameterized instance.
-An optional \textit{priority} can be declared, 0 being the highest
-priority as for auto hints. If the priority is not specified, it defaults to
-$n$, the number of binders of the instance.
-
-\begin{Variants}
-\item {\tt Instance {\ident} {\binder$_1$ \ldots \binder$_n$} :
- forall {\binder$_{n+1}$ \ldots \binder$_m$},
- {Class} {t$_1$ \ldots t$_n$} [| \textit{priority}] := \term}
- This syntax is used for declaration of singleton class instances or
- for directly giving an explicit term of type
- {\tt forall {\binder$_{n+1}$ \ldots \binder$_m$}, {Class} {t$_1$ \ldots t$_n$}}.
- One need not even mention the unique field name for singleton classes.
-
-\item {\tt Global Instance} One can use the \texttt{Global} modifier on
- instances declared in a section so that their generalization is automatically
- redeclared after the section is closed.
-
-\item {\tt Program Instance} \comindex{Program Instance}
- Switches the type-checking to \Program~(chapter \ref{Program})
- and uses the obligation mechanism to manage missing fields.
-
-\item {\tt Declare Instance} \comindex{Declare Instance}
- In a {\tt Module Type}, this command states that a corresponding
- concrete instance should exist in any implementation of this
- {\tt Module Type}. This is similar to the distinction between
- {\tt Parameter} vs. {\tt Definition}, or between {\tt Declare Module}
- and {\tt Module}.
-
-\end{Variants}
-
-Besides the {\tt Class} and {\tt Instance} vernacular commands, there
-are a few other commands related to type classes.
-
-\subsection{\tt Existing Instance {\ident} [| \textit{priority}]}
-\comindex{Existing Instance}
-\label{ExistingInstance}
-
-This commands adds an arbitrary constant whose type ends with an applied
-type class to the instance database with an optional priority. It can be used
-for redeclaring instances at the end of sections, or declaring structure
-projections as instances. This is almost equivalent to {\tt Hint Resolve
-{\ident} : typeclass\_instances}.
-
-\begin{Variants}
-\item {\tt Existing Instances {\ident}$_1$ \ldots {\ident}$_n$
- [| \textit{priority}]}
- \comindex{Existing Instances}
- With this command, several existing instances can be declared at once.
-\end{Variants}
-
-\subsection{\tt Context {\binder$_1$ \ldots \binder$_n$}}
-\comindex{Context}
-\label{Context}
-
-Declares variables according to the given binding context, which might
-use implicit generalization (see \ref{SectionContext}).
-
-\asubsection{\tt typeclasses eauto}
-\tacindex{typeclasses eauto}
-\label{typeclasseseauto}
-
-The {\tt typeclasses eauto} tactic uses a different resolution engine
-than {\tt eauto} and {\tt auto}. The main differences are the following:
-\begin{itemize}
-\item Contrary to {\tt eauto} and {\tt auto}, the resolution is done
- entirely in the new proof engine (as of Coq v8.6), meaning that
- backtracking is available among dependent subgoals, and shelving goals
- is supported. {\tt typeclasses eauto} is a multi-goal tactic.
- It analyses the dependencies between subgoals to avoid
- backtracking on subgoals that are entirely independent.
-\item When called with no arguments, {\tt typeclasses eauto} uses the
- {\tt typeclass\_instances} database by default (instead of {\tt
- core}).
- Dependent subgoals are automatically shelved, and shelved
- goals can remain after resolution ends (following the behavior of
- \Coq{} 8.5).
-
- \emph{Note: } As of Coq 8.6, {\tt all:once (typeclasses eauto)}
- faithfully mimicks what happens during typeclass resolution when it is
- called during refinement/type-inference, except that \emph{only}
- declared class subgoals are considered at the start of resolution
- during type inference, while ``all'' can select non-class subgoals as
- well. It might move to {\tt all:typeclasses eauto} in future versions
- when the refinement engine will be able to backtrack.
-\item When called with specific databases (e.g. {\tt with}), {\tt
- typeclasses eauto} allows shelved goals to remain at any point
- during search and treat typeclasses goals like any other.
-\item The transparency information of databases is used consistently for
- all hints declared in them. It is always used when calling the unifier.
- When considering the local hypotheses, we use the transparent
- state of the first hint database given. Using an empty database
- (created with {\tt Create HintDb} for example) with
- unfoldable variables and constants as the first argument of
- typeclasses eauto hence makes resolution with the local hypotheses use
- full conversion during unification.
-\end{itemize}
-
-\begin{Variants}
-\item \label{depth} {\tt typeclasses eauto \zeroone{\num}}
- \emph{Warning:} The semantics for the limit {\num} is different than
- for {\tt auto}. By default, if no limit is given the search is
- unbounded. Contrary to {\tt auto}, introduction steps ({\tt intro})
- are counted, which might result in larger limits being necessary
- when searching with {\tt typeclasses eauto} than {\tt auto}.
-
-\item \label{with} {\tt typeclasses eauto with {\ident}$_1$ \ldots {\ident}$_n$}.
- This variant runs resolution with the given hint databases. It treats
- typeclass subgoals the same as other subgoals (no shelving of
- non-typeclass goals in particular).
-\end{Variants}
-
-\asubsection{\tt autoapply {\term} with {\ident}}
-\tacindex{autoapply}
-
-The tactic {\tt autoapply} applies a term using the transparency
-information of the hint database {\ident}, and does \emph{no} typeclass
-resolution. This can be used in {\tt Hint Extern}'s for typeclass
-instances (in hint db {\tt typeclass\_instances}) to
-allow backtracking on the typeclass subgoals created by the lemma
-application, rather than doing type class resolution locally at the hint
-application time.
-
-\subsection{\tt Typeclasses Transparent, Opaque {\ident$_1$ \ldots \ident$_n$}}
-\comindex{Typeclasses Transparent}
-\comindex{Typeclasses Opaque}
-\label{TypeclassesTransparency}
-
-This commands defines the transparency of {\ident$_1$ \ldots \ident$_n$}
-during type class resolution. It is useful when some constants prevent some
-unifications and make resolution fail. It is also useful to declare
-constants which should never be unfolded during proof-search, like
-fixpoints or anything which does not look like an abbreviation. This can
-additionally speed up proof search as the typeclass map can be indexed
-by such rigid constants (see \ref{HintTransparency}).
-By default, all constants and local variables are considered transparent.
-One should take care not to make opaque any constant that is used to
-abbreviate a type, like {\tt relation A := A -> A -> Prop}.
-
-This is equivalent to {\tt Hint Transparent,Opaque} {\ident} {\tt: typeclass\_instances}.
-
-\subsection{\tt Set Typeclasses Axioms Are Instances}
-\optindex{Typeclasses Axioms Are Instances}
-
-This option (off by default since 8.8) automatically declares axioms
-whose type is a typeclass at declaration time as instances of that
-class.
-
-\subsection{\tt Set Typeclasses Dependency Order}
-\optindex{Typeclasses Dependency Order}
-
-This option (on by default since 8.6) respects the dependency order between
-subgoals, meaning that subgoals which are depended on by other subgoals
-come first, while the non-dependent subgoals were put before the
-dependent ones previously (Coq v8.5 and below). This can result in quite
-different performance behaviors of proof search.
-
-\subsection{\tt Set Typeclasses Filtered Unification}
-\optindex{Typeclasses Filtered Unification}
-
-This option, available since Coq 8.6 and off by default, switches the
-hint application procedure to a filter-then-unify strategy. To apply a
-hint, we first check that the goal \emph{matches} syntactically the
-inferred or specified pattern of the hint, and only then try to
-\emph{unify} the goal with the conclusion of the hint. This can
-drastically improve performance by calling unification less often,
-matching syntactic patterns being very quick. This also provides more
-control on the triggering of instances. For example, forcing a constant
-to explicitely appear in the pattern will make it never apply on a goal
-where there is a hole in that place.
-
-\subsection{\tt Set Typeclasses Limit Intros}
-\optindex{Typeclasses Limit Intros}
-
-This option (on by default) controls the ability to
-apply hints while avoiding (functional) eta-expansions in the generated
-proof term. It does so by allowing hints that conclude in a product to
-apply to a goal with a matching product directly, avoiding an
-introduction. \emph{Warning:} this can be expensive as it requires
-rebuilding hint clauses dynamically, and does not benefit from the
-invertibility status of the product introduction rule, resulting in
-potentially more expensive proof-search (i.e. more useless
-backtracking).
-
-\subsection{\tt Set Typeclass Resolution For Conversion}
-\optindex{Typeclass Resolution For Conversion}
-
-This option (on by default) controls the use of typeclass resolution
-when a unification problem cannot be solved during
-elaboration/type-inference. With this option on, when a unification
-fails, typeclass resolution is tried before launching unification once again.
-
-\subsection{\tt Set Typeclasses Strict Resolution}
-\optindex{Typeclasses Strict Resolution}
-
-Typeclass declarations introduced when this option is set have a
-stricter resolution behavior (the option is off by default). When
-looking for unifications of a goal with an instance of this class, we
-``freeze'' all the existentials appearing in the goals, meaning that
-they are considered rigid during unification and cannot be instantiated.
-
-\subsection{\tt Set Typeclasses Unique Solutions}
-\optindex{Typeclasses Unique Solutions}
-
-When a typeclass resolution is launched we ensure that it has a single
-solution or fail. This ensures that the resolution is canonical, but can
-make proof search much more expensive.
-
-\subsection{\tt Set Typeclasses Unique Instances}
-\optindex{Typeclasses Unique Instances}
-
-Typeclass declarations introduced when this option is set have a
-more efficient resolution behavior (the option is off by default). When
-a solution to the typeclass goal of this class is found, we never
-backtrack on it, assuming that it is canonical.
-
-\subsection{\tt Typeclasses eauto := [debug] [(dfs) | (bfs)] [\emph{depth}]}
-\comindex{Typeclasses eauto}
-\label{TypeclassesEauto}
-
-This command allows more global customization of the type class
-resolution tactic.
-The semantics of the options are:
-\begin{itemize}
-\item {\tt debug} In debug mode, the trace of successfully applied
- tactics is printed.
-\item {\tt dfs, bfs} This sets the search strategy to depth-first search
- (the default) or breadth-first search.
-\item {\emph{depth}} This sets the depth limit of the search.
-\end{itemize}
-
-\subsection{\tt Set Typeclasses Debug [Verbosity {\num}]}
-\optindex{Typeclasses Debug}
-\optindex{Typeclasses Debug Verbosity}
-
-These options allow to see the resolution steps of typeclasses that are
-performed during search. The {\tt Debug} option is synonymous to
-{\tt Debug Verbosity 1}, and {\tt Debug Verbosity 2} provides more
-information (tried tactics, shelving of goals, etc\ldots).
-
-\subsection{\tt Set Refine Instance Mode}
-\optindex{Refine Instance Mode}
-
-The option {\tt Refine Instance Mode} allows to switch the behavior of instance
-declarations made through the {\tt Instance} command.
-\begin{itemize}
-\item When it is on (the default), instances that have unsolved holes in their
-proof-term silently open the proof mode with the remaining obligations to prove.
-\item When it is off, they fail with an error instead.
-\end{itemize}
-
-%%% Local Variables:
-%%% mode: latex
-%%% TeX-master: "Reference-Manual"
-%%% End:
diff --git a/doc/refman/Coercion.tex b/doc/refman/Coercion.tex
deleted file mode 100644
index 9862a9b30..000000000
--- a/doc/refman/Coercion.tex
+++ /dev/null
@@ -1,563 +0,0 @@
-\achapter{Implicit Coercions}
-%HEVEA\cutname{coercions.html}
-\aauthor{Amokrane Saïbi}
-
-\label{Coercions-full}
-\index{Coercions!presentation}
-
-\asection{General Presentation}
-
-This section describes the inheritance mechanism of {\Coq}. In {\Coq} with
-inheritance, we are not interested in adding any expressive power to
-our theory, but only convenience. Given a term, possibly not typable,
-we are interested in the problem of determining if it can be well
-typed modulo insertion of appropriate coercions. We allow to write:
-
-\begin{itemize}
-\item $f~a$ where $f:forall~ x:A, B$ and $a:A'$ when $A'$ can
- be seen in some sense as a subtype of $A$.
-\item $x:A$ when $A$ is not a type, but can be seen in
- a certain sense as a type: set, group, category etc.
-\item $f~a$ when $f$ is not a function, but can be seen in a certain sense
- as a function: bijection, functor, any structure morphism etc.
-\end{itemize}
-
-\asection{Classes}
-\index{Coercions!classes}
- A class with $n$ parameters is any defined name with a type
-$forall~ (x_1:A_1)..(x_n:A_n), s$ where $s$ is a sort. Thus a class with
-parameters is considered as a single class and not as a family of
-classes. An object of a class $C$ is any term of type $C~t_1
-.. t_n$. In addition to these user-classes, we have two abstract
-classes:
-
-\begin{itemize}
-\item {\tt Sortclass}, the class of sorts;
- its objects are the terms whose type is a sort (e.g., \texttt{Prop}
- or \texttt{Type}).
-\item {\tt Funclass}, the class of functions;
- its objects are all the terms with a functional
- type, i.e. of form $forall~ x:A, B$.
-\end{itemize}
-
-Formally, the syntax of a classes is defined on Figure~\ref{fig:classes}.
-\begin{figure}
-\begin{centerframe}
-\begin{tabular}{lcl}
-{\class} & ::= & {\qualid} \\
- & $|$ & {\tt Sortclass} \\
- & $|$ & {\tt Funclass}
-\end{tabular}
-\end{centerframe}
-\caption{Syntax of classes}
-\label{fig:classes}
-\end{figure}
-
-\asection{Coercions}
-\index{Coercions!Funclass}
-\index{Coercions!Sortclass}
- A name $f$ can be declared as a coercion between a source user-class
-$C$ with $n$ parameters and a target class $D$ if one of these
-conditions holds:
-
-\newcommand{\oftype}{\!:\!}
-
-\begin{itemize}
-\item $D$ is a user-class, then the type of $f$ must have the form
- $forall~ (x_1 \oftype A_1)..(x_n \oftype A_n)(y\oftype C~x_1..x_n), D~u_1..u_m$ where $m$
- is the number of parameters of $D$.
-\item $D$ is {\tt Funclass}, then the type of $f$ must have the form
- $forall~ (x_1\oftype A_1)..(x_n\oftype A_n)(y\oftype C~x_1..x_n)(x:A), B$.
-\item $D$ is {\tt Sortclass}, then the type of $f$ must have the form
- $forall~ (x_1\oftype A_1)..(x_n\oftype A_n)(y\oftype C~x_1..x_n), s$ with $s$ a sort.
-\end{itemize}
-
-We then write $f:C \mbox{\texttt{>->}} D$. The restriction on the type
-of coercions is called {\em the uniform inheritance condition}.
-Remark: the abstract class {\tt Sortclass} can be used as source class,
-but the abstract class {\tt Funclass} cannot.
-
-To coerce an object $t:C~t_1..t_n$ of $C$ towards $D$, we have to
-apply the coercion $f$ to it; the obtained term $f~t_1..t_n~t$ is
-then an object of $D$.
-
-\asection{Identity Coercions}
-\index{Coercions!identity}
-
- Identity coercions are special cases of coercions used to go around
-the uniform inheritance condition. Let $C$ and $D$ be two classes
-with respectively $n$ and $m$ parameters and
-$f:forall~(x_1:T_1)..(x_k:T_k)(y:C~u_1..u_n), D~v_1..v_m$ a function which
-does not verify the uniform inheritance condition. To declare $f$ as
-coercion, one has first to declare a subclass $C'$ of $C$:
-
-$$C' := fun~ (x_1:T_1)..(x_k:T_k) => C~u_1..u_n$$
-
-\noindent We then define an {\em identity coercion} between $C'$ and $C$:
-\begin{eqnarray*}
-Id\_C'\_C & := & fun~ (x_1:T_1)..(x_k:T_k)(y:C'~x_1..x_k) => (y:C~u_1..u_n)\\
-\end{eqnarray*}
-
-We can now declare $f$ as coercion from $C'$ to $D$, since we can
-``cast'' its type as
-$forall~ (x_1:T_1)..(x_k:T_k)(y:C'~x_1..x_k),D~v_1..v_m$.\\ The identity
-coercions have a special status: to coerce an object $t:C'~t_1..t_k$
-of $C'$ towards $C$, we does not have to insert explicitly $Id\_C'\_C$
-since $Id\_C'\_C~t_1..t_k~t$ is convertible with $t$. However we
-``rewrite'' the type of $t$ to become an object of $C$; in this case,
-it becomes $C~u_1^*..u_k^*$ where each $u_i^*$ is the result of the
-substitution in $u_i$ of the variables $x_j$ by $t_j$.
-
-
-\asection{Inheritance Graph}
-\index{Coercions!inheritance graph}
-Coercions form an inheritance graph with classes as nodes. We call
-{\em coercion path} an ordered list of coercions between two nodes of
-the graph. A class $C$ is said to be a subclass of $D$ if there is a
-coercion path in the graph from $C$ to $D$; we also say that $C$
-inherits from $D$. Our mechanism supports multiple inheritance since a
-class may inherit from several classes, contrary to simple inheritance
-where a class inherits from at most one class. However there must be
-at most one path between two classes. If this is not the case, only
-the {\em oldest} one is valid and the others are ignored. So the order
-of declaration of coercions is important.
-
-We extend notations for coercions to coercion paths. For instance
-$[f_1;..;f_k]:C \mbox{\texttt{>->}} D$ is the coercion path composed
-by the coercions $f_1..f_k$. The application of a coercion path to a
-term consists of the successive application of its coercions.
-
-\asection{Declaration of Coercions}
-
-%%%%% "Class" is useless, since classes are implicitely defined via coercions.
-
-% \asubsection{\tt Class {\qualid}.}\comindex{Class}
-% Declares {\qualid} as a new class.
-
-% \begin{ErrMsgs}
-% \item {\qualid} \errindex{not declared}
-% \item {\qualid} \errindex{is already a class}
-% \item \errindex{Type of {\qualid} does not end with a sort}
-% \end{ErrMsgs}
-
-% \begin{Variant}
-% \item {\tt Class Local {\qualid}.} \\
-% Declares the construction denoted by {\qualid} as a new local class to
-% the current section.
-% \end{Variant}
-
-% END "Class" is useless
-
-\asubsection{\tt Coercion {\qualid} : {\class$_1$} >-> {\class$_2$}.}
-\comindex{Coercion}
-
-Declares the construction denoted by {\qualid} as a coercion between
-{\class$_1$} and {\class$_2$}.
-
-% Useless information
-% The classes {\class$_1$} and {\class$_2$} are first declared if necessary.
-
-\begin{ErrMsgs}
-\item {\qualid} \errindex{not declared}
-\item {\qualid} \errindex{is already a coercion}
-\item \errindex{Funclass cannot be a source class}
-\item {\qualid} \errindex{is not a function}
-\item \errindex{Cannot find the source class of {\qualid}}
-\item \errindex{Cannot recognize {\class$_1$} as a source class of {\qualid}}
-\item {\qualid} \errindex{does not respect the uniform inheritance condition}
-\item \errindex{Found target class {\class} instead of {\class$_2$}}
-
-\end{ErrMsgs}
-
-When the coercion {\qualid} is added to the inheritance graph, non
-valid coercion paths are ignored; they are signaled by a warning.
-\\[0.3cm]
-\noindent {\bf Warning :}
-\begin{enumerate}
-\item \begin{tabbing}
-{\tt Ambiguous paths: }\= $[f_1^1;..;f_{n_1}^1] : C_1\mbox{\tt >->}D_1$\\
- \> {\ldots} \\
- \>$[f_1^m;..;f_{n_m}^m] : C_m\mbox{\tt >->}D_m$
- \end{tabbing}
-\end{enumerate}
-
-\begin{Variants}
-\item {\tt Local Coercion {\qualid} : {\class$_1$} >-> {\class$_2$}.}
-\comindex{Local Coercion}\\
- Declares the construction denoted by {\qualid} as a coercion local to
- the current section.
-
-\item {\tt Coercion {\ident} := {\term}}\comindex{Coercion}\\
- This defines {\ident} just like \texttt{Definition {\ident} :=
- {\term}}, and then declares {\ident} as a coercion between it
- source and its target.
-
-\item {\tt Coercion {\ident} := {\term} : {\type}}\\
- This defines {\ident} just like
- \texttt{Definition {\ident} : {\type} := {\term}}, and then
- declares {\ident} as a coercion between it source and its target.
-
-\item {\tt Local Coercion {\ident} := {\term}}\comindex{Local Coercion}\\
- This defines {\ident} just like \texttt{Let {\ident} :=
- {\term}}, and then declares {\ident} as a coercion between it
- source and its target.
-
-\item Assumptions can be declared as coercions at declaration
-time. This extends the grammar of assumptions from
-Figure~\ref{sentences-syntax} as follows:
-\comindex{Variable \mbox{\rm (and coercions)}}
-\comindex{Axiom \mbox{\rm (and coercions)}}
-\comindex{Parameter \mbox{\rm (and coercions)}}
-\comindex{Hypothesis \mbox{\rm (and coercions)}}
-
-\begin{tabular}{lcl}
-%% Declarations
-{\assumption} & ::= & {\assumptionkeyword} {\assums} {\tt .} \\
-&&\\
-{\assums} & ::= & {\simpleassums} \\
- & $|$ & \nelist{{\tt (} \simpleassums {\tt )}}{} \\
-&&\\
-{\simpleassums} & ::= & \nelist{\ident}{} {\tt :}\zeroone{{\tt >}} {\term}\\
-\end{tabular}
-
-If the extra {\tt >} is present before the type of some assumptions, these
-assumptions are declared as coercions.
-
-\item Constructors of inductive types can be declared as coercions at
-definition time of the inductive type. This extends and modifies the
-grammar of inductive types from Figure \ref{sentences-syntax} as follows:
-\comindex{Inductive \mbox{\rm (and coercions)}}
-\comindex{CoInductive \mbox{\rm (and coercions)}}
-
-\begin{center}
-\begin{tabular}{lcl}
-%% Inductives
-{\inductive} & ::= &
- {\tt Inductive} \nelist{\inductivebody}{with} {\tt .} \\
- & $|$ & {\tt CoInductive} \nelist{\inductivebody}{with} {\tt .} \\
- & & \\
-{\inductivebody} & ::= &
- {\ident} \zeroone{\binders} {\tt :} {\term} {\tt :=} \\
- && ~~~\zeroone{\zeroone{\tt |} \nelist{\constructor}{|}} \\
- & & \\
-{\constructor} & ::= & {\ident} \zeroone{\binders} \zeroone{{\tt :}\zeroone{\tt >} {\term}} \\
-\end{tabular}
-\end{center}
-
-Especially, if the extra {\tt >} is present in a constructor
-declaration, this constructor is declared as a coercion.
-\end{Variants}
-
-\asubsection{\tt Identity Coercion {\ident}:{\class$_1$} >-> {\class$_2$}.}
-\comindex{Identity Coercion}
-
-We check that {\class$_1$} is a constant with a value of the form
-$fun~ (x_1:T_1)..(x_n:T_n) => (\mbox{\class}_2~t_1..t_m)$ where $m$ is the
-number of parameters of \class$_2$. Then we define an identity
-function with the type
-$forall~ (x_1:T_1)..(x_n:T_n)(y:\mbox{\class}_1~x_1..x_n),
-{\mbox{\class}_2}~t_1..t_m$, and we declare it as an identity
-coercion between {\class$_1$} and {\class$_2$}.
-
-\begin{ErrMsgs}
-\item {\class$_1$} \errindex{must be a transparent constant}
-\end{ErrMsgs}
-
-\begin{Variants}
-\item {\tt Local Identity Coercion {\ident}:{\ident$_1$} >-> {\ident$_2$}.} \\
-Idem but locally to the current section.
-
-\item {\tt SubClass {\ident} := {\type}.} \\
-\comindex{SubClass}
- If {\type} is a class
-{\ident'} applied to some arguments then {\ident} is defined and an
-identity coercion of name {\tt Id\_{\ident}\_{\ident'}} is
-declared. Otherwise said, this is an abbreviation for
-
-{\tt Definition {\ident} := {\type}.}
-
- followed by
-
-{\tt Identity Coercion Id\_{\ident}\_{\ident'}:{\ident} >-> {\ident'}}.
-
-\item {\tt Local SubClass {\ident} := {\type}.} \\
-Same as before but locally to the current section.
-
-\end{Variants}
-
-\asection{Displaying Available Coercions}
-
-\asubsection{\tt Print Classes.}
-\comindex{Print Classes}
-Print the list of declared classes in the current context.
-
-\asubsection{\tt Print Coercions.}
-\comindex{Print Coercions}
-Print the list of declared coercions in the current context.
-
-\asubsection{\tt Print Graph.}
-\comindex{Print Graph}
-Print the list of valid coercion paths in the current context.
-
-\asubsection{\tt Print Coercion Paths {\class$_1$} {\class$_2$}.}
-\comindex{Print Coercion Paths}
-Print the list of valid coercion paths from {\class$_1$} to {\class$_2$}.
-
-\asection{Activating the Printing of Coercions}
-
-\asubsection{\tt Set Printing Coercions.}
-\optindex{Printing Coercions}
-
-This command forces all the coercions to be printed.
-Conversely, to skip the printing of coercions, use
- {\tt Unset Printing Coercions}.
-By default, coercions are not printed.
-
-\asubsection{\tt Add Printing Coercion {\qualid}.}
-\comindex{Add Printing Coercion}
-\comindex{Remove Printing Coercion}
-
-This command forces coercion denoted by {\qualid} to be printed.
-To skip the printing of coercion {\qualid}, use
- {\tt Remove Printing Coercion {\qualid}}.
-By default, a coercion is never printed.
-
-\asection{Classes as Records}
-\label{Coercions-and-records}
-\index{Coercions!and records}
-We allow the definition of {\em Structures with Inheritance} (or
-classes as records) by extending the existing {\tt Record} macro
-(see Section~\ref{Record}). Its new syntax is:
-
-\begin{center}
-\begin{tabular}{l}
-{\tt Record \zeroone{>}~{\ident} \zeroone{\binders} : {\sort} := \zeroone{\ident$_0$} \verb+{+} \\
-~~~~\begin{tabular}{l}
- {\tt \ident$_1$ $[$:$|$:>$]$ \term$_1$ ;} \\
- ... \\
- {\tt \ident$_n$ $[$:$|$:>$]$ \term$_n$ \verb+}+. }
- \end{tabular}
-\end{tabular}
-\end{center}
-The identifier {\ident} is the name of the defined record and {\sort}
-is its type. The identifier {\ident$_0$} is the name of its
-constructor. The identifiers {\ident$_1$}, .., {\ident$_n$} are the
-names of its fields and {\term$_1$}, .., {\term$_n$} their respective
-types. The alternative {\tt $[$:$|$:>$]$} is ``{\tt :}'' or ``{\tt
-:>}''. If {\tt {\ident$_i$}:>{\term$_i$}}, then {\ident$_i$} is
-automatically declared as coercion from {\ident} to the class of
-{\term$_i$}. Remark that {\ident$_i$} always verifies the uniform
-inheritance condition. If the optional ``{\tt >}'' before {\ident} is
-present, then {\ident$_0$} (or the default name {\tt Build\_{\ident}}
-if {\ident$_0$} is omitted) is automatically declared as a coercion
-from the class of {\term$_n$} to {\ident} (this may fail if the
-uniform inheritance condition is not satisfied).
-
-\Rem The keyword {\tt Structure}\comindex{Structure} is a synonym of {\tt
-Record}.
-
-\asection{Coercions and Sections}
-\index{Coercions!and sections}
- The inheritance mechanism is compatible with the section
-mechanism. The global classes and coercions defined inside a section
-are redefined after its closing, using their new value and new
-type. The classes and coercions which are local to the section are
-simply forgotten.
-Coercions with a local source class or a local target class, and
-coercions which do not verify the uniform inheritance condition any longer
-are also forgotten.
-
-\asection{Coercions and Modules}
-\index{Coercions!and modules}
-
-From Coq version 8.3, the coercions present in a module are activated
-only when the module is explicitly imported. Formerly, the coercions
-were activated as soon as the module was required, whatever it was
-imported or not.
-
-To recover the behavior of the versions of Coq prior to 8.3, use the
-following command:
-
-\optindex{Automatic Coercions Import}
-\begin{verbatim}
-Set Automatic Coercions Import.
-\end{verbatim}
-
-To cancel the effect of the option, use instead:
-
-\begin{verbatim}
-Unset Automatic Coercions Import.
-\end{verbatim}
-
-\asection{Examples}
-
- There are three situations:
-
-\begin{itemize}
-\item $f~a$ is ill-typed where $f:forall~x:A,B$ and $a:A'$. If there is a
- coercion path between $A'$ and $A$, $f~a$ is transformed into
- $f~a'$ where $a'$ is the result of the application of this
- coercion path to $a$.
-
-We first give an example of coercion between atomic inductive types
-
-%\begin{\small}
-\begin{coq_example}
-Definition bool_in_nat (b:bool) := if b then 0 else 1.
-Coercion bool_in_nat : bool >-> nat.
-Check (0 = true).
-Set Printing Coercions.
-Check (0 = true).
-\end{coq_example}
-%\end{small}
-
-\begin{coq_eval}
-Unset Printing Coercions.
-\end{coq_eval}
-
-\Warning ``\verb|Check true=O.|'' fails. This is ``normal'' behaviour of
-coercions. To validate \verb|true=O|, the coercion is searched from
-\verb=nat= to \verb=bool=. There is none.
-
-We give an example of coercion between classes with parameters.
-
-%\begin{\small}
-\begin{coq_example}
-Parameters
- (C : nat -> Set) (D : nat -> bool -> Set) (E : bool -> Set).
-Parameter f : forall n:nat, C n -> D (S n) true.
-Coercion f : C >-> D.
-Parameter g : forall (n:nat) (b:bool), D n b -> E b.
-Coercion g : D >-> E.
-Parameter c : C 0.
-Parameter T : E true -> nat.
-Check (T c).
-Set Printing Coercions.
-Check (T c).
-\end{coq_example}
-%\end{small}
-
-\begin{coq_eval}
-Unset Printing Coercions.
-\end{coq_eval}
-
-We give now an example using identity coercions.
-
-%\begin{small}
-\begin{coq_example}
-Definition D' (b:bool) := D 1 b.
-Identity Coercion IdD'D : D' >-> D.
-Print IdD'D.
-Parameter d' : D' true.
-Check (T d').
-Set Printing Coercions.
-Check (T d').
-\end{coq_example}
-%\end{small}
-
-\begin{coq_eval}
-Unset Printing Coercions.
-\end{coq_eval}
-
-
- In the case of functional arguments, we use the monotonic rule of
-sub-typing. Approximatively, to coerce $t:forall~x:A, B$ towards
-$forall~x:A',B'$, one have to coerce $A'$ towards $A$ and $B$ towards
-$B'$. An example is given below:
-
-%\begin{small}
-\begin{coq_example}
-Parameters (A B : Set) (h : A -> B).
-Coercion h : A >-> B.
-Parameter U : (A -> E true) -> nat.
-Parameter t : B -> C 0.
-Check (U t).
-Set Printing Coercions.
-Check (U t).
-\end{coq_example}
-%\end{small}
-
-\begin{coq_eval}
-Unset Printing Coercions.
-\end{coq_eval}
-
- Remark the changes in the result following the modification of the
-previous example.
-
-%\begin{small}
-\begin{coq_example}
-Parameter U' : (C 0 -> B) -> nat.
-Parameter t' : E true -> A.
-Check (U' t').
-Set Printing Coercions.
-Check (U' t').
-\end{coq_example}
-%\end{small}
-
-\begin{coq_eval}
-Unset Printing Coercions.
-\end{coq_eval}
-
-\item An assumption $x:A$ when $A$ is not a type, is ill-typed. It is
- replaced by $x:A'$ where $A'$ is the result of the application
- to $A$ of the coercion path between the class of $A$ and {\tt
- Sortclass} if it exists. This case occurs in the abstraction
- $fun~ x:A => t$, universal quantification $forall~x:A, B$,
- global variables and parameters of (co-)inductive definitions
- and functions. In $forall~x:A, B$, such a coercion path may be
- applied to $B$ also if necessary.
-
-%\begin{small}
-\begin{coq_example}
-Parameter Graph : Type.
-Parameter Node : Graph -> Type.
-Coercion Node : Graph >-> Sortclass.
-Parameter G : Graph.
-Parameter Arrows : G -> G -> Type.
-Check Arrows.
-Parameter fg : G -> G.
-Check fg.
-Set Printing Coercions.
-Check fg.
-\end{coq_example}
-%\end{small}
-
-\begin{coq_eval}
-Unset Printing Coercions.
-\end{coq_eval}
-
-\item $f~a$ is ill-typed because $f:A$ is not a function. The term
- $f$ is replaced by the term obtained by applying to $f$ the
- coercion path between $A$ and {\tt Funclass} if it exists.
-
-%\begin{small}
-\begin{coq_example}
-Parameter bij : Set -> Set -> Set.
-Parameter ap : forall A B:Set, bij A B -> A -> B.
-Coercion ap : bij >-> Funclass.
-Parameter b : bij nat nat.
-Check (b 0).
-Set Printing Coercions.
-Check (b 0).
-\end{coq_example}
-%\end{small}
-
-\begin{coq_eval}
-Unset Printing Coercions.
-\end{coq_eval}
-
-Let us see the resulting graph of this session.
-
-%\begin{small}
-\begin{coq_example}
-Print Graph.
-\end{coq_example}
-%\end{small}
-
-\end{itemize}
-
-
-%%% Local Variables:
-%%% mode: latex
-%%% TeX-master: "Reference-Manual"
-%%% End:
diff --git a/doc/refman/Extraction.tex b/doc/refman/Extraction.tex
deleted file mode 100644
index cff7be3e9..000000000
--- a/doc/refman/Extraction.tex
+++ /dev/null
@@ -1,620 +0,0 @@
-\achapter{Extraction of programs in OCaml and Haskell}
-%HEVEA\cutname{extraction.html}
-\label{Extraction}
-\aauthor{Jean-Christophe Filliâtre and Pierre Letouzey}
-\index{Extraction}
-
-\noindent We present here the \Coq\ extraction commands, used to build certified
-and relatively efficient functional programs, extracting them from
-either \Coq\ functions or \Coq\ proofs of specifications. The
-functional languages available as output are currently \ocaml{},
-\textsc{Haskell} and \textsc{Scheme}. In the following, ``ML'' will
-be used (abusively) to refer to any of the three.
-
-%% \paragraph{Differences with old versions.}
-%% The current extraction mechanism is new for version 7.0 of {\Coq}.
-%% In particular, the \FW\ toplevel used as an intermediate step between
-%% \Coq\ and ML has been withdrawn. It is also not possible
-%% any more to import ML objects in this \FW\ toplevel.
-%% The current mechanism also differs from
-%% the one in previous versions of \Coq: there is no more
-%% an explicit toplevel for the language (formerly called \textsc{Fml}).
-
-Before using any of the commands or options described in this chapter,
-the extraction framework should first be loaded explicitly
-via {\tt Require Extraction}, or via the more robust
-{\tt From Coq Require Extraction}.
-Note that in earlier versions of Coq, these commands and options were
-directly available without any preliminary {\tt Require}.
-
-\begin{coq_example}
-Require Extraction.
-\end{coq_example}
-
-\asection{Generating ML code}
-\comindex{Extraction}
-\comindex{Recursive Extraction}
-\comindex{Separate Extraction}
-\comindex{Extraction Library}
-\comindex{Recursive Extraction Library}
-
-The next two commands are meant to be used for rapid preview of
-extraction. They both display extracted term(s) inside \Coq.
-
-\begin{description}
-\item {\tt Extraction \qualid{}.} ~\par
- Extraction of a constant or module in the \Coq\ toplevel.
-
-\item {\tt Recursive Extraction} \qualid$_1$ \dots\ \qualid$_n$. ~\par
- Recursive extraction of all the globals (or modules) \qualid$_1$ \dots\
- \qualid$_n$ and all their dependencies in the \Coq\ toplevel.
-\end{description}
-
-%% TODO error messages
-
-\noindent All the following commands produce real ML files. User can choose to produce
-one monolithic file or one file per \Coq\ library.
-
-\begin{description}
-\item {\tt Extraction "{\em file}"}
- \qualid$_1$ \dots\ \qualid$_n$. ~\par
- Recursive extraction of all the globals (or modules) \qualid$_1$ \dots\
- \qualid$_n$ and all their dependencies in one monolithic file {\em file}.
- Global and local identifiers are renamed according to the chosen ML
- language to fulfill its syntactic conventions, keeping original
- names as much as possible.
-
-\item {\tt Extraction Library} \ident. ~\par
- Extraction of the whole \Coq\ library {\tt\ident.v} to an ML module
- {\tt\ident.ml}. In case of name clash, identifiers are here renamed
- using prefixes \verb!coq_! or \verb!Coq_! to ensure a
- session-independent renaming.
-
-\item {\tt Recursive Extraction Library} \ident. ~\par
- Extraction of the \Coq\ library {\tt\ident.v} and all other modules
- {\tt\ident.v} depends on.
-
-\item {\tt Separate Extraction}
- \qualid$_1$ \dots\ \qualid$_n$. ~\par
- Recursive extraction of all the globals (or modules) \qualid$_1$ \dots\
- \qualid$_n$ and all their dependencies, just as {\tt
- Extraction "{\em file}"}, but instead of producing one monolithic
- file, this command splits the produced code in separate ML files, one per
- corresponding Coq {\tt .v} file. This command is hence quite similar
- to {\tt Recursive Extraction Library}, except that only the needed
- parts of Coq libraries are extracted instead of the whole. The
- naming convention in case of name clash is the same one as
- {\tt Extraction Library}: identifiers are here renamed
- using prefixes \verb!coq_! or \verb!Coq_!.
-\end{description}
-
-\noindent The following command is meant to help automatic testing of
- the extraction, see for instance the {\tt test-suite} directory
- in the \Coq\ sources.
-
-\begin{description}
-\item {\tt Extraction TestCompile} \qualid$_1$ \dots\ \qualid$_n$. ~\par
- All the globals (or modules) \qualid$_1$ \dots\ \qualid$_n$ and all
- their dependencies are extracted to a temporary {\ocaml} file, just as in
- {\tt Extraction "{\em file}"}. Then this temporary file and its
- signature are compiled with the same {\ocaml} compiler used to built
- \Coq. This command succeeds only if the extraction and the {\ocaml}
- compilation succeed (and it fails if the current target language
- of the extraction is not {\ocaml}).
-\end{description}
-
-\asection{Extraction options}
-
-\asubsection{Setting the target language}
-\comindex{Extraction Language}
-
-The ability to fix target language is the first and more important
-of the extraction options. Default is {\ocaml}.
-\begin{description}
-\item {\tt Extraction Language OCaml}.
-\item {\tt Extraction Language Haskell}.
-\item {\tt Extraction Language Scheme}.
-\end{description}
-
-\asubsection{Inlining and optimizations}
-
-Since {\ocaml} is a strict language, the extracted code has to
-be optimized in order to be efficient (for instance, when using
-induction principles we do not want to compute all the recursive calls
-but only the needed ones). So the extraction mechanism provides an
-automatic optimization routine that will be called each time the user
-want to generate {\ocaml} programs. The optimizations can be split in two
-groups: the type-preserving ones -- essentially constant inlining and
-reductions -- and the non type-preserving ones -- some function
-abstractions of dummy types are removed when it is deemed safe in order
-to have more elegant types. Therefore some constants may not appear in the
-resulting monolithic {\ocaml} program. In the case of modular extraction,
-even if some inlining is done, the inlined constant are nevertheless
-printed, to ensure session-independent programs.
-
-Concerning Haskell, type-preserving optimizations are less useful
-because of laziness. We still make some optimizations, for example in
-order to produce more readable code.
-
-The type-preserving optimizations are controlled by the following \Coq\ options:
-
-\begin{description}
-
-\item \optindex{Extraction Optimize} {\tt Unset Extraction Optimize.}
-
-Default is Set. This controls all type-preserving optimizations made on
-the ML terms (mostly reduction of dummy beta/iota redexes, but also
-simplifications on Cases, etc). Put this option to Unset if you want a
-ML term as close as possible to the Coq term.
-
-\item \optindex{Extraction Conservative Types}
-{\tt Set Extraction Conservative Types.}
-
-Default is Unset. This controls the non type-preserving optimizations
-made on ML terms (which try to avoid function abstraction of dummy
-types). Turn this option to Set to make sure that {\tt e:t}
-implies that {\tt e':t'} where {\tt e'} and {\tt t'} are the extracted
-code of {\tt e} and {\tt t} respectively.
-
-\item \optindex{Extraction KeepSingleton}
-{\tt Set Extraction KeepSingleton.}
-
-Default is Unset. Normally, when the extraction of an inductive type
-produces a singleton type (i.e. a type with only one constructor, and
-only one argument to this constructor), the inductive structure is
-removed and this type is seen as an alias to the inner type.
-The typical example is {\tt sig}. This option allows disabling this
-optimization when one wishes to preserve the inductive structure of types.
-
-\item \optindex{Extraction AutoInline} {\tt Unset Extraction AutoInline.}
-
-Default is Set. The extraction mechanism
-inlines the bodies of some defined constants, according to some heuristics
-like size of bodies, uselessness of some arguments, etc. Those heuristics are
-not always perfect; if you want to disable this feature, do it by Unset.
-
-\item \comindex{Extraction Inline} \comindex{Extraction NoInline}
-{\tt Extraction [Inline|NoInline] \qualid$_1$ \dots\ \qualid$_n$}.
-
-In addition to the automatic inline feature, you can tell to
-inline some more constants by the {\tt Extraction Inline} command. Conversely,
-you can forbid the automatic inlining of some specific constants by
-the {\tt Extraction NoInline} command.
-Those two commands enable a precise control of what is inlined and what is not.
-
-\item \comindex{Print Extraction Inline}
-{\tt Print Extraction Inline}.
-
-Prints the current state of the table recording the custom inlinings
-declared by the two previous commands.
-
-\item \comindex{Reset Extraction Inline}
-{\tt Reset Extraction Inline}.
-
-Puts the table recording the custom inlinings back to empty.
-
-\end{description}
-
-
-\paragraph{Inlining and printing of a constant declaration.}
-
-A user can explicitly ask for a constant to be extracted by two means:
-\begin{itemize}
-\item by mentioning it on the extraction command line
-\item by extracting the whole \Coq\ module of this constant.
-\end{itemize}
-In both cases, the declaration of this constant will be present in the
-produced file.
-But this same constant may or may not be inlined in the following
-terms, depending on the automatic/custom inlining mechanism.
-
-
-For the constants non-explicitly required but needed for dependency
-reasons, there are two cases:
-\begin{itemize}
-\item If an inlining decision is taken, whether automatically or not,
-all occurrences of this constant are replaced by its extracted body, and
-this constant is not declared in the generated file.
-\item If no inlining decision is taken, the constant is normally
- declared in the produced file.
-\end{itemize}
-
-\asubsection{Extra elimination of useless arguments}
-
-The following command provides some extra manual control on the
-code elimination performed during extraction, in a way which
-is independent but complementary to the main elimination
-principles of extraction (logical parts and types).
-
-\begin{description}
-\item \comindex{Extraction Implicit}
- {\tt Extraction Implicit} \qualid\ [ \ident$_1$ \dots\ \ident$_n$ ].
-
-This experimental command allows declaring some arguments of
-\qualid\ as implicit, i.e. useless in extracted code and hence to
-be removed by extraction. Here \qualid\ can be any function or
-inductive constructor, and \ident$_i$ are the names of the concerned
-arguments. In fact, an argument can also be referred by a number
-indicating its position, starting from 1.
-\end{description}
-
-\noindent When an actual extraction takes place, an error is normally raised if the
-{\tt Extraction Implicit}
-declarations cannot be honored, that is if any of the implicited
-variables still occurs in the final code. This behavior can be relaxed
-via the following option:
-
-\begin{description}
-\item \optindex{Extraction SafeImplicits} {\tt Unset Extraction SafeImplicits.}
-
-Default is Set. When this option is Unset, a warning is emitted
-instead of an error if some implicited variables still occur in the
-final code of an extraction. This way, the extracted code may be
-obtained nonetheless and reviewed manually to locate the source of the issue
-(in the code, some comments mark the location of these remaining
-implicited variables).
-Note that this extracted code might not compile or run properly,
-depending of the use of these remaining implicited variables.
-
-\end{description}
-
-\asubsection{Realizing axioms}\label{extraction:axioms}
-
-Extraction will fail if it encounters an informative
-axiom not realized (see Section~\ref{extraction:axioms}).
-A warning will be issued if it encounters a logical axiom, to remind the
-user that inconsistent logical axioms may lead to incorrect or
-non-terminating extracted terms.
-
-It is possible to assume some axioms while developing a proof. Since
-these axioms can be any kind of proposition or object or type, they may
-perfectly well have some computational content. But a program must be
-a closed term, and of course the system cannot guess the program which
-realizes an axiom. Therefore, it is possible to tell the system
-what ML term corresponds to a given axiom.
-
-\comindex{Extract Constant}
-\begin{description}
-\item{\tt Extract Constant \qualid\ => \str.} ~\par
- Give an ML extraction for the given constant.
- The \str\ may be an identifier or a quoted string.
-\item{\tt Extract Inlined Constant \qualid\ => \str.} ~\par
- Same as the previous one, except that the given ML terms will
- be inlined everywhere instead of being declared via a let.
-\end{description}
-
-\noindent Note that the {\tt Extract Inlined Constant} command is sugar
-for an {\tt Extract Constant} followed by a {\tt Extraction Inline}.
-Hence a {\tt Reset Extraction Inline} will have an effect on the
-realized and inlined axiom.
-
-Of course, it is the responsibility of the user to ensure that the ML
-terms given to realize the axioms do have the expected types. In
-fact, the strings containing realizing code are just copied to the
-extracted files. The extraction recognizes whether the realized axiom
-should become a ML type constant or a ML object declaration.
-
-\Example
-\begin{coq_example*}
-Axiom X:Set.
-Axiom x:X.
-Extract Constant X => "int".
-Extract Constant x => "0".
-\end{coq_example*}
-
-\noindent Notice that in the case of type scheme axiom (i.e. whose type is an
-arity, that is a sequence of product finished by a sort), then some type
-variables have to be given. The syntax is then:
-
-\begin{description}
-\item{\tt Extract Constant \qualid\ \str$_1$ \dots\ \str$_n$ => \str.}
-\end{description}
-
-\noindent The number of type variables is checked by the system.
-
-\Example
-\begin{coq_example*}
-Axiom Y : Set -> Set -> Set.
-Extract Constant Y "'a" "'b" => " 'a*'b ".
-\end{coq_example*}
-
-\noindent Realizing an axiom via {\tt Extract Constant} is only useful in the
-case of an informative axiom (of sort Type or Set). A logical axiom
-have no computational content and hence will not appears in extracted
-terms. But a warning is nonetheless issued if extraction encounters a
-logical axiom. This warning reminds user that inconsistent logical
-axioms may lead to incorrect or non-terminating extracted terms.
-
-If an informative axiom has not been realized before an extraction, a
-warning is also issued and the definition of the axiom is filled with
-an exception labeled {\tt AXIOM TO BE REALIZED}. The user must then
-search these exceptions inside the extracted file and replace them by
-real code.
-
-\comindex{Extract Inductive}
-
-The system also provides a mechanism to specify ML terms for inductive
-types and constructors. For instance, the user may want to use the ML
-native boolean type instead of \Coq\ one. The syntax is the following:
-
-\begin{description}
-\item{\tt Extract Inductive \qualid\ => \str\ [ \str\ \dots\ \str\ ] {\it optstring}.}\par
- Give an ML extraction for the given inductive type. You must specify
- extractions for the type itself (first \str) and all its
- constructors (between square brackets). If given, the final optional
- string should contain a function emulating pattern-matching over this
- inductive type. If this optional string is not given, the ML
- extraction must be an ML inductive datatype, and the native
- pattern-matching of the language will be used.
-\end{description}
-
-\noindent For an inductive type with $k$ constructor, the function used to
-emulate the match should expect $(k+1)$ arguments, first the $k$
-branches in functional form, and then the inductive element to
-destruct. For instance, the match branch \verb$| S n => foo$ gives the
-functional form \verb$(fun n -> foo)$. Note that a constructor with no
-argument is considered to have one unit argument, in order to block
-early evaluation of the branch: \verb$| O => bar$ leads to the functional
-form \verb$(fun () -> bar)$. For instance, when extracting {\tt nat}
-into {\tt int}, the code to provide has type:
-{\tt (unit->'a)->(int->'a)->int->'a}.
-
-As for {\tt Extract Inductive}, this command should be used with care:
-\begin{itemize}
-\item The ML code provided by the user is currently \emph{not} checked at all by
- extraction, even for syntax errors.
-
-\item Extracting an inductive type to a pre-existing ML inductive type
-is quite sound. But extracting to a general type (by providing an
-ad-hoc pattern-matching) will often \emph{not} be fully rigorously
-correct. For instance, when extracting {\tt nat} to {\ocaml}'s {\tt
-int}, it is theoretically possible to build {\tt nat} values that are
-larger than {\ocaml}'s {\tt max\_int}. It is the user's responsibility to
-be sure that no overflow or other bad events occur in practice.
-
-\item Translating an inductive type to an ML type does \emph{not}
-magically improve the asymptotic complexity of functions, even if the
-ML type is an efficient representation. For instance, when extracting
-{\tt nat} to {\ocaml}'s {\tt int}, the function {\tt mult} stays
-quadratic. It might be interesting to associate this translation with
-some specific {\tt Extract Constant} when primitive counterparts exist.
-\end{itemize}
-
-\Example
-Typical examples are the following:
-\begin{coq_eval}
-Require Extraction.
-\end{coq_eval}
-\begin{coq_example}
-Extract Inductive unit => "unit" [ "()" ].
-Extract Inductive bool => "bool" [ "true" "false" ].
-Extract Inductive sumbool => "bool" [ "true" "false" ].
-\end{coq_example}
-
-\noindent When extracting to {\ocaml}, if an inductive constructor or type
-has arity 2 and the corresponding string is enclosed by parentheses,
-and the string meets {\ocaml}'s lexical criteria for an infix symbol,
-then the rest of the string is used as infix constructor or type.
-
-\begin{coq_example}
-Extract Inductive list => "list" [ "[]" "(::)" ].
-Extract Inductive prod => "(*)" [ "(,)" ].
-\end{coq_example}
-
-\noindent As an example of translation to a non-inductive datatype, let's turn
-{\tt nat} into {\ocaml}'s {\tt int} (see caveat above):
-\begin{coq_example}
-Extract Inductive nat => int [ "0" "succ" ]
- "(fun fO fS n -> if n=0 then fO () else fS (n-1))".
-\end{coq_example}
-
-\asubsection{Avoiding conflicts with existing filenames}
-
-\comindex{Extraction Blacklist}
-
-When using {\tt Extraction Library}, the names of the extracted files
-directly depends from the names of the \Coq\ files. It may happen that
-these filenames are in conflict with already existing files,
-either in the standard library of the target language or in other
-code that is meant to be linked with the extracted code.
-For instance the module {\tt List} exists both in \Coq\ and in {\ocaml}.
-It is possible to instruct the extraction not to use particular filenames.
-
-\begin{description}
-\item{\tt Extraction Blacklist} \ident\ \dots\ \ident. ~\par
- Instruct the extraction to avoid using these names as filenames
- for extracted code.
-\item{\tt Print Extraction Blacklist.} ~\par
- Show the current list of filenames the extraction should avoid.
-\item{\tt Reset Extraction Blacklist.} ~\par
- Allow the extraction to use any filename.
-\end{description}
-
-\noindent For {\ocaml}, a typical use of these commands is
-{\tt Extraction Blacklist String List}.
-
-\asection{Differences between \Coq\ and ML type systems}
-
-
-Due to differences between \Coq\ and ML type systems,
-some extracted programs are not directly typable in ML.
-We now solve this problem (at least in {\ocaml}) by adding
-when needed some unsafe casting {\tt Obj.magic}, which give
-a generic type {\tt 'a} to any term.
-
-For example, here are two kinds of problem that can occur:
-
-\begin{itemize}
- \item If some part of the program is {\em very} polymorphic, there
- may be no ML type for it. In that case the extraction to ML works
- alright but the generated code may be refused by the ML
- type-checker. A very well known example is the {\em distr-pair}
- function:
-\begin{verbatim}
-Definition dp :=
- fun (A B:Set)(x:A)(y:B)(f:forall C:Set, C->C) => (f A x, f B y).
-\end{verbatim}
-
-In {\ocaml}, for instance, the direct extracted term would be
-\begin{verbatim}
-let dp x y f = Pair((f () x),(f () y))
-\end{verbatim}
-
-and would have type
-\begin{verbatim}
-dp : 'a -> 'a -> (unit -> 'a -> 'b) -> ('b,'b) prod
-\end{verbatim}
-
-which is not its original type, but a restriction.
-
-We now produce the following correct version:
-\begin{verbatim}
-let dp x y f = Pair ((Obj.magic f () x), (Obj.magic f () y))
-\end{verbatim}
-
- \item Some definitions of \Coq\ may have no counterpart in ML. This
- happens when there is a quantification over types inside the type
- of a constructor; for example:
-\begin{verbatim}
-Inductive anything : Type := dummy : forall A:Set, A -> anything.
-\end{verbatim}
-
-which corresponds to the definition of an ML dynamic type.
-In {\ocaml}, we must cast any argument of the constructor dummy.
-
-\end{itemize}
-
-\noindent Even with those unsafe castings, you should never get error like
-``segmentation fault''. In fact even if your program may seem
-ill-typed to the {\ocaml} type-checker, it can't go wrong: it comes
-from a Coq well-typed terms, so for example inductives will always
-have the correct number of arguments, etc.
-
-More details about the correctness of the extracted programs can be
-found in \cite{Let02}.
-
-We have to say, though, that in most ``realistic'' programs, these
-problems do not occur. For example all the programs of Coq library are
-accepted by Caml type-checker without any {\tt Obj.magic} (see examples below).
-
-
-
-\asection{Some examples}
-
-We present here two examples of extractions, taken from the
-\Coq\ Standard Library. We choose \ocaml\ as target language,
-but all can be done in the other dialects with slight modifications.
-We then indicate where to find other examples and tests of Extraction.
-
-\asubsection{A detailed example: Euclidean division}
-
-The file {\tt Euclid} contains the proof of Euclidean division
-(theorem {\tt eucl\_dev}). The natural numbers defined in the example
-files are unary integers defined by two constructors $O$ and $S$:
-\begin{coq_example*}
-Inductive nat : Set :=
- | O : nat
- | S : nat -> nat.
-\end{coq_example*}
-
-\noindent This module contains a theorem {\tt eucl\_dev}, whose type is
-\begin{verbatim}
-forall b:nat, b > 0 -> forall a:nat, diveucl a b
-\end{verbatim}
-where {\tt diveucl} is a type for the pair of the quotient and the
-modulo, plus some logical assertions that disappear during extraction.
-We can now extract this program to \ocaml:
-
-\begin{coq_eval}
-Reset Initial.
-\end{coq_eval}
-\begin{coq_example}
-Require Extraction.
-Require Import Euclid Wf_nat.
-Extraction Inline gt_wf_rec lt_wf_rec induction_ltof2.
-Recursive Extraction eucl_dev.
-\end{coq_example}
-
-\noindent The inlining of {\tt gt\_wf\_rec} and others is not
-mandatory. It only enhances readability of extracted code.
-You can then copy-paste the output to a file {\tt euclid.ml} or let
-\Coq\ do it for you with the following command:
-
-\begin{verbatim}
-Extraction "euclid" eucl_dev.
-\end{verbatim}
-
-\noindent Let us play the resulting program:
-
-\begin{verbatim}
-# #use "euclid.ml";;
-type nat = O | S of nat
-type sumbool = Left | Right
-val minus : nat -> nat -> nat = <fun>
-val le_lt_dec : nat -> nat -> sumbool = <fun>
-val le_gt_dec : nat -> nat -> sumbool = <fun>
-type diveucl = Divex of nat * nat
-val eucl_dev : nat -> nat -> diveucl = <fun>
-# eucl_dev (S (S O)) (S (S (S (S (S O)))));;
-- : diveucl = Divex (S (S O), S O)
-\end{verbatim}
-It is easier to test on \ocaml\ integers:
-\begin{verbatim}
-# let rec nat_of_int = function 0 -> O | n -> S (nat_of_int (n-1));;
-val nat_of_int : int -> nat = <fun>
-# let rec int_of_nat = function O -> 0 | S p -> 1+(int_of_nat p);;
-val int_of_nat : nat -> int = <fun>
-# let div a b =
- let Divex (q,r) = eucl_dev (nat_of_int b) (nat_of_int a)
- in (int_of_nat q, int_of_nat r);;
-val div : int -> int -> int * int = <fun>
-# div 173 15;;
-- : int * int = (11, 8)
-\end{verbatim}
-
-\noindent Note that these {\tt nat\_of\_int} and {\tt int\_of\_nat} are now
-available via a mere {\tt Require Import ExtrOcamlIntConv} and then
-adding these functions to the list of functions to extract. This file
-{\tt ExtrOcamlIntConv.v} and some others in {\tt plugins/extraction/}
-are meant to help building concrete program via extraction.
-
-\asubsection{Extraction's horror museum}
-
-Some pathological examples of extraction are grouped in the file\\
-{\tt test-suite/success/extraction.v} of the sources of \Coq.
-
-\asubsection{Users' Contributions}
-
-Several of the \Coq\ Users' Contributions use extraction to produce
-certified programs. In particular the following ones have an automatic
-extraction test:
-
-\begin{itemize}
-\item {\tt additions}
-\item {\tt bdds}
-\item {\tt canon-bdds}
-\item {\tt chinese}
-\item {\tt continuations}
-\item {\tt coq-in-coq}
-\item {\tt exceptions}
-\item {\tt firing-squad}
-\item {\tt founify}
-\item {\tt graphs}
-\item {\tt higman-cf}
-\item {\tt higman-nw}
-\item {\tt hardware}
-\item {\tt multiplier}
-\item {\tt search-trees}
-\item {\tt stalmarck}
-\end{itemize}
-
-\noindent {\tt continuations} and {\tt multiplier} are a bit particular. They are
-examples of developments where {\tt Obj.magic} are needed. This is
-probably due to an heavy use of impredicativity. After compilation, those
-two examples run nonetheless, thanks to the correction of the
-extraction~\cite{Let02}.
-
-%%% Local Variables:
-%%% mode: latex
-%%% TeX-master: "Reference-Manual"
-%%% End:
diff --git a/doc/refman/Misc.tex b/doc/refman/Misc.tex
deleted file mode 100644
index ab00fbfe3..000000000
--- a/doc/refman/Misc.tex
+++ /dev/null
@@ -1,63 +0,0 @@
-\achapter{\protect{Miscellaneous extensions}}
-%HEVEA\cutname{miscellaneous.html}
-
-\asection{Program derivation}
-
-Coq comes with an extension called {\tt Derive}, which supports
-program derivation. Typically in the style of Bird and Meertens or
-derivations of program refinements. To use the {\tt Derive} extension
-it must first be required with {\tt Require Coq.Derive.Derive}. When
-the extension is loaded, it provides the following command.
-
-\subsection[\tt Derive \ident$_1$ SuchThat \term{} As \ident$_2$]
- {\tt Derive \ident$_1$ SuchThat \term{} As \ident$_2$\comindex{Derive}}
-
-The name $\ident_1$ can appear in \term. This command opens a new
-proof presenting the user with a goal for \term{} in which the name
-$\ident_1$ is bound to a existential variables {\tt ?x} (formally,
-there are other goals standing for the existential variables but they
-are shelved, as described in Section~\ref{shelve}).
-
-When the proof ends two constants are defined:
-\begin{itemize}
-\item The first one is name $\ident_1$ and is defined as the proof of
- the shelved goal (which is also the value of {\tt ?x}). It is
-always transparent.
-\item The second one is name $\ident_2$. It has type {\tt \term}, and
- its body is the proof of the initially visible goal. It is opaque if
- the proof ends with {\tt Qed}, and transparent if the proof ends
- with {\tt Defined}.
-\end{itemize}
-
-\Example
-\begin{coq_example*}
-Require Coq.derive.Derive.
-Require Import Coq.Numbers.Natural.Peano.NPeano.
-
-Section P.
-
-Variables (n m k:nat).
-
-\end{coq_example*}
-\begin{coq_example}
-Derive p SuchThat ((k*n)+(k*m) = p) As h.
-Proof.
-rewrite <- Nat.mul_add_distr_l.
-subst p.
-reflexivity.
-\end{coq_example}
-\begin{coq_example*}
-Qed.
-
-End P.
-
-\end{coq_example*}
-\begin{coq_example}
-Print p.
-Check h.
-\end{coq_example}
-
-Any property can be used as \term, not only an equation. In
-particular, it could be an order relation specifying some form of
-program refinement or a non-executable property from which deriving a
-program is convenient.
diff --git a/doc/refman/Nsatz.tex b/doc/refman/Nsatz.tex
deleted file mode 100644
index 1401af10f..000000000
--- a/doc/refman/Nsatz.tex
+++ /dev/null
@@ -1,102 +0,0 @@
-\achapter{Nsatz: tactics for proving equalities in integral domains}
-%HEVEA\cutname{nsatz.html}
-\aauthor{Loïc Pottier}
-
-The tactic \texttt{nsatz} proves goals of the form
-
-\[ \begin{array}{l}
- \forall X_1,\ldots,X_n \in A,\\
- P_1(X_1,\ldots,X_n) = Q_1(X_1,\ldots,X_n) , \ldots , P_s(X_1,\ldots,X_n) =Q_s(X_1,\ldots,X_n)\\
- \vdash P(X_1,\ldots,X_n) = Q(X_1,\ldots,X_n)\\
- \end{array}
-\]
-where $P,Q, P_1,Q_1,\ldots,P_s,Q_s$ are polynomials and A is an integral
-domain, i.e. a commutative ring with no zero divisor. For example, A can be
-$\mathbb{R}$, $\mathbb{Z}$, of $\mathbb{Q}$. Note that the equality $=$ used in these
-goals can be any setoid equality
-(see \ref{setoidtactics})
-, not only Leibnitz equality.
-
-It also proves formulas
-\[ \begin{array}{l}
- \forall X_1,\ldots,X_n \in A,\\
- P_1(X_1,\ldots,X_n) = Q_1(X_1,\ldots,X_n) \wedge \ldots \wedge P_s(X_1,\ldots,X_n) =Q_s(X_1,\ldots,X_n)\\
- \rightarrow P(X_1,\ldots,X_n) = Q(X_1,\ldots,X_n)\\
- \end{array}
-\] doing automatic introductions.
-
-\asection{Using the basic tactic \texttt{nsatz}}
-\tacindex{nsatz}
-
-Load the
-\texttt{Nsatz} module: \texttt{Require Import Nsatz}.\\
- and use the tactic \texttt{nsatz}.
-
-\asection{More about \texttt{nsatz}}
-
-Hilbert's Nullstellensatz theorem shows how to reduce proofs of equalities on
-polynomials on a commutative ring A with no zero divisor to algebraic computations: it is easy to see that if a polynomial
-$P$ in $A[X_1,\ldots,X_n]$ verifies $c P^r = \sum_{i=1}^{s} S_i P_i$, with $c
-\in A$, $c \not = 0$, $r$ a positive integer, and the $S_i$s in
-$A[X_1,\ldots,X_n]$, then $P$ is zero whenever polynomials $P_1,...,P_s$ are
-zero (the converse is also true when A is an algebraic closed field:
-the method is complete).
-
-So, proving our initial problem can reduce into finding $S_1,\ldots,S_s$, $c$
-and $r$ such that $c (P-Q)^r = \sum_{i} S_i (P_i-Q_i)$, which will be proved by the
-tactic \texttt{ring}.
-
-This is achieved by the computation of a Groebner basis of the
-ideal generated by $P_1-Q_1,...,P_s-Q_s$, with an adapted version of the Buchberger
-algorithm.
-
-This computation is done after a step of {\em reification}, which is
-performed using {\em Type Classes}
-(see \ref{typeclasses})
-.
-
-The \texttt{Nsatz} module defines the tactic
-\texttt{nsatz}, which can be used without arguments: \\
-\vspace*{3mm}
-\texttt{nsatz}\\
-or with the syntax: \\
-\vspace*{3mm}
-\texttt{nsatz with radicalmax:={\em number}\%N strategy:={\em number}\%Z parameters:={\em list of variables} variables:={\em list of variables}}\\
-where:
-
-\begin{itemize}
- \item \texttt{radicalmax} is a bound when for searching r s.t.$c (P-Q)^r =
-\sum_{i=1..s} S_i (P_i - Q_i)$
-
- \item \texttt{strategy} gives the order on variables $X_1,...X_n$ and
-the strategy used in Buchberger algorithm (see
-\cite{sugar} for details):
-
- \begin{itemize}
- \item strategy = 0: reverse lexicographic order and newest s-polynomial.
- \item strategy = 1: reverse lexicographic order and sugar strategy.
- \item strategy = 2: pure lexicographic order and newest s-polynomial.
- \item strategy = 3: pure lexicographic order and sugar strategy.
- \end{itemize}
-
- \item \texttt{parameters} is the list of variables
-$X_{i_1},\ldots,X_{i_k}$ among $X_1,...,X_n$ which are considered as
- parameters: computation will be performed with rational fractions in these
- variables, i.e. polynomials are considered with coefficients in
-$R(X_{i_1},\ldots,X_{i_k})$. In this case, the coefficient $c$ can be a non
-constant polynomial in $X_{i_1},\ldots,X_{i_k}$, and the tactic produces a goal
-which states that $c$ is not zero.
-
- \item \texttt{variables} is the list of the variables
-in the decreasing order in which they will be used in Buchberger algorithm. If \texttt{variables} = {(@nil
-R)}, then \texttt{lvar} is replaced by all the variables which are not in
-parameters.
-
-\end{itemize}
-
-See file \texttt{Nsatz.v} for many examples, specially in geometry.
-
-%%% Local Variables:
-%%% mode: latex
-%%% TeX-master: "Reference-Manual"
-%%% End:
diff --git a/doc/refman/Polynom.tex b/doc/refman/Polynom.tex
deleted file mode 100644
index d9b8b8c52..000000000
--- a/doc/refman/Polynom.tex
+++ /dev/null
@@ -1,736 +0,0 @@
-\achapter{The \texttt{ring} and \texttt{field} tactic families}
-%HEVEA\cutname{ring.html}
-\aauthor{Bruno Barras, Benjamin Gr\'egoire, Assia
- Mahboubi, Laurent Th\'ery\footnote{based on previous work from
- Patrick Loiseleur and Samuel Boutin}}
-\label{ring}
-\tacindex{ring}
-
-This chapter presents the tactics dedicated to deal with ring and
-field equations.
-
-\asection{What does this tactic do?}
-
-\texttt{ring} does associative-commutative rewriting in ring and semi-ring
-structures. Assume you have two binary functions $\oplus$ and $\otimes$
-that are associative and commutative, with $\oplus$ distributive on
-$\otimes$, and two constants 0 and 1 that are unities for $\oplus$ and
-$\otimes$. A \textit{polynomial} is an expression built on variables $V_0, V_1,
-\dots$ and constants by application of $\oplus$ and $\otimes$.
-
-Let an {\it ordered product} be a product of variables $V_{i_1}
-\otimes \ldots \otimes V_{i_n}$ verifying $i_1 \le i_2 \le \dots \le
-i_n$. Let a \textit{monomial} be the product of a constant and an
-ordered product. We can order the monomials by the lexicographic
-order on products of variables. Let a \textit{canonical sum} be an
-ordered sum of monomials that are all different, i.e. each monomial in
-the sum is strictly less than the following monomial according to the
-lexicographic order. It is an easy theorem to show that every
-polynomial is equivalent (modulo the ring properties) to exactly one
-canonical sum. This canonical sum is called the \textit{normal form}
-of the polynomial. In fact, the actual representation shares monomials
-with same prefixes. So what does \texttt{ring}? It normalizes
-polynomials over any ring or semi-ring structure. The basic use of
-\texttt{ring} is to simplify ring expressions, so that the user does
-not have to deal manually with the theorems of associativity and
-commutativity.
-
-\begin{Examples}
-\item In the ring of integers, the normal form of
-$x (3 + yx + 25(1 - z)) + zx$ is $28x + (-24)xz + xxy$.
-\end{Examples}
-
-\texttt{ring} is also able to compute a normal form modulo monomial
-equalities. For example, under the hypothesis that $2x^2 = yz+1$,
- the normal form of $2(x + 1)x - x - zy$ is $x+1$.
-
-\asection{The variables map}
-
-It is frequent to have an expression built with + and
- $\times$, but rarely on variables only.
-Let us associate a number to each subterm of a ring
-expression in the \gallina\ language. For example in the ring
-\texttt{nat}, consider the expression:
-
-\begin{quotation}
-\begin{verbatim}
-(plus (mult (plus (f (5)) x) x)
- (mult (if b then (4) else (f (3))) (2)))
-\end{verbatim}
-\end{quotation}
-
-\noindent As a ring expression, it has 3 subterms. Give each subterm a
-number in an arbitrary order:
-
-\begin{tabular}{ccl}
-0 & $\mapsto$ & \verb|if b then (4) else (f (3))| \\
-1 & $\mapsto$ & \verb|(f (5))| \\
-2 & $\mapsto$ & \verb|x| \\
-\end{tabular}
-
-\noindent Then normalize the ``abstract'' polynomial
-
-$$((V_1 \otimes V_2) \oplus V_2) \oplus (V_0 \otimes 2) $$
-
-\noindent In our example the normal form is:
-
-$$(2 \otimes V_0) \oplus (V_1 \otimes V_2) \oplus (V_2 \otimes V_2)$$
-
-\noindent Then substitute the variables by their values in the variables map to
-get the concrete normal polynomial:
-
-\begin{quotation}
-\begin{verbatim}
-(plus (mult (2) (if b then (4) else (f (3))))
- (plus (mult (f (5)) x) (mult x x)))
-\end{verbatim}
-\end{quotation}
-
-\asection{Is it automatic?}
-
-Yes, building the variables map and doing the substitution after
-normalizing is automatically done by the tactic. So you can just forget
-this paragraph and use the tactic according to your intuition.
-
-\asection{Concrete usage in \Coq
-\tacindex{ring}
-\tacindex{ring\_simplify}}
-
-The {\tt ring} tactic solves equations upon polynomial expressions of
-a ring (or semi-ring) structure. It proceeds by normalizing both hand
-sides of the equation (w.r.t. associativity, commutativity and
-distributivity, constant propagation, rewriting of monomials)
-and comparing syntactically the results.
-
-{\tt ring\_simplify} applies the normalization procedure described
-above to the terms given. The tactic then replaces all occurrences of
-the terms given in the conclusion of the goal by their normal
-forms. If no term is given, then the conclusion should be an equation
-and both hand sides are normalized.
-The tactic can also be applied in a hypothesis.
-
-The tactic must be loaded by \texttt{Require Import Ring}. The ring
-structures must be declared with the \texttt{Add Ring} command (see
-below). The ring of booleans is predefined; if one wants to use the
-tactic on \texttt{nat} one must first require the module
-\texttt{ArithRing} (exported by \texttt{Arith});
-for \texttt{Z}, do \texttt{Require Import
-ZArithRing} or simply \texttt{Require Import ZArith};
-for \texttt{N}, do \texttt{Require Import NArithRing} or
-\texttt{Require Import NArith}.
-
-\Example
-\begin{coq_eval}
-Reset Initial.
-\end{coq_eval}
-\begin{coq_example*}
-Require Import ZArith.
-\end{coq_example*}
-\begin{coq_example}
-Open Scope Z_scope.
-Goal forall a b c:Z,
- (a + b + c)^2 =
- a * a + b^2 + c * c + 2 * a * b + 2 * a * c + 2 * b * c.
-\end{coq_example}
-\begin{coq_example}
-intros; ring.
-\end{coq_example}
-\begin{coq_eval}
-Abort.
-\end{coq_eval}
-\begin{coq_example}
-Goal forall a b:Z, 2*a*b = 30 ->
- (a+b)^2 = a^2 + b^2 + 30.
-\end{coq_example}
-\begin{coq_example}
-intros a b H; ring [H].
-\end{coq_example}
-\begin{coq_eval}
-Reset Initial.
-\end{coq_eval}
-
-\begin{Variants}
- \item {\tt ring [\term$_1$ {\ldots} \term$_n$]} decides the equality of two
- terms modulo ring operations and rewriting of the equalities
- defined by \term$_1$ {\ldots} \term$_n$. Each of \term$_1$
- {\ldots} \term$_n$ has to be a proof of some equality $m = p$,
- where $m$ is a monomial (after ``abstraction''),
- $p$ a polynomial and $=$ the corresponding equality of the ring structure.
-
- \item {\tt ring\_simplify [\term$_1$ {\ldots} \term$_n$] $t_1 \ldots t_m$ in
-{\ident}}
- performs the simplification in the hypothesis named {\tt ident}.
-\end{Variants}
-
-\Warning \texttt{ring\_simplify \term$_1$; ring\_simplify \term$_2$} is
-not equivalent to \texttt{ring\_simplify \term$_1$ \term$_2$}. In the
-latter case the variables map is shared between the two terms, and
-common subterm $t$ of \term$_1$ and \term$_2$ will have the same
-associated variable number. So the first alternative should be
-avoided for terms belonging to the same ring theory.
-
-
-\begin{ErrMsgs}
-\item \errindex{not a valid ring equation}
- The conclusion of the goal is not provable in the corresponding ring
- theory.
-\item \errindex{arguments of ring\_simplify do not have all the same type}
- {\tt ring\_simplify} cannot simplify terms of several rings at the
- same time. Invoke the tactic once per ring structure.
-\item \errindex{cannot find a declared ring structure over {\tt term}}
- No ring has been declared for the type of the terms to be
- simplified. Use {\tt Add Ring} first.
-\item \errindex{cannot find a declared ring structure for equality
- {\tt term}}
- Same as above is the case of the {\tt ring} tactic.
-\end{ErrMsgs}
-
-\asection{Adding a ring structure
-\comindex{Add Ring}}
-
-Declaring a new ring consists in proving that a ring signature (a
-carrier set, an equality, and ring operations: {\tt
-Ring\_theory.ring\_theory} and {\tt Ring\_theory.semi\_ring\_theory})
-satisfies the ring axioms. Semi-rings (rings without $+$ inverse) are
-also supported. The equality can be either Leibniz equality, or any
-relation declared as a setoid (see~\ref{setoidtactics}). The definition
-of ring and semi-rings (see module {\tt Ring\_theory}) is:
-\begin{verbatim}
-Record ring_theory : Prop := mk_rt {
- Radd_0_l : forall x, 0 + x == x;
- Radd_sym : forall x y, x + y == y + x;
- Radd_assoc : forall x y z, x + (y + z) == (x + y) + z;
- Rmul_1_l : forall x, 1 * x == x;
- Rmul_sym : forall x y, x * y == y * x;
- Rmul_assoc : forall x y z, x * (y * z) == (x * y) * z;
- Rdistr_l : forall x y z, (x + y) * z == (x * z) + (y * z);
- Rsub_def : forall x y, x - y == x + -y;
- Ropp_def : forall x, x + (- x) == 0
-}.
-
-Record semi_ring_theory : Prop := mk_srt {
- SRadd_0_l : forall n, 0 + n == n;
- SRadd_sym : forall n m, n + m == m + n ;
- SRadd_assoc : forall n m p, n + (m + p) == (n + m) + p;
- SRmul_1_l : forall n, 1*n == n;
- SRmul_0_l : forall n, 0*n == 0;
- SRmul_sym : forall n m, n*m == m*n;
- SRmul_assoc : forall n m p, n*(m*p) == (n*m)*p;
- SRdistr_l : forall n m p, (n + m)*p == n*p + m*p
-}.
-\end{verbatim}
-
-This implementation of {\tt ring} also features a notion of constant
-that can be parameterized. This can be used to improve the handling of
-closed expressions when operations are effective. It consists in
-introducing a type of \emph{coefficients} and an implementation of the
-ring operations, and a morphism from the coefficient type to the ring
-carrier type. The morphism needs not be injective, nor surjective.
-
-As
-an example, one can consider the real numbers. The set of coefficients
-could be the rational numbers, upon which the ring operations can be
-implemented. The fact that there exists a morphism is defined by the
-following properties:
-\begin{verbatim}
-Record ring_morph : Prop := mkmorph {
- morph0 : [cO] == 0;
- morph1 : [cI] == 1;
- morph_add : forall x y, [x +! y] == [x]+[y];
- morph_sub : forall x y, [x -! y] == [x]-[y];
- morph_mul : forall x y, [x *! y] == [x]*[y];
- morph_opp : forall x, [-!x] == -[x];
- morph_eq : forall x y, x?=!y = true -> [x] == [y]
-}.
-
-Record semi_morph : Prop := mkRmorph {
- Smorph0 : [cO] == 0;
- Smorph1 : [cI] == 1;
- Smorph_add : forall x y, [x +! y] == [x]+[y];
- Smorph_mul : forall x y, [x *! y] == [x]*[y];
- Smorph_eq : forall x y, x?=!y = true -> [x] == [y]
-}.
-\end{verbatim}
-where {\tt c0} and {\tt cI} denote the 0 and 1 of the coefficient set,
-{\tt +!}, {\tt *!}, {\tt -!} are the implementations of the ring
-operations, {\tt ==} is the equality of the coefficients, {\tt ?+!} is
-an implementation of this equality, and {\tt [x]} is a notation for
-the image of {\tt x} by the ring morphism.
-
-
-
-Since {\tt Z} is an initial ring (and {\tt N} is an initial
-semi-ring), it can always be considered as a set of
-coefficients. There are basically three kinds of (semi-)rings:
-\begin{description}
-\item[abstract rings] to be used when operations are not
- effective. The set of coefficients is {\tt Z} (or {\tt N} for
- semi-rings).
-\item[computational rings] to be used when operations are
- effective. The set of coefficients is the ring itself. The user only
- has to provide an implementation for the equality.
-\item[customized ring] for other cases. The user has to provide the
- coefficient set and the morphism.
-\end{description}
-
-This implementation of ring can also recognize simple
-power expressions as ring expressions. A power function is specified by
-the following property:
-\begin{verbatim}
-Section POWER.
- Variable Cpow : Set.
- Variable Cp_phi : N -> Cpow.
- Variable rpow : R -> Cpow -> R.
-
- Record power_theory : Prop := mkpow_th {
- rpow_pow_N : forall r n, req (rpow r (Cp_phi n)) (pow_N rI rmul r n)
- }.
-
-End POWER.
-\end{verbatim}
-
-
-The syntax for adding a new ring is {\tt Add Ring $name$ : $ring$
-($mod_1$,\dots,$mod_2$)}. The name is not relevant. It is just used
-for error messages. The term $ring$ is a proof that the ring signature
-satisfies the (semi-)ring axioms. The optional list of modifiers is
-used to tailor the behavior of the tactic. The following list
-describes their syntax and effects:
-\begin{description}
-\item[abstract] declares the ring as abstract. This is the default.
-\item[decidable \term] declares the ring as computational. The expression
- \term{} is
- the correctness proof of an equality test {\tt ?=!} (which should be
- evaluable). Its type should be of
- the form {\tt forall x y, x?=!y = true $\rightarrow$ x == y}.
-\item[morphism \term] declares the ring as a customized one. The expression
- \term{} is
- a proof that there exists a morphism between a set of coefficient
- and the ring carrier (see {\tt Ring\_theory.ring\_morph} and {\tt
- Ring\_theory.semi\_morph}).
-\item[setoid \term$_1$ \term$_2$] forces the use of given setoid. The
- expression \term$_1$ is a proof that the equality is indeed a setoid
- (see {\tt Setoid.Setoid\_Theory}), and \term$_2$ a proof that the
- ring operations are morphisms (see {\tt Ring\_theory.ring\_eq\_ext} and
- {\tt Ring\_theory.sring\_eq\_ext}). This modifier needs not be used if the
- setoid and morphisms have been declared.
-\item[constants [\ltac]] specifies a tactic expression that, given a term,
- returns either an object of the coefficient set that is mapped to
- the expression via the morphism, or returns {\tt
- InitialRing.NotConstant}. The default behavior is to map only 0 and
- 1 to their counterpart in the coefficient set. This is generally not
- desirable for non trivial computational rings.
-\item[preprocess [\ltac]]
- specifies a tactic that is applied as a preliminary step for {\tt
- ring} and {\tt ring\_simplify}. It can be used to transform a goal
- so that it is better recognized. For instance, {\tt S n} can be
- changed to {\tt plus 1 n}.
-\item[postprocess [\ltac]] specifies a tactic that is applied as a final step
- for {\tt ring\_simplify}. For instance, it can be used to undo
- modifications of the preprocessor.
-\item[power\_tac {\term} [\ltac]] allows {\tt ring} and {\tt ring\_simplify} to
- recognize power expressions with a constant positive integer exponent
- (example: $x^2$). The term {\term} is a proof that a given power function
- satisfies the specification of a power function ({\term} has to be a
- proof of {\tt Ring\_theory.power\_theory}) and {\ltac} specifies a
- tactic expression that, given a term, ``abstracts'' it into an
- object of type {\tt N} whose interpretation via {\tt Cp\_phi} (the
- evaluation function of power coefficient) is the original term, or
- returns {\tt InitialRing.NotConstant} if not a constant coefficient
- (i.e. {\ltac} is the inverse function of {\tt Cp\_phi}).
- See files {\tt plugins/setoid\_ring/ZArithRing.v} and
- {\tt plugins/setoid\_ring/RealField.v} for examples.
- By default the tactic does not recognize power expressions as ring
- expressions.
-\item[sign {\term}] allows {\tt ring\_simplify} to use a minus operation
- when outputting its normal form, i.e writing $x - y$ instead of $x + (-y)$.
- The term {\term} is a proof that a given sign function indicates expressions
- that are signed ({\term} has to be a
- proof of {\tt Ring\_theory.get\_sign}). See {\tt plugins/setoid\_ring/InitialRing.v} for examples of sign function.
-\item[div {\term}] allows {\tt ring} and {\tt ring\_simplify} to use monomials
-with coefficient other than 1 in the rewriting. The term {\term} is a proof that a given division function satisfies the specification of an euclidean
- division function ({\term} has to be a
- proof of {\tt Ring\_theory.div\_theory}). For example, this function is
- called when trying to rewrite $7x$ by $2x = z$ to tell that $7 = 3 * 2 + 1$.
- See {\tt plugins/setoid\_ring/InitialRing.v} for examples of div function.
-
-\end{description}
-
-
-\begin{ErrMsgs}
-\item \errindex{bad ring structure}
- The proof of the ring structure provided is not of the expected type.
-\item \errindex{bad lemma for decidability of equality}
- The equality function provided in the case of a computational ring
- has not the expected type.
-\item \errindex{ring {\it operation} should be declared as a morphism}
- A setoid associated to the carrier of the ring structure as been
- found, but the ring operation should be declared as
- morphism. See~\ref{setoidtactics}.
-\end{ErrMsgs}
-
-\asection{How does it work?}
-
-The code of \texttt{ring} is a good example of tactic written using
-\textit{reflection}. What is reflection? Basically, it is writing
-\Coq{} tactics in \Coq, rather than in \ocaml. From the philosophical
-point of view, it is using the ability of the Calculus of
-Constructions to speak and reason about itself. For the \texttt{ring}
-tactic we used \Coq\ as a programming language and also as a proof
-environment to build a tactic and to prove it correctness.
-
-The interested reader is strongly advised to have a look at the file
-\texttt{Ring\_polynom.v}. Here a type for polynomials is defined:
-
-\begin{small}
-\begin{flushleft}
-\begin{verbatim}
-Inductive PExpr : Type :=
- | PEc : C -> PExpr
- | PEX : positive -> PExpr
- | PEadd : PExpr -> PExpr -> PExpr
- | PEsub : PExpr -> PExpr -> PExpr
- | PEmul : PExpr -> PExpr -> PExpr
- | PEopp : PExpr -> PExpr
- | PEpow : PExpr -> N -> PExpr.
-\end{verbatim}
-\end{flushleft}
-\end{small}
-
-Polynomials in normal form are defined as:
-\begin{small}
-\begin{flushleft}
-\begin{verbatim}
-Inductive Pol : Type :=
- | Pc : C -> Pol
- | Pinj : positive -> Pol -> Pol
- | PX : Pol -> positive -> Pol -> Pol.
-\end{verbatim}
-\end{flushleft}
-\end{small}
-where {\tt Pinj n P} denotes $P$ in which $V_i$ is replaced by
-$V_{i+n}$, and {\tt PX P n Q} denotes $P \otimes V_1^{n} \oplus Q'$,
-$Q'$ being $Q$ where $V_i$ is replaced by $V_{i+1}$.
-
-
-Variables maps are represented by list of ring elements, and two
-interpretation functions, one that maps a variables map and a
-polynomial to an element of the concrete ring, and the second one that
-does the same for normal forms:
-\begin{small}
-\begin{flushleft}
-\begin{verbatim}
-Definition PEeval : list R -> PExpr -> R := [...].
-Definition Pphi_dev : list R -> Pol -> R := [...].
-\end{verbatim}
-\end{flushleft}
-\end{small}
-
-A function to normalize polynomials is defined, and the big theorem is
-its correctness w.r.t interpretation, that is:
-
-\begin{small}
-\begin{flushleft}
-\begin{verbatim}
-Definition norm : PExpr -> Pol := [...].
-Lemma Pphi_dev_ok :
- forall l pe npe, norm pe = npe -> PEeval l pe == Pphi_dev l npe.
-\end{verbatim}
-\end{flushleft}
-\end{small}
-
-So now, what is the scheme for a normalization proof? Let \texttt{p}
-be the polynomial expression that the user wants to normalize. First a
-little piece of ML code guesses the type of \texttt{p}, the ring
-theory \texttt{T} to use, an abstract polynomial \texttt{ap} and a
-variables map \texttt{v} such that \texttt{p} is
-$\beta\delta\iota$-equivalent to \verb|(PEeval v ap)|. Then we
-replace it by \verb|(Pphi_dev v (norm ap))|, using the
-main correctness theorem and we reduce it to a concrete expression
-\texttt{p'}, which is the concrete normal form of
-\texttt{p}. This is summarized in this diagram:
-\begin{center}
-\begin{tabular}{rcl}
-\texttt{p} & $\rightarrow_{\beta\delta\iota}$
- & \texttt{(PEeval v ap)} \\
- & & $=_{\mathrm{(by\ the\ main\ correctness\ theorem)}}$ \\
-\texttt{p'}
- & $\leftarrow_{\beta\delta\iota}$
- & \texttt{(Pphi\_dev v (norm ap))}
-\end{tabular}
-\end{center}
-The user do not see the right part of the diagram.
-From outside, the tactic behaves like a
-$\beta\delta\iota$ simplification extended with AC rewriting rules.
-Basically, the proof is only the application of the main
-correctness theorem to well-chosen arguments.
-
-
-\asection{Dealing with fields
-\tacindex{field}
-\tacindex{field\_simplify}
-\tacindex{field\_simplify\_eq}}
-
-
-The {\tt field} tactic is an extension of the {\tt ring} to deal with
-rational expression. Given a rational expression $F=0$. It first reduces the
-expression $F$ to a common denominator $N/D= 0$ where $N$ and $D$ are two ring
-expressions.
-For example, if we take $F = (1 - 1/x) x - x + 1$, this gives
-$ N= (x -1) x - x^2 + x$ and $D= x$. It then calls {\tt ring}
-to solve $N=0$. Note that {\tt field} also generates non-zero conditions
-for all the denominators it encounters in the reduction.
-In our example, it generates the condition $x \neq 0$. These
-conditions appear as one subgoal which is a conjunction if there are
-several denominators.
-Non-zero conditions are {\it always} polynomial expressions. For example
-when reducing the expression $1/(1 + 1/x)$, two side conditions are
-generated: $x\neq 0$ and $x + 1 \neq 0$. Factorized expressions are
-broken since a field is an integral domain, and when the equality test
-on coefficients is complete w.r.t. the equality of the target field,
-constants can be proven different from zero automatically.
-
-The tactic must be loaded by \texttt{Require Import Field}. New field
-structures can be declared to the system with the \texttt{Add Field}
-command (see below). The field of real numbers is defined in module
-\texttt{RealField} (in texttt{plugins/setoid\_ring}). It is exported
-by module \texttt{Rbase}, so that requiring \texttt{Rbase} or
-\texttt{Reals} is enough to use the field tactics on real
-numbers. Rational numbers in canonical form are also declared as a
-field in module \texttt{Qcanon}.
-
-
-\Example
-\begin{coq_eval}
-Reset Initial.
-\end{coq_eval}
-\begin{coq_example*}
-Require Import Reals.
-\end{coq_example*}
-\begin{coq_example}
-Open Scope R_scope.
-Goal forall x, x <> 0 ->
- (1 - 1/x) * x - x + 1 = 0.
-\end{coq_example}
-\begin{coq_example}
-intros; field; auto.
-\end{coq_example}
-\begin{coq_eval}
-Abort.
-\end{coq_eval}
-\begin{coq_example}
-Goal forall x y, y <> 0 -> y = x -> x/y = 1.
-\end{coq_example}
-\begin{coq_example}
-intros x y H H1; field [H1]; auto.
-\end{coq_example}
-\begin{coq_eval}
-Reset Initial.
-\end{coq_eval}
-
-\begin{Variants}
- \item {\tt field [\term$_1$ {\ldots} \term$_n$]} decides the equality of two
- terms modulo field operations and rewriting of the equalities
- defined by \term$_1$ {\ldots} \term$_n$. Each of \term$_1$
- {\ldots} \term$_n$ has to be a proof of some equality $m = p$,
- where $m$ is a monomial (after ``abstraction''),
- $p$ a polynomial and $=$ the corresponding equality of the field structure.
- Beware that rewriting works with the equality $m=p$ only if $p$ is a
- polynomial since rewriting is handled by the underlying {\tt ring}
- tactic.
- \item {\tt field\_simplify}
- performs the simplification in the conclusion of the goal, $F_1 = F_2$
- becomes $N_1/D_1 = N_2/D_2$. A normalization step (the same as the
- one for rings) is then applied to $N_1$, $D_1$, $N_2$ and
- $D_2$. This way, polynomials remain in factorized form during the
- fraction simplifications. This yields smaller expressions when
- reducing to the same denominator since common factors can be
- canceled.
-
- \item {\tt field\_simplify [\term$_1$ {\ldots} \term$_n$]}
- performs the simplification in the conclusion of the goal using
- the equalities
- defined by \term$_1$ {\ldots} \term$_n$.
-
- \item {\tt field\_simplify [\term$_1$ {\ldots} \term$_n$] $t_1$ \ldots
-$t_m$}
- performs the simplification in the terms $t_1$ \ldots $t_m$
- of the conclusion of the goal using
- the equalities
- defined by \term$_1$ {\ldots} \term$_n$.
-
- \item {\tt field\_simplify in $H$}
- performs the simplification in the assumption $H$.
-
- \item {\tt field\_simplify [\term$_1$ {\ldots} \term$_n$] in $H$}
- performs the simplification in the assumption $H$ using
- the equalities
- defined by \term$_1$ {\ldots} \term$_n$.
-
- \item {\tt field\_simplify [\term$_1$ {\ldots} \term$_n$] $t_1$ \ldots
-$t_m$ in $H$}
- performs the simplification in the terms $t_1$ \ldots $t_n$
- of the assumption $H$ using
- the equalities
- defined by \term$_1$ {\ldots} \term$_m$.
-
- \item {\tt field\_simplify\_eq}
- performs the simplification in the conclusion of the goal removing
- the denominator. $F_1 = F_2$
- becomes $N_1 D_2 = N_2 D_1$.
-
- \item {\tt field\_simplify\_eq [\term$_1$ {\ldots} \term$_n$]}
- performs the simplification in the conclusion of the goal using
- the equalities
- defined by \term$_1$ {\ldots} \term$_n$.
-
- \item {\tt field\_simplify\_eq} in $H$
- performs the simplification in the assumption $H$.
-
- \item {\tt field\_simplify\_eq [\term$_1$ {\ldots} \term$_n$] in $H$}
- performs the simplification in the assumption $H$ using
- the equalities
- defined by \term$_1$ {\ldots} \term$_n$.
-\end{Variants}
-
-\asection{Adding a new field structure
-\comindex{Add Field}}
-
-Declaring a new field consists in proving that a field signature (a
-carrier set, an equality, and field operations: {\tt
-Field\_theory.field\_theory} and {\tt Field\_theory.semi\_field\_theory})
-satisfies the field axioms. Semi-fields (fields without $+$ inverse) are
-also supported. The equality can be either Leibniz equality, or any
-relation declared as a setoid (see~\ref{setoidtactics}). The definition
-of fields and semi-fields is:
-\begin{verbatim}
-Record field_theory : Prop := mk_field {
- F_R : ring_theory rO rI radd rmul rsub ropp req;
- F_1_neq_0 : ~ 1 == 0;
- Fdiv_def : forall p q, p / q == p * / q;
- Finv_l : forall p, ~ p == 0 -> / p * p == 1
-}.
-
-Record semi_field_theory : Prop := mk_sfield {
- SF_SR : semi_ring_theory rO rI radd rmul req;
- SF_1_neq_0 : ~ 1 == 0;
- SFdiv_def : forall p q, p / q == p * / q;
- SFinv_l : forall p, ~ p == 0 -> / p * p == 1
-}.
-\end{verbatim}
-
-The result of the normalization process is a fraction represented by
-the following type:
-\begin{verbatim}
-Record linear : Type := mk_linear {
- num : PExpr C;
- denum : PExpr C;
- condition : list (PExpr C)
-}.
-\end{verbatim}
-where {\tt num} and {\tt denum} are the numerator and denominator;
-{\tt condition} is a list of expressions that have appeared as a
-denominator during the normalization process. These expressions must
-be proven different from zero for the correctness of the algorithm.
-
-The syntax for adding a new field is {\tt Add Field $name$ : $field$
-($mod_1$,\dots,$mod_2$)}. The name is not relevant. It is just used
-for error messages. $field$ is a proof that the field signature
-satisfies the (semi-)field axioms. The optional list of modifiers is
-used to tailor the behavior of the tactic. Since field tactics are
-built upon ring tactics, all modifiers of the {\tt Add Ring}
-apply. There is only one specific modifier:
-\begin{description}
-\item[completeness \term] allows the field tactic to prove
- automatically that the image of non-zero coefficients are mapped to
- non-zero elements of the field. \term is a proof of {\tt forall x y,
- [x] == [y] -> x?=!y = true}, which is the completeness of equality
- on coefficients w.r.t. the field equality.
-\end{description}
-
-\asection{History of \texttt{ring}}
-
-First Samuel Boutin designed the tactic \texttt{ACDSimpl}.
-This tactic did lot of rewriting. But the proofs
-terms generated by rewriting were too big for \Coq's type-checker.
-Let us see why:
-
-\begin{coq_eval}
-Require Import ZArith.
-Open Scope Z_scope.
-\end{coq_eval}
-\begin{coq_example}
-Goal forall x y z:Z, x + 3 + y + y * z = x + 3 + y + z * y.
-\end{coq_example}
-\begin{coq_example*}
-intros; rewrite (Z.mul_comm y z); reflexivity.
-Save toto.
-\end{coq_example*}
-\begin{coq_example}
-Print toto.
-\end{coq_example}
-
-At each step of rewriting, the whole context is duplicated in the proof
-term. Then, a tactic that does hundreds of rewriting generates huge proof
-terms. Since \texttt{ACDSimpl} was too slow, Samuel Boutin rewrote it
-using reflection (see his article in TACS'97 \cite{Bou97}). Later, the
-stuff was rewritten by Patrick
-Loiseleur: the new tactic does not any more require \texttt{ACDSimpl}
-to compile and it makes use of $\beta\delta\iota$-reduction
-not only to replace the rewriting steps, but also to achieve the
-interleaving of computation and
-reasoning (see \ref{DiscussReflection}). He also wrote a
-few ML code for the \texttt{Add Ring} command, that allow to register
-new rings dynamically.
-
-Proofs terms generated by \texttt{ring} are quite small, they are
-linear in the number of $\oplus$ and $\otimes$ operations in the
-normalized terms. Type-checking those terms requires some time because it
-makes a large use of the conversion rule, but
-memory requirements are much smaller.
-
-\asection{Discussion}
-\label{DiscussReflection}
-
-Efficiency is not the only motivation to use reflection
-here. \texttt{ring} also deals with constants, it rewrites for example the
-expression $34 + 2*x -x + 12$ to the expected result $x + 46$. For the
-tactic \texttt{ACDSimpl}, the only constants were 0 and 1. So the
-expression $34 + 2*(x - 1) + 12$ is interpreted as
-$V_0 \oplus V_1 \otimes (V_2 \ominus 1) \oplus V_3$,
-with the variables mapping
-$\{V_0 \mt 34; V_1 \mt 2; V_2 \mt x; V_3 \mt 12 \}$. Then it is
-rewritten to $34 - x + 2*x + 12$, very far from the expected
-result. Here rewriting is not sufficient: you have to do some kind of
-reduction (some kind of \textit{computation}) to achieve the
-normalization.
-
-The tactic \texttt{ring} is not only faster than a classical one:
-using reflection, we get for free integration of computation and
-reasoning that would be very complex to implement in the classic fashion.
-
-Is it the ultimate way to write tactics? The answer is: yes and
-no. The \texttt{ring} tactic uses intensively the conversion rule of
-\CIC, that is replaces proof by computation the most as it is
-possible. It can be useful in all situations where a classical tactic
-generates huge proof terms. Symbolic Processing and Tautologies are in
-that case. But there are also tactics like \texttt{auto} or
-\texttt{linear} that do many complex computations, using side-effects
-and backtracking, and generate a small proof term. Clearly, it would
-be significantly less efficient to replace them by tactics using
-reflection.
-
-Another idea suggested by Benjamin Werner: reflection could be used to
-couple an external tool (a rewriting program or a model checker) with
-\Coq. We define (in \Coq) a type of terms, a type of \emph{traces},
-and prove a correction theorem that states that \emph{replaying
-traces} is safe w.r.t some interpretation. Then we let the external
-tool do every computation (using side-effects, backtracking,
-exception, or others features that are not available in pure lambda
-calculus) to produce the trace: now we can check in Coq{} that the
-trace has the expected semantic by applying the correction lemma.
-
-%%% Local Variables:
-%%% mode: latex
-%%% TeX-master: "Reference-Manual"
-%%% End:
diff --git a/doc/refman/Program.tex b/doc/refman/Program.tex
deleted file mode 100644
index 1e204dc83..000000000
--- a/doc/refman/Program.tex
+++ /dev/null
@@ -1,329 +0,0 @@
-\achapter{\Program{}}
-%HEVEA\cutname{program.html}
-\label{Program}
-\aauthor{Matthieu Sozeau}
-\index{Program}
-
-We present here the \Program\ tactic commands, used to build certified
-\Coq\ programs, elaborating them from their algorithmic skeleton and a
-rich specification \cite{Sozeau06}. It can be thought of as a dual of extraction
-(see Chapter~\ref{Extraction}). The goal of \Program~is to program as in a regular
-functional programming language whilst using as rich a specification as
-desired and proving that the code meets the specification using the whole \Coq{} proof
-apparatus. This is done using a technique originating from the
-``Predicate subtyping'' mechanism of \PVS \cite{Rushby98}, which generates type-checking
-conditions while typing a term constrained to a particular type.
-Here we insert existential variables in the term, which must be filled
-with proofs to get a complete \Coq\ term. \Program\ replaces the
-\Program\ tactic by Catherine Parent \cite{Parent95b} which had a similar goal but is no longer
-maintained.
-
-The languages available as input are currently restricted to \Coq's term
-language, but may be extended to \ocaml{}, \textsc{Haskell} and others
-in the future. We use the same syntax as \Coq\ and permit to use implicit
-arguments and the existing coercion mechanism.
-Input terms and types are typed in an extended system (\Russell) and
-interpreted into \Coq\ terms. The interpretation process may produce
-some proof obligations which need to be resolved to create the final term.
-
-\asection{Elaborating programs}
-The main difference from \Coq\ is that an object in a type $T : \Set$
-can be considered as an object of type $\{ x : T~|~P\}$ for any
-wellformed $P : \Prop$.
-If we go from $T$ to the subset of $T$ verifying property $P$, we must
-prove that the object under consideration verifies it. \Russell\ will
-generate an obligation for every such coercion. In the other direction,
-\Russell\ will automatically insert a projection.
-
-Another distinction is the treatment of pattern-matching. Apart from the
-following differences, it is equivalent to the standard {\tt match}
-operation (see Section~\ref{Caseexpr}).
-\begin{itemize}
-\item Generation of equalities. A {\tt match} expression is always
- generalized by the corresponding equality. As an example,
- the expression:
-
-\begin{verbatim}
- match x with
- | 0 => t
- | S n => u
- end.
-\end{verbatim}
-will be first rewritten to:
-\begin{verbatim}
- (match x as y return (x = y -> _) with
- | 0 => fun H : x = 0 -> t
- | S n => fun H : x = S n -> u
- end) (eq_refl n).
-\end{verbatim}
-
- This permits to get the proper equalities in the context of proof
- obligations inside clauses, without which reasoning is very limited.
-
-\item Generation of inequalities. If a pattern intersects with a
- previous one, an inequality is added in the context of the second
- branch. See for example the definition of {\tt div2} below, where the second
- branch is typed in a context where $\forall p, \_ <> S (S p)$.
-
-\item Coercion. If the object being matched is coercible to an inductive
- type, the corresponding coercion will be automatically inserted. This also
- works with the previous mechanism.
-
-\end{itemize}
-
-There are options to control the generation of equalities
-and coercions.
-
-\begin{itemize}
-\item {\tt Unset Program Cases}\optindex{Program Cases} This deactivates
- the special treatment of pattern-matching generating equalities and
- inequalities when using \Program\ (it is on by default). All
- pattern-matchings and let-patterns are handled using the standard
- algorithm of Coq (see Section~\ref{Mult-match-full}) when this option is
- deactivated.
-\item {\tt Unset Program Generalized Coercion}\optindex{Program
- Generalized Coercion} This deactivates the coercion of general
- inductive types when using \Program\ (the option is on by default).
- Coercion of subset types and pairs is still active in this case.
-\end{itemize}
-
-\subsection{Syntactic control over equalities}
-\label{ProgramSyntax}
-To give more control over the generation of equalities, the typechecker will
-fall back directly to \Coq's usual typing of dependent pattern-matching
-if a {\tt return} or {\tt in} clause is specified. Likewise,
-the {\tt if} construct is not treated specially by \Program{} so boolean
-tests in the code are not automatically reflected in the obligations.
-One can use the {\tt dec} combinator to get the correct hypotheses as in:
-
-\begin{coq_eval}
-Require Import Program Arith.
-\end{coq_eval}
-\begin{coq_example}
-Program Definition id (n : nat) : { x : nat | x = n } :=
- if dec (leb n 0) then 0
- else S (pred n).
-\end{coq_example}
-
-The let tupling construct {\tt let (x1, ..., xn) := t in b}
-does not produce an equality, contrary to the let pattern construct
-{\tt let '(x1, ..., xn) := t in b}.
-Also, {\tt {\term}:>} explicitly asks the system to coerce {\tt \term} to its
-support type. It can be useful in notations, for example:
-\begin{coq_example}
-Notation " x `= y " := (@eq _ (x :>) (y :>)) (only parsing).
-\end{coq_example}
-
-This notation denotes equality on subset types using equality on their
-support types, avoiding uses of proof-irrelevance that would come up
-when reasoning with equality on the subset types themselves.
-
-The next two commands are similar to their standard counterparts
-Definition (see Section~\ref{Basic-definitions}) and Fixpoint (see Section~\ref{Fixpoint}) in that
-they define constants. However, they may require the user to prove some
-goals to construct the final definitions.
-
-\subsection{\tt Program Definition {\ident} := {\term}.
- \comindex{Program Definition}\label{ProgramDefinition}}
-
-This command types the value {\term} in \Russell\ and generates proof
-obligations. Once solved using the commands shown below, it binds the final
-\Coq\ term to the name {\ident} in the environment.
-
-\begin{ErrMsgs}
-\item \errindex{{\ident} already exists}
-\end{ErrMsgs}
-
-\begin{Variants}
-\item {\tt Program Definition {\ident} {\tt :}{\term$_1$} :=
- {\term$_2$}.}\\
- It interprets the type {\term$_1$}, potentially generating proof
- obligations to be resolved. Once done with them, we have a \Coq\ type
- {\term$_1'$}. It then checks that the type of the interpretation of
- {\term$_2$} is coercible to {\term$_1'$}, and registers {\ident} as
- being of type {\term$_1'$} once the set of obligations generated
- during the interpretation of {\term$_2$} and the aforementioned
- coercion derivation are solved.
-\item {\tt Program Definition {\ident} {\binder$_1$}\ldots{\binder$_n$}
- {\tt :}\term$_1$ {\tt :=} {\term$_2$}.}\\
- This is equivalent to \\
- {\tt Program Definition\,{\ident}\,{\tt :\,forall} %
- {\binder$_1$}\ldots{\binder$_n$}{\tt ,}\,\term$_1$\,{\tt :=}} \\
- \qquad {\tt fun}\,{\binder$_1$}\ldots{\binder$_n$}\,{\tt =>}\,{\term$_2$}\,%
- {\tt .}
-\end{Variants}
-
-\begin{ErrMsgs}
-\item \errindex{In environment {\dots} the term: {\term$_2$} does not have type
- {\term$_1$}}.\\
- \texttt{Actually, it has type {\term$_3$}}.
-\end{ErrMsgs}
-
-\SeeAlso Sections \ref{Opaque}, \ref{Transparent}, \ref{unfold}
-
-\subsection{\tt Program Fixpoint {\ident} {\params} {\tt \{order\}} : type := \term
- \comindex{Program Fixpoint}
- \label{ProgramFixpoint}}
-
-The structural fixpoint operator behaves just like the one of Coq
-(see Section~\ref{Fixpoint}), except it may also generate obligations.
-It works with mutually recursive definitions too.
-
-\begin{coq_eval}
-Admit Obligations.
-\end{coq_eval}
-\begin{coq_example}
-Program Fixpoint div2 (n : nat) : { x : nat | n = 2 * x \/ n = 2 * x + 1 } :=
- match n with
- | S (S p) => S (div2 p)
- | _ => O
- end.
-\end{coq_example}
-
-Here we have one obligation for each branch (branches for \verb:0: and \verb:(S 0): are
-automatically generated by the pattern-matching compilation algorithm).
-\begin{coq_example}
- Obligation 1.
-\end{coq_example}
-
-One can use a well-founded order or a measure as termination orders using the syntax:
-\begin{coq_eval}
-Reset Initial.
-Require Import Arith.
-Require Import Program.
-\end{coq_eval}
-\begin{coq_example*}
-Program Fixpoint div2 (n : nat) {measure n} :
- { x : nat | n = 2 * x \/ n = 2 * x + 1 } :=
- match n with
- | S (S p) => S (div2 p)
- | _ => O
- end.
-\end{coq_example*}
-
-The order annotation can be either:
-\begin{itemize}
-\item {\tt measure f (R)?} where {\tt f} is a value of type {\tt X}
- computed on any subset of the arguments and the optional
- (parenthesised) term {\tt (R)} is a relation
- on {\tt X}. By default {\tt X} defaults to {\tt nat} and {\tt R} to
- {\tt lt}.
-\item {\tt wf R x} which is equivalent to {\tt measure x (R)}.
-\end{itemize}
-
-\paragraph{Caution}
-When defining structurally recursive functions, the
-generated obligations should have the prototype of the currently defined functional
-in their context. In this case, the obligations should be transparent
-(e.g. defined using {\tt Defined}) so that the guardedness condition on
-recursive calls can be checked by the
-kernel's type-checker. There is an optimization in the generation of
-obligations which gets rid of the hypothesis corresponding to the
-functional when it is not necessary, so that the obligation can be
-declared opaque (e.g. using {\tt Qed}). However, as soon as it appears in the
-context, the proof of the obligation is \emph{required} to be declared transparent.
-
-No such problems arise when using measures or well-founded recursion.
-
-\subsection{\tt Program Lemma {\ident} : type.
- \comindex{Program Lemma}
- \label{ProgramLemma}}
-
-The \Russell\ language can also be used to type statements of logical
-properties. It will generate obligations, try to solve them
-automatically and fail if some unsolved obligations remain.
-In this case, one can first define the lemma's
-statement using {\tt Program Definition} and use it as the goal afterwards.
-Otherwise the proof will be started with the elaborated version as a goal.
-The {\tt Program} prefix can similarly be used as a prefix for {\tt Variable}, {\tt
- Hypothesis}, {\tt Axiom} etc...
-
-\section{Solving obligations}
-The following commands are available to manipulate obligations. The
-optional identifier is used when multiple functions have unsolved
-obligations (e.g. when defining mutually recursive blocks). The optional
-tactic is replaced by the default one if not specified.
-
-\begin{itemize}
-\item {\tt [Local|Global] Obligation Tactic := \tacexpr}\comindex{Obligation Tactic}
- Sets the default obligation
- solving tactic applied to all obligations automatically, whether to
- solve them or when starting to prove one, e.g. using {\tt Next}.
- Local makes the setting last only for the current module. Inside
- sections, local is the default.
-\item {\tt Show Obligation Tactic}\comindex{Show Obligation Tactic}
- Displays the current default tactic.
-\item {\tt Obligations [of \ident]}\comindex{Obligations} Displays all remaining
- obligations.
-\item {\tt Obligation num [of \ident]}\comindex{Obligation} Start the proof of
- obligation {\tt num}.
-\item {\tt Next Obligation [of \ident]}\comindex{Next Obligation} Start the proof of the next
- unsolved obligation.
-\item {\tt Solve Obligations [of \ident] [with
- \tacexpr]}\comindex{Solve Obligations}
- Tries to solve
- each obligation of \ident using the given tactic or the default one.
-\item {\tt Solve All Obligations [with \tacexpr]} Tries to solve
- each obligation of every program using the given tactic or the default
- one (useful for mutually recursive definitions).
-\item {\tt Admit Obligations [of \ident]}\comindex{Admit Obligations}
- Admits all obligations (does not work with structurally recursive programs).
-\item {\tt Preterm [of \ident]}\comindex{Preterm}
- Shows the term that will be fed to
- the kernel once the obligations are solved. Useful for debugging.
-\item {\tt Set Transparent Obligations}\optindex{Transparent Obligations}
- Control whether all obligations should be declared as transparent (the
- default), or if the system should infer which obligations can be declared opaque.
-\item {\tt Set Hide Obligations}\optindex{Hide Obligations}
- Control whether obligations appearing in the term should be hidden
- as implicit arguments of the special constant
- \texttt{Program.Tactics.obligation}.
-\item {\tt Set Shrink Obligations}\optindex{Shrink Obligations}
-\emph{Deprecated since 8.7}
- This option (on by default) controls whether obligations should have their
- context minimized to the set of variables used in the proof of the
- obligation, to avoid unnecessary dependencies.
-\end{itemize}
-
-The module {\tt Coq.Program.Tactics} defines the default tactic for solving
-obligations called {\tt program\_simpl}. Importing
-{\tt Coq.Program.Program} also adds some useful notations, as documented in the file itself.
-
-\section{Frequently Asked Questions
- \label{ProgramFAQ}}
-
-\begin{itemize}
-\item {Ill-formed recursive definitions}
- This error can happen when one tries to define a
- function by structural recursion on a subset object, which means the Coq
- function looks like:
-
- \verb$Program Fixpoint f (x : A | P) := match x with A b => f b end.$
-
- Supposing $b : A$, the argument at the recursive call to f is not a
- direct subterm of x as b is wrapped inside an {\tt exist} constructor to build
- an object of type \verb${x : A | P}$. Hence the definition is rejected
- by the guardedness condition checker. However one can use
- wellfounded recursion on subset objects like this:
-
-\begin{verbatim}
-Program Fixpoint f (x : A | P) { measure (size x) } :=
- match x with A b => f b end.
-\end{verbatim}
-
- One will then just have to prove that the measure decreases at each recursive
- call. There are three drawbacks though:
- \begin{enumerate}
- \item A measure function has to be defined;
- \item The reduction is a little more involved, although it works well
- using lazy evaluation;
- \item Mutual recursion on the underlying inductive type isn't possible
- anymore, but nested mutual recursion is always possible.
- \end{enumerate}
-\end{itemize}
-
-%%% Local Variables:
-%%% mode: latex
-%%% TeX-master: "Reference-Manual"
-%%% compile-command: "BIBINPUTS=\".\" make QUICK=1 -C ../.. doc/refman/Reference-Manual.pdf"
-%%% End:
diff --git a/doc/refman/Reference-Manual.tex b/doc/refman/Reference-Manual.tex
index 86f123322..e51116007 100644
--- a/doc/refman/Reference-Manual.tex
+++ b/doc/refman/Reference-Manual.tex
@@ -117,16 +117,7 @@ Options A and B of the licence are {\em not} elected.}
%END LATEX
\part{Addendum to the Reference Manual}
\include{AddRefMan-pre}%
-\include{Coercion.v}%
-\include{Classes.v}%
-\include{Extraction.v}%
-\include{Program.v}%
-\include{Polynom.v}% = Ring
-\include{Nsatz.v}%
-\include{Setoid.v}% Tactique pour les setoides
-\include{AsyncProofs}% Paral-ITP
\include{Universes.v}% Universe polymorphes
-\include{Misc.v}
%BEGIN LATEX
\RefManCutCommand{ENDADDENDUM=\thepage}
%END LATEX
diff --git a/doc/refman/Setoid.tex b/doc/refman/Setoid.tex
deleted file mode 100644
index b7b343112..000000000
--- a/doc/refman/Setoid.tex
+++ /dev/null
@@ -1,842 +0,0 @@
-\newtheorem{cscexample}{Example}
-
-\achapter{\protect{Generalized rewriting}}
-%HEVEA\cutname{setoid.html}
-\aauthor{Matthieu Sozeau}
-\label{setoids}
-
-This chapter presents the extension of several equality related tactics
-to work over user-defined structures (called setoids) that are equipped
-with ad-hoc equivalence relations meant to behave as equalities.
-Actually, the tactics have also been generalized to relations weaker
-then equivalences (e.g. rewriting systems). The toolbox also extends the
-automatic rewriting capabilities of the system, allowing the specification of
-custom strategies for rewriting.
-
-This documentation is adapted from the previous setoid documentation by
-Claudio Sacerdoti Coen (based on previous work by Cl\'ement Renard).
-The new implementation is a drop-in replacement for the old one,\footnote{Nicolas
-Tabareau helped with the gluing.} hence most of the documentation still applies.
-
-The work is a complete rewrite of the previous implementation, based on
-the type class infrastructure. It also improves on and generalizes
-the previous implementation in several ways:
-\begin{itemize}
-\item User-extensible algorithm. The algorithm is separated in two
- parts: generations of the rewriting constraints (done in ML) and
- solving of these constraints using type class resolution. As type
- class resolution is extensible using tactics, this allows users to define
- general ways to solve morphism constraints.
-\item Sub-relations. An example extension to the base algorithm is the
- ability to define one relation as a subrelation of another so that
- morphism declarations on one relation can be used automatically for
- the other. This is done purely using tactics and type class search.
-\item Rewriting under binders. It is possible to rewrite under binders
- in the new implementation, if one provides the proper
- morphisms. Again, most of the work is handled in the tactics.
-\item First-class morphisms and signatures. Signatures and morphisms are
- ordinary Coq terms, hence they can be manipulated inside Coq, put
- inside structures and lemmas about them can be proved inside the
- system. Higher-order morphisms are also allowed.
-\item Performance. The implementation is based on a depth-first search for the first
- solution to a set of constraints which can be as fast as linear in the
- size of the term, and the size of the proof term is linear
- in the size of the original term. Besides, the extensibility allows the
- user to customize the proof search if necessary.
-\end{itemize}
-
-\asection{Introduction to generalized rewriting}
-
-\subsection{Relations and morphisms}
-
-A parametric \emph{relation} \texttt{R} is any term of type
-\texttt{forall ($x_1$:$T_1$) \ldots ($x_n$:$T_n$), relation $A$}. The
-expression $A$, which depends on $x_1$ \ldots $x_n$, is called the
-\emph{carrier} of the relation and \texttt{R} is
-said to be a relation over \texttt{A}; the list $x_1,\ldots,x_n$
-is the (possibly empty) list of parameters of the relation.
-
-\firstexample
-\begin{cscexample}[Parametric relation]
-It is possible to implement finite sets of elements of type \texttt{A}
-as unordered list of elements of type \texttt{A}. The function
-\texttt{set\_eq: forall (A: Type), relation (list A)} satisfied by two lists
-with the same elements is a parametric relation over \texttt{(list A)} with
-one parameter \texttt{A}. The type of \texttt{set\_eq} is convertible with
-\texttt{forall (A: Type), list A -> list A -> Prop}.
-\end{cscexample}
-
-An \emph{instance} of a parametric relation \texttt{R} with $n$ parameters
-is any term \texttt{(R $t_1$ \ldots $t_n$)}.
-
-Let \texttt{R} be a relation over \texttt{A} with $n$ parameters.
-A term is a parametric proof of reflexivity for \texttt{R} if it has type
-\texttt{forall ($x_1$:$T_1$) \ldots ($x_n$:$T_n$),
- reflexive (R $x_1$ \ldots $x_n$)}. Similar definitions are given for
-parametric proofs of symmetry and transitivity.
-
-\begin{cscexample}[Parametric relation (cont.)]
-The \texttt{set\_eq} relation of the previous example can be proved to be
-reflexive, symmetric and transitive.
-\end{cscexample}
-
-A parametric unary function $f$ of type
-\texttt{forall ($x_1$:$T_1$) \ldots ($x_n$:$T_n$), $A_1$ -> $A_2$}
-covariantly respects two parametric relation instances $R_1$ and $R_2$ if,
-whenever $x, y$ satisfy $R_1~x~y$, their images $(f~x)$ and $(f~y)$
-satisfy $R_2~(f~x)~(f~y)$ . An $f$ that respects its input and output relations
-will be called a unary covariant \emph{morphism}. We can also say that $f$ is
-a monotone function with respect to $R_1$ and $R_2$.
-The sequence $x_1,\ldots x_n$ represents the parameters of the morphism.
-
-Let $R_1$ and $R_2$ be two parametric relations.
-The \emph{signature} of a parametric morphism of type
-\texttt{forall ($x_1$:$T_1$) \ldots ($x_n$:$T_n$), $A_1$ -> $A_2$} that
-covariantly respects two instances $I_{R_1}$ and $I_{R_2}$ of $R_1$ and $R_2$ is written $I_{R_1} \texttt{++>} I_{R_2}$.
-Notice that the special arrow \texttt{++>}, which reminds the reader
-of covariance, is placed between the two relation instances, not
-between the two carriers. The signature relation instances and morphism will
-be typed in a context introducing variables for the parameters.
-
-The previous definitions are extended straightforwardly to $n$-ary morphisms,
-that are required to be simultaneously monotone on every argument.
-
-Morphisms can also be contravariant in one or more of their arguments.
-A morphism is contravariant on an argument associated to the relation instance
-$R$ if it is covariant on the same argument when the inverse relation
-$R^{-1}$ (\texttt{inverse R} in Coq) is considered.
-The special arrow \texttt{-{}->} is used in signatures
-for contravariant morphisms.
-
-Functions having arguments related by symmetric relations instances are both
-covariant and contravariant in those arguments. The special arrow
-\texttt{==>} is used in signatures for morphisms that are both covariant
-and contravariant.
-
-An instance of a parametric morphism $f$ with $n$ parameters is any term
-\texttt{f $t_1$ \ldots $t_n$}.
-
-\begin{cscexample}[Morphisms]
-Continuing the previous example, let
-\texttt{union: forall (A: Type), list A -> list A -> list A} perform the union
-of two sets by appending one list to the other. \texttt{union} is a binary
-morphism parametric over \texttt{A} that respects the relation instance
-\texttt{(set\_eq A)}. The latter condition is proved by showing
-\texttt{forall (A: Type) (S1 S1' S2 S2': list A), set\_eq A S1 S1' ->
- set\_eq A S2 S2' -> set\_eq A (union A S1 S2) (union A S1' S2')}.
-
-The signature of the function \texttt{union A} is
-\texttt{set\_eq A ==> set\_eq A ==> set\_eq A} for all \texttt{A}.
-\end{cscexample}
-
-\begin{cscexample}[Contravariant morphism]
-The division function \texttt{Rdiv: R -> R -> R} is a morphism of
-signature \texttt{le ++> le -{}-> le} where \texttt{le} is
-the usual order relation over real numbers. Notice that division is
-covariant in its first argument and contravariant in its second
-argument.
-\end{cscexample}
-
-Leibniz equality is a relation and every function is a
-morphism that respects Leibniz equality. Unfortunately, Leibniz equality
-is not always the intended equality for a given structure.
-
-In the next section we will describe the commands to register terms as
-parametric relations and morphisms. Several tactics that deal with equality
-in \Coq\ can also work with the registered relations.
-The exact list of tactic will be given in Sect.~\ref{setoidtactics}.
-For instance, the
-tactic \texttt{reflexivity} can be used to close a goal $R~n~n$ whenever
-$R$ is an instance of a registered reflexive relation. However, the tactics
-that replace in a context $C[]$ one term with another one related by $R$
-must verify that $C[]$ is a morphism that respects the intended relation.
-Currently the verification consists in checking whether $C[]$ is a syntactic
-composition of morphism instances that respects some obvious
-compatibility constraints.
-
-\begin{cscexample}[Rewriting]
-Continuing the previous examples, suppose that the user must prove
-\texttt{set\_eq int (union int (union int S1 S2) S2) (f S1 S2)} under the
-hypothesis \texttt{H: set\_eq int S2 (@nil int)}. It is possible to
-use the \texttt{rewrite} tactic to replace the first two occurrences of
-\texttt{S2} with \texttt{@nil int} in the goal since the context
-\texttt{set\_eq int (union int (union int S1 nil) nil) (f S1 S2)}, being
-a composition of morphisms instances, is a morphism. However the tactic
-will fail replacing the third occurrence of \texttt{S2} unless \texttt{f}
-has also been declared as a morphism.
-\end{cscexample}
-
-\subsection{Adding new relations and morphisms}
-A parametric relation
-\textit{Aeq}\texttt{: forall ($y_1 : \beta_!$ \ldots $y_m : \beta_m$), relation (A $t_1$ \ldots $t_n$)} over
-\textit{(A : $\alpha_i$ -> \ldots $\alpha_n$ -> }\texttt{Type})
-can be declared with the following command:
-
-\comindex{Add Parametric Relation}
-\begin{quote}
- \texttt{Add Parametric Relation} ($x_1 : T_1$) \ldots ($x_n : T_k$) :
- \textit{(A $t_1$ \ldots $t_n$) (Aeq $t'_1$ \ldots $t'_m$)}\\
- ~\zeroone{\texttt{reflexivity proved by} \textit{refl}}\\
- ~\zeroone{\texttt{symmetry proved by} \textit{sym}}\\
- ~\zeroone{\texttt{transitivity proved by} \textit{trans}}\\
- \texttt{~as} \textit{id}.
-\end{quote}
-after having required the \texttt{Setoid} module with the
-\texttt{Require Setoid} command.
-
-The identifier \textit{id} gives a unique name to the morphism and it is
-used by the command to generate fresh names for automatically provided lemmas
-used internally.
-
-Notice that the carrier and relation parameters may refer to the context
-of variables introduced at the beginning of the declaration, but the
-instances need not be made only of variables.
-Also notice that \textit{A} is \emph{not} required to be a term
-having the same parameters as \textit{Aeq}, although that is often the
-case in practice (this departs from the previous implementation).
-
-\comindex{Add Relation}
-In case the carrier and relations are not parametric, one can use the
-command \texttt{Add Relation} instead, whose syntax is the same except
-there is no local context.
-
-The proofs of reflexivity, symmetry and transitivity can be omitted if the
-relation is not an equivalence relation. The proofs must be instances of the
-corresponding relation definitions: e.g. the proof of reflexivity must
-have a type convertible to \texttt{reflexive (A $t_1$ \ldots $t_n$) (Aeq $t'_1$ \ldots
- $t'_n$)}. Each proof may refer to the introduced variables as well.
-
-\begin{cscexample}[Parametric relation]
-For Leibniz equality, we may declare:
-\texttt{Add Parametric Relation (A : Type) :} \texttt{A (@eq A)}\\
-~\zeroone{\texttt{reflexivity proved by} \texttt{@refl\_equal A}}\\
-\ldots
-\end{cscexample}
-
-Some tactics
-(\texttt{reflexivity}, \texttt{symmetry}, \texttt{transitivity}) work only
-on relations that respect the expected properties. The remaining tactics
-(\texttt{replace}, \texttt{rewrite} and derived tactics such as
-\texttt{autorewrite}) do not require any properties over the relation.
-However, they are able to replace terms with related ones only in contexts
-that are syntactic compositions of parametric morphism instances declared with
-the following command.
-
-\comindex{Add Parametric Morphism}
-\begin{quote}
- \texttt{Add Parametric Morphism} ($x_1 : \T_1$) \ldots ($x_k : \T_k$) :
- (\textit{f $t_1$ \ldots $t_n$})\\
- \texttt{~with signature} \textit{sig}\\
- \texttt{~as id}.\\
- \texttt{Proof}\\
- ~\ldots\\
- \texttt{Qed}
-\end{quote}
-
-The command declares \textit{f} as a parametric morphism of signature
-\textit{sig}. The identifier \textit{id} gives a unique name to the morphism
-and it is used as the base name of the type class instance definition
-and as the name of the lemma that proves the well-definedness of the morphism.
-The parameters of the morphism as well as the signature may refer to the
-context of variables.
-The command asks the user to prove interactively that \textit{f} respects
-the relations identified from the signature.
-
-\begin{cscexample}
-We start the example by assuming a small theory over homogeneous sets and
-we declare set equality as a parametric equivalence relation and
-union of two sets as a parametric morphism.
-\begin{coq_example*}
-Require Export Setoid.
-Require Export Relation_Definitions.
-Set Implicit Arguments.
-Parameter set: Type -> Type.
-Parameter empty: forall A, set A.
-Parameter eq_set: forall A, set A -> set A -> Prop.
-Parameter union: forall A, set A -> set A -> set A.
-Axiom eq_set_refl: forall A, reflexive _ (eq_set (A:=A)).
-Axiom eq_set_sym: forall A, symmetric _ (eq_set (A:=A)).
-Axiom eq_set_trans: forall A, transitive _ (eq_set (A:=A)).
-Axiom empty_neutral: forall A (S: set A), eq_set (union S (empty A)) S.
-Axiom union_compat:
- forall (A : Type),
- forall x x' : set A, eq_set x x' ->
- forall y y' : set A, eq_set y y' ->
- eq_set (union x y) (union x' y').
-Add Parametric Relation A : (set A) (@eq_set A)
- reflexivity proved by (eq_set_refl (A:=A))
- symmetry proved by (eq_set_sym (A:=A))
- transitivity proved by (eq_set_trans (A:=A))
- as eq_set_rel.
-Add Parametric Morphism A : (@union A) with
-signature (@eq_set A) ==> (@eq_set A) ==> (@eq_set A) as union_mor.
-Proof. exact (@union_compat A). Qed.
-\end{coq_example*}
-
-\end{cscexample}
-
-It is possible to reduce the burden of specifying parameters using
-(maximally inserted) implicit arguments. If \texttt{A} is always set as
-maximally implicit in the previous example, one can write:
-
-\begin{coq_eval}
-Reset Initial.
-Require Export Setoid.
-Require Export Relation_Definitions.
-Parameter set: Type -> Type.
-Parameter empty: forall {A}, set A.
-Parameter eq_set: forall {A}, set A -> set A -> Prop.
-Parameter union: forall {A}, set A -> set A -> set A.
-Axiom eq_set_refl: forall {A}, reflexive (set A) eq_set.
-Axiom eq_set_sym: forall {A}, symmetric (set A) eq_set.
-Axiom eq_set_trans: forall {A}, transitive (set A) eq_set.
-Axiom empty_neutral: forall A (S: set A), eq_set (union S empty) S.
-Axiom union_compat:
- forall (A : Type),
- forall x x' : set A, eq_set x x' ->
- forall y y' : set A, eq_set y y' ->
- eq_set (union x y) (union x' y').
-\end{coq_eval}
-
-\begin{coq_example*}
-Add Parametric Relation A : (set A) eq_set
- reflexivity proved by eq_set_refl
- symmetry proved by eq_set_sym
- transitivity proved by eq_set_trans
- as eq_set_rel.
-Add Parametric Morphism A : (@union A) with
- signature eq_set ==> eq_set ==> eq_set as union_mor.
-Proof. exact (@union_compat A). Qed.
-\end{coq_example*}
-
-We proceed now by proving a simple lemma performing a rewrite step
-and then applying reflexivity, as we would do working with Leibniz
-equality. Both tactic applications are accepted
-since the required properties over \texttt{eq\_set} and
-\texttt{union} can be established from the two declarations above.
-
-\begin{coq_example*}
-Goal forall (S: set nat),
- eq_set (union (union S empty) S) (union S S).
-Proof. intros. rewrite empty_neutral. reflexivity. Qed.
-\end{coq_example*}
-
-The tables of relations and morphisms are managed by the type class
-instance mechanism. The behavior on section close is to generalize
-the instances by the variables of the section (and possibly hypotheses
-used in the proofs of instance declarations) but not to export them in
-the rest of the development for proof search. One can use the
-\texttt{Existing Instance} command to do so outside the section,
-using the name of the declared morphism suffixed by \texttt{\_Morphism},
-or use the \texttt{Global} modifier for the corresponding class instance
-declaration (see \S\ref{setoid:first-class}) at definition time.
-When loading a compiled file or importing a module,
-all the declarations of this module will be loaded.
-
-\subsection{Rewriting and non reflexive relations}
-To replace only one argument of an n-ary morphism it is necessary to prove
-that all the other arguments are related to themselves by the respective
-relation instances.
-
-\begin{cscexample}
-To replace \texttt{(union S empty)} with \texttt{S} in
-\texttt{(union (union S empty) S) (union S S)} the rewrite tactic must
-exploit the monotony of \texttt{union} (axiom \texttt{union\_compat} in
-the previous example). Applying \texttt{union\_compat} by hand we are left
-with the goal \texttt{eq\_set (union S S) (union S S)}.
-\end{cscexample}
-
-When the relations associated to some arguments are not reflexive, the tactic
-cannot automatically prove the reflexivity goals, that are left to the user.
-
-Setoids whose relation are partial equivalence relations (PER)
-are useful to deal with partial functions. Let \texttt{R} be a PER. We say
-that an element \texttt{x} is defined if \texttt{R x x}. A partial function
-whose domain comprises all the defined elements only is declared as a
-morphism that respects \texttt{R}. Every time a rewriting step is performed
-the user must prove that the argument of the morphism is defined.
-
-\begin{cscexample}
-Let \texttt{eqO} be \texttt{fun x y => x = y $\land$ ~x$\neq$ 0} (the smaller PER over
-non zero elements). Division can be declared as a morphism of signature
-\texttt{eq ==> eq0 ==> eq}. Replace \texttt{x} with \texttt{y} in
-\texttt{div x n = div y n} opens the additional goal \texttt{eq0 n n} that
-is equivalent to \texttt{n=n $\land$ n$\neq$0}.
-\end{cscexample}
-
-\subsection{Rewriting and non symmetric relations}
-When the user works up to relations that are not symmetric, it is no longer
-the case that any covariant morphism argument is also contravariant. As a
-result it is no longer possible to replace a term with a related one in
-every context, since the obtained goal implies the previous one if and
-only if the replacement has been performed in a contravariant position.
-In a similar way, replacement in an hypothesis can be performed only if
-the replaced term occurs in a covariant position.
-
-\begin{cscexample}[Covariance and contravariance]
-Suppose that division over real numbers has been defined as a
-morphism of signature \texttt{Z.div: Z.lt ++> Z.lt -{}-> Z.lt} (i.e.
-\texttt{Z.div} is increasing in its first argument, but decreasing on the
-second one). Let \texttt{<} denotes \texttt{Z.lt}.
-Under the hypothesis \texttt{H: x < y} we have
-\texttt{k < x / y -> k < x / x}, but not
-\texttt{k < y / x -> k < x / x}.
-Dually, under the same hypothesis \texttt{k < x / y -> k < y / y} holds,
-but \texttt{k < y / x -> k < y / y} does not.
-Thus, if the current goal is \texttt{k < x / x}, it is possible to replace
-only the second occurrence of \texttt{x} (in contravariant position)
-with \texttt{y} since the obtained goal must imply the current one.
-On the contrary, if \texttt{k < x / x} is
-an hypothesis, it is possible to replace only the first occurrence of
-\texttt{x} (in covariant position) with \texttt{y} since
-the current hypothesis must imply the obtained one.
-\end{cscexample}
-
-Contrary to the previous implementation, no specific error message will
-be raised when trying to replace a term that occurs in the wrong
-position. It will only fail because the rewriting constraints are not
-satisfiable. However it is possible to use the \texttt{at} modifier to
-specify which occurrences should be rewritten.
-
-As expected, composing morphisms together propagates the variance annotations by
-switching the variance every time a contravariant position is traversed.
-\begin{cscexample}
-Let us continue the previous example and let us consider the goal
-\texttt{x / (x / x) < k}. The first and third occurrences of \texttt{x} are
-in a contravariant position, while the second one is in covariant position.
-More in detail, the second occurrence of \texttt{x} occurs
-covariantly in \texttt{(x / x)} (since division is covariant in its first
-argument), and thus contravariantly in \texttt{x / (x / x)} (since division
-is contravariant in its second argument), and finally covariantly in
-\texttt{x / (x / x) < k} (since \texttt{<}, as every transitive relation,
-is contravariant in its first argument with respect to the relation itself).
-\end{cscexample}
-
-\subsection{Rewriting in ambiguous setoid contexts}
-One function can respect several different relations and thus it can be
-declared as a morphism having multiple signatures.
-
-\begin{cscexample}
-Union over homogeneous lists can be given all the following signatures:
-\texttt{eq ==> eq ==> eq} (\texttt{eq} being the equality over ordered lists)
-\texttt{set\_eq ==> set\_eq ==> set\_eq} (\texttt{set\_eq} being the equality
-over unordered lists up to duplicates),
-\texttt{multiset\_eq ==> multiset\_eq ==> multiset\_eq} (\texttt{multiset\_eq}
-being the equality over unordered lists).
-\end{cscexample}
-
-To declare multiple signatures for a morphism, repeat the \texttt{Add Morphism}
-command.
-
-When morphisms have multiple signatures it can be the case that a rewrite
-request is ambiguous, since it is unclear what relations should be used to
-perform the rewriting. Contrary to the previous implementation, the
-tactic will always choose the first possible solution to the set of
-constraints generated by a rewrite and will not try to find \emph{all}
-possible solutions to warn the user about.
-
-\asection{Commands and tactics}
-\subsection{First class setoids and morphisms}
-\label{setoid:first-class}
-
-The implementation is based on a first-class representation of
-properties of relations and morphisms as type classes. That is,
-the various combinations of properties on relations and morphisms
-are represented as records and instances of theses classes are put
-in a hint database.
-For example, the declaration:
-
-\begin{quote}
- \texttt{Add Parametric Relation} ($x_1 : T_1$) \ldots ($x_n : T_k$) :
- \textit{(A $t_1$ \ldots $t_n$) (Aeq $t'_1$ \ldots $t'_m$)}\\
- ~\zeroone{\texttt{reflexivity proved by} \textit{refl}}\\
- ~\zeroone{\texttt{symmetry proved by} \textit{sym}}\\
- ~\zeroone{\texttt{transitivity proved by} \textit{trans}}\\
- \texttt{~as} \textit{id}.
-\end{quote}
-
-is equivalent to an instance declaration:
-
-\begin{quote}
- \texttt{Instance} ($x_1 : T_1$) \ldots ($x_n : T_k$) \texttt{=>}
- \textit{id} : \texttt{@Equivalence} \textit{(A $t_1$ \ldots $t_n$) (Aeq
- $t'_1$ \ldots $t'_m$)} :=\\
- ~\zeroone{\texttt{Equivalence\_Reflexive :=} \textit{refl}}\\
- ~\zeroone{\texttt{Equivalence\_Symmetric :=} \textit{sym}}\\
- ~\zeroone{\texttt{Equivalence\_Transitive :=} \textit{trans}}.
-\end{quote}
-
-The declaration itself amounts to the definition of an object of the
-record type \texttt{Coq.Classes.RelationClasses.Equivalence} and a
-hint added to the \texttt{typeclass\_instances} hint database.
-Morphism declarations are also instances of a type class defined in
-\texttt{Classes.Morphisms}.
-See the documentation on type classes \ref{typeclasses} and
-the theories files in \texttt{Classes} for further explanations.
-
-One can inform the rewrite tactic about morphisms and relations just by
-using the typeclass mechanism to declare them using \texttt{Instance}
-and \texttt{Context} vernacular commands.
-Any object of type \texttt{Proper} (the type of morphism declarations)
-in the local context will also be automatically used by the rewriting
-tactic to solve constraints.
-
-Other representations of first class setoids and morphisms can also
-be handled by encoding them as records. In the following example,
-the projections of the setoid relation and of the morphism function
-can be registered as parametric relations and morphisms.
-\begin{cscexample}[First class setoids]
-
-\begin{coq_example*}
-Require Import Relation_Definitions Setoid.
-Record Setoid: Type :=
-{ car:Type;
- eq:car->car->Prop;
- refl: reflexive _ eq;
- sym: symmetric _ eq;
- trans: transitive _ eq
-}.
-Add Parametric Relation (s : Setoid) : (@car s) (@eq s)
- reflexivity proved by (refl s)
- symmetry proved by (sym s)
- transitivity proved by (trans s) as eq_rel.
-Record Morphism (S1 S2:Setoid): Type :=
-{ f:car S1 ->car S2;
- compat: forall (x1 x2: car S1), eq S1 x1 x2 -> eq S2 (f x1) (f x2) }.
-Add Parametric Morphism (S1 S2 : Setoid) (M : Morphism S1 S2) :
- (@f S1 S2 M) with signature (@eq S1 ==> @eq S2) as apply_mor.
-Proof. apply (compat S1 S2 M). Qed.
-Lemma test: forall (S1 S2:Setoid) (m: Morphism S1 S2)
- (x y: car S1), eq S1 x y -> eq S2 (f _ _ m x) (f _ _ m y).
-Proof. intros. rewrite H. reflexivity. Qed.
-\end{coq_example*}
-\end{cscexample}
-
-\subsection{Tactics enabled on user provided relations}
-\label{setoidtactics}
-The following tactics, all prefixed by \texttt{setoid\_},
-deal with arbitrary
-registered relations and morphisms. Moreover, all the corresponding unprefixed
-tactics (i.e. \texttt{reflexivity}, \texttt{symmetry}, \texttt{transitivity},
-\texttt{replace}, \texttt{rewrite})
-have been extended to fall back to their prefixed counterparts when
-the relation involved is not Leibniz equality. Notice, however, that using
-the prefixed tactics it is possible to pass additional arguments such as
-\texttt{using relation}.
-\medskip
-
-\tacindex{setoid\_reflexivity}
-\texttt{setoid\_reflexivity}
-
-\tacindex{setoid\_symmetry}
-\texttt{setoid\_symmetry} \zeroone{\texttt{in} \textit{ident}}
-
-\tacindex{setoid\_transitivity}
-\texttt{setoid\_transitivity}
-
-\tacindex{setoid\_rewrite}
-\texttt{setoid\_rewrite} \zeroone{\textit{orientation}} \textit{term}
-~\zeroone{\texttt{at} \textit{occs}} ~\zeroone{\texttt{in} \textit{ident}}
-
-\tacindex{setoid\_replace}
-\texttt{setoid\_replace} \textit{term} \texttt{with} \textit{term}
-~\zeroone{\texttt{in} \textit{ident}}
-~\zeroone{\texttt{using relation} \textit{term}}
-~\zeroone{\texttt{by} \textit{tactic}}
-\medskip
-
-The \texttt{using relation}
-arguments cannot be passed to the unprefixed form. The latter argument
-tells the tactic what parametric relation should be used to replace
-the first tactic argument with the second one. If omitted, it defaults
-to the \texttt{DefaultRelation} instance on the type of the objects.
-By default, it means the most recent \texttt{Equivalence} instance in
-the environment, but it can be customized by declaring new
-\texttt{DefaultRelation} instances. As Leibniz equality is a declared
-equivalence, it will fall back to it if no other relation is declared on
-a given type.
-
-Every derived tactic that is based on the unprefixed forms of the tactics
-considered above will also work up to user defined relations. For instance,
-it is possible to register hints for \texttt{autorewrite} that are
-not proof of Leibniz equalities. In particular it is possible to exploit
-\texttt{autorewrite} to simulate normalization in a term rewriting system
-up to user defined equalities.
-
-\subsection{Printing relations and morphisms}
-The \texttt{Print Instances} command can be used to show the list of
-currently registered \texttt{Reflexive} (using \texttt{Print Instances Reflexive}),
-\texttt{Symmetric} or \texttt{Transitive} relations,
-\texttt{Equivalence}s, \texttt{PreOrder}s, \texttt{PER}s, and
-Morphisms (implemented as \texttt{Proper} instances). When
- the rewriting tactics refuse to replace a term in a context
-because the latter is not a composition of morphisms, the \texttt{Print Instances}
-commands can be useful to understand what additional morphisms should be
-registered.
-
-\subsection{Deprecated syntax and backward incompatibilities}
-Due to backward compatibility reasons, the following syntax for the
-declaration of setoids and morphisms is also accepted.
-
-\comindex{Add Setoid}
-\begin{quote}
- \texttt{Add Setoid} \textit{A Aeq ST} \texttt{as} \textit{ident}
-\end{quote}
-where \textit{Aeq} is a congruence relation without parameters,
-\textit{A} is its carrier and \textit{ST} is an object of type
-\texttt{(Setoid\_Theory A Aeq)} (i.e. a record packing together the reflexivity,
-symmetry and transitivity lemmas). Notice that the syntax is not completely
-backward compatible since the identifier was not required.
-
-\comindex{Add Morphism}
-\begin{quote}
- \texttt{Add Morphism} \textit{f}:\textit{ident}.\\
- Proof.\\
- \ldots\\
- Qed.
-\end{quote}
-
-The latter command also is restricted to the declaration of morphisms without
-parameters. It is not fully backward compatible since the property the user
-is asked to prove is slightly different: for $n$-ary morphisms the hypotheses
-of the property are permuted; moreover, when the morphism returns a
-proposition, the property is now stated using a bi-implication in place of
-a simple implication. In practice, porting an old development to the new
-semantics is usually quite simple.
-
-Notice that several limitations of the old implementation have been lifted.
-In particular, it is now possible to declare several relations with the
-same carrier and several signatures for the same morphism. Moreover, it is
-now also possible to declare several morphisms having the same signature.
-Finally, the replace and rewrite tactics can be used to replace terms in
-contexts that were refused by the old implementation. As discussed in
-the next section, the semantics of the new \texttt{setoid\_rewrite}
-command differs slightly from the old one and \texttt{rewrite}.
-
-\asection{Extensions}
-\subsection{Rewriting under binders}
-
-\textbf{Warning}: Due to compatibility issues, this feature is enabled only when calling
-the \texttt{setoid\_rewrite} tactics directly and not \texttt{rewrite}.
-
-To be able to rewrite under binding constructs, one must declare
-morphisms with respect to pointwise (setoid) equivalence of functions.
-Example of such morphisms are the standard \texttt{all} and \texttt{ex}
-combinators for universal and existential quantification respectively.
-They are declared as morphisms in the \texttt{Classes.Morphisms\_Prop}
-module. For example, to declare that universal quantification is a
-morphism for logical equivalence:
-
-\begin{coq_eval}
-Reset Initial.
-Require Import Setoid Morphisms.
-\end{coq_eval}
-\begin{coq_example}
-Instance all_iff_morphism (A : Type) :
- Proper (pointwise_relation A iff ==> iff) (@all A).
-Proof. simpl_relation.
-\end{coq_example}
-\begin{coq_eval}
-Admitted.
-\end{coq_eval}
-
-One then has to show that if two predicates are equivalent at every
-point, their universal quantifications are equivalent. Once we have
-declared such a morphism, it will be used by the setoid rewriting tactic
-each time we try to rewrite under an \texttt{all} application (products
-in \Prop{} are implicitly translated to such applications).
-
-Indeed, when rewriting under a lambda, binding variable $x$, say from
-$P~x$ to $Q~x$ using the relation \texttt{iff}, the tactic will generate
-a proof of \texttt{pointwise\_relation A iff (fun x => P x) (fun x => Q
-x)} from the proof of \texttt{iff (P x) (Q x)} and a constraint of the
-form \texttt{Proper (pointwise\_relation A iff ==> ?) m} will be
-generated for the surrounding morphism \texttt{m}.
-
-Hence, one can add higher-order combinators as morphisms by providing
-signatures using pointwise extension for the relations on the functional
-arguments (or whatever subrelation of the pointwise extension).
-For example, one could declare the \texttt{map} combinator on lists as
-a morphism:
-\begin{coq_eval}
-Require Import List Setoid Morphisms.
-Set Implicit Arguments.
-Inductive list_equiv {A:Type} (eqA : relation A) : relation (list A) :=
-| eq_nil : list_equiv eqA nil nil
-| eq_cons : forall x y, eqA x y ->
- forall l l', list_equiv eqA l l' -> list_equiv eqA (x :: l) (y :: l').
-Generalizable All Variables.
-\end{coq_eval}
-\begin{coq_example*}
-Instance map_morphism `{Equivalence A eqA, Equivalence B eqB} :
- Proper ((eqA ==> eqB) ==> list_equiv eqA ==> list_equiv eqB) (@map A B).
-\end{coq_example*}
-
-where \texttt{list\_equiv} implements an equivalence on lists
-parameterized by an equivalence on the elements.
-
-Note that when one does rewriting with a lemma under a binder
-using \texttt{setoid\_rewrite}, the application of the lemma may capture
-the bound variable, as the semantics are different from rewrite where
-the lemma is first matched on the whole term. With the new
-\texttt{setoid\_rewrite}, matching is done on each subterm separately
-and in its local environment, and all matches are rewritten
-\emph{simultaneously} by default. The semantics of the previous
-\texttt{setoid\_rewrite} implementation can almost be recovered using
-the \texttt{at 1} modifier.
-
-\subsection{Sub-relations}
-
-Sub-relations can be used to specify that one relation is included in
-another, so that morphisms signatures for one can be used for the other.
-If a signature mentions a relation $R$ on the left of an arrow
-\texttt{==>}, then the signature also applies for any relation $S$ that
-is smaller than $R$, and the inverse applies on the right of an arrow.
-One can then declare only a few morphisms instances that generate the complete set
-of signatures for a particular constant. By default, the only declared
-subrelation is \texttt{iff}, which is a subrelation of \texttt{impl}
-and \texttt{inverse impl} (the dual of implication). That's why we can
-declare only two morphisms for conjunction:
-\texttt{Proper (impl ==> impl ==> impl) and} and
-\texttt{Proper (iff ==> iff ==> iff) and}. This is sufficient to satisfy
-any rewriting constraints arising from a rewrite using \texttt{iff},
-\texttt{impl} or \texttt{inverse impl} through \texttt{and}.
-
-Sub-relations are implemented in \texttt{Classes.Morphisms} and are a
-prime example of a mostly user-space extension of the algorithm.
-
-\subsection{Constant unfolding}
-
-The resolution tactic is based on type classes and hence regards user-defined
-constants as transparent by default. This may slow down the resolution
-due to a lot of unifications (all the declared \texttt{Proper}
-instances are tried at each node of the search tree).
-To speed it up, declare your constant as rigid for proof search
-using the command \texttt{Typeclasses Opaque} (see \S
-\ref{TypeclassesTransparency}).
-
-\asection{Strategies for rewriting}
-
-\subsection{Definitions}
-The generalized rewriting tactic is based on a set of strategies that
-can be combined to obtain custom rewriting procedures. Its set of
-strategies is based on Elan's rewriting strategies
-\cite{Luttik97specificationof}. Rewriting strategies are applied using
-the tactic \texttt{rewrite\_strat $s$} where $s$ is a strategy
-expression. Strategies are defined inductively as described by the
-following grammar:
-
-\def\str#1{\texttt{#1}}
-
-\def\strline#1#2{& \vert & #1 & \text{#2}}
-\def\strlinea#1#2#3{& \vert & \str{#1}~#2 & \text{#3}}
-
-\[\begin{array}{lcll}
- s, t, u & ::= & ( s ) & \text{strategy} \\
- \strline{c}{lemma} \\
- \strline{\str{<-}~c}{lemma, right-to-left} \\
-
- \strline{\str{fail}}{failure} \\
- \strline{\str{id}}{identity} \\
- \strline{\str{refl}}{reflexivity} \\
- \strlinea{progress}{s}{progress} \\
- \strlinea{try}{s}{failure catch} \\
-
- \strline{s~\str{;}~u}{composition} \\
- \strline{\str{choice}~s~t}{left-biased choice} \\
-
- \strlinea{repeat}{s}{iteration (+)} \\
- \strlinea{any}{s}{iteration (*)} \\
-
- \strlinea{subterm}{s}{one subterm} \\
- \strlinea{subterms}{s}{all subterms} \\
- \strlinea{innermost}{s}{innermost first} \\
- \strlinea{outermost}{s}{outermost first}\\
- \strlinea{bottomup}{s}{bottom-up} \\
- \strlinea{topdown}{s}{top-down} \\
-
- \strlinea{hints}{hintdb}{apply hint} \\
- \strlinea{terms}{c \ldots c}{any of the terms}\\
- \strlinea{eval}{redexpr}{apply reduction}\\
- \strlinea{fold}{c}{fold expression}
-\end{array}\]
-
-Actually a few of these are defined in term of the others using
-a primitive fixpoint operator:
-
-\[\begin{array}{lcl}
- \str{try}~s & = & \str{choice}~s~\str{id} \\
- \str{any}~s & = & \str{fix}~u. \str{try}~(s~\str{;}~u) \\
- \str{repeat}~s & = & s~\str{;}~\str{any}~s \\
- \str{bottomup}~s & = &
- \str{fix}~bu. (\str{choice}~(\str{progress}~(\str{subterms}~bu))~s)~\str{;}~\str{try}~bu \\
- \str{topdown}~s & = &
- \str{fix}~td. (\str{choice}~s~(\str{progress}~(\str{subterms}~td)))~\str{;}~\str{try}~td \\
- \str{innermost}~s & = & \str{fix}~i. (\str{choice}~(\str{subterm}~i)~s) \\
- \str{outermost}~s & = &
- \str{fix}~o. (\str{choice}~s~(\str{subterm}~o))
-\end{array}\]
-
-The basic control strategy semantics are straightforward: strategies are
-applied to subterms of the term to rewrite, starting from the root of
-the term. The lemma strategies unify the left-hand-side of the
-lemma with the current subterm and on success rewrite it to the
-right-hand-side. Composition can be used to continue rewriting on the
-current subterm. The fail strategy always fails while the identity
-strategy succeeds without making progress. The reflexivity strategy
-succeeds, making progress using a reflexivity proof of
-rewriting. Progress tests progress of the argument strategy and fails if
-no progress was made, while \str{try} always succeeds, catching
-failures. Choice is left-biased: it will launch the first strategy and
-fall back on the second one in case of failure. One can iterate a
-strategy at least 1 time using \str{repeat} and at least 0 times using
-\str{any}.
-
-The \str{subterm} and \str{subterms} strategies apply their argument
-strategy $s$ to respectively one or all subterms of the current term
-under consideration, left-to-right. \str{subterm} stops at the first
-subterm for which $s$ made progress. The composite strategies
-\str{innermost} and \str{outermost} perform a single innermost our outermost
-rewrite using their argument strategy. Their counterparts
-\str{bottomup} and \str{topdown} perform as many rewritings as possible,
-starting from the bottom or the top of the term.
-
-Hint databases created for \texttt{autorewrite} can also be used by
-\texttt{rewrite\_strat} using the \str{hints} strategy that applies any
-of the lemmas at the current subterm. The \str{terms} strategy takes the
-lemma names directly as arguments. The \str{eval} strategy expects a
-reduction expression (see \S\ref{Conversion-tactics}) and succeeds if it
-reduces the subterm under consideration. The \str{fold} strategy takes a
-term $c$ and tries to \emph{unify} it to the current subterm, converting
-it to $c$ on success, it is stronger than the tactic \texttt{fold}.
-
-
-\subsection{Usage}
-\tacindex{rewrite\_strat}
-
-\texttt{rewrite\_strat}~\textit{s}~\zeroone{\texttt{in} \textit{ident}}:
-
- Rewrite using the strategy \textit{s} in hypothesis \textit{ident}
- or the conclusion.
-
- \begin{ErrMsgs}
- \item \errindex{Nothing to rewrite}. If the strategy failed.
- \item \errindex{No progress made}. If the strategy succeeded but
- made no progress.
- \item \errindex{Unable to satisfy the rewriting constraints}.
- If the strategy succeeded and made progress but the corresponding
- rewriting constraints are not satisfied.
- \end{ErrMsgs}
-
-
-The \texttt{setoid\_rewrite}~c tactic is basically equivalent to
-\texttt{rewrite\_strat}~(\str{outermost}~c).
-
-
-
-
-
-%%% Local Variables:
-%%% mode: latex
-%%% TeX-master: "Reference-Manual"
-%%% End:
diff --git a/doc/sphinx/addendum/extraction.rst b/doc/sphinx/addendum/extraction.rst
new file mode 100644
index 000000000..d7f97edab
--- /dev/null
+++ b/doc/sphinx/addendum/extraction.rst
@@ -0,0 +1,586 @@
+.. _extraction:
+
+.. include:: ../replaces.rst
+
+Extraction of programs in OCaml and Haskell
+============================================
+
+:Authors: Jean-Christophe Filliâtre and Pierre Letouzey
+
+We present here the |Coq| extraction commands, used to build certified
+and relatively efficient functional programs, extracting them from
+either |Coq| functions or |Coq| proofs of specifications. The
+functional languages available as output are currently OCaml, Haskell
+and Scheme. In the following, "ML" will be used (abusively) to refer
+to any of the three.
+
+Before using any of the commands or options described in this chapter,
+the extraction framework should first be loaded explicitly
+via ``Require Extraction``, or via the more robust
+``From Coq Require Extraction``.
+Note that in earlier versions of Coq, these commands and options were
+directly available without any preliminary ``Require``.
+
+.. coqtop:: in
+
+ Require Extraction.
+
+Generating ML Code
+-------------------
+
+.. note::
+
+ In the following, a qualified identifier `qualid`
+ can be used to refer to any kind of |Coq| global "object" : constant,
+ inductive type, inductive constructor or module name.
+
+The next two commands are meant to be used for rapid preview of
+extraction. They both display extracted term(s) inside |Coq|.
+
+.. cmd:: Extraction @qualid.
+
+ Extraction of the mentioned object in the |Coq| toplevel.
+
+.. cmd:: Recursive Extraction @qualid ... @qualid.
+
+ Recursive extraction of all the mentioned objects and
+ all their dependencies in the |Coq| toplevel.
+
+All the following commands produce real ML files. User can choose to
+produce one monolithic file or one file per |Coq| library.
+
+.. cmd:: Extraction "@file" @qualid ... @qualid.
+
+ Recursive extraction of all the mentioned objects and all
+ their dependencies in one monolithic `file`.
+ Global and local identifiers are renamed according to the chosen ML
+ language to fulfill its syntactic conventions, keeping original
+ names as much as possible.
+
+.. cmd:: Extraction Library @ident.
+
+ Extraction of the whole |Coq| library ``ident.v`` to an ML module
+ ``ident.ml``. In case of name clash, identifiers are here renamed
+ using prefixes ``coq_`` or ``Coq_`` to ensure a session-independent
+ renaming.
+
+.. cmd:: Recursive Extraction Library @ident.
+
+ Extraction of the |Coq| library ``ident.v`` and all other modules
+ ``ident.v`` depends on.
+
+.. cmd:: Separate Extraction @qualid ... @qualid.
+
+ Recursive extraction of all the mentioned objects and all
+ their dependencies, just as ``Extraction "file"``,
+ but instead of producing one monolithic file, this command splits
+ the produced code in separate ML files, one per corresponding Coq
+ ``.v`` file. This command is hence quite similar to
+ ``Recursive Extraction Library``, except that only the needed
+ parts of Coq libraries are extracted instead of the whole.
+ The naming convention in case of name clash is the same one as
+ ``Extraction Library``: identifiers are here renamed using prefixes
+ ``coq_`` or ``Coq_``.
+
+The following command is meant to help automatic testing of
+the extraction, see for instance the ``test-suite`` directory
+in the |Coq| sources.
+
+.. cmd:: Extraction TestCompile @qualid ... @qualid.
+
+ All the mentioned objects and all their dependencies are extracted
+ to a temporary OCaml file, just as in ``Extraction "file"``. Then
+ this temporary file and its signature are compiled with the same
+ OCaml compiler used to built |Coq|. This command succeeds only
+ if the extraction and the OCaml compilation succeed. It fails
+ if the current target language of the extraction is not OCaml.
+
+Extraction Options
+-------------------
+
+Setting the target language
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The ability to fix target language is the first and more important
+of the extraction options. Default is ``Ocaml``.
+
+.. cmd:: Extraction Language Ocaml.
+.. cmd:: Extraction Language Haskell.
+.. cmd:: Extraction Language Scheme.
+
+Inlining and optimizations
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Since OCaml is a strict language, the extracted code has to
+be optimized in order to be efficient (for instance, when using
+induction principles we do not want to compute all the recursive calls
+but only the needed ones). So the extraction mechanism provides an
+automatic optimization routine that will be called each time the user
+want to generate OCaml programs. The optimizations can be split in two
+groups: the type-preserving ones (essentially constant inlining and
+reductions) and the non type-preserving ones (some function
+abstractions of dummy types are removed when it is deemed safe in order
+to have more elegant types). Therefore some constants may not appear in the
+resulting monolithic OCaml program. In the case of modular extraction,
+even if some inlining is done, the inlined constant are nevertheless
+printed, to ensure session-independent programs.
+
+Concerning Haskell, type-preserving optimizations are less useful
+because of laziness. We still make some optimizations, for example in
+order to produce more readable code.
+
+The type-preserving optimizations are controlled by the following |Coq| options:
+
+.. opt:: Extraction Optimize.
+
+ Default is on. This controls all type-preserving optimizations made on
+ the ML terms (mostly reduction of dummy beta/iota redexes, but also
+ simplifications on Cases, etc). Turn this option off if you want a
+ ML term as close as possible to the Coq term.
+
+.. opt:: Extraction Conservative Types.
+
+ Default is off. This controls the non type-preserving optimizations
+ made on ML terms (which try to avoid function abstraction of dummy
+ types). Turn this option on to make sure that ``e:t``
+ implies that ``e':t'`` where ``e'`` and ``t'`` are the extracted
+ code of ``e`` and ``t`` respectively.
+
+.. opt:: Extraction KeepSingleton.
+
+ Default is off. Normally, when the extraction of an inductive type
+ produces a singleton type (i.e. a type with only one constructor, and
+ only one argument to this constructor), the inductive structure is
+ removed and this type is seen as an alias to the inner type.
+ The typical example is ``sig``. This option allows disabling this
+ optimization when one wishes to preserve the inductive structure of types.
+
+.. opt:: Extraction AutoInline.
+
+ Default is on. The extraction mechanism inlines the bodies of
+ some defined constants, according to some heuristics
+ like size of bodies, uselessness of some arguments, etc.
+ Those heuristics are not always perfect; if you want to disable
+ this feature, turn this option off.
+
+.. cmd:: Extraction Inline @qualid ... @qualid.
+
+ In addition to the automatic inline feature, the constants
+ mentionned by this command will always be inlined during extraction.
+
+.. cmd:: Extraction NoInline @qualid ... @qualid.
+
+ Conversely, the constants mentionned by this command will
+ never be inlined during extraction.
+
+.. cmd:: Print Extraction Inline.
+
+ Prints the current state of the table recording the custom inlinings
+ declared by the two previous commands.
+
+.. cmd:: Reset Extraction Inline.
+
+ Empties the table recording the custom inlinings (see the
+ previous commands).
+
+**Inlining and printing of a constant declaration:**
+
+A user can explicitly ask for a constant to be extracted by two means:
+
+ * by mentioning it on the extraction command line
+
+ * by extracting the whole |Coq| module of this constant.
+
+In both cases, the declaration of this constant will be present in the
+produced file. But this same constant may or may not be inlined in
+the following terms, depending on the automatic/custom inlining mechanism.
+
+For the constants non-explicitly required but needed for dependency
+reasons, there are two cases:
+
+ * If an inlining decision is taken, whether automatically or not,
+ all occurrences of this constant are replaced by its extracted body,
+ and this constant is not declared in the generated file.
+
+ * If no inlining decision is taken, the constant is normally
+ declared in the produced file.
+
+Extra elimination of useless arguments
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The following command provides some extra manual control on the
+code elimination performed during extraction, in a way which
+is independent but complementary to the main elimination
+principles of extraction (logical parts and types).
+
+.. cmd:: Extraction Implicit @qualid [ @ident ... @ident ].
+
+ This experimental command allows declaring some arguments of
+ `qualid` as implicit, i.e. useless in extracted code and hence to
+ be removed by extraction. Here `qualid` can be any function or
+ inductive constructor, and the given `ident` are the names of
+ the concerned arguments. In fact, an argument can also be referred
+ by a number indicating its position, starting from 1.
+
+When an actual extraction takes place, an error is normally raised if the
+``Extraction Implicit`` declarations cannot be honored, that is
+if any of the implicited variables still occurs in the final code.
+This behavior can be relaxed via the following option:
+
+.. opt:: Extraction SafeImplicits.
+
+ Default is on. When this option is off, a warning is emitted
+ instead of an error if some implicited variables still occur in the
+ final code of an extraction. This way, the extracted code may be
+ obtained nonetheless and reviewed manually to locate the source of the issue
+ (in the code, some comments mark the location of these remaining
+ implicited variables).
+ Note that this extracted code might not compile or run properly,
+ depending of the use of these remaining implicited variables.
+
+Realizing axioms
+~~~~~~~~~~~~~~~~
+
+Extraction will fail if it encounters an informative axiom not realized.
+A warning will be issued if it encounters a logical axiom, to remind the
+user that inconsistent logical axioms may lead to incorrect or
+non-terminating extracted terms.
+
+It is possible to assume some axioms while developing a proof. Since
+these axioms can be any kind of proposition or object or type, they may
+perfectly well have some computational content. But a program must be
+a closed term, and of course the system cannot guess the program which
+realizes an axiom. Therefore, it is possible to tell the system
+what ML term corresponds to a given axiom.
+
+.. cmd:: Extract Constant @qualid => @string.
+
+ Give an ML extraction for the given constant.
+ The `string` may be an identifier or a quoted string.
+
+.. cmd:: Extract Inlined Constant @qualid => @string.
+
+ Same as the previous one, except that the given ML terms will
+ be inlined everywhere instead of being declared via a ``let``.
+
+ .. note::
+
+ This command is sugar for an ``Extract Constant`` followed
+ by a ``Extraction Inline``. Hence a ``Reset Extraction Inline``
+ will have an effect on the realized and inlined axiom.
+
+.. caution:: It is the responsibility of the user to ensure that the ML
+ terms given to realize the axioms do have the expected types. In
+ fact, the strings containing realizing code are just copied to the
+ extracted files. The extraction recognizes whether the realized axiom
+ should become a ML type constant or a ML object declaration. For example:
+
+.. coqtop:: in
+
+ Axiom X:Set.
+ Axiom x:X.
+ Extract Constant X => "int".
+ Extract Constant x => "0".
+
+Notice that in the case of type scheme axiom (i.e. whose type is an
+arity, that is a sequence of product finished by a sort), then some type
+variables have to be given (as quoted strings). The syntax is then:
+
+.. cmdv:: Extract Constant @qualid @string ... @string => @string.
+
+The number of type variables is checked by the system. For example:
+
+.. coqtop:: in
+
+ Axiom Y : Set -> Set -> Set.
+ Extract Constant Y "'a" "'b" => " 'a * 'b ".
+
+Realizing an axiom via ``Extract Constant`` is only useful in the
+case of an informative axiom (of sort ``Type`` or ``Set``). A logical axiom
+have no computational content and hence will not appears in extracted
+terms. But a warning is nonetheless issued if extraction encounters a
+logical axiom. This warning reminds user that inconsistent logical
+axioms may lead to incorrect or non-terminating extracted terms.
+
+If an informative axiom has not been realized before an extraction, a
+warning is also issued and the definition of the axiom is filled with
+an exception labeled ``AXIOM TO BE REALIZED``. The user must then
+search these exceptions inside the extracted file and replace them by
+real code.
+
+Realizing inductive types
+~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The system also provides a mechanism to specify ML terms for inductive
+types and constructors. For instance, the user may want to use the ML
+native boolean type instead of |Coq| one. The syntax is the following:
+
+.. cmd:: Extract Inductive @qualid => @string [ @string ... @string ].
+
+ Give an ML extraction for the given inductive type. You must specify
+ extractions for the type itself (first `string`) and all its
+ constructors (all the `string` between square brackets). In this form,
+ the ML extraction must be an ML inductive datatype, and the native
+ pattern-matching of the language will be used.
+
+.. cmdv:: Extract Inductive @qualid => @string [ @string ... @string ] @string.
+
+ Same as before, with a final extra `string` that indicates how to
+ perform pattern-matching over this inductive type. In this form,
+ the ML extraction could be an arbitrary type.
+ For an inductive type with `k` constructors, the function used to
+ emulate the pattern-matching should expect `(k+1)` arguments, first the `k`
+ branches in functional form, and then the inductive element to
+ destruct. For instance, the match branch ``| S n => foo`` gives the
+ functional form ``(fun n -> foo)``. Note that a constructor with no
+ argument is considered to have one unit argument, in order to block
+ early evaluation of the branch: ``| O => bar`` leads to the functional
+ form ``(fun () -> bar)``. For instance, when extracting ``nat``
+ into OCaml ``int``, the code to provide has type:
+ ``(unit->'a)->(int->'a)->int->'a``.
+
+.. caution:: As for ``Extract Constant``, this command should be used with care:
+
+ * The ML code provided by the user is currently **not** checked at all by
+ extraction, even for syntax errors.
+
+ * Extracting an inductive type to a pre-existing ML inductive type
+ is quite sound. But extracting to a general type (by providing an
+ ad-hoc pattern-matching) will often **not** be fully rigorously
+ correct. For instance, when extracting ``nat`` to OCaml ``int``,
+ it is theoretically possible to build ``nat`` values that are
+ larger than OCaml ``max_int``. It is the user's responsibility to
+ be sure that no overflow or other bad events occur in practice.
+
+ * Translating an inductive type to an arbitrary ML type does **not**
+ magically improve the asymptotic complexity of functions, even if the
+ ML type is an efficient representation. For instance, when extracting
+ ``nat`` to OCaml ``int``, the function ``Nat.mul`` stays quadratic.
+ It might be interesting to associate this translation with
+ some specific ``Extract Constant`` when primitive counterparts exist.
+
+Typical examples are the following:
+
+.. coqtop:: in
+
+ Extract Inductive unit => "unit" [ "()" ].
+ Extract Inductive bool => "bool" [ "true" "false" ].
+ Extract Inductive sumbool => "bool" [ "true" "false" ].
+
+.. note::
+
+ When extracting to Ocaml, if an inductive constructor or type has arity 2 and
+ the corresponding string is enclosed by parentheses, and the string meets
+ Ocaml's lexical criteria for an infix symbol, then the rest of the string is
+ used as infix constructor or type.
+
+.. coqtop:: in
+
+ Extract Inductive list => "list" [ "[]" "(::)" ].
+ Extract Inductive prod => "(*)" [ "(,)" ].
+
+As an example of translation to a non-inductive datatype, let's turn
+``nat`` into OCaml ``int`` (see caveat above):
+
+.. coqtop:: in
+
+ Extract Inductive nat => int [ "0" "succ" ] "(fun fO fS n -> if n=0 then fO () else fS (n-1))".
+
+Avoiding conflicts with existing filenames
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+When using ``Extraction Library``, the names of the extracted files
+directly depends from the names of the |Coq| files. It may happen that
+these filenames are in conflict with already existing files,
+either in the standard library of the target language or in other
+code that is meant to be linked with the extracted code.
+For instance the module ``List`` exists both in |Coq| and in OCaml.
+It is possible to instruct the extraction not to use particular filenames.
+
+.. cmd:: Extraction Blacklist @ident ... @ident.
+
+ Instruct the extraction to avoid using these names as filenames
+ for extracted code.
+
+.. cmd:: Print Extraction Blacklist.
+
+ Show the current list of filenames the extraction should avoid.
+
+.. cmd:: Reset Extraction Blacklist.
+
+ Allow the extraction to use any filename.
+
+For OCaml, a typical use of these commands is
+``Extraction Blacklist String List``.
+
+Differences between |Coq| and ML type systems
+----------------------------------------------
+
+Due to differences between |Coq| and ML type systems,
+some extracted programs are not directly typable in ML.
+We now solve this problem (at least in OCaml) by adding
+when needed some unsafe casting ``Obj.magic``, which give
+a generic type ``'a`` to any term.
+
+First, if some part of the program is *very* polymorphic, there
+may be no ML type for it. In that case the extraction to ML works
+alright but the generated code may be refused by the ML
+type-checker. A very well known example is the ``distr-pair``
+function:
+
+.. coqtop:: in
+
+ Definition dp {A B:Type}(x:A)(y:B)(f:forall C:Type, C->C) := (f A x, f B y).
+
+In Ocaml, for instance, the direct extracted term would be::
+
+ let dp x y f = Pair((f () x),(f () y))
+
+and would have type::
+
+ dp : 'a -> 'a -> (unit -> 'a -> 'b) -> ('b,'b) prod
+
+which is not its original type, but a restriction.
+
+We now produce the following correct version::
+
+ let dp x y f = Pair ((Obj.magic f () x), (Obj.magic f () y))
+
+Secondly, some |Coq| definitions may have no counterpart in ML. This
+happens when there is a quantification over types inside the type
+of a constructor; for example:
+
+.. coqtop:: in
+
+ Inductive anything : Type := dummy : forall A:Set, A -> anything.
+
+which corresponds to the definition of an ML dynamic type.
+In OCaml, we must cast any argument of the constructor dummy
+(no GADT are produced yet by the extraction).
+
+Even with those unsafe castings, you should never get error like
+``segmentation fault``. In fact even if your program may seem
+ill-typed to the Ocaml type-checker, it can't go wrong : it comes
+from a Coq well-typed terms, so for example inductive types will always
+have the correct number of arguments, etc. Of course, when launching
+manually some extracted function, you should apply it to arguments
+of the right shape (from the |Coq| point-of-view).
+
+More details about the correctness of the extracted programs can be
+found in :cite:`Let02`.
+
+We have to say, though, that in most "realistic" programs, these problems do not
+occur. For example all the programs of Coq library are accepted by the OCaml
+type-checker without any ``Obj.magic`` (see examples below).
+
+Some examples
+-------------
+
+We present here two examples of extractions, taken from the
+|Coq| Standard Library. We choose OCaml as target language,
+but all can be done in the other dialects with slight modifications.
+We then indicate where to find other examples and tests of extraction.
+
+A detailed example: Euclidean division
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The file ``Euclid`` contains the proof of Euclidean division.
+The natural numbers used there are unary integers of type ``nat``,
+defined by two constructors ``O`` and ``S``.
+This module contains a theorem ``eucl_dev``, whose type is::
+
+ forall b:nat, b > 0 -> forall a:nat, diveucl a b
+
+where ``diveucl`` is a type for the pair of the quotient and the
+modulo, plus some logical assertions that disappear during extraction.
+We can now extract this program to OCaml:
+
+.. coqtop:: none
+
+ Reset Initial.
+
+.. coqtop:: all
+
+ Require Extraction.
+ Require Import Euclid Wf_nat.
+ Extraction Inline gt_wf_rec lt_wf_rec induction_ltof2.
+ Recursive Extraction eucl_dev.
+
+The inlining of ``gt_wf_rec`` and others is not
+mandatory. It only enhances readability of extracted code.
+You can then copy-paste the output to a file ``euclid.ml`` or let
+|Coq| do it for you with the following command::
+
+ Extraction "euclid" eucl_dev.
+
+Let us play the resulting program (in an OCaml toplevel)::
+
+ #use "euclid.ml";;
+ type nat = O | S of nat
+ type sumbool = Left | Right
+ val sub : nat -> nat -> nat = <fun>
+ val le_lt_dec : nat -> nat -> sumbool = <fun>
+ val le_gt_dec : nat -> nat -> sumbool = <fun>
+ type diveucl = Divex of nat * nat
+ val eucl_dev : nat -> nat -> diveucl = <fun>
+
+ # eucl_dev (S (S O)) (S (S (S (S (S O)))));;
+ - : diveucl = Divex (S (S O), S O)
+
+It is easier to test on OCaml integers::
+
+ # let rec nat_of_int = function 0 -> O | n -> S (nat_of_int (n-1));;
+ val nat_of_int : int -> nat = <fun>
+
+ # let rec int_of_nat = function O -> 0 | S p -> 1+(int_of_nat p);;
+ val int_of_nat : nat -> int = <fun>
+
+ # let div a b =
+ let Divex (q,r) = eucl_dev (nat_of_int b) (nat_of_int a)
+ in (int_of_nat q, int_of_nat r);;
+ val div : int -> int -> int * int = <fun>
+
+ # div 173 15;;
+ - : int * int = (11, 8)
+
+Note that these ``nat_of_int`` and ``int_of_nat`` are now
+available via a mere ``Require Import ExtrOcamlIntConv`` and then
+adding these functions to the list of functions to extract. This file
+``ExtrOcamlIntConv.v`` and some others in ``plugins/extraction/``
+are meant to help building concrete program via extraction.
+
+Extraction's horror museum
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Some pathological examples of extraction are grouped in the file
+``test-suite/success/extraction.v`` of the sources of |Coq|.
+
+Users' Contributions
+~~~~~~~~~~~~~~~~~~~~
+
+Several of the |Coq| Users' Contributions use extraction to produce
+certified programs. In particular the following ones have an automatic
+extraction test:
+
+ * ``additions`` : https://github.com/coq-contribs/additions
+ * ``bdds`` : https://github.com/coq-contribs/bdds
+ * ``canon-bdds`` : https://github.com/coq-contribs/canon-bdds
+ * ``chinese`` : https://github.com/coq-contribs/chinese
+ * ``continuations`` : https://github.com/coq-contribs/continuations
+ * ``coq-in-coq`` : https://github.com/coq-contribs/coq-in-coq
+ * ``exceptions`` : https://github.com/coq-contribs/exceptions
+ * ``firing-squad`` : https://github.com/coq-contribs/firing-squad
+ * ``founify`` : https://github.com/coq-contribs/founify
+ * ``graphs`` : https://github.com/coq-contribs/graphs
+ * ``higman-cf`` : https://github.com/coq-contribs/higman-cf
+ * ``higman-nw`` : https://github.com/coq-contribs/higman-nw
+ * ``hardware`` : https://github.com/coq-contribs/hardware
+ * ``multiplier`` : https://github.com/coq-contribs/multiplier
+ * ``search-trees`` : https://github.com/coq-contribs/search-trees
+ * ``stalmarck`` : https://github.com/coq-contribs/stalmarck
+
+Note that ``continuations`` and ``multiplier`` are a bit particular. They are
+examples of developments where ``Obj.magic`` are needed. This is
+probably due to an heavy use of impredicativity. After compilation, those
+two examples run nonetheless, thanks to the correction of the
+extraction :cite:`Let02`.
diff --git a/doc/sphinx/addendum/generalized-rewriting.rst b/doc/sphinx/addendum/generalized-rewriting.rst
new file mode 100644
index 000000000..da9e97e6f
--- /dev/null
+++ b/doc/sphinx/addendum/generalized-rewriting.rst
@@ -0,0 +1,845 @@
+.. _generalizedrewriting:
+
+-----------------------
+ Generalized rewriting
+-----------------------
+
+:Author: Matthieu Sozeau
+
+Generalized rewriting
+=====================
+
+
+This chapter presents the extension of several equality related
+tactics to work over user-defined structures (called setoids) that are
+equipped with ad-hoc equivalence relations meant to behave as
+equalities. Actually, the tactics have also been generalized to
+relations weaker then equivalences (e.g. rewriting systems). The
+toolbox also extends the automatic rewriting capabilities of the
+system, allowing the specification of custom strategies for rewriting.
+
+This documentation is adapted from the previous setoid documentation
+by Claudio Sacerdoti Coen (based on previous work by Clément Renard).
+The new implementation is a drop-in replacement for the old one
+[#tabareau]_, hence most of the documentation still applies.
+
+The work is a complete rewrite of the previous implementation, based
+on the type class infrastructure. It also improves on and generalizes
+the previous implementation in several ways:
+
+
++ User-extensible algorithm. The algorithm is separated in two parts:
+ generations of the rewriting constraints (done in ML) and solving of
+ these constraints using type class resolution. As type class
+ resolution is extensible using tactics, this allows users to define
+ general ways to solve morphism constraints.
++ Sub-relations. An example extension to the base algorithm is the
+ ability to define one relation as a subrelation of another so that
+ morphism declarations on one relation can be used automatically for
+ the other. This is done purely using tactics and type class search.
++ Rewriting under binders. It is possible to rewrite under binders in
+ the new implementation, if one provides the proper morphisms. Again,
+ most of the work is handled in the tactics.
++ First-class morphisms and signatures. Signatures and morphisms are
+ ordinary Coq terms, hence they can be manipulated inside Coq, put
+ inside structures and lemmas about them can be proved inside the
+ system. Higher-order morphisms are also allowed.
++ Performance. The implementation is based on a depth-first search for
+ the first solution to a set of constraints which can be as fast as
+ linear in the size of the term, and the size of the proof term is
+ linear in the size of the original term. Besides, the extensibility
+ allows the user to customize the proof search if necessary.
+
+.. [#tabareau] Nicolas Tabareau helped with the gluing.
+
+Introduction to generalized rewriting
+-------------------------------------
+
+
+Relations and morphisms
+~~~~~~~~~~~~~~~~~~~~~~~
+
+A parametric *relation* ``R`` is any term of type
+``forall (x1 :T1 ) ... (xn :Tn ), relation A``.
+The expression ``A``, which depends on ``x1 ... xn`` , is called the *carrier*
+of the relation and ``R`` is said to be a relation over ``A``; the list
+``x1,...,xn`` is the (possibly empty) list of parameters of the relation.
+
+**Example 1 (Parametric relation):**
+
+It is possible to implement finite sets of elements of type ``A`` as
+unordered list of elements of type ``A``.
+The function ``set_eq: forall (A: Type), relation (list A)``
+satisfied by two lists with the same elements is a parametric relation
+over ``(list A)`` with one parameter ``A``. The type of ``set_eq``
+is convertible with ``forall (A: Type), list A -> list A -> Prop.``
+
+An *instance* of a parametric relation ``R`` with n parameters is any term
+``(R t1 ... tn )``.
+
+Let ``R`` be a relation over ``A`` with ``n`` parameters. A term is a parametric
+proof of reflexivity for ``R`` if it has type
+``forall (x1 :T1 ) ... (xn :Tn), reflexive (R x1 ... xn )``.
+Similar definitions are given for parametric proofs of symmetry and transitivity.
+
+**Example 2 (Parametric relation (cont.)):**
+
+The ``set_eq`` relation of the previous example can be proved to be
+reflexive, symmetric and transitive. A parametric unary function ``f`` of type
+``forall (x1 :T1 ) ... (xn :Tn ), A1 -> A2`` covariantly respects two parametric relation instances
+``R1`` and ``R2`` if, whenever ``x``, ``y`` satisfy ``R1 x y``, their images (``f x``) and (``f y``)
+satisfy ``R2 (f x) (f y)``. An ``f`` that respects its input and output
+relations will be called a unary covariant *morphism*. We can also say
+that ``f`` is a monotone function with respect to ``R1`` and ``R2`` . The
+sequence ``x1 ... xn`` represents the parameters of the morphism.
+
+Let ``R1`` and ``R2`` be two parametric relations. The *signature* of a
+parametric morphism of type ``forall (x1 :T1 ) ... (xn :Tn ), A1 -> A2``
+that covariantly respects two instances :math:`I_{R_1}` and :math:`I_{R_2}` of ``R1`` and ``R2``
+is written :math:`I_{R_1} ++> I_{R_2}`. Notice that the special arrow ++>, which
+reminds the reader of covariance, is placed between the two relation
+instances, not between the two carriers. The signature relation
+instances and morphism will be typed in a context introducing
+variables for the parameters.
+
+The previous definitions are extended straightforwardly to n-ary
+morphisms, that are required to be simultaneously monotone on every
+argument.
+
+Morphisms can also be contravariant in one or more of their arguments.
+A morphism is contravariant on an argument associated to the relation
+instance :math`R` if it is covariant on the same argument when the inverse
+relation :math:`R^{−1}` (``inverse R`` in Coq) is considered. The special arrow ``-->``
+is used in signatures for contravariant morphisms.
+
+Functions having arguments related by symmetric relations instances
+are both covariant and contravariant in those arguments. The special
+arrow ``==>`` is used in signatures for morphisms that are both
+covariant and contravariant.
+
+An instance of a parametric morphism :math:`f` with :math:`n`
+parameters is any term :math:`f \, t_1 \ldots t_n`.
+
+**Example 3 (Morphisms):**
+
+Continuing the previous example, let ``union: forall (A: Type), list A -> list A -> list A``
+perform the union of two sets by appending one list to the other. ``union` is a binary
+morphism parametric over ``A`` that respects the relation instance
+``(set_eq A)``. The latter condition is proved by showing:
+
+.. coqtop:: in
+
+ forall (A: Type) (S1 S1’ S2 S2’: list A),
+ set_eq A S1 S1’ ->
+ set_eq A S2 S2’ ->
+ set_eq A (union A S1 S2) (union A S1’ S2’).
+
+The signature of the function ``union A`` is ``set_eq A ==> set_eq A ==> set_eq A``
+for all ``A``.
+
+**Example 4 (Contravariant morphism):**
+
+The division function ``Rdiv: R -> R -> R`` is a morphism of signature
+``le ++> le --> le`` where ``le`` is the usual order relation over
+real numbers. Notice that division is covariant in its first argument
+and contravariant in its second argument.
+
+Leibniz equality is a relation and every function is a morphism that
+respects Leibniz equality. Unfortunately, Leibniz equality is not
+always the intended equality for a given structure.
+
+In the next section we will describe the commands to register terms as
+parametric relations and morphisms. Several tactics that deal with
+equality in Coq can also work with the registered relations. The exact
+list of tactic will be given :ref:`in this section <tactics-enabled-on-user-provided-relations>`.
+For instance, the tactic reflexivity can be used to close a goal ``R n n`` whenever ``R``
+is an instance of a registered reflexive relation. However, the
+tactics that replace in a context ``C[]`` one term with another one
+related by ``R`` must verify that ``C[]`` is a morphism that respects the
+intended relation. Currently the verification consists in checking
+whether ``C[]`` is a syntactic composition of morphism instances that respects some obvious
+compatibility constraints.
+
+
+**Example 5 (Rewriting):**
+
+Continuing the previous examples, suppose that the user must prove
+``set_eq int (union int (union int S1 S2) S2) (f S1 S2)`` under the
+hypothesis ``H: set_eq int S2 (@nil int)``. It
+is possible to use the ``rewrite`` tactic to replace the first two
+occurrences of ``S2`` with ``@nil int`` in the goal since the
+context ``set_eq int (union int (union int S1 nil) nil) (f S1 S2)``,
+being a composition of morphisms instances, is a morphism. However the
+tactic will fail replacing the third occurrence of ``S2`` unless ``f``
+has also been declared as a morphism.
+
+
+Adding new relations and morphisms
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+A parametric relation :g:`Aeq: forall (y1 : β1 ... ym : βm )`,
+:g:`relation (A t1 ... tn)` over :g:`(A : αi -> ... αn -> Type)` can be
+declared with the following command:
+
+.. cmd:: Add Parametric Relation (x1 : T1) ... (xn : Tk) : (A t1 ... tn) (Aeq t′1 ... t′m ) {? reflexivity proved by refl} {? symmetry proved by sym} {? transitivity proved by trans} as @ident.
+
+after having required the ``Setoid`` module with the ``Require Setoid``
+command.
+
+The :g:`@ident` gives a unique name to the morphism and it is used
+by the command to generate fresh names for automatically provided
+lemmas used internally.
+
+Notice that the carrier and relation parameters may refer to the
+context of variables introduced at the beginning of the declaration,
+but the instances need not be made only of variables. Also notice that
+``A`` is *not* required to be a term having the same parameters as ``Aeq``,
+although that is often the case in practice (this departs from the
+previous implementation).
+
+
+.. cmd:: Add Relation
+
+In case the carrier and relations are not parametric, one can use this command
+instead, whose syntax is the same except there is no local context.
+
+The proofs of reflexivity, symmetry and transitivity can be omitted if
+the relation is not an equivalence relation. The proofs must be
+instances of the corresponding relation definitions: e.g. the proof of
+reflexivity must have a type convertible to
+:g:`reflexive (A t1 ... tn) (Aeq t′ 1 …t′ n )`.
+Each proof may refer to the introduced variables as well.
+
+**Example 6 (Parametric relation):**
+
+For Leibniz equality, we may declare:
+
+.. coqtop:: in
+
+ Add Parametric Relation (A : Type) : A (@eq A)
+ [reflexivity proved by @refl_equal A]
+ ...
+
+Some tactics (``reflexivity``, ``symmetry``, ``transitivity``) work only on
+relations that respect the expected properties. The remaining tactics
+(``replace``, ``rewrite`` and derived tactics such as ``autorewrite``) do not
+require any properties over the relation. However, they are able to
+replace terms with related ones only in contexts that are syntactic
+compositions of parametric morphism instances declared with the
+following command.
+
+.. cmd:: Add Parametric Morphism (x1 : T1 ) ... (xk : Tk ) : (f t1 ... tn ) with signature sig as @ident.
+
+The command declares ``f`` as a parametric morphism of signature ``sig``. The
+identifier ``id`` gives a unique name to the morphism and it is used as
+the base name of the type class instance definition and as the name of
+the lemma that proves the well-definedness of the morphism. The
+parameters of the morphism as well as the signature may refer to the
+context of variables. The command asks the user to prove interactively
+that ``f`` respects the relations identified from the signature.
+
+**Example 7:**
+
+We start the example by assuming a small theory over
+homogeneous sets and we declare set equality as a parametric
+equivalence relation and union of two sets as a parametric morphism.
+
+.. coqtop:: in
+
+ Require Export Setoid.
+ Require Export Relation_Definitions.
+
+ Set Implicit Arguments.
+
+ Parameter set: Type -> Type.
+ Parameter empty: forall A, set A.
+ Parameter eq_set: forall A, set A -> set A -> Prop.
+ Parameter union: forall A, set A -> set A -> set A.
+
+ Axiom eq_set_refl: forall A, reflexive _ (eq_set (A:=A)).
+ Axiom eq_set_sym: forall A, symmetric _ (eq_set (A:=A)).
+ Axiom eq_set_trans: forall A, transitive _ (eq_set (A:=A)).
+ Axiom empty_neutral: forall A (S: set A), eq_set (union S (empty A)) S.
+
+ Axiom union_compat: forall (A : Type),
+ forall x x' : set A, eq_set x x' ->
+ forall y y' : set A, eq_set y y' ->
+ eq_set (union x y) (union x' y').
+
+ Add Parametric Relation A : (set A) (@eq_set A)
+ reflexivity proved by (eq_set_refl (A:=A))
+ symmetry proved by (eq_set_sym (A:=A))
+ transitivity proved by (eq_set_trans (A:=A))
+ as eq_set_rel.
+
+ Add Parametric Morphism A : (@union A) with
+ signature (@eq_set A) ==> (@eq_set A) ==> (@eq_set A) as union_mor.
+ Proof.
+ exact (@union_compat A).
+ Qed.
+
+It is possible to reduce the burden of specifying parameters using
+(maximally inserted) implicit arguments. If ``A`` is always set as
+maximally implicit in the previous example, one can write:
+
+.. coqtop:: in
+
+ Add Parametric Relation A : (set A) eq_set
+ reflexivity proved by eq_set_refl
+ symmetry proved by eq_set_sym
+ transitivity proved by eq_set_trans
+ as eq_set_rel.
+
+.. coqtop:: in
+
+ Add Parametric Morphism A : (@union A) with
+ signature eq_set ==> eq_set ==> eq_set as union_mor.
+
+.. coqtop:: in
+
+ Proof. exact (@union_compat A). Qed.
+
+We proceed now by proving a simple lemma performing a rewrite step and
+then applying reflexivity, as we would do working with Leibniz
+equality. Both tactic applications are accepted since the required
+properties over ``eq_set`` and ``union`` can be established from the two
+declarations above.
+
+.. coqtop:: in
+
+ Goal forall (S: set nat),
+ eq_set (union (union S empty) S) (union S S).
+
+.. coqtop:: in
+
+ Proof. intros. rewrite empty_neutral. reflexivity. Qed.
+
+The tables of relations and morphisms are managed by the type class
+instance mechanism. The behavior on section close is to generalize the
+instances by the variables of the section (and possibly hypotheses
+used in the proofs of instance declarations) but not to export them in
+the rest of the development for proof search. One can use the
+``Existing Instance`` command to do so outside the section, using the name of the
+declared morphism suffixed by ``_Morphism``, or use the ``Global`` modifier
+for the corresponding class instance declaration
+(see :ref:`First Class Setoids and Morphisms <first-class-setoids-and-morphisms>`) at
+definition time. When loading a compiled file or importing a module,
+all the declarations of this module will be loaded.
+
+
+Rewriting and non reflexive relations
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+To replace only one argument of an n-ary morphism it is necessary to
+prove that all the other arguments are related to themselves by the
+respective relation instances.
+
+**Example 8:**
+
+To replace ``(union S empty)`` with ``S`` in ``(union (union S empty) S) (union S S)``
+the rewrite tactic must exploit the monotony of ``union`` (axiom ``union_compat``
+in the previous example). Applying ``union_compat`` by hand we are left with the
+goal ``eq_set (union S S) (union S S)``.
+
+When the relations associated to some arguments are not reflexive, the
+tactic cannot automatically prove the reflexivity goals, that are left
+to the user.
+
+Setoids whose relation are partial equivalence relations (PER) are
+useful to deal with partial functions. Let ``R`` be a PER. We say that an
+element ``x`` is defined if ``R x x``. A partial function whose domain
+comprises all the defined elements only is declared as a morphism that
+respects ``R``. Every time a rewriting step is performed the user must
+prove that the argument of the morphism is defined.
+
+**Example 9:**
+
+Let ``eqO`` be ``fun x y => x = y /\ x <> 0`` (the
+smaller PER over non zero elements). Division can be declared as a
+morphism of signature ``eq ==> eq0 ==> eq``. Replace ``x`` with
+``y`` in ``div x n = div y n`` opens the additional goal ``eq0 n n``
+that is equivalent to ``n = n /\ n <> 0``.
+
+
+Rewriting and non symmetric relations
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+When the user works up to relations that are not symmetric, it is no
+longer the case that any covariant morphism argument is also
+contravariant. As a result it is no longer possible to replace a term
+with a related one in every context, since the obtained goal implies
+the previous one if and only if the replacement has been performed in
+a contravariant position. In a similar way, replacement in an
+hypothesis can be performed only if the replaced term occurs in a
+covariant position.
+
+**Example 10 (Covariance and contravariance):**
+
+Suppose that division over real numbers has been defined as a morphism of signature
+``Z.div: Z.lt ++> Z.lt --> Z.lt`` (i.e. ``Z.div`` is increasing in
+its first argument, but decreasing on the second one). Let ``<``
+denotes ``Z.lt``. Under the hypothesis ``H: x < y`` we have
+``k < x / y -> k < x / x``, but not ``k < y / x -> k < x / x``. Dually,
+under the same hypothesis ``k < x / y -> k < y / y`` holds, but
+``k < y / x -> k < y / y`` does not. Thus, if the current goal is
+``k < x / x``, it is possible to replace only the second occurrence of
+``x`` (in contravariant position) with ``y`` since the obtained goal
+must imply the current one. On the contrary, if ``k < x / x`` is an
+hypothesis, it is possible to replace only the first occurrence of
+``x`` (in covariant position) with ``y`` since the current
+hypothesis must imply the obtained one.
+
+Contrary to the previous implementation, no specific error message
+will be raised when trying to replace a term that occurs in the wrong
+position. It will only fail because the rewriting constraints are not
+satisfiable. However it is possible to use the at modifier to specify
+which occurrences should be rewritten.
+
+As expected, composing morphisms together propagates the variance
+annotations by switching the variance every time a contravariant
+position is traversed.
+
+**Example 11:**
+
+Let us continue the previous example and let us consider
+the goal ``x / (x / x) < k``. The first and third occurrences of
+``x`` are in a contravariant position, while the second one is in
+covariant position. More in detail, the second occurrence of ``x``
+occurs covariantly in ``(x / x)`` (since division is covariant in
+its first argument), and thus contravariantly in ``x / (x / x)``
+(since division is contravariant in its second argument), and finally
+covariantly in ``x / (x / x) < k`` (since ``<``, as every
+transitive relation, is contravariant in its first argument with
+respect to the relation itself).
+
+
+Rewriting in ambiguous setoid contexts
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+One function can respect several different relations and thus it can
+be declared as a morphism having multiple signatures.
+
+**Example 12:**
+
+
+Union over homogeneous lists can be given all the
+following signatures: ``eq ==> eq ==> eq`` (``eq`` being the
+equality over ordered lists) ``set_eq ==> set_eq ==> set_eq``
+(``set_eq`` being the equality over unordered lists up to duplicates),
+``multiset_eq ==> multiset_eq ==> multiset_eq`` (``multiset_eq``
+being the equality over unordered lists).
+
+To declare multiple signatures for a morphism, repeat the ``Add Morphism``
+command.
+
+When morphisms have multiple signatures it can be the case that a
+rewrite request is ambiguous, since it is unclear what relations
+should be used to perform the rewriting. Contrary to the previous
+implementation, the tactic will always choose the first possible
+solution to the set of constraints generated by a rewrite and will not
+try to find *all* possible solutions to warn the user about.
+
+
+Commands and tactics
+--------------------
+
+
+.. _first-class-setoids-and-morphisms:
+
+First class setoids and morphisms
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+
+
+The implementation is based on a first-class representation of
+properties of relations and morphisms as type classes. That is, the
+various combinations of properties on relations and morphisms are
+represented as records and instances of theses classes are put in a
+hint database. For example, the declaration:
+
+.. coqtop:: in
+
+ Add Parametric Relation (x1 : T1) ... (xn : Tk) : (A t1 ... tn) (Aeq t′1 ... t′m)
+ [reflexivity proved by refl]
+ [symmetry proved by sym]
+ [transitivity proved by trans]
+ as id.
+
+
+is equivalent to an instance declaration:
+
+.. coqtop:: in
+
+ Instance (x1 : T1) ... (xn : Tk) => id : @Equivalence (A t1 ... tn) (Aeq t′1 ... t′m) :=
+ [Equivalence_Reflexive := refl]
+ [Equivalence_Symmetric := sym]
+ [Equivalence_Transitive := trans].
+
+The declaration itself amounts to the definition of an object of the
+record type ``Coq.Classes.RelationClasses.Equivalence`` and a hint added
+to the ``typeclass_instances`` hint database. Morphism declarations are
+also instances of a type class defined in ``Classes.Morphisms``. See the
+documentation on type classes :ref:`TODO-chapter-20-type-classes`
+and the theories files in Classes for further explanations.
+
+One can inform the rewrite tactic about morphisms and relations just
+by using the typeclass mechanism to declare them using Instance and
+Context vernacular commands. Any object of type Proper (the type of
+morphism declarations) in the local context will also be automatically
+used by the rewriting tactic to solve constraints.
+
+Other representations of first class setoids and morphisms can also be
+handled by encoding them as records. In the following example, the
+projections of the setoid relation and of the morphism function can be
+registered as parametric relations and morphisms.
+
+**Example 13 (First class setoids):**
+
+.. coqtop:: in
+
+ Require Import Relation_Definitions Setoid.
+
+ Record Setoid: Type :=
+ { car: Type;
+ eq: car -> car -> Prop;
+ refl: reflexive _ eq;
+ sym: symmetric _ eq;
+ trans: transitive _ eq
+ }.
+
+ Add Parametric Relation (s : Setoid) : (@car s) (@eq s)
+ reflexivity proved by (refl s)
+ symmetry proved by (sym s)
+ transitivity proved by (trans s) as eq_rel.
+
+ Record Morphism (S1 S2:Setoid): Type :=
+ { f: car S1 -> car S2;
+ compat: forall (x1 x2: car S1), eq S1 x1 x2 -> eq S2 (f x1) (f x2)
+ }.
+
+ Add Parametric Morphism (S1 S2 : Setoid) (M : Morphism S1 S2) :
+ (@f S1 S2 M) with signature (@eq S1 ==> @eq S2) as apply_mor.
+ Proof. apply (compat S1 S2 M). Qed.
+
+ Lemma test: forall (S1 S2:Setoid) (m: Morphism S1 S2)
+ (x y: car S1), eq S1 x y -> eq S2 (f _ _ m x) (f _ _ m y).
+ Proof. intros. rewrite H. reflexivity. Qed.
+
+.. _tactics-enabled-on-user-provided-relations:
+
+Tactics enabled on user provided relations
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The following tactics, all prefixed by ``setoid_``, deal with arbitrary
+registered relations and morphisms. Moreover, all the corresponding
+unprefixed tactics (i.e. ``reflexivity``, ``symmetry``, ``transitivity``,
+``replace``, ``rewrite``) have been extended to fall back to their prefixed
+counterparts when the relation involved is not Leibniz equality.
+Notice, however, that using the prefixed tactics it is possible to
+pass additional arguments such as ``using relation``.
+
+.. tacv:: setoid_reflexivity
+
+.. tacv:: setoid_symmetry [in @ident]
+
+.. tacv:: setoid_transitivity
+
+.. tacv:: setoid_rewrite [@orientation] @term [at @occs] [in @ident]
+
+.. tacv:: setoid_replace @term with @term [in @ident] [using relation @term] [by @tactic]
+
+
+The ``using relation`` arguments cannot be passed to the unprefixed form.
+The latter argument tells the tactic what parametric relation should
+be used to replace the first tactic argument with the second one. If
+omitted, it defaults to the ``DefaultRelation`` instance on the type of
+the objects. By default, it means the most recent ``Equivalence`` instance
+in the environment, but it can be customized by declaring
+new ``DefaultRelation`` instances. As Leibniz equality is a declared
+equivalence, it will fall back to it if no other relation is declared
+on a given type.
+
+Every derived tactic that is based on the unprefixed forms of the
+tactics considered above will also work up to user defined relations.
+For instance, it is possible to register hints for ``autorewrite`` that
+are not proof of Leibniz equalities. In particular it is possible to
+exploit ``autorewrite`` to simulate normalization in a term rewriting
+system up to user defined equalities.
+
+
+Printing relations and morphisms
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The ``Print Instances`` command can be used to show the list of currently
+registered ``Reflexive`` (using ``Print Instances Reflexive``), ``Symmetric``
+or ``Transitive`` relations, Equivalences, PreOrders, PERs, and Morphisms
+(implemented as ``Proper`` instances). When the rewriting tactics refuse
+to replace a term in a context because the latter is not a composition
+of morphisms, the ``Print Instances`` commands can be useful to understand
+what additional morphisms should be registered.
+
+
+Deprecated syntax and backward incompatibilities
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Due to backward compatibility reasons, the following syntax for the
+declaration of setoids and morphisms is also accepted.
+
+.. tacv:: Add Setoid @A @Aeq @ST as @ident
+
+where ``Aeq`` is a congruence relation without parameters, ``A`` is its carrier
+and ``ST`` is an object of type (``Setoid_Theory A Aeq``) (i.e. a record
+packing together the reflexivity, symmetry and transitivity lemmas).
+Notice that the syntax is not completely backward compatible since the
+identifier was not required.
+
+.. cmd:: Add Morphism f : @ident.
+
+The latter command also is restricted to the declaration of morphisms
+without parameters. It is not fully backward compatible since the
+property the user is asked to prove is slightly different: for n-ary
+morphisms the hypotheses of the property are permuted; moreover, when
+the morphism returns a proposition, the property is now stated using a
+bi-implication in place of a simple implication. In practice, porting
+an old development to the new semantics is usually quite simple.
+
+Notice that several limitations of the old implementation have been
+lifted. In particular, it is now possible to declare several relations
+with the same carrier and several signatures for the same morphism.
+Moreover, it is now also possible to declare several morphisms having
+the same signature. Finally, the replace and rewrite tactics can be
+used to replace terms in contexts that were refused by the old
+implementation. As discussed in the next section, the semantics of the
+new ``setoid_rewrite`` command differs slightly from the old one and
+``rewrite``.
+
+
+Extensions
+----------
+
+
+Rewriting under binders
+~~~~~~~~~~~~~~~~~~~~~~~
+
+warning:: Due to compatibility issues, this feature is enabled only
+when calling the ``setoid_rewrite`` tactics directly and not ``rewrite``.
+
+To be able to rewrite under binding constructs, one must declare
+morphisms with respect to pointwise (setoid) equivalence of functions.
+Example of such morphisms are the standard ``all`` and ``ex`` combinators for
+universal and existential quantification respectively. They are
+declared as morphisms in the ``Classes.Morphisms_Prop`` module. For
+example, to declare that universal quantification is a morphism for
+logical equivalence:
+
+.. coqtop:: in
+
+ Instance all_iff_morphism (A : Type) :
+ Proper (pointwise_relation A iff ==> iff) (@all A).
+
+.. coqtop:: all
+
+ Proof. simpl_relation.
+
+One then has to show that if two predicates are equivalent at every
+point, their universal quantifications are equivalent. Once we have
+declared such a morphism, it will be used by the setoid rewriting
+tactic each time we try to rewrite under an ``all`` application (products
+in ``Prop`` are implicitly translated to such applications).
+
+Indeed, when rewriting under a lambda, binding variable ``x``, say from ``P x``
+to ``Q x`` using the relation iff, the tactic will generate a proof of
+``pointwise_relation A iff (fun x => P x) (fun x => Q x)`` from the proof
+of ``iff (P x) (Q x)`` and a constraint of the form Proper
+``(pointwise_relation A iff ==> ?) m`` will be generated for the
+surrounding morphism ``m``.
+
+Hence, one can add higher-order combinators as morphisms by providing
+signatures using pointwise extension for the relations on the
+functional arguments (or whatever subrelation of the pointwise
+extension). For example, one could declare the ``map`` combinator on lists
+as a morphism:
+
+.. coqtop:: in
+
+ Instance map_morphism `{Equivalence A eqA, Equivalence B eqB} :
+ Proper ((eqA ==> eqB) ==> list_equiv eqA ==> list_equiv eqB) (@map A B).
+
+where ``list_equiv`` implements an equivalence on lists parameterized by
+an equivalence on the elements.
+
+Note that when one does rewriting with a lemma under a binder using
+``setoid_rewrite``, the application of the lemma may capture the bound
+variable, as the semantics are different from rewrite where the lemma
+is first matched on the whole term. With the new ``setoid_rewrite``,
+matching is done on each subterm separately and in its local
+environment, and all matches are rewritten *simultaneously* by
+default. The semantics of the previous ``setoid_rewrite`` implementation
+can almost be recovered using the ``at 1`` modifier.
+
+
+Sub-relations
+~~~~~~~~~~~~~
+
+Sub-relations can be used to specify that one relation is included in
+another, so that morphisms signatures for one can be used for the
+other. If a signature mentions a relation ``R`` on the left of an
+arrow ``==>``, then the signature also applies for any relation ``S`` that is
+smaller than ``R``, and the inverse applies on the right of an arrow. One
+can then declare only a few morphisms instances that generate the
+complete set of signatures for a particular constant. By default, the
+only declared subrelation is ``iff``, which is a subrelation of ``impl`` and
+``inverse impl`` (the dual of implication). That’s why we can declare only
+two morphisms for conjunction: ``Proper (impl ==> impl ==> impl) and`` and
+``Proper (iff ==> iff ==> iff) and``. This is sufficient to satisfy any
+rewriting constraints arising from a rewrite using ``iff``, ``impl`` or
+``inverse impl`` through ``and``.
+
+Sub-relations are implemented in ``Classes.Morphisms`` and are a prime
+example of a mostly user-space extension of the algorithm.
+
+
+Constant unfolding
+~~~~~~~~~~~~~~~~~~
+
+The resolution tactic is based on type classes and hence regards user-
+defined constants as transparent by default. This may slow down the
+resolution due to a lot of unifications (all the declared ``Proper``
+instances are tried at each node of the search tree). To speed it up,
+declare your constant as rigid for proof search using the command
+``Typeclasses Opaque`` (see :ref:`TODO-20.6.7-typeclasses-transparency`).
+
+
+Strategies for rewriting
+------------------------
+
+
+Definitions
+~~~~~~~~~~~
+
+The generalized rewriting tactic is based on a set of strategies that
+can be combined to obtain custom rewriting procedures. Its set of
+strategies is based on Elan’s rewriting strategies :ref:`TODO-102-biblio`. Rewriting
+strategies are applied using the tactic ``rewrite_strat s`` where ``s`` is a
+strategy expression. Strategies are defined inductively as described
+by the following grammar:
+
+.. productionlist:: rewriting
+ s, t, u : `strategy`
+ : | `lemma`
+ : | `lemma_right_to_left`
+ : | `failure`
+ : | `identity`
+ : | `reflexivity`
+ : | `progress`
+ : | `failure_catch`
+ : | `composition`
+ : | `left_biased_choice`
+ : | `iteration_one_or_more`
+ : | `iteration_zero_or_more`
+ : | `one_subterm`
+ : | `all_subterms`
+ : | `innermost_first`
+ : | `outermost_first`
+ : | `bottom_up`
+ : | `top_down`
+ : | `apply_hint`
+ : | `any_of_the_terms`
+ : | `apply_reduction`
+ : | `fold_expression`
+
+.. productionlist:: rewriting
+ strategy : "(" `s` ")"
+ lemma : `c`
+ lemma_right_to_left : "<-" `c`
+ failure : `fail`
+ identity : `id`
+ reflexivity : `refl`
+ progress : `progress` `s`
+ failure_catch : `try` `s`
+ composition : `s` ";" `u`
+ left_biased_choice : choice `s` `t`
+ iteration_one_or_more : `repeat` `s`
+ iteration_zero_or_more : `any` `s`
+ one_subterm : subterm `s`
+ all_subterms : subterms `s`
+ innermost_first : `innermost` `s`
+ outermost_first : `outermost` `s`
+ bottom_up : `bottomup` `s`
+ top_down : `topdown` `s`
+ apply_hint : hints `hintdb`
+ any_of_the_terms : terms (`c`)+
+ apply_reduction : eval `redexpr`
+ fold_expression : fold `c`
+
+
+Actually a few of these are defined in term of the others using a
+primitive fixpoint operator:
+
+.. productionlist:: rewriting
+ try `s` : choice `s` `id`
+ any `s` : fix `u`. try (`s` ; `u`)
+ repeat `s` : `s` ; `any` `s`
+ bottomup s : fix `bu`. (choice (progress (subterms bu)) s) ; try bu
+ topdown s : fix `td`. (choice s (progress (subterms td))) ; try td
+ innermost s : fix `i`. (choice (subterm i) s)
+ outermost s : fix `o`. (choice s (subterm o))
+
+The basic control strategy semantics are straightforward: strategies
+are applied to subterms of the term to rewrite, starting from the root
+of the term. The lemma strategies unify the left-hand-side of the
+lemma with the current subterm and on success rewrite it to the right-
+hand-side. Composition can be used to continue rewriting on the
+current subterm. The fail strategy always fails while the identity
+strategy succeeds without making progress. The reflexivity strategy
+succeeds, making progress using a reflexivity proof of rewriting.
+Progress tests progress of the argument strategy and fails if no
+progress was made, while ``try`` always succeeds, catching failures.
+Choice is left-biased: it will launch the first strategy and fall back
+on the second one in case of failure. One can iterate a strategy at
+least 1 time using ``repeat`` and at least 0 times using ``any``.
+
+The ``subterm`` and ``subterms`` strategies apply their argument strategy ``s`` to
+respectively one or all subterms of the current term under
+consideration, left-to-right. ``subterm`` stops at the first subterm for
+which ``s`` made progress. The composite strategies ``innermost`` and ``outermost``
+perform a single innermost or outermost rewrite using their argument
+strategy. Their counterparts ``bottomup`` and ``topdown`` perform as many
+rewritings as possible, starting from the bottom or the top of the
+term.
+
+Hint databases created for ``autorewrite`` can also be used
+by ``rewrite_strat`` using the ``hints`` strategy that applies any of the
+lemmas at the current subterm. The ``terms`` strategy takes the lemma
+names directly as arguments. The ``eval`` strategy expects a reduction
+expression (see :ref:`TODO-8.7-performing-computations`) and succeeds
+if it reduces the subterm under consideration. The ``fold`` strategy takes
+a term ``c`` and tries to *unify* it to the current subterm, converting it to ``c``
+on success, it is stronger than the tactic ``fold``.
+
+
+Usage
+~~~~~
+
+
+.. tacv:: rewrite_strat @s [in @ident]
+
+ Rewrite using the strategy s in hypothesis ident or the conclusion.
+
+ .. exn:: Nothing to rewrite.
+
+ If the strategy failed.
+
+ .. exn:: No progress made.
+
+ If the strategy succeeded but made no progress.
+
+ .. exn:: Unable to satisfy the rewriting constraints.
+
+ If the strategy succeeded and made progress but the
+ corresponding rewriting constraints are not satisfied.
+
+
+ The ``setoid_rewrite c`` tactic is basically equivalent to
+ ``rewrite_strat (outermost c)``.
+
diff --git a/doc/sphinx/addendum/implicit-coercions.rst b/doc/sphinx/addendum/implicit-coercions.rst
new file mode 100644
index 000000000..f5ca5be44
--- /dev/null
+++ b/doc/sphinx/addendum/implicit-coercions.rst
@@ -0,0 +1,469 @@
+.. _implicitcoercions:
+
+.. include:: ../replaces.rst
+
+Implicit Coercions
+====================
+
+:Author: Amokrane Saïbi
+
+General Presentation
+---------------------
+
+This section describes the inheritance mechanism of |Coq|. In |Coq| with
+inheritance, we are not interested in adding any expressive power to
+our theory, but only convenience. Given a term, possibly not typable,
+we are interested in the problem of determining if it can be well
+typed modulo insertion of appropriate coercions. We allow to write:
+
+ * :g:`f a` where :g:`f:(forall x:A,B)` and :g:`a:A'` when ``A'`` can
+ be seen in some sense as a subtype of ``A``.
+ * :g:`x:A` when ``A`` is not a type, but can be seen in
+ a certain sense as a type: set, group, category etc.
+ * :g:`f a` when ``f`` is not a function, but can be seen in a certain sense
+ as a function: bijection, functor, any structure morphism etc.
+
+
+Classes
+-------
+
+A class with `n` parameters is any defined name with a type
+:g:`forall (x₁:A₁)..(xₙ:Aₙ),s` where ``s`` is a sort. Thus a class with
+parameters is considered as a single class and not as a family of
+classes. An object of a class ``C`` is any term of type :g:`C t₁ .. tₙ`.
+In addition to these user-classes, we have two abstract classes:
+
+
+ * ``Sortclass``, the class of sorts; its objects are the terms whose type is a
+ sort (e.g. :g:`Prop` or :g:`Type`).
+ * ``Funclass``, the class of functions; its objects are all the terms with a functional
+ type, i.e. of form :g:`forall x:A,B`.
+
+Formally, the syntax of a classes is defined as:
+
+.. productionlist::
+ class: qualid
+ : | `Sortclass`
+ : | `Funclass`
+
+
+Coercions
+---------
+
+A name ``f`` can be declared as a coercion between a source user-class
+``C`` with `n` parameters and a target class ``D`` if one of these
+conditions holds:
+
+ * ``D`` is a user-class, then the type of ``f`` must have the form
+ :g:`forall (x₁:A₁)..(xₙ:Aₙ)(y:C x₁..xₙ), D u₁..uₘ` where `m`
+ is the number of parameters of ``D``.
+ * ``D`` is ``Funclass``, then the type of ``f`` must have the form
+ :g:`forall (x₁:A₁)..(xₙ:Aₙ)(y:C x₁..xₙ)(x:A), B`.
+ * ``D`` is ``Sortclass``, then the type of ``f`` must have the form
+ :g:`forall (x₁:A₁)..(xₙ:Aₙ)(y:C x₁..xₙ), s` with ``s`` a sort.
+
+We then write :g:`f : C >-> D`. The restriction on the type
+of coercions is called *the uniform inheritance condition*.
+
+.. note:: The abstract classe ``Sortclass`` can be used as a source class, but
+ the abstract class ``Funclass`` cannot.
+
+To coerce an object :g:`t:C t₁..tₙ` of ``C`` towards ``D``, we have to
+apply the coercion ``f`` to it; the obtained term :g:`f t₁..tₙ t` is
+then an object of ``D``.
+
+
+Identity Coercions
+-------------------
+
+Identity coercions are special cases of coercions used to go around
+the uniform inheritance condition. Let ``C`` and ``D`` be two classes
+with respectively `n` and `m` parameters and
+:g:`f:forall (x₁:T₁)..(xₖ:Tₖ)(y:C u₁..uₙ), D v₁..vₘ` a function which
+does not verify the uniform inheritance condition. To declare ``f`` as
+coercion, one has first to declare a subclass ``C'`` of ``C``:
+
+ :g:`C' := fun (x₁:T₁)..(xₖ:Tₖ) => C u₁..uₙ`
+
+We then define an *identity coercion* between ``C'`` and ``C``:
+
+ :g:`Id_C'_C := fun (x₁:T₁)..(xₖ:Tₖ)(y:C' x₁..xₖ) => (y:C u₁..uₙ)`
+
+We can now declare ``f`` as coercion from ``C'`` to ``D``, since we can
+"cast" its type as
+:g:`forall (x₁:T₁)..(xₖ:Tₖ)(y:C' x₁..xₖ),D v₁..vₘ`.
+
+The identity coercions have a special status: to coerce an object
+:g:`t:C' t₁..tₖ`
+of ``C'`` towards ``C``, we does not have to insert explicitly ``Id_C'_C``
+since :g:`Id_C'_C t₁..tₖ t` is convertible with ``t``. However we
+"rewrite" the type of ``t`` to become an object of ``C``; in this case,
+it becomes :g:`C uₙ'..uₖ'` where each ``uᵢ'`` is the result of the
+substitution in ``uᵢ`` of the variables ``xⱼ`` by ``tⱼ``.
+
+Inheritance Graph
+------------------
+
+Coercions form an inheritance graph with classes as nodes. We call
+*coercion path* an ordered list of coercions between two nodes of
+the graph. A class ``C`` is said to be a subclass of ``D`` if there is a
+coercion path in the graph from ``C`` to ``D``; we also say that ``C``
+inherits from ``D``. Our mechanism supports multiple inheritance since a
+class may inherit from several classes, contrary to simple inheritance
+where a class inherits from at most one class. However there must be
+at most one path between two classes. If this is not the case, only
+the *oldest* one is valid and the others are ignored. So the order
+of declaration of coercions is important.
+
+We extend notations for coercions to coercion paths. For instance
+:g:`[f₁;..;fₖ] : C >-> D` is the coercion path composed
+by the coercions ``f₁..fₖ``. The application of a coercion path to a
+term consists of the successive application of its coercions.
+
+
+Declaration of Coercions
+-------------------------
+
+.. cmd:: Coercion @qualid : @class >-> @class.
+
+ Declares the construction denoted by `qualid` as a coercion between
+ the two given classes.
+
+ .. exn:: @qualid not declared
+ .. exn:: @qualid is already a coercion
+ .. exn:: Funclass cannot be a source class
+ .. exn:: @qualid is not a function
+ .. exn:: Cannot find the source class of @qualid
+ .. exn:: Cannot recognize @class as a source class of @qualid
+ .. exn:: @qualid does not respect the uniform inheritance condition
+ .. exn:: Found target class ... instead of ...
+
+ .. warn:: Ambigous path:
+
+ When the coercion `qualid` is added to the inheritance graph, non
+ valid coercion paths are ignored; they are signaled by a warning
+ displaying these paths of the form :g:`[f₁;..;fₙ] : C >-> D`.
+
+ .. cmdv:: Local Coercion @qualid : @class >-> @class.
+
+ Declares the construction denoted by `qualid` as a coercion local to
+ the current section.
+
+ .. cmdv:: Coercion @ident := @term.
+
+ This defines `ident` just like ``Definition`` `ident` ``:=`` `term`,
+ and then declares `ident` as a coercion between it source and its target.
+
+ .. cmdv:: Coercion @ident := @term : @type.
+
+ This defines `ident` just like ``Definition`` `ident` : `type` ``:=`` `term`,
+ and then declares `ident` as a coercion between it source and its target.
+
+ .. cmdv:: Local Coercion @ident := @term.
+
+ This defines `ident` just like ``Let`` `ident` ``:=`` `term`,
+ and then declares `ident` as a coercion between it source and its target.
+
+Assumptions can be declared as coercions at declaration time.
+This extends the grammar of assumptions from
+Figure :ref:`TODO-1.3-sentences-syntax` as follows:
+
+..
+ FIXME:
+ \comindex{Variable \mbox{\rm (and coercions)}}
+ \comindex{Axiom \mbox{\rm (and coercions)}}
+ \comindex{Parameter \mbox{\rm (and coercions)}}
+ \comindex{Hypothesis \mbox{\rm (and coercions)}}
+
+.. productionlist::
+ assumption : assumption_keyword assums .
+ assums : simple_assums
+ : | (simple_assums) ... (simple_assums)
+ simple_assums : ident ... ident :[>] term
+
+If the extra ``>`` is present before the type of some assumptions, these
+assumptions are declared as coercions.
+
+Similarly, constructors of inductive types can be declared as coercions at
+definition time of the inductive type. This extends and modifies the
+grammar of inductive types from Figure :ref:`TODO-1.3-sentences-syntax` as follows:
+
+..
+ FIXME:
+ \comindex{Inductive \mbox{\rm (and coercions)}}
+ \comindex{CoInductive \mbox{\rm (and coercions)}}
+
+.. productionlist::
+ inductive : `Inductive` ind_body `with` ... `with` ind_body
+ : | `CoInductive` ind_body `with` ... `with` ind_body
+ ind_body : ident [binders] : term := [[|] constructor | ... | constructor]
+ constructor : ident [binders] [:[>] term]
+
+Especially, if the extra ``>`` is present in a constructor
+declaration, this constructor is declared as a coercion.
+
+.. cmd:: Identity Coercion @ident : @class >-> @class.
+
+ If ``C`` is the source `class` and ``D`` the destination, we check
+ that ``C`` is a constant with a body of the form
+ :g:`fun (x₁:T₁)..(xₙ:Tₙ) => D t₁..tₘ` where `m` is the
+ number of parameters of ``D``. Then we define an identity
+ function with type :g:`forall (x₁:T₁)..(xₙ:Tₙ)(y:C x₁..xₙ),D t₁..tₘ`,
+ and we declare it as an identity coercion between ``C`` and ``D``.
+
+ .. exn:: @class must be a transparent constant
+
+ .. cmdv:: Local Identity Coercion @ident : @ident >-> @ident.
+
+ Idem but locally to the current section.
+
+ .. cmdv:: SubClass @ident := @type.
+
+ If `type` is a class `ident'` applied to some arguments then
+ `ident` is defined and an identity coercion of name
+ `Id_ident_ident'` is
+ declared. Otherwise said, this is an abbreviation for
+
+ ``Definition`` `ident` ``:=`` `type`.
+
+ ``Identity Coercion`` `Id_ident_ident'` : `ident` ``>->`` `ident'`.
+
+ .. cmdv:: Local SubClass @ident := @type.
+
+ Same as before but locally to the current section.
+
+
+Displaying Available Coercions
+-------------------------------
+
+.. cmd:: Print Classes.
+
+ Print the list of declared classes in the current context.
+
+.. cmd:: Print Coercions.
+
+ Print the list of declared coercions in the current context.
+
+.. cmd:: Print Graph.
+
+ Print the list of valid coercion paths in the current context.
+
+.. cmd:: Print Coercion Paths @class @class.
+
+ Print the list of valid coercion paths between the two given classes.
+
+Activating the Printing of Coercions
+-------------------------------------
+
+.. cmd:: Set Printing Coercions.
+
+ This command forces all the coercions to be printed.
+ Conversely, to skip the printing of coercions, use
+ ``Unset Printing Coercions``. By default, coercions are not printed.
+
+.. cmd:: Add Printing Coercion @qualid.
+
+ This command forces coercion denoted by `qualid` to be printed.
+ To skip the printing of coercion `qualid`, use
+ ``Remove Printing Coercion`` `qualid`. By default, a coercion is never printed.
+
+
+Classes as Records
+------------------
+
+We allow the definition of *Structures with Inheritance* (or
+classes as records) by extending the existing ``Record`` macro
+(see Section :ref:`TODO-2.1-Record`). Its new syntax is:
+
+.. cmd:: Record {? >} @ident {? @binders} : @sort := {? @ident} { {+; @ident :{? >} @term } }.
+
+ The first identifier `ident` is the name of the defined record and
+ `sort` is its type. The optional identifier after ``:=`` is the name
+ of the constuctor (it will be ``Build_``\ `ident` if not given).
+ The other identifiers are the names of the fields, and the `term`
+ are their respective types. If ``:>`` is used instead of ``:`` in
+ the declaration of a field, then the name of this field is automatically
+ declared as a coercion from the record name to the class of this
+ field type. Remark that the fields always verify the uniform
+ inheritance condition. If the optional ``>`` is given before the
+ record name, then the constructor name is automatically declared as
+ a coercion from the class of the last field type to the record name
+ (this may fail if the uniform inheritance condition is not
+ satisfied).
+
+.. note::
+
+ The keyword ``Structure`` is a synonym of ``Record``.
+
+..
+ FIXME: \comindex{Structure}
+
+
+Coercions and Sections
+----------------------
+
+The inheritance mechanism is compatible with the section
+mechanism. The global classes and coercions defined inside a section
+are redefined after its closing, using their new value and new
+type. The classes and coercions which are local to the section are
+simply forgotten.
+Coercions with a local source class or a local target class, and
+coercions which do not verify the uniform inheritance condition any longer
+are also forgotten.
+
+Coercions and Modules
+--------------------=
+
+From |Coq| version 8.3, the coercions present in a module are activated
+only when the module is explicitly imported. Formerly, the coercions
+were activated as soon as the module was required, whatever it was
+imported or not.
+
+To recover the behavior of the versions of |Coq| prior to 8.3, use the
+following command:
+
+.. cmd:: Set Automatic Coercions Import.
+
+To cancel the effect of the option, use instead ``Unset Automatic Coercions Import``.
+
+
+Examples
+--------
+
+There are three situations:
+
+Coercion at function application
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+:g:`f a` is ill-typed where :g:`f:forall x:A,B` and :g:`a:A'`. If there is a
+coercion path between ``A'`` and ``A``, then :g:`f a` is transformed into
+:g:`f a'` where ``a'`` is the result of the application of this
+coercion path to ``a``.
+
+We first give an example of coercion between atomic inductive types
+
+.. coqtop:: all
+
+ Definition bool_in_nat (b:bool) := if b then 0 else 1.
+ Coercion bool_in_nat : bool >-> nat.
+ Check (0 = true).
+ Set Printing Coercions.
+ Check (0 = true).
+ Unset Printing Coercions.
+
+
+.. warning::
+
+ Note that ``Check true=O`` would fail. This is "normal" behaviour of
+ coercions. To validate ``true=O``, the coercion is searched from
+ ``nat`` to ``bool``. There is none.
+
+We give an example of coercion between classes with parameters.
+
+.. coqtop:: all
+
+ Parameters (C : nat -> Set) (D : nat -> bool -> Set) (E : bool -> Set).
+ Parameter f : forall n:nat, C n -> D (S n) true.
+ Coercion f : C >-> D.
+ Parameter g : forall (n:nat) (b:bool), D n b -> E b.
+ Coercion g : D >-> E.
+ Parameter c : C 0.
+ Parameter T : E true -> nat.
+ Check (T c).
+ Set Printing Coercions.
+ Check (T c).
+ Unset Printing Coercions.
+
+We give now an example using identity coercions.
+
+.. coqtop:: all
+
+ Definition D' (b:bool) := D 1 b.
+ Identity Coercion IdD'D : D' >-> D.
+ Print IdD'D.
+ Parameter d' : D' true.
+ Check (T d').
+ Set Printing Coercions.
+ Check (T d').
+ Unset Printing Coercions.
+
+
+In the case of functional arguments, we use the monotonic rule of
+sub-typing. Approximatively, to coerce :g:`t:forall x:A,B` towards
+:g:`forall x:A',B'`, one have to coerce ``A'`` towards ``A`` and ``B``
+towards ``B'``. An example is given below:
+
+.. coqtop:: all
+
+ Parameters (A B : Set) (h : A -> B).
+ Coercion h : A >-> B.
+ Parameter U : (A -> E true) -> nat.
+ Parameter t : B -> C 0.
+ Check (U t).
+ Set Printing Coercions.
+ Check (U t).
+ Unset Printing Coercions.
+
+Remark the changes in the result following the modification of the
+previous example.
+
+.. coqtop:: all
+
+ Parameter U' : (C 0 -> B) -> nat.
+ Parameter t' : E true -> A.
+ Check (U' t').
+ Set Printing Coercions.
+ Check (U' t').
+ Unset Printing Coercions.
+
+
+Coercion to a type
+~~~~~~~~~~~~~~~~~~
+
+An assumption ``x:A`` when ``A`` is not a type, is ill-typed. It is
+replaced by ``x:A'`` where ``A'`` is the result of the application to
+``A`` of the coercion path between the class of ``A`` and
+``Sortclass`` if it exists. This case occurs in the abstraction
+:g:`fun x:A => t`, universal quantification :g:`forall x:A,B`, global
+variables and parameters of (co-)inductive definitions and
+functions. In :g:`forall x:A,B`, such a coercion path may be applied
+to ``B`` also if necessary.
+
+.. coqtop:: all
+
+ Parameter Graph : Type.
+ Parameter Node : Graph -> Type.
+ Coercion Node : Graph >-> Sortclass.
+ Parameter G : Graph.
+ Parameter Arrows : G -> G -> Type.
+ Check Arrows.
+ Parameter fg : G -> G.
+ Check fg.
+ Set Printing Coercions.
+ Check fg.
+ Unset Printing Coercions.
+
+
+Coercion to a function
+~~~~~~~~~~~~~~~~~~~~~~
+
+``f a`` is ill-typed because ``f:A`` is not a function. The term
+``f`` is replaced by the term obtained by applying to ``f`` the
+coercion path between ``A`` and ``Funclass`` if it exists.
+
+.. coqtop:: all
+
+ Parameter bij : Set -> Set -> Set.
+ Parameter ap : forall A B:Set, bij A B -> A -> B.
+ Coercion ap : bij >-> Funclass.
+ Parameter b : bij nat nat.
+ Check (b 0).
+ Set Printing Coercions.
+ Check (b 0).
+ Unset Printing Coercions.
+
+Let us see the resulting graph after all these examples.
+
+.. coqtop:: all
+
+ Print Graph.
diff --git a/doc/sphinx/addendum/miscellaneous-extensions.rst b/doc/sphinx/addendum/miscellaneous-extensions.rst
new file mode 100644
index 000000000..b0343a8f0
--- /dev/null
+++ b/doc/sphinx/addendum/miscellaneous-extensions.rst
@@ -0,0 +1,67 @@
+.. include:: ../replaces.rst
+
+.. _miscellaneousextensions:
+
+Miscellaneous extensions
+=======================
+
+:Source: https://coq.inria.fr/distrib/current/refman/miscellaneous.html
+:Converted by: Paul Steckler
+
+.. contents::
+ :local:
+ :depth: 1
+----
+
+Program derivation
+-----------------
+
+|Coq| comes with an extension called ``Derive``, which supports program
+derivation. Typically in the style of Bird and Meertens or derivations
+of program refinements. To use the Derive extension it must first be
+required with ``Require Coq.Derive.Derive``. When the extension is loaded,
+it provides the following command:
+
+.. cmd:: Derive @ident SuchThat @term As @ident
+
+The first `ident` can appear in `term`. This command opens a new proof
+presenting the user with a goal for term in which the name `ident` is
+bound to an existential variable `?x` (formally, there are other goals
+standing for the existential variables but they are shelved, as
+described in Section :ref:`TODO-8.17.4`).
+
+When the proof ends two constants are defined:
+
++ The first one is named using the first `ident` and is defined as the proof of the
+ shelved goal (which is also the value of `?x`). It is always
+ transparent.
++ The second one is named using the second `ident`. It has type `term`, and its body is
+ the proof of the initially visible goal. It is opaque if the proof
+ ends with ``Qed``, and transparent if the proof ends with ``Defined``.
+
+.. example::
+ .. coqtop:: all
+
+ Require Coq.derive.Derive.
+ Require Import Coq.Numbers.Natural.Peano.NPeano.
+
+ Section P.
+
+ Variables (n m k:nat).
+
+ Derive p SuchThat ((k*n)+(k*m) = p) As h.
+ Proof.
+ rewrite <- Nat.mul_add_distr_l.
+ subst p.
+ reflexivity.
+ Qed.
+
+ End P.
+
+ Print p.
+ Check h.
+
+Any property can be used as `term`, not only an equation. In particular,
+it could be an order relation specifying some form of program
+refinement or a non-executable property from which deriving a program
+is convenient.
diff --git a/doc/sphinx/addendum/nsatz.rst b/doc/sphinx/addendum/nsatz.rst
new file mode 100644
index 000000000..ef9b3505d
--- /dev/null
+++ b/doc/sphinx/addendum/nsatz.rst
@@ -0,0 +1,101 @@
+.. include:: ../preamble.rst
+
+.. _nsatz:
+
+Nsatz: tactics for proving equalities in integral domains
+===========================================================
+
+:Author: Loïc Pottier
+
+The tactic `nsatz` proves goals of the form
+
+:math:`\begin{array}{l}
+\forall X_1,\ldots,X_n \in A,\\
+P_1(X_1,\ldots,X_n) = Q_1(X_1,\ldots,X_n) , \ldots , P_s(X_1,\ldots,X_n) =Q_s(X_1,\ldots,X_n)\\
+\vdash P(X_1,\ldots,X_n) = Q(X_1,\ldots,X_n)\\
+\end{array}`
+
+where :math:`P, Q, P₁,Q₁,\ldots,Pₛ, Qₛ` are polynomials and :math:`A` is an integral
+domain, i.e. a commutative ring with no zero divisor. For example, :math:`A`
+can be :math:`\mathbb{R}`, :math:`\mathbb{Z}`, or :math:`\mathbb{Q}`.
+Note that the equality :math:`=` used in these goals can be
+any setoid equality (see :ref:`TODO-27.2.2`) , not only Leibnitz equality.
+
+It also proves formulas
+
+:math:`\begin{array}{l}
+\forall X_1,\ldots,X_n \in A,\\
+P_1(X_1,\ldots,X_n) = Q_1(X_1,\ldots,X_n) \wedge \ldots \wedge P_s(X_1,\ldots,X_n) =Q_s(X_1,\ldots,X_n)\\
+\rightarrow P(X_1,\ldots,X_n) = Q(X_1,\ldots,X_n)\\
+\end{array}`
+
+doing automatic introductions.
+
+
+Using the basic tactic `nsatz`
+------------------------------
+
+
+Load the Nsatz module:
+
+.. coqtop:: all
+
+ Require Import Nsatz.
+
+and use the tactic `nsatz`.
+
+More about `nsatz`
+---------------------
+
+Hilbert’s Nullstellensatz theorem shows how to reduce proofs of
+equalities on polynomials on a commutative ring :math:`A` with no zero divisor
+to algebraic computations: it is easy to see that if a polynomial :math:`P` in
+:math:`A[X_1,\ldots,X_n]` verifies :math:`c P^r = \sum_{i=1}^{s} S_i P_i`, with
+:math:`c \in A`, :math:`c \not = 0`,
+:math:`r` a positive integer, and the :math:`S_i` s in :math:`A[X_1,\ldots,X_n ]`,
+then :math:`P` is zero whenever polynomials :math:`P_1,\ldots,P_s` are zero
+(the converse is also true when :math:`A` is an algebraic closed field: the method is
+complete).
+
+So, proving our initial problem can reduce into finding :math:`S_1,\ldots,S_s`,
+:math:`c` and :math:`r` such that :math:`c (P-Q)^r = \sum_{i} S_i (P_i-Q_i)`,
+which will be proved by the tactic ring.
+
+This is achieved by the computation of a Gröbner basis of the ideal
+generated by :math:`P_1-Q_1,...,P_s-Q_s`, with an adapted version of the
+Buchberger algorithm.
+
+This computation is done after a step of *reification*, which is
+performed using :ref:`typeclasses`.
+
+The ``Nsatz`` module defines the tactic `nsatz`, which can be used without
+arguments, or with the syntax:
+
+| nsatz with radicalmax:=num%N strategy:=num%Z parameters:= :n:`{* var}` variables:= :n:`{* var}`
+
+where:
+
+* `radicalmax` is a bound when for searching r s.t.
+ :math:`c (P−Q) r = \sum_{i=1..s} S_i (P i − Q i)`
+
+* `strategy` gives the order on variables :math:`X_1,\ldots,X_n` and the strategy
+ used in Buchberger algorithm (see :cite:`sugar` for details):
+
+ * strategy = 0: reverse lexicographic order and newest s-polynomial.
+ * strategy = 1: reverse lexicographic order and sugar strategy.
+ * strategy = 2: pure lexicographic order and newest s-polynomial.
+ * strategy = 3: pure lexicographic order and sugar strategy.
+
+* `parameters` is the list of variables :math:`X_{i_1},\ldots,X_{i_k}` among
+ :math:`X_1,\ldots,X_n` which are considered as parameters: computation will be performed with
+ rational fractions in these variables, i.e. polynomials are considered
+ with coefficients in :math:`R(X_{i_1},\ldots,X_{i_k})`. In this case, the coefficient
+ :math:`c` can be a non constant polynomial in :math:`X_{i_1},\ldots,X_{i_k}`, and the tactic
+ produces a goal which states that :math:`c` is not zero.
+
+* `variables` is the list of the variables in the decreasing order in
+ which they will be used in Buchberger algorithm. If `variables` = `(@nil R)`,
+ then `lvar` is replaced by all the variables which are not in
+ `parameters`.
+
+See file `Nsatz.v` for many examples, especially in geometry.
diff --git a/doc/sphinx/addendum/parallel-proof-processing.rst b/doc/sphinx/addendum/parallel-proof-processing.rst
new file mode 100644
index 000000000..8c1b9d152
--- /dev/null
+++ b/doc/sphinx/addendum/parallel-proof-processing.rst
@@ -0,0 +1,229 @@
+.. include:: ../replaces.rst
+
+.. _asynchronousandparallelproofprocessing:
+
+Asynchronous and Parallel Proof Processing
+==========================================
+
+:Author: Enrico Tassi
+
+This chapter explains how proofs can be asynchronously processed by
+|Coq|. This feature improves the reactivity of the system when used in
+interactive mode via |CoqIDE|. In addition, it allows |Coq| to take
+advantage of parallel hardware when used as a batch compiler by
+decoupling the checking of statements and definitions from the
+construction and checking of proofs objects.
+
+This feature is designed to help dealing with huge libraries of
+theorems characterized by long proofs. In the current state, it may
+not be beneficial on small sets of short files.
+
+This feature has some technical limitations that may make it
+unsuitable for some use cases.
+
+For example, in interactive mode, some errors coming from the kernel
+of |Coq| are signaled late. The type of errors belonging to this
+category are universe inconsistencies.
+
+At the time of writing, only opaque proofs (ending with ``Qed`` or
+``Admitted``) can be processed asynchronously.
+
+Finally, asynchronous processing is disabled when running |CoqIDE| in
+Windows. The current implementation of the feature is not stable on
+Windows. It can be enabled, as described below at :ref:`interactive-mode`,
+though doing so is not recommended.
+
+Proof annotations
+----------------------
+
+To process a proof asynchronously |Coq| needs to know the precise
+statement of the theorem without looking at the proof. This requires
+some annotations if the theorem is proved inside a Section (see
+Section :ref:`TODO-2.4`).
+
+When a section ends, |Coq| looks at the proof object to decide which
+section variables are actually used and hence have to be quantified in
+the statement of the theorem. To avoid making the construction of
+proofs mandatory when ending a section, one can start each proof with
+the ``Proof using`` command (Section :ref:`TODO-7.1.5`) that declares which section
+variables the theorem uses.
+
+The presence of ``Proof`` using is needed to process proofs asynchronously
+in interactive mode.
+
+It is not strictly mandatory in batch mode if it is not the first time
+the file is compiled and if the file itself did not change. When the
+proof does not begin with Proof using, the system records in an
+auxiliary file, produced along with the `.vo` file, the list of section
+variables used.
+
+Automatic suggestion of proof annotations
+`````````````````````````````````````````
+
+The command ``Set Suggest Proof Using`` makes |Coq| suggest, when a ``Qed``
+command is processed, a correct proof annotation. It is up to the user
+to modify the proof script accordingly.
+
+
+Proof blocks and error resilience
+--------------------------------------
+
+|Coq| 8.6 introduced a mechanism for error resiliency: in interactive
+mode |Coq| is able to completely check a document containing errors
+instead of bailing out at the first failure.
+
+Two kind of errors are supported: errors occurring in vernacular
+commands and errors occurring in proofs.
+
+To properly recover from a failing tactic, |Coq| needs to recognize the
+structure of the proof in order to confine the error to a sub proof.
+Proof block detection is performed by looking at the syntax of the
+proof script (i.e. also looking at indentation). |Coq| comes with four
+kind of proof blocks, and an ML API to add new ones.
+
+:curly: blocks are delimited by { and }, see Chapter :ref:`proofhandling`
+:par: blocks are atomic, i.e. just one tactic introduced by the `par:`
+ goal selector
+:indent: blocks end with a tactic indented less than the previous one
+:bullet: blocks are delimited by two equal bullet signs at the same
+ indentation level
+
+Caveats
+````````
+
+When a vernacular command fails the subsequent error messages may be
+bogus, i.e. caused by the first error. Error resiliency for vernacular
+commands can be switched off by passing ``-async-proofs-command-error-resilience off``
+to |CoqIDE|.
+
+An incorrect proof block detection can result into an incorrect error
+recovery and hence in bogus errors. Proof block detection cannot be
+precise for bullets or any other non well parenthesized proof
+structure. Error resiliency can be turned off or selectively activated
+for any set of block kind passing to |CoqIDE| one of the following
+options:
+
+- ``-async-proofs-tactic-error-resilience off``
+- ``-async-proofs-tactic-error-resilience all``
+- ``-async-proofs-tactic-error-resilience`` :n:`{*, blocktype}`
+
+Valid proof block types are: “curly”, “par”, “indent”, and “bullet”.
+
+.. _interactive-mode:
+
+Interactive mode
+---------------------
+
+At the time of writing the only user interface supporting asynchronous
+proof processing is |CoqIDE|.
+
+When |CoqIDE| is started, two |Coq| processes are created. The master one
+follows the user, giving feedback as soon as possible by skipping
+proofs, which are delegated to the worker process. The worker process,
+whose state can be seen by clicking on the button in the lower right
+corner of the main |CoqIDE| window, asynchronously processes the proofs.
+If a proof contains an error, it is reported in red in the label of
+the very same button, that can also be used to see the list of errors
+and jump to the corresponding line.
+
+If a proof is processed asynchronously the corresponding Qed command
+is colored using a lighter color that usual. This signals that the
+proof has been delegated to a worker process (or will be processed
+lazily if the ``-async-proofs lazy`` option is used). Once finished, the
+worker process will provide the proof object, but this will not be
+automatically checked by the kernel of the main process. To force the
+kernel to check all the proof objects, one has to click the button
+with the gears. Only then are all the universe constraints checked.
+
+Caveats
+```````
+
+The number of worker processes can be increased by passing |CoqIDE|
+the ``-async-proofs-j n`` flag. Note that the memory consumption increases too,
+since each worker requires the same amount of memory as the master
+process. Also note that increasing the number of workers may reduce
+the reactivity of the master process to user commands.
+
+To disable this feature, one can pass the ``-async-proofs off`` flag to
+|CoqIDE|. Conversely, on Windows, where the feature is disabled by
+default, pass the ``-async-proofs on`` flag to enable it.
+
+Proofs that are known to take little time to process are not delegated
+to a worker process. The threshold can be configure with
+``-async-proofs-delegation-threshold``. Default is 0.03 seconds.
+
+Batch mode
+---------------
+
+When |Coq| is used as a batch compiler by running `coqc` or `coqtop`
+-compile, it produces a `.vo` file for each `.v` file. A `.vo` file contains,
+among other things, theorems statements and proofs. Hence to produce a
+.vo |Coq| need to process all the proofs of the `.v` file.
+
+The asynchronous processing of proofs can decouple the generation of a
+compiled file (like the `.vo` one) that can be loaded by ``Require`` from the
+generation and checking of the proof objects. The ``-quick`` flag can be
+passed to `coqc` or `coqtop` to produce, quickly, `.vio` files.
+Alternatively, when using a Makefile produced by `coq_makefile`,
+the ``quick`` target can be used to compile all files using the ``-quick`` flag.
+
+A `.vio` file can be loaded using ``Require`` exactly as a `.vo` file but
+proofs will not be available (the Print command produces an error).
+Moreover, some universe constraints might be missing, so universes
+inconsistencies might go unnoticed. A `.vio` file does not contain proof
+objects, but proof tasks, i.e. what a worker process can transform
+into a proof object.
+
+Compiling a set of files with the ``-quick`` flag allows one to work,
+interactively, on any file without waiting for all the proofs to be
+checked.
+
+When working interactively, one can fully check all the `.v` files by
+running `coqc` as usual.
+
+Alternatively one can turn each `.vio` into the corresponding `.vo`. All
+.vio files can be processed in parallel, hence this alternative might
+be faster. The command ``coqtop -schedule-vio2vo 2 a b c`` can be used to
+obtain a good scheduling for two workers to produce `a.vo`, `b.vo`, and
+`c.vo`. When using a Makefile produced by `coq_makefile`, the ``vio2vo`` target
+can be used for that purpose. Variable `J` should be set to the number
+of workers, e.g. ``make vio2vo J=2``. The only caveat is that, while the
+.vo files obtained from `.vio` files are complete (they contain all proof
+terms and universe constraints), the satisfiability of all universe
+constraints has not been checked globally (they are checked to be
+consistent for every single proof). Constraints will be checked when
+these `.vo` files are (recursively) loaded with ``Require``.
+
+There is an extra, possibly even faster, alternative: just check the
+proof tasks stored in `.vio` files without producing the `.vo` files. This
+is possibly faster because all the proof tasks are independent, hence
+one can further partition the job to be done between workers. The
+``coqtop -schedule-vio-checking 6 a b c`` command can be used to obtain a
+good scheduling for 6 workers to check all the proof tasks of `a.vio`,
+`b.vio`, and `c.vio`. Auxiliary files are used to predict how long a proof
+task will take, assuming it will take the same amount of time it took
+last time. When using a Makefile produced by coq_makefile, the
+``checkproofs`` target can be used to check all `.vio` files. Variable `J`
+should be set to the number of workers, e.g. ``make checkproofs J=6``. As
+when converting `.vio` files to `.vo` files, universe constraints are not
+checked to be globally consistent. Hence this compilation mode is only
+useful for quick regression testing and on developments not making
+heavy use of the `Type` hierarchy.
+
+Limiting the number of parallel workers
+--------------------------------------------
+
+Many |Coq| processes may run on the same computer, and each of them may
+start many additional worker processes. The `coqworkmgr` utility lets
+one limit the number of workers, globally.
+
+The utility accepts the ``-j`` argument to specify the maximum number of
+workers (defaults to 2). `coqworkmgr` automatically starts in the
+background and prints an environment variable assignment
+like ``COQWORKMGR_SOCKET=localhost:45634``. The user must set this variable
+in all the shells from which |Coq| processes will be started. If one
+uses just one terminal running the bash shell, then
+``export ‘coqworkmgr -j 4‘`` will do the job.
+
+After that, all |Coq| processes, e.g. `coqide` and `coqc`, will honor the
+limit, globally.
diff --git a/doc/sphinx/addendum/program.rst b/doc/sphinx/addendum/program.rst
new file mode 100644
index 000000000..eb50e52dc
--- /dev/null
+++ b/doc/sphinx/addendum/program.rst
@@ -0,0 +1,381 @@
+.. include:: ../preamble.rst
+.. include:: ../replaces.rst
+
+.. this should be just "_program", but refs to it don't work
+
+.. _programs:
+
+Program
+========
+
+:Author: Matthieu Sozeau
+
+We present here the |Program| tactic commands, used to build
+certified |Coq| programs, elaborating them from their algorithmic
+skeleton and a rich specification :cite:`sozeau06`. It can be thought of as a
+dual of :ref:`Extraction <extraction>`. The goal of |Program| is to
+program as in a regular functional programming language whilst using
+as rich a specification as desired and proving that the code meets the
+specification using the whole |Coq| proof apparatus. This is done using
+a technique originating from the “Predicate subtyping” mechanism of
+PVS :cite:`Rushby98`, which generates type-checking conditions while typing a
+term constrained to a particular type. Here we insert existential
+variables in the term, which must be filled with proofs to get a
+complete |Coq| term. |Program| replaces the |Program| tactic by Catherine
+Parent :cite:`Parent95b` which had a similar goal but is no longer maintained.
+
+The languages available as input are currently restricted to |Coq|’s
+term language, but may be extended to OCaml, Haskell and
+others in the future. We use the same syntax as |Coq| and permit to use
+implicit arguments and the existing coercion mechanism. Input terms
+and types are typed in an extended system (Russell) and interpreted
+into |Coq| terms. The interpretation process may produce some proof
+obligations which need to be resolved to create the final term.
+
+
+.. _elaborating-programs:
+
+Elaborating programs
+---------------------
+
+The main difference from |Coq| is that an object in a type T : Set can
+be considered as an object of type { x : T | P} for any wellformed P :
+Prop. If we go from T to the subset of T verifying property P, we must
+prove that the object under consideration verifies it. Russell will
+generate an obligation for every such coercion. In the other
+direction, Russell will automatically insert a projection.
+
+Another distinction is the treatment of pattern-matching. Apart from
+the following differences, it is equivalent to the standard match
+operation (see :ref:`extendedpatternmatching`).
+
+
++ Generation of equalities. A match expression is always generalized
+ by the corresponding equality. As an example, the expression:
+
+ ::
+
+ match x with
+ | 0 => t
+ | S n => u
+ end.
+
+ will be first rewritten to:
+
+ ::
+
+ (match x as y return (x = y -> _) with
+ | 0 => fun H : x = 0 -> t
+ | S n => fun H : x = S n -> u
+ end) (eq_refl n).
+
+ This permits to get the proper equalities in the context of proof
+ obligations inside clauses, without which reasoning is very limited.
+
++ Generation of inequalities. If a pattern intersects with a previous
+ one, an inequality is added in the context of the second branch. See
+ for example the definition of div2 below, where the second branch is
+ typed in a context where ∀ p, _ <> S (S p).
++ Coercion. If the object being matched is coercible to an inductive
+ type, the corresponding coercion will be automatically inserted. This
+ also works with the previous mechanism.
+
+
+There are options to control the generation of equalities and
+coercions.
+
+.. opt:: Program Cases
+
+ This controls the special treatment of pattern-matching generating equalities
+ and inequalities when using |Program| (it is on by default). All
+ pattern-matchings and let-patterns are handled using the standard algorithm
+ of |Coq| (see :ref:`extendedpatternmatching`) when this option is
+ deactivated.
+
+.. opt:: Program Generalized Coercion
+
+ This controls the coercion of general inductive types when using |Program|
+ (the option is on by default). Coercion of subset types and pairs is still
+ active in this case.
+
+.. _syntactic_control:
+
+Syntactic control over equalities
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+To give more control over the generation of equalities, the
+typechecker will fall back directly to |Coq|’s usual typing of dependent
+pattern-matching if a return or in clause is specified. Likewise, the
+if construct is not treated specially by |Program| so boolean tests in
+the code are not automatically reflected in the obligations. One can
+use the dec combinator to get the correct hypotheses as in:
+
+.. coqtop:: none
+
+ Require Import Program Arith.
+
+.. coqtop:: all
+
+ Program Definition id (n : nat) : { x : nat | x = n } :=
+ if dec (leb n 0) then 0
+ else S (pred n).
+
+The let tupling construct :g:`let (x1, ..., xn) := t in b` does not
+produce an equality, contrary to the let pattern construct :g:`let ’(x1,
+..., xn) := t in b`. Also, :g:`term :>` explicitly asks the system to
+coerce term to its support type. It can be useful in notations, for
+example:
+
+.. coqtop:: all
+
+ Notation " x `= y " := (@eq _ (x :>) (y :>)) (only parsing).
+
+This notation denotes equality on subset types using equality on their
+support types, avoiding uses of proof-irrelevance that would come up
+when reasoning with equality on the subset types themselves.
+
+The next two commands are similar to their standard counterparts
+Definition (see Section `TODO-1.3.2-Definition`_) and Fixpoint (see Section `TODO-1.3.4-Fixpoint`_)
+in that they define constants. However, they may require the user to
+prove some goals to construct the final definitions.
+
+
+.. _program_definition:
+
+Program Definition
+~~~~~~~~~~~~~~~~~~
+
+.. cmd:: Program Definition @ident := @term.
+
+ This command types the value term in Russell and generates proof
+ obligations. Once solved using the commands shown below, it binds the
+ final |Coq| term to the name ``ident`` in the environment.
+
+ .. exn:: ident already exists
+
+ .. cmdv:: Program Definition @ident : @type := @term
+
+ It interprets the type ``type``, potentially generating proof
+ obligations to be resolved. Once done with them, we have a |Coq|
+ type |type_0|. It then elaborates the preterm ``term`` into a |Coq|
+ term |term_0|, checking that the type of |term_0| is coercible to
+ |type_0|, and registers ``ident`` as being of type |type_0| once the
+ set of obligations generated during the interpretation of |term_0|
+ and the aforementioned coercion derivation are solved.
+
+ .. exn:: In environment … the term: @term does not have type @type. Actually, it has type ...
+
+
+ .. cmdv:: Program Definition @ident @binders : @type := @term.
+
+ This is equivalent to:
+
+ :g:`Program Definition ident : forall binders, type := fun binders => term`.
+
+ .. TODO refer to production in alias
+
+See also: Sections `TODO-6.10.1-Opaque`_, `TODO-6.10.2-Transparent`_, `TODO-8.7.5-unfold`_
+
+.. _program_fixpoint:
+
+Program Fixpoint
+~~~~~~~~~~~~~~~~
+
+.. cmd:: Program Fixpoint @ident @params {? {@order}} : @type := @term.
+
+The optional order annotation follows the grammar:
+
+.. productionlist:: orderannot
+ order : measure `term` (`term`)? | wf `term` `term`
+
++ :g:`measure f ( R )` where :g:`f` is a value of type :g:`X` computed on
+ any subset of the arguments and the optional (parenthesised) term
+ ``(R)`` is a relation on ``X``. By default ``X`` defaults to ``nat`` and ``R``
+ to ``lt``.
+
++ :g:`wf R x` which is equivalent to :g:`measure x (R)`.
+
+The structural fixpoint operator behaves just like the one of |Coq| (see
+Section `TODO-1.3.4-Fixpoint`_), except it may also generate obligations. It works
+with mutually recursive definitions too.
+
+.. coqtop:: reset none
+
+ Require Import Program Arith.
+
+.. coqtop:: all
+
+ Program Fixpoint div2 (n : nat) : { x : nat | n = 2 * x \/ n = 2 * x + 1 } :=
+ match n with
+ | S (S p) => S (div2 p)
+ | _ => O
+ end.
+
+Here we have one obligation for each branch (branches for :g:`0` and
+``(S 0)`` are automatically generated by the pattern-matching
+compilation algorithm).
+
+.. coqtop:: all
+
+ Obligation 1.
+
+.. coqtop:: reset none
+
+ Require Import Program Arith.
+
+One can use a well-founded order or a measure as termination orders
+using the syntax:
+
+.. coqtop:: in
+
+ Program Fixpoint div2 (n : nat) {measure n} : { x : nat | n = 2 * x \/ n = 2 * x + 1 } :=
+ match n with
+ | S (S p) => S (div2 p)
+ | _ => O
+ end.
+
+
+
+.. caution:: When defining structurally recursive functions, the generated
+ obligations should have the prototype of the currently defined
+ functional in their context. In this case, the obligations should be
+ transparent (e.g. defined using :g:`Defined`) so that the guardedness
+ condition on recursive calls can be checked by the kernel’s type-
+ checker. There is an optimization in the generation of obligations
+ which gets rid of the hypothesis corresponding to the functional when
+ it is not necessary, so that the obligation can be declared opaque
+ (e.g. using :g:`Qed`). However, as soon as it appears in the context, the
+ proof of the obligation is *required* to be declared transparent.
+
+ No such problems arise when using measures or well-founded recursion.
+
+.. _program_lemma:
+
+Program Lemma
+~~~~~~~~~~~~~
+
+.. cmd:: Program Lemma @ident : @type.
+
+ The Russell language can also be used to type statements of logical
+ properties. It will generate obligations, try to solve them
+ automatically and fail if some unsolved obligations remain. In this
+ case, one can first define the lemma’s statement using :g:`Program
+ Definition` and use it as the goal afterwards. Otherwise the proof
+ will be started with the elaborated version as a goal. The
+ :g:`Program` prefix can similarly be used as a prefix for
+ :g:`Variable`, :g:`Hypothesis`, :g:`Axiom` etc...
+
+.. _solving_obligations:
+
+Solving obligations
+--------------------
+
+The following commands are available to manipulate obligations. The
+optional identifier is used when multiple functions have unsolved
+obligations (e.g. when defining mutually recursive blocks). The
+optional tactic is replaced by the default one if not specified.
+
+.. cmd:: {? Local|Global} Obligation Tactic := @tactic
+
+ Sets the default obligation solving tactic applied to all obligations
+ automatically, whether to solve them or when starting to prove one,
+ e.g. using :g:`Next`. :g:`Local` makes the setting last only for the current
+ module. Inside sections, local is the default.
+
+.. cmd:: Show Obligation Tactic
+
+ Displays the current default tactic.
+
+.. cmd:: Obligations {? of @ident}
+
+ Displays all remaining obligations.
+
+.. cmd:: Obligation num {? of @ident}
+
+ Start the proof of obligation num.
+
+.. cmd:: Next Obligation {? of @ident}
+
+ Start the proof of the next unsolved obligation.
+
+.. cmd:: Solve Obligations {? of @ident} {? with @tactic}
+
+ Tries to solve each obligation of ``ident`` using the given ``tactic`` or the default one.
+
+.. cmd:: Solve All Obligations {? with @tactic}
+
+ Tries to solve each obligation of every program using the given
+ tactic or the default one (useful for mutually recursive definitions).
+
+.. cmd:: Admit Obligations {? of @ident}
+
+ Admits all obligations (of ``ident``).
+
+ .. note:: Does not work with structurally recursive programs.
+
+.. cmd:: Preterm {? of @ident}
+
+ Shows the term that will be fed to the kernel once the obligations
+ are solved. Useful for debugging.
+
+.. opt:: Transparent Obligations
+
+ Control whether all obligations should be declared as transparent
+ (the default), or if the system should infer which obligations can be
+ declared opaque.
+
+.. opt:: Hide Obligations
+
+ Control whether obligations appearing in the
+ term should be hidden as implicit arguments of the special
+ constantProgram.Tactics.obligation.
+
+.. opt:: Shrink Obligations
+
+ *Deprecated since 8.7*
+
+ This option (on by default) controls whether obligations should have
+ their context minimized to the set of variables used in the proof of
+ the obligation, to avoid unnecessary dependencies.
+
+The module :g:`Coq.Program.Tactics` defines the default tactic for solving
+obligations called :g:`program_simpl`. Importing :g:`Coq.Program.Program` also
+adds some useful notations, as documented in the file itself.
+
+.. _program-faq:
+
+Frequently Asked Questions
+---------------------------
+
+
+.. exn:: Ill-formed recursive definition
+
+ This error can happen when one tries to define a function by structural
+ recursion on a subset object, which means the |Coq| function looks like:
+
+ ::
+
+ Program Fixpoint f (x : A | P) := match x with A b => f b end.
+
+ Supposing ``b : A``, the argument at the recursive call to ``f`` is not a
+ direct subterm of ``x`` as ``b`` is wrapped inside an ``exist`` constructor to
+ build an object of type ``{x : A | P}``. Hence the definition is
+ rejected by the guardedness condition checker. However one can use
+ wellfounded recursion on subset objects like this:
+
+ ::
+
+ Program Fixpoint f (x : A | P) { measure (size x) } :=
+ match x with A b => f b end.
+
+ One will then just have to prove that the measure decreases at each
+ recursive call. There are three drawbacks though:
+
+ #. A measure function has to be defined;
+ #. The reduction is a little more involved, although it works well
+ using lazy evaluation;
+ #. Mutual recursion on the underlying inductive type isn’t possible
+ anymore, but nested mutual recursion is always possible.
+
+.. bibliography:: ../biblio.bib
+ :keyprefix: p-
diff --git a/doc/sphinx/addendum/ring.rst b/doc/sphinx/addendum/ring.rst
new file mode 100644
index 000000000..b861892cb
--- /dev/null
+++ b/doc/sphinx/addendum/ring.rst
@@ -0,0 +1,770 @@
+.. include:: ../replaces.rst
+.. |ra| replace:: :math:`\rightarrow_{\beta\delta\iota}`
+.. |la| replace:: :math:`\leftarrow_{\beta\delta\iota}`
+.. |eq| replace:: `=`:sub:`(by the main correctness theorem)`
+.. |re| replace:: ``(PEeval`` `v` `ap`\ ``)``
+.. |le| replace:: ``(Pphi_dev`` `v` ``(norm`` `ap`\ ``))``
+
+
+.. _theringandfieldtacticfamilies:
+
+The ring and field tactic families
+====================================
+
+:Author: Bruno Barras, Benjamin Grégoire, Assia Mahboubi, Laurent Théry [#f1]_
+
+This chapter presents the tactics dedicated to deal with ring and
+field equations.
+
+What does this tactic do?
+------------------------------
+
+``ring`` does associative-commutative rewriting in ring and semi-ring
+structures. Assume you have two binary functions :math:`\oplus` and
+:math:`\otimes` that are associative and commutative, with :math:`\oplus`
+distributive on :math:`\otimes`, and two constants 0 and 1 that are unities for
+:math:`\oplus` and :math:`\otimes`. A polynomial is an expression built on
+variables :math:`V_0`, :math:`V_1`, :math:`\dots` and constants by application
+of :math:`\oplus` and :math:`\otimes`.
+
+Let an ordered product be a product of variables :math:`V_{i_1} \otimes \dots
+\otimes V_{i_n}` verifying :math:`i_1 ≤ i_2 ≤ \dots ≤ i_n` . Let a monomial be
+the product of a constant and an ordered product. We can order the monomials by
+the lexicographic order on products of variables. Let a canonical sum be an
+ordered sum of monomials that are all different, i.e. each monomial in the sum
+is strictly less than the following monomial according to the lexicographic
+order. It is an easy theorem to show that every polynomial is equivalent (modulo
+the ring properties) to exactly one canonical sum. This canonical sum is called
+the normal form of the polynomial. In fact, the actual representation shares
+monomials with same prefixes. So what does ring? It normalizes polynomials over
+any ring or semi-ring structure. The basic use of ``ring`` is to simplify ring
+expressions, so that the user does not have to deal manually with the theorems
+of associativity and commutativity.
+
+
+.. example::
+
+ In the ring of integers, the normal form of
+ :math:`x (3 + yx + 25(1 − z)) + zx`
+ is
+ :math:`28x + (−24)xz + xxy`.
+
+
+``ring`` is also able to compute a normal form modulo monomial equalities.
+For example, under the hypothesis that :math:`2x^2 = yz+1`, the normal form of
+:math:`2(x + 1)x − x − zy` is :math:`x+1`.
+
+The variables map
+----------------------
+
+It is frequent to have an expression built with :math:`+` and :math:`\times`,
+but rarely on variables only. Let us associate a number to each subterm of a
+ring expression in the Gallina language. For example in the ring |nat|, consider
+the expression:
+
+
+::
+
+ (plus (mult (plus (f (5)) x) x)
+ (mult (if b then (4) else (f (3))) (2)))
+
+
+As a ring expression, it has 3 subterms. Give each subterm a number in
+an arbitrary order:
+
+===== =============== =========================
+0 :math:`\mapsto` if b then (4) else (f (3))
+1 :math:`\mapsto` (f (5))
+2 :math:`\mapsto` x
+===== =============== =========================
+
+Then normalize the “abstract” polynomial
+:math:`((V_1 \otimes V_2 ) \oplus V_2) \oplus (V_0 \otimes 2)`
+In our example the normal form is:
+:math:`(2 \otimes V_0 ) \oplus (V_1 \otimes V_2) \oplus (V_2 \otimes V_2 )`.
+Then substitute the variables by their values in the variables map to
+get the concrete normal polynomial:
+
+::
+
+ (plus (mult (2) (if b then (4) else (f (3))))
+ (plus (mult (f (5)) x) (mult x x)))
+
+
+Is it automatic?
+---------------------
+
+Yes, building the variables map and doing the substitution after
+normalizing is automatically done by the tactic. So you can just
+forget this paragraph and use the tactic according to your intuition.
+
+Concrete usage in Coq
+--------------------------
+
+.. tacn:: ring
+
+The ``ring`` tactic solves equations upon polynomial expressions of a ring
+(or semi-ring) structure. It proceeds by normalizing both hand sides
+of the equation (w.r.t. associativity, commutativity and
+distributivity, constant propagation, rewriting of monomials) and
+comparing syntactically the results.
+
+.. tacn:: ring_simplify
+
+``ring_simplify`` applies the normalization procedure described above to
+the terms given. The tactic then replaces all occurrences of the terms
+given in the conclusion of the goal by their normal forms. If no term
+is given, then the conclusion should be an equation and both hand
+sides are normalized. The tactic can also be applied in a hypothesis.
+
+The tactic must be loaded by ``Require Import Ring``. The ring structures
+must be declared with the ``Add Ring`` command (see below). The ring of
+booleans is predefined; if one wants to use the tactic on |nat| one must
+first require the module ``ArithRing`` exported by ``Arith``); for |Z|, do
+``Require Import ZArithRing`` or simply ``Require Import ZArith``; for |N|, do
+``Require Import NArithRing`` or ``Require Import NArith``.
+
+
+.. example::
+
+ .. coqtop:: all
+
+ Require Import ZArith.
+ Open Scope Z_scope.
+ Goal forall a b c:Z,
+ (a + b + c) ^ 2 =
+ a * a + b ^ 2 + c * c + 2 * a * b + 2 * a * c + 2 * b * c.
+ intros; ring.
+ Abort.
+ Goal forall a b:Z,
+ 2 * a * b = 30 -> (a + b) ^ 2 = a ^ 2 + b ^ 2 + 30.
+ intros a b H; ring [H].
+ Abort.
+
+
+.. tacv:: ring [{* @term }]
+
+decides the equality of two terms modulo ring operations and
+the equalities defined by the :n:`@term`\ s.
+Each :n:`@term` has to be a proof of some equality `m = p`, where `m` is a monomial (after “abstraction”), `p` a polynomial and `=` the corresponding equality of the ring structure.
+
+.. tacv:: ring_simplify [{* @term }] {* @term } in @ident
+
+performs the simplification in the hypothesis named :n:`@ident`.
+
+
+.. note::
+
+ .. tacn:: ring_simplify @term1; ring_simplify @term2
+
+ is not equivalent to
+
+ .. tacn:: ring_simplify @term1 @term2
+
+ In the latter case the variables map
+ is shared between the two terms, and common subterm `t` of :n:`@term1` and :n:`@term2`
+ will have the same associated variable number. So the first
+ alternative should be avoided for terms belonging to the same ring
+ theory.
+
+
+Error messages:
+
+
+.. exn:: not a valid ring equation
+
+ The conclusion of the goal is not provable in the corresponding ring theory.
+
+.. exn:: arguments of ring_simplify do not have all the same type
+
+ ``ring_simplify`` cannot simplify terms of several rings at the same
+ time. Invoke the tactic once per ring structure.
+
+.. exn:: cannot find a declared ring structure over @term
+
+ No ring has been declared for the type of the terms to be simplified.
+ Use ``Add Ring`` first.
+
+.. exn:: cannot find a declared ring structure for equality @term
+
+ Same as above is the case of the ``ring`` tactic.
+
+
+Adding a ring structure
+----------------------------
+
+Declaring a new ring consists in proving that a ring signature (a
+carrier set, an equality, and ring operations: ``Ring_theory.ring_theory``
+and ``Ring_theory.semi_ring_theory``) satisfies the ring axioms. Semi-
+rings (rings without + inverse) are also supported. The equality can
+be either Leibniz equality, or any relation declared as a setoid (see
+:ref:`tactics-enabled-on-user-provided-relations`). The definition of ring and semi-rings (see module
+``Ring_theory``) is:
+
+.. coqtop:: in
+
+ Record ring_theory : Prop := mk_rt {
+ Radd_0_l : forall x, 0 + x == x;
+ Radd_sym : forall x y, x + y == y + x;
+ Radd_assoc : forall x y z, x + (y + z) == (x + y) + z;
+ Rmul_1_l : forall x, 1 * x == x;
+ Rmul_sym : forall x y, x * y == y * x;
+ Rmul_assoc : forall x y z, x * (y * z) == (x * y) * z;
+ Rdistr_l : forall x y z, (x + y) * z == (x * z) + (y * z);
+ Rsub_def : forall x y, x - y == x + -y;
+ Ropp_def : forall x, x + (- x) == 0
+ }.
+
+ Record semi_ring_theory : Prop := mk_srt {
+ SRadd_0_l : forall n, 0 + n == n;
+ SRadd_sym : forall n m, n + m == m + n ;
+ SRadd_assoc : forall n m p, n + (m + p) == (n + m) + p;
+ SRmul_1_l : forall n, 1*n == n;
+ SRmul_0_l : forall n, 0*n == 0;
+ SRmul_sym : forall n m, n*m == m*n;
+ SRmul_assoc : forall n m p, n*(m*p) == (n*m)*p;
+ SRdistr_l : forall n m p, (n + m)*p == n*p + m*p
+ }.
+
+
+This implementation of ``ring`` also features a notion of constant that
+can be parameterized. This can be used to improve the handling of
+closed expressions when operations are effective. It consists in
+introducing a type of *coefficients* and an implementation of the ring
+operations, and a morphism from the coefficient type to the ring
+carrier type. The morphism needs not be injective, nor surjective.
+
+As an example, one can consider the real numbers. The set of
+coefficients could be the rational numbers, upon which the ring
+operations can be implemented. The fact that there exists a morphism
+is defined by the following properties:
+
+.. coqtop:: in
+
+ Record ring_morph : Prop := mkmorph {
+ morph0 : [cO] == 0;
+ morph1 : [cI] == 1;
+ morph_add : forall x y, [x +! y] == [x]+[y];
+ morph_sub : forall x y, [x -! y] == [x]-[y];
+ morph_mul : forall x y, [x *! y] == [x]*[y];
+ morph_opp : forall x, [-!x] == -[x];
+ morph_eq : forall x y, x?=!y = true -> [x] == [y]
+ }.
+
+ Record semi_morph : Prop := mkRmorph {
+ Smorph0 : [cO] == 0;
+ Smorph1 : [cI] == 1;
+ Smorph_add : forall x y, [x +! y] == [x]+[y];
+ Smorph_mul : forall x y, [x *! y] == [x]*[y];
+ Smorph_eq : forall x y, x?=!y = true -> [x] == [y]
+ }.
+
+
+where ``c0`` and ``cI`` denote the 0 and 1 of the coefficient set, ``+!``, ``*!``, ``-!``
+are the implementations of the ring operations, ``==`` is the equality of
+the coefficients, ``?+!`` is an implementation of this equality, and ``[x]``
+is a notation for the image of ``x`` by the ring morphism.
+
+Since |Z| is an initial ring (and |N| is an initial semi-ring), it can
+always be considered as a set of coefficients. There are basically
+three kinds of (semi-)rings:
+
+abstract rings
+ to be used when operations are not effective. The set
+ of coefficients is |Z| (or |N| for semi-rings).
+
+computational rings
+ to be used when operations are effective. The
+ set of coefficients is the ring itself. The user only has to provide
+ an implementation for the equality.
+
+customized ring
+ for other cases. The user has to provide the
+ coefficient set and the morphism.
+
+
+This implementation of ring can also recognize simple power
+expressions as ring expressions. A power function is specified by the
+following property:
+
+.. coqtop:: in
+
+ Section POWER.
+ Variable Cpow : Set.
+ Variable Cp_phi : N -> Cpow.
+ Variable rpow : R -> Cpow -> R.
+
+ Record power_theory : Prop := mkpow_th {
+ rpow_pow_N : forall r n, req (rpow r (Cp_phi n)) (pow_N rI rmul r n)
+ }.
+
+ End POWER.
+
+
+The syntax for adding a new ring is
+
+.. cmd:: Add Ring @ident : @term {? ( @ring_mod {* , @ring_mod } )}.
+
+The :n:`@ident` is not relevant. It is just used for error messages. The
+:n:`@term` is a proof that the ring signature satisfies the (semi-)ring
+axioms. The optional list of modifiers is used to tailor the behavior
+of the tactic. The following list describes their syntax and effects:
+
+.. prodn::
+ ring_mod ::= abstract %| decidable @term %| morphism @term
+ %| setoid @term @term
+ %| constants [@ltac]
+ %| preprocess [@ltac]
+ %| postprocess [@ltac]
+ %| power_tac @term [@ltac]
+ %| sign @term
+ %| div @term
+
+
+abstract
+ declares the ring as abstract. This is the default.
+
+decidable :n:`@term`
+ declares the ring as computational. The expression
+ :n:`@term` is the correctness proof of an equality test ``?=!``
+ (which hould be evaluable). Its type should be of the form
+ ``forall x y, x ?=! y = true → x == y``.
+
+morphism :n:`@term`
+ declares the ring as a customized one. The expression
+ :n:`@term` is a proof that there exists a morphism between a set of
+ coefficient and the ring carrier (see ``Ring_theory.ring_morph`` and
+ ``Ring_theory.semi_morph``).
+
+setoid :n:`@term` :n:`@term`
+ forces the use of given setoid. The first
+ :n:`@term` is a proof that the equality is indeed a setoid (see
+ ``Setoid.Setoid_Theory``), and the second :n:`@term` a proof that the
+ ring operations are morphisms (see ``Ring_theory.ring_eq_ext`` and
+ ``Ring_theory.sring_eq_ext``).
+ This modifier needs not be used if the setoid and morphisms have been
+ declared.
+
+constants [:n:`@ltac`]
+ specifies a tactic expression :n:`@ltac` that, given a
+ term, returns either an object of the coefficient set that is mapped
+ to the expression via the morphism, or returns
+ ``InitialRing.NotConstant``. The default behavior is to map only 0 and 1
+ to their counterpart in the coefficient set. This is generally not
+ desirable for non trivial computational rings.
+
+preprocess [:n:`@ltac`]
+ specifies a tactic :n:`@ltac` that is applied as a
+ preliminary step for ``ring`` and ``ring_simplify``. It can be used to
+ transform a goal so that it is better recognized. For instance, ``S n``
+ can be changed to ``plus 1 n``.
+
+postprocess [:n:`@ltac`]
+ specifies a tactic :n:`@ltac` that is applied as a final
+ step for ``ring_simplify``. For instance, it can be used to undo
+ modifications of the preprocessor.
+
+power_tac :n:`@term` [:n:`@ltac`]
+ allows ``ring`` and ``ring_simplify`` to recognize
+ power expressions with a constant positive integer exponent (example:
+ ::math:`x^2` ). The term :n:`@term` is a proof that a given power function satisfies
+ the specification of a power function (term has to be a proof of
+ ``Ring_theory.power_theory``) and :n:`@ltac` specifies a tactic expression
+ that, given a term, “abstracts” it into an object of type |N| whose
+ interpretation via ``Cp_phi`` (the evaluation function of power
+ coefficient) is the original term, or returns ``InitialRing.NotConstant``
+ if not a constant coefficient (i.e. |L_tac| is the inverse function of
+ ``Cp_phi``). See files ``plugins/setoid_ring/ZArithRing.v``
+ and ``plugins/setoid_ring/RealField.v`` for examples. By default the tactic
+ does not recognize power expressions as ring expressions.
+
+sign :n:`@term`
+ allows ``ring_simplify`` to use a minus operation when
+ outputting its normal form, i.e writing ``x − y`` instead of ``x + (− y)``. The
+ term `:n:`@term` is a proof that a given sign function indicates expressions
+ that are signed (`term` has to be a proof of ``Ring_theory.get_sign``). See
+ ``plugins/setoid_ring/InitialRing.v`` for examples of sign function.
+
+div :n:`@term`
+ allows ``ring`` and ``ring_simplify`` to use monomials with
+ coefficient other than 1 in the rewriting. The term :n:`@term` is a proof
+ that a given division function satisfies the specification of an
+ euclidean division function (:n:`@term` has to be a proof of
+ ``Ring_theory.div_theory``). For example, this function is called when
+ trying to rewrite :math:`7x` by :math:`2x = z` to tell that :math:`7 = 3 \times 2 + 1`. See
+ ``plugins/setoid_ring/InitialRing.v`` for examples of div function.
+
+Error messages:
+
+.. exn:: bad ring structure
+
+ The proof of the ring structure provided is not
+ of the expected type.
+
+.. exn:: bad lemma for decidability of equality
+
+ The equality function
+ provided in the case of a computational ring has not the expected
+ type.
+
+.. exn:: ring operation should be declared as a morphism
+
+ A setoid associated to the carrier of the ring structure has been found,
+ but the ring operation should be declared as morphism. See :ref:`tactics-enabled-on-user-provided-relations`.
+
+How does it work?
+----------------------
+
+The code of ring is a good example of tactic written using *reflection*.
+What is reflection? Basically, it is writing |Coq| tactics in |Coq|, rather
+than in |OCaml|. From the philosophical point of view, it is
+using the ability of the Calculus of Constructions to speak and reason
+about itself. For the ring tactic we used Coq as a programming
+language and also as a proof environment to build a tactic and to
+prove it correctness.
+
+The interested reader is strongly advised to have a look at the
+file ``Ring_polynom.v``. Here a type for polynomials is defined:
+
+
+.. coqtop:: in
+
+ Inductive PExpr : Type :=
+ | PEc : C -> PExpr
+ | PEX : positive -> PExpr
+ | PEadd : PExpr -> PExpr -> PExpr
+ | PEsub : PExpr -> PExpr -> PExpr
+ | PEmul : PExpr -> PExpr -> PExpr
+ | PEopp : PExpr -> PExpr
+ | PEpow : PExpr -> N -> PExpr.
+
+
+Polynomials in normal form are defined as:
+
+
+.. coqtop:: in
+
+ Inductive Pol : Type :=
+ | Pc : C -> Pol
+ | Pinj : positive -> Pol -> Pol
+ | PX : Pol -> positive -> Pol -> Pol.
+
+
+where ``Pinj n P`` denotes ``P`` in which :math:`V_i` is replaced by :math:`V_{i+n}` ,
+and ``PX P n Q`` denotes :math:`P \otimes V_1^n \oplus Q'`, `Q'` being `Q` where :math:`V_i` is replaced by :math:`V_{i+1}`.
+
+Variables maps are represented by list of ring elements, and two
+interpretation functions, one that maps a variables map and a
+polynomial to an element of the concrete ring, and the second one that
+does the same for normal forms:
+
+
+.. coqtop:: in
+
+
+ Definition PEeval : list R -> PExpr -> R := [...].
+ Definition Pphi_dev : list R -> Pol -> R := [...].
+
+
+A function to normalize polynomials is defined, and the big theorem is
+its correctness w.r.t interpretation, that is:
+
+
+.. coqtop:: in
+
+ Definition norm : PExpr -> Pol := [...].
+ Lemma Pphi_dev_ok :
+ forall l pe npe, norm pe = npe -> PEeval l pe == Pphi_dev l npe.
+
+
+So now, what is the scheme for a normalization proof? Let p be the
+polynomial expression that the user wants to normalize. First a little
+piece of |ML| code guesses the type of `p`, the ring theory `T` to use, an
+abstract polynomial `ap` and a variables map `v` such that `p` is |bdi|-
+equivalent to ``(PEeval`` `v` `ap`\ ``)``. Then we replace it by ``(Pphi_dev`` `v`
+``(norm`` `ap`\ ``))``, using the main correctness theorem and we reduce it to a
+concrete expression `p’`, which is the concrete normal form of `p`. This is summarized in this diagram:
+
+========= ====== ====
+`p` |ra| |re|
+\ |eq| \
+`p’` |la| |le|
+========= ====== ====
+
+The user do not see the right part of the diagram. From outside, the
+tactic behaves like a |bdi| simplification extended with AC rewriting
+rules. Basically, the proof is only the application of the main
+correctness theorem to well-chosen arguments.
+
+Dealing with fields
+------------------------
+
+.. tacn:: field
+
+The ``field`` tactic is an extension of the ``ring`` to deal with rational
+expression. Given a rational expression :math:`F = 0`. It first reduces the
+expression `F` to a common denominator :math:`N/D = 0` where `N` and `D`
+are two ring expressions. For example, if we take :math:`F = (1 − 1/x) x − x + 1`, this
+gives :math:`N = (x − 1) x − x^2 + x` and :math:`D = x`. It then calls ring to solve
+:math:`N = 0`.
+Note that ``field`` also generates non-zero conditions for all the
+denominators it encounters in the reduction. In our example, it
+generates the condition :math:`x \neq 0`. These conditions appear as one subgoal
+which is a conjunction if there are several denominators. Non-zero
+conditions are always polynomial expressions. For example when
+reducing the expression :math:`1/(1 + 1/x)`, two side conditions are
+generated: :math:`x \neq 0` and :math:`x + 1 \neq 0`. Factorized expressions are broken since
+a field is an integral domain, and when the equality test on
+coefficients is complete w.r.t. the equality of the target field,
+constants can be proven different from zero automatically.
+
+The tactic must be loaded by ``Require Import Field``. New field
+structures can be declared to the system with the ``Add Field`` command
+(see below). The field of real numbers is defined in module ``RealField``
+(in ``plugins/setoid_ring``). It is exported by module ``Rbase``, so
+that requiring ``Rbase`` or ``Reals`` is enough to use the field tactics on
+real numbers. Rational numbers in canonical form are also declared as
+a field in module ``Qcanon``.
+
+
+.. example::
+
+ .. coqtop:: all
+
+ Require Import Reals.
+ Open Scope R_scope.
+ Goal forall x,
+ x <> 0 -> (1 - 1 / x) * x - x + 1 = 0.
+ intros; field; auto.
+ Abort.
+ Goal forall x y,
+ y <> 0 -> y = x -> x / y = 1.
+ intros x y H H1; field [H1]; auto.
+ Abort.
+
+.. tacv:: field [{* @term}]
+
+ decides the equality of two terms modulo
+ field operations and the equalities defined
+ by the :n:`@term`\ s. Each :n:`@term` has to be a proof of some equality
+ `m` ``=`` `p`, where `m` is a monomial (after “abstraction”), `p` a polynomial
+ and ``=`` the corresponding equality of the field structure.
+
+.. note::
+
+ rewriting works with the equality `m` ``=`` `p` only if `p` is a polynomial since
+ rewriting is handled by the underlying ring tactic.
+
+.. tacv:: field_simplify
+
+ performs the simplification in the conclusion of the
+ goal, :math:`F_1 = F_2` becomes :math:`N_1 / D_1 = N_2 / D_2`. A normalization step
+ (the same as the one for rings) is then applied to :math:`N_1`, :math:`D_1`,
+ :math:`N_2` and :math:`D_2`. This way, polynomials remain in factorized form during the
+ fraction simplifications. This yields smaller expressions when
+ reducing to the same denominator since common factors can be canceled.
+
+.. tacv:: field_simplify [{* @term }]
+
+ performs the simplification in the conclusion of the goal using the equalities
+ defined by the :n:`@term`\ s.
+
+.. tacv:: field_simplify [{* @term }] {* @term }
+
+ performs the simplification in the terms :n:`@terms` of the conclusion of the goal
+ using the equalities defined by :n:`@term`\ s inside the brackets.
+
+.. tacv :: field_simplify in @ident
+
+ performs the simplification in the assumption :n:`@ident`.
+
+.. tacv :: field_simplify [{* @term }] in @ident
+
+ performs the simplification
+ in the assumption :n:`@ident` using the equalities defined by the :n:`@term`\ s.
+
+.. tacv:: field_simplify [{* @term }] {* @term } in @ident
+
+ performs the simplification in the :n:`@term`\ s of the assumption :n:`@ident` using the
+ equalities defined by the :n:`@term`\ s inside the brackets.
+
+.. tacv:: field_simplify_eq
+
+ performs the simplification in the conclusion of
+ the goal removing the denominator. :math:`F_1 = F_2` becomes :math:`N_1 D_2 = N_2 D_1`.
+
+.. tacv:: field_simplify_eq [ {* @term }]
+
+ performs the simplification in
+ the conclusion of the goal using the equalities defined by
+ :n:`@term`\ s.
+
+.. tacv:: field_simplify_eq in @ident
+
+ performs the simplification in the assumption :n:`@ident`.
+
+.. tacv:: field_simplify_eq [{* @term}] in @ident
+
+ performs the simplification in the assumption :n:`@ident` using the equalities defined by
+ :n:`@terms`\ s and removing the denominator.
+
+
+Adding a new field structure
+---------------------------------
+
+Declaring a new field consists in proving that a field signature (a
+carrier set, an equality, and field operations:
+``Field_theory.field_theory`` and ``Field_theory.semi_field_theory``)
+satisfies the field axioms. Semi-fields (fields without + inverse) are
+also supported. The equality can be either Leibniz equality, or any
+relation declared as a setoid (see :ref:`tactics-enabled-on-user-provided-relations`). The definition of
+fields and semi-fields is:
+
+.. coqtop:: in
+
+ Record field_theory : Prop := mk_field {
+ F_R : ring_theory rO rI radd rmul rsub ropp req;
+ F_1_neq_0 : ~ 1 == 0;
+ Fdiv_def : forall p q, p / q == p * / q;
+ Finv_l : forall p, ~ p == 0 -> / p * p == 1
+ }.
+
+ Record semi_field_theory : Prop := mk_sfield {
+ SF_SR : semi_ring_theory rO rI radd rmul req;
+ SF_1_neq_0 : ~ 1 == 0;
+ SFdiv_def : forall p q, p / q == p * / q;
+ SFinv_l : forall p, ~ p == 0 -> / p * p == 1
+ }.
+
+
+The result of the normalization process is a fraction represented by
+the following type:
+
+.. coqtop:: in
+
+ Record linear : Type := mk_linear {
+ num : PExpr C;
+ denum : PExpr C;
+ condition : list (PExpr C)
+ }.
+
+
+where ``num`` and ``denum`` are the numerator and denominator; ``condition`` is a
+list of expressions that have appeared as a denominator during the
+normalization process. These expressions must be proven different from
+zero for the correctness of the algorithm.
+
+The syntax for adding a new field is
+
+.. cmd:: Add Field @ident : @term {? ( @field_mod {* , @field_mod } )}.
+
+The :n:`@ident` is not relevant. It is just used for error
+messages. :n:`@term` is a proof that the field signature satisfies the
+(semi-)field axioms. The optional list of modifiers is used to tailor
+the behavior of the tactic.
+
+.. prodn::
+ field_mod := @ring_mod %| completeness @term
+
+Since field tactics are built upon ``ring``
+tactics, all modifiers of the ``Add Ring`` apply. There is only one
+specific modifier:
+
+completeness :n:`@term`
+ allows the field tactic to prove automatically
+ that the image of non-zero coefficients are mapped to non-zero
+ elements of the field. :n:`@term` is a proof of
+
+ ``forall x y, [x] == [y] -> x ?=! y = true``,
+
+ which is the completeness of equality on coefficients
+ w.r.t. the field equality.
+
+
+History of ring
+--------------------
+
+First Samuel Boutin designed the tactic ``ACDSimpl``. This tactic did lot
+of rewriting. But the proofs terms generated by rewriting were too big
+for |Coq|’s type-checker. Let us see why:
+
+.. coqtop:: all
+
+ Require Import ZArith.
+ Open Scope Z_scope.
+ Goal forall x y z : Z,
+ x + 3 + y + y * z = x + 3 + y + z * y.
+ intros; rewrite (Zmult_comm y z); reflexivity.
+ Save foo.
+ Print foo.
+
+At each step of rewriting, the whole context is duplicated in the
+proof term. Then, a tactic that does hundreds of rewriting generates
+huge proof terms. Since ``ACDSimpl`` was too slow, Samuel Boutin rewrote
+it using reflection (see his article in TACS’97 [Bou97]_). Later, it
+was rewritten by Patrick Loiseleur: the new tactic does not any
+more require ``ACDSimpl`` to compile and it makes use of |bdi|-reduction not
+only to replace the rewriting steps, but also to achieve the
+interleaving of computation and reasoning (see :ref:`discussion_reflection`). He also wrote a
+few |ML| code for the ``Add Ring`` command, that allow to register new rings
+dynamically.
+
+Proofs terms generated by ring are quite small, they are linear in the
+number of :math:`\oplus` and :math:`\otimes` operations in the normalized terms. Type-checking
+those terms requires some time because it makes a large use of the
+conversion rule, but memory requirements are much smaller.
+
+
+.. _discussion_reflection:
+
+
+Discussion
+----------------
+
+
+Efficiency is not the only motivation to use reflection here. ``ring``
+also deals with constants, it rewrites for example the expression
+``34 + 2 * x − x + 12`` to the expected result ``x + 46``.
+For the tactic ``ACDSimpl``, the only constants were 0 and 1.
+So the expression ``34 + 2 * (x − 1) + 12``
+is interpreted as :math:`V_0 \oplus V_1 \otimes (V_2 \ominus 1) \oplus V_3`\ ,
+with the variables mapping
+:math:`\{V_0 \mapsto 34; V_1 \mapsto 2; V_2 \mapsto x; V_3 \mapsto 12\}`\ .
+Then it is rewritten to ``34 − x + 2 * x + 12``, very far from the expected result.
+Here rewriting is not sufficient: you have to do some kind of reduction
+(some kind of computation) to achieve the normalization.
+
+The tactic ``ring`` is not only faster than a classical one: using
+reflection, we get for free integration of computation and reasoning
+that would be very complex to implement in the classic fashion.
+
+Is it the ultimate way to write tactics? The answer is: yes and no.
+The ``ring`` tactic uses intensively the conversion rule of |Cic|, that is
+replaces proof by computation the most as it is possible. It can be
+useful in all situations where a classical tactic generates huge proof
+terms. Symbolic Processing and Tautologies are in that case. But there
+are also tactics like ``auto`` or ``linear`` that do many complex computations,
+using side-effects and backtracking, and generate a small proof term.
+Clearly, it would be significantly less efficient to replace them by
+tactics using reflection.
+
+Another idea suggested by Benjamin Werner: reflection could be used to
+couple an external tool (a rewriting program or a model checker)
+with |Coq|. We define (in |Coq|) a type of terms, a type of *traces*, and
+prove a correction theorem that states that *replaying traces* is safe
+w.r.t some interpretation. Then we let the external tool do every
+computation (using side-effects, backtracking, exception, or others
+features that are not available in pure lambda calculus) to produce
+the trace: now we can check in |Coq| that the trace has the expected
+semantic by applying the correction lemma.
+
+
+
+
+
+
+.. rubric:: Footnotes
+.. [#f1] based on previous work from Patrick Loiseleur and Samuel Boutin
+
+
+
diff --git a/doc/sphinx/addendum/type-classes.rst b/doc/sphinx/addendum/type-classes.rst
new file mode 100644
index 000000000..becebb421
--- /dev/null
+++ b/doc/sphinx/addendum/type-classes.rst
@@ -0,0 +1,587 @@
+.. include:: ../replaces.rst
+
+.. _typeclasses:
+
+Type Classes
+============
+
+:Source: https://coq.inria.fr/distrib/current/refman/type-classes.html
+:Author: Matthieu Sozeau
+
+This chapter presents a quick reference of the commands related to type
+classes. For an actual introduction to type classes, there is a
+description of the system :cite:`sozeau08` and the literature on type
+classes in Haskell which also applies.
+
+
+Class and Instance declarations
+-------------------------------
+
+The syntax for class and instance declarations is the same as the record
+syntax of Coq:
+
+``Class Id (`` |p_1| ``:`` |t_1| ``) ⋯ (`` |p_n| ``:`` |t_n| ``) [:
+sort] := {`` |f_1| ``:`` |u_1| ``; ⋮`` |f_m| ``:`` |u_m| ``}.``
+
+``Instance ident : Id`` |p_1| ``⋯`` |p_n| ``:= {`` |f_1| ``:=`` |t_1| ``; ⋮`` |f_m| ``:=`` |t_m| ``}.``
+
+The |p_i| ``:`` |t_i| variables are called the *parameters* of the class and
+the |f_i| ``:`` |t_i| are called the *methods*. Each class definition gives
+rise to a corresponding record declaration and each instance is a
+regular definition whose name is given by ident and type is an
+instantiation of the record type.
+
+We’ll use the following example class in the rest of the chapter:
+
+.. coqtop:: in
+
+ Class EqDec (A : Type) := {
+ eqb : A -> A -> bool ;
+ eqb_leibniz : forall x y, eqb x y = true -> x = y }.
+
+This class implements a boolean equality test which is compatible with
+Leibniz equality on some type. An example implementation is:
+
+.. coqtop:: in
+
+ Instance unit_EqDec : EqDec unit :=
+ { eqb x y := true ;
+ eqb_leibniz x y H :=
+ match x, y return x = y with tt, tt => eq_refl tt end }.
+
+If one does not give all the members in the Instance declaration, Coq
+enters the proof-mode and the user is asked to build inhabitants of
+the remaining fields, e.g.:
+
+.. coqtop:: in
+
+ Instance eq_bool : EqDec bool :=
+ { eqb x y := if x then y else negb y }.
+
+.. coqtop:: all
+
+ Proof. intros x y H.
+
+.. coqtop:: all
+
+ destruct x ; destruct y ; (discriminate || reflexivity).
+
+.. coqtop:: all
+
+ Defined.
+
+One has to take care that the transparency of every field is
+determined by the transparency of the ``Instance`` proof. One can use
+alternatively the ``Program Instance`` variant which has richer facilities
+for dealing with obligations.
+
+
+Binding classes
+---------------
+
+Once a type class is declared, one can use it in class binders:
+
+.. coqtop:: all
+
+ Definition neqb {A} {eqa : EqDec A} (x y : A) := negb (eqb x y).
+
+When one calls a class method, a constraint is generated that is
+satisfied only in contexts where the appropriate instances can be
+found. In the example above, a constraint ``EqDec A`` is generated and
+satisfied by ``eqa : EqDec A``. In case no satisfying constraint can be
+found, an error is raised:
+
+.. coqtop:: all
+
+ Fail Definition neqb' (A : Type) (x y : A) := negb (eqb x y).
+
+The algorithm used to solve constraints is a variant of the eauto
+tactic that does proof search with a set of lemmas (the instances). It
+will use local hypotheses as well as declared lemmas in
+the ``typeclass_instances`` database. Hence the example can also be
+written:
+
+.. coqtop:: all
+
+ Definition neqb' A (eqa : EqDec A) (x y : A) := negb (eqb x y).
+
+However, the generalizing binders should be used instead as they have
+particular support for type classes:
+
++ They automatically set the maximally implicit status for type class
+ arguments, making derived functions as easy to use as class methods.
+ In the example above, ``A`` and ``eqa`` should be set maximally implicit.
++ They support implicit quantification on partially applied type
+ classes (:ref:`implicit-generalization`). Any argument not given as part of a type class
+ binder will be automatically generalized.
++ They also support implicit quantification on :ref:`superclasses`.
+
+
+Following the previous example, one can write:
+
+.. coqtop:: all
+
+ Generalizable Variables A B C.
+
+ Definition neqb_impl `{eqa : EqDec A} (x y : A) := negb (eqb x y).
+
+Here ``A`` is implicitly generalized, and the resulting function is
+equivalent to the one above.
+
+Parameterized Instances
+-----------------------
+
+One can declare parameterized instances as in Haskell simply by giving
+the constraints as a binding context before the instance, e.g.:
+
+.. coqtop:: in
+
+ Instance prod_eqb `(EA : EqDec A, EB : EqDec B) : EqDec (A * B) :=
+ { eqb x y := match x, y with
+ | (la, ra), (lb, rb) => andb (eqb la lb) (eqb ra rb)
+ end }.
+
+.. coqtop:: none
+
+ Abort.
+
+These instances are used just as well as lemmas in the instance hint
+database.
+
+Sections and contexts
+---------------------
+
+To ease the parametrization of developments by type classes, we
+provide a new way to introduce variables into section contexts,
+compatible with the implicit argument mechanism. The new command works
+similarly to the ``Variables`` vernacular (:ref:`TODO-1.3.2-Definitions`), except it
+accepts any binding context as argument. For example:
+
+.. coqtop:: all
+
+ Section EqDec_defs.
+
+ Context `{EA : EqDec A}.
+
+ Global Instance option_eqb : EqDec (option A) :=
+ { eqb x y := match x, y with
+ | Some x, Some y => eqb x y
+ | None, None => true
+ | _, _ => false
+ end }.
+ Admitted.
+
+ End EqDec_defs.
+
+ About option_eqb.
+
+Here the Global modifier redeclares the instance at the end of the
+section, once it has been generalized by the context variables it
+uses.
+
+
+Building hierarchies
+--------------------
+
+.. _superclasses:
+
+Superclasses
+~~~~~~~~~~~~
+
+One can also parameterize classes by other classes, generating a
+hierarchy of classes and superclasses. In the same way, we give the
+superclasses as a binding context:
+
+.. coqtop:: all
+
+ Class Ord `(E : EqDec A) := { le : A -> A -> bool }.
+
+Contrary to Haskell, we have no special syntax for superclasses, but
+this declaration is morally equivalent to:
+
+::
+
+ Class `(E : EqDec A) => Ord A :=
+ { le : A -> A -> bool }.
+
+
+This declaration means that any instance of the ``Ord`` class must have
+an instance of ``EqDec``. The parameters of the subclass contain at
+least all the parameters of its superclasses in their order of
+appearance (here A is the only one). As we have seen, ``Ord`` is encoded
+as a record type with two parameters: a type ``A`` and an ``E`` of type
+``EqDec A``. However, one can still use it as if it had a single
+parameter inside generalizing binders: the generalization of
+superclasses will be done automatically.
+
+.. coqtop:: all
+
+ Definition le_eqb `{Ord A} (x y : A) := andb (le x y) (le y x).
+
+In some cases, to be able to specify sharing of structures, one may
+want to give explicitly the superclasses. It is is possible to do it
+directly in regular binders, and using the ``!`` modifier in class
+binders. For example:
+
+.. coqtop:: all
+
+ Definition lt `{eqa : EqDec A, ! Ord eqa} (x y : A) := andb (le x y) (neqb x y).
+
+The ``!`` modifier switches the way a binder is parsed back to the regular
+interpretation of Coq. In particular, it uses the implicit arguments
+mechanism if available, as shown in the example.
+
+Substructures
+~~~~~~~~~~~~~
+
+Substructures are components of a class which are instances of a class
+themselves. They often arise when using classes for logical
+properties, e.g.:
+
+.. coqtop:: none
+
+ Require Import Relation_Definitions.
+
+.. coqtop:: in
+
+ Class Reflexive (A : Type) (R : relation A) :=
+ reflexivity : forall x, R x x.
+
+ Class Transitive (A : Type) (R : relation A) :=
+ transitivity : forall x y z, R x y -> R y z -> R x z.
+
+This declares singleton classes for reflexive and transitive relations,
+(see the :ref:`singleton class <singleton-class>` variant for an
+explanation). These may be used as part of other classes:
+
+.. coqtop:: all
+
+ Class PreOrder (A : Type) (R : relation A) :=
+ { PreOrder_Reflexive :> Reflexive A R ;
+ PreOrder_Transitive :> Transitive A R }.
+
+The syntax ``:>`` indicates that each ``PreOrder`` can be seen as a
+``Reflexive`` relation. So each time a reflexive relation is needed, a
+preorder can be used instead. This is very similar to the coercion
+mechanism of ``Structure`` declarations. The implementation simply
+declares each projection as an instance.
+
+One can also declare existing objects or structure projections using
+the Existing Instance command to achieve the same effect.
+
+
+Summary of the commands
+-----------------------
+
+
+.. _Class:
+
+.. cmd:: Class @ident {? @binders} : {? @sort} := {? @ident} { {+; @ident :{? >} @term } }.
+
+ The ``Class`` command is used to declare a type class with parameters
+ ``binders`` and fields the declared record fields.
+
+Variants:
+
+.. _singleton-class:
+
+.. cmd:: Class @ident {? @binders} : {? @sort} := @ident : @term
+
+ This variant declares a *singleton* class with a single method. This
+ singleton class is a so-called definitional class, represented simply
+ as a definition ``ident binders := term`` and whose instances are
+ themselves objects of this type. Definitional classes are not wrapped
+ inside records, and the trivial projection of an instance of such a
+ class is convertible to the instance itself. This can be useful to
+ make instances of existing objects easily and to reduce proof size by
+ not inserting useless projections. The class constant itself is
+ declared rigid during resolution so that the class abstraction is
+ maintained.
+
+.. cmd:: Existing Class @ident
+
+ This variant declares a class a posteriori from a constant or
+ inductive definition. No methods or instances are defined.
+
+.. _Instance:
+
+.. cmd:: Instance @ident {? @binders} : Class t1 … tn [| priority] := { field1 := b1 ; …; fieldi := bi }
+
+The ``Instance`` command is used to declare a type class instance named
+``ident`` of the class ``Class`` with parameters ``t1`` to ``tn`` and
+fields ``b1`` to ``bi``, where each field must be a declared field of
+the class. Missing fields must be filled in interactive proof mode.
+
+An arbitrary context of ``binders`` can be put after the name of the
+instance and before the colon to declare a parameterized instance. An
+optional priority can be declared, 0 being the highest priority as for
+auto hints. If the priority is not specified, it defaults to the number
+of non-dependent binders of the instance.
+
+Variants:
+
+
+.. cmd:: Instance ident {? @binders} : forall {? @binders}, Class t1 … tn [| priority] := @term
+
+ This syntax is used for declaration of singleton class instances or
+ for directly giving an explicit term of type ``forall binders, Class
+ t1 … tn``. One need not even mention the unique field name for
+ singleton classes.
+
+.. cmd:: Global Instance
+
+ One can use the ``Global`` modifier on instances declared in a
+ section so that their generalization is automatically redeclared
+ after the section is closed.
+
+.. cmd:: Program Instance
+
+ Switches the type-checking to Program (chapter :ref:`program`) and
+ uses the obligation mechanism to manage missing fields.
+
+.. cmd:: Declare Instance
+
+ In a Module Type, this command states that a corresponding concrete
+ instance should exist in any implementation of thisModule Type. This
+ is similar to the distinction betweenParameter vs. Definition, or
+ between Declare Module and Module.
+
+
+Besides the ``Class`` and ``Instance`` vernacular commands, there are a
+few other commands related to type classes.
+
+.. _ExistingInstance:
+
+Existing Instance
+~~~~~~~~~~~~~~~~~
+
+.. cmd:: Existing Instance {+ @ident} [| priority]
+
+This commands adds an arbitrary list of constants whose type ends with
+an applied type class to the instance database with an optional
+priority. It can be used for redeclaring instances at the end of
+sections, or declaring structure projections as instances. This is
+equivalent to ``Hint Resolve ident : typeclass_instances``, except it
+registers instances for ``Print Instances``.
+
+.. _Context:
+
+Context
+~~~~~~~
+
+.. cmd:: Context @binders
+
+Declares variables according to the given binding context, which might
+use :ref:`implicit-generalization`.
+
+
+.. _typeclasses-eauto:
+
+``typeclasses eauto``
+~~~~~~~~~~~~~~~~~~~~~
+
+The ``typeclasses eauto`` tactic uses a different resolution engine than
+eauto and auto. The main differences are the following:
+
++ Contrary to ``eauto`` and ``auto``, the resolution is done entirely in
+ the new proof engine (as of Coq v8.6), meaning that backtracking is
+ available among dependent subgoals, and shelving goals is supported.
+ typeclasses eauto is a multi-goal tactic. It analyses the dependencies
+ between subgoals to avoid backtracking on subgoals that are entirely
+ independent.
+
++ When called with no arguments, typeclasses eauto uses
+ thetypeclass_instances database by default (instead of core).
+ Dependent subgoals are automatically shelved, and shelved goals can
+ remain after resolution ends (following the behavior ofCoq 8.5).
+ *Note: * As of Coq 8.6, all:once (typeclasses eauto) faithfully
+ mimicks what happens during typeclass resolution when it is called
+ during refinement/type-inference, except that *only* declared class
+ subgoals are considered at the start of resolution during type
+ inference, while “all” can select non-class subgoals as well. It might
+ move to ``all:typeclasses eauto`` in future versions when the
+ refinement engine will be able to backtrack.
+
++ When called with specific databases (e.g. with), typeclasses eauto
+ allows shelved goals to remain at any point during search and treat
+ typeclasses goals like any other.
+
++ The transparency information of databases is used consistently for
+ all hints declared in them. It is always used when calling the
+ unifier. When considering the local hypotheses, we use the transparent
+ state of the first hint database given. Using an empty database
+ (created with Create HintDb for example) with unfoldable variables and
+ constants as the first argument of typeclasses eauto hence makes
+ resolution with the local hypotheses use full conversion during
+ unification.
+
+
+Variants:
+
+#. ``typeclasses eauto [num]``
+
+ *Warning:* The semantics for the limit num
+ is different than for auto. By default, if no limit is given the
+ search is unbounded. Contrary to auto, introduction steps (intro) are
+ counted, which might result in larger limits being necessary when
+ searching with typeclasses eauto than auto.
+
+#. ``typeclasses eauto with {+ @ident}``
+
+ This variant runs resolution with the given hint databases. It treats
+ typeclass subgoals the same as other subgoals (no shelving of
+ non-typeclass goals in particular).
+
+.. _autoapply:
+
+``autoapply term with ident``
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The tactic autoapply applies a term using the transparency information
+of the hint database ident, and does *no* typeclass resolution. This can
+be used in ``Hint Extern``’s for typeclass instances (in the hint
+database ``typeclass_instances``) to allow backtracking on the typeclass
+subgoals created by the lemma application, rather than doing type class
+resolution locally at the hint application time.
+
+.. _TypeclassesTransparent:
+
+Typeclasses Transparent, Typclasses Opaque
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. cmd:: Typeclasses { Transparent | Opaque } {+ @ident}
+
+ This commands defines the transparency of the given identifiers
+ during type class resolution. It is useful when some constants
+ prevent some unifications and make resolution fail. It is also useful
+ to declare constants which should never be unfolded during
+ proof-search, like fixpoints or anything which does not look like an
+ abbreviation. This can additionally speed up proof search as the
+ typeclass map can be indexed by such rigid constants (see
+ :ref:`thehintsdatabasesforautoandeauto`). By default, all constants
+ and local variables are considered transparent. One should take care
+ not to make opaque any constant that is used to abbreviate a type,
+ like:
+
+::
+
+ relation A := A -> A -> Prop.
+
+This is equivalent to ``Hint Transparent, Opaque ident : typeclass_instances``.
+
+
+Set Typeclasses Dependency Order
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+This option (on by default since 8.6) respects the dependency order
+between subgoals, meaning that subgoals which are depended on by other
+subgoals come first, while the non-dependent subgoals were put before
+the dependent ones previously (Coq v8.5 and below). This can result in
+quite different performance behaviors of proof search.
+
+
+Set Typeclasses Filtered Unification
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+This option, available since Coq 8.6 and off by default, switches the
+hint application procedure to a filter-then-unify strategy. To apply a
+hint, we first check that the goal *matches* syntactically the
+inferred or specified pattern of the hint, and only then try to
+*unify* the goal with the conclusion of the hint. This can drastically
+improve performance by calling unification less often, matching
+syntactic patterns being very quick. This also provides more control
+on the triggering of instances. For example, forcing a constant to
+explicitely appear in the pattern will make it never apply on a goal
+where there is a hole in that place.
+
+
+Set Typeclasses Limit Intros
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+
+This option (on by default) controls the ability to apply hints while
+avoiding (functional) eta-expansions in the generated proof term. It
+does so by allowing hints that conclude in a product to apply to a
+goal with a matching product directly, avoiding an introduction.
+*Warning:* this can be expensive as it requires rebuilding hint
+clauses dynamically, and does not benefit from the invertibility
+status of the product introduction rule, resulting in potentially more
+expensive proof-search (i.e. more useless backtracking).
+
+
+Set Typeclass Resolution For Conversion
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+This option (on by default) controls the use of typeclass resolution
+when a unification problem cannot be solved during elaboration/type-
+inference. With this option on, when a unification fails, typeclass
+resolution is tried before launching unification once again.
+
+
+Set Typeclasses Strict Resolution
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Typeclass declarations introduced when this option is set have a
+stricter resolution behavior (the option is off by default). When
+looking for unifications of a goal with an instance of this class, we
+“freeze” all the existentials appearing in the goals, meaning that
+they are considered rigid during unification and cannot be
+instantiated.
+
+
+Set Typeclasses Unique Solutions
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+When a typeclass resolution is launched we ensure that it has a single
+solution or fail. This ensures that the resolution is canonical, but
+can make proof search much more expensive.
+
+
+Set Typeclasses Unique Instances
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Typeclass declarations introduced when this option is set have a more
+efficient resolution behavior (the option is off by default). When a
+solution to the typeclass goal of this class is found, we never
+backtrack on it, assuming that it is canonical.
+
+
+Typeclasses eauto `:=`
+~~~~~~~~~~~~~~~~~~~~~~
+
+.. cmd:: Typeclasses eauto := {? debug} {? {dfs | bfs}} depth
+
+ This command allows more global customization of the type class
+ resolution tactic. The semantics of the options are:
+
+ + ``debug`` In debug mode, the trace of successfully applied tactics is
+ printed.
+
+ + ``dfs, bfs`` This sets the search strategy to depth-first search (the
+ default) or breadth-first search.
+
+ + ``depth`` This sets the depth limit of the search.
+
+
+Set Typeclasses Debug
+~~~~~~~~~~~~~~~~~~~~~
+
+.. cmd:: Set Typeclasses Debug {? Verbosity @num}
+
+These options allow to see the resolution steps of typeclasses that are
+performed during search. The ``Debug`` option is synonymous to ``Debug
+Verbosity 1``, and ``Debug Verbosity 2`` provides more information
+(tried tactics, shelving of goals, etc…).
+
+
+Set Refine Instance Mode
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+The option Refine Instance Mode allows to switch the behavior of
+instance declarations made through the Instance command.
+
++ When it is on (the default), instances that have unsolved holes in
+ their proof-term silently open the proof mode with the remaining
+ obligations to prove.
+
++ When it is off, they fail with an error instead.
diff --git a/doc/sphinx/credits.rst b/doc/sphinx/credits.rst
index a60f32645..fac0d0a4f 100644
--- a/doc/sphinx/credits.rst
+++ b/doc/sphinx/credits.rst
@@ -376,7 +376,7 @@ contributed by Jean Goubault was integrated in the basic theories.
Pierre Courtieu developed a command and a tactic to reason on the
inductive structure of recursively defined functions.
-Jacek Chrzszcz designed and implemented the module system of |Coq| whose
+Jacek Chrząszcz designed and implemented the module system of |Coq| whose
foundations are in Judicaël Courant’s PhD thesis.
The development was coordinated by C. Paulin.
@@ -478,7 +478,7 @@ Marché and Bruno Barras.
Claude Marché coordinated the edition of the Reference Manual for |Coq|
V8.0.
-Pierre Letouzey and Jacek Chrzszcz respectively maintained the
+Pierre Letouzey and Jacek Chrząszcz respectively maintained the
extraction tool and module system of |Coq|.
Jean-Christophe Filliâtre, Pierre Letouzey, Hugo Herbelin and other
diff --git a/doc/sphinx/index.rst b/doc/sphinx/index.rst
index c5d4936b1..db03693ff 100644
--- a/doc/sphinx/index.rst
+++ b/doc/sphinx/index.rst
@@ -44,9 +44,18 @@ Table of contents
:caption: Addendum
addendum/extended-pattern-matching
+ addendum/implicit-coercions
addendum/canonical-structures
+ addendum/type-classes
addendum/omega
addendum/micromega
+ addendum/extraction
+ addendum/program
+ addendum/ring
+ addendum/nsatz
+ addendum/generalized-rewriting
+ addendum/parallel-proof-processing
+ addendum/miscellaneous-extensions
.. toctree::
:caption: Reference
diff --git a/doc/sphinx/language/gallina-extensions.rst b/doc/sphinx/language/gallina-extensions.rst
index d618d90ad..1d6c11b38 100644
--- a/doc/sphinx/language/gallina-extensions.rst
+++ b/doc/sphinx/language/gallina-extensions.rst
@@ -2109,6 +2109,8 @@ case, this latter type is considered).
Adds blocks of implicit types with different specifications.
+.. _implicit-generalization:
+
Implicit generalization
~~~~~~~~~~~~~~~~~~~~~~~
@@ -2189,12 +2191,7 @@ an inductive type or any constant with a type of the form
Then the user is able to apply an object that is not a function, but
can be coerced to a function, and more generally to consider that a
term of type ``A`` is of type ``B`` provided that there is a declared coercion
-between ``A`` and ``B``. The main command is
-
-.. cmd:: Coercion @qualid : @class >-> @class.
-
-which declares the construction denoted by qualid as a coercion
-between the two given classes.
+between ``A`` and ``B``.
More details and examples, and a description of the commands related
to coercions are provided in :ref:`implicitcoercions`.
diff --git a/doc/sphinx/replaces.rst b/doc/sphinx/replaces.rst
index d4f6835ef..1b2e17221 100644
--- a/doc/sphinx/replaces.rst
+++ b/doc/sphinx/replaces.rst
@@ -64,6 +64,14 @@
.. |t_i| replace:: `t`\ :math:`_{i}`
.. |t_m| replace:: `t`\ :math:`_{m}`
.. |t_n| replace:: `t`\ :math:`_{n}`
+.. |f_1| replace:: `f`\ :math:`_{1}`
+.. |f_i| replace:: `f`\ :math:`_{i}`
+.. |f_m| replace:: `f`\ :math:`_{m}`
+.. |f_n| replace:: `f`\ :math:`_{n}`
+.. |u_1| replace:: `u`\ :math:`_{1}`
+.. |u_i| replace:: `u`\ :math:`_{i}`
+.. |u_m| replace:: `u`\ :math:`_{m}`
+.. |u_n| replace:: `u`\ :math:`_{n}`
.. |term_0| replace:: `term`\ :math:`_{0}`
.. |term_1| replace:: `term`\ :math:`_{1}`
.. |term_2| replace:: `term`\ :math:`_{2}`
diff --git a/engine/evarutil.ml b/engine/evarutil.ml
index 9cf81ecce..45760c6b4 100644
--- a/engine/evarutil.ml
+++ b/engine/evarutil.ml
@@ -807,11 +807,11 @@ let judge_of_new_Type evd =
let (evd', s) = new_univ_variable univ_rigid evd in
(evd', { uj_val = mkSort (Type s); uj_type = mkSort (Type (Univ.super s)) })
-let subterm_source evk (loc,k) =
+let subterm_source evk ?where (loc,k) =
let evk = match k with
- | Evar_kinds.SubEvar (evk) -> evk
+ | Evar_kinds.SubEvar (None,evk) when where = None -> evk
| _ -> evk in
- (loc,Evar_kinds.SubEvar evk)
+ (loc,Evar_kinds.SubEvar (where,evk))
(* Add equality constraints for covariant/invariant positions. For
irrelevant positions, unify universes when flexible. *)
diff --git a/engine/evarutil.mli b/engine/evarutil.mli
index e289ca169..972b0b9e1 100644
--- a/engine/evarutil.mli
+++ b/engine/evarutil.mli
@@ -254,7 +254,7 @@ val evd_comb0 : (evar_map -> evar_map * 'a) -> evar_map ref -> 'a
val evd_comb1 : (evar_map -> 'b -> evar_map * 'a) -> evar_map ref -> 'b -> 'a
val evd_comb2 : (evar_map -> 'b -> 'c -> evar_map * 'a) -> evar_map ref -> 'b -> 'c -> 'a
-val subterm_source : Evar.t -> Evar_kinds.t Loc.located ->
+val subterm_source : Evar.t -> ?where:Evar_kinds.subevar_kind -> Evar_kinds.t Loc.located ->
Evar_kinds.t Loc.located
val meta_counter_summary_tag : int Summary.Dyn.tag
diff --git a/engine/proofview.ml b/engine/proofview.ml
index 22271dd02..639f48e77 100644
--- a/engine/proofview.ml
+++ b/engine/proofview.ml
@@ -710,13 +710,19 @@ let partition_unifiable sigma l =
(** Shelves the unifiable goals under focus, i.e. the goals which
appear in other goals under focus (the unfocused goals are not
considered). *)
-let shelve_unifiable =
+let shelve_unifiable_informative =
let open Proof in
Pv.get >>= fun initial ->
let (u,n) = partition_unifiable initial.solution initial.comb in
Comb.set n >>
InfoL.leaf (Info.Tactic (fun () -> Pp.str"shelve_unifiable")) >>
- Shelf.modify (fun gls -> gls @ CList.map drop_state u)
+ let u = CList.map drop_state u in
+ Shelf.modify (fun gls -> gls @ u) >>
+ tclUNIT u
+
+let shelve_unifiable =
+ let open Proof in
+ shelve_unifiable_informative >>= fun _ -> tclUNIT ()
(** [guard_no_unifiable] returns the list of unifiable goals if some
goals are unifiable (see {!shelve_unifiable}) in the current focus. *)
@@ -1035,6 +1041,8 @@ module Unsafe = struct
let advance = Evarutil.advance
+ let undefined = undefined
+
let mark_as_unresolvable p gl =
{ p with solution = mark_in_evm ~goal:false p.solution gl }
diff --git a/engine/proofview.mli b/engine/proofview.mli
index e7be66552..1905686fe 100644
--- a/engine/proofview.mli
+++ b/engine/proofview.mli
@@ -326,6 +326,9 @@ val unifiable : Evd.evar_map -> Evar.t -> Evar.t list -> bool
considered). *)
val shelve_unifiable : unit tactic
+(** Idem but also returns the list of shelved variables *)
+val shelve_unifiable_informative : Evar.t list tactic
+
(** [guard_no_unifiable] returns the list of unifiable goals if some
goals are unifiable (see {!shelve_unifiable}) in the current focus. *)
val guard_no_unifiable : Names.Name.t list option tactic
@@ -466,6 +469,12 @@ module Unsafe : sig
solved. *)
val advance : Evd.evar_map -> Evar.t -> Evar.t option
+ (** [undefined sigma l] applies [advance] to the goals of [l], then
+ returns the subset of resulting goals which have not yet been
+ defined *)
+ val undefined : Evd.evar_map -> Proofview_monad.goal_with_state list ->
+ Proofview_monad.goal_with_state list
+
val typeclass_resolvable : unit Evd.Store.field
end
diff --git a/engine/termops.ml b/engine/termops.ml
index 3dfb0c34f..b7531f6fc 100644
--- a/engine/termops.ml
+++ b/engine/termops.ml
@@ -206,8 +206,12 @@ let pr_evar_source = function
| Evar_kinds.ImpossibleCase -> str "type of impossible pattern-matching clause"
| Evar_kinds.MatchingVar _ -> str "matching variable"
| Evar_kinds.VarInstance id -> str "instance of " ++ Id.print id
- | Evar_kinds.SubEvar evk ->
- str "subterm of " ++ Evar.print evk
+ | Evar_kinds.SubEvar (where,evk) ->
+ (match where with
+ | None -> str "subterm of "
+ | Some Evar_kinds.Body -> str "body of "
+ | Some Evar_kinds.Domain -> str "domain of "
+ | Some Evar_kinds.Codomain -> str "codomain of ") ++ Evar.print evk
let pr_evar_info evi =
let open Evd in
diff --git a/ide/MacOS/relatify_with-respect-to_.sh b/ide/MacOS/relatify_with-respect-to_.sh
deleted file mode 100755
index a24af9395..000000000
--- a/ide/MacOS/relatify_with-respect-to_.sh
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/sh
-
-set -e
-
-for i in "$3/"*.dylib
-do install_name_tool -change "$2"/$(basename $i) @executable_path/../Resources/lib/$(basename $i) "$1"
-done
-case "$1" in
- *.dylib)
- install_name_tool -id @executable_path/../Resources/lib/$(basename $1) $1
- for i in "$3"/*.dylib
- do install_name_tool -change "$2/"$(basename $1) @executable_path/../Resources/lib/$(basename $1) $i
- done;;
- *)
-esac
diff --git a/interp/constrextern.ml b/interp/constrextern.ml
index 19444988b..bb5fd5294 100644
--- a/interp/constrextern.ml
+++ b/interp/constrextern.ml
@@ -14,7 +14,6 @@ open CErrors
open Util
open Names
open Nameops
-open Constr
open Termops
open Libnames
open Globnames
@@ -590,11 +589,17 @@ let explicitize inctx impl (cf,f) args =
let expl () =
match ip with
| Some i ->
- if not (List.is_empty impl) && is_status_implicit (List.nth impl (i-1)) then
- raise Expl
+ (* Careful: It is possible to have declared implicits ending
+ before the principal argument *)
+ let is_impl =
+ try is_status_implicit (List.nth impl (i-1))
+ with Failure _ -> false
+ in
+ if is_impl
+ then raise Expl
else
let (args1,args2) = List.chop i args in
- let (impl1,impl2) = if List.is_empty impl then [],[] else List.chop i impl in
+ let (impl1,impl2) = try List.chop i impl with Failure _ -> impl, [] in
let args1 = exprec 1 (args1,impl1) in
let args2 = exprec (i+1) (args2,impl2) in
let ip = Some (List.length args1) in
@@ -1223,8 +1228,36 @@ let rec glob_of_pat avoid env sigma pat = DAst.make @@ match pat with
| _ -> anomaly (Pp.str "PCase with non-trivial predicate but unknown inductive.")
in
GCases (RegularStyle,rtn,[glob_of_pat avoid env sigma tm,indnames],mat)
- | PFix f -> DAst.get (Detyping.detype_names false avoid env (Global.env()) sigma (EConstr.of_constr (mkFix f))) (** FIXME bad env *)
- | PCoFix c -> DAst.get (Detyping.detype_names false avoid env (Global.env()) sigma (EConstr.of_constr (mkCoFix c)))
+ | PFix ((ln,i),(lna,tl,bl)) ->
+ let def_avoid, def_env, lfi =
+ Array.fold_left
+ (fun (avoid, env, l) na ->
+ let id = Namegen.next_name_away na avoid in
+ (Id.Set.add id avoid, Name id :: env, id::l))
+ (avoid, env, []) lna in
+ let n = Array.length tl in
+ let v = Array.map3
+ (fun c t i -> Detyping.share_pattern_names glob_of_pat (i+1) [] def_avoid def_env sigma c (Patternops.lift_pattern n t))
+ bl tl ln in
+ GRec(GFix (Array.map (fun i -> Some i, GStructRec) ln,i),Array.of_list (List.rev lfi),
+ Array.map (fun (bl,_,_) -> bl) v,
+ Array.map (fun (_,_,ty) -> ty) v,
+ Array.map (fun (_,bd,_) -> bd) v)
+ | PCoFix (ln,(lna,tl,bl)) ->
+ let def_avoid, def_env, lfi =
+ Array.fold_left
+ (fun (avoid, env, l) na ->
+ let id = Namegen.next_name_away na avoid in
+ (Id.Set.add id avoid, Name id :: env, id::l))
+ (avoid, env, []) lna in
+ let ntys = Array.length tl in
+ let v = Array.map2
+ (fun c t -> share_pattern_names glob_of_pat 0 [] def_avoid def_env sigma c (Patternops.lift_pattern ntys t))
+ bl tl in
+ GRec(GCoFix ln,Array.of_list (List.rev lfi),
+ Array.map (fun (bl,_,_) -> bl) v,
+ Array.map (fun (_,_,ty) -> ty) v,
+ Array.map (fun (_,bd,_) -> bd) v)
| PSort s -> GSort s
let extern_constr_pattern env sigma pat =
diff --git a/interp/impargs.ml b/interp/impargs.ml
index 9ad62c0de..b424f73de 100644
--- a/interp/impargs.ml
+++ b/interp/impargs.ml
@@ -139,7 +139,7 @@ let argument_less = function
| Hyp _, Conclusion -> true
| Conclusion, _ -> false
-let update pos rig (na,st) =
+let update pos rig st =
let e =
if rig then
match st with
@@ -163,7 +163,7 @@ let update pos rig (na,st) =
| Some (DepFlex fpos as x) ->
if argument_less (pos,fpos) then DepFlex pos else x
| Some Manual -> assert false
- in na, Some e
+ in Some e
(* modified is_rigid_reference with a truncated env *)
let is_flexible_reference env sigma bound depth f =
@@ -214,6 +214,8 @@ let add_free_rels_until strict strongly_strict revpat bound env sigma m pos acc
let () = if not (Vars.noccur_between sigma 1 bound m) then frec true (env,1) m in
acc
+(* compute the list of implicit arguments *)
+
let rec is_rigid_head sigma t = match kind sigma t with
| Rel _ | Evar _ -> false
| Ind _ | Const _ | Var _ | Sort _ -> true
@@ -226,7 +228,14 @@ let rec is_rigid_head sigma t = match kind sigma t with
| Lambda _ | LetIn _ | Construct _ | CoFix _ | Fix _
| Prod _ | Meta _ | Cast _ -> assert false
-(* calcule la liste des arguments implicites *)
+let is_rigid env sigma t =
+ let open Context.Rel.Declaration in
+ let t = whd_all env sigma t in
+ match kind sigma t with
+ | Prod (na,a,b) ->
+ let (_,t) = splay_prod (push_rel (LocalAssum (na,a)) env) sigma b in
+ is_rigid_head sigma t
+ | _ -> true
let find_displayed_name_in all avoid na (env, b) =
let envnames_b = (env, b) in
@@ -234,43 +243,54 @@ let find_displayed_name_in all avoid na (env, b) =
if all then compute_and_force_displayed_name_in Evd.empty flag avoid na b
else compute_displayed_name_in Evd.empty flag avoid na b
-let compute_implicits_gen strict strongly_strict revpat contextual all env sigma (t : EConstr.t) =
- let rigid = ref true in
+let compute_implicits_names_gen all env sigma t =
+ let open Context.Rel.Declaration in
+ let rec aux env avoid names t =
+ let t = whd_all env sigma t in
+ match kind sigma t with
+ | Prod (na,a,b) ->
+ let na',avoid' = find_displayed_name_in all avoid na (names,b) in
+ aux (push_rel (LocalAssum (na,a)) env) avoid' (na'::names) b
+ | _ -> List.rev names
+ in aux env Id.Set.empty [] t
+
+let compute_implicits_names = compute_implicits_names_gen true
+
+let compute_implicits_explanation_gen strict strongly_strict revpat contextual env sigma t =
let open Context.Rel.Declaration in
- let rec aux env avoid n names (t : EConstr.t) =
+ let rec aux env n t =
let t = whd_all env sigma t in
match kind sigma t with
- | Prod (na,a,b) ->
- let na',avoid' = find_displayed_name_in all avoid na (names,b) in
- add_free_rels_until strict strongly_strict revpat n env sigma a (Hyp (n+1))
- (aux (push_rel (LocalAssum (na',a)) env) avoid' (n+1) (na'::names) b)
- | _ ->
- rigid := is_rigid_head sigma t;
- let names = List.rev names in
- let v = Array.map (fun na -> na,None) (Array.of_list names) in
- if contextual then
- add_free_rels_until strict strongly_strict revpat n env sigma t Conclusion v
- else v
+ | Prod (na,a,b) ->
+ add_free_rels_until strict strongly_strict revpat n env sigma a (Hyp (n+1))
+ (aux (push_rel (LocalAssum (na,a)) env) (n+1) b)
+ | _ ->
+ let v = Array.make n None in
+ if contextual then
+ add_free_rels_until strict strongly_strict revpat n env sigma t Conclusion v
+ else v
in
match kind sigma (whd_all env sigma t) with
- | Prod (na,a,b) ->
- let na',avoid = find_displayed_name_in all Id.Set.empty na ([],b) in
- let v = aux (push_rel (LocalAssum (na',a)) env) avoid 1 [na'] b in
- !rigid, Array.to_list v
- | _ -> true, []
+ | Prod (na,a,b) ->
+ let v = aux (push_rel (LocalAssum (na,a)) env) 1 b in
+ Array.to_list v
+ | _ -> []
-let compute_implicits_flags env sigma f all t =
- compute_implicits_gen
+let compute_implicits_explanation_flags env sigma f t =
+ compute_implicits_explanation_gen
(f.strict || f.strongly_strict) f.strongly_strict
- f.reversible_pattern f.contextual all env sigma t
+ f.reversible_pattern f.contextual env sigma t
-let compute_auto_implicits env sigma flags enriching t =
- if enriching then compute_implicits_flags env sigma flags true t
- else compute_implicits_gen false false false true true env sigma t
+let compute_implicits_flags env sigma f all t =
+ List.combine
+ (compute_implicits_names_gen all env sigma t)
+ (compute_implicits_explanation_flags env sigma f t)
-let compute_implicits_names env sigma t =
- let _, impls = compute_implicits_gen false false false false true env sigma t in
- List.map fst impls
+let compute_auto_implicits env sigma flags enriching t =
+ List.combine
+ (compute_implicits_names env sigma t)
+ (if enriching then compute_implicits_explanation_flags env sigma flags t
+ else compute_implicits_explanation_gen false false false true env sigma t)
(* Extra information about implicit arguments *)
@@ -329,13 +349,16 @@ let rec prepare_implicits f = function
Some (id,imp,(set_maximality imps' f.maximal,true)) :: imps'
| _::imps -> None :: prepare_implicits f imps
-let set_implicit id imp insmax =
- (id,(match imp with None -> Manual | Some imp -> imp),insmax)
-
-let rec assoc_by_pos k = function
- (ExplByPos (k', x), b) :: tl when Int.equal k k' -> (x,b), tl
- | hd :: tl -> let (x, tl) = assoc_by_pos k tl in x, hd :: tl
- | [] -> raise Not_found
+(*
+If found, returns Some (x,(b,fi,fo)) and l with the entry removed,
+otherwise returns None and l unchanged.
+ *)
+let assoc_by_pos k l =
+ let rec aux = function
+ (ExplByPos (k', x), b) :: tl when Int.equal k k' -> Some (x,b), tl
+ | hd :: tl -> let (x, tl) = aux tl in x, hd :: tl
+ | [] -> raise Not_found
+ in try aux l with Not_found -> None, l
let check_correct_manual_implicits autoimps l =
List.iter (function
@@ -352,70 +375,65 @@ let check_correct_manual_implicits autoimps l =
(str "Cannot set implicit argument number " ++ int i ++
str ": it has no name.")) l
-let set_manual_implicits env flags enriching autoimps l =
- let try_forced k l =
- try
- let (id, (b, fi, fo)), l' = assoc_by_pos k l in
- if fo then
- let id = match id with Some id -> id | None -> Id.of_string ("arg_" ^ string_of_int k) in
- l', Some (id,Manual,(b,fi))
- else l, None
- with Not_found -> l, None
- in
+(* Take a list l of explicitations, and map them to positions. *)
+let flatten_explicitations l autoimps =
+ let rec aux k l = function
+ | (Name id,_)::imps ->
+ let value, l' =
+ try
+ let eq = explicitation_eq in
+ let flags = List.assoc_f eq (ExplByName id) l in
+ Some (Some id, flags), List.remove_assoc_f eq (ExplByName id) l
+ with Not_found -> assoc_by_pos k l
+ in value :: aux (k+1) l' imps
+ | (Anonymous,_)::imps ->
+ let value, l' = assoc_by_pos k l
+ in value :: aux (k+1) l' imps
+ | [] when List.is_empty l -> []
+ | [] ->
+ check_correct_manual_implicits autoimps l;
+ []
+ in aux 1 l autoimps
+
+let set_manual_implicits flags enriching autoimps l =
if not (List.distinct l) then
user_err Pp.(str "Some parameters are referred more than once.");
(* Compare with automatic implicits to recover printing data and names *)
- let rec merge k l = function
- | (Name id,imp)::imps ->
- let l',imp,m =
- try
- let eq = explicitation_eq in
- let (b, fi, fo) = List.assoc_f eq (ExplByName id) l in
- List.remove_assoc_f eq (ExplByName id) l, (Some Manual), (Some (b, fi))
- with Not_found ->
- try
- let (id, (b, fi, fo)), l' = assoc_by_pos k l in
- l', (Some Manual), (Some (b,fi))
- with Not_found ->
- let m = match enriching, imp with
- | true, Some _ -> Some (flags.maximal, true)
- | _ -> None
- in
- l, imp, m
- in
- let imps' = merge (k+1) l' imps in
- let m = Option.map (fun (b,f) ->
- (* match imp with Some Manual -> (b,f) *)
- (* | _ -> *)set_maximality imps' b, f) m in
- Option.map (set_implicit id imp) m :: imps'
- | (Anonymous,imp)::imps ->
- let l', forced = try_forced k l in
- forced :: merge (k+1) l' imps
- | [] when begin match l with [] -> true | _ -> false end -> []
- | [] ->
- check_correct_manual_implicits autoimps l;
- []
- in
- merge 1 l autoimps
-
-let compute_semi_auto_implicits env sigma f manual t =
- match manual with
- | [] ->
- if not f.auto then [DefaultImpArgs, []]
- else let _,l = compute_implicits_flags env sigma f false t in
- [DefaultImpArgs, prepare_implicits f l]
- | _ ->
- let _,autoimpls = compute_auto_implicits env sigma f f.auto t in
- [DefaultImpArgs, set_manual_implicits env f f.auto autoimpls manual]
+ let rec merge k autoimps explimps = match autoimps, explimps with
+ | autoimp::autoimps, explimp::explimps ->
+ let imps' = merge (k+1) autoimps explimps in
+ begin match autoimp, explimp with
+ | (Name id,_), Some (_, (b, fi, _)) ->
+ Some (id, Manual, (set_maximality imps' b, fi))
+ | (Name id,Some exp), None when enriching ->
+ Some (id, exp, (set_maximality imps' flags.maximal, true))
+ | (Name _,_), None -> None
+ | (Anonymous,_), Some (Some id, (b, fi, true)) ->
+ Some (id,Manual,(b,fi))
+ | (Anonymous,_), Some (None, (b, fi, true)) ->
+ let id = Id.of_string ("arg_" ^ string_of_int k) in
+ Some (id,Manual,(b,fi))
+ | (Anonymous,_), Some (_, (_, _, false)) -> None
+ | (Anonymous,_), None -> None
+ end :: imps'
+ | [], [] -> []
+ (* flatten_explicitations returns a list of the same length as autoimps *)
+ | _ -> assert false
+ in merge 1 autoimps (flatten_explicitations l autoimps)
+
+let compute_semi_auto_implicits env sigma f t =
+ if not f.auto then [DefaultImpArgs, []]
+ else let l = compute_implicits_flags env sigma f false t in
+ [DefaultImpArgs, prepare_implicits f l]
(*s Constants. *)
-let compute_constant_implicits flags manual cst =
+let compute_constant_implicits flags cst =
let env = Global.env () in
let sigma = Evd.from_env env in
let cb = Environ.lookup_constant cst env in
let ty = of_constr cb.const_type in
- let impls = compute_semi_auto_implicits env sigma flags manual ty in
+ let impls = compute_semi_auto_implicits env sigma flags ty in
impls
(*s Inductives and constructors. Their implicit arguments are stored
@@ -423,7 +441,7 @@ let compute_constant_implicits flags manual cst =
$i$ are the implicit arguments of the inductive and $v$ the array of
implicit arguments of the constructors. *)
-let compute_mib_implicits flags manual kn =
+let compute_mib_implicits flags kn =
let env = Global.env () in
let sigma = Evd.from_env env in
let mib = Environ.lookup_mind kn env in
@@ -439,34 +457,34 @@ let compute_mib_implicits flags manual kn =
let imps_one_inductive i mip =
let ind = (kn,i) in
let ar, _ = Global.type_of_global_in_context env (IndRef ind) in
- ((IndRef ind,compute_semi_auto_implicits env sigma flags manual (of_constr ar)),
+ ((IndRef ind,compute_semi_auto_implicits env sigma flags (of_constr ar)),
Array.mapi (fun j c ->
- (ConstructRef (ind,j+1),compute_semi_auto_implicits env_ar sigma flags manual c))
+ (ConstructRef (ind,j+1),compute_semi_auto_implicits env_ar sigma flags c))
(Array.map of_constr mip.mind_nf_lc))
in
Array.mapi imps_one_inductive mib.mind_packets
-let compute_all_mib_implicits flags manual kn =
- let imps = compute_mib_implicits flags manual kn in
+let compute_all_mib_implicits flags kn =
+ let imps = compute_mib_implicits flags kn in
List.flatten
(Array.map_to_list (fun (ind,cstrs) -> ind::Array.to_list cstrs) imps)
(*s Variables. *)
-let compute_var_implicits flags manual id =
+let compute_var_implicits flags id =
let env = Global.env () in
let sigma = Evd.from_env env in
- compute_semi_auto_implicits env sigma flags manual (NamedDecl.get_type (lookup_named id env))
+ compute_semi_auto_implicits env sigma flags (NamedDecl.get_type (lookup_named id env))
(* Implicits of a global reference. *)
-let compute_global_implicits flags manual = function
- | VarRef id -> compute_var_implicits flags manual id
- | ConstRef kn -> compute_constant_implicits flags manual kn
+let compute_global_implicits flags = function
+ | VarRef id -> compute_var_implicits flags id
+ | ConstRef kn -> compute_constant_implicits flags kn
| IndRef (kn,i) ->
- let ((_,imps),_) = (compute_mib_implicits flags manual kn).(i) in imps
+ let ((_,imps),_) = (compute_mib_implicits flags kn).(i) in imps
| ConstructRef ((kn,i),j) ->
- let (_,cimps) = (compute_mib_implicits flags manual kn).(i) in snd cimps.(j-1)
+ let (_,cimps) = (compute_mib_implicits flags kn).(i) in snd cimps.(j-1)
(* Merge a manual explicitation with an implicit_status list *)
@@ -573,34 +591,34 @@ let rebuild_implicits (req,l) =
| ImplLocal -> assert false
| ImplConstant (con,flags) ->
let oldimpls = snd (List.hd l) in
- let newimpls = compute_constant_implicits flags [] con in
+ let newimpls = compute_constant_implicits flags con in
req, [ConstRef con, List.map2 merge_impls oldimpls newimpls]
| ImplMutualInductive (kn,flags) ->
- let newimpls = compute_all_mib_implicits flags [] kn in
+ let newimpls = compute_all_mib_implicits flags kn in
let rec aux olds news =
- match olds, news with
- | (_, oldimpls) :: old, (gr, newimpls) :: tl ->
- (gr, List.map2 merge_impls oldimpls newimpls) :: aux old tl
- | [], [] -> []
- | _, _ -> assert false
+ match olds, news with
+ | (_, oldimpls) :: old, (gr, newimpls) :: tl ->
+ (gr, List.map2 merge_impls oldimpls newimpls) :: aux old tl
+ | [], [] -> []
+ | _, _ -> assert false
in req, aux l newimpls
| ImplInteractive (ref,flags,o) ->
(if isVarRef ref && is_in_section ref then ImplLocal else req),
match o with
| ImplAuto ->
- let oldimpls = snd (List.hd l) in
- let newimpls = compute_global_implicits flags [] ref in
- [ref,List.map2 merge_impls oldimpls newimpls]
+ let oldimpls = snd (List.hd l) in
+ let newimpls = compute_global_implicits flags ref in
+ [ref,List.map2 merge_impls oldimpls newimpls]
| ImplManual userimplsize ->
- let oldimpls = snd (List.hd l) in
- if flags.auto then
- let newimpls = List.hd (compute_global_implicits flags [] ref) in
- let p = List.length (snd newimpls) - userimplsize in
- let newimpls = on_snd (List.firstn p) newimpls in
- [ref,List.map (fun o -> merge_impls o newimpls) oldimpls]
- else
- [ref,oldimpls]
+ let oldimpls = snd (List.hd l) in
+ if flags.auto then
+ let newimpls = List.hd (compute_global_implicits flags ref) in
+ let p = List.length (snd newimpls) - userimplsize in
+ let newimpls = on_snd (List.firstn p) newimpls in
+ [ref,List.map (fun o -> merge_impls o newimpls) oldimpls]
+ else
+ [ref,oldimpls]
let classify_implicits (req,_ as obj) = match req with
| ImplLocal -> Dispose
@@ -622,7 +640,7 @@ let inImplicits : implicits_obj -> obj =
let is_local local ref = local || isVarRef ref && is_in_section ref
let declare_implicits_gen req flags ref =
- let imps = compute_global_implicits flags [] ref in
+ let imps = compute_global_implicits flags ref in
add_anonymous_leaf (inImplicits (req,[ref,imps]))
let declare_implicits local ref =
@@ -643,7 +661,7 @@ let declare_mib_implicits kn =
let flags = !implicit_args in
let imps = Array.map_to_list
(fun (ind,cstrs) -> ind::(Array.to_list cstrs))
- (compute_mib_implicits flags [] kn) in
+ (compute_mib_implicits flags kn) in
add_anonymous_leaf
(inImplicits (ImplMutualInductive (kn,flags),List.flatten imps))
@@ -653,8 +671,8 @@ type manual_explicitation = Constrexpr.explicitation * (bool * bool * bool)
type manual_implicits = manual_explicitation list
let compute_implicits_with_manual env sigma typ enriching l =
- let _,autoimpls = compute_auto_implicits env sigma !implicit_args enriching typ in
- set_manual_implicits env !implicit_args enriching autoimpls l
+ let autoimpls = compute_auto_implicits env sigma !implicit_args enriching typ in
+ set_manual_implicits !implicit_args enriching autoimpls l
let check_inclusion l =
(* Check strict inclusion *)
@@ -679,26 +697,26 @@ let declare_manual_implicits local ref ?enriching l =
let env = Global.env () in
let sigma = Evd.from_env env in
let t, _ = Global.type_of_global_in_context env ref in
+ let t = of_constr t in
let enriching = Option.default flags.auto enriching in
- let isrigid,autoimpls = compute_auto_implicits env sigma flags enriching (of_constr t) in
+ let autoimpls = compute_auto_implicits env sigma flags enriching t in
let l' = match l with
| [] -> assert false
| [l] ->
- [DefaultImpArgs, set_manual_implicits env flags enriching autoimpls l]
+ [DefaultImpArgs, set_manual_implicits flags enriching autoimpls l]
| _ ->
- check_rigidity isrigid;
- let l = List.map (fun imps -> (imps,List.length imps)) l in
- let l = List.sort (fun (_,n1) (_,n2) -> n2 - n1) l in
- check_inclusion l;
- let nargs = List.length autoimpls in
- List.map (fun (imps,n) ->
- (LessArgsThan (nargs-n),
- set_manual_implicits env flags enriching autoimpls imps)) l in
+ check_rigidity (is_rigid env sigma t);
+ let l = List.map (fun imps -> (imps,List.length imps)) l in
+ let l = List.sort (fun (_,n1) (_,n2) -> n2 - n1) l in
+ check_inclusion l;
+ let nargs = List.length autoimpls in
+ List.map (fun (imps,n) ->
+ (LessArgsThan (nargs-n),
+ set_manual_implicits flags enriching autoimpls imps)) l in
let req =
if is_local local ref then ImplLocal
else ImplInteractive(ref,flags,ImplManual (List.length autoimpls))
- in
- add_anonymous_leaf (inImplicits (req,[ref,l']))
+ in add_anonymous_leaf (inImplicits (req,[ref,l']))
let maybe_declare_manual_implicits local ref ?enriching l =
match l with
diff --git a/interp/implicit_quantifiers.ml b/interp/implicit_quantifiers.ml
index a1a3be70f..58df9abc4 100644
--- a/interp/implicit_quantifiers.ml
+++ b/interp/implicit_quantifiers.ml
@@ -245,6 +245,12 @@ let implicit_application env ?(allow_partial=true) f ty =
CAst.make ?loc @@ CAppExpl ((None, id, inst), args), avoid
in c, avoid
+let warn_ignoring_implicit_status =
+ CWarnings.create ~name:"ignoring_implicit_status" ~category:"implicits"
+ (fun na ->
+ strbrk "Ignoring implicit status of product binder " ++
+ Name.print na ++ strbrk " and following binders")
+
let implicits_of_glob_constr ?(with_products=true) l =
let add_impl i na bk l = match bk with
| Implicit ->
@@ -260,20 +266,18 @@ let implicits_of_glob_constr ?(with_products=true) l =
let abs na bk b =
add_impl i na bk (aux (succ i) b)
in
- match DAst.get c with
- | GProd (na, bk, t, b) ->
- if with_products then abs na bk b
- else
- let () = match bk with
- | Implicit ->
- Feedback.msg_warning (strbrk "Ignoring implicit status of product binder " ++
- Name.print na ++ strbrk " and following binders")
- | _ -> ()
- in []
- | GLambda (na, bk, t, b) -> abs na bk b
- | GLetIn (na, b, t, c) -> aux i b
- | GRec (fix_kind, nas, args, tys, bds) ->
- let nb = match fix_kind with |GFix (_, n) -> n | GCoFix n -> n in
- List.fold_left_i (fun i l (na,bk,_,_) -> add_impl i na bk l) i (aux (List.length args.(nb) + i) bds.(nb)) args.(nb)
- | _ -> []
+ match DAst.get c with
+ | GProd (na, bk, t, b) ->
+ if with_products then abs na bk b
+ else
+ let () = match bk with
+ | Implicit -> warn_ignoring_implicit_status na ?loc:c.CAst.loc
+ | _ -> ()
+ in []
+ | GLambda (na, bk, t, b) -> abs na bk b
+ | GLetIn (na, b, t, c) -> aux i b
+ | GRec (fix_kind, nas, args, tys, bds) ->
+ let nb = match fix_kind with |GFix (_, n) -> n | GCoFix n -> n in
+ List.fold_left_i (fun i l (na,bk,_,_) -> add_impl i na bk l) i (aux (List.length args.(nb) + i) bds.(nb)) args.(nb)
+ | _ -> []
in aux 1 l
diff --git a/intf/evar_kinds.ml b/intf/evar_kinds.ml
index c5de383b2..c964ecf1f 100644
--- a/intf/evar_kinds.ml
+++ b/intf/evar_kinds.ml
@@ -21,6 +21,8 @@ type obligation_definition_status = Define of bool | Expand
type matching_var_kind = FirstOrderPatVar of patvar | SecondOrderPatVar of patvar
+type subevar_kind = Domain | Codomain | Body
+
type t =
| ImplicitArg of global_reference * (int * Id.t option)
* bool (** Force inference *)
@@ -34,4 +36,4 @@ type t =
| ImpossibleCase
| MatchingVar of matching_var_kind
| VarInstance of Id.t
- | SubEvar of Evar.t
+ | SubEvar of subevar_kind option * Evar.t
diff --git a/intf/misctypes.ml b/intf/misctypes.ml
index 9eb6f62cc..72db3b31c 100644
--- a/intf/misctypes.ml
+++ b/intf/misctypes.ml
@@ -142,19 +142,6 @@ type multi =
| RepeatStar
| RepeatPlus
-type 'a core_destruction_arg =
- | ElimOnConstr of 'a
- | ElimOnIdent of lident
- | ElimOnAnonHyp of int
-
-type 'a destruction_arg =
- clear_flag * 'a core_destruction_arg
-
-type inversion_kind =
- | SimpleInversion
- | FullInversion
- | FullInversionClear
-
type ('a, 'b) gen_universe_decl = {
univdecl_instance : 'a; (* Declared universes *)
univdecl_extensible_instance : bool; (* Can new universes be added *)
diff --git a/intf/pattern.ml b/intf/pattern.ml
index af2347674..76367b612 100644
--- a/intf/pattern.ml
+++ b/intf/pattern.ml
@@ -10,7 +10,6 @@
open Names
open Globnames
-open Constr
open Misctypes
(** {5 Patterns} *)
@@ -37,8 +36,8 @@ type constr_pattern =
| PIf of constr_pattern * constr_pattern * constr_pattern
| PCase of case_info_pattern * constr_pattern * constr_pattern *
(int * bool list * constr_pattern) list (** index of constructor, nb of args *)
- | PFix of fixpoint
- | PCoFix of cofixpoint
+ | PFix of (int array * int) * (Name.t array * constr_pattern array * constr_pattern array)
+ | PCoFix of int * (Name.t array * constr_pattern array * constr_pattern array)
(** Nota : in a [PCase], the array of branches might be shorter than
expected, denoting the use of a final "_ => _" branch *)
diff --git a/intf/vernacexpr.ml b/intf/vernacexpr.ml
index dc1110ad8..06f969f19 100644
--- a/intf/vernacexpr.ml
+++ b/intf/vernacexpr.ml
@@ -297,13 +297,9 @@ type inline =
type module_ast_inl = module_ast * inline
type module_binder = bool option * lident list * module_ast_inl
-(** Cumulativity can be set globally, locally or unset locally and it
- can not enabled at all. *)
-type cumulative_inductive_parsing_flag =
- | GlobalCumulativity
- | GlobalNonCumulativity
- | LocalCumulativity
- | LocalNonCumulativity
+(** [Some b] if locally enabled/disabled according to [b], [None] if
+ we should use the global flag. *)
+type vernac_cumulative = VernacCumulative | VernacNonCumulative
(** {6 The type of vernacular expressions} *)
@@ -338,7 +334,7 @@ type nonrec vernac_expr =
| VernacExactProof of constr_expr
| VernacAssumption of (Decl_kinds.discharge * Decl_kinds.assumption_object_kind) *
inline * (ident_decl list * constr_expr) with_coercion list
- | VernacInductive of cumulative_inductive_parsing_flag * Decl_kinds.private_flag * inductive_flag * (inductive_expr * decl_notation list) list
+ | VernacInductive of vernac_cumulative option * Decl_kinds.private_flag * inductive_flag * (inductive_expr * decl_notation list) list
| VernacFixpoint of Decl_kinds.discharge * (fixpoint_expr * decl_notation list) list
| VernacCoFixpoint of Decl_kinds.discharge * (cofixpoint_expr * decl_notation list) list
| VernacScheme of (lident option * scheme) list
@@ -409,8 +405,6 @@ type nonrec vernac_expr =
| VernacHints of string list * hints_expr
| VernacSyntacticDefinition of lident * (Id.t list * constr_expr) *
onlyparsing_flag
- | VernacDeclareImplicits of reference or_by_notation *
- (explicitation * bool * bool) list list
| VernacArguments of reference or_by_notation *
vernac_argument_status list (* Main arguments status list *) *
(Name.t * vernac_implicit_status) list list (* Extra implicit status lists *) *
@@ -418,8 +412,6 @@ type nonrec vernac_expr =
[ `ReductionDontExposeCase | `ReductionNeverUnfold | `Rename |
`ExtraScopes | `Assert | `ClearImplicits | `ClearScopes |
`DefaultImplicits ] list
- | VernacArgumentsScope of reference or_by_notation *
- scope_name option list
| VernacReserve of simple_binder list
| VernacGeneralizable of (lident list) option
| VernacSetOpacity of (Conv_oracle.level * reference or_by_notation list)
@@ -446,7 +438,6 @@ type nonrec vernac_expr =
| VernacRestart
| VernacUndo of int
| VernacUndoTo of int
- | VernacBacktrack of int*int*int
| VernacFocus of int option
| VernacUnfocus
| VernacUnfocused
@@ -506,14 +497,13 @@ type vernac_type =
| VtProofMode of string
(* Queries are commands assumed to be "pure", that is to say, they
don't modify the interpretation state. *)
- | VtQuery of vernac_part_of_script * Feedback.route_id
+ | VtQuery
(* To be removed *)
| VtMeta
| VtUnknown
and vernac_qed_type = VtKeep | VtKeepAsAxiom | VtDrop (* Qed/Admitted, Abort *)
and vernac_start = string * opacity_guarantee * Id.t list
and vernac_sideff_type = Id.t list
-and vernac_part_of_script = bool
and opacity_guarantee =
| GuaranteesOpacity (** Only generates opaque terms at [Qed] *)
| Doesn'tGuaranteeOpacity (** May generate transparent terms even with [Qed].*)
diff --git a/parsing/g_vernac.ml4 b/parsing/g_vernac.ml4
index 8543d2b84..593dcbf58 100644
--- a/parsing/g_vernac.ml4
+++ b/parsing/g_vernac.ml4
@@ -161,20 +161,10 @@ GEXTEND Gram
| IDENT "Let"; id = identref; b = def_body ->
VernacDefinition ((DoDischarge, Let), (lname_of_lident id, None), b)
(* Gallina inductive declarations *)
- | cum = cumulativity_token; priv = private_token; f = finite_token;
+ | cum = OPT cumulativity_token; priv = private_token; f = finite_token;
indl = LIST1 inductive_definition SEP "with" ->
let (k,f) = f in
let indl=List.map (fun ((a,b,c,d),e) -> ((a,b,c,k,d),e)) indl in
- let cum =
- match cum with
- Some true -> LocalCumulativity
- | Some false -> LocalNonCumulativity
- | None ->
- if Flags.is_polymorphic_inductive_cumulativity () then
- GlobalCumulativity
- else
- GlobalNonCumulativity
- in
VernacInductive (cum, priv,f,indl)
| "Fixpoint"; recs = LIST1 rec_definition SEP "with" ->
VernacFixpoint (NoDischarge, recs)
@@ -257,7 +247,8 @@ GEXTEND Gram
| IDENT "Class" -> (Class true,BiFinite) ] ]
;
cumulativity_token:
- [ [ IDENT "Cumulative" -> Some true | IDENT "NonCumulative" -> Some false | -> None ] ]
+ [ [ IDENT "Cumulative" -> VernacCumulative
+ | IDENT "NonCumulative" -> VernacNonCumulative ] ]
;
private_token:
[ [ IDENT "Private" -> true | -> false ] ]
@@ -601,14 +592,6 @@ GEXTEND Gram
;
END
-let warn_deprecated_arguments_scope =
- CWarnings.create ~name:"deprecated-arguments-scope" ~category:"deprecated"
- (fun () -> strbrk "Arguments Scope is deprecated; use Arguments instead")
-
-let warn_deprecated_implicit_arguments =
- CWarnings.create ~name:"deprecated-implicit-arguments" ~category:"deprecated"
- (fun () -> strbrk "Implicit Arguments is deprecated; use Arguments instead")
-
(* Extensions: implicits, coercions, etc. *)
GEXTEND Gram
GLOBAL: gallina_ext instance_name hint_info;
@@ -691,20 +674,6 @@ GEXTEND Gram
let more_implicits = Option.default [] more_implicits in
VernacArguments (qid, args, more_implicits, !slash_position, mods)
-
- (* moved there so that camlp5 factors it with the previous rule *)
- | IDENT "Arguments"; IDENT "Scope"; qid = smart_global;
- "["; scl = LIST0 [ "_" -> None | sc = IDENT -> Some sc ]; "]" ->
- warn_deprecated_arguments_scope ~loc:!@loc ();
- VernacArgumentsScope (qid,scl)
-
- (* Implicit *)
- | IDENT "Implicit"; IDENT "Arguments"; qid = smart_global;
- pos = LIST0 [ "["; l = LIST0 implicit_name; "]" ->
- List.map (fun (id,b,f) -> (ExplByName id,b,f)) l ] ->
- warn_deprecated_implicit_arguments ~loc:!@loc ();
- VernacDeclareImplicits (qid,pos)
-
| IDENT "Implicit"; "Type"; bl = reserv_list ->
VernacReserve bl
@@ -734,12 +703,6 @@ GEXTEND Gram
[`ClearImplicits; `ClearScopes]
] ]
;
- implicit_name:
- [ [ "!"; id = ident -> (id, false, true)
- | id = ident -> (id,false,false)
- | "["; "!"; id = ident; "]" -> (id,true,true)
- | "["; id = ident; "]" -> (id,true, false) ] ]
- ;
scope:
[ [ "%"; key = IDENT -> key ] ]
;
@@ -1065,8 +1028,6 @@ GEXTEND Gram
| IDENT "Back" -> VernacBack 1
| IDENT "Back"; n = natural -> VernacBack n
| IDENT "BackTo"; n = natural -> VernacBackTo n
- | IDENT "Backtrack"; n = natural ; m = natural ; p = natural ->
- VernacBacktrack (n,m,p)
(* Tactic Debugger *)
| IDENT "Debug"; IDENT "On" ->
diff --git a/plugins/funind/glob_term_to_relation.ml b/plugins/funind/glob_term_to_relation.ml
index 49f7aae43..319b410df 100644
--- a/plugins/funind/glob_term_to_relation.ml
+++ b/plugins/funind/glob_term_to_relation.ml
@@ -1512,7 +1512,7 @@ let do_build_inductive
in
let msg =
str "while trying to define"++ spc () ++
- Ppvernac.pr_vernac Vernacexpr.(VernacExpr([], VernacInductive(GlobalNonCumulativity,false,Declarations.Finite,repacked_rel_inds)))
+ Ppvernac.pr_vernac Vernacexpr.(VernacExpr([], VernacInductive(None,false,Declarations.Finite,repacked_rel_inds)))
++ fnl () ++
msg
in
@@ -1527,7 +1527,7 @@ let do_build_inductive
in
let msg =
str "while trying to define"++ spc () ++
- Ppvernac.pr_vernac Vernacexpr.(VernacExpr([], VernacInductive(GlobalNonCumulativity,false,Declarations.Finite,repacked_rel_inds)))
+ Ppvernac.pr_vernac Vernacexpr.(VernacExpr([], VernacInductive(None,false,Declarations.Finite,repacked_rel_inds)))
++ fnl () ++
CErrors.print reraise
in
diff --git a/plugins/funind/invfun.ml b/plugins/funind/invfun.ml
index 2743a8a2f..ae84eaa93 100644
--- a/plugins/funind/invfun.ml
+++ b/plugins/funind/invfun.ml
@@ -969,7 +969,7 @@ let functional_inversion kn hid fconst f_correct : Tacmach.tactic =
Proofview.V82.of_tactic (generalize [applist(f_correct,(Array.to_list f_args)@[res;mkVar hid])]);
thin [hid];
Proofview.V82.of_tactic (Simple.intro hid);
- Proofview.V82.of_tactic (Inv.inv FullInversion None (NamedHyp hid));
+ Proofview.V82.of_tactic (Inv.inv Inv.FullInversion None (NamedHyp hid));
(fun g ->
let new_ids = List.filter (fun id -> not (Id.Set.mem id old_ids)) (pf_ids_of_hyps g) in
tclMAP (revert_graph kn pre_tac) (hid::new_ids) g
diff --git a/plugins/ltac/pltac.mli b/plugins/ltac/pltac.mli
index 6637de745..434feba95 100644
--- a/plugins/ltac/pltac.mli
+++ b/plugins/ltac/pltac.mli
@@ -25,7 +25,7 @@ val constr_may_eval : (constr_expr,reference or_by_notation,constr_expr) may_eva
val constr_eval : (constr_expr,reference or_by_notation,constr_expr) may_eval Gram.entry
val uconstr : constr_expr Gram.entry
val quantified_hypothesis : quantified_hypothesis Gram.entry
-val destruction_arg : constr_expr with_bindings destruction_arg Gram.entry
+val destruction_arg : constr_expr with_bindings Tactics.destruction_arg Gram.entry
val int_or_var : int or_var Gram.entry
val simple_tactic : raw_tactic_expr Gram.entry
val simple_intropattern : constr_expr intro_pattern_expr CAst.t Gram.entry
diff --git a/plugins/ltac/pptactic.mli b/plugins/ltac/pptactic.mli
index 5951f2b11..aea00c240 100644
--- a/plugins/ltac/pptactic.mli
+++ b/plugins/ltac/pptactic.mli
@@ -84,7 +84,7 @@ type pp_tactic = {
pptac_prods : grammar_terminals;
}
-val pr_goal_selector : toplevel:bool -> goal_selector -> Pp.t
+val pr_goal_selector : toplevel:bool -> Vernacexpr.goal_selector -> Pp.t
val declare_notation_tactic_pprule : KerName.t -> pp_tactic -> unit
diff --git a/plugins/ltac/tacarg.mli b/plugins/ltac/tacarg.mli
index 5347eda7d..59473a5e5 100644
--- a/plugins/ltac/tacarg.mli
+++ b/plugins/ltac/tacarg.mli
@@ -23,7 +23,7 @@ val wit_tactic : (raw_tactic_expr, glob_tactic_expr, Geninterp.Val.t) genarg_typ
val wit_ltac : (raw_tactic_expr, glob_tactic_expr, unit) genarg_type
val wit_destruction_arg :
- (constr_expr with_bindings Tacexpr.destruction_arg,
- glob_constr_and_expr with_bindings Tacexpr.destruction_arg,
- delayed_open_constr_with_bindings Tacexpr.destruction_arg) genarg_type
+ (constr_expr with_bindings Tactics.destruction_arg,
+ glob_constr_and_expr with_bindings Tactics.destruction_arg,
+ delayed_open_constr_with_bindings Tactics.destruction_arg) genarg_type
diff --git a/plugins/ltac/tacexpr.ml b/plugins/ltac/tacexpr.ml
index 8b0c44041..3baa475ab 100644
--- a/plugins/ltac/tacexpr.ml
+++ b/plugins/ltac/tacexpr.ml
@@ -40,25 +40,29 @@ type goal_selector = Vernacexpr.goal_selector =
| SelectList of (int * int) list
| SelectId of Id.t
| SelectAll
+[@@ocaml.deprecated "Use Vernacexpr.goal_selector"]
-type 'a core_destruction_arg = 'a Misctypes.core_destruction_arg =
+type 'a core_destruction_arg = 'a Tactics.core_destruction_arg =
| ElimOnConstr of 'a
| ElimOnIdent of lident
| ElimOnAnonHyp of int
+[@@ocaml.deprecated "Use Tactics.core_destruction_arg"]
type 'a destruction_arg =
- clear_flag * 'a core_destruction_arg
+ clear_flag * 'a Tactics.core_destruction_arg
+[@@ocaml.deprecated "Use Tactics.destruction_arg"]
-type inversion_kind = Misctypes.inversion_kind =
+type inversion_kind = Inv.inversion_kind =
| SimpleInversion
| FullInversion
| FullInversionClear
+[@@ocaml.deprecated "Use Tactics.inversion_kind"]
type ('c,'d,'id) inversion_strength =
| NonDepInversion of
- inversion_kind * 'id list * 'd or_and_intro_pattern_expr CAst.t or_var option
+ Inv.inversion_kind * 'id list * 'd or_and_intro_pattern_expr CAst.t or_var option
| DepInversion of
- inversion_kind * 'c option * 'd or_and_intro_pattern_expr CAst.t or_var option
+ Inv.inversion_kind * 'c option * 'd or_and_intro_pattern_expr CAst.t or_var option
| InversionUsing of 'c * 'id list
type ('a,'b) location = HypLocation of 'a | ConclLocation of 'b
@@ -69,7 +73,7 @@ type 'id message_token =
| MsgIdent of 'id
type ('dconstr,'id) induction_clause =
- 'dconstr with_bindings destruction_arg *
+ 'dconstr with_bindings Tactics.destruction_arg *
(intro_pattern_naming_expr CAst.t option (* eqn:... *)
* 'dconstr or_and_intro_pattern_expr CAst.t or_var option) (* as ... *)
* 'id clause_expr option (* in ... *)
@@ -265,7 +269,7 @@ and 'a gen_tactic_expr =
('p,'a gen_tactic_expr) match_rule list
| TacFun of 'a gen_tactic_fun_ast
| TacArg of 'a gen_tactic_arg located
- | TacSelect of goal_selector * 'a gen_tactic_expr
+ | TacSelect of Vernacexpr.goal_selector * 'a gen_tactic_expr
(* For ML extensions *)
| TacML of (ml_tactic_entry * 'a gen_tactic_arg list) Loc.located
(* For syntax extensions *)
diff --git a/plugins/ltac/tacexpr.mli b/plugins/ltac/tacexpr.mli
index 8b0c44041..3baa475ab 100644
--- a/plugins/ltac/tacexpr.mli
+++ b/plugins/ltac/tacexpr.mli
@@ -40,25 +40,29 @@ type goal_selector = Vernacexpr.goal_selector =
| SelectList of (int * int) list
| SelectId of Id.t
| SelectAll
+[@@ocaml.deprecated "Use Vernacexpr.goal_selector"]
-type 'a core_destruction_arg = 'a Misctypes.core_destruction_arg =
+type 'a core_destruction_arg = 'a Tactics.core_destruction_arg =
| ElimOnConstr of 'a
| ElimOnIdent of lident
| ElimOnAnonHyp of int
+[@@ocaml.deprecated "Use Tactics.core_destruction_arg"]
type 'a destruction_arg =
- clear_flag * 'a core_destruction_arg
+ clear_flag * 'a Tactics.core_destruction_arg
+[@@ocaml.deprecated "Use Tactics.destruction_arg"]
-type inversion_kind = Misctypes.inversion_kind =
+type inversion_kind = Inv.inversion_kind =
| SimpleInversion
| FullInversion
| FullInversionClear
+[@@ocaml.deprecated "Use Tactics.inversion_kind"]
type ('c,'d,'id) inversion_strength =
| NonDepInversion of
- inversion_kind * 'id list * 'd or_and_intro_pattern_expr CAst.t or_var option
+ Inv.inversion_kind * 'id list * 'd or_and_intro_pattern_expr CAst.t or_var option
| DepInversion of
- inversion_kind * 'c option * 'd or_and_intro_pattern_expr CAst.t or_var option
+ Inv.inversion_kind * 'c option * 'd or_and_intro_pattern_expr CAst.t or_var option
| InversionUsing of 'c * 'id list
type ('a,'b) location = HypLocation of 'a | ConclLocation of 'b
@@ -69,7 +73,7 @@ type 'id message_token =
| MsgIdent of 'id
type ('dconstr,'id) induction_clause =
- 'dconstr with_bindings destruction_arg *
+ 'dconstr with_bindings Tactics.destruction_arg *
(intro_pattern_naming_expr CAst.t option (* eqn:... *)
* 'dconstr or_and_intro_pattern_expr CAst.t or_var option) (* as ... *)
* 'id clause_expr option (* in ... *)
@@ -265,7 +269,7 @@ and 'a gen_tactic_expr =
('p,'a gen_tactic_expr) match_rule list
| TacFun of 'a gen_tactic_fun_ast
| TacArg of 'a gen_tactic_arg located
- | TacSelect of goal_selector * 'a gen_tactic_expr
+ | TacSelect of Vernacexpr.goal_selector * 'a gen_tactic_expr
(* For ML extensions *)
| TacML of (ml_tactic_entry * 'a gen_tactic_arg list) Loc.located
(* For syntax extensions *)
diff --git a/plugins/ltac/tactic_debug.ml b/plugins/ltac/tactic_debug.ml
index e55b49fb4..57a11d947 100644
--- a/plugins/ltac/tactic_debug.ml
+++ b/plugins/ltac/tactic_debug.ml
@@ -391,13 +391,10 @@ let explain_ltac_call_trace last trace loc =
let skip_extensions trace =
let rec aux = function
- | (_,Tacexpr.LtacNameCall f as tac) :: _
- when Tacenv.is_ltac_for_ml_tactic f -> [tac]
- | (_,Tacexpr.LtacNotationCall _ as tac) :: (_,Tacexpr.LtacMLCall _) :: _ ->
+ | (_,Tacexpr.LtacNotationCall _ as tac) :: (_,Tacexpr.LtacMLCall _) :: tail ->
(* Case of an ML defined tactic with entry of the form <<"foo" args>> *)
(* see tacextend.mlp *)
- [tac]
- | (_,Tacexpr.LtacMLCall _ as tac) :: _ -> [tac]
+ tac :: aux tail
| t :: tail -> t :: aux tail
| [] -> [] in
List.rev (aux (List.rev trace))
diff --git a/plugins/micromega/Tauto.v b/plugins/micromega/Tauto.v
index 31f55ae9c..458844e1b 100644
--- a/plugins/micromega/Tauto.v
+++ b/plugins/micromega/Tauto.v
@@ -211,7 +211,7 @@ Set Implicit Arguments.
(* BC *)
simpl.
case_eq (deduce t t) ; auto.
- intros until 0.
+ intros *.
case_eq (unsat t0) ; auto.
unfold eval_clause.
rewrite make_conj_cons.
@@ -263,7 +263,7 @@ Set Implicit Arguments.
Proof.
induction cl.
simpl. tauto.
- intros until 0.
+ intros *.
simpl.
assert (HH := add_term_correct env a cl').
case_eq (add_term a cl').
diff --git a/plugins/ssr/ssripats.ml b/plugins/ssr/ssripats.ml
index 42566575c..7897cb170 100644
--- a/plugins/ssr/ssripats.ml
+++ b/plugins/ssr/ssripats.ml
@@ -133,6 +133,12 @@ let intro_clear ids future_ipats =
isCLR_PUSHL clear_ids
end
+let tacCHECK_HYPS_EXIST hyps = Goal.enter begin fun gl ->
+ let ctx = Goal.hyps gl in
+ List.iter (Ssrcommon.check_hyp_exists ctx) hyps;
+ tclUNIT ()
+end
+
(** [=> []] *****************************************************************)
let tac_case t =
Goal.enter begin fun _ ->
@@ -229,7 +235,9 @@ let rec ipat_tac1 future_ipats ipat : unit tactic =
| IPatNoop -> tclUNIT ()
| IPatSimpl Nop -> tclUNIT ()
- | IPatClear ids -> intro_clear (List.map Ssrcommon.hyp_id ids) future_ipats
+ | IPatClear ids ->
+ tacCHECK_HYPS_EXIST ids <*>
+ intro_clear (List.map Ssrcommon.hyp_id ids) future_ipats
| IPatSimpl (Simpl n) ->
V82.tactic ~nf_evars:false (Ssrequality.simpltac (Simpl n))
diff --git a/plugins/ssr/ssrparser.ml4 b/plugins/ssr/ssrparser.ml4
index 0d82a9f09..5f3967440 100644
--- a/plugins/ssr/ssrparser.ml4
+++ b/plugins/ssr/ssrparser.ml4
@@ -585,21 +585,10 @@ let pr_ssripat _ _ _ = pr_ipat
let pr_ssripats _ _ _ = pr_ipats
let pr_ssriorpat _ _ _ = pr_iorpat
-(*
-let intern_ipat ist ipat =
- let rec check_pat = function
- | IPatClear clr -> ignore (List.map (intern_hyp ist) clr)
- | IPatCase iorpat -> List.iter (List.iter check_pat) iorpat
- | IPatDispatch iorpat -> List.iter (List.iter check_pat) iorpat
- | IPatInj iorpat -> List.iter (List.iter check_pat) iorpat
- | _ -> () in
- check_pat ipat; ipat
-*)
-
let intern_ipat ist =
map_ipat
(fun id -> id)
- (intern_hyp ist) (* TODO: check with ltac, old code was ignoring the result *)
+ (intern_hyp ist)
(glob_ast_closure_term ist)
let intern_ipats ist = List.map (intern_ipat ist)
diff --git a/pretyping/cases.ml b/pretyping/cases.ml
index a5b7a9e6f..73be9d6b7 100644
--- a/pretyping/cases.ml
+++ b/pretyping/cases.ml
@@ -1662,7 +1662,7 @@ let rec list_assoc_in_triple x = function
let abstract_tycon ?loc env evdref subst tycon extenv t =
let t = nf_betaiota env !evdref t in (* it helps in some cases to remove K-redex*)
let src = match EConstr.kind !evdref t with
- | Evar (evk,_) -> (Loc.tag ?loc @@ Evar_kinds.SubEvar evk)
+ | Evar (evk,_) -> (Loc.tag ?loc @@ Evar_kinds.SubEvar (None,evk))
| _ -> (Loc.tag ?loc @@ Evar_kinds.CasesType true) in
let subst0,t0 = adjust_to_extended_env_and_remove_deps env extenv !evdref subst t in
(* We traverse the type T of the original problem Xi looking for subterms
diff --git a/pretyping/constr_matching.ml b/pretyping/constr_matching.ml
index 888c76e3d..89d490a41 100644
--- a/pretyping/constr_matching.ml
+++ b/pretyping/constr_matching.ml
@@ -183,9 +183,36 @@ let push_binder na1 na2 t ctx =
Namegen.next_ident_away Namegen.default_non_dependent_ident avoid in
(na1, id2, t) :: ctx
-let to_fix (idx, (nas, cs, ts)) =
- let inj = EConstr.of_constr in
- (idx, (nas, Array.map inj cs, Array.map inj ts))
+(* This is an optimization of the main pattern-matching which shares
+ the longest common prefix of the body and type of a fixpoint. The
+ only practical effect at the time of writing is in binding variable
+ names: these variable names must be bound only once since the user
+ view at a fix displays only a (maximal) shared common prefix *)
+
+let rec match_under_common_fix_binders sorec sigma binding_vars ctx ctx' env env' subst t1 t2 b1 b2 =
+ match t1, EConstr.kind sigma t2, b1, EConstr.kind sigma b2 with
+ | PProd(na1,c1,t1'), Prod(na2,c2,t2'), PLambda (_,c1',b1'), Lambda (na2',c2',b2') ->
+ let ctx = push_binder na1 na2 c2 ctx in
+ let ctx' = push_binder na1 na2' c2' ctx' in
+ let env = EConstr.push_rel (LocalAssum (na2,c2)) env in
+ let subst = sorec ctx env subst c1 c2 in
+ let subst = sorec ctx env subst c1' c2' in
+ let subst = add_binders na1 na2 binding_vars subst in
+ match_under_common_fix_binders sorec sigma binding_vars
+ ctx ctx' env env' subst t1' t2' b1' b2'
+ | PLetIn(na1,c1,u1,t1), LetIn(na2,c2,u2,t2), PLetIn(_,c1',u1',b1), LetIn(na2',c2',u2',b2) ->
+ let ctx = push_binder na1 na2 u2 ctx in
+ let ctx' = push_binder na1 na2' u2' ctx' in
+ let env = EConstr.push_rel (LocalDef (na2,c2,t2)) env in
+ let subst = sorec ctx env subst c1 c2 in
+ let subst = sorec ctx env subst c1' c2' in
+ let subst = Option.fold_left (fun subst u1 -> sorec ctx env subst u1 u2) subst u1 in
+ let subst = Option.fold_left (fun subst u1' -> sorec ctx env subst u1' u2') subst u1' in
+ let subst = add_binders na1 na2 binding_vars subst in
+ match_under_common_fix_binders sorec sigma binding_vars
+ ctx ctx' env env' subst t1 t2 b1 b2
+ | _ ->
+ sorec ctx' env' (sorec ctx env subst t1 t2) b1 b2
let merge_binding sigma allow_bound_rels ctx n cT subst =
let c = match ctx with
@@ -364,8 +391,20 @@ let matches_core env sigma allow_bound_rels
let chk_head = sorec ctx env (sorec ctx env subst a1 a2) p1 p2 in
List.fold_left chk_branch chk_head br1
- | PFix c1, Fix _ when eq_constr sigma (mkFix (to_fix c1)) cT -> subst
- | PCoFix c1, CoFix _ when eq_constr sigma (mkCoFix (to_fix c1)) cT -> subst
+ | PFix ((ln1,i1),(lna1,tl1,bl1)), Fix ((ln2,i2),(lna2,tl2,bl2))
+ when Array.equal Int.equal ln1 ln2 && i1 = i2 ->
+ let ctx' = Array.fold_left3 (fun ctx na1 na2 t2 -> push_binder na1 na2 t2 ctx) ctx lna1 lna2 tl2 in
+ let env' = Array.fold_left2 (fun env na2 c2 -> EConstr.push_rel (LocalAssum (na2,c2)) env) env lna2 tl2 in
+ let subst = Array.fold_left4 (match_under_common_fix_binders sorec sigma binding_vars ctx ctx' env env') subst tl1 tl2 bl1 bl2 in
+ Array.fold_left2 (fun subst na1 na2 -> add_binders na1 na2 binding_vars subst) subst lna1 lna2
+
+ | PCoFix (i1,(lna1,tl1,bl1)), CoFix (i2,(lna2,tl2,bl2))
+ when i1 = i2 ->
+ let ctx' = Array.fold_left3 (fun ctx na1 na2 t2 -> push_binder na1 na2 t2 ctx) ctx lna1 lna2 tl2 in
+ let env' = Array.fold_left2 (fun env na2 c2 -> EConstr.push_rel (LocalAssum (na2,c2)) env) env lna2 tl2 in
+ let subst = Array.fold_left4 (match_under_common_fix_binders sorec sigma binding_vars ctx ctx' env env') subst tl1 tl2 bl1 bl2 in
+ Array.fold_left2 (fun subst na1 na2 -> add_binders na1 na2 binding_vars subst) subst lna1 lna2
+
| PEvar (c1,args1), Evar (c2,args2) when Evar.equal c1 c2 ->
Array.fold_left2 (sorec ctx env) subst args1 args2
| (PRef _ | PVar _ | PRel _ | PApp _ | PProj _ | PLambda _
diff --git a/pretyping/detyping.ml b/pretyping/detyping.ml
index 587892141..bb563220b 100644
--- a/pretyping/detyping.ml
+++ b/pretyping/detyping.ml
@@ -501,6 +501,97 @@ let detype_case computable detype detype_eqns testdep avoid data p c bl =
let eqnl = detype_eqns constructs constagsl bl in
GCases (tag,pred,[tomatch,(alias,aliastyp)],eqnl)
+let rec share_names detype n l avoid env sigma c t =
+ match EConstr.kind sigma c, EConstr.kind sigma t with
+ (* factorize even when not necessary to have better presentation *)
+ | Lambda (na,t,c), Prod (na',t',c') ->
+ let na = match (na,na') with
+ Name _, _ -> na
+ | _, Name _ -> na'
+ | _ -> na in
+ let t' = detype avoid env sigma t in
+ let id = next_name_away na avoid in
+ let avoid = Id.Set.add id avoid and env = add_name (Name id) None t env in
+ share_names detype (n-1) ((Name id,Explicit,None,t')::l) avoid env sigma c c'
+ (* May occur for fix built interactively *)
+ | LetIn (na,b,t',c), _ when n > 0 ->
+ let t'' = detype avoid env sigma t' in
+ let b' = detype avoid env sigma b in
+ let id = next_name_away na avoid in
+ let avoid = Id.Set. add id avoid and env = add_name (Name id) (Some b) t' env in
+ share_names detype n ((Name id,Explicit,Some b',t'')::l) avoid env sigma c (lift 1 t)
+ (* Only if built with the f/n notation or w/o let-expansion in types *)
+ | _, LetIn (_,b,_,t) when n > 0 ->
+ share_names detype n l avoid env sigma c (subst1 b t)
+ (* If it is an open proof: we cheat and eta-expand *)
+ | _, Prod (na',t',c') when n > 0 ->
+ let t'' = detype avoid env sigma t' in
+ let id = next_name_away na' avoid in
+ let avoid = Id.Set.add id avoid and env = add_name (Name id) None t' env in
+ let appc = mkApp (lift 1 c,[|mkRel 1|]) in
+ share_names detype (n-1) ((Name id,Explicit,None,t'')::l) avoid env sigma appc c'
+ (* If built with the f/n notation: we renounce to share names *)
+ | _ ->
+ if n>0 then Feedback.msg_debug (strbrk "Detyping.detype: cannot factorize fix enough");
+ let c = detype avoid env sigma c in
+ let t = detype avoid env sigma t in
+ (List.rev l,c,t)
+
+let rec share_pattern_names detype n l avoid env sigma c t =
+ let open Pattern in
+ if n = 0 then
+ let c = detype avoid env sigma c in
+ let t = detype avoid env sigma t in
+ (List.rev l,c,t)
+ else match c, t with
+ | PLambda (na,t,c), PProd (na',t',c') ->
+ let na = match (na,na') with
+ Name _, _ -> na
+ | _, Name _ -> na'
+ | _ -> na in
+ let t' = detype avoid env sigma t in
+ let id = next_name_away na avoid in
+ let avoid = Id.Set.add id avoid in
+ let env = Name id :: env in
+ share_pattern_names detype (n-1) ((Name id,Explicit,None,t')::l) avoid env sigma c c'
+ | _ ->
+ if n>0 then Feedback.msg_debug (strbrk "Detyping.detype: cannot factorize fix enough");
+ let c = detype avoid env sigma c in
+ let t = detype avoid env sigma t in
+ (List.rev l,c,t)
+
+let detype_fix detype avoid env sigma (vn,_ as nvn) (names,tys,bodies) =
+ let def_avoid, def_env, lfi =
+ Array.fold_left2
+ (fun (avoid, env, l) na ty ->
+ let id = next_name_away na avoid in
+ (Id.Set.add id avoid, add_name (Name id) None ty env, id::l))
+ (avoid, env, []) names tys in
+ let n = Array.length tys in
+ let v = Array.map3
+ (fun c t i -> share_names detype (i+1) [] def_avoid def_env sigma c (lift n t))
+ bodies tys vn in
+ GRec(GFix (Array.map (fun i -> Some i, GStructRec) (fst nvn), snd nvn),Array.of_list (List.rev lfi),
+ Array.map (fun (bl,_,_) -> bl) v,
+ Array.map (fun (_,_,ty) -> ty) v,
+ Array.map (fun (_,bd,_) -> bd) v)
+
+let detype_cofix detype avoid env sigma n (names,tys,bodies) =
+ let def_avoid, def_env, lfi =
+ Array.fold_left2
+ (fun (avoid, env, l) na ty ->
+ let id = next_name_away na avoid in
+ (Id.Set.add id avoid, add_name (Name id) None ty env, id::l))
+ (avoid, env, []) names tys in
+ let ntys = Array.length tys in
+ let v = Array.map2
+ (fun c t -> share_names detype 0 [] def_avoid def_env sigma c (lift ntys t))
+ bodies tys in
+ GRec(GCoFix n,Array.of_list (List.rev lfi),
+ Array.map (fun (bl,_,_) -> bl) v,
+ Array.map (fun (_,_,ty) -> ty) v,
+ Array.map (fun (_,bd,_) -> bd) v)
+
let detype_universe sigma u =
let fn (l, n) = Some (Termops.reference_of_level sigma l, n) in
Univ.Universe.map fn u
@@ -655,76 +746,8 @@ and detype_r d flags avoid env sigma t =
(ci.ci_ind,ci.ci_pp_info.style,
ci.ci_pp_info.cstr_tags,ci.ci_pp_info.ind_tags)
p c bl
- | Fix (nvn,recdef) -> detype_fix d flags avoid env sigma nvn recdef
- | CoFix (n,recdef) -> detype_cofix d flags avoid env sigma n recdef
-
-and detype_fix d flags avoid env sigma (vn,_ as nvn) (names,tys,bodies) =
- let def_avoid, def_env, lfi =
- Array.fold_left2
- (fun (avoid, env, l) na ty ->
- let id = next_name_away na avoid in
- (Id.Set.add id avoid, add_name (Name id) None ty env, id::l))
- (avoid, env, []) names tys in
- let n = Array.length tys in
- let v = Array.map3
- (fun c t i -> share_names d flags (i+1) [] def_avoid def_env sigma c (lift n t))
- bodies tys vn in
- GRec(GFix (Array.map (fun i -> Some i, GStructRec) (fst nvn), snd nvn),Array.of_list (List.rev lfi),
- Array.map (fun (bl,_,_) -> bl) v,
- Array.map (fun (_,_,ty) -> ty) v,
- Array.map (fun (_,bd,_) -> bd) v)
-
-and detype_cofix d flags avoid env sigma n (names,tys,bodies) =
- let def_avoid, def_env, lfi =
- Array.fold_left2
- (fun (avoid, env, l) na ty ->
- let id = next_name_away na avoid in
- (Id.Set.add id avoid, add_name (Name id) None ty env, id::l))
- (avoid, env, []) names tys in
- let ntys = Array.length tys in
- let v = Array.map2
- (fun c t -> share_names d flags 0 [] def_avoid def_env sigma c (lift ntys t))
- bodies tys in
- GRec(GCoFix n,Array.of_list (List.rev lfi),
- Array.map (fun (bl,_,_) -> bl) v,
- Array.map (fun (_,_,ty) -> ty) v,
- Array.map (fun (_,bd,_) -> bd) v)
-
-and share_names d flags n l avoid env sigma c t =
- match EConstr.kind sigma c, EConstr.kind sigma t with
- (* factorize even when not necessary to have better presentation *)
- | Lambda (na,t,c), Prod (na',t',c') ->
- let na = match (na,na') with
- Name _, _ -> na
- | _, Name _ -> na'
- | _ -> na in
- let t' = detype d flags avoid env sigma t in
- let id = next_name_away na avoid in
- let avoid = Id.Set.add id avoid and env = add_name (Name id) None t env in
- share_names d flags (n-1) ((Name id,Explicit,None,t')::l) avoid env sigma c c'
- (* May occur for fix built interactively *)
- | LetIn (na,b,t',c), _ when n > 0 ->
- let t'' = detype d flags avoid env sigma t' in
- let b' = detype d flags avoid env sigma b in
- let id = next_name_away na avoid in
- let avoid = Id.Set. add id avoid and env = add_name (Name id) (Some b) t' env in
- share_names d flags n ((Name id,Explicit,Some b',t'')::l) avoid env sigma c (lift 1 t)
- (* Only if built with the f/n notation or w/o let-expansion in types *)
- | _, LetIn (_,b,_,t) when n > 0 ->
- share_names d flags n l avoid env sigma c (subst1 b t)
- (* If it is an open proof: we cheat and eta-expand *)
- | _, Prod (na',t',c') when n > 0 ->
- let t'' = detype d flags avoid env sigma t' in
- let id = next_name_away na' avoid in
- let avoid = Id.Set.add id avoid and env = add_name (Name id) None t' env in
- let appc = mkApp (lift 1 c,[|mkRel 1|]) in
- share_names d flags (n-1) ((Name id,Explicit,None,t'')::l) avoid env sigma appc c'
- (* If built with the f/n notation: we renounce to share names *)
- | _ ->
- if n>0 then Feedback.msg_debug (strbrk "Detyping.detype: cannot factorize fix enough");
- let c = detype d flags avoid env sigma c in
- let t = detype d flags avoid env sigma t in
- (List.rev l,c,t)
+ | Fix (nvn,recdef) -> detype_fix (detype d flags) avoid env sigma nvn recdef
+ | CoFix (n,recdef) -> detype_cofix (detype d flags) avoid env sigma n recdef
and detype_eqns d flags avoid env sigma ci computable constructs consnargsl bl =
try
diff --git a/pretyping/detyping.mli b/pretyping/detyping.mli
index 32b94e1b0..817b8ba6e 100644
--- a/pretyping/detyping.mli
+++ b/pretyping/detyping.mli
@@ -56,6 +56,13 @@ val detype_sort : evar_map -> Sorts.t -> glob_sort
val detype_rel_context : 'a delay -> ?lax:bool -> constr option -> Id.Set.t -> (names_context * env) ->
evar_map -> rel_context -> 'a glob_decl_g list
+val share_pattern_names :
+ (Id.Set.t -> names_context -> 'c -> Pattern.constr_pattern -> 'a) -> int ->
+ (Name.t * Decl_kinds.binding_kind * 'b option * 'a) list ->
+ Id.Set.t -> names_context -> 'c -> Pattern.constr_pattern ->
+ Pattern.constr_pattern ->
+ (Name.t * Decl_kinds.binding_kind * 'b option * 'a) list * 'a * 'a
+
val detype_closed_glob : ?lax:bool -> bool -> Id.Set.t -> env -> evar_map -> closed_glob_constr -> glob_constr
(** look for the index of a named var or a nondep var as it is renamed *)
diff --git a/pretyping/evardefine.ml b/pretyping/evardefine.ml
index 03f40ad92..4cffbbb83 100644
--- a/pretyping/evardefine.ml
+++ b/pretyping/evardefine.ml
@@ -19,6 +19,7 @@ open Vars
open Namegen
open Evd
open Evarutil
+open Evar_kinds
open Pretype_errors
module RelDecl = Context.Rel.Declaration
@@ -78,12 +79,14 @@ let define_pure_evar_as_product evd evk =
let id = next_ident_away idx (Environ.ids_of_named_context_val evi.evar_hyps) in
let concl = Reductionops.whd_all evenv evd (EConstr.of_constr evi.evar_concl) in
let s = destSort evd concl in
+ let evksrc = evar_source evk evd in
+ let src = subterm_source evk ~where:Domain evksrc in
let evd1,(dom,u1) =
- new_type_evar evenv evd univ_flexible_alg ~filter:(evar_filter evi)
+ new_type_evar evenv evd univ_flexible_alg ~src ~filter:(evar_filter evi)
in
let evd2,rng =
let newenv = push_named (LocalAssum (id, dom)) evenv in
- let src = evar_source evk evd1 in
+ let src = subterm_source evk ~where:Codomain evksrc in
let filter = Filter.extend 1 (evar_filter evi) in
if Sorts.is_prop (ESorts.kind evd1 s) then
(* Impredicative product, conclusion must fall in [Prop]. *)
@@ -135,7 +138,7 @@ let define_pure_evar_as_lambda env evd evk =
next_name_away_with_default_using_types "x" na avoid (Reductionops.whd_evar evd dom) in
let newenv = push_named (LocalAssum (id, dom)) evenv in
let filter = Filter.extend 1 (evar_filter evi) in
- let src = evar_source evk evd1 in
+ let src = subterm_source evk ~where:Body (evar_source evk evd1) in
let evd2,body = new_evar newenv evd1 ~src (subst1 (mkVar id) rng) ~filter in
let lam = mkLambda (Name id, dom, subst_var id body) in
Evd.define evk (EConstr.Unsafe.to_constr lam) evd2, lam
diff --git a/pretyping/glob_ops.ml b/pretyping/glob_ops.ml
index 74f2cefab..e89bbf7c3 100644
--- a/pretyping/glob_ops.ml
+++ b/pretyping/glob_ops.ml
@@ -136,7 +136,7 @@ let mk_glob_constr_eq f c1 c2 = match DAst.get c1, DAst.get c2 with
| GIf (m1, (pat1, p1), c1, t1), GIf (m2, (pat2, p2), c2, t2) ->
f m1 m2 && Name.equal pat1 pat2 &&
Option.equal f p1 p2 && f c1 c2 && f t1 t2
- | GRec (kn1, id1, decl1, c1, t1), GRec (kn2, id2, decl2, c2, t2) ->
+ | GRec (kn1, id1, decl1, t1, c1), GRec (kn2, id2, decl2, t2, c2) ->
fix_kind_eq f kn1 kn2 && Array.equal Id.equal id1 id2 &&
Array.equal (fun l1 l2 -> List.equal (glob_decl_eq f) l1 l2) decl1 decl2 &&
Array.equal f c1 c2 && Array.equal f t1 t2
diff --git a/pretyping/patternops.ml b/pretyping/patternops.ml
index dcb93bfb6..e52112fda 100644
--- a/pretyping/patternops.ml
+++ b/pretyping/patternops.ml
@@ -15,7 +15,6 @@ open Globnames
open Nameops
open Term
open Constr
-open Vars
open Glob_term
open Pp
open Mod_subst
@@ -57,10 +56,10 @@ let rec constr_pattern_eq p1 p2 = match p1, p2 with
constr_pattern_eq p1 p2 &&
constr_pattern_eq r1 r2 &&
List.equal pattern_eq l1 l2
-| PFix f1, PFix f2 ->
- fixpoint_eq f1 f2
-| PCoFix f1, PCoFix f2 ->
- cofixpoint_eq f1 f2
+| PFix ((ln1,i1),f1), PFix ((ln2,i2),f2) ->
+ Array.equal Int.equal ln1 ln2 && Int.equal i1 i2 && rec_declaration_eq f1 f2
+| PCoFix (i1,f1), PCoFix (i2,f2) ->
+ Int.equal i1 i2 && rec_declaration_eq f1 f2
| PProj (p1, t1), PProj (p2, t2) ->
Projection.equal p1 p2 && constr_pattern_eq t1 t2
| (PRef _ | PVar _ | PEvar _ | PRel _ | PApp _ | PSoApp _
@@ -71,19 +70,10 @@ let rec constr_pattern_eq p1 p2 = match p1, p2 with
and pattern_eq (i1, j1, p1) (i2, j2, p2) =
Int.equal i1 i2 && List.equal (==) j1 j2 && constr_pattern_eq p1 p2
-and fixpoint_eq ((arg1, i1), r1) ((arg2, i2), r2) =
- Int.equal i1 i2 &&
- Array.equal Int.equal arg1 arg2 &&
- rec_declaration_eq r1 r2
-
-and cofixpoint_eq (i1, r1) (i2, r2) =
- Int.equal i1 i2 &&
- rec_declaration_eq r1 r2
-
and rec_declaration_eq (n1, c1, r1) (n2, c2, r2) =
Array.equal Name.equal n1 n2 &&
- Array.equal Constr.equal c1 c2 &&
- Array.equal Constr.equal r1 r2
+ Array.equal constr_pattern_eq c1 c2 &&
+ Array.equal constr_pattern_eq r1 r2
let rec occur_meta_pattern = function
| PApp (f,args) ->
@@ -123,8 +113,10 @@ let rec occurn_pattern n = function
| PMeta _ | PSoApp _ -> true
| PEvar (_,args) -> Array.exists (occurn_pattern n) args
| PVar _ | PRef _ | PSort _ -> false
- | PFix fix -> not (noccurn n (mkFix fix))
- | PCoFix cofix -> not (noccurn n (mkCoFix cofix))
+ | PFix (_,(_,tl,bl)) ->
+ Array.exists (occurn_pattern n) tl || Array.exists (occurn_pattern (n+Array.length tl)) bl
+ | PCoFix (_,(_,tl,bl)) ->
+ Array.exists (occurn_pattern n) tl || Array.exists (occurn_pattern (n+Array.length tl)) bl
let noccurn_pattern n c = not (occurn_pattern n c)
@@ -209,8 +201,16 @@ let pattern_of_constr env sigma t =
in
PCase (cip, pattern_of_constr env p, pattern_of_constr env a,
Array.to_list (Array.mapi branch_of_constr br))
- | Fix f -> PFix f
- | CoFix f -> PCoFix f in
+ | Fix (lni,(lna,tl,bl)) ->
+ let push env na2 c2 = push_rel (LocalAssum (na2,c2)) env in
+ let env' = Array.fold_left2 push env lna tl in
+ PFix (lni,(lna,Array.map (pattern_of_constr env) tl,
+ Array.map (pattern_of_constr env') bl))
+ | CoFix (ln,(lna,tl,bl)) ->
+ let push env na2 c2 = push_rel (LocalAssum (na2,c2)) env in
+ let env' = Array.fold_left2 push env lna tl in
+ PCoFix (ln,(lna,Array.map (pattern_of_constr env) tl,
+ Array.map (pattern_of_constr env') bl)) in
pattern_of_constr env t
(* To process patterns, we need a translation without typing at all. *)
@@ -225,10 +225,14 @@ let map_pattern_with_binders g f l = function
| PCase (ci,po,p,pl) ->
PCase (ci,f l po,f l p, List.map (fun (i,n,c) -> (i,n,f l c)) pl)
| PProj (p,pc) -> PProj (p, f l pc)
+ | PFix (lni,(lna,tl,bl)) ->
+ let l' = Array.fold_left (fun l na -> g na l) l lna in
+ PFix (lni,(lna,Array.map (f l) tl,Array.map (f l') bl))
+ | PCoFix (ln,(lna,tl,bl)) ->
+ let l' = Array.fold_left (fun l na -> g na l) l lna in
+ PCoFix (ln,(lna,Array.map (f l) tl,Array.map (f l') bl))
(* Non recursive *)
- | (PVar _ | PEvar _ | PRel _ | PRef _ | PSort _ | PMeta _
- (* Bound to terms *)
- | PFix _ | PCoFix _ as x) -> x
+ | (PVar _ | PEvar _ | PRel _ | PRef _ | PSort _ | PMeta _ as x) -> x
let error_instantiate_pattern id l =
let is = match l with
@@ -262,15 +266,12 @@ let instantiate_pattern env sigma lvar c =
error_instantiate_pattern id (List.subtract Id.equal ctx vars)
with Not_found (* Map.find failed *) ->
x)
- | (PFix _ | PCoFix _) -> user_err Pp.(str "Non instantiable pattern.")
| c ->
map_pattern_with_binders (fun id vars -> id::vars) aux vars c in
aux [] c
let rec liftn_pattern k n = function
| PRel i as x -> if i >= n then PRel (i+k) else x
- | PFix x -> PFix (destFix (liftn k n (mkFix x)))
- | PCoFix x -> PCoFix (destCoFix (liftn k n (mkCoFix x)))
| c -> map_pattern_with_binders (fun _ -> succ) (liftn_pattern k) n c
let lift_pattern k = liftn_pattern k 1
@@ -337,19 +338,35 @@ let rec subst_pattern subst pat =
if cip' == cip && typ' == typ && c' == c && branches' == branches
then pat
else PCase(cip', typ', c', branches')
- | PFix fixpoint ->
- let cstr = mkFix fixpoint in
- let fixpoint' = destFix (subst_mps subst cstr) in
- if fixpoint' == fixpoint then pat else
- PFix fixpoint'
- | PCoFix cofixpoint ->
- let cstr = mkCoFix cofixpoint in
- let cofixpoint' = destCoFix (subst_mps subst cstr) in
- if cofixpoint' == cofixpoint then pat else
- PCoFix cofixpoint'
-
-let mkPLambda na b = PLambda(na,PMeta None,b)
-let rev_it_mkPLambda = List.fold_right mkPLambda
+ | PFix (lni,(lna,tl,bl)) ->
+ let tl' = Array.smartmap (subst_pattern subst) tl in
+ let bl' = Array.smartmap (subst_pattern subst) bl in
+ if bl' == bl && tl' == tl then pat
+ else PFix (lni,(lna,tl',bl'))
+ | PCoFix (ln,(lna,tl,bl)) ->
+ let tl' = Array.smartmap (subst_pattern subst) tl in
+ let bl' = Array.smartmap (subst_pattern subst) bl in
+ if bl' == bl && tl' == tl then pat
+ else PCoFix (ln,(lna,tl',bl'))
+
+let mkPLetIn na b t c = PLetIn(na,b,t,c)
+let mkPProd na t u = PProd(na,t,u)
+let mkPLambda na t b = PLambda(na,t,b)
+let mkPLambdaUntyped na b = PLambda(na,PMeta None,b)
+let rev_it_mkPLambdaUntyped = List.fold_right mkPLambdaUntyped
+
+let mkPProd_or_LetIn (na,_,bo,t) c =
+ match bo with
+ | None -> mkPProd na t c
+ | Some b -> mkPLetIn na b (Some t) c
+
+let mkPLambda_or_LetIn (na,_,bo,t) c =
+ match bo with
+ | None -> mkPLambda na t c
+ | Some b -> mkPLetIn na b (Some t) c
+
+let it_mkPProd_or_LetIn = List.fold_left (fun c d -> mkPProd_or_LetIn d c)
+let it_mkPLambda_or_LetIn = List.fold_left (fun c d -> mkPLambda_or_LetIn d c)
let err ?loc pp = user_err ?loc ~hdr:"pattern_of_glob_constr" pp
@@ -428,7 +445,7 @@ let rec pat_of_raw metas vars = DAst.with_loc_val (fun ?loc -> function
let pred = match p,indnames with
| Some p, Some {CAst.v=(_,nal)} ->
let nvars = na :: List.rev nal @ vars in
- rev_it_mkPLambda nal (mkPLambda na (pat_of_raw metas nvars p))
+ rev_it_mkPLambdaUntyped nal (mkPLambdaUntyped na (pat_of_raw metas nvars p))
| None, _ -> PMeta None
| Some p, None ->
match DAst.get p with
@@ -450,9 +467,40 @@ let rec pat_of_raw metas vars = DAst.with_loc_val (fun ?loc -> function
| GProj(p,c) ->
PProj(p, pat_of_raw metas vars c)
- | GPatVar _ | GIf _ | GLetTuple _ | GCases _ | GEvar _ | GRec _ ->
+ | GRec (GFix (ln,n), ids, decls, tl, cl) ->
+ if Array.exists (function (Some n, GStructRec) -> false | _ -> true) ln then
+ err ?loc (Pp.str "\"struct\" annotation is expected.")
+ else
+ let ln = Array.map (fst %> Option.get) ln in
+ let ctxtl = Array.map2 (pat_of_glob_in_context metas vars) decls tl in
+ let tl = Array.map (fun (ctx,tl) -> it_mkPProd_or_LetIn tl ctx) ctxtl in
+ let vars = Array.fold_left (fun vars na -> Name na::vars) vars ids in
+ let ctxtl = Array.map2 (pat_of_glob_in_context metas vars) decls cl in
+ let cl = Array.map (fun (ctx,cl) -> it_mkPLambda_or_LetIn cl ctx) ctxtl in
+ let names = Array.map (fun id -> Name id) ids in
+ PFix ((ln,n), (names, tl, cl))
+
+ | GRec (GCoFix n, ids, decls, tl, cl) ->
+ let ctxtl = Array.map2 (pat_of_glob_in_context metas vars) decls tl in
+ let tl = Array.map (fun (ctx,tl) -> it_mkPProd_or_LetIn tl ctx) ctxtl in
+ let vars = Array.fold_left (fun vars na -> Name na::vars) vars ids in
+ let ctxtl = Array.map2 (pat_of_glob_in_context metas vars) decls cl in
+ let cl = Array.map (fun (ctx,cl) -> it_mkPLambda_or_LetIn cl ctx) ctxtl in
+ let names = Array.map (fun id -> Name id) ids in
+ PCoFix (n, (names, tl, cl))
+
+ | GPatVar _ | GIf _ | GLetTuple _ | GCases _ | GEvar _ ->
err ?loc (Pp.str "Non supported pattern."))
+and pat_of_glob_in_context metas vars decls c =
+ let rec aux acc vars = function
+ | (na,bk,b,t) :: decls ->
+ let decl = (na,bk,Option.map (pat_of_raw metas vars) b,pat_of_raw metas vars t) in
+ aux (decl::acc) (na::vars) decls
+ | [] ->
+ acc, pat_of_raw metas vars c
+ in aux [] vars decls
+
and pats_of_glob_branches loc metas vars ind brs =
let get_arg p = match DAst.get p with
| PatVar na ->
@@ -477,7 +525,7 @@ and pats_of_glob_branches loc metas vars ind brs =
(str "No unique branch for " ++ int j ++ str"-th constructor.");
let lna = List.map get_arg lv in
let vars' = List.rev lna @ vars in
- let pat = rev_it_mkPLambda lna (pat_of_raw metas vars' br) in
+ let pat = rev_it_mkPLambdaUntyped lna (pat_of_raw metas vars' br) in
let ext,pats = get_pat (Int.Set.add (j-1) indexes) brs in
let tags = List.map (fun _ -> false) lv (* approximation, w/o let-in *) in
ext, ((j-1, tags, pat) :: pats)
diff --git a/printing/ppvernac.ml b/printing/ppvernac.ml
index 7df0a0c94..7eb8396ac 100644
--- a/printing/ppvernac.ml
+++ b/printing/ppvernac.ml
@@ -155,13 +155,6 @@ open Decl_kinds
let pr_locality local = if local then keyword "Local" else keyword "Global"
- let pr_explanation (e,b,f) =
- let a = match e with
- | ExplByPos (n,_) -> anomaly (Pp.str "No more supported.")
- | ExplByName id -> pr_id id in
- let a = if f then str"!" ++ a else a in
- if b then str "[" ++ a ++ str "]" else a
-
let pr_option_ref_value = function
| QualidRefValue id -> pr_reference id
| StringRefValue s -> qs s
@@ -591,8 +584,6 @@ open Decl_kinds
)
| VernacUndoTo i ->
return (keyword "Undo" ++ spc() ++ keyword "To" ++ pr_intarg i)
- | VernacBacktrack (i,j,k) ->
- return (keyword "Backtrack" ++ spc() ++ prlist_with_sep sep int [i;j;k])
| VernacFocus i ->
return (keyword "Focus" ++ pr_opt int i)
| VernacShow s ->
@@ -653,16 +644,6 @@ open Decl_kinds
keyword "Bind Scope" ++ spc () ++ str sc ++
spc() ++ keyword "with" ++ spc () ++ prlist_with_sep spc pr_class_rawexpr cll
)
- | VernacArgumentsScope (q,scl) ->
- let pr_opt_scope = function
- | None -> str"_"
- | Some sc -> str sc
- in
- return (
- keyword "Arguments Scope"
- ++ spc() ++ pr_smart_global q
- ++ spc() ++ str"[" ++ prlist_with_sep sep pr_opt_scope scl ++ str"]"
- )
| VernacInfix (({v=s},mv),q,sn) -> (* A Verifier *)
return (
hov 0 (hov 0 (keyword "Infix "
@@ -786,8 +767,9 @@ open Decl_kinds
if p then
let cm =
match cum with
- | GlobalCumulativity | LocalCumulativity -> "Cumulative"
- | GlobalNonCumulativity | LocalNonCumulativity -> "NonCumulative"
+ | Some VernacCumulative -> "Cumulative"
+ | Some VernacNonCumulative -> "NonCumulative"
+ | None -> ""
in
cm ^ " " ^ kind
else kind
@@ -1016,18 +998,6 @@ open Decl_kinds
| Some Flags.Current -> [SetOnlyParsing]
| Some v -> [SetCompatVersion v]))
)
- | VernacDeclareImplicits (q,[]) ->
- return (
- hov 2 (keyword "Implicit Arguments" ++ spc() ++ pr_smart_global q)
- )
- | VernacDeclareImplicits (q,impls) ->
- return (
- hov 1 (keyword "Implicit Arguments" ++ spc () ++
- spc() ++ pr_smart_global q ++ spc() ++
- prlist_with_sep spc (fun imps ->
- str"[" ++ prlist_with_sep sep pr_explanation imps ++ str"]")
- impls)
- )
| VernacArguments (q, args, more_implicits, nargs, mods) ->
return (
hov 2 (
diff --git a/stm/stm.ml b/stm/stm.ml
index 4b49d1998..ba0a2017a 100644
--- a/stm/stm.ml
+++ b/stm/stm.ml
@@ -1072,7 +1072,7 @@ let stm_vernac_interp ?proof ?route id st { verbose; loc; expr } : Vernacstate.t
let is_filtered_command = function
| VernacResetName _ | VernacResetInitial | VernacBack _
| VernacBackTo _ | VernacRestart | VernacUndo _ | VernacUndoTo _
- | VernacBacktrack _ | VernacAbortAll | VernacAbort _ -> true
+ | VernacAbortAll | VernacAbort _ -> true
| _ -> false
in
let aux_interp st expr =
@@ -1097,7 +1097,6 @@ let stm_vernac_interp ?proof ?route id st { verbose; loc; expr } : Vernacstate.t
module Backtrack : sig
val record : unit -> unit
- val backto : Stateid.t -> unit
(* we could navigate the dag, but this ways easy *)
val branches_of : Stateid.t -> backup
@@ -1122,14 +1121,6 @@ end = struct (* {{{ *)
info.vcs_backup <- backup, branches)
[VCS.current_branch (); VCS.Branch.master]
- let backto oid =
- let info = VCS.get_info oid in
- match info.vcs_backup with
- | None, _ ->
- anomaly Pp.(str"Backtrack.backto "++str(Stateid.to_string oid)++
- str": a state with no vcs_backup.")
- | Some vcs, _ -> VCS.restore vcs
-
let branches_of id =
let info = VCS.get_info id in
match info.vcs_backup with
@@ -1220,7 +1211,6 @@ end = struct (* {{{ *)
match Vcs_.branches vcs with [_] -> `Stop id | _ -> `Cont ())
() id in
oid, VtLater
- | VernacBacktrack (id,_,_)
| VernacBackTo id ->
Stateid.of_int id, VtNow
| _ -> anomaly Pp.(str "incorrect VtMeta classification")
@@ -2757,9 +2747,7 @@ let snapshot_vio ~doc ldir long_f_dot_vo =
let reset_task_queue = Slaves.reset_task_queue
(* Document building *)
-let process_back_meta_command ~part_of_script ~newtip ~head oid aast w =
- match part_of_script, w with
- | true, w ->
+let process_back_meta_command ~newtip ~head oid aast w =
let id = VCS.new_node ~id:newtip () in
let { mine; others } = Backtrack.branches_of oid in
let valid = VCS.get_branch_pos head in
@@ -2779,16 +2767,7 @@ let process_back_meta_command ~part_of_script ~newtip ~head oid aast w =
VCS.commit id (Alias (oid,aast));
Backtrack.record (); if w == VtNow then ignore(finish ~doc:dummy_doc); `Ok
- | false, VtNow ->
- stm_prerr_endline (fun () -> "undo to state " ^ Stateid.to_string oid);
- Backtrack.backto oid;
- VCS.checkout_shallowest_proof_branch ();
- Reach.known_state ~cache:(VCS.is_interactive ()) oid; `Ok
-
- | false, VtLater ->
- anomaly(str"undo classifier: VtMeta + VtLater must imply part_of_script.")
-
-let process_transaction ?(newtip=Stateid.fresh ()) ?(part_of_script=true)
+let process_transaction ?(newtip=Stateid.fresh ())
({ verbose; loc; expr } as x) c =
stm_pperr_endline (fun () -> str "{{{ processing: " ++ pr_ast x);
let vcs = VCS.backup () in
@@ -2802,22 +2781,10 @@ let process_transaction ?(newtip=Stateid.fresh ()) ?(part_of_script=true)
(* Meta *)
| VtMeta, _ ->
let id, w = Backtrack.undo_vernac_classifier expr in
- (* Special case Backtrack, as it is never part of a script. See #6240 *)
- let part_of_script = begin match Vernacprop.under_control expr with
- | VernacBacktrack _ -> false
- | _ -> part_of_script
- end in
- process_back_meta_command ~part_of_script ~newtip ~head id x w
+ process_back_meta_command ~newtip ~head id x w
+
(* Query *)
- | VtQuery (false,route), VtNow ->
- let query_sid = VCS.cur_tip () in
- (try
- let st = Vernacstate.freeze_interp_state `No in
- ignore(stm_vernac_interp ~route query_sid st x)
- with e ->
- let e = CErrors.push e in
- Exninfo.iraise (State.exn_on ~valid:Stateid.dummy query_sid e)); `Ok
- | VtQuery (true, route), w ->
+ | VtQuery, w ->
let id = VCS.new_node ~id:newtip () in
let queue =
if !cur_opt.async_proofs_full then `QueryQueue (ref false)
@@ -2829,9 +2796,6 @@ let process_transaction ?(newtip=Stateid.fresh ()) ?(part_of_script=true)
VCS.commit id (mkTransCmd x [] false queue);
Backtrack.record (); if w == VtNow then ignore(finish ~doc:dummy_doc); `Ok
- | VtQuery (false,_), VtLater ->
- anomaly(str"classifier: VtQuery + VtLater must imply part_of_script.")
-
(* Proof *)
| VtStartProof (mode, guarantee, names), w ->
let id = VCS.new_node ~id:newtip () in
@@ -2884,18 +2848,22 @@ let process_transaction ?(newtip=Stateid.fresh ()) ?(part_of_script=true)
Backtrack.record (); if w == VtNow then ignore(finish ~doc:dummy_doc);
rc
- (* Side effect on all branches *)
+ (* Side effect in a (still open) proof is replayed on all branches*)
| VtSideff l, w ->
- let in_proof = not (VCS.Branch.equal head VCS.Branch.master) in
let id = VCS.new_node ~id:newtip () in
- VCS.checkout VCS.Branch.master;
- VCS.commit id (mkTransCmd x l in_proof `MainQueue);
- (* We can't replay a Definition since universes may be differently
- * inferred. This holds in Coq >= 8.5 *)
- let action = match Vernacprop.under_control x.expr with
- | VernacDefinition(_, _, DefineBody _) -> CherryPickEnv
- | _ -> ReplayCommand x in
- VCS.propagate_sideff ~action;
+ begin match (VCS.get_branch head).VCS.kind with
+ | `Edit _ -> VCS.commit id (mkTransCmd x l true `MainQueue);
+ | `Master -> VCS.commit id (mkTransCmd x l false `MainQueue);
+ | `Proof _ ->
+ VCS.checkout VCS.Branch.master;
+ VCS.commit id (mkTransCmd x l true `MainQueue);
+ (* We can't replay a Definition since universes may be differently
+ * inferred. This holds in Coq >= 8.5 *)
+ let action = match Vernacprop.under_control x.expr with
+ | VernacDefinition(_, _, DefineBody _) -> CherryPickEnv
+ | _ -> ReplayCommand x in
+ VCS.propagate_sideff ~action;
+ end;
VCS.checkout_shallowest_proof_branch ();
Backtrack.record (); if w == VtNow then ignore(finish ~doc:dummy_doc); `Ok
@@ -2924,9 +2892,14 @@ let process_transaction ?(newtip=Stateid.fresh ()) ?(part_of_script=true)
VCS.branch bname (`Proof (proof_mode, VCS.proof_nesting () + 1));
Proof_global.activate_proof_mode proof_mode [@ocaml.warning "-3"];
end else begin
- VCS.commit id (mkTransCmd x [] in_proof `MainQueue);
- (* We hope it can be replayed, but we can't really know *)
- VCS.propagate_sideff ~action:(ReplayCommand x);
+ begin match (VCS.get_branch head).VCS.kind with
+ | `Edit _ -> VCS.commit id (mkTransCmd x [] in_proof `MainQueue);
+ | `Master -> VCS.commit id (mkTransCmd x [] in_proof `MainQueue);
+ | `Proof _ ->
+ VCS.commit id (mkTransCmd x [] in_proof `MainQueue);
+ (* We hope it can be replayed, but we can't really know *)
+ VCS.propagate_sideff ~action:(ReplayCommand x);
+ end;
VCS.checkout_shallowest_proof_branch ();
end in
State.define ~safe_id:head_id ~cache:`Yes step id;
@@ -3065,13 +3038,9 @@ let query ~doc ~at ~route s =
let { CAst.loc; v=ast } = parse_sentence ~doc at s in
let indentation, strlen = compute_indentation ?loc at in
CWarnings.set_current_loc loc;
- let clas = Vernac_classifier.classify_vernac ast in
+ let st = State.get_cached at in
let aast = { verbose = true; indentation; strlen; loc; expr = ast } in
- match clas with
- | VtMeta , _ -> (* TODO: can this still happen ? *)
- ignore(process_transaction ~part_of_script:false aast (VtMeta,VtNow))
- | _ ->
- ignore(process_transaction aast (VtQuery (false,route), VtNow))
+ ignore(stm_vernac_interp ~route at st aast)
done;
with
| End_of_input -> ()
diff --git a/stm/stm.mli b/stm/stm.mli
index a8eb10fb3..7a720aa72 100644
--- a/stm/stm.mli
+++ b/stm/stm.mli
@@ -39,14 +39,25 @@ module AsyncOpts : sig
end
-(** The STM doc type determines some properties such as what
- uncompleted proofs are allowed and recording of aux files. *)
+(** The STM document type [stm_doc_type] determines some properties
+ such as what uncompleted proofs are allowed and what gets recorded
+ to aux files. *)
type stm_doc_type =
- | VoDoc of string
- | VioDoc of string
- | Interactive of DirPath.t
+ | VoDoc of string (* file path *)
+ | VioDoc of string (* file path *)
+ | Interactive of DirPath.t (* module path *)
-(* Main initalization routine *)
+(** Coq initalization options:
+
+ - [doc_type]: Type of document being created.
+
+ - [require_libs]: list of libraries/modules to be pre-loaded at
+ startup. A tuple [(modname,modfrom,import)] is equivalent to [From
+ modfrom Require modname]; [import] works similarly to
+ [Library.require_library_from_dirpath], [Some false] will import
+ the module, [Some true] will additionally export it.
+
+*)
type stm_init_options = {
(* The STM will set some internal flags differently depending on the
specified [doc_type]. This distinction should dissappear at some
@@ -72,12 +83,14 @@ type stm_init_options = {
(** The type of a STM document *)
type doc
+(** [init_core] performs some low-level initalization; should go away
+ in future releases. *)
val init_core : unit -> unit
-(* Starts a new document *)
+(** [new_doc opt] Creates a new document with options [opt] *)
val new_doc : stm_init_options -> doc * Stateid.t
-(* [parse_sentence sid pa] Reads a sentence from [pa] with parsing
+(** [parse_sentence sid pa] Reads a sentence from [pa] with parsing
state [sid] Returns [End_of_input] if the stream ends *)
val parse_sentence : doc:doc -> Stateid.t -> Pcoq.Gram.coq_parsable ->
Vernacexpr.vernac_control CAst.t
@@ -115,14 +128,15 @@ val query : doc:doc ->
type focus = { start : Stateid.t; stop : Stateid.t; tip : Stateid.t }
val edit_at : doc:doc -> Stateid.t -> doc * [ `NewTip | `Focus of focus ]
-(* Evaluates the tip of the current branch *)
+(* [observe doc sid]] Check / execute span [sid] *)
+val observe : doc:doc -> Stateid.t -> doc
+
+(* [finish doc] Fully checks a document up to the "current" tip. *)
val finish : doc:doc -> doc
(* Internal use (fake_ide) only, do not use *)
val wait : doc:doc -> doc
-val observe : doc:doc -> Stateid.t -> doc
-
val stop_worker : string -> unit
(* Joins the entire document. Implies finish, but also checks proofs *)
diff --git a/stm/vernac_classifier.ml b/stm/vernac_classifier.ml
index 9a8af3a58..c08cc6e36 100644
--- a/stm/vernac_classifier.ml
+++ b/stm/vernac_classifier.ml
@@ -16,8 +16,6 @@ open Vernacexpr
let default_proof_mode () = Proof_global.get_default_proof_mode_name () [@ocaml.warning "-3"]
-let string_of_in_script b = if b then " (inside script)" else ""
-
let string_of_parallel = function
| `Yes (solve,abs) ->
"par" ^ if solve then "solve" else "" ^ if abs then "abs" else ""
@@ -34,7 +32,7 @@ let string_of_vernac_type = function
"ProofStep " ^ string_of_parallel parallel ^
Option.default "" proof_block_detection
| VtProofMode s -> "ProofMode " ^ s
- | VtQuery (b, route) -> "Query " ^ string_of_in_script b ^ " route " ^ string_of_int route
+ | VtQuery -> "Query"
| VtMeta -> "Meta "
let string_of_vernac_when = function
@@ -70,7 +68,7 @@ let classify_vernac e =
| VernacEndProof _ | VernacExactProof _ -> VtQed VtKeep, VtLater
(* Query *)
| VernacShow _ | VernacPrint _ | VernacSearch _ | VernacLocate _
- | VernacCheckMayEval _ -> VtQuery (true,Feedback.default_route), VtLater
+ | VernacCheckMayEval _ -> VtQuery, VtLater
(* ProofStep *)
| VernacProof _
| VernacFocus _ | VernacUnfocus
@@ -145,7 +143,7 @@ let classify_vernac e =
| VernacAddLoadPath _ | VernacRemoveLoadPath _ | VernacAddMLPath _
| VernacChdir _
| VernacCreateHintDb _ | VernacRemoveHints _ | VernacHints _
- | VernacDeclareImplicits _ | VernacArguments _ | VernacArgumentsScope _
+ | VernacArguments _
| VernacReserve _
| VernacGeneralizable _
| VernacSetOpacity _ | VernacSetStrategy _
@@ -183,7 +181,7 @@ let classify_vernac e =
| VernacBack _ | VernacAbortAll
| VernacUndoTo _ | VernacUndo _
| VernacResetName _ | VernacResetInitial
- | VernacBacktrack _ | VernacBackTo _ | VernacRestart -> VtMeta, VtNow
+ | VernacBackTo _ | VernacRestart -> VtMeta, VtNow
(* What are these? *)
| VernacRestoreState _
| VernacWriteState _ -> VtSideff [], VtNow
@@ -205,7 +203,7 @@ let classify_vernac e =
static_control_classifier ~poly e
| VernacFail e -> (* Fail Qed or Fail Lemma must not join/fork the DAG *)
(match static_control_classifier ~poly e with
- | ( VtQuery _ | VtProofStep _ | VtSideff _
+ | ( VtQuery | VtProofStep _ | VtSideff _
| VtProofMode _ | VtMeta), _ as x -> x
| VtQed _, _ ->
VtProofStep { parallel = `No; proof_block_detection = None },
@@ -214,6 +212,6 @@ let classify_vernac e =
in
static_control_classifier ~poly:(Flags.is_universe_polymorphism ()) e
-let classify_as_query = VtQuery (true,Feedback.default_route), VtLater
+let classify_as_query = VtQuery, VtLater
let classify_as_sideeff = VtSideff [], VtLater
let classify_as_proofstep = VtProofStep { parallel = `No; proof_block_detection = None}, VtLater
diff --git a/tactics/equality.mli b/tactics/equality.mli
index c0be917a0..ccf454c3e 100644
--- a/tactics/equality.mli
+++ b/tactics/equality.mli
@@ -80,20 +80,20 @@ val discrConcl : unit Proofview.tactic
val discrHyp : Id.t -> unit Proofview.tactic
val discrEverywhere : evars_flag -> unit Proofview.tactic
val discr_tac : evars_flag ->
- constr with_bindings destruction_arg option -> unit Proofview.tactic
+ constr with_bindings Tactics.destruction_arg option -> unit Proofview.tactic
(* Below, if flag is [None], it takes the value from the dynamic value of the option *)
val inj : inj_flags option -> intro_patterns option -> evars_flag ->
clear_flag -> constr with_bindings -> unit Proofview.tactic
val injClause : inj_flags option -> intro_patterns option -> evars_flag ->
- constr with_bindings destruction_arg option -> unit Proofview.tactic
+ constr with_bindings Tactics.destruction_arg option -> unit Proofview.tactic
val injHyp : inj_flags option -> clear_flag -> Id.t -> unit Proofview.tactic
val injConcl : inj_flags option -> unit Proofview.tactic
val simpleInjClause : inj_flags option -> evars_flag ->
- constr with_bindings destruction_arg option -> unit Proofview.tactic
+ constr with_bindings Tactics.destruction_arg option -> unit Proofview.tactic
-val dEq : keep_proofs:(bool option) -> evars_flag -> constr with_bindings destruction_arg option -> unit Proofview.tactic
-val dEqThen : keep_proofs:(bool option) -> evars_flag -> (clear_flag -> constr -> int -> unit Proofview.tactic) -> constr with_bindings destruction_arg option -> unit Proofview.tactic
+val dEq : keep_proofs:(bool option) -> evars_flag -> constr with_bindings Tactics.destruction_arg option -> unit Proofview.tactic
+val dEqThen : keep_proofs:(bool option) -> evars_flag -> (clear_flag -> constr -> int -> unit Proofview.tactic) -> constr with_bindings Tactics.destruction_arg option -> unit Proofview.tactic
val make_iterated_tuple :
env -> evar_map -> constr -> (constr * types) -> evar_map * (constr * constr * constr)
diff --git a/tactics/inv.ml b/tactics/inv.ml
index 067fc8941..d76c9a697 100644
--- a/tactics/inv.ml
+++ b/tactics/inv.ml
@@ -64,6 +64,11 @@ let var_occurs_in_pf gl id =
type inversion_status = Dep of constr option | NoDep
+type inversion_kind =
+ | SimpleInversion
+ | FullInversion
+ | FullInversionClear
+
let compute_eqn env sigma n i ai =
(mkRel (n-i),get_type_of env sigma (mkRel (n-i)))
diff --git a/tactics/inv.mli b/tactics/inv.mli
index c63d57af5..9d4ffdd7b 100644
--- a/tactics/inv.mli
+++ b/tactics/inv.mli
@@ -15,6 +15,11 @@ open Tactypes
type inversion_status = Dep of constr option | NoDep
+type inversion_kind =
+ | SimpleInversion
+ | FullInversion
+ | FullInversionClear
+
val inv_clause :
inversion_kind -> or_and_intro_pattern option -> Id.t list ->
quantified_hypothesis -> unit Proofview.tactic
diff --git a/tactics/tacticals.ml b/tactics/tacticals.ml
index 958a205a1..a97ae8f65 100644
--- a/tactics/tacticals.ml
+++ b/tactics/tacticals.ml
@@ -369,9 +369,36 @@ module New = struct
tclTHENSFIRSTn t1 l (tclUNIT())
let tclTHENFIRST t1 t2 =
tclTHENFIRSTn t1 [|t2|]
+
+ let tclBINDFIRST t1 t2 =
+ t1 >>= fun ans ->
+ Proofview.Unsafe.tclGETGOALS >>= fun gls ->
+ match gls with
+ | [] -> tclFAIL 0 (str "Expect at least one goal.")
+ | hd::tl ->
+ Proofview.Unsafe.tclSETGOALS [hd] <*> t2 ans >>= fun ans ->
+ Proofview.Unsafe.tclNEWGOALS tl <*>
+ Proofview.tclUNIT ans
+
let tclTHENLASTn t1 l =
tclTHENS3PARTS t1 [||] (tclUNIT()) l
let tclTHENLAST t1 t2 = tclTHENLASTn t1 [|t2|]
+
+ let option_of_failure f x = try Some (f x) with Failure _ -> None
+
+ let tclBINDLAST t1 t2 =
+ t1 >>= fun ans ->
+ Proofview.Unsafe.tclGETGOALS >>= fun gls ->
+ match option_of_failure List.sep_last gls with
+ | None -> tclFAIL 0 (str "Expect at least one goal.")
+ | Some (last,firstn) ->
+ Proofview.Unsafe.tclSETGOALS [last] <*> t2 ans >>= fun ans ->
+ Proofview.Unsafe.tclGETGOALS >>= fun newgls ->
+ tclEVARMAP >>= fun sigma ->
+ let firstn = Proofview.Unsafe.undefined sigma firstn in
+ Proofview.Unsafe.tclSETGOALS (firstn@newgls) <*>
+ Proofview.tclUNIT ans
+
let tclTHENS t l =
tclINDEPENDENT begin
t <*>Proofview.tclORELSE (* converts the [SizeMismatch] error into an ltac error *)
diff --git a/tactics/tacticals.mli b/tactics/tacticals.mli
index f0ebac780..340d8fbf3 100644
--- a/tactics/tacticals.mli
+++ b/tactics/tacticals.mli
@@ -196,8 +196,10 @@ module New : sig
(** [tclTHENFIRST tac1 tac2 gls] applies the tactic [tac1] to [gls]
and [tac2] to the first resulting subgoal *)
val tclTHENFIRST : unit tactic -> unit tactic -> unit tactic
+ val tclBINDFIRST : 'a tactic -> ('a -> 'b tactic) -> 'b tactic
val tclTHENLASTn : unit tactic -> unit tactic array -> unit tactic
val tclTHENLAST : unit tactic -> unit tactic -> unit tactic
+ val tclBINDLAST : 'a tactic -> ('a -> 'b tactic) -> 'b tactic
(* [tclTHENS t l = t <*> tclDISPATCH l] *)
val tclTHENS : unit tactic -> unit tactic list -> unit tactic
(* [tclTHENLIST [t1;…;tn]] is [t1<*>…<*>tn] *)
diff --git a/tactics/tactics.ml b/tactics/tactics.ml
index df3cca144..d0ec3358a 100644
--- a/tactics/tactics.ml
+++ b/tactics/tactics.ml
@@ -1102,7 +1102,13 @@ let msg_quantified_hypothesis = function
pr_nth n ++
str " non dependent hypothesis"
+let warn_deprecated_intros_until_0 =
+ CWarnings.create ~name:"deprecated-intros-until-0" ~category:"tactics"
+ (fun () ->
+ strbrk"\"intros until 0\" is deprecated, use \"intros *\"; instead of \"induction 0\" and \"destruct 0\" use explicitly a name.\"")
+
let depth_of_quantified_hypothesis red h gl =
+ if h = AnonHyp 0 then warn_deprecated_intros_until_0 ();
match lookup_hypothesis_as_renamed_gen red h gl with
| Some depth -> depth
| None ->
@@ -1153,6 +1159,13 @@ let tactic_infer_flags with_evar = {
Pretyping.fail_evar = not with_evar;
Pretyping.expand_evars = true }
+type 'a core_destruction_arg =
+ | ElimOnConstr of 'a
+ | ElimOnIdent of lident
+ | ElimOnAnonHyp of int
+
+type 'a destruction_arg =
+ clear_flag * 'a core_destruction_arg
let onOpenInductionArg env sigma tac = function
| clear_flag,ElimOnConstr f ->
@@ -4981,15 +4994,15 @@ let anon_id = Id.of_string "anonymous"
let name_op_to_name name_op object_kind suffix =
let open Proof_global in
let default_gk = (Global, false, object_kind) in
+ let name, gk = match Proof_global.V82.get_current_initial_conclusions () with
+ | (id, (_, gk)) -> Some id, gk
+ | exception NoCurrentProof -> None, default_gk
+ in
match name_op with
- | Some s ->
- (try let _, gk, _ = Pfedit.current_proof_statement () in s, gk
- with NoCurrentProof -> s, default_gk)
- | None ->
- let name, gk =
- try let name, gk, _ = Pfedit.current_proof_statement () in name, gk
- with NoCurrentProof -> anon_id, default_gk in
- add_suffix name suffix, gk
+ | Some s -> s, gk
+ | None ->
+ let name = Option.default anon_id name in
+ add_suffix name suffix, gk
let tclABSTRACT ?(opaque=true) name_op tac =
let s, gk = if opaque
diff --git a/tactics/tactics.mli b/tactics/tactics.mli
index 079baa3ef..7809dbf48 100644
--- a/tactics/tactics.mli
+++ b/tactics/tactics.mli
@@ -95,6 +95,14 @@ val try_intros_until :
(** Apply a tactic on a quantified hypothesis, an hypothesis in context
or a term with bindings *)
+type 'a core_destruction_arg =
+ | ElimOnConstr of 'a
+ | ElimOnIdent of lident
+ | ElimOnAnonHyp of int
+
+type 'a destruction_arg =
+ clear_flag * 'a core_destruction_arg
+
val onInductionArg :
(clear_flag -> constr with_bindings -> unit Proofview.tactic) ->
constr with_bindings destruction_arg -> unit Proofview.tactic
diff --git a/test-suite/bugs/closed/1341.v b/test-suite/bugs/closed/1341.v
index 8c5a38859..79a0a14d7 100644
--- a/test-suite/bugs/closed/1341.v
+++ b/test-suite/bugs/closed/1341.v
@@ -8,7 +8,7 @@ Hypothesis Xst : forall A, Equivalence (Xeq A).
Variable map : forall A B, (A -> B) -> X A -> X B.
-Implicit Arguments map [A B].
+Arguments map [A B].
Goal forall A B (a b:X (B -> A)) (c:X A) (f:A -> B -> A), Xeq _ a b -> Xeq _ b (map f c) -> Xeq _ a (map f c).
intros A B a b c f Hab Hbc.
diff --git a/test-suite/bugs/closed/1844.v b/test-suite/bugs/closed/1844.v
index 17eeb3529..c41e45900 100644
--- a/test-suite/bugs/closed/1844.v
+++ b/test-suite/bugs/closed/1844.v
@@ -5,7 +5,7 @@ Definition zeq := Z.eq_dec.
Definition update (A: Set) (x: Z) (v: A) (s: Z -> A) : Z -> A :=
fun y => if zeq x y then v else s y.
-Implicit Arguments update [A].
+Arguments update [A].
Definition ident := Z.
Parameter operator: Set.
diff --git a/test-suite/bugs/closed/1891.v b/test-suite/bugs/closed/1891.v
index 685811176..5024a5bc9 100644
--- a/test-suite/bugs/closed/1891.v
+++ b/test-suite/bugs/closed/1891.v
@@ -3,7 +3,7 @@
Definition f (A: Set) (l: T A): unit := tt.
- Implicit Arguments f [A].
+ Arguments f [A].
Lemma L (x: T unit): (unit -> T unit) -> unit.
Proof.
diff --git a/test-suite/bugs/closed/1951.v b/test-suite/bugs/closed/1951.v
index 7558b0b86..e950554c4 100644
--- a/test-suite/bugs/closed/1951.v
+++ b/test-suite/bugs/closed/1951.v
@@ -42,7 +42,7 @@ match s as a return (S a) with
pair (ind2 a0) IHl) l)
end. (* some induction principle *)
-Implicit Arguments ind [S].
+Arguments ind [S].
Lemma k : a -> Type. (* some ininteresting lemma *)
intro;pattern H;apply ind;intros.
diff --git a/test-suite/bugs/closed/1981.v b/test-suite/bugs/closed/1981.v
index 99952682d..a3d942930 100644
--- a/test-suite/bugs/closed/1981.v
+++ b/test-suite/bugs/closed/1981.v
@@ -1,4 +1,4 @@
-Implicit Arguments ex_intro [A].
+Arguments ex_intro [A].
Goal exists n : nat, True.
eapply ex_intro. exact 0. exact I.
diff --git a/test-suite/bugs/closed/2362.v b/test-suite/bugs/closed/2362.v
index febb9c7bb..10e86cd12 100644
--- a/test-suite/bugs/closed/2362.v
+++ b/test-suite/bugs/closed/2362.v
@@ -8,7 +8,7 @@ Class Pointed (M:Type -> Type) :=
Unset Implicit Arguments.
Inductive FPair (A B:Type) (neutral: B) : Type:=
fpair : forall (a:A) (b:B), FPair A B neutral.
-Implicit Arguments fpair [[A] [B] [neutral]].
+Arguments fpair {A B neutral}.
Set Implicit Arguments.
diff --git a/test-suite/bugs/closed/2378.v b/test-suite/bugs/closed/2378.v
index 23a58501f..6d73d58d4 100644
--- a/test-suite/bugs/closed/2378.v
+++ b/test-suite/bugs/closed/2378.v
@@ -63,7 +63,7 @@ Fixpoint lpSat st f: Prop :=
end.
End PropLogic.
-Implicit Arguments lpSat.
+Arguments lpSat : default implicits.
Fixpoint LPTransfo Pred1 Pred2 p2lp (f: LP Pred1): LP Pred2 :=
match f with
@@ -71,7 +71,7 @@ Fixpoint LPTransfo Pred1 Pred2 p2lp (f: LP Pred1): LP Pred2 :=
| LPAnd _ f1 f2 => LPAnd _ (LPTransfo Pred1 Pred2 p2lp f1) (LPTransfo Pred1 Pred2 p2lp f2)
| LPNot _ f1 => LPNot _ (LPTransfo Pred1 Pred2 p2lp f1)
end.
-Implicit Arguments LPTransfo.
+Arguments LPTransfo : default implicits.
Definition addIndex (Ind:Type) (Pred: Ind -> Type) (i: Ind) f :=
LPTransfo (fun p => LPPred _ (existT (fun i => Pred i) i p)) f.
@@ -139,7 +139,7 @@ Definition trProd (State: Type) Ind (Pred: Ind -> Type) (tts: Ind -> TTS State)
{i:Ind & Pred i} -> LP (Predicate _ (TTSIndexedProduct _ Ind tts)) :=
fun p => addIndex Ind _ (projS1 p) (tr (projS1 p) (projS2 p)).
-Implicit Arguments trProd.
+Arguments trProd : default implicits.
Require Import Setoid.
Theorem satTrProd:
diff --git a/test-suite/bugs/closed/2404.v b/test-suite/bugs/closed/2404.v
index 8ac696e91..f6ec67601 100644
--- a/test-suite/bugs/closed/2404.v
+++ b/test-suite/bugs/closed/2404.v
@@ -22,13 +22,13 @@ Section Derived.
Definition bexportw := exportw base.
Definition bwweak := wweak base.
- Implicit Arguments bexportw [a b].
+ Arguments bexportw [a b].
Inductive RstarSetProof {I : Type} (T : I -> I -> Type) : I -> I -> Type :=
starReflS : forall a, RstarSetProof T a a
| starTransS : forall i j k, T i j -> (RstarSetProof T j k) -> RstarSetProof T i k.
-Implicit Arguments starTransS [I T i j k].
+Arguments starTransS [I T i j k].
Definition RstarInv {A : Set} (rel : relation A) : A -> A -> Type := (flip (RstarSetProof (flip rel))).
diff --git a/test-suite/bugs/closed/2584.v b/test-suite/bugs/closed/2584.v
index ef2e4e355..b5a723b47 100644
--- a/test-suite/bugs/closed/2584.v
+++ b/test-suite/bugs/closed/2584.v
@@ -8,7 +8,7 @@ Inductive res (A: Type) : Type :=
| OK: A -> res A
| Error: err -> res A.
-Implicit Arguments Error [A].
+Arguments Error [A].
Set Printing Universes.
diff --git a/test-suite/bugs/closed/2667.v b/test-suite/bugs/closed/2667.v
index 0631e5358..0e6d0108c 100644
--- a/test-suite/bugs/closed/2667.v
+++ b/test-suite/bugs/closed/2667.v
@@ -1,11 +1,11 @@
-(* Check that extra arguments to Arguments Scope do not disturb use of *)
+(* Check that extra arguments to Arguments do not disturb use of *)
(* scopes in constructors *)
Inductive stmt : Type := Sskip: stmt | Scall : nat -> stmt.
Bind Scope Cminor with stmt.
(* extra argument is ok because of possible coercion to funclass *)
-Arguments Scope Scall [_ Cminor ].
+Arguments Scall _ _%Cminor : extra scopes.
(* extra argument is ok because of possible coercion to funclass *)
Fixpoint f (c: stmt) : Prop := match c with Scall _ => False | _ => False end.
diff --git a/test-suite/bugs/closed/2729.v b/test-suite/bugs/closed/2729.v
index 7929b8810..c9d65c12c 100644
--- a/test-suite/bugs/closed/2729.v
+++ b/test-suite/bugs/closed/2729.v
@@ -82,8 +82,8 @@ Inductive SequenceBase (pu : PatchUniverse)
(p : pu_type from mid)
(qs : SequenceBase pu mid to),
SequenceBase pu from to.
-Implicit Arguments Nil [pu cxt].
-Implicit Arguments Cons [pu from mid to].
+Arguments Nil [pu cxt].
+Arguments Cons [pu from mid to].
Program Fixpoint insertBase {pu : PatchUniverse}
{from mid to : NameSet}
diff --git a/test-suite/bugs/closed/2830.v b/test-suite/bugs/closed/2830.v
index bb607b785..07a5cf91a 100644
--- a/test-suite/bugs/closed/2830.v
+++ b/test-suite/bugs/closed/2830.v
@@ -49,9 +49,9 @@ Record ageable_facts (A:Type) (level: A -> nat) (age1:A -> option A) :=
; af_level2 : forall x y, age1 x = Some y -> level x = S (level y)
}.
-Implicit Arguments af_unage [[A] [level] [age1]].
-Implicit Arguments af_level1 [[A] [level] [age1]].
-Implicit Arguments af_level2 [[A] [level] [age1]].
+Arguments af_unage {A level age1}.
+Arguments af_level1 {A level age1}.
+Arguments af_level2 {A level age1}.
Class ageable (A:Type) := mkAgeable
{ level : A -> nat
@@ -77,7 +77,7 @@ Coercion app_pred : pred >-> Funclass.
Global Opaque pred.
Definition derives {A} `{ageable A} (P Q:pred A) := forall a:A, P a -> Q a.
-Implicit Arguments derives.
+Arguments derives : default implicits.
Program Definition andp {A} `{ageable A} (P Q:pred A) : pred A :=
fun a:A => P a /\ Q a.
@@ -170,7 +170,7 @@ Class Functor `(C:Category) `(D:Category) (im : C -> D) := {
fmap g ∘ fmap f ≈ fmap (g ∘ f)
}.
Coercion functor_im : Functor >-> Funclass.
-Implicit Arguments fmap [Object Hom C Object0 Hom0 D im a b].
+Arguments fmap [Object Hom C Object0 Hom0 D im] _ [a b].
Add Parametric Morphism `(C:Category) `(D:Category)
(Im:C->D) (F:Functor C D Im) (a b:C) : (@fmap _ _ C _ _ D Im F a b)
diff --git a/test-suite/bugs/closed/3068.v b/test-suite/bugs/closed/3068.v
index 79671ce93..9811733dc 100644
--- a/test-suite/bugs/closed/3068.v
+++ b/test-suite/bugs/closed/3068.v
@@ -33,7 +33,7 @@ Section Counted_list.
End Counted_list.
-Implicit Arguments counted_def_nth [A n].
+Arguments counted_def_nth [A n].
Section Finite_nat_set.
diff --git a/test-suite/bugs/closed/3513.v b/test-suite/bugs/closed/3513.v
index 1f0f3b0da..a1d0b9107 100644
--- a/test-suite/bugs/closed/3513.v
+++ b/test-suite/bugs/closed/3513.v
@@ -21,7 +21,7 @@ Section ILogic_Fun.
Local Instance ILFun_Ops : ILogicOps (@ILFunFrm T _ Frm _) := admit.
Definition ILFun_ILogic : ILogic (@ILFunFrm T _ Frm _) := admit.
End ILogic_Fun.
-Implicit Arguments ILFunFrm [[ILOps] [e]].
+Arguments ILFunFrm _ {e} _ {ILOps}.
Instance ILogicOps_Prop : ILogicOps Prop | 2 := {| lentails P Q := (P : Prop) -> Q;
ltrue := True;
land P Q := P /\ Q;
diff --git a/test-suite/bugs/closed/3647.v b/test-suite/bugs/closed/3647.v
index f5a22bd50..e91c004c7 100644
--- a/test-suite/bugs/closed/3647.v
+++ b/test-suite/bugs/closed/3647.v
@@ -26,7 +26,7 @@ Record morphism T T' `{e : type T} `{e' : type T'} :=
mkMorph {
morph :> T -> T';
morph_resp : setoid_resp morph}.
-Implicit Arguments mkMorph [T T' e e0 e' e1].
+Arguments mkMorph [T T' e0 e e1 e'].
Infix "-s>" := morphism (at level 45, right associativity).
Section Morphisms.
Context {S T U V} `{eS : type S} `{eT : type T} `{eU : type U} `{eV : type V}.
@@ -334,8 +334,8 @@ Section ILogic_Fun.
End ILogic_Fun.
-Implicit Arguments ILFunFrm [[ILOps] [e]].
-Implicit Arguments mkILFunFrm [T Frm ILOps].
+Arguments ILFunFrm _ {e} _ {ILOps}.
+Arguments mkILFunFrm [T] _ [Frm ILOps].
Program Definition ILFun_eq {T R} {ILOps: ILogicOps R} {ILogic: ILogic R} (P : T -> R) :
@ILFunFrm T _ R ILOps :=
diff --git a/test-suite/bugs/closed/3732.v b/test-suite/bugs/closed/3732.v
index 09f1149c2..13d62b8ff 100644
--- a/test-suite/bugs/closed/3732.v
+++ b/test-suite/bugs/closed/3732.v
@@ -16,7 +16,7 @@ Section machine.
| Inj : forall G, Prop -> propX G
| ExistsX : forall G A, propX (A :: G) -> propX G.
- Implicit Arguments Inj [G].
+ Arguments Inj [G].
Definition PropX := propX nil.
Fixpoint last (G : list Type) : Type.
diff --git a/test-suite/bugs/closed/4095.v b/test-suite/bugs/closed/4095.v
index 8d7dfbd49..bc9380f90 100644
--- a/test-suite/bugs/closed/4095.v
+++ b/test-suite/bugs/closed/4095.v
@@ -23,7 +23,7 @@ Section ILogic_Fun.
Local Instance ILFun_Ops : ILogicOps (@ILFunFrm T _ Frm _) := admit.
Definition ILFun_ILogic : ILogic (@ILFunFrm T _ Frm _) := admit.
End ILogic_Fun.
-Implicit Arguments ILFunFrm [[ILOps] [e]].
+Arguments ILFunFrm _ {e} _ {ILOps}.
Instance ILogicOps_Prop : ILogicOps Prop | 2 := {| lentails P Q := (P : Prop) -> Q;
ltrue := True;
land P Q := P /\ Q;
diff --git a/test-suite/bugs/closed/4865.v b/test-suite/bugs/closed/4865.v
index c5bf3289b..da4e53aab 100644
--- a/test-suite/bugs/closed/4865.v
+++ b/test-suite/bugs/closed/4865.v
@@ -48,5 +48,5 @@ Fail Check g 0 0 1. (* 2nd 0 in bool *)
Fixpoint arr n := match n with 0%nat => nat | S n => nat -> arr n end.
Fixpoint lam n : arr n := match n with 0%nat => 0%nat | S n => fun x => lam n end.
Notation "0" := true.
-Arguments Scope lam [nat_scope nat_scope].
+Arguments lam _%nat_scope _%nat_scope : extra scopes.
Check (lam 1 0).
diff --git a/test-suite/bugs/closed/6631.v b/test-suite/bugs/closed/6631.v
new file mode 100644
index 000000000..100dc13fc
--- /dev/null
+++ b/test-suite/bugs/closed/6631.v
@@ -0,0 +1,7 @@
+Require Import Coq.derive.Derive.
+
+Derive f SuchThat (f = 1 + 1) As feq.
+Proof.
+ transitivity 2; [refine (eq_refl 2)|].
+ transitivity 2.
+ 2:abstract exact (eq_refl 2).
diff --git a/test-suite/bugs/closed/7092.v b/test-suite/bugs/closed/7092.v
new file mode 100644
index 000000000..d90de8b93
--- /dev/null
+++ b/test-suite/bugs/closed/7092.v
@@ -0,0 +1,70 @@
+(* Examples matching fix/cofix in Ltac pattern-matching *)
+
+Goal True.
+lazymatch (eval cbv delta [Nat.add] in Nat.add) with
+| (fix F (n : nat) (v : ?A) {struct n} : @?P n v
+ := match n with
+ | O => @?O_case v
+ | S n' => @?S_case n' v F
+ end)
+ =>
+ unify A nat;
+ unify P (fun _ _ : nat => nat);
+ unify O_case (fun v : nat => v);
+ unify S_case (fun (p : nat) (m : nat) (add : nat -> nat -> nat)
+ => S (add p m))
+ end.
+Abort.
+
+Fixpoint f l n := match n with 0 => 0 | S n => g n (cons n l) end
+with g n l := match n with 0 => 1 | S n => f (cons 0 l) n end.
+
+Goal True.
+
+lazymatch (eval cbv delta [f] in f) with
+| fix myf (l : ?L) (n : ?N) {struct n} : nat :=
+ match n as _ with
+ | 0 => ?Z
+ | S n0 => @?S myf myg n0 l
+ end
+ with myg (n' : ?N') (l' : ?L') {struct n'} : nat :=
+ match n' as _ with
+ | 0 => ?Z'
+ | S n0' => @?S' myf myg n0' l'
+ end
+ for myf =>
+ unify L (list nat);
+ unify L' (list nat);
+ unify N nat;
+ unify N' nat;
+ unify Z 0;
+ unify Z' 1;
+ unify S (fun (f : L -> N -> nat) (g : N -> L -> nat) n l => g n (cons n l));
+ unify S' (fun (f : L -> N -> nat) (g : N -> L -> nat) (n:N) l => f (cons 0 l) n)
+end.
+
+Abort.
+
+CoInductive S1 := C1 : nat -> S2 -> S1 with S2 := C2 : bool -> S1 -> S2.
+
+CoFixpoint f' n l := C1 n (g' (cons n l) n n)
+with g' l n p := C2 true (f' (S n) l).
+
+Goal True.
+
+lazymatch (eval cbv delta [f'] in f') with
+| cofix myf (n : ?N) (l : ?L) : ?T := @?X n g l
+ with g (l' : ?L') (n' : ?N') (p' : ?N'') : ?T' := @?X' n' myf l'
+ for myf =>
+ unify L (list nat);
+ unify L' (list nat);
+ unify N nat;
+ unify N' nat;
+ unify N'' nat;
+ unify T S1;
+ unify T' S2;
+ unify X (fun n g l => C1 n (g (cons n l) n n));
+ unify X' (fun n f (l : list nat) => C2 true (f (S n) l))
+end.
+
+Abort.
diff --git a/test-suite/bugs/opened/2456.v b/test-suite/bugs/opened/2456.v
index 6cca5c9fb..5294adefd 100644
--- a/test-suite/bugs/opened/2456.v
+++ b/test-suite/bugs/opened/2456.v
@@ -6,7 +6,7 @@ Parameter Patch : nat -> nat -> Set.
Inductive Catch (from to : nat) : Type
:= MkCatch : forall (p : Patch from to),
Catch from to.
-Implicit Arguments MkCatch [from to].
+Arguments MkCatch [from to].
Inductive CatchCommute5
: forall {from mid1 mid2 to : nat},
diff --git a/test-suite/bugs/opened/3295.v b/test-suite/bugs/opened/3295.v
index 2a156e333..c09649de7 100644
--- a/test-suite/bugs/opened/3295.v
+++ b/test-suite/bugs/opened/3295.v
@@ -5,7 +5,7 @@ Class lops := lmk_ops {
weq: relation car
}.
-Implicit Arguments car [].
+Arguments car : clear implicits.
Coercion car: lops >-> Sortclass.
@@ -23,7 +23,7 @@ Class ops := mk_ops {
dot: forall n m p, mor n m -> mor m p -> mor n p
}.
Coercion mor: ops >-> Funclass.
-Implicit Arguments ob [].
+Arguments ob : clear implicits.
Instance dot_weq `{ops} n m p: Proper (weq ==> weq ==> weq) (dot n m p).
Proof.
diff --git a/test-suite/complexity/injection.v b/test-suite/complexity/injection.v
index 08f489d75..a76fa19d3 100644
--- a/test-suite/complexity/injection.v
+++ b/test-suite/complexity/injection.v
@@ -47,7 +47,7 @@ Parameter mkJoinmap : forall (key: Type) (t: Type) (j: joinable t),
joinmap key j.
Parameter ADMIT: forall p: Prop, p.
-Implicit Arguments ADMIT [p].
+Arguments ADMIT [p].
Module Share.
Parameter jb : joinable bool.
diff --git a/test-suite/coq-makefile/coqdoc1/run.sh b/test-suite/coq-makefile/coqdoc1/run.sh
index dc5a500db..88237815b 100755
--- a/test-suite/coq-makefile/coqdoc1/run.sh
+++ b/test-suite/coq-makefile/coqdoc1/run.sh
@@ -9,7 +9,15 @@ make html mlihtml
make install DSTROOT="$PWD/tmp"
make install-doc DSTROOT="$PWD/tmp"
#make debug
-(for d in `find tmp -name user-contrib` ; do pushd $d >/dev/null && find . && popd >/dev/null; done) | sort -u > actual
+
+# to learn about <(cmd) see https://www.gnu.org/software/bash/manual/html_node/Process-Substitution.html
+(
+ while IFS= read -r -d '' d
+ do
+ pushd "$d" >/dev/null && find . && popd >/dev/null
+ done < <(find tmp -name user-contrib -print0)
+) | sort -u > actual
+
sort -u > desired <<EOT
.
./test
diff --git a/test-suite/coq-makefile/coqdoc2/run.sh b/test-suite/coq-makefile/coqdoc2/run.sh
index dc5a500db..5811dd17e 100755
--- a/test-suite/coq-makefile/coqdoc2/run.sh
+++ b/test-suite/coq-makefile/coqdoc2/run.sh
@@ -9,7 +9,13 @@ make html mlihtml
make install DSTROOT="$PWD/tmp"
make install-doc DSTROOT="$PWD/tmp"
#make debug
-(for d in `find tmp -name user-contrib` ; do pushd $d >/dev/null && find . && popd >/dev/null; done) | sort -u > actual
+(
+ while IFS= read -r -d '' d
+ do
+ pushd "$d" >/dev/null && find . && popd >/dev/null
+ done < <(find tmp -name user-contrib -print0)
+) | sort -u > actual
+
sort -u > desired <<EOT
.
./test
diff --git a/test-suite/coq-makefile/findlib-package/run.sh b/test-suite/coq-makefile/findlib-package/run.sh
index 5b24df639..5cab400cc 100755
--- a/test-suite/coq-makefile/findlib-package/run.sh
+++ b/test-suite/coq-makefile/findlib-package/run.sh
@@ -7,7 +7,8 @@ export OCAMLPATH=$OCAMLPATH:$PWD/findlib
if which cygpath 2>/dev/null; then
# the only way I found to pass OCAMLPATH on win is to have it contain
# only one entry
- export OCAMLPATH=`cygpath -w $PWD/findlib`
+ OCAMLPATH=$(cygpath -w "$PWD"/findlib)
+ export OCAMLPATH
fi
make -C findlib/foo clean
coq_makefile -f _CoqProject -o Makefile
diff --git a/test-suite/coq-makefile/mlpack1/run.sh b/test-suite/coq-makefile/mlpack1/run.sh
index 03df9cf05..bbd2fc460 100755
--- a/test-suite/coq-makefile/mlpack1/run.sh
+++ b/test-suite/coq-makefile/mlpack1/run.sh
@@ -8,7 +8,7 @@ make
make html mlihtml
make install DSTROOT="$PWD/tmp"
#make debug
-(cd `find tmp -name user-contrib` && find .) | sort > actual
+(cd "$(find tmp -name user-contrib)" && find .) | sort > actual
sort > desired <<EOT
.
./test
diff --git a/test-suite/coq-makefile/mlpack2/run.sh b/test-suite/coq-makefile/mlpack2/run.sh
index 03df9cf05..bbd2fc460 100755
--- a/test-suite/coq-makefile/mlpack2/run.sh
+++ b/test-suite/coq-makefile/mlpack2/run.sh
@@ -8,7 +8,7 @@ make
make html mlihtml
make install DSTROOT="$PWD/tmp"
#make debug
-(cd `find tmp -name user-contrib` && find .) | sort > actual
+(cd "$(find tmp -name user-contrib)" && find .) | sort > actual
sort > desired <<EOT
.
./test
diff --git a/test-suite/coq-makefile/multiroot/run.sh b/test-suite/coq-makefile/multiroot/run.sh
index d3bb53106..45bf1481d 100755
--- a/test-suite/coq-makefile/multiroot/run.sh
+++ b/test-suite/coq-makefile/multiroot/run.sh
@@ -11,7 +11,12 @@ make html mlihtml
make install DSTROOT="$PWD/tmp"
make install-doc DSTROOT="$PWD/tmp"
#make debug
-(for d in `find tmp -name user-contrib` ; do pushd $d >/dev/null && find . && popd >/dev/null; done) | sort -u > actual
+(
+ while IFS= read -r -d '' d
+ do
+ pushd "$d" >/dev/null && find . && popd >/dev/null
+ done < <(find tmp -name user-contrib -print0)
+) | sort -u > actual
sort > desired <<EOT
.
./test
diff --git a/test-suite/coq-makefile/native1/run.sh b/test-suite/coq-makefile/native1/run.sh
index 89bafe9ad..8f9ab9a71 100755
--- a/test-suite/coq-makefile/native1/run.sh
+++ b/test-suite/coq-makefile/native1/run.sh
@@ -1,17 +1,17 @@
#!/usr/bin/env bash
-NATIVECOMP=`grep "let no_native_compiler = false" ../../../config/coq_config.ml`||true
-if [[ `which ocamlopt` && $NATIVECOMP ]]; then
+NATIVECOMP=$(grep "let no_native_compiler = false" ../../../config/coq_config.ml)||true
+if [[ $(which ocamlopt) && $NATIVECOMP ]]; then
. ../template/init.sh
-
+
coq_makefile -f _CoqProject -o Makefile
cat Makefile.conf
make
make html mlihtml
make install DSTROOT="$PWD/tmp"
#make debug
-(cd `find tmp -name user-contrib` && find .) | sort > actual
+(cd "$(find tmp -name user-contrib)" && find .) | sort > actual
sort > desired <<EOT
.
./test
diff --git a/test-suite/coq-makefile/plugin1/run.sh b/test-suite/coq-makefile/plugin1/run.sh
index 5433d9e92..1e2bd979b 100755
--- a/test-suite/coq-makefile/plugin1/run.sh
+++ b/test-suite/coq-makefile/plugin1/run.sh
@@ -9,7 +9,7 @@ make
make html mlihtml
make install DSTROOT="$PWD/tmp"
#make debug
-(cd `find tmp -name user-contrib` && find .) | sort > actual
+(cd "$(find tmp -name user-contrib)" && find .) | sort > actual
sort > desired <<EOT
.
./test
diff --git a/test-suite/coq-makefile/plugin2/run.sh b/test-suite/coq-makefile/plugin2/run.sh
index 5433d9e92..1e2bd979b 100755
--- a/test-suite/coq-makefile/plugin2/run.sh
+++ b/test-suite/coq-makefile/plugin2/run.sh
@@ -9,7 +9,7 @@ make
make html mlihtml
make install DSTROOT="$PWD/tmp"
#make debug
-(cd `find tmp -name user-contrib` && find .) | sort > actual
+(cd "$(find tmp -name user-contrib)" && find .) | sort > actual
sort > desired <<EOT
.
./test
diff --git a/test-suite/coq-makefile/plugin3/run.sh b/test-suite/coq-makefile/plugin3/run.sh
index 5433d9e92..1e2bd979b 100755
--- a/test-suite/coq-makefile/plugin3/run.sh
+++ b/test-suite/coq-makefile/plugin3/run.sh
@@ -9,7 +9,7 @@ make
make html mlihtml
make install DSTROOT="$PWD/tmp"
#make debug
-(cd `find tmp -name user-contrib` && find .) | sort > actual
+(cd "$(find tmp -name user-contrib)" && find .) | sort > actual
sort > desired <<EOT
.
./test
diff --git a/test-suite/coq-makefile/quick2vo/run.sh b/test-suite/coq-makefile/quick2vo/run.sh
index 9e681223b..dda51dd2e 100755
--- a/test-suite/coq-makefile/quick2vo/run.sh
+++ b/test-suite/coq-makefile/quick2vo/run.sh
@@ -1,11 +1,11 @@
#!/usr/bin/env bash
-a=`uname`
+a=$(uname)
. ../template/init.sh
coq_makefile -f _CoqProject -o Makefile
# vio2vo is broken on Windows (#6720)
-if [ "$a" = "Darwin" -o "$a" = "Linux" ]; then
+if [ "$a" = "Darwin" ] || [ "$a" = "Linux" ]; then
make quick2vo J=2
test -f theories/test.vo
make validate
diff --git a/test-suite/coq-makefile/template/init.sh b/test-suite/coq-makefile/template/init.sh
index e19d168cf..2e066d30d 100755
--- a/test-suite/coq-makefile/template/init.sh
+++ b/test-suite/coq-makefile/template/init.sh
@@ -1,10 +1,11 @@
+#!/bin/sh
. ../template/path-init.sh
rm -rf _test
mkdir _test
find . -maxdepth 1 -not -name . -not -name _test -exec cp -r '{}' -t _test ';'
-cd _test
+cd _test || exit 1
mkdir -p src
mkdir -p theories/sub
diff --git a/test-suite/coq-makefile/template/path-init.sh b/test-suite/coq-makefile/template/path-init.sh
index dd19ab2b1..c79b56652 100755
--- a/test-suite/coq-makefile/template/path-init.sh
+++ b/test-suite/coq-makefile/template/path-init.sh
@@ -1,3 +1,4 @@
+#!/bin/sh
set -e
set -o pipefail
diff --git a/test-suite/coq-makefile/timing/precomputed-time-tests/run.sh b/test-suite/coq-makefile/timing/precomputed-time-tests/run.sh
index a918cceb6..9f3b648aa 100755
--- a/test-suite/coq-makefile/timing/precomputed-time-tests/run.sh
+++ b/test-suite/coq-makefile/timing/precomputed-time-tests/run.sh
@@ -4,7 +4,8 @@ set -x
set -e
cd "$(dirname "${BASH_SOURCE[0]}")"
-export COQLIB="$(cd ../../../.. && pwd)"
+COQLIB="$(cd ../../../.. && pwd)"
+export COQLIB
-./001-correct-diff-sorting-order/run.sh || exit $?
-./002-single-file-sorting/run.sh || exit $?
+./001-correct-diff-sorting-order/run.sh
+./002-single-file-sorting/run.sh
diff --git a/test-suite/coq-makefile/timing/run.sh b/test-suite/coq-makefile/timing/run.sh
index aa6b0a9a4..11a04d5c2 100755
--- a/test-suite/coq-makefile/timing/run.sh
+++ b/test-suite/coq-makefile/timing/run.sh
@@ -40,7 +40,7 @@ INFINITY_REPLACEMENT="+.%" # assume that if the before time is zero, we expected
TO_SED_IN_BOTH=(
-e s"/${INFINITY}/${INFINITY_REPLACEMENT}/g" # Whether or not something shows up as ∞ depends on whether a time registers as 0.s or as 0.001s, so we can't rely on this being consistent
- -e s":|\s*N/A\s*$:| ${INFINITY_REPLACEMENT}:g" # Whether or not something shows up as N/A depends on whether a time registers as 0.s or as 0.001s, so we can't rely on this being consistent
+ -e s':|\s*N/A\s*$:| '"${INFINITY_REPLACEMENT}"':g' # Whether or not something shows up as N/A depends on whether a time registers as 0.s or as 0.001s, so we can't rely on this being consistent
-e s'/ *$//g' # the number of trailing spaces depends on how many digits percentages end up being; since this varies across runs, we remove trailing spaces
-e s'/[0-9]*\.[0-9]*//g' # the precise timing numbers vary, so we strip them out
-e s'/^-*$/------/g' # When none of the numbers get over 100 (or 1000, in per-file), the width of the table is different, so we normalize the number of dashes for table separators
@@ -58,16 +58,14 @@ TO_SED_IN_PER_LINE=(
-e s'/+/-/g' # some code lines don't really change, but this can show up as either -0m00.01s or +0m00.01s, so we need to normalize the signs
)
-for ext in "" .desired; do
- for file in time-of-build-before.log time-of-build-after.log time-of-build-both.log; do
- cat ${file}${ext} | grep -v 'warning: undefined variable' | sed "${TO_SED_IN_BOTH[@]}" "${TO_SED_IN_PER_FILE[@]}" > ${file}${ext}.processed
- done
-done
for file in time-of-build-before.log time-of-build-after.log time-of-build-both.log; do
- echo "cat $file"
- cat "$file"
- echo
- diff -u $file.desired.processed $file.processed || exit $?
+ for ext in "" .desired; do
+ grep -v 'warning: undefined variable' < ${file}${ext} | sed "${TO_SED_IN_BOTH[@]}" "${TO_SED_IN_PER_FILE[@]}" > ${file}${ext}.processed
+ done
+ echo "cat $file"
+ cat "$file"
+ echo
+ diff -u $file.desired.processed $file.processed || exit $?
done
cd ../per-file-before
@@ -92,13 +90,12 @@ echo "cat A.v.timing.diff"
cat A.v.timing.diff
echo
+file=A.v.timing.diff
+
for ext in "" .desired; do
- for file in A.v.timing.diff; do
- cat ${file}${ext} | sed "${TO_SED_IN_BOTH[@]}" "${TO_SED_IN_PER_LINE[@]}" | sort > ${file}${ext}.processed
- done
-done
-for file in A.v.timing.diff; do
- diff -u $file.desired.processed $file.processed || exit $?
+ sed "${TO_SED_IN_BOTH[@]}" "${TO_SED_IN_PER_LINE[@]}" < "${file}${ext}" | sort > "${file}${ext}.processed"
done
+diff -u "$file.desired.processed" "$file.processed" || exit $?
+
exit 0
diff --git a/test-suite/coq-makefile/uninstall1/run.sh b/test-suite/coq-makefile/uninstall1/run.sh
index 5354f794f..fc95d84b9 100755
--- a/test-suite/coq-makefile/uninstall1/run.sh
+++ b/test-suite/coq-makefile/uninstall1/run.sh
@@ -11,7 +11,12 @@ make install-doc DSTROOT="$PWD/tmp"
make uninstall DSTROOT="$PWD/tmp"
make uninstall-doc DSTROOT="$PWD/tmp"
#make debug
-(for d in `find tmp -name user-contrib` ; do pushd $d >/dev/null && find . && popd >/dev/null; done) | sort -u > actual
+(
+ while IFS= read -r -d '' d
+ do
+ pushd "$d" >/dev/null && find . && popd >/dev/null
+ done < <(find tmp -name user-contrib -print0)
+) | sort -u > actual
sort -u > desired <<EOT
.
EOT
diff --git a/test-suite/coq-makefile/uninstall2/run.sh b/test-suite/coq-makefile/uninstall2/run.sh
index 5354f794f..fc95d84b9 100755
--- a/test-suite/coq-makefile/uninstall2/run.sh
+++ b/test-suite/coq-makefile/uninstall2/run.sh
@@ -11,7 +11,12 @@ make install-doc DSTROOT="$PWD/tmp"
make uninstall DSTROOT="$PWD/tmp"
make uninstall-doc DSTROOT="$PWD/tmp"
#make debug
-(for d in `find tmp -name user-contrib` ; do pushd $d >/dev/null && find . && popd >/dev/null; done) | sort -u > actual
+(
+ while IFS= read -r -d '' d
+ do
+ pushd "$d" >/dev/null && find . && popd >/dev/null
+ done < <(find tmp -name user-contrib -print0)
+) | sort -u > actual
sort -u > desired <<EOT
.
EOT
diff --git a/test-suite/coq-makefile/vio2vo/run.sh b/test-suite/coq-makefile/vio2vo/run.sh
index 85656da41..e555d62f3 100755
--- a/test-suite/coq-makefile/vio2vo/run.sh
+++ b/test-suite/coq-makefile/vio2vo/run.sh
@@ -1,12 +1,12 @@
#!/usr/bin/env bash
-a=`uname`
+a=$(uname)
. ../template/init.sh
coq_makefile -f _CoqProject -o Makefile
make quick
# vio2vo is broken on Windows (#6720)
-if [ "$a" = "Darwin" -o "$a" = "Linux" ]; then
+if [ "$a" = "Darwin" ] || [ "$a" = "Linux" ]; then
make vio2vo J=2
test -f theories/test.vo
make validate
diff --git a/test-suite/failure/check.v b/test-suite/failure/check.v
index a148ebe8e..0ef4b417a 100644
--- a/test-suite/failure/check.v
+++ b/test-suite/failure/check.v
@@ -1,3 +1,3 @@
-Implicit Arguments eq [A].
+Arguments eq [A].
Fail Check (bool = true).
diff --git a/test-suite/ide/bug7088.fake b/test-suite/ide/bug7088.fake
new file mode 100644
index 000000000..e2a2aa52a
--- /dev/null
+++ b/test-suite/ide/bug7088.fake
@@ -0,0 +1,13 @@
+ADD { Arguments id T x : rename. }
+ADD { Lemma foo : True. }
+ADD here { Proof. }
+ADD { exact 3. }
+ADD { Qed. }
+WAIT
+EDIT_AT here
+ADD { Arguments id FOO BAR : rename. }
+ADD { exact I. }
+ADD { Qed. }
+ADD { Arguments id T x : assert. }
+JOIN
+
diff --git a/test-suite/ide/load.fake b/test-suite/ide/load.fake
new file mode 100644
index 000000000..f6a7ef4dc
--- /dev/null
+++ b/test-suite/ide/load.fake
@@ -0,0 +1,11 @@
+ADD revert { Load "output/load/Load_noproof.v". }
+ADD { Load "output/load/Load_proof.v". }
+ADD { Fail Load "output/load/Load_openproof.v". }
+WAIT
+QUERY { Check f. }
+QUERY { Check u. }
+EDIT_AT revert
+QUERY { Check f. }
+QUERY { Fail Check u. }
+JOIN
+
diff --git a/test-suite/misc/deps-checksum.sh b/test-suite/misc/deps-checksum.sh
index e07612b84..a15a8fbee 100755
--- a/test-suite/misc/deps-checksum.sh
+++ b/test-suite/misc/deps-checksum.sh
@@ -1,3 +1,4 @@
+#!/bin/sh
rm -f misc/deps/A/*.vo misc/deps/B/*.vo
$coqc -R misc/deps/A A misc/deps/A/A.v
$coqc -R misc/deps/B A misc/deps/B/A.v
diff --git a/test-suite/misc/deps-order.sh b/test-suite/misc/deps-order.sh
index 299f49469..6bb2ba2da 100755
--- a/test-suite/misc/deps-order.sh
+++ b/test-suite/misc/deps-order.sh
@@ -1,17 +1,18 @@
+#!/bin/sh
# Check that both coqdep and coqtop/coqc supports -R
# Check that both coqdep and coqtop/coqc takes the later -R
# See bugs 2242, 2337, 2339
rm -f misc/deps/lib/*.vo misc/deps/client/*.vo
-tmpoutput=`mktemp /tmp/coqcheck.XXXXXX`
-$coqdep -R misc/deps/lib lib -R misc/deps/client client misc/deps/client/bar.v 2>&1 | head -n 1 > $tmpoutput
-diff -u --strip-trailing-cr misc/deps/deps.out $tmpoutput 2>&1
+tmpoutput=$(mktemp /tmp/coqcheck.XXXXXX)
+$coqdep -R misc/deps/lib lib -R misc/deps/client client misc/deps/client/bar.v 2>&1 | head -n 1 > "$tmpoutput"
+diff -u --strip-trailing-cr misc/deps/deps.out "$tmpoutput" 2>&1
R=$?
times
$coqc -R misc/deps/lib lib misc/deps/lib/foo.v 2>&1
$coqc -R misc/deps/lib lib -R misc/deps/client client misc/deps/client/foo.v 2>&1
$coqtop -R misc/deps/lib lib -R misc/deps/client client -load-vernac-source misc/deps/client/bar.v 2>&1
S=$?
-if [ $R = 0 -a $S = 0 ]; then
+if [ $R = 0 ] && [ $S = 0 ]; then
printf "coqdep and coqtop agree\n"
exit 0
else
diff --git a/test-suite/misc/deps-utf8.sh b/test-suite/misc/deps-utf8.sh
index 13e264c09..acb45b229 100755
--- a/test-suite/misc/deps-utf8.sh
+++ b/test-suite/misc/deps-utf8.sh
@@ -1,15 +1,16 @@
+#!/bin/sh
# Check reading directories matching non pure ascii idents
# See bug #5715 (utf-8 working on macos X and linux)
# Windows is still not compliant
-a=`uname`
-if [ "$a" = "Darwin" -o "$a" = "Linux" ]; then
+a=$(uname)
+if [ "$a" = "Darwin" ] || [ "$a" = "Linux" ]; then
rm -f misc/deps/théorèmes/*.v
-tmpoutput=`mktemp /tmp/coqcheck.XXXXXX`
+tmpoutput=$(mktemp /tmp/coqcheck.XXXXXX)
$coqc -R misc/deps AlphaBêta misc/deps/αβ/γδ.v
R=$?
$coqtop -R misc/deps AlphaBêta -load-vernac-source misc/deps/αβ/εζ.v
S=$?
-if [ $R = 0 -a $S = 0 ]; then
+if [ $R = 0 ] && [ $S = 0 ]; then
exit 0
else
exit 1
diff --git a/test-suite/misc/exitstatus.sh b/test-suite/misc/exitstatus.sh
index cea1de862..a327f4248 100755
--- a/test-suite/misc/exitstatus.sh
+++ b/test-suite/misc/exitstatus.sh
@@ -1,7 +1,8 @@
+#!/bin/sh
$coqtop -load-vernac-source misc/exitstatus/illtyped.v
N=$?
$coqc misc/exitstatus/illtyped.v
P=$?
-printf "On ill-typed input, coqtop returned $N.\n"
-printf "On ill-typed input, coqc returned $P.\n"
-if [ $N = 1 -a $P = 1 ]; then exit 0; else exit 1; fi
+printf "On ill-typed input, coqtop returned %s.\n" "$N"
+printf "On ill-typed input, coqc returned %s.\n" "$P"
+if [ $N = 1 ] && [ $P = 1 ]; then exit 0; else exit 1; fi
diff --git a/test-suite/misc/printers.sh b/test-suite/misc/printers.sh
index 28e7dc362..ef3f056d8 100755
--- a/test-suite/misc/printers.sh
+++ b/test-suite/misc/printers.sh
@@ -1,3 +1,2 @@
-printf "Drop. #use\"include\";; #quit;;\n" | $coqtopbyte 2>&1 | egrep "Error|Unbound"
-if [ $? = 0 ]; then exit 1; else exit 0; fi
-
+#!/bin/sh
+if printf "Drop. #use\"include\";; #quit;;\n" | $coqtopbyte 2>&1 | grep -E "Error|Unbound" ; then exit 1; else exit 0; fi
diff --git a/test-suite/misc/universes.sh b/test-suite/misc/universes.sh
index d87a86035..ef61ca624 100755
--- a/test-suite/misc/universes.sh
+++ b/test-suite/misc/universes.sh
@@ -1,8 +1,9 @@
+#!/bin/sh
# Sort universes for the whole standard library
EXPECTED_UNIVERSES=4 # Prop is not counted
$coqc -R misc/universes Universes misc/universes/all_stdlib 2>&1
$coqc -R misc/universes Universes misc/universes/universes 2>&1
mv universes.txt misc/universes
-N=`awk '{print $3}' misc/universes/universes.txt | sort -u | wc -l`
-printf "Found %s/%s universes\n" $N $EXPECTED_UNIVERSES
+N=$(awk '{print $3}' misc/universes/universes.txt | sort -u | wc -l)
+printf "Found %s/%s universes\n" "$N" "$EXPECTED_UNIVERSES"
if [ "$N" -eq $EXPECTED_UNIVERSES ]; then exit 0; else exit 1; fi
diff --git a/test-suite/modules/PO.v b/test-suite/modules/PO.v
index 8ba8525c6..be3310491 100644
--- a/test-suite/modules/PO.v
+++ b/test-suite/modules/PO.v
@@ -1,8 +1,8 @@
Set Implicit Arguments.
Unset Strict Implicit.
-Implicit Arguments fst.
-Implicit Arguments snd.
+Arguments fst : default implicits.
+Arguments snd : default implicits.
Module Type PO.
Parameter T : Set.
diff --git a/test-suite/modules/Przyklad.v b/test-suite/modules/Przyklad.v
index 7214287a6..ece1b47b4 100644
--- a/test-suite/modules/Przyklad.v
+++ b/test-suite/modules/Przyklad.v
@@ -1,7 +1,7 @@
Definition ifte (T : Set) (A B : Prop) (s : {A} + {B})
(th el : T) := if s then th else el.
-Implicit Arguments ifte.
+Arguments ifte : default implicits.
Lemma Reflexivity_provable :
forall (A : Set) (a : A) (s : {a = a} + {a <> a}),
diff --git a/test-suite/output/Errors.out b/test-suite/output/Errors.out
index 38d055b28..24180c455 100644
--- a/test-suite/output/Errors.out
+++ b/test-suite/output/Errors.out
@@ -8,3 +8,11 @@ Unable to unify "nat" with "True".
The command has indeed failed with message:
Ltac call to "instantiate ( (ident) := (lglob) )" failed.
Instance is not well-typed in the environment of ?x.
+The command has indeed failed with message:
+Cannot infer the domain of the type of f.
+The command has indeed failed with message:
+Cannot infer the domain of the implicit parameter A of id whose type is
+"Type".
+The command has indeed failed with message:
+Cannot infer the codomain of the type of f in environment:
+x : nat
diff --git a/test-suite/output/Errors.v b/test-suite/output/Errors.v
index 424d24801..c9b509134 100644
--- a/test-suite/output/Errors.v
+++ b/test-suite/output/Errors.v
@@ -25,3 +25,9 @@ eexists ?[x].
destruct H1 as [x1 H1].
Fail instantiate (x:=projT1 x1).
Abort.
+
+(* Test some messages for non solvable evars *)
+
+Fail Goal forall a f, f a = 0.
+Fail Goal forall f x, id f x = 0.
+Fail Goal forall f P, P (f 0).
diff --git a/test-suite/output/Projections.out b/test-suite/output/Projections.out
new file mode 100644
index 000000000..e9c28faf1
--- /dev/null
+++ b/test-suite/output/Projections.out
@@ -0,0 +1,2 @@
+fun S : store => S.(store_funcs)
+ : store -> host_func
diff --git a/test-suite/output/Projections.v b/test-suite/output/Projections.v
new file mode 100644
index 000000000..098a518dc
--- /dev/null
+++ b/test-suite/output/Projections.v
@@ -0,0 +1,11 @@
+
+Set Printing Projections.
+
+Class HostFunction := host_func : Type.
+
+Section store.
+ Context `{HostFunction}.
+ Record store := { store_funcs : host_func }.
+End store.
+
+Check (fun (S:@store nat) => S.(store_funcs)).
diff --git a/test-suite/output/bug5778.out b/test-suite/output/bug5778.out
index 91ceb1b58..d6056c509 100644
--- a/test-suite/output/bug5778.out
+++ b/test-suite/output/bug5778.out
@@ -1,4 +1,4 @@
The command has indeed failed with message:
-In nested Ltac calls to "c", "abs" and "abstract b ltac:(())", last call
-failed.
+In nested Ltac calls to "c", "abs", "abstract b ltac:(())",
+"b", "a", "pose (I : I)" and "(I : I)", last term evaluation failed.
The term "I" has type "True" which should be Set, Prop or Type.
diff --git a/test-suite/output/bug6404.out b/test-suite/output/bug6404.out
new file mode 100644
index 000000000..05464755f
--- /dev/null
+++ b/test-suite/output/bug6404.out
@@ -0,0 +1,4 @@
+The command has indeed failed with message:
+In nested Ltac calls to "c", "abs", "transparent_abstract (tactic3)",
+"b", "a", "pose (I : I)" and "(I : I)", last term evaluation failed.
+The term "I" has type "True" which should be Set, Prop or Type.
diff --git a/test-suite/output/bug6404.v b/test-suite/output/bug6404.v
new file mode 100644
index 000000000..bbe6b1a00
--- /dev/null
+++ b/test-suite/output/bug6404.v
@@ -0,0 +1,7 @@
+Ltac a _ := pose (I : I).
+Ltac b _ := a ().
+Ltac abs _ := transparent_abstract b ().
+Ltac c _ := abs ().
+Goal True.
+ Fail c ().
+Abort.
diff --git a/test-suite/output/ssr_clear.out b/test-suite/output/ssr_clear.out
new file mode 100644
index 000000000..151595406
--- /dev/null
+++ b/test-suite/output/ssr_clear.out
@@ -0,0 +1,3 @@
+The command has indeed failed with message:
+Ltac call to "move (ssrmovearg) (ssrclauses)" failed.
+No assumption is named NO_SUCH_NAME
diff --git a/test-suite/output/ssr_clear.v b/test-suite/output/ssr_clear.v
new file mode 100644
index 000000000..573ec47e0
--- /dev/null
+++ b/test-suite/output/ssr_clear.v
@@ -0,0 +1,6 @@
+Require Import ssreflect.
+
+Example foo : True -> True.
+Proof.
+Fail move=> {NO_SUCH_NAME}.
+Abort.
diff --git a/test-suite/prerequisite/make_local.v b/test-suite/prerequisite/make_local.v
index 8700a6c4e..6d9117c05 100644
--- a/test-suite/prerequisite/make_local.v
+++ b/test-suite/prerequisite/make_local.v
@@ -2,8 +2,7 @@
Definition f (A:Type) (a:A) := a.
-Local Arguments Scope f [type_scope type_scope].
-Local Implicit Arguments f [A].
+Local Arguments f [A]%type_scope _%type_scope.
(* Used in ImportedCoercion.v to test the locality flag *)
diff --git a/test-suite/success/AdvancedTypeClasses.v b/test-suite/success/AdvancedTypeClasses.v
index b4efa7edc..d0aa5c857 100644
--- a/test-suite/success/AdvancedTypeClasses.v
+++ b/test-suite/success/AdvancedTypeClasses.v
@@ -28,8 +28,8 @@ Class interp_pair (abs : Type) :=
{ repr : term;
link: abs = interp repr }.
-Implicit Arguments repr [[interp_pair]].
-Implicit Arguments link [[interp_pair]].
+Arguments repr _ {interp_pair}.
+Arguments link _ {interp_pair}.
Lemma prod_interp `{interp_pair a, interp_pair b} : a * b = interp (Prod (repr a) (repr b)).
simpl. intros. rewrite <- link. rewrite <- (link b). reflexivity.
diff --git a/test-suite/success/ImplicitArguments.v b/test-suite/success/ImplicitArguments.v
index 921433cad..9a19b595e 100644
--- a/test-suite/success/ImplicitArguments.v
+++ b/test-suite/success/ImplicitArguments.v
@@ -2,7 +2,7 @@ Inductive vector {A : Type} : nat -> Type :=
| vnil : vector 0
| vcons : A -> forall {n'}, vector n' -> vector (S n').
-Implicit Arguments vector [].
+Arguments vector A : clear implicits.
Require Import Coq.Program.Program.
diff --git a/test-suite/success/Inductive.v b/test-suite/success/Inductive.v
index 5b1482fd5..f07c0191f 100644
--- a/test-suite/success/Inductive.v
+++ b/test-suite/success/Inductive.v
@@ -73,7 +73,7 @@ CoInductive LList (A : Set) : Set :=
| LNil : LList A
| LCons : A -> LList A -> LList A.
-Implicit Arguments LNil [A].
+Arguments LNil [A].
Inductive Finite (A : Set) : LList A -> Prop :=
| Finite_LNil : Finite LNil
diff --git a/test-suite/success/Inversion.v b/test-suite/success/Inversion.v
index 45c71615f..ca8da3948 100644
--- a/test-suite/success/Inversion.v
+++ b/test-suite/success/Inversion.v
@@ -31,7 +31,7 @@ Inductive in_extension (I : Set) (r : rule I) : extension I -> Type :=
| in_first : forall e, in_extension r (add_rule r e)
| in_rest : forall e r', in_extension r e -> in_extension r (add_rule r' e).
-Implicit Arguments NL [I].
+Arguments NL [I].
Inductive super_extension (I : Set) (e : extension I) :
extension I -> Type :=
diff --git a/test-suite/success/RecTutorial.v b/test-suite/success/RecTutorial.v
index 841940492..29350d620 100644
--- a/test-suite/success/RecTutorial.v
+++ b/test-suite/success/RecTutorial.v
@@ -991,10 +991,10 @@ Proof.
Qed.
-Implicit Arguments Vector.cons [A n].
-Implicit Arguments Vector.nil [A].
-Implicit Arguments Vector.hd [A n].
-Implicit Arguments Vector.tl [A n].
+Arguments Vector.cons [A] _ [n].
+Arguments Vector.nil [A].
+Arguments Vector.hd [A n].
+Arguments Vector.tl [A n].
Definition Vid : forall (A : Type)(n:nat), Vector.t A n -> Vector.t A n.
Proof.
@@ -1064,7 +1064,7 @@ Fixpoint vector_nth (A:Set)(n:nat)(p:nat)(v:Vector.t A p){struct v}
| S n', Vector.cons _ v' => vector_nth A n' _ v'
end.
-Implicit Arguments vector_nth [A p].
+Arguments vector_nth [A] _ [p].
Lemma nth_bitwise : forall (n:nat) (v1 v2: Vector.t bool n) i a b,
@@ -1159,7 +1159,7 @@ infiniteproof map_iterate'.
Qed.
-Implicit Arguments LNil [A].
+Arguments LNil [A].
Lemma Lnil_not_Lcons : forall (A:Set)(a:A)(l:LList A),
LNil <> (LCons a l).
diff --git a/test-suite/success/Record.v b/test-suite/success/Record.v
index 6f27c1d36..18ebcd638 100644
--- a/test-suite/success/Record.v
+++ b/test-suite/success/Record.v
@@ -5,7 +5,7 @@ Require Import Program.
Require Import List.
Record vector {A : Type} {n : nat} := { vec_list : list A ; vec_len : length vec_list = n }.
-Implicit Arguments vector [].
+Arguments vector : clear implicits.
Coercion vec_list : vector >-> list.
diff --git a/test-suite/success/Scopes.v b/test-suite/success/Scopes.v
index ca3746716..2da630633 100644
--- a/test-suite/success/Scopes.v
+++ b/test-suite/success/Scopes.v
@@ -11,7 +11,7 @@ Check (A.opp 3).
Record B := { f :> Z -> Z }.
Variable a:B.
-Arguments Scope a [Z_scope].
+Arguments a _%Z_scope : extra scopes.
Check a 0.
(* Check that casts activate scopes if ever possible *)
diff --git a/test-suite/success/Typeclasses.v b/test-suite/success/Typeclasses.v
index cd6eac35c..400479ae8 100644
--- a/test-suite/success/Typeclasses.v
+++ b/test-suite/success/Typeclasses.v
@@ -128,8 +128,8 @@ Record Monad {m : Type -> Type} := {
Print Visibility.
Print unit.
-Implicit Arguments unit [[m] [m0] [α]].
-Implicit Arguments Monad [].
+Arguments unit {m m0 α}.
+Arguments Monad : clear implicits.
Notation "'return' t" := (unit t).
(* Test correct handling of existentials and defined fields. *)
diff --git a/test-suite/success/apply.v b/test-suite/success/apply.v
index 02e043bc3..b287b5fac 100644
--- a/test-suite/success/apply.v
+++ b/test-suite/success/apply.v
@@ -39,7 +39,7 @@ Qed.
(* Check apply/eapply distinction in presence of open terms *)
Parameter h : forall x y z : nat, x = z -> x = y.
-Implicit Arguments h [[x] [y]].
+Arguments h {x y}.
Goal 1 = 0 -> True.
intro H.
apply h in H || exact I.
diff --git a/test-suite/success/dependentind.v b/test-suite/success/dependentind.v
index f5bb884d2..55ae54ca0 100644
--- a/test-suite/success/dependentind.v
+++ b/test-suite/success/dependentind.v
@@ -42,7 +42,7 @@ Inductive ctx : Type :=
Bind Scope context_scope with ctx.
Delimit Scope context_scope with ctx.
-Arguments Scope snoc [context_scope].
+Arguments snoc _%context_scope.
Notation " Γ , τ " := (snoc Γ τ) (at level 25, τ at next level, left associativity) : context_scope.
diff --git a/test-suite/success/evars.v b/test-suite/success/evars.v
index 627794832..5b13f35d5 100644
--- a/test-suite/success/evars.v
+++ b/test-suite/success/evars.v
@@ -386,7 +386,7 @@ Record iffT (X Y:Type) : Type := mkIff { iffLR : X->Y; iffRL : Y->X }.
Record tri (R:Type->Type->Type) (S:Type->Type->Type) (T:Type->Type->Type) := mkTri {
tri0 : forall a b c, R a b -> S a c -> T b c
}.
-Implicit Arguments mkTri [R S T].
+Arguments mkTri [R S T].
Definition tri_iffT : tri iffT iffT iffT :=
(mkTri
(fun X0 X1 X2 E01 E02 =>
diff --git a/test-suite/success/implicit.v b/test-suite/success/implicit.v
index a0981311b..23853890d 100644
--- a/test-suite/success/implicit.v
+++ b/test-suite/success/implicit.v
@@ -33,11 +33,11 @@ Definition eq1 := fun (A:Type) (x y:A) => x=y.
Definition eq2 := fun (A:Type) (x y:A) => x=y.
Definition eq3 := fun (A:Type) (x y:A) => x=y.
-Implicit Arguments op' [].
-Global Implicit Arguments op'' [].
+Arguments op' : clear implicits.
+Global Arguments op'' : clear implicits.
-Implicit Arguments eq2 [].
-Global Implicit Arguments eq3 [].
+Arguments eq2 : clear implicits.
+Global Arguments eq3 : clear implicits.
Check (op 0 0).
Check (op' nat 0 0).
@@ -89,14 +89,14 @@ Fixpoint plus n m {struct n} :=
(* Check multiple implicit arguments signatures *)
-Implicit Arguments eq_refl [[A] [x]] [[A]].
+Arguments eq_refl {A x}, {A}.
Check eq_refl : 0 = 0.
(* Check that notations preserve implicit (since 8.3) *)
Parameter p : forall A, A -> forall n, n = 0 -> True.
-Implicit Arguments p [A n].
+Arguments p [A] _ [n].
Notation Q := (p 0).
Check Q eq_refl.
diff --git a/tools/gallina-syntax.el b/tools/gallina-syntax.el
index 662762b08..7c59fb6ae 100644
--- a/tools/gallina-syntax.el
+++ b/tools/gallina-syntax.el
@@ -432,7 +432,6 @@
("Add Semi Ring" nil "Add Semi Ring #." t "Add\\s-+Semi\\s-+Ring")
("Add Setoid" nil "Add Setoid #." t "Add\\s-+Setoid")
("Admit Obligations" "oblsadmit" "Admit Obligations." nil "Admit\\s-+Obligations")
- ("Arguments Scope" "argsc" "Arguments Scope @{id} [ @{_} ]" t "Arguments\\s-+Scope")
("Bind Scope" "bndsc" "Bind Scope @{scope} with @{type}" t "Bind\\s-+Scope")
("Canonical Structure" nil "Canonical Structure #." t "Canonical\\s-+Structure")
("Cd" nil "Cd #." nil "Cd")
diff --git a/toplevel/coqloop.ml b/toplevel/coqloop.ml
index 64d839f18..d0989cfcc 100644
--- a/toplevel/coqloop.ml
+++ b/toplevel/coqloop.ml
@@ -325,6 +325,24 @@ let cproof p1 p2 =
let drop_last_doc = ref None
+(* We try to behave better when goal printing raises an exception
+ [usually Ctrl-C]
+
+ This is mostly a hack as we should protect printing in a more
+ generic way, but that'll do for now *)
+let top_goal_print oldp newp =
+ try
+ let proof_changed = not (Option.equal cproof oldp newp) in
+ let print_goals = not !Flags.quiet &&
+ proof_changed && Proof_global.there_are_pending_proofs () in
+ if print_goals then Feedback.msg_notice (pr_open_cur_subgoals ())
+ with
+ | exn ->
+ let (e, info) = CErrors.push exn in
+ let loc = Loc.get_loc info in
+ let msg = CErrors.iprint (e, info) in
+ TopErr.print_error_for_buffer ?loc Feedback.Error msg top_buffer
+
(* Careful to keep this loop tail-rec *)
let rec vernac_loop ~state =
let open CAst in
@@ -338,6 +356,13 @@ let rec vernac_loop ~state =
try
let input = top_buffer.tokens in
match read_sentence ~state input with
+ | {v=VernacBacktrack(bid,_,_)} ->
+ let bid = Stateid.of_int bid in
+ let doc, res = Stm.edit_at ~doc:state.doc bid in
+ assert (res = `NewTip);
+ let state = { state with doc; sid = bid } in
+ vernac_loop ~state
+
| {v=VernacQuit} ->
exit 0
| {v=VernacDrop} ->
@@ -346,10 +371,7 @@ let rec vernac_loop ~state =
else (Feedback.msg_warning (str "There is no ML toplevel."); vernac_loop ~state)
| {v=VernacControl c; loc} ->
let nstate = Vernac.process_expr ~state (make ?loc c) in
- let proof_changed = not (Option.equal cproof nstate.proof state.proof) in
- let print_goals = not !Flags.quiet &&
- proof_changed && Proof_global.there_are_pending_proofs () in
- if print_goals then Feedback.msg_notice (pr_open_cur_subgoals ());
+ top_goal_print state.proof nstate.proof;
vernac_loop ~state:nstate
with
| Stm.End_of_input ->
diff --git a/toplevel/coqtop.ml b/toplevel/coqtop.ml
index a08cfa9f4..0dabed6b7 100644
--- a/toplevel/coqtop.ml
+++ b/toplevel/coqtop.ml
@@ -315,16 +315,24 @@ let check_vio_tasks opts =
(* vio files *)
let schedule_vio opts =
- (* We must add update the loadpath here as the scheduling process
- happens outside of the STM *)
- let iload_path = build_load_path opts in
- List.iter Mltop.add_coq_path iload_path;
-
if opts.vio_checking then
Vio_checking.schedule_vio_checking opts.vio_files_j opts.vio_files
else
Vio_checking.schedule_vio_compilation opts.vio_files_j opts.vio_files
+let do_vio opts =
+ (* We must initialize the loadpath here as the vio scheduling
+ process happens outside of the STM *)
+ if opts.vio_files <> [] || opts.vio_tasks <> [] then
+ let iload_path = build_load_path opts in
+ List.iter Mltop.add_coq_path iload_path;
+
+ (* Vio compile pass *)
+ if opts.vio_files <> [] then schedule_vio opts;
+ (* Vio task pass *)
+ if opts.vio_tasks <> [] then check_vio_tasks opts
+
+
(******************************************************************************)
(* Color Options *)
(******************************************************************************)
@@ -483,10 +491,9 @@ let init_toplevel arglist =
end else begin
try
compile_files opts;
- (* Vio compile pass *)
- if opts.vio_files <> [] then schedule_vio opts;
- (* Vio task pass *)
- check_vio_tasks opts;
+ (* Careful this will modify the load-path and state so after
+ this point some stuff may not be safe anymore. *)
+ do_vio opts;
(* Allow the user to output an arbitrary state *)
outputstate opts;
None, opts
diff --git a/toplevel/g_toplevel.ml4 b/toplevel/g_toplevel.ml4
index 7526f3071..d5d558b9b 100644
--- a/toplevel/g_toplevel.ml4
+++ b/toplevel/g_toplevel.ml4
@@ -9,10 +9,12 @@
(************************************************************************)
open Pcoq
+open Pcoq.Prim
open Vernacexpr
(* Vernaculars specific to the toplevel *)
type vernac_toplevel =
+ | VernacBacktrack of int * int * int
| VernacDrop
| VernacQuit
| VernacControl of vernac_control
@@ -31,6 +33,8 @@ GEXTEND Gram
vernac_toplevel: FIRST
[ [ IDENT "Drop"; "." -> CAst.make VernacDrop
| IDENT "Quit"; "." -> CAst.make VernacQuit
+ | IDENT "Backtrack"; n = natural ; m = natural ; p = natural; "." ->
+ CAst.make (VernacBacktrack (n,m,p))
| cmd = main_entry ->
match cmd with
| None -> raise Stm.End_of_input
diff --git a/vernac/himsg.ml b/vernac/himsg.ml
index 249e7893c..698ee4703 100644
--- a/vernac/himsg.ml
+++ b/vernac/himsg.ml
@@ -559,15 +559,21 @@ let rec explain_evar_kind env sigma evk ty = function
| Evar_kinds.VarInstance id ->
strbrk "an instance of type " ++ ty ++
str " for the variable " ++ Id.print id
- | Evar_kinds.SubEvar evk' ->
+ | Evar_kinds.SubEvar (where,evk') ->
let evi = Evd.find sigma evk' in
let pc = match evi.evar_body with
| Evar_defined c -> pr_leconstr_env env sigma (EConstr.of_constr c)
| Evar_empty -> assert false in
let ty' = EConstr.of_constr evi.evar_concl in
+ (match where with
+ | Some Evar_kinds.Body -> str "the body of "
+ | Some Evar_kinds.Domain -> str "the domain of "
+ | Some Evar_kinds.Codomain -> str "the codomain of "
+ | None ->
pr_existential_key sigma evk ++ str " of type " ++ ty ++
str " in the partial instance " ++ pc ++
- str " found for " ++ explain_evar_kind env sigma evk'
+ str " found for ") ++
+ explain_evar_kind env sigma evk'
(pr_leconstr_env env sigma ty') (snd evi.evar_source)
let explain_typeclass_resolution env sigma evi k =
diff --git a/vernac/vernacentries.ml b/vernac/vernacentries.ml
index 9ff4e3302..b44c7cccb 100644
--- a/vernac/vernacentries.ml
+++ b/vernac/vernacentries.ml
@@ -534,17 +534,14 @@ let vernac_assumption ~atts discharge kind l nl =
if not status then Feedback.feedback Feedback.AddedAxiom
let should_treat_as_cumulative cum poly =
- if poly then
- match cum with
- | GlobalCumulativity | LocalCumulativity -> true
- | GlobalNonCumulativity | LocalNonCumulativity -> false
- else
- match cum with
- | GlobalCumulativity | GlobalNonCumulativity -> false
- | LocalCumulativity ->
- user_err Pp.(str "The Cumulative prefix can only be used in a polymorphic context.")
- | LocalNonCumulativity ->
- user_err Pp.(str "The NonCumulative prefix can only be used in a polymorphic context.")
+ match cum with
+ | Some VernacCumulative ->
+ if poly then true
+ else user_err Pp.(str "The Cumulative prefix can only be used in a polymorphic context.")
+ | Some VernacNonCumulative ->
+ if poly then false
+ else user_err Pp.(str "The NonCumulative prefix can only be used in a polymorphic context.")
+ | None -> poly && Flags.is_polymorphic_inductive_cumulativity ()
let vernac_record cum k poly finite struc binders sort nameopt cfs =
let is_cumulative = should_treat_as_cumulative cum poly in
@@ -565,7 +562,6 @@ let vernac_record cum k poly finite struc binders sort nameopt cfs =
indicates whether the type is inductive, co-inductive or
neither. *)
let vernac_inductive ~atts cum lo finite indl =
- let is_cumulative = should_treat_as_cumulative cum atts.polymorphic in
if Dumpglob.dump () then
List.iter (fun (((coe,(lid,_)), _, _, _, cstrs), _) ->
match cstrs with
@@ -602,6 +598,7 @@ let vernac_inductive ~atts cum lo finite indl =
| _ -> user_err Pp.(str "Cannot handle mutually (co)inductive records.")
in
let indl = List.map unpack indl in
+ let is_cumulative = should_treat_as_cumulative cum atts.polymorphic in
ComInductive.do_mutual_inductive indl is_cumulative atts.polymorphic lo finite
let vernac_fixpoint ~atts discharge l =
@@ -2008,7 +2005,6 @@ let interp ?proof ~atts ~st c =
| VernacRestart -> CErrors.user_err (str "Restart cannot be used through the Load command")
| VernacUndo _ -> CErrors.user_err (str "Undo cannot be used through the Load command")
| VernacUndoTo _ -> CErrors.user_err (str "UndoTo cannot be used through the Load command")
- | VernacBacktrack _ -> CErrors.user_err (str "Backtrack cannot be used through the Load command")
(* Resetting *)
| VernacResetName _ -> anomaly (str "VernacResetName not handled by Stm.")
@@ -2025,7 +2021,6 @@ let interp ?proof ~atts ~st c =
| VernacDelimiters (sc,lr) -> vernac_delimiters sc lr
| VernacBindScope (sc,rl) -> vernac_bind_scope sc rl
| VernacOpenCloseScope (b, s) -> vernac_open_close_scope ~atts (b,s)
- | VernacArgumentsScope (qid,scl) -> vernac_arguments_scope ~atts qid scl
| VernacInfix (mv,qid,sc) -> vernac_infix ~atts mv qid sc
| VernacNotation (c,infpl,sc) ->
vernac_notation ~atts c infpl sc
@@ -2099,8 +2094,6 @@ let interp ?proof ~atts ~st c =
vernac_hints ~atts dbnames hints
| VernacSyntacticDefinition (id,c,b) ->
vernac_syntactic_definition ~atts id c b
- | VernacDeclareImplicits (qid,l) ->
- vernac_declare_implicits ~atts qid l
| VernacArguments (qid, args, more_implicits, nargs, flags) ->
vernac_arguments ~atts qid args more_implicits nargs flags
| VernacReserve bl -> vernac_reserve bl
@@ -2168,7 +2161,7 @@ let check_vernac_supports_locality c l =
| VernacDeclareMLModule _
| VernacCreateHintDb _ | VernacRemoveHints _ | VernacHints _
| VernacSyntacticDefinition _
- | VernacArgumentsScope _ | VernacDeclareImplicits _ | VernacArguments _
+ | VernacArguments _
| VernacGeneralizable _
| VernacSetOpacity _ | VernacSetStrategy _
| VernacSetOption _ | VernacUnsetOption _
diff --git a/vernac/vernacprop.ml b/vernac/vernacprop.ml
index a837b77a3..0fdd2faaf 100644
--- a/vernac/vernacprop.ml
+++ b/vernac/vernacprop.ml
@@ -31,7 +31,6 @@ let rec has_Fail = function
let is_navigation_vernac_expr = function
| VernacResetInitial
| VernacResetName _
- | VernacBacktrack _
| VernacBackTo _
| VernacBack _ -> true
| _ -> false