Skip to content

Commit 489536d

Browse files
Merge pull request #207 from impermeable/coq-master-update
Coq master update
2 parents 48f6e56 + 4a29d57 commit 489536d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2810
-1537
lines changed

.devcontainer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM rocq/rocq-prover:dev-ocaml-4.14.2-flambda
22

33
RUN opam update; \
4-
opam install coq-lsp.0.2.2+dev -y; \
4+
opam install coq-lsp.0.2.3+dev -y; \
55
opam install ocaml-lsp-server -y

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "coq-waterproof dev container for Coq dev",
2+
"name": "coq-waterproof dev container",
33

44
"build": {
55
"dockerfile": "Dockerfile"

.github/workflows/doc.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ on:
44

55
push:
66
branches: [ "main" ]
7+
pull_request:
8+
branches: [ "main" ]
79

810
workflow_dispatch:
911

@@ -51,7 +53,7 @@ jobs:
5153
deploy:
5254
name: deploy
5355
needs: build
54-
56+
if: github.ref == 'refs/heads/main'
5557
permissions:
5658
pages: write
5759
id-token: write
@@ -64,4 +66,4 @@ jobs:
6466
steps:
6567
- name: Deploy documentation to GitHub Pages
6668
id: deployment
67-
uses: actions/deploy-pages@v4
69+
uses: actions/deploy-pages@v4

CHANGES.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Change log for the coq-waterproof library
22

3+
## Version 3.1.0+9.1
4+
5+
- No longer throw an error if there are unused lemmas (this speeds up automation when using `By ... it holds that ...`)
6+
- Remove parentheses in suggestions
7+
- Fix issue with keywords
8+
- Allow for multiple reasons in `By ...`-clause
9+
- Add framework for registering definitions and alternative characterizations
10+
- Add Expand All functionality to Help
11+
- Simplify ffi mechanism
12+
313
## Version 3.0.0+9.0
414

515
- Remove need for parentheses in many places

Developer-instructions.md

Lines changed: 22 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ port install opam
2525
```
2626

2727
### Creating the desired opam environment: simplified version
28-
When we develop, we need to be aware of the version of Coq we develop for.
28+
When we develop, we need to be aware of the version of Rocq (formerly Coq) we develop for.
2929
Most development is done based off the main branch, and then the following setup will suffice.
3030

3131
```
3232
opam init
3333
eval $(opam env)
34-
opam install coq-lsp.0.2.2+8.20
34+
opam install coq-lsp.0.2.3+9.1
3535
opam install ocaml-lsp-server
3636
```
37-
replacing 8.20 with the desired version of Coq, or more generally, replacing
38-
0.2.2+8.20 by the desired version of coq-lsp.
37+
replacing 9.1 with the desired version of Rocq, or more generally, replacing
38+
0.2.3+9.1 by the desired version of coq-lsp.
3939

40-
### Creating the desired opam environment: advanced version for supporting multiple versions of Coq
40+
### Creating the desired opam environment: advanced version for supporting multiple versions of Rocq
4141

4242
When we bring changes into different versions of Coq (for instance for the branches 8.18, 8.19...)
4343
it is convenient to have multiple opam environement, i.e. switches, available. If you prefer to start
@@ -51,10 +51,10 @@ opam switch create your_preferred_switch_name ocaml-base-compiler.4.14.1
5151
```
5252
Next you can install the background libraries again
5353
```
54-
opam install coq-lsp.0.2.2+8.20
54+
opam install coq-lsp.0.2.3+9.0
5555
opam install ocaml-lsp-server
5656
```
57-
again replacing 8.20 with the desired version of Coq
57+
again replacing 9.0 with the desired version of Coq
5858

5959
### Caveat: locally compiling the coq-master branch
6060

@@ -139,110 +139,18 @@ If you use VSCode, we recommend installing the [OCaml Platform](https://marketpl
139139

140140
One can make Ocaml functions available for use in Ltac2 by using the
141141
foreign function interface (ffi). For now, we gather all such
142-
definitions in `Wp_ffi.ml`.
143-
144-
Suppose one has an Ocaml function `f : a -> b -> c -> d` where `a, b, c, d` are types, and one would like to make this function available as an Ltac2 tactic.
145-
146-
### Make a tactic
147-
148-
First of all, only tactics can pass the ffi, so one needs to convert `f` into
149-
something that outputs a tactic. An element of type `'a` can be converted into an `'a`-valued tactic, ie.e. an element of type `'a tactic` by using `tclUNIT`:
150-
151-
Consider this example:
152-
```
153-
let my_unit_tactic : unit tactic = tclUNIT ()
154-
```
155-
156-
```
157-
let my_bool_tactic : bool tactic = tclUNIT true
158-
```
159-
160-
Hence, we can convert `f` into something that outputs a tactic by
161-
162-
```
163-
let my_f_tactic : a -> b -> c -> d tactic =
164-
fun input_a input_b input_c -> tclUNIT (f input_a input_b input_c)
165-
```
166-
167-
### Make a `valexpr` tactic
168-
169-
Datatypes in Ocaml and in Ltac2 need to be translated to each other
170-
by using an intermediate datatype: namely `valexpr`. This also means that
171-
only `valexpr`-valued tactics can pass the ffi.
172-
Luckily, for many types there are already conversion functions available from
173-
and to `valexpr`, such as `of_bool`, `to_bool` and `of_unit`, `to_unit`.
174-
In general, these conversions are captured in elements of the type `'a repr`:
175-
an element `c` of `'a repr` has a conversion `repr_to c : valexpr -> 'a` and
176-
a conversion `repr_of c : 'a -> valexpr`. For more information, one can look
177-
at Coq's `tac2ffi.ml` file.
178-
179-
We can then use the strategy from the previous section to make a valexpr tactic.
180-
```
181-
let my_valexpr_tactic_from_unit : valexpr tactic = tclUNIT (of_unit ())
182-
```
183-
It is common to use the `@@` operator to put everything that comes after it
184-
in parentheses, so one could also write
185-
```
186-
let my_valexpr_tactic_from_unit : valexpr tactic = tclUNIT @@ of_unit ()
187-
```
188-
Similarly, here is a `valexpr` tactic created from a `bool`
189-
```
190-
let my_valexpr_tactic_from_bool : valexpr tactic = tclUNIT @@ of_bool ()
191-
```
192-
193-
### Make the function available for the ffi
194-
195-
Considering an example of a function `f : a -> b -> c -> d`, and given
196-
`a_repr : a repr`, `b_repr : b repr`, `c_repr : c repr`, `d_repr : d repr`, we can
197-
make this function available for the ffi by
198-
199-
```
200-
let () = define3 "my_f_external" a_repr b_repr c_repr @@
201-
fun input_a, input_b, input_c ->
202-
tclUNIT (repr_of d (f input_a input_b input_c))
203-
```
204-
205-
The `3` is chosen because `f` has `3` inputs.
206-
207-
Note that with some monad magic, the same definition can also be
208-
achieved by
209-
```
210-
let () = define3 "my_f_external" a_repr b_repr c_repr @@
211-
fun input_a input_b input_c ->
212-
tclUNIT @@ f input_a input_b input_c >>= fun z -> tclUNIT @@ repr_of d z
213-
```
214-
Here "my_f_external" is the name by which you can refer to this function
215-
from Ltac2. Any name can be chosen, and it won't be the name that you use
216-
to call the function from Ltac2. Representations for many different datatypes
217-
can be found in Coq's `tac2ffi.ml`. For many datatypes, the respresentation
218-
of that datatype is called the same: `bool` is for instance the name for `bool repr`, so that the following would be valid code
219-
220-
```
221-
let () = define1 "my_bool_tactic" bool @@
222-
fun input -> tclUNIT input >>= fun z -> tclUNIT @@ of_bool z
223-
```
224-
or yet another option
225-
```
226-
let () = define1 "my_bool_tactic" bool @@
227-
fun input -> tclUNIT input >>= fun z -> tclUNIT @@ repr_of bool z
228-
```
229-
230-
Note that in Coq v8.19, a new file `tac2externals.ml` was created, which
231-
can be used to handle a lot of the above issues.
232-
233-
### Make the function available from Ltac2
234-
235-
From a `.v` file, one can simply load
236-
```
237-
Require Import Waterproof.Waterproof.
238-
```
239-
and then define (in Coq v8.17) (given the caveat below)
240-
```
241-
Ltac2 @ external my_f_in_ltac2 : a_ltac2 -> b_ltac2 -> c_ltac2 -> d_ltac2 := "coq-waterproof" "my_f_external".
242-
```
243-
where `a_ltac2`, ... `d_ltac2` are the corresponding types on the
244-
Ltac2 side of the types `a`, ..., `d`. The caveat is that there aren't always
245-
corresponding types on the Ltac2 side of Ocaml types.
246-
247-
Note that the syntax is a bit different in different versions of Coq.
248-
Please see the code for examples.
142+
definitions in `wp_ffi.ml`.
143+
144+
Note that with Coq v8.19, using the ffi got a lot easier.
145+
It may be possible to just look at the examples in `wp_ffi.ml`.
146+
This process is also explained in [tuto2](https://github.com/rocq-prover/rocq/tree/master/doc/plugin_tutorial/tuto4) of the [Rocq plugin tutorial](https://github.com/rocq-prover/rocq/tree/master/doc/plugin_tutorial).
147+
The documentation in the file `Tac2externals.mli` may also help.
148+
149+
A few remarks:
150+
- For passing variables through the ffi, one needs to convert them to an intermediate datatype: namely `valexpr`.
151+
For existing datatypes these conversion functions exist and can be used conveniently.
152+
With some syntactic sugar from `Tac2externals`, there's really nothing to do.
153+
For inductive datatypes, it is relatively easy to create new conversion functions.
154+
This process is explained in the tutorial mentioned above.
155+
- Although this is not really necessary for the ffi anymore, an element of type `'a` can be converted into an `'a`-valued tactic by using `tclUNIT`.
156+
- To make a tactic available from Ltac2, one needs to use the `Ltac2 @ external` syntax. It may be best to look for examples in the code.

coq-waterproof.opam

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
opam-version: "2.0"
22
name: "coq-waterproof"
3-
version: "3.0.0+dev"
3+
version: "3.1.1+dev"
44
maintainer: "Jim Portegies <[email protected]>"
55
authors: [
66
"Jelle Wemmenhove"
77
"Pim Otte"
88
"Balthazar Pathiachvili"
9+
"Dick Arends"
910
"Cosmin Manea"
1011
"Lulof Pirée"
1112
"Adrian Vrămuleţ"
@@ -25,16 +26,17 @@ bug-reports: "https://github.com/impermeable/coq-waterproof/issues"
2526

2627
depends: [
2728
"ocaml" {>= "4.09.0"}
28-
"rocq-prover" {>= "9.0" & < "9.1" | = "dev"}
29-
"coq" {>= "9.0" & < "9.1" | = "dev"}
29+
"rocq-core" {>= "9.1" & < "9.2" | = "dev" }
30+
"rocq-stdlib" {>= "9" | = "dev" }
31+
"coq" {>= "9.1" & < "9.2" | = "dev"}
3032
"dune" {>= "3.8"}
3133
]
3234

3335
build: [
3436
["dune" "build" "-p" name "-j" jobs "@install"]
3537
]
3638

37-
available: (arch != "s390x") & (arch != "ppc64") & (os != "win32")
39+
available: (arch != "s390x") & (arch != "ppc64")
3840

3941
tags: [
4042
"keyword:mathematics education"

dune-project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55

66
(package
77
(name coq-waterproof)
8-
(version 3.0.0+dev)
8+
(version 3.1.1+dev)
99
(synopsis "Coq proofs in a style that resembles non-mechanized mathematical proofs")
1010
(depends rocq-core rocq-stdlib))

src/META.coq-waterproof

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package "plugin" (
22
directory = "."
3-
version = "3.0.0+9.0"
3+
version = "3.1.1+dev"
44
description = "Waterproof plugin"
55
requires = "rocq-runtime.plugins.ltac rocq-runtime.plugins.ltac2"
66
archive(byte) = "waterproof.cma"
77
archive(native) = "waterproof.cmxa"
88
plugin(byte) = "waterproof.cma"
99
plugin(native) = "waterproof.cmxs"
1010
)
11-
directory = "."
11+
directory = "."

src/exceptions.ml

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,10 @@ let err (input : Pp.t) : unit Proofview.tactic =
156156
(**
157157
Return the last warning
158158
*)
159-
let get_last_warning () : Pp.t option Proofview.tactic =
160-
Proofview.tclUNIT @@
161-
match !(feedback_log Warning) with
162-
| [] -> None
163-
| hd :: tl -> Some hd
159+
let get_last_warning () : Pp.t option =
160+
match !(feedback_log Warning) with
161+
| [] -> None
162+
| hd :: tl -> Some hd
164163

165164
let wp_error_handler (e : exn) : Pp.t option =
166165
if !filter_errors then
@@ -180,3 +179,20 @@ let wp_error_handler (e : exn) : Pp.t option =
180179
else None
181180

182181
let () = CErrors.register_handler wp_error_handler
182+
183+
(**
184+
Convert a reference in a shortest string representation of the
185+
corresponding qualid
186+
*)
187+
let shortest_string_of_global (gr : Names.GlobRef.t) : string =
188+
Nametab.shortest_qualid_of_global Names.Id.Set.empty gr
189+
|> Libnames.string_of_qualid
190+
191+
let check_feedback_level_Ltac2_to_Ocaml (lvl: Feedback.level) (n: int) : bool =
192+
match n with
193+
| 0 -> lvl == Debug
194+
| 1 -> lvl == Info
195+
| 2 -> lvl == Notice
196+
| 3 -> lvl == Warning
197+
| 4 -> lvl == Error
198+
| _ -> throw (CastError "Tried to check a feedback level outside range {0,1,2,3,4}")

src/exceptions.mli

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,15 @@ val message :
112112
(**
113113
Check the last warning against a string
114114
*)
115-
val get_last_warning : unit -> Pp.t option Proofview.tactic
115+
val get_last_warning : unit -> Pp.t option
116+
117+
(**
118+
Convert a reference in a shortest string representation of the
119+
corresponding qualid
120+
*)
121+
val shortest_string_of_global : Names.GlobRef.t -> string
122+
123+
(**
124+
Purely for testing that passing Feedback levels through the ffi works
125+
*)
126+
val check_feedback_level_Ltac2_to_Ocaml : Feedback.level -> int -> bool

0 commit comments

Comments
 (0)