Skip to content
This repository has been archived by the owner on Mar 1, 2019. It is now read-only.

improve dependency handling for cmi files #13

Open
agarwal opened this issue May 6, 2016 · 2 comments
Open

improve dependency handling for cmi files #13

agarwal opened this issue May 6, 2016 · 2 comments

Comments

@agarwal
Copy link
Member

agarwal commented May 6, 2016

$ ls
a.ml       b.ml       b.mli

$ cat a.ml 
type t = int
let x = 42

$ cat b.mli
val y : A.t

$ cat b.ml
let y = A.x

Now, run ocamldep:

$ ocamldep *
a.cmo :
a.cmx :
b.cmo : a.cmo b.cmi
b.cmx : a.cmx b.cmi
b.cmi : a.cmo

The dependency of b.cmi is listed as a.cmo, which is true if you're byte compiling. However, what if you only want to compile to native code, this introduces a wrong dependency, and surely ocamlopt would only expect a.cmx to previously be compiled.

So could use the -native option:

$ ocamldep -native *
a.cmo :
a.cmx :
b.cmo : a.cmx b.cmi
b.cmx : a.cmx b.cmi
b.cmi : a.cmx

Now we see that it does produce a.cmx correctly. (Strangely it still prints out lines for .cmos even though the documentation for -native says specifically "(no .cmo files)".)

The logically correct dependency for b.cmi is "a.cmo or a.cmx".

@pveber
Copy link
Contributor

pveber commented May 8, 2016

If I follow your last remark, it means there is no correct way to handle the problem: you don't want the -native option when you're byte-compiling only, right? Also, it seems to me that while the dependency is indeed wrong, it still permits a correct (only suboptimal) compilation.

@agarwal
Copy link
Member Author

agarwal commented May 9, 2016

it still permits a correct (only suboptimal) compilation

Right. I guess the .cmi gets regenerated when it is not strictly necessary to do so. I haven't tested the affect on total compilation time, which isn't much concern to me since during development I almost always do byte compilation only.

If I follow your last remark, it means there is no correct way to handle the problem

I can think of a couple of solutions (which are probably not worth implementing):

  • Provide a way to specify if byte and/or native compilation are being requested, e.g. by defining an environment variable. Inspect these variables and adjust the rules that get registered accordingly:
    • If either byte or native mode are requested, but not both, then add a rule to build the .cmi.
    • If both byte and native are requested, be sure to add this rule only once.
  • Maybe a dynamic rule would work. The action that is registered could itself check if the .cmi already exists and is out of date, build the .cmi only if necessary.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants