Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
28 changes: 25 additions & 3 deletions doc/rocq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ The supported Rocq language versions (not the version of Rocq) are:
+ ``(mode native)`` is not allowed anymore. It is the default if Rocq was configured with native compute enabled.
+ ``COQPATH`` is not recognized anymore, use ``ROCQPATH``.
- ``0.12``: Support for output tests.
- ``0.13``: ``rocq.extraction`` now uses ``extracted_files`` instead of
``extracted_modules``, supporting extraction to languages other than OCaml.

.. _rocq-lang-1.0:

Expand All @@ -391,21 +393,41 @@ unchanged or minimally modified.
rocq.extraction
---------------

Rocq may be instructed to *extract* OCaml sources as part of the compilation
Rocq may be instructed to *extract* sources as part of the compilation
process by using the ``rocq.extraction`` stanza:

For ``(rocq 0.12)`` and below:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's only keep the new version otherwise it risks being confusing.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

i.e. don't repeat the stanza, just show the new version.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I moved info about extracted_modules into a note, because it felt a bit orphaned now


.. code:: dune

(rocq.extraction
(prelude <name>)
(extracted_modules <names>)
<optional-fields>)

For ``(rocq 0.13)`` and above:

.. code:: dune

(rocq.extraction
(prelude <name>)
(extracted_files <filenames>)
<optional-fields>)

- ``(prelude <name>)`` refers to the Rocq source that contains the extraction
commands.

- ``(extracted_modules <names>)`` is an exhaustive list of OCaml modules
extracted.
- ``(extracted_modules <names>)`` specifies the OCaml modules to be extracted.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would put the information about upgrading in this section, and move this section below.

For each module name, Dune expects both a ``.ml`` and ``.mli`` file to be
produced. Available in ``(rocq 0.12)`` and below; replaced by
``extracted_files`` in ``(rocq 0.13)``.

- ``(extracted_files <filenames>)`` is a list of filenames (with extensions)
that will be produced by the extraction. This allows extraction to languages
other than OCaml, such as Haskell (``.hs``) or Scheme (``.scm``). Available
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We have a since field somewhere in the docs. That should be used when describing this field.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I couldn't exactly find a since field, but maybe what I ended up doing is what you intended?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sorry, my memory this morning was very poor, its

      .. versionadded:: 3.23

since ``(rocq 0.13)``. Users upgrading from ``0.12`` should replace
``(extracted_modules M1 ... Mn)`` with ``(extracted_files M1.ml M1.mli ... Mn.ml
Mn.mli)``.

- ``<optional-fields>`` are ``flags``, ``stdlib``, ``theories``, and
``plugins``. All of these fields have the same meaning as in the
Expand Down
2 changes: 1 addition & 1 deletion src/dune_rules/dir_contents.ml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ end = struct
Path.Build.set_extension mlg_file ~ext:Filename.Extension.ml
|> Path.Build.basename)
| Rocq_stanza.Extraction.T s ->
Memo.return (Rocq_stanza.Extraction.ml_target_fnames s)
Memo.return (Rocq_stanza.Extraction.target_fnames s)
| Rule_conf.T rule ->
Simple_rules.user_rule sctx rule ~dir ~expander
>>| (function
Expand Down
2 changes: 1 addition & 1 deletion src/dune_rules/rocq/rocq_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,7 @@ let setup_extraction_rules ~sctx ~dir ~dir_contents (s : Rocq_stanza.Extraction.
let* rocq_sources = Dir_contents.rocq dir_contents in
let rocq_module = Rocq_sources.extract rocq_sources s in
let file_targets =
Rocq_stanza.Extraction.ml_target_fnames s |> List.map ~f:(Path.Build.relative dir)
Rocq_stanza.Extraction.target_fnames s |> List.map ~f:(Path.Build.relative dir)
in
let loc = s.buildable.loc in
let use_stdlib = s.buildable.use_stdlib in
Expand Down
45 changes: 35 additions & 10 deletions src/dune_rules/rocq/rocq_stanza.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let rocq_syntax =
Dune_lang.Syntax.create
~name:(Syntax.Name.parse "rocq")
~desc:"Rocq Prover build language"
[ (0, 11), `Since (3, 21); (0, 12), `Since (3, 22) ]
[ (0, 11), `Since (3, 21); (0, 12), `Since (3, 22); (0, 13), `Since (3, 22) ]
Comment thread
Durbatuluk1701 marked this conversation as resolved.
Outdated
;;

let get_rocq_syntax () = Dune_lang.Syntax.get_exn rocq_syntax
Expand Down Expand Up @@ -70,23 +70,48 @@ end

module Extraction = struct
type t =
{ (* not a list of modules because we want to preserve whatever case Rocq
uses *)
extracted_modules : string list
{ target_fnames : string list
; prelude : Loc.t * Rocq_module.Name.t
; buildable : Buildable.t
}

let ml_target_fnames t =
List.concat_map t.extracted_modules ~f:(fun m -> [ m ^ ".ml"; m ^ ".mli" ])
;;
let target_fnames t = t.target_fnames

let decode =
fields
(let+ extracted_modules = field "extracted_modules" (repeat string)
(let* ver = get_rocq_syntax () in
let+ extracted_modules_opt =
field_o
"extracted_modules"
(Dune_lang.Syntax.deleted_in
rocq_syntax
(0, 13)
~extra_info:
"Use (extracted_files ...) instead, listing each .ml and .mli file \
explicitly."
>>> repeat string)
and+ extracted_files_opt =
field_o
"extracted_files"
(Dune_lang.Syntax.since rocq_syntax (0, 13) >>> repeat string)
and+ prelude = field "prelude" (located (string >>| Rocq_module.Name.make))
and+ buildable = Buildable.decode in
{ prelude; extracted_modules; buildable })
and+ buildable = Buildable.decode
and+ loc = loc in
let target_fnames =
if ver < (0, 13)
then (
match extracted_modules_opt with
| None ->
User_error.raise ~loc [ Pp.text "Field \"extracted_modules\" is required" ]
| Some modules ->
List.concat_map modules ~f:(fun m -> [ m ^ ".ml"; m ^ ".mli" ]))
else (
match extracted_files_opt with
| None ->
User_error.raise ~loc [ Pp.text "Field \"extracted_files\" is required" ]
| Some files -> files)
in
{ target_fnames; prelude; buildable })
;;

include Stanza.Make (struct
Expand Down
4 changes: 2 additions & 2 deletions src/dune_rules/rocq/rocq_stanza.mli
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ end

module Extraction : sig
type t =
{ extracted_modules : string list
{ target_fnames : string list
; prelude : Loc.t * Rocq_module.Name.t
; buildable : Buildable.t
}

val ml_target_fnames : t -> string list
val target_fnames : t -> string list

include Stanza.S with type t := t
end
Expand Down
Loading
Loading