Skip to content

Commit 1c02abf

Browse files
Create (stdlib) syntax for Coq stanza
Fixes #6163 Signed-off-by: Lasse Blaauwbroek <lasse@blaauwbroek.eu>
1 parent 9b722bb commit 1c02abf

File tree

24 files changed

+120
-5
lines changed

24 files changed

+120
-5
lines changed

CHANGES.md

+4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@
6363

6464
- The test suite for Coq now requires Coq >= 8.16 due to changes in the
6565
plugin loading mechanism upstream (which now uses findlib).
66+
67+
- Starting with Coq build language 0.6, theories can be built without importing
68+
Coq's standard library by including `(stdlib no)`.
69+
(#6165 #6164, fixes #6163, @ejgallego @Alizter @LasseBlaauwbroek)
6670

6771
3.4.1 (26-07-2022)
6872
------------------

doc/coq.rst

+10-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ version<coq-lang>` in the :ref:`dune-project` file. For example, adding
3030

3131
.. code:: scheme
3232
33-
(using coq 0.4)
33+
(using coq 0.6)
3434
3535
to a :ref:`dune-project` file enables using the ``coq.theory`` stanza and other
3636
``coq.*`` stanzas. See the :ref:`Dune Coq language<coq-lang>` section for more
@@ -53,6 +53,7 @@ stanza:
5353
(modules <ordered_set_lang>)
5454
(plugins <ocaml_plugins>)
5555
(flags <coq_flags>)
56+
(stdlib <stdlib_included>)
5657
(mode <coq_native_mode>)
5758
(theories <coq_theories>))
5859
@@ -98,6 +99,11 @@ The semantics of the fields are:
9899
is taken from the value set in the ``(coq (flags <flags>))`` field in ``env``
99100
profile. See :ref:`dune-env` for more information.
100101

102+
- ``<stdlib_included>`` can either be ``yes`` or ``no``, currently defaulting to
103+
``yes``. When set to ``no``, Coq's standard library won't be visible from this
104+
theory, which means the ``Coq`` prefix won't be bound, and ``Coq.Init.Prelude``
105+
won't be imported by default.
106+
101107
- The path to the installed locations of the ``<ocaml_plugins>`` is passed to
102108
``coqdep`` and ``coqc`` using Coq's ``-I`` flag. This allows a Coq theory to
103109
depend on OCaml plugins.
@@ -235,6 +241,8 @@ The supported Coq language versions (not the version of Coq) are:
235241
- ``0.3``: Support for ``(mode native)`` requires Coq >= 8.10 (and Dune >= 2.9
236242
for Coq >= 8.14).
237243
- ``0.4``: Support for interproject composition of theories.
244+
- ``0.5``: ``(libraries ...)`` field deprecated in favor of ``(plugins ...)`` field.
245+
- ``0.6``: Support for ``(stdlib no)``.
238246

239247
.. _coq-lang-1.0:
240248

@@ -267,7 +275,7 @@ process by using the ``coq.extraction`` stanza:
267275
- ``(extracted_modules <names>)`` is an exhaustive list of OCaml modules
268276
extracted.
269277

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

273281
The extracted sources can then be used in ``executable`` or ``library`` stanzas

src/dune_rules/coq_stanza.ml

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ let coq_syntax =
2525
; ((0, 3), `Since (2, 8))
2626
; ((0, 4), `Since (3, 3))
2727
; ((0, 5), `Since (3, 4))
28+
; ((0, 6), `Since (3, 5))
2829
]
2930

3031
module Buildable = struct
@@ -63,7 +64,8 @@ module Buildable = struct
6364
(Dune_lang.Syntax.since coq_syntax (0, 3) >>> Coq_mode.decode))
6465
and+ use_stdlib =
6566
field ~default:true "stdlib"
66-
Dune_lang.Decoder.(enum [ ("yes", true); ("no", false) ])
67+
(Dune_lang.Syntax.since coq_syntax (0, 6)
68+
>>> enum [ ("yes", true); ("no", false) ])
6769
and+ libraries =
6870
field "libraries" ~default:[]
6971
(Dune_sexp.Syntax.deprecated_in coq_syntax (0, 5)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Print LoadPath.
2+
Fail Print Prelude.
3+
From Coq Require Import Prelude.
4+
Print Prelude.
5+
Require Import mytheory.
6+
Check Hello.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(coq.theory
2+
(name A)
3+
(stdlib no)
4+
(theories Coq))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(lang dune 3.5)
2+
(using coq 0.6)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Print LoadPath.
2+
Print Prelude.
3+
Require Import mytheory.
4+
Check Hello.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(coq.theory
2+
(name B)
3+
(stdlib yes)
4+
(theories Coq))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(lang dune 3.5)
2+
(using coq 0.6)

test/blackbox-tests/test-cases/coq/compose-boot-nostdlib.t/Coq/Coq.opam

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Unset Elimination Schemes.
2+
Inductive BootType := boot | type.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(coq.theory
2+
(name Coq)
3+
(package Coq)
4+
(boot))
5+
6+
(include_subdirs qualified)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(lang dune 3.3)
2+
(using coq 0.4)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
Inductive Hello := World | Bye.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(lang dune 3.3)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Testing composition of theories accross a dune workspace with a boot library and
2+
importing stdlib enabled or disabled.
3+
4+
Composing a library A depending on Coq but having `(stdlib no)`:
5+
6+
$ dune build A
7+
Logical Path / Physical path:
8+
A
9+
$TESTCASE_ROOT/_build/default/A
10+
Coq
11+
$TESTCASE_ROOT/_build/default/Coq
12+
Coq.Init
13+
$TESTCASE_ROOT/_build/default/Coq/Init
14+
Module
15+
Prelude
16+
:= Struct Inductive BootType : Set := boot : BootType | type : BootType. End
17+
18+
Hello
19+
: Set
20+
21+
Composing a library B depending on Coq but having `(stdlib yes)`:
22+
23+
$ dune build B
24+
Logical Path / Physical path:
25+
B
26+
$TESTCASE_ROOT/_build/default/B
27+
Coq
28+
$TESTCASE_ROOT/_build/default/Coq
29+
Coq.Init
30+
$TESTCASE_ROOT/_build/default/Coq/Init
31+
Module
32+
Prelude
33+
:= Struct Inductive BootType : Set := boot : BootType | type : BootType. End
34+
35+
Hello
36+
: Set

test/blackbox-tests/test-cases/coq/coqtop-root.t/run.t

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ This test is currently broken due to the workspace resolution being faulty #5899
1414
1 | (coq.theory
1515
2 | (name foo))
1616
Error: 'coq.theory' is available only when coq is enabled in the dune-project
17-
file. You must enable it using (using coq 0.5) in your dune-project file.
17+
file. You must enable it using (using coq 0.6) in your dune-project file.
1818
[1]

test/blackbox-tests/test-cases/coq/github3624.t

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ that the error message is good when the coq extension is not enabled.
1616
1 | (coq.theory
1717
2 | (name foo))
1818
Error: 'coq.theory' is available only when coq is enabled in the dune-project
19-
file. You must enable it using (using coq 0.5) in your dune-project file.
19+
file. You must enable it using (using coq 0.6) in your dune-project file.
2020
[1]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Definition mynat := nat.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(coq.theory
2+
(name basic)
3+
(package no-stdlib)
4+
(stdlib no)
5+
(synopsis "Test Coq library"))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(lang dune 3.5)
2+
3+
(using coq 0.6)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
From Coq Require Import Prelude.

test/blackbox-tests/test-cases/coq/no-stdlib.t/no-stdlib.opam

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Test that when `(stdlib no)` is provided, the standard library is not bound to `Coq`
2+
and the prelude is not imported
3+
4+
$ dune build --display=short foo.vo
5+
coqdep foo.v.d
6+
*** Warning: in file foo.v, library Prelude is required from root Coq and has not been found in the loadpath!
7+
coqc foo.{glob,vo} (exit 1)
8+
File "./foo.v", line 1, characters 0-32:
9+
Error: Cannot find a physical path bound to logical path
10+
Prelude with prefix Coq.
11+
12+
[1]
13+
14+
$ dune build --display=short bar.vo
15+
coqdep bar.v.d
16+
coqc bar.{glob,vo} (exit 1)
17+
File "./bar.v", line 1, characters 20-23:
18+
Error: The reference nat was not found in the current environment.
19+
20+
[1]

0 commit comments

Comments
 (0)