Skip to content

test: regression guard for include-flag soundness through pre-pp entry - #14435

Merged
shonfeder merged 3 commits into
ocaml:mainfrom
robinbb:robinbb-test-cross-lib-walk-pre-pp-implicit-transitive
May 9, 2026
Merged

test: regression guard for include-flag soundness through pre-pp entry#14435
shonfeder merged 3 commits into
ocaml:mainfrom
robinbb:robinbb-test-cross-lib-walk-pre-pp-implicit-transitive

Conversation

@robinbb

@robinbb robinbb commented May 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds a cross-library cram test: a consumer reaches a transitive type only through a preprocessed library's .mli, where the type is never syntactically named in the consumer's source.

Three libraries:

  • other_dep — unwrapped, exposes type t = { x : int; y : string }.
  • pp_dep — unwrapped + preprocessed, depends on other_dep, exposes val make_thing : unit -> Other.t.
  • consumer — depends on pp_dep, accesses (D.make_thing ()).x.

consumer/c.ml never mentions Other, but the field access forces the type checker to load other.cmi. The test asserts dune build @check succeeds.

Sibling to #14400's cross-lib-walk-pre-pp-source.t. That test exercises behaviour at a preprocessed entry directly; this one exercises the transitive leg — where the preprocessed entry's .mli re-exports a type from a deeper library.

The cross-library walker stops at preprocessed entry modules
because ocamldep on the pre-pp source can fail (the neighbour
test [cross-lib-walk-pre-pp-source.t] guards that stopping
behaviour). When the preprocessed module's [.mli] mentions a
type from another library, the walker cannot observe the link.
Any per-module filtering of include flags must be conservative
enough to keep that other library's [-I]/[-H] on the consumer's
compile rule.

The test wires [other_dep] -> [pp_dep] -> [consumer]: [other_dep]
is unwrapped with a record type [Other.t]; [pp_dep] is unwrapped
+ preprocessed and exposes [val make_thing : unit -> Other.t];
the consumer destructures [.x] without ever naming [Other]. The
field access forces the type checker to load [other.cmi], so a
narrower include filter that drops [other_dep] makes the build
fail.

Signed-off-by: Robin Bate Boerop <me@robinbb.com>
@robinbb robinbb self-assigned this May 6, 2026
@robinbb
robinbb requested a review from Copilot May 6, 2026 05:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a new blackbox (cram) regression test to ensure Dune’s per-module dependency/include-flag logic remains conservative when a consumer only becomes dependent on a transitive library via a preprocessed library’s .mli—even if the consumer never syntactically mentions the transitive module.

Changes:

  • Introduces a new cross-library test case covering an “implicit transitive through pre-pp entry” path not exercised by existing tests.
  • Sets up three small libraries (other_deppp_dep (preprocessed) → consumer) and asserts dune build @check succeeds when the consumer forces loading the transitive .cmi via record-field access.

@robinbb
robinbb requested a review from Alizter May 7, 2026 18:21
@robinbb

robinbb commented May 7, 2026

Copy link
Copy Markdown
Collaborator Author

@Alizter I'm adding you as a reviewer since you looked at the "sibling" test in #14400.

@robinbb
robinbb marked this pull request as ready for review May 7, 2026 18:23

@shonfeder shonfeder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Despite several rereads, I'm having trouble understanding what is meant to be tested or demonstrated here.

It's possible some time rewording the description would help, or just that I don't have enough prior context to follow along clearly. My suggestions are superficial, and while I can approve to merge the test (which is passing, so doesn't do any harm), you may want to get a review from someone who understands the context better, or try rewording to make it easier for someone in my position to digest!

Replaces the inline OCaml helper executable with `(action (run cat
%{input-file}))`, matching the convention established in
`test/blackbox-tests/test-cases/include-qualified/pp-github6866.t` and
`pp.t/dune`. The walker only cares that some preprocess action is
declared on the entry module; the pass-through's contents are
irrelevant.

Signed-off-by: Robin Bate Boerop <me@robinbb.com>
@robinbb robinbb assigned shonfeder and unassigned Alizter May 9, 2026
@robinbb
robinbb removed the request for review from Alizter May 9, 2026 02:00
Rewrite the test's prose so a reader without prior context can
follow what is set up and why the assertion is non-trivial.

Lead with the concrete three-library scenario before explaining
why dune cannot observe the dependency. Drop "tight" /
"tight-eligible" terminology that has no meaning in the context
of this test, drop the parenthetical "(used to compute
per-module dependency sets)", and trim the per-block prose now
that the header carries the load.

Signed-off-by: Robin Bate Boerop <me@robinbb.com>
@robinbb

robinbb commented May 9, 2026

Copy link
Copy Markdown
Collaborator Author

@shonfeder, thanks for the careful read; your trouble understanding is fair signal that the prose wasn't doing its job.

Reworked the test on the latest commits:

  • Header now leads with the concrete three-library scenario (what each lib does, what the consumer touches, what would fail) before explaining why dune cannot observe the dependency.
  • Dropped "tight"/"tight-eligible" jargon (carryover from feat: per-module inter-library dependency filtering (#4572) #14116) that has no meaning in this PR.
  • Trimmed per-block prose now that the header carries the load.
  • Replaced the inline OCaml pass-through preprocessor with (action (run cat %{input-file})) per your other comment.

If it still doesn't read clearly, please push back — happy to keep iterating.

Copilot AI left a comment

Copy link
Copy Markdown

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 1 out of 1 changed files in this pull request and generated no new comments.

@shonfeder shonfeder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This reads much clearer now! Everything makes sense to me, up to limit of my knowledge. Thanks :)

@shonfeder
shonfeder merged commit cb122ec into ocaml:main May 9, 2026
34 checks passed
@robinbb
robinbb deleted the robinbb-test-cross-lib-walk-pre-pp-implicit-transitive branch May 9, 2026 15:36
@Alizter Alizter added this to the 3.24.0 milestone Jul 8, 2026
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.

4 participants