Skip to content

test: regression guard for menhir mock-compile + sibling-module incremental rebuild on lib-cmi change#14479

Open
robinbb wants to merge 2 commits into
ocaml:mainfrom
robinbb:robinbb-test-menhir-incremental-lib-cmi
Open

test: regression guard for menhir mock-compile + sibling-module incremental rebuild on lib-cmi change#14479
robinbb wants to merge 2 commits into
ocaml:mainfrom
robinbb:robinbb-test-menhir-incremental-lib-cmi

Conversation

@robinbb
Copy link
Copy Markdown
Collaborator

@robinbb robinbb commented May 10, 2026

Summary

Adds test/blackbox-tests/test-cases/per-module-lib-deps/menhir-incremental-lib-cmi.t, a regression guard for two incremental-rebuild invariants on a library that combines a menhir grammar with a sibling module, both referencing types/values from a (libraries ...) dep:

  1. The menhir --infer mock-compile (grammar__mock.mli.inferred) rebuilds when the dep's .cmi changes.
  2. The sibling module's .cmo rebuilds when the dep's .cmi changes.

The mock-compile path (menhir_rules.ml) derives a sandboxed cctx via Compilation_context.set_sandbox for the ocamlc -i action. The test asserts the two invariants independently and does not pin the full set of rebuilt artefacts, so it stays robust under cctx-wide-vs-per-module dep filtering.

…mental rebuild on lib-cmi change

When a library declares a menhir grammar whose semantic action references
types or values from a [(libraries ...)] dep, dune emits two compile rules
whose deps cover that library's cmis: menhir's [--infer] mock-compile
(which runs [ocamlc -i] on a generated mock module to type-check the
grammar's semantic actions) and the regular sibling-module compile that
also references the dep. Both rules must invalidate when the dep's
interface changes.

The menhir mock-compile path ([menhir_rules.ml]) derives a sandboxed cctx
via [Compilation_context.set_sandbox] for the [ocamlc -i] action. The
test asserts the two invariants independently — the mock-compile rebuilds
and the helper [.cmo] rebuilds — without pinning the exact set of
rebuilt artefacts, so it is robust to whether the surrounding code uses
cctx-wide-glob or per-module-filtered cmi-deps.

Surfaced during review of ocaml#14474.

Signed-off-by: Robin Bate Boerop <me@robinbb.com>
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 a new blackbox regression test to ensure Dune’s incremental rebuild logic correctly invalidates both Menhir’s --infer mock-compile and a regular sibling module compilation when a dependent library’s .cmi changes (covering the sandboxed cctx path used by the mock-compile).

Changes:

  • Add a new blackbox test case that builds a Menhir + sibling-module library depending on a sibling dep library.
  • Assert the Menhir ocamlc -i mock-compile runs and includes dep’s objdir on its -I path.
  • After changing dep’s interface, assert both the mock-compile inferred .mli and the sibling module’s .cmo are rebuilt.

Comment thread test/blackbox-tests/test-cases/per-module-lib-deps/menhir-incremental-lib-cmi.t Outdated
The previous single composite query
([{target: .target_files[0], dep_in_args: any(. == "dep/.dep.objs/byte")}])
relied on (1) [target_files] being a singleton (indexing [[0]]
silently masks regressions if a future dune change adds extra
targets) and (2) exact-string match against the dep objdir
spelling (brittle to path-rendering changes).

Replace with two separate queries, mirroring the pattern used by
[test-cases/menhir/with-library-deps.t]:
- one query asserts the mock-compile's full [target_files] array;
- the other filters [process_args] for entries [startswith("dep/")].

Robust to multiple [target_files] entries and to dune path-rendering
changes.

Addresses Copilot review at
ocaml#14479 (comment).

Signed-off-by: Robin Bate Boerop <me@robinbb.com>
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 1 out of 1 changed files in this pull request and generated no new comments.

@robinbb robinbb marked this pull request as ready for review May 10, 2026 20:20
@robinbb robinbb requested a review from Alizter May 12, 2026 04:39
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