-
Notifications
You must be signed in to change notification settings - Fork 410
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
[coq] Preliminary support for split native compilation #4750
Conversation
This comment has been minimized.
This comment has been minimized.
bb54f5d
to
d166e97
Compare
I don't think there is a very pressing need to have this in 2.9 if the next non-patch release (be it 2.10 or 3.0) has it and comes in just a few months. |
8a6a3b2
to
404bfc5
Compare
Sounds good, thanks for the feedback, re-targetting 2.9 then. The code, while not perfect, is in a reviewable state, thus un-drafting. |
2b567b2
to
3746727
Compare
… are used Backported from ocaml#4750
… are used Backported from ocaml#4750 Signed-off-by: Emilio Jesus Gallego Arias <[email protected]>
@proux01 this should be interesting for testing with coq-master, or coq-v8.14.dev once a small patch gets backported, in particular this should provide a nice speedup I assume if you got a few core on your machine. Note that support for |
… are used Backported from ocaml#4750
f7eff0b
to
2127386
Compare
… are used (#4753) Backported from #4750 Signed-off-by: Emilio Jesus Gallego Arias <[email protected]>
… are used Backported from ocaml#4750
87195a5
to
61ceeb5
Compare
@ejgallego yes, I am not surprised that for the stdlib we get a non-trivial overhead due to repeated requires, because all the compilation times are short and dominated by the chain of requires. I think that in theory we shouldn't even need to transitively require dependencies for native compilation, it could probably be performed directly on the kernel term without knowing anything about the dependencies. |
@ejgallego could you retry with coq/coq#14540? I don't know how much linking takes time in the absolute, but removing it can only make things faster. |
Thanks for the quick turnaround @ppedrot , timings added to the above post; improvements are significant, like 50% of the overhead seems gone which is good news; I'll keep testing stuff with the patch and let you know if I find any trouble [seems unlikekly] |
@ejgallego I tested this with multinomials on top of Coq master. I had to modify multinomials' dunes files but it worked fine (I was able to build CoqEAL on top of it), that's great! However, I still fail to see the big picture here:
I think that dune should work just as well as coq-makefile or remake with the current setting 1. This is unfortunately currently not the case: the simple fact that coq-multinomials switched to dune as a build system made it (hence CoqEAL and everything based on it) unbuildable with coq-native. I offered what I hope could be a reasonably simple short term solution in this comment #4722 (comment) do you have a better idea ? Do you have a precise view of how the current PR will help with 2. ? (the details on the OPAM repo side remain unclear to me) @erikmd you might be interested in those discussions |
Hi @proux01 , indeed we can improve the situation, Dune 3.0 can actually query a particular configuration value from coqc [would be great if opam provided an interface for this] and setup the rules after that. That would amount to actually fixing your patch so the query happens thru the build system interface. A thing to consider tho is that the Coq developers have been considering removing the old mode where coqc generates native files, so I dunno. |
That could indeed be a nice fix. Do we have an idea of the schedule for Dune 3.0 ?
That's certainly the way to go in the long term. But it is impossible to proceed until the split package approach gets implemented on the OPAM repo side (otherwise, that would mean going back to the pre 8.13 status where native-compiler was practically unusable, which would be pointlless). Unfortunately, no one seems to be working on it yet, or even have a precise idea of the technical details. Thus I still think that we need to fix dune in the current setting. |
Likely early fall. But if we add this code it would be useful for many other things, like exposing a This reduces parallelism a bit, but not a big deal IMO.
Note that there is a migration path in this sense that doesn't require any action on OPAM path, with this patch, Dune can build the native objects regardless of how Coq was configured, thus you can have a Dunerized package This has the downside of being less granular, but on the other hand it works, and can be made granular in the following sense, |
Great, feel free to ask if I can be of any help.
Good point, although I don't see how that would fix for instance the issue with multinomials pointed above (most users don't want mutlinomials to build native objects but the users of coq-native want it). |
Yes and no. The |
Note that opam 2.1 has a new |
ba117da
to
c9d0ba4
Compare
…ges. In some cases, it is convenient for stanzas to produce objects that will be installed under different packages. For example, in Coq we may want to install the costly native files in a `foo-native` package, or distributions such as Debian like to split packages in `-doc`, `-dev`, and `-dbg` variants. This PR modifies the code so this is possible. This code is cherry-picked from ocaml#4750 (which would be the first user of the feature), but I am submitting separately as I think the change deserves more discussion. For example, this implies that `Dune_file.stanza_package stanza` is not canonical anymore. Likely, a better modelling would be to introduce the notion of "sub-package". The code changes themselves don't make me super-happy, consider them a draft. If you folks are OK with the idea, I can improve it so the common case of one stanza installing files only for one package is better optimized. Signed-off-by: Emilio Jesus Gallego Arias <[email protected]>
Coq 8.14 can generate native files independently from .vo file generation by using a new `coqnative` compiler, which will do the `.vo -> .cmxs` translation. This allows Dune to have a simpler rule setup, as it is always possible to rely on coqnative to compile native files, as opposed to before where native file generation was controlled by a Coq-level configure flag. The new rule setup is enabled for `(lang coq 0.4)`, and we provide a couple of configuration options in the `mode` field via a couple of optional fields: ```lisp (coq.theory ... (mode (native (package pkg) (profile p1 ... pn)))) ``` The first field, `(package )` allows to override the package under which native files for the corresponding theory will be installed. This is useful for packagers willing to split the native compilation under a different package, given that it can be extremely resource-intensive. The default for this setting is the same package name. The second field controls under which profiles Dune will setup the native build rules; the default for this setting is `release`, so Dune will skip Coq's native compilation when in `dev` mode. `(mode vo)` is still accepted, in case developers would like to completely disable native generation. TODO: take into account the `(package field)` for `native` , to be implemented in the next commit. Signed-off-by: Emilio Jesus Gallego Arias <[email protected]>
The code changes doesn't make me super-happy, tho I think that in general it makes sense for stanzas to produce object files that do belong to multiple packages, as for example it is common in some upstream packagers to allow to install debug and doc files into a different package. However this implies that `Dune_file.stanza_package stanza` is not canonical anymore. Likely to model this better, we may need to define the notion of sub-packages of a stanza / package, but awaiting for feedback.
c9d0ba4
to
9b3d101
Compare
…ges. In some cases, it is convenient for stanzas to produce objects that will be installed under different packages. For example, in Coq we may want to install the costly native files in a `foo-native` package, or distributions such as Debian like to split packages in `-doc`, `-dev`, and `-dbg` variants. This PR modifies the code so this is possible. This code is cherry-picked from ocaml#4750 (which would be the first user of the feature), but I am submitting separately as I think the change deserves more discussion. For example, this implies that `Dune_file.stanza_package stanza` is not canonical anymore. Likely, a better modelling would be to introduce the notion of "sub-package". The code changes themselves don't make me super-happy, consider them a draft. If you folks are OK with the idea, I can improve it so the common case of one stanza installing files only for one package is better optimized. Signed-off-by: Emilio Jesus Gallego Arias <[email protected]>
I removed the 3.0 milestone as this PR isn't ready and we're being very strict with what's actually blocking 3.0 |
I looked over this PR, and the code looks good to me. I'm a bit skeptical of the end user experience proposed though. I only have a cursory understanding of coq users, so feel free to dismiss my objections. If I understand correctly, there are essentially two groups of coq users:
Well I think the proposal here will irritate both groups. Those who don't care about native compilation will be grumbling about slower builds and resorting to inserting random metadata (in their eyes) to gain back some speed. Those who do care about native compilation will now need to track their dependencies and make sure they depend on In the ocaml world, we had a similar problem with js_of_ocaml compilation. I think we solved this problem quite handily and I wonder if coq could learn a lesson or two. In development mode, we rely on jsoo's "separate compilation" mode. This requires a .cma -> .js rules for every single library. Now clearly, it's undesirable to execute this rule when installing a package. Not everyone cares about compiling to js, and the jsoo compiler may not even be present. So what do we do? Well we just setup .cma -> .js rules for all external libraries in the background. If we do this naively, there are two disadvantages:
Thankfully, we are able to adequately address both of these concerns.
I realize that some people might feel uneasy about delaying building the artifacts post the installation of the package. But I think these are mostly bad ideas we inherited from inflexible package managers like apt and opam. There's no reason to be constrained by them now. |
Thanks for sharing this experience! It indeed seem that this feature requires further discussion. If I dare a question: currently part of the Coq packages are built with CoqMakefile, another part with dune and a few other with other build systems and even if dune could improve its "market share", that situation will likely last for long, if not forever. How would the jsoo "delayed" solution work in this setting? |
Thanks a lot for the feedback @rgrinberg , I will try to revisit this proposal; actually the lazy generation of native files was done by Unfortunately this didn't work so well due to the lack of cache and other issues [maybe related to file lookup] , so this mode was removed in favor of a global setting to enable native. I need to ponder how things would work with the Dune cache, but this PR is for now stuck due to this, and due to some concerns with the "subpackage" idea that require a bit of analysis. |
In the jsoo world, it was never a problem because we a have simple convention that every library must have a cma archive file no matter what build system was used to generate it. If there's an analogous rule in coq (e.g. every .v file needs a .cmxs), I imagine there would also be little difficulty. The downside would be for non dune based coq projects using native artifacts. But perhaps it is acceptable to only provide this feature for newer coq projects that decide to use dune? There's always a limit to what you can do in make, so I doubt it will be the only limitation.
I can definitely see why it didn't work well. Coqc just doesn't have enough context here. The build system is the right place to add all such optimizations IMO. |
@rgrinberg the discussion above is related to your recent question |
I'll comment here as I know some people has been interested in working on this setup (for example @Alizter ) The code in this PR is fine from the point of view of Coq's funcionality, and I'll be happy to resurrect it if there is interest. Main reason progress on this got blocked was due to a pre-requisite for this PR: #4908 So indeed, if there is interest in doing this, we should first resolve how the install targets would work. It still seems to me that a stanza could belong to different packages, in principle I see nothing essential about the design of such a setup that would not work; how the code is today in Dune, that's a different story. |
Please re-open if this is still relevant |
Coq 8.14 can generate native files independently from .vo file
generation by using a new
coqnative
compiler, which will do the.vo -> .cmxs
translation.This allows Dune to have a simpler rule setup, as it is always
possible to rely on coqnative to compile native files, as opposed to
before where native file generation was controlled by a Coq-level
configure flag.
The new rule setup is enabled for
(lang coq 0.4)
, and we provide acouple of configuration options in the
mode
field via a couple ofoptional fields:
(coq.theory ... (mode (native (package pkg) (profile p1 ... pn))))
The first field,
(package )
allows to override the package underwhich native files for the corresponding theory will be
installed. This is useful for packagers willing to split the native
compilation under a different package, given that it can be extremely
resource-intensive. The default for this setting is the same package
name.
The second field controls under which profiles Dune will setup the
native build rules; the default for this setting is
release
, so Dunewill skip Coq's native compilation when in
dev
mode.(mode vo)
is still accepted, in case developers would like tocompletely disable native generation.