Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create (stdlib) syntax for Coq stanza #6164

Merged
merged 2 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,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 build 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
12 changes: 10 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,8 @@ 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.5``: ``(libraries ...)`` field deprecated in favor of ``(plugins ...)`` field.
- ``0.6``: Support for ``(stdlib no)``.

.. _coq-lang-1.0:

Expand Down Expand Up @@ -267,7 +275,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
4 changes: 3 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,8 @@ 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, 6)
>>> 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 across a Dune workspace with a boot library and
importing ``stdlib`` enabled or disabled.

Composing 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 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Error: 'coq.theory' is available only when coq is enabled in the dune-project
Error: 'coq.theory' is available only when Coq is enabled in the ``dune-project``

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is automatically generated output.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But also technically correct since it is talking about the coq mode which is enabled in the dune-project file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! Thanks for clarifying. Perhaps both coq and dune-project in monospace then?

Copy link
Collaborator

@Alizter Alizter Oct 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it appears in a command line error message, demarking it monospace would waste space.

Copy link
Contributor Author

@LasseBlaauwbroek LasseBlaauwbroek Oct 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@christinerose These are Cram (I/O) tests. The test system runs specified commands, and the output of the commands is compared against what is committed here. Hence, you cannot just change this output because then the tests would fail. If you would want to change the wording of the messages, you'd have to do it where the I/O is actually performed.

(As an additional note, I'd say that the required standard of copy-editing in tests is a bit lower than one would expect for, say, documentation.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood. Please feel free to discard anything that's not useful. I was tagged to review, so I did my thing. 😄 .... Do you need me to go back and "approve" it before you can move forward?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the PR has already been merged and completed. Thanks for your comments @christinerose.

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
file. You must enable it using (using coq 0.6) in your dune-project file.
file. You must enable it using (using ``coq 0.6``) in your ``dune-project`` file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Autogenerated output.

[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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Error: 'coq.theory' is available only when coq is enabled in the dune-project
Error: 'coq.theory' is available only when Coq is enabled in the ``dune-project``

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Autogenerated output.

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
file. You must enable it using (using coq 0.6) in your dune-project file.
file. You must enable it using (using ``coq 0.6``) in your ``dune-project`` file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Autogenerated output.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Autogenerated from where? Like by odoc?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the command line error message of Dune.

[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.
20 changes: 20 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,20 @@
Test that when `(stdlib no)` is provided, the standard library is not bound to `Coq`
and the prelude is not imported

$ dune build --display=short foo.vo
coqdep foo.v.d
*** Warning: in file foo.v, library Prelude is required from root Coq and has not been found in the loadpath!
coqc foo.{glob,vo} (exit 1)
File "./foo.v", line 1, characters 0-32:
Error: Cannot find a physical path bound to logical path
Prelude with prefix Coq.

[1]

$ dune build --display=short bar.vo
coqdep bar.v.d
coqc bar.{glob,vo} (exit 1)
File "./bar.v", line 1, characters 20-23:
Error: The reference nat was not found in the current environment.

[1]