-
Notifications
You must be signed in to change notification settings - Fork 411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: support for extracted OCaml files in Coq builds #2178
Comments
I guess we can run Coq to generate the list of extracted files, as indeed recursive extraction is problematic. |
In another way, could we choose in the dune file what to extract and then dune will instruct Coq about what to do. |
I would personally prefer to choose a file/module in the the dune file and let dune instruct Coq. This would work great for Verdi Raft. However, for other projects such as Disel which produces tons of files/modules during (recursive) extraction, this would not work as well (see, e.g., |
Same for metacoq, if listing could be avoided it would be great. Although, currently, the make-based build does list the produced .ml files. |
IMO explicit listing should only happen when somehow we'd like to constraint the default file list. |
I agree that listing should happen only when the default list is not sufficient. But the main question, in my opinion, is should we need to run coq or another tool to know the list of generated files? Currently dune only need the list of existing files and the content of dune files for all (most?) of the current rules. Could we make coq extraction follow this property by restricting which kinds of extraction are accepted? |
That would prevent the kind of |
Not completely, it is just not coq which is computing the recursive dependency, for javascript (separate compilation mode) there is something similar where the ocaml dependencies must be compiled to javascript. In the case of coq it could be the same, we extract once the dependencies separately that dune should be able to know in some ways. |
I'd like to implement this soon, at least for the explicit listing mode; any suggestion on the syntax? cc: @cpitclaudel |
In most of my developments I extract a single file and the extraction command is fairly large (it lists a bunch of identifiers). I imagine this could move to the dune file (something like
OTOH, I see the appeal of somehow putting all extraction commands inside of the I would be fine with telling dune explicitly about the ml files that an extraction command generates, and I would also be fine with changing my workflow to use a different style of extraction (like library extraction) if that makes things easier. |
I think it would make sense to keep the extraction command within the Coq file and only inform Dune of what ML files are generated. In fact, this could even be the job of |
Here's an extra thought: in my case an ideal solution would allow me to say that a .ml file is generated by extraction, and make that ml file a module of a regular Coq library (possibly through an intermediate rules that copies it, of course) |
Didn't you mean OCaml library? |
Yes:) Woops. |
Note that dune must know this information "statically". That means dune needs to know if a module is a target of some rule (in this case - extraction) without running any external commands. So I think you would at least need to say which modules you expect to be extracted with some sort of
One example:
|
Another current limitation that dune imposes on extraction is that you will not be able to extract source in more than 1 directory. That means you will not be able to extract trees usable with This is the same limitation with native compute. Hopefully we'll lift it soon. In any case, the above should be quite simple to achieve and it will require no additional boilerplate to use extracted sources in normal |
Thinking more of this, should this even be specific to coq? The following could tell dune that generating xyz.vo also generates
|
In general, I would be careful with features that are low level like this. In dune we’ve learned the hard way that exposing more build artifacts to users than necessary is a common theme for breakage. For example, we’ve had to break many user written rules that relied on where dune would write cmi files. When possible, we should strive to design features that are as high level possible so that we can evolve the internals of dune without breaking user rules. So in this particular case, it would be preferable to attach the extraction targets to the coq modules themselves:
|
Got it |
I would definitely prefer
and not having to worry (specify statically) what the dependencies of the |
Just to clarify: dune only requires a complete static description of the targets. It lets you discover dependencies dynamically as any good build tool.
Not only it's a good idea, but it is also a hard requirement. Otherwise, dune will delete those .mli files on the next run. |
In that case, and since to my knowledge there is no way to not produce both
and make dune account for all of |
it may be a good idea to drop the extensions and just write:
Doesn’t coq support extraction to languages other than OCaml? Granted, none of those languages need dune as a build system but at least it’s conceivable that it will be useful.
…On Nov 2, 2019 00:39 +0900, Karl Palmskog ***@***.***>, wrote:
> Not only it's a good idea, but it is also a hard requirement. Otherwise, dune will delete those .mli files on the next run.
In that case, and since to my knowledge there is no way to not produce both .ml and .mli files through Extraction, it may be a good idea to drop the extensions and just write:
(extract
(xyz foo bar)
and make dune account for all of foo.ml, foo.mli, bar.ml, and bar.mli implicitly.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
It does; that's a good point to keep in mind. |
Let's not forget about composable builds. I have a project (Helix) that uses extraction, which in turn depends on another project (Vellvm) which also uses extraction. Ideally, it would be nice to compose dune builds of both projects for both Coq and OCaml. |
At the Dune meeting @rgrinberg proposed a design for extraction support which IMO is the way to go for now. The basic idea is to add an IMO this should provide a nice solution for many use cases. For example in CompCert we would turn:
into
etc... |
What about customizing extraction? Here is an example: https://github.com/vellvm/vellvm/blob/master/src/ml/extracted/Extract.v See |
These can go in a .v file which is used by Dune by a |
I've tried building the vellevm project and it seems like the amount of code you guys extract is quite high. It might be too tedious for you to list all your modules statically like in my earlier suggestion. However, if you don't mind this boilerplate. It will not be hard for me the form of extraction suggested by Emilio above. |
At some point we can have Coq generate the list of targets and use something like promotion to keep it up to date. |
Or have |
There is no way to do this properly in dune currently. Why should coqdep know about the list of targets some .v extracts by the way? A link to the docs regarding this would be appreciated.
Yes, it should work with old versions. Note that to support this feature properly, no new features from coq are required. What is required is to relax some current design limitations in dune to allow dynamic targets. Unfortunately, lifting these limitations is a bit of a slow process, as we're bound both by both backwards compatibility and performance needs of our users. Which is why I think that it would be best to provide something functional in the short term for coq users, even if it requires a bit of boilerplate (listing all modules they intend to extract in a dune file) from users. |
This sounds quite fine. But how will it work with extracting multiple definitions to a single file? |
I guess the field could be something such as
|
Works for me :) |
It's fine to list the modules we extract, that's the same requirement today using |
Rudy has just submitted a PR adding extraction support to Dune c.f. #3299 |
Dear dune developers,
Coq vernacular files can contain extraction commands, that, when processed by Coq, produce OCaml code from Coq code. For example,
coqc
generatesVarDRaft.ml
andVarDRaft.mli
when processing the following directive:Extraction "VarDRaft.ml" vard_raft_failure_params.
There are many Coq projects that build large OCaml projects in this way by extracting OCaml code and then linking it with other code.
However, it's usually hard to set up a build that does the least amount of processing possible to produce the OCaml project (i.e., that skips proofs that may take hours). I have personally resorted to brittle Makefile hacks to accomplish this, e.g., in Verdi Raft.
If there was some way to make dune aware of extracted OCaml files, they could be included in composable builds as other files. I believe this has to be done by manual annotation, since it is not always possible to tell (at least not without a Coq plugin) which files will be produced by an extraction command.
cc: @ejgallego
The text was updated successfully, but these errors were encountered: