feat: per-module inter-library dependency filtering (#4572)#14116
Draft
robinbb wants to merge 4 commits intoocaml:mainfrom
Draft
feat: per-module inter-library dependency filtering (#4572)#14116robinbb wants to merge 4 commits intoocaml:mainfrom
robinbb wants to merge 4 commits intoocaml:mainfrom
Conversation
…lds (ocaml#4572) Add baseline tests documenting existing behavior: - lib-deps-preserved: every non-alias module declares glob deps on its library dependencies' .cmi files - sandbox-lib-deps: sandboxed package builds have dependency libraries' .cmi files available when a library depends on another library Signed-off-by: Robin Bate Boerop <me@robinbb.com>
Add baseline test verifying that incremental builds succeed when a module re-exports a library via a transparent alias (module M = Mylib) and the library's interface changes. Regression reported by @Alizter. Signed-off-by: Robin Bate Boerop <me@robinbb.com>
Add baseline test showing that single-module library consumers are recompiled when an unused module in a dependency changes. This happens because dune skips ocamldep for singleton stanzas, preventing future per-module filtering from determining which libraries the module actually references. Signed-off-by: Robin Bate Boerop <me@robinbb.com>
15c3919 to
2b4ab03
Compare
2b4ab03 to
e273290
Compare
…caml#4572) Use the already-computed ocamldep output to filter inter-library dependencies on a per-module basis. Each module now only depends on .cmi/.cmx files from libraries it actually imports, rather than glob deps on all files from all dependent libraries. This eliminates unnecessary recompilation when a module in a dependency changes but the current module doesn't reference that library. The implementation: - Add read_immediate_deps_raw_of to ocamldep, returning raw module names without filtering against the stanza's module set - Move Hidden_deps from Includes (library-wide) to per-module in build_cm - Add Lib_index mapping module names to libraries, computed from requires_compile and requires_hidden - In build_cm, use ocamldep output + Lib_index to determine which libraries each module actually needs; fall back to all-library glob deps when filtering is not possible (Melange, virtual library implementations, singleton stanzas, alias/root modules) - For local unwrapped libraries, use per-file deps on specific .cmi/.cmx files rather than directory-wide globs Signed-off-by: Robin Bate Boerop <me@robinbb.com>
e273290 to
31ab29b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Use the already-computed
ocamldepoutput to filter inter-librarydependencies on a per-module basis, resolving #4572.
Previously, when
libAdepends onlibB, every module oflibAgot aglob dependency on all
.cmifiles inlibB. Now each module onlydepends on
.cmi/.cmxfiles from libraries it actually imports,eliminating unnecessary recompilation.
(was 2)
recompilations (was 2), via per-file deps on individual
.cmifilesmodule M = Mylib): correctly propagatedto conservative glob deps
Known limitations
dyn_depsexploring dependency paths differently. These needinvestigation.
this can be addressed in a follow-up.
Test plan
dune build @checkpassesper-module-lib-deps/tests pass (13 tests)lib-deps-preserved.t,transparent-alias.t,sandbox-lib-deps.t,single-module-lib.tedge cases
Ref: #4572