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

regression (3.7): chamelon-unix.0.0.7 - dependency cycle between modules #7018

Closed
emillon opened this issue Feb 7, 2023 · 6 comments
Closed
Assignees
Labels
Milestone

Comments

@emillon
Copy link
Collaborator

emillon commented Feb 7, 2023

Hi,

chamelon-unix.0.0.7 does not build with 3.7.0~alpha1, though it does with 3.6.2.

The error is:

Error: dependency cycle between modules in _build/default/lib:
   Entry
-> Entry
-> required by _build/default/lib/chamelon.a
-> required by _build/install/default/lib/chamelon/chamelon.a
-> required by _build/default/chamelon.install
-> required by alias install

I bisected that to fb085c0 (#6594).
The dune file in lib does not seem to have any gotchas:

(library
  (public_name chamelon)
  (libraries checkseum cstruct ptime)
  (preprocess (pps ppx_cstruct))
)

This might be related to #7015 since it comes from the same feature but it's hard to tell.
@rgrinberg if you could have a look at this one too (or if you fix #7015 first I'm happy to check if that fixes this too).

Thanks!

@rgrinberg
Copy link
Member

I had a look and there's indeed a cycle:

$ ocamldep -modules dir.mli
dir.mli: Cstruct Entry Tag

$ ocamldep -modules entry.ml
entry.ml: Cstruct Dir File Int Int32 List Tag

Now I need to understand why we weren't detecting it before.

@rgrinberg
Copy link
Member

I guess the above isn't really a cycle. If we expand the dependency chain we get:

dir.mli -> entry.mli
entry.ml -> dir.mli -> entry.mli

rgrinberg added a commit that referenced this issue Feb 9, 2023
Demonstrate various types of module cycles that aren't cycles if we
separate the module interface and module implementation graphs

Signed-off-by: Rudi Grinberg <me@rgrinberg.com>

<!-- ps-id: c79b09d2-6b42-415e-a789-fda7340a29ad -->
rgrinberg added a commit that referenced this issue Feb 9, 2023
Demonstrate various types of module cycles that aren't cycles if we
separate the module interface and module implementation graphs

Signed-off-by: Rudi Grinberg <me@rgrinberg.com>

<!-- ps-id: c79b09d2-6b42-415e-a789-fda7340a29ad -->
rgrinberg added a commit that referenced this issue Feb 10, 2023
Demonstrate various types of module cycles that aren't cycles if we
separate the module interface and module implementation graphs

Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
@emillon emillon linked a pull request Feb 13, 2023 that will close this issue
@rgrinberg
Copy link
Member

I thought about this again and I'm no longer sure we need to fix a bug here. Our dependency algorithm was specified to be:

transitive_deps_of(M, Kind) =
  let deps = deps_of(M, Kind) in
  deps U transitive_deps_of(X, Intf) for X in deps

And chamelon violates this specification. We have:

dep(impl, entry, [dir]).
dep(intf, entry, []).

dep(impl, dir, []).
dep(intf, dir, [entry]).

So when we compute transitive_deps_of(impl, entry), we clearly get a cycle.

The only reason why this works is that dir.mli is only using a type alias defined in entry.mli. But I don't see how can we detect this in general.

@emillon
Copy link
Collaborator Author

emillon commented Feb 16, 2023

OK. I think that it makes sense. Since the latest version of chamelon is affected, I sent a PR to fix this: yomimono/chamelon#18.
Semgrep is also affected (in the commons library), I'll try to make a fix too.

@emillon
Copy link
Collaborator Author

emillon commented Feb 16, 2023

I did the same for commons which was similarly affected: semgrep/semgrep#7173. And I'll add upper bounds in opam-repository.

@emillon
Copy link
Collaborator Author

emillon commented Feb 16, 2023

If there's nothing to fix, let's close this one then. Thanks

@emillon emillon closed this as completed Feb 16, 2023
emillon added a commit to emillon/opam-repository that referenced this issue Feb 20, 2023
Two packages got broken by dune 3.7: commons and chamelon. They were
relying on behavior in dune's dependency cycle detection that we
classified as a bug (see ocaml/dune#7018).

Since the latest versions are affected, we sent patches upstream:
yomimono/chamelon#18, semgrep/semgrep#7173.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants