feat: per-module library dependency filter via ocamldep BFS#14516
Open
robinbb wants to merge 1 commit into
Open
feat: per-module library dependency filter via ocamldep BFS#14516robinbb wants to merge 1 commit into
robinbb wants to merge 1 commit into
Conversation
This was referenced May 13, 2026
d3418da to
246a914
Compare
da056f0 to
a0893d7
Compare
246a914 to
d88da28
Compare
4e63363 to
4c95b95
Compare
8dcb05b to
60b92c8
Compare
48451fc to
e65efd4
Compare
60b92c8 to
dde100d
Compare
e65efd4 to
6fc605c
Compare
dde100d to
63c3651
Compare
6fc605c to
b95dd0f
Compare
63c3651 to
416e701
Compare
b95dd0f to
d5a41a6
Compare
416e701 to
1c1953d
Compare
d5a41a6 to
73246cc
Compare
robinbb
added a commit
that referenced
this pull request
May 23, 2026
Layer 3 of 9 of #14492. Behaviour-equivalent refactor. `Compilation_context.Includes.make` drops `~opaque` and stops emitting `Hidden_deps`; `Includes.t` carries only `-I`/`-H` flags. `Module_compilation.lib_deps_for_module` (scaffold form: always-glob) and `lib_cm_deps` wire the dep set back in via `deps_of_entries`. `build_cm` and `ocamlc_i` are switched to consume `lib_cm_deps`; `Alias` / `Wrapped_compat` short-circuit to the cctx's now-flag-only `Includes`. `Lib_file_deps.deps_with_exts` removed — only used by the old `Cmx` arm of `Includes.make`. Combined effect: same `-I` / `-H`, same lib file deps. Stack: rebases on #14514. Next: #14516. Part of #14492. Related to #4572. Signed-off-by: Robin Bate Boerop <me@robinbb.com>
Base automatically changed from
robinbb-14492-l3-includes-refactor
to
robinbb-14492-test-stack-integration
May 23, 2026 04:51
c8ab405 to
57f1c08
Compare
robinbb
added a commit
that referenced
this pull request
May 23, 2026
Layer 3 of 9 of #14492. Behaviour-equivalent refactor. `Compilation_context.Includes.make` drops `~opaque` and stops emitting `Hidden_deps`; `Includes.t` carries only `-I`/`-H` flags. `Module_compilation.lib_deps_for_module` (scaffold form: always-glob) and `lib_cm_deps` wire the dep set back in via `deps_of_entries`. `build_cm` and `ocamlc_i` are switched to consume `lib_cm_deps`; `Alias` / `Wrapped_compat` short-circuit to the cctx's now-flag-only `Includes`. `Lib_file_deps.deps_with_exts` removed — only used by the old `Cmx` arm of `Includes.make`. Combined effect: same `-I` / `-H`, same lib file deps. Stack: rebases on #14514. Next: #14516. Part of #14492. Related to #4572. Signed-off-by: Robin Bate Boerop <me@robinbb.com>
73246cc to
f156ea2
Compare
f156ea2 to
ec8180d
Compare
Activates the tight branch in [lib_deps_for_module]: a per-module BFS over the cross-library dependency graph (built from each lib's [ocamldep -modules] output, normalised through [build_lib_index]'s post-pp module map) produces the set of dep-lib modules actually referenced by the consumer module. The compile rule sees only those [.cmi]/[.cmx] files; sibling-module recompilations on unreferenced dep-lib cmi changes drop out. Include flags are still the cctx-wide [-I]/[-H] in this layer; the filtered include flags ship separately. Wrapped-lib soundness recovery, virtual-impl gating on the deps side, ppx-runtime force-glob, and the new soundness test fixtures ship in a follow-up — this commit leaves five existing cram tests broken ([auto-wrapped-child-reexport.t], [ppx-runtime-libraries.t], [virtual-library.t], [wrapped-closure-precision.t], [wrapped-reexport-via-open-flag.t]) that the soundness recovery restores. [Module_compilation]: - [union_module_name_sets_mapped]: parallel fold over a list of [Module_name.Set.t] producers. - [module_kind_is_filterable]: predicate excluding kinds whose dep story is handled outside the BFS ([Root], [Wrapped_compat], [Impl_vmodule], [Virtual], [Parameter]). - [cross_lib_tight_set]: BFS expanding through the lib_index's [(lib, entry)] pairs, reading each entry's impl + intf [ocamldep] output. Non-tight-eligible libs terminate chains. - [lib_deps_for_module]: replaces the scaffold body. A [can_filter] guard (consumer-side virtual / parameter, dummy dep graph, module kind, [Module.has m ~ml_kind]) falls back to glob; otherwise runs the BFS, classifies libs via [Lib_file_deps.Lib_index.filter_libs_with_modules], and emits specific-file deps for tight libs + glob deps for non-tight / unreached-non-eligible libs. Returns the cctx-wide [Includes]; filtered include flags follow in a later layer. [Compilation_context.create]: peek [direct_requires] / [hidden_requires] and pass [has_library_deps] to [Dep_rules.rules]. Single-module stanzas with library deps now produce real dep graphs (the filter needs them). [Dep_rules.rules]: gate the singleton short-circuit on [(not has_library_deps) || for_ = Melange]. Other singletons fall through to the full dep-graph build. [Ocaml_flags]: [extract_open_module_names] surfaces [-open Foo] references that ocamldep doesn't see; they join [BFS]'s initial frontier. [Virtual_rules]: [is_virtual_or_parameter] — true for virtual impls and parameter cctxs; used by [can_filter] to suppress per-module filtering on consumer cctxs whose dep story [Dep_rules] handles specially. [Parameterised_rules]: pass [~has_library_deps:true] to the [Dep_rules.rules] call; conservative — the dep-rules path here serves external parameterised libs whose dep set is built from generated sources. Tests: rebuild-precision promotions for the existing modified-test set in #14492 — cram outputs reflect the tighter dep / rebuild behavior that L4 already produces. New soundness test fixtures (and the two tests gated on filtered include flags, [per-module-include-flags.t] / [add-unreferenced-sibling-lib.t]) are deferred to their respective follow-ups. Signed-off-by: Robin Bate Boerop <me@robinbb.com>
ec8180d to
662e008
Compare
Comment on lines
+23
to
+29
| (* BFS over tight-eligible entries: each (lib, entry) pair's impl+intf ocamldep | ||
| names extend the frontier. Non-tight-eligible libs (wrapped locals, | ||
| externals, virtual-impls, staged-Pps libs) are skipped by | ||
| [lookup_tight_entries], terminating chains through them. The [Module.t] | ||
| supplied here is the post-pp form (constructed in [build_lib_index]), so | ||
| ocamldep runs on the dep lib's [.pp.ml] (action / non-staged Pps) or directly | ||
| on the source (no preprocessing / future-syntax). *) |
Comment on lines
+148
to
+155
| (* Classify each lib in [all_libs]: - lib has [None]-entry referenced | ||
| (mixed-entry or wrapped) → glob (covers the None entries' [.cmi]s); - | ||
| lib has only [Some] entries referenced → per-module deps; - lib | ||
| unreached but tight-eligible → drop (link rule pulls it in via | ||
| [requires_link]); - lib unreached and not tight-eligible → glob. | ||
| [kept_libs] gets every lib that contributes a tight or glob dep — used | ||
| by [Compilation_context.filtered_include_flags] to scope the consumer's | ||
| [-I]/[-H] flags. *) |
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.
Layer 4 of 9 of #14492. The core BFS. NOTE: this is the only layer that is expected to fail tests. This cannot be merged without layer 5.
Module_compilation.lib_deps_for_moduleactivates the tight branch: a per-module BFS over the cross-library dep graph (cross_lib_tight_set) computes the dep-lib modules the consumer actually references. The compile rule sees only those cmi/cmx files.can_filterfalls back to glob for Melange, dummy dep graphs, synthesised modules, non-filterable kinds, and consumer-side virtual / parameter cctxs.Dep_rules.rulesgates its singleton short-circuit on~has_library_deps || for_ = Melange.Compilation_context.createcomputes and passes the flag.Ocaml_flags.extract_open_module_namessurfaces-open Fooreferences for the BFS frontier.Virtual_rules.is_virtual_or_parameterpowers the consumer-sidecan_filtercheck.Parameterised_rulespasses~has_library_deps:trueto itsDep_rules.rulescall.Includes are still the cctx-wide
-I/-H; filtered include flags ship in layer 6. Soundness recovery for wrapped libs / ppx-runtime / virtual-impl deps ships in layer 5.Cram outputs across
per-module-lib-deps/reflect the tighter dep / rebuild behaviour L4 produces (e.g.singleton-with-requires.tflips from wide-glob to specific-cmi dep tracking,single-module-lib.t/transitive.t/lib-to-lib-*.tetc. drop unreferenced-lib cmi globs).melange-conditional-modules.t(outside per-module-lib-deps/) is also promoted: theDep_rules.ruleschange introduces one extraocamldep (internal)invocation and reordersmelc/ocamlcsteps in the build trace; the assertion accepts the new shape. A few unrelated test directories (reporting-of-cycles.t,strict-package-deps.t,watching/multiple-errors-output.t,inline-tests/alias-cycle.t,custom-cross-compilation/cross-compilation-ocamlfind.t) get promotions for the same reason — the new dep graph changes their traces.Five existing cram tests fail on this PR; layer 5's soundness recovery restores them without test file changes:
test/blackbox-tests/test-cases/per-module-lib-deps/auto-wrapped-child-reexport.ttest/blackbox-tests/test-cases/per-module-lib-deps/ppx-runtime-libraries.ttest/blackbox-tests/test-cases/per-module-lib-deps/virtual-library.ttest/blackbox-tests/test-cases/per-module-lib-deps/wrapped-closure-precision.ttest/blackbox-tests/test-cases/per-module-lib-deps/wrapped-reexport-via-open-flag.tStack: rebases on #14515. Next: #14517.
Part of #14492. Related to #4572.