Skip to content

Commit 5868645

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

File tree

24 files changed

+111
-5
lines changed

24 files changed

+111
-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 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

+9-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,7 @@ 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.6``: Support for ``(stdlib no)``.
238245

239246
.. _coq-lang-1.0:
240247

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

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

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

src/dune_rules/coq_stanza.ml

+2-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,7 @@ 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, 3) >>> enum [ ("yes", true); ("no", false) ])
6768
and+ libraries =
6869
field "libraries" ~default:[]
6970
(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,13 @@
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
5+
*** Warning: in file foo.v, library Prelude is required from root Coq and has not been found in the loadpath!
6+
File "./bar.v", line 1, characters 20-23:
7+
Error: The reference nat was not found in the current environment.
8+
9+
File "./foo.v", line 1, characters 0-32:
10+
Error: Cannot find a physical path bound to logical path
11+
Prelude with prefix Coq.
12+
13+
[1]

0 commit comments

Comments
 (0)