Skip to content

scaffold: thread Lib_index, has_virtual_impl, pps_runtime_libs through cctx#14514

Draft
robinbb wants to merge 3 commits into
robinbb-14492-test-stack-integrationfrom
robinbb-14492-l2-cctx-fields
Draft

scaffold: thread Lib_index, has_virtual_impl, pps_runtime_libs through cctx#14514
robinbb wants to merge 3 commits into
robinbb-14492-test-stack-integrationfrom
robinbb-14492-l2-cctx-fields

Conversation

@robinbb
Copy link
Copy Markdown
Collaborator

@robinbb robinbb commented May 13, 2026

Layer 2 of 9 of #14492.

Threads lib_index, has_virtual_impl, and pps_runtime_libs through Compilation_context.t. Adds build_lib_index (constructs the Lib_index from the cctx's libs, indexing on post-pp modules for non-staged-ppx local libs). Wires pps_runtime_libs at Lib_rules / Exe_rules call sites. Exposes Dep_graph.dir / mem for layer 4's can_filter guard. Adds Modules.as_singleton.

Fields are populated but never read; consumers arrive in layer 4.

Stack: rebases on main (L1 merged in #14513). Next: #14515.

Part of #14492. Related to #4572.

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

This PR scaffolds dependency-filtering data through Compilation_context.t for later layers of the inter-library per-module dependency work.

Changes:

  • Adds lib_index, has_virtual_impl, and pps_runtime_libs to compilation contexts.
  • Builds a Lib_file_deps.Lib_index from direct/hidden library dependencies.
  • Exposes small helper APIs on Modules and Dep_graph.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/dune_rules/modules.mli Exposes Modules.as_singleton.
src/dune_rules/modules.ml Implements singleton detection for module sets.
src/dune_rules/lib_rules.ml Passes PPX runtime libraries into library compilation contexts.
src/dune_rules/exe_rules.ml Passes PPX runtime libraries into executable compilation contexts.
src/dune_rules/dep_graph.mli Exposes dependency graph directory and membership helpers.
src/dune_rules/dep_graph.ml Implements dependency graph directory and membership helpers.
src/dune_rules/compilation_context.mli Adds accessors for lib index, virtual implementation status, and PPX runtime libraries.
src/dune_rules/compilation_context.ml Stores new context fields and constructs the library dependency index.

Comment thread src/dune_rules/compilation_context.ml
Comment thread src/dune_rules/compilation_context.ml Outdated
Comment thread src/dune_rules/compilation_context.ml Outdated
Comment thread src/dune_rules/compilation_context.ml
@robinbb robinbb force-pushed the robinbb-14492-l2-cctx-fields branch 3 times, most recently from 7459ded to 22fcd5f Compare May 14, 2026 00:28
@robinbb robinbb requested a review from Copilot May 14, 2026 00:28
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

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Comment thread src/dune_rules/compilation_context.ml Outdated
@robinbb robinbb marked this pull request as ready for review May 14, 2026 00:51
Alizter added a commit that referenced this pull request May 14, 2026
#14513)

Layer 1 of 9 stacked PRs reconstructing #14492 in reviewable layers.

Adds the dataflow infrastructure subsequent layers consume —
`Lib_file_deps.Lib_index`, `deps_of_entries`, `deps_of_entry_modules`,
`Ocamldep.read_immediate_deps_words` (top-level cache keyed on (source
path, ml_kind)), and `Ocamldep.read_immediate_deps_raw_of`. No consumer
yet.

Stack: this PR → main. Next: #14514.

Part of #14492. Related to #4572.
Base automatically changed from robinbb-14492-l1-lib-index-infra to main May 14, 2026 11:16
@robinbb robinbb force-pushed the robinbb-14492-l2-cctx-fields branch 2 times, most recently from 0dfddde to 2d4b53c Compare May 14, 2026 18:37
@robinbb robinbb requested a review from Copilot May 14, 2026 18:37
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

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Comment thread src/dune_rules/lib_rules.ml
Comment thread src/dune_rules/exe_rules.ml
@robinbb robinbb force-pushed the robinbb-14492-l2-cctx-fields branch from 2d4b53c to 87a2380 Compare May 14, 2026 19:07
@robinbb robinbb requested a review from Copilot May 14, 2026 19:08
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

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

@robinbb robinbb marked this pull request as draft May 18, 2026 17:14
@robinbb robinbb force-pushed the robinbb-14492-l2-cctx-fields branch 2 times, most recently from 82bc32c to 7f288f7 Compare May 18, 2026 18:03
@robinbb robinbb changed the base branch from main to robinbb-14492-test-stack-integration May 18, 2026 18:06
@robinbb robinbb force-pushed the robinbb-14492-test-stack-integration branch from 24149c4 to 009d755 Compare May 18, 2026 20:54
@robinbb robinbb force-pushed the robinbb-14492-l2-cctx-fields branch from 7f288f7 to a8de106 Compare May 18, 2026 22:17
@robinbb robinbb force-pushed the robinbb-14492-test-stack-integration branch from 009d755 to bfe8f31 Compare May 18, 2026 22:54
@robinbb robinbb force-pushed the robinbb-14492-l2-cctx-fields branch from a8de106 to 5cee98e Compare May 18, 2026 22:54
@robinbb robinbb force-pushed the robinbb-14492-test-stack-integration branch from bfe8f31 to c06fc6c Compare May 18, 2026 23:17
@robinbb robinbb force-pushed the robinbb-14492-l2-cctx-fields branch from 5cee98e to 1e5dfd1 Compare May 18, 2026 23:17
@robinbb robinbb marked this pull request as ready for review May 19, 2026 00:09
Comment thread src/dune_rules/compilation_context.mli Outdated
@robinbb robinbb marked this pull request as draft May 19, 2026 17:52
robinbb added a commit that referenced this pull request May 19, 2026
The optional argument with default [Resolve.Memo.return []] hid
the silent-wrongness Alizter flagged on #14514: a new caller that
forgets to pass [~pps_runtime_libs] would silently drop ppx
runtime libs from the must-glob set under narrowing.

Make the parameter required. The five sites without a meaningful
pps_runtime_libs to compute (ppx_driver, utop, mdx, inline_tests,
melange) now pass [Resolve.Memo.return []] explicitly, documenting
the absence at the call site rather than at the API.

Melange compile rules bypass narrowing today (`can_filter = false`
in module_compilation.ml), so the explicit empty preserves prior
behaviour. utop's pps surface (collected from in-scope libraries)
could in principle carry runtime libs; treat this as a separate
follow-up rather than papering over via API.

Signed-off-by: Robin Bate Boerop <me@robinbb.com>
@robinbb robinbb force-pushed the robinbb-14492-l2-cctx-fields branch from 1e5dfd1 to b5c7e42 Compare May 19, 2026 19:11
robinbb added 3 commits May 19, 2026 13:06
…h cctx

Pure-additive scaffolding for #4572's per-module inter-library filter.
Fields are populated but no consumer reads them yet; the per-module
filter (which is the only caller) lands in a follow-up.

[Compilation_context]:
- [build_lib_index]: builds a [Lib_file_deps.Lib_index.t] from the cctx's
  direct + hidden libs. Each entry carries [Some Module.t] for unwrapped
  locals (tight-eligible) and [None] otherwise (wrapped locals / externals).
  Local libs whose source is preprocessed by a non-staged ppx are indexed
  on the post-pp module so the cross-lib walker reads ocamldep on the
  same source the dep lib's compile pipeline produces.
- Three new fields on [t]: [lib_index] (Memo.Lazy.t computing the index),
  [has_virtual_impl] (Memo.Lazy.t flag — true iff any dep lib implements
  a virtual lib), and [pps_runtime_libs] (closure of ppx_runtime_libraries
  introduced by [pps] in this stanza, threaded through [create]).
- Accessors for each. [for_module_generated_at_link_time] populates
  [lib_index] with a [Code_error.raise] sentinel — the per-module filter's
  [can_filter] guard prevents reaching it from synthesised link-time cctxs.

[Lib_rules] / [Exe_rules]: compute [pps_runtime_libs] from the stanza's
[compile_info] and thread it through [Compilation_context.create].

[Dep_graph]: expose [dir] and [mem]; the cross-lib walker's [can_filter]
guard uses these to detect synthesised dummy graphs.

[Modules]: add [as_singleton] returning [Some m] iff the module set is a
single user-written module. Used by [build_lib_index] to detect the
single-module-no-deps short-circuit case.

Signed-off-by: Robin Bate Boerop <me@robinbb.com>
The cinaps and toplevel `Compilation_context.create` call sites
omit the new `?pps_runtime_libs` field, leaving it at the default
`Resolve.Memo.return []`. Under the per-module narrowing
introduced later in the stack, this silently drops ppx runtime
libs from `must_glob_libs`, producing missing `.cmi` globs in the
stanzas' compile rules.

Compute and pass it via the same `Lib.Compile.pps` +
`Lib.ppx_runtime_deps` pattern used in `exe_rules.ml` and
`lib_rules.ml`. Melange bypasses narrowing (`can_filter = false`)
so it keeps the optional default and is unaffected today.

Signed-off-by: Robin Bate Boerop <me@robinbb.com>
The optional argument with default [Resolve.Memo.return []] hid
the silent-wrongness Alizter flagged on #14514: a new caller that
forgets to pass [~pps_runtime_libs] would silently drop ppx
runtime libs from the must-glob set under narrowing.

Make the parameter required. The five sites without a meaningful
pps_runtime_libs to compute (ppx_driver, utop, mdx, inline_tests,
melange) now pass [Resolve.Memo.return []] explicitly, documenting
the absence at the call site rather than at the API.

Melange compile rules bypass narrowing today (`can_filter = false`
in module_compilation.ml), so the explicit empty preserves prior
behaviour. utop's pps surface (collected from in-scope libraries)
could in principle carry runtime libs; treat this as a separate
follow-up rather than papering over via API.

Signed-off-by: Robin Bate Boerop <me@robinbb.com>
@robinbb robinbb force-pushed the robinbb-14492-test-stack-integration branch from dbec1d3 to 686951f Compare May 19, 2026 20:08
@robinbb robinbb force-pushed the robinbb-14492-l2-cctx-fields branch from b5c7e42 to c0de663 Compare May 19, 2026 20:08
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.

3 participants