flambda with -nostdlib and transtive stdlib not finding cmx
Nobody has claimed this yet.
- Dominant language
- OCaml
- Stars
- 1.9k
- Forks
- 500
- Avg merge
- 15h 21m
- Merged PRs (30d)
- 277
Description
I found a situation where flambda fails to optimize a project when using dune, transitive stdlib and -nostdlib. I’ve included reproduction steps and a proposed fix.
Context
The goal is to compile Tezos using dune with the flambda optimization enabled. Flambda relies on either the build system (dune) or the compiler to provide the position of cmx files; however, dune assumes that the compiler will provide the position of the stdlib. When using the -nostdlib flag, this is not the case. Thus, flambda cannot find them and fails to optimize, giving the Warning 58.
Expected behavior
Dune should add every dependency during the linking of an executable, including transitive dependencies and the stdlib. Flambda should behave identically to the closure compiler in this regard.
I propose the stdlib be added during the linking of every executable.
Actual behavior
Dune seems not to add the stdlib when it is only included as a transitive dependency. For example, in the dependency tree depicted below, the compiler cannot find the cmx files:
custom_stdlib(stdlib) -> lib_a(nostdlib) -> executable(stdlib)
Reproduction
You can try the following the reproduction with and without flambda when using --profile=release. Without flambda, it will compile without any warning. With flambda enabled, it still builds; however, it fails to optimize as the cmx for the stdlib isn’t available.
https://github.com/EduardoRFS/dune-flambda-nostdlib-no-cmx
Specifications
- Version of
dune(output ofdune --version): 2.7.1 - Version of
ocaml(output ofocamlc --version): 4.09.1 - Operating system (distribution and version): Arch Linux
- Link to gist with verbose output (run
dunewith the--verboseflag): https://github.com/EduardoRFS/dune-flambda-nostdlib-no-cmx/blob/main/build.output.txt
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked dune-flambda-nostdlib-no-cmx reproduction and compare builds with and without flambda under the release profile. Trace how transitive stdlib dependencies are handled when linking an executable with -nostdlib; done means the cmx files are found and the flambda build no longer emits Warning 58.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ocaml
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100