Skip to content

Commit

Permalink
Create (stdlib) syntax for Coq stanza
Browse files Browse the repository at this point in the history
Fixes ocaml#6163

Signed-off-by: Lasse Blaauwbroek <[email protected]>
  • Loading branch information
LasseBlaauwbroek committed Oct 3, 2022
1 parent 9b722bb commit 5868645
Show file tree
Hide file tree
Showing 24 changed files with 111 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@

- The test suite for Coq now requires Coq >= 8.16 due to changes in the
plugin loading mechanism upstream (which now uses findlib).

- Starting with Coq language 0.6, theories can be built without importing
Coq's standard library by including `(stdlib no)`.
(#6165 #6164, fixes #6163, @ejgallego @Alizter @LasseBlaauwbroek)

3.4.1 (26-07-2022)
------------------
Expand Down
11 changes: 9 additions & 2 deletions doc/coq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ version<coq-lang>` in the :ref:`dune-project` file. For example, adding

.. code:: scheme
(using coq 0.4)
(using coq 0.6)
to a :ref:`dune-project` file enables using the ``coq.theory`` stanza and other
``coq.*`` stanzas. See the :ref:`Dune Coq language<coq-lang>` section for more
Expand All @@ -53,6 +53,7 @@ stanza:
(modules <ordered_set_lang>)
(plugins <ocaml_plugins>)
(flags <coq_flags>)
(stdlib <stdlib_included>)
(mode <coq_native_mode>)
(theories <coq_theories>))
Expand Down Expand Up @@ -98,6 +99,11 @@ The semantics of the fields are:
is taken from the value set in the ``(coq (flags <flags>))`` field in ``env``
profile. See :ref:`dune-env` for more information.

- ``<stdlib_included>`` can either be ``yes`` or ``no``, currently defaulting to
``yes``. When set to ``no``, Coq's standard library won't be visible from this
theory, which means the ``Coq`` prefix won't be bound, and ``Coq.Init.Prelude``
won't be imported by default.

- The path to the installed locations of the ``<ocaml_plugins>`` is passed to
``coqdep`` and ``coqc`` using Coq's ``-I`` flag. This allows a Coq theory to
depend on OCaml plugins.
Expand Down Expand Up @@ -235,6 +241,7 @@ The supported Coq language versions (not the version of Coq) are:
- ``0.3``: Support for ``(mode native)`` requires Coq >= 8.10 (and Dune >= 2.9
for Coq >= 8.14).
- ``0.4``: Support for interproject composition of theories.
- ``0.6``: Support for ``(stdlib no)``.

.. _coq-lang-1.0:

Expand Down Expand Up @@ -267,7 +274,7 @@ process by using the ``coq.extraction`` stanza:
- ``(extracted_modules <names>)`` is an exhaustive list of OCaml modules
extracted.

- ``<optional-fields>`` are ``flags``, ``theories``, and ``plugins``. All of
- ``<optional-fields>`` are ``flags``, ``stdlib``, ``theories``, and ``plugins``. All of
these fields have the same meaning as in the ``coq.theory`` stanza.

The extracted sources can then be used in ``executable`` or ``library`` stanzas
Expand Down
3 changes: 2 additions & 1 deletion src/dune_rules/coq_stanza.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ let coq_syntax =
; ((0, 3), `Since (2, 8))
; ((0, 4), `Since (3, 3))
; ((0, 5), `Since (3, 4))
; ((0, 6), `Since (3, 5))
]

module Buildable = struct
Expand Down Expand Up @@ -63,7 +64,7 @@ module Buildable = struct
(Dune_lang.Syntax.since coq_syntax (0, 3) >>> Coq_mode.decode))
and+ use_stdlib =
field ~default:true "stdlib"
Dune_lang.Decoder.(enum [ ("yes", true); ("no", false) ])
(Dune_lang.Syntax.since coq_syntax (0, 3) >>> enum [ ("yes", true); ("no", false) ])
and+ libraries =
field "libraries" ~default:[]
(Dune_sexp.Syntax.deprecated_in coq_syntax (0, 5)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Print LoadPath.
Fail Print Prelude.
From Coq Require Import Prelude.
Print Prelude.
Require Import mytheory.
Check Hello.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(coq.theory
(name A)
(stdlib no)
(theories Coq))
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(lang dune 3.5)
(using coq 0.6)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Print LoadPath.
Print Prelude.
Require Import mytheory.
Check Hello.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(coq.theory
(name B)
(stdlib yes)
(theories Coq))
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(lang dune 3.5)
(using coq 0.6)
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Unset Elimination Schemes.
Inductive BootType := boot | type.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(coq.theory
(name Coq)
(package Coq)
(boot))

(include_subdirs qualified)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(lang dune 3.3)
(using coq 0.4)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

Inductive Hello := World | Bye.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(lang dune 3.3)
36 changes: 36 additions & 0 deletions test/blackbox-tests/test-cases/coq/compose-boot-nostdlib.t/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Testing composition of theories accross a dune workspace with a boot library and
importing stdlib enabled or disabled.

Composing a library A depending on Coq but having `(stdlib no)`:

$ dune build A
Logical Path / Physical path:
A
$TESTCASE_ROOT/_build/default/A
Coq
$TESTCASE_ROOT/_build/default/Coq
Coq.Init
$TESTCASE_ROOT/_build/default/Coq/Init
Module
Prelude
:= Struct Inductive BootType : Set := boot : BootType | type : BootType. End

Hello
: Set

Composing a library B depending on Coq but having `(stdlib yes)`:

$ dune build B
Logical Path / Physical path:
B
$TESTCASE_ROOT/_build/default/B
Coq
$TESTCASE_ROOT/_build/default/Coq
Coq.Init
$TESTCASE_ROOT/_build/default/Coq/Init
Module
Prelude
:= Struct Inductive BootType : Set := boot : BootType | type : BootType. End

Hello
: Set
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/coq/coqtop-root.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ This test is currently broken due to the workspace resolution being faulty #5899
1 | (coq.theory
2 | (name foo))
Error: 'coq.theory' is available only when coq is enabled in the dune-project
file. You must enable it using (using coq 0.5) in your dune-project file.
file. You must enable it using (using coq 0.6) in your dune-project file.
[1]
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/coq/github3624.t
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ that the error message is good when the coq extension is not enabled.
1 | (coq.theory
2 | (name foo))
Error: 'coq.theory' is available only when coq is enabled in the dune-project
file. You must enable it using (using coq 0.5) in your dune-project file.
file. You must enable it using (using coq 0.6) in your dune-project file.
[1]
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/coq/no-stdlib.t/bar.v
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Definition mynat := nat.
5 changes: 5 additions & 0 deletions test/blackbox-tests/test-cases/coq/no-stdlib.t/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(coq.theory
(name basic)
(package no-stdlib)
(stdlib no)
(synopsis "Test Coq library"))
3 changes: 3 additions & 0 deletions test/blackbox-tests/test-cases/coq/no-stdlib.t/dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(lang dune 3.5)

(using coq 0.6)
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/coq/no-stdlib.t/foo.v
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
From Coq Require Import Prelude.
Empty file.
13 changes: 13 additions & 0 deletions test/blackbox-tests/test-cases/coq/no-stdlib.t/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Test that when `(stdlib no)` is provided, the standard library is not bound to `Coq`
and the prelude is not imported

$ dune build
*** Warning: in file foo.v, library Prelude is required from root Coq and has not been found in the loadpath!
File "./bar.v", line 1, characters 20-23:
Error: The reference nat was not found in the current environment.

File "./foo.v", line 1, characters 0-32:
Error: Cannot find a physical path bound to logical path
Prelude with prefix Coq.

[1]

0 comments on commit 5868645

Please sign in to comment.