Skip to content

Commit d7d8744

Browse files
refactor: update rocq extraction to use extracted_files instead of extracted_modules for version 0.13
Signed-off-by: Will Thomas <30wthomas@gmail.com>
1 parent f4150d8 commit d7d8744

4 files changed

Lines changed: 73 additions & 115 deletions

File tree

doc/rocq.rst

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,8 @@ The supported Rocq language versions (not the version of Rocq) are:
374374
+ ``(mode native)`` is not allowed anymore. It is the default if Rocq was configured with native compute enabled.
375375
+ ``COQPATH`` is not recognized anymore, use ``ROCQPATH``.
376376
- ``0.12``: Support for output tests.
377-
- ``0.13``: Support for ``extracted_files`` in ``rocq.extraction``.
377+
- ``0.13``: ``rocq.extraction`` now uses ``extracted_files`` instead of
378+
``extracted_modules``, supporting extraction to languages other than OCaml.
378379

379380
.. _rocq-lang-1.0:
380381

@@ -395,27 +396,38 @@ rocq.extraction
395396
Rocq may be instructed to *extract* sources as part of the compilation
396397
process by using the ``rocq.extraction`` stanza:
397398

399+
For ``(rocq 0.12)`` and below:
400+
398401
.. code:: dune
399402
400403
(rocq.extraction
401404
(prelude <name>)
402405
(extracted_modules <names>)
406+
<optional-fields>)
407+
408+
For ``(rocq 0.13)`` and above:
409+
410+
.. code:: dune
411+
412+
(rocq.extraction
413+
(prelude <name>)
403414
(extracted_files <filenames>)
404415
<optional-fields>)
405416
406417
- ``(prelude <name>)`` refers to the Rocq source that contains the extraction
407418
commands.
408419

409-
- ``(extracted_modules <names>)`` is a list of OCaml modules extracted. For each
410-
module name, Dune expects both a ``.ml`` and ``.mli`` file to be produced.
411-
412-
- ``(extracted_files <filenames>)`` is a list of filenames (with extensions) that
413-
will be produced by the extraction. This allows extraction to languages other
414-
than OCaml, such as Haskell (``.hs``) or Scheme (``.scm``). Available since
415-
``(rocq 0.13)``.
416-
417-
At least one of ``extracted_modules`` or ``extracted_files`` must be specified.
418-
Both can be provided simultaneously, and the targets will be merged.
420+
- ``(extracted_modules <names>)`` specifies the OCaml modules to be extracted.
421+
For each module name, Dune expects both a ``.ml`` and ``.mli`` file to be
422+
produced. Available in ``(rocq 0.12)`` and below; replaced by
423+
``extracted_files`` in ``(rocq 0.13)``.
424+
425+
- ``(extracted_files <filenames>)`` is a list of filenames (with extensions)
426+
that will be produced by the extraction. This allows extraction to languages
427+
other than OCaml, such as Haskell (``.hs``) or Scheme (``.scm``). Available
428+
since ``(rocq 0.13)``. Users upgrading from ``0.12`` should replace
429+
``(extracted_modules M1 ... Mn)`` with ``(extracted_files M1.ml M1.mli ... Mn.ml
430+
Mn.mli)``.
419431

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

src/dune_rules/rocq/rocq_stanza.ml

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -70,52 +70,48 @@ end
7070

7171
module Extraction = struct
7272
type t =
73-
{ (* not a list of modules because we want to preserve whatever case Rocq
74-
uses *)
75-
extracted_modules : string list
76-
; extracted_files : string list
73+
{ target_fnames : string list
7774
; prelude : Loc.t * Rocq_module.Name.t
7875
; buildable : Buildable.t
7976
}
8077

81-
let target_fnames t =
82-
List.concat_map t.extracted_modules ~f:(fun m -> [ m ^ ".ml"; m ^ ".mli" ])
83-
@ t.extracted_files
84-
;;
78+
let target_fnames t = t.target_fnames
8579

8680
let decode =
8781
fields
88-
(let+ extracted_modules = field "extracted_modules" (repeat string) ~default:[]
89-
and+ extracted_files =
90-
field
82+
(let* ver = get_rocq_syntax () in
83+
let+ extracted_modules_opt =
84+
field_o
85+
"extracted_modules"
86+
(Dune_lang.Syntax.deleted_in
87+
rocq_syntax
88+
(0, 13)
89+
~extra_info:
90+
"Use (extracted_files ...) instead, listing each .ml and .mli file \
91+
explicitly."
92+
>>> repeat string)
93+
and+ extracted_files_opt =
94+
field_o
9195
"extracted_files"
9296
(Dune_lang.Syntax.since rocq_syntax (0, 13) >>> repeat string)
93-
~default:[]
9497
and+ prelude = field "prelude" (located (string >>| Rocq_module.Name.make))
9598
and+ buildable = Buildable.decode
9699
and+ loc = loc in
97-
if List.is_empty extracted_modules && List.is_empty extracted_files
98-
then
99-
User_error.raise
100-
~loc
101-
[ Pp.text
102-
"At least one of (extracted_modules) or (extracted_files) must be \
103-
specified"
104-
];
105-
let all_targets =
106-
target_fnames { extracted_modules; extracted_files; prelude; buildable }
100+
let target_fnames =
101+
if ver < (0, 13)
102+
then (
103+
match extracted_modules_opt with
104+
| None ->
105+
User_error.raise ~loc [ Pp.text "Field \"extracted_modules\" is required" ]
106+
| Some modules ->
107+
List.concat_map modules ~f:(fun m -> [ m ^ ".ml"; m ^ ".mli" ]))
108+
else (
109+
match extracted_files_opt with
110+
| None ->
111+
User_error.raise ~loc [ Pp.text "Field \"extracted_files\" is required" ]
112+
| Some files -> files)
107113
in
108-
(match String.Map.of_list (List.map all_targets ~f:(fun t -> t, ())) with
109-
| Ok _ -> ()
110-
| Error (dup, (), ()) ->
111-
User_warning.emit
112-
~loc
113-
[ Pp.textf
114-
"Duplicate target filename %S across (extracted_modules) and \
115-
(extracted_files)"
116-
dup
117-
]);
118-
{ prelude; extracted_modules; extracted_files; buildable })
114+
{ target_fnames; prelude; buildable })
119115
;;
120116

121117
include Stanza.Make (struct

src/dune_rules/rocq/rocq_stanza.mli

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ end
2727

2828
module Extraction : sig
2929
type t =
30-
{ extracted_modules : string list
31-
; extracted_files : string list
30+
{ target_fnames : string list
3231
; prelude : Loc.t * Rocq_module.Name.t
3332
; buildable : Buildable.t
3433
}

test/blackbox-tests/test-cases/rocq/extraction/extracted-files.t

Lines changed: 20 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Test error when neither extracted_modules nor extracted_files is provided:
1+
Test error when extracted_files is not provided in rocq 0.13:
22

33
$ cat >dune-project <<EOF
44
> (lang dune 3.22)
@@ -21,8 +21,7 @@ Test error when neither extracted_modules nor extracted_files is provided:
2121
File "dune", lines 1-2, characters 0-33:
2222
1 | (rocq.extraction
2323
2 | (prelude extr))
24-
Error: At least one of (extracted_modules) or (extracted_files) must be
25-
specified
24+
Error: Field "extracted_files" is required
2625
[1]
2726

2827
Test version gating: extracted_files requires (rocq 0.13):
@@ -47,7 +46,7 @@ Test version gating: extracted_files requires (rocq 0.13):
4746
0.13).
4847
[1]
4948

50-
Test warning on duplicate target filename across extracted_modules and extracted_files:
49+
Test that extracted_modules is deleted in rocq 0.13 with a helpful error message:
5150

5251
$ cat >dune-project <<EOF
5352
> (lang dune 3.22)
@@ -58,54 +57,16 @@ Test warning on duplicate target filename across extracted_modules and extracted
5857
> (rocq.extraction
5958
> (prelude extr)
6059
> (extracted_modules extr)
61-
> (extracted_files extr.ml)
6260
> (flags (:standard -w -extraction-default-directory)))
6361
> EOF
6462

6563
$ dune build
66-
File "dune", lines 1-5, characters 0-140:
67-
1 | (rocq.extraction
68-
2 | (prelude extr)
69-
3 | (extracted_modules extr)
70-
4 | (extracted_files extr.ml)
71-
5 | (flags (:standard -w -extraction-default-directory)))
72-
Warning: Duplicate target filename "extr.ml" across (extracted_modules) and
73-
(extracted_files)
74-
$ ls _build/default | sort
75-
Datatypes.ml
76-
Datatypes.mli
77-
extr.glob
78-
extr.ml
79-
extr.mli
80-
extr.v
81-
extr.vo
82-
extr.vok
83-
extr.vos
84-
85-
Test completeness of both extracted_modules and extracted_files (expected failure):
86-
87-
$ cat >dune-project <<EOF
88-
> (lang dune 3.22)
89-
> (using rocq 0.13)
90-
> EOF
91-
92-
$ cat >dune <<EOF
93-
> (rocq.extraction
94-
> (prelude extr)
95-
> (extracted_modules extr)
96-
> (extracted_files fake.hs)
97-
> (flags (:standard -w -extraction-default-directory)))
98-
> EOF
99-
100-
$ dune build
101-
File "dune", lines 1-5, characters 0-140:
102-
1 | (rocq.extraction
103-
2 | (prelude extr)
64+
File "dune", line 3, characters 1-25:
10465
3 | (extracted_modules extr)
105-
4 | (extracted_files fake.hs)
106-
5 | (flags (:standard -w -extraction-default-directory)))
107-
Error: Rule failed to generate the following targets:
108-
- fake.hs
66+
^^^^^^^^^^^^^^^^^^^^^^^^
67+
Error: 'extracted_modules' was deleted in version 0.13 of Rocq Prover build
68+
language. Use (extracted_files ...) instead, listing each .ml and .mli file
69+
explicitly.
10970
[1]
11071

11172
Test using extracted_files with explicit filenames:
@@ -138,7 +99,7 @@ Test using extracted_files with explicit filenames:
13899
_build/default/Datatypes.ml
139100
_build/default/extr.ml
140101

141-
Test using extracted_modules with Haskell outputs (expected failure):
102+
Test that extracted_modules in 0.13 gives deleted_in error for Haskell extraction:
142103

143104
$ cat >dune-project <<EOF
144105
> (lang dune 3.22)
@@ -165,16 +126,12 @@ Test using extracted_modules with Haskell outputs (expected failure):
165126
> EOF
166127

167128
$ dune build
168-
File "dune", lines 1-4, characters 0-129:
169-
1 | (rocq.extraction
170-
2 | (prelude extr)
129+
File "dune", line 3, characters 1-41:
171130
3 | (extracted_modules Datatypes.hs extr.hs)
172-
4 | (flags (:standard -w -extraction-default-directory)))
173-
Error: Rule failed to generate the following targets:
174-
- Datatypes.hs.ml
175-
- Datatypes.hs.mli
176-
- extr.hs.ml
177-
- extr.hs.mli
131+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
132+
Error: 'extracted_modules' was deleted in version 0.13 of Rocq Prover build
133+
language. Use (extracted_files ...) instead, listing each .ml and .mli file
134+
explicitly.
178135
[1]
179136

180137
Test using extracted_files with Haskell outputs (expected success):
@@ -210,8 +167,6 @@ Test using extracted_files with Haskell outputs (expected success):
210167
extr.hs
211168
extr.v
212169
extr.vo
213-
extr.vok
214-
extr.vos
215170

216171
Test rebuild does not clean extracted files:
217172
(NOTE: re-using above pre-built context)
@@ -223,7 +178,7 @@ Test rebuild does not clean extracted files:
223178
extr.v
224179
extr.vo
225180

226-
Test using extracted_modules with Scheme outputs (expected failure):
181+
Test that extracted_modules in 0.13 gives deleted_in error for Scheme extraction:
227182

228183
$ cat >dune-project <<EOF
229184
> (lang dune 3.22)
@@ -250,14 +205,12 @@ Test using extracted_modules with Scheme outputs (expected failure):
250205
> EOF
251206

252207
$ dune build
253-
File "dune", lines 1-4, characters 0-115:
254-
1 | (rocq.extraction
255-
2 | (prelude extr)
208+
File "dune", line 3, characters 1-27:
256209
3 | (extracted_modules nb.scm)
257-
4 | (flags (:standard -w -extraction-default-directory)))
258-
Error: Rule failed to generate the following targets:
259-
- nb.scm.ml
260-
- nb.scm.mli
210+
^^^^^^^^^^^^^^^^^^^^^^^^^^
211+
Error: 'extracted_modules' was deleted in version 0.13 of Rocq Prover build
212+
language. Use (extracted_files ...) instead, listing each .ml and .mli file
213+
explicitly.
261214
[1]
262215

263216
Test using extracted_files with Scheme outputs (expected success):
@@ -291,6 +244,4 @@ Test using extracted_files with Scheme outputs (expected success):
291244
extr.glob
292245
extr.v
293246
extr.vo
294-
extr.vok
295-
extr.vos
296247
nb.scm

0 commit comments

Comments
 (0)