Skip to content

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

Open
robinbb wants to merge 1 commit into
mainfrom
robinbb-14492-l2-cctx-fields
Open

scaffold: thread Lib_index, has_virtual_impl, pps_runtime_libs through cctx#14514
robinbb wants to merge 1 commit into
mainfrom
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
@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
…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>
@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.

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