Skip to content
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

Make dune describe correctly handle overlapping implementations for virtual libraries #5971

Merged
merged 2 commits into from
Jul 20, 2022

Conversation

esope
Copy link
Collaborator

@esope esope commented Jul 14, 2022

Fixes issue #5747

Here is what happened before this fix: if your project was using a
virtual library and at least two implementations for that virtual
library, then dune describe would not produce any information for the
libraries of your project (it would only show information about the
executables, if there were any). The issue was in the computation of
the transitive closure of libraires, that raised an error by default
in the presence of overlapping implementations of virtual libraries.
In such a case, the error was treated by discarding all information
about the libraries.

The fix consists in computing the transitive closure of libraries
without performing any overlap checks between implementations of a
virtual library. We have defined the descriptive_closure function
for this very purpose.

The overlap check is necessary when you compute the transitive closure
of libraries that you intend to build (otherwise you do not know which
implementation should be picked).

In dune describe, you want to describe the whole workspace, regardless
of what you want to build or not, which means that you need to handle
all the libraries of your workspace, that may include several
implementations for virtual modules.

If you absolutely want to perform the overlap check in dune describe,
then will not always be able to describe the whole workspace.

Signed-off-by: Benoît Montagu [email protected]

@rgrinberg
Copy link
Member

I haven't looked at the PR closely, but the first question that comes to mind is why is it correct to ignore the overlap check for dune describe?

@esope
Copy link
Collaborator Author

esope commented Jul 14, 2022

The overlap check is necessary when you compute the transitive closure of libraries that you intend to build (otherwise you do not know which implementation should be picked).
In dune describe, you want to describe the whole workspace, regardless of what you want to build or not, which means that you need to handle all the libraries of your workspace, that may include several implementations for virtual modules.
I you absolutely want to perform the overlap check in dune describe, then will not always be able to describe the whole workspace.

@rgrinberg
Copy link
Member

Thanks for the explanation. It makes sense and I'd like it included either in the commit message or the PR message.

Now for some points about the implementation:

  • The test commit demonstrating the bug should come first. The bug should be described and the corresponding github issue be linked.
  • Instead of adding a flag to our closure functions used for compilation/linking, you should introduce a new function that does what you want without introducing all these concerns about linking, virtual libraries, etc. It should be perhaps called a descriptive_closure and it should be much simpler.

@esope
Copy link
Collaborator Author

esope commented Jul 18, 2022

@rgrinberg : if you want to have a look, here is a new version with the changes that you suggested.

@rgrinberg
Copy link
Member

Thanks, it looks good. I simplified the descriptive closure a bit further. None of the Resolve monad book keeping is necessary because we don't need to delay errors like we do for setting up build rules.

@rgrinberg rgrinberg added this to the 3.4.0 milestone Jul 19, 2022
@esope
Copy link
Collaborator Author

esope commented Jul 20, 2022

Thanks for the cleanup. I must confess it is not completely clear to me what role each monad is actually playing in dune.

Added a failing test for `dune describe` that involves virtual
libraries.

In the presence of virtual libraries, `dune describe` fails at computing
the right set of libraries, because the code for transitive closure may
detect some overlapping implementations for a given virtual library. In
such a case, the whole set of libraries is dropped.

The detection of overlapping libraries is necessary when the user asks
to build a library or an executable (because `dune` has to pick an
implementation, and this choice should be controlled by the user).

In the case of `dune describe`, however, the goal is to describe the
whole workspace, which may include several implementation for a virtual
library. In this case, if `dune describe` currently fails when several
implementations are found, it cannot fully describe the whole workspace.

The code for transitive closure (when used by `dune describe`) therefore
must not try to detect overlapping implementations.

Signed-off-by: Benoît Montagu <[email protected]>
Make `dune describe` correctly handle overlapping implementations for
virtual libraries.

Fixes issue ocaml#5747

Here is what happened before this fix: if your project was using a
virtual library and at least two implementations for that virtual
library, then dune describe would not produce any information for the
libraries of your project (it would only show information about the
executables, if there were any). The issue was in the computation of the
transitive closure of libraires, that raised an error by default in the
presence of overlapping implementations of virtual libraries. In such a
case, the error was treated by discarding all information about the
libraries.

The fix consists in computing the transitive closure of libraries
without performing any overlap checks between implementations of a
virtual library. We have defined the `descriptive_closure` function for
this very purpose.

The overlap check is necessary when you compute the transitive closure
of libraries that you intend to build (otherwise you do not know which
implementation should be picked).

In dune describe, you want to describe the whole workspace, regardless
of what you want to build or not, which means that you need to handle
all the libraries of your workspace, that may include several
implementations for virtual modules.

If you absolutely want to perform the overlap check in dune describe,
then will not always be able to describe the whole workspace.

Signed-off-by: Benoît Montagu <[email protected]>
@emillon emillon linked an issue Jul 20, 2022 that may be closed by this pull request
@emillon emillon merged commit 3ea2fcc into ocaml:main Jul 20, 2022
@emillon
Copy link
Collaborator

emillon commented Jul 20, 2022

Thanks!

@esope esope deleted the describe_issue5747 branch July 20, 2022 12:19
emillon added a commit to emillon/opam-repository that referenced this pull request Jul 20, 2022
…ne-site, dune-rpc, dune-rpc-lwt, dune-private-libs, dune-glob, dune-configurator, dune-build-info, dune-action-plugin and chrome-trace (3.4.0)

CHANGES:

- Make `dune describe` correctly handle overlapping implementations
  for virtual libraries (ocaml/dune#5971, fixes ocaml/dune#5747, @esope)

- Building the `@check` alias should make sure the libraries and executables
  don't have dependency cycles (ocaml/dune#5892, @rgrinberg)

- [ctypes] Add support for the `errno` parameter using the `errno_policy` field
  in the ctypes settings. (ocaml/dune#5827, @droyo)

- Fix `dune coq top` when it is invoked on files from a subdirectory of the
  directory containing the associated stanza (ocaml/dune#5784, fixes ocaml/dune#5552, @ejgallego,
  @rlepigre, @Alizter)

- Fix hint when an invalid module name is found. (ocaml/dune#5922, fixes ocaml/dune#5273, @emillon)

- The `(cat)` action now supports several files. (ocaml/dune#5928, fixes ocaml/dune#5795, @emillon)

- Dune no longer uses shimmed `META` files for OCaml 5.x, solely using the ones
  installed by the compiler. (ocaml/dune#5916, @dra27)

- Fix handling of the `(deps)` field in `(test)` stanzas when there is an
  `.expected` file. (ocaml/dune#5952, ocaml/dune#5951, fixes ocaml/dune#5950, @emillon)

- Ignore insignificant filesystem events. This stops RPC in watch mode from
  flashing errors on insignificant file system events such as changes in the
  `.git/` directory. (ocaml/dune#5953, @rgrinberg)

- Fix parsing more error messages emitted by the OCaml compiler. In
  particular, messages where the excerpt line number started with a blank
  character were skipped. (ocaml/dune#5981, @rgrinberg)

- env stanza: warn if some rules are ignored because they appear after a
  wildcard rule. (ocaml/dune#5898, fixes ocaml/dune#5886, @emillon)

- On Windows, XDG_CACHE_HOME is taken to be the `FOLDERID_InternetCache` if
  unset, and XDG_CONFIG_HOME and XDG_DATA_HOME are both taken to be
  `FOLDERID_LocalAppData` if unset.  (ocaml/dune#5943, fixes ocaml/dune#5808, @nojb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"dune describe workspace" should work without executables as well
3 participants