Skip to content

fix(pkg): unify workspace and lockdir dependency traversal - #15636

Open
Alizter wants to merge 1 commit into
ocaml:mainfrom
Alizter:push-svuqwnmomsll
Open

fix(pkg): unify workspace and lockdir dependency traversal#15636
Alizter wants to merge 1 commit into
ocaml:mainfrom
Alizter:push-svuqwnmomsll

Conversation

@Alizter

@Alizter Alizter commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

Description

Dune currently computes dependency reachability separately for workspace
packages and lock-directory packages. This works only because locked packages
are currently forbidden from depending back on workspace packages. It cannot
represent a dependency path such as:

workspace a → locked b → workspace c

This refactor makes Package_universe own a single view of dependencies across
both package sets. Dependency queries and lock-directory reachability checks now
use that view, removing the assumption that dependency traversal ends after
entering the lock directory.

This does not yet permit lock-directory packages to depend on workspace
packages. Follow-up changes use this graph to produce dependency-first build
plans, reject cycles across the combined graph, and ultimately enable those
dependencies.

Existing valid lock directories produce the same dependency closures. The only
observable change is that querying a cycle between workspace packages no longer
raises an internal error; the following PR replaces this temporary tolerance
with a user-facing cycle diagnostic.

Related Issue and Motivation

This is the dependency-graph foundation for supporting lock-directory packages
that depend on workspace packages in #8652.

@Alizter
Alizter force-pushed the push-svuqwnmomsll branch 2 times, most recently from c21ac99 to 01cab0f Compare July 31, 2026 15:32
@rgrinberg

Copy link
Copy Markdown
Member

The fact that this change seems to remove a bunch of code without dropping functionality is good, but the description makes no sense. Can you rewrite it to something that describes what is accomplished without so much references to mechanical changes?

@Alizter Alizter changed the title refactor(pkg): traverse Package_universe as a single dependency graph refactor(pkg): unify workspace and lockdir dependency traversal Aug 3, 2026
@Alizter
Alizter marked this pull request as ready for review August 3, 2026 08:34
@Alizter
Alizter requested a review from rgrinberg August 3, 2026 08:34
@Alizter
Alizter force-pushed the push-svuqwnmomsll branch 2 times, most recently from 94962af to ce74cb1 Compare August 3, 2026 13:13
@Alizter Alizter changed the title refactor(pkg): unify workspace and lockdir dependency traversal fix(pkg): unify workspace and lockdir dependency traversal Aug 3, 2026
@Alizter
Alizter force-pushed the push-svuqwnmomsll branch from ce74cb1 to e0ac898 Compare August 4, 2026 07:33
Store the platform-filtered lock packages in the universe and compute
transitive closures with one reachability traversal over a combined
graph whose nodes are local packages (via their resolved dependency
formulas) and lock packages (via their platform-selected dependency
lists), instead of stitching a local-only closure onto
Lock_dir.transitive_dependency_closure.

The unnecessary-packages check is converted to the same traversal,
which leaves Lock_dir.transitive_dependency_closure without callers;
it is deleted together with Packages.choose_pkg_for_platform, which it
was the last user of. Caching the platform-filtered packages also
confines the platform projection of the package set to the universe
constructor instead of reprojecting at every consumer.

For valid input this preserves behaviour. Lock-directory packages
cannot name workspace packages, so from local roots the combined
traversal can only discover the local closure followed by the lockdir
closure of its non-local frontier: exactly the union the two-phase code
computed. Names that resolve to neither package map are leaves; the
previous code ignored them during lockdir traversal (dune,
platform-disabled packages) and its missing-seed Code_error was
unreachable for validated input.

For cyclic input the traversal is plain reachability, so dependency
cycles between workspace packages are now tolerated like lockdir
cycles instead of crashing the local-only closure with a Code_error,
as pinned by the updated lockdir-dependency-cycle test. Rejecting both
kinds of cycle properly is the subject of a follow-up commit.

Signed-off-by: Ali Caglayan <alizter@gmail.com>
@Alizter
Alizter force-pushed the push-svuqwnmomsll branch from e0ac898 to e5db0d5 Compare August 5, 2026 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants