ocaml / ocaml/dune

flambda with -nostdlib and transtive stdlib not finding cmx

Open
#4,039 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

acknowledged requires-team-discussion
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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.