Skip to content

feat: per-module [-I]/[-H] include flags via [kept_libs]#14518

Draft
robinbb wants to merge 1 commit into
robinbb-14492-l5-soundnessfrom
robinbb-14492-l6-filtered-include-flags
Draft

feat: per-module [-I]/[-H] include flags via [kept_libs]#14518
robinbb wants to merge 1 commit into
robinbb-14492-l5-soundnessfrom
robinbb-14492-l6-filtered-include-flags

Conversation

@robinbb
Copy link
Copy Markdown
Collaborator

@robinbb robinbb commented May 13, 2026

Layer 6 of 9 of #14492.

Compilation_context.filtered_include_flags: new function returning -I / -H flags restricted to kept_libs. The cctx's requires_compile and requires_hidden are each filtered by Lib.Set.mem kept_libs. No caching yet — layer 7 adds it.

Module_compilation.lib_deps_for_module: the tight branch was already producing kept_libs (unused at layers 4–5); now wired into filtered_include_flags. Returns the filtered include args instead of the cctx-wide Includes.

Effect: a consumer's compile command sees -I / -H only for libraries its ocamldep reference set actually reaches. Adding an unreferenced sibling to the cctx's (libraries ...) no longer changes the compile command, so the rule does not re-execute.

Promotes per-module-include-flags.t and add-unreferenced-sibling-lib.t — both deferred from layer 4 because their assertions depend on this filter.

Stack: rebases on #14517. Next: #14519.

Part of #14492. Related to #4572.

@robinbb robinbb self-assigned this May 13, 2026
@robinbb robinbb force-pushed the robinbb-14492-l5-soundness branch from c82233e to 0373a72 Compare May 14, 2026 00:35
@robinbb robinbb force-pushed the robinbb-14492-l6-filtered-include-flags branch from c50afa4 to 38a7871 Compare May 14, 2026 00:36
@robinbb robinbb force-pushed the robinbb-14492-l5-soundness branch from 0373a72 to a94a5c6 Compare May 15, 2026 02:57
@robinbb robinbb force-pushed the robinbb-14492-l6-filtered-include-flags branch from 38a7871 to 8634a30 Compare May 15, 2026 02:57
@robinbb robinbb force-pushed the robinbb-14492-l5-soundness branch 4 times, most recently from 8655699 to e0a6cdf Compare May 20, 2026 01:14
@robinbb robinbb force-pushed the robinbb-14492-l6-filtered-include-flags branch from 8634a30 to 323cf88 Compare May 20, 2026 01:14
@robinbb robinbb force-pushed the robinbb-14492-l5-soundness branch from e0a6cdf to 6a96f3d Compare May 20, 2026 20:35
@robinbb robinbb force-pushed the robinbb-14492-l6-filtered-include-flags branch from 323cf88 to b8bba4b Compare May 20, 2026 20:41
@robinbb robinbb force-pushed the robinbb-14492-l5-soundness branch from 6a96f3d to 90b06f8 Compare May 21, 2026 01:34
@robinbb robinbb force-pushed the robinbb-14492-l6-filtered-include-flags branch from b8bba4b to c73a510 Compare May 21, 2026 01:34
@robinbb robinbb force-pushed the robinbb-14492-l5-soundness branch 2 times, most recently from bd0ca68 to 37cc59a Compare May 22, 2026 02:05
@robinbb robinbb force-pushed the robinbb-14492-l6-filtered-include-flags branch from c73a510 to d12a8e5 Compare May 22, 2026 02:05
@robinbb robinbb force-pushed the robinbb-14492-l5-soundness branch from 37cc59a to fca9936 Compare May 23, 2026 05:18
@robinbb robinbb force-pushed the robinbb-14492-l6-filtered-include-flags branch from d12a8e5 to 9dfc6ed Compare May 23, 2026 05:18
@robinbb robinbb force-pushed the robinbb-14492-l5-soundness branch from fca9936 to a7491f0 Compare May 23, 2026 20:36
[Compilation_context.filtered_include_flags]: new function returning the
[-I]/[-H] flags restricted to [kept_libs]. The cctx's [requires_compile]
and [requires_hidden] are each filtered by [Lib.Set.mem kept_libs]; the
result is built as a single [Command.Args.t] under [Action_builder]. No
caching yet — each call recomputes; a follow-up adds the cache.

[Module_compilation.lib_deps_for_module]: the tight branch was already
threading [kept_libs] through the classification fold (it had been
unused at L4-L5). Now wired into [filtered_include_flags]; the returned
pair is [(filtered_include_flags, tight_deps + glob_deps)] instead of
[(cctx_includes_for_cm_kind (), …)].

Behavioural effect: a consumer module's compile command sees [-I] /
[-H] only for libraries its ocamldep reference set actually reaches.
Adding an unreferenced sibling to the cctx's [(libraries ...)] no
longer changes the consumer module's compile command, so the rule does
not re-execute.

Tests:
- [per-module-include-flags.t]: promoted — [-I] for the unreferenced
  [unrelated_lib] no longer appears in the consumer's compile rule.
- [add-unreferenced-sibling-lib.t]: promoted — adding an unreferenced
  sibling lib produces no rebuild for consumer modules.

Signed-off-by: Robin Bate Boerop <me@robinbb.com>
@robinbb robinbb force-pushed the robinbb-14492-l5-soundness branch from a7491f0 to 929749a Compare May 23, 2026 21:24
@robinbb robinbb force-pushed the robinbb-14492-l6-filtered-include-flags branch from 9dfc6ed to 1c8148e Compare May 23, 2026 21:24
@robinbb robinbb requested a review from Copilot May 23, 2026 21:24
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds per-module filtering of OCaml include flags so compile rules only see -I/-H for libraries actually reached by that module’s ocamldep reference set (via kept_libs), reducing unnecessary rule cache invalidations/rebuilds when unrelated sibling libraries are present in (libraries ...).

Changes:

  • Introduce Compilation_context.filtered_include_flags to compute -I/-H restricted to a Lib.Set.t of “kept” libraries.
  • Wire Module_compilation.lib_deps_for_module to use kept_libs to produce per-module include args (instead of cctx-wide includes) alongside the deps set.
  • Promote/adjust blackbox tests to assert the new per-module include-flag behavior and the resulting no-rebuild trace when adding an unreferenced sibling lib.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/blackbox-tests/test-cases/per-module-lib-deps/per-module-include-flags.t Updates expectations so only the referenced dep library’s objdir appears in -I flags.
test/blackbox-tests/test-cases/per-module-lib-deps/add-unreferenced-sibling-lib.t Updates expectations to assert no rebuild occurs when adding an unreferenced library to (libraries ...).
src/dune_rules/module_compilation.ml Uses kept_libs to request per-module include flags via Compilation_context.filtered_include_flags.
src/dune_rules/compilation_context.mli Exposes the new filtered_include_flags API with documentation describing kept_libs semantics.
src/dune_rules/compilation_context.ml Implements filtered_include_flags by filtering requires_compile/requires_hidden against kept_libs and generating -I/-H.

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.

2 participants