-
Notifications
You must be signed in to change notification settings - Fork 474
test: regression guard for menhir mock-compile + sibling-module incremental rebuild on lib-cmi change #14479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
robinbb
merged 4 commits into
ocaml:main
from
robinbb:robinbb-test-menhir-incremental-lib-cmi
May 14, 2026
+124
−0
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f996e4d
test: regression guard for menhir mock-compile + sibling-module incre…
robinbb b3a7de6
test: split mock-compile assertion into two robust jq queries
robinbb ae48cac
test: polish per cram-test-tips and Alizter suggestions
robinbb 5ec3fa0
test: surface mock-compile rule deps via `dune rules --deps`
robinbb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
123 changes: 123 additions & 0 deletions
123
test/blackbox-tests/test-cases/per-module-lib-deps/menhir-incremental-lib-cmi.t
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| Regression guard for menhir mock-compile and sibling module | ||
| incremental rebuild when a sibling library's interface changes. | ||
|
|
||
| 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. | ||
|
|
||
| This test pins the property. The menhir mock-compile path | ||
| ([menhir_rules.ml]) derives a sandboxed cctx via | ||
| [Compilation_context.set_sandbox]; if a future change to the | ||
| dep-graph machinery weakens cross-rule invalidation along that path | ||
| (e.g., by sharing cached dep-info builders across cctxs in a | ||
| sandbox-dependent way), this test surfaces the regression. | ||
|
|
||
| $ cat > dune-project <<EOF | ||
| > (lang dune 3.23) | ||
| > (using menhir 3.0) | ||
| > EOF | ||
|
|
||
| [dep] is a sibling library exposing a value the parent library's | ||
| menhir grammar will reference. | ||
|
|
||
| $ mkdir dep | ||
| $ cat > dep/dune <<EOF | ||
| > (library (name dep)) | ||
| > EOF | ||
| $ cat > dep/dep.ml <<EOF | ||
| > let value = 42 | ||
| > EOF | ||
| $ cat > dep/dep.mli <<EOF | ||
| > val value : int | ||
| > EOF | ||
|
|
||
| [parser]: a library with a menhir grammar whose semantic action | ||
| references [Dep.value], plus a sibling module [helper] that also | ||
| references [Dep.value]. | ||
|
|
||
| $ mkdir parser | ||
| $ cat > parser/dune <<EOF | ||
| > (library | ||
| > (name parser) | ||
| > (libraries dep)) | ||
| > (menhir (modules grammar)) | ||
| > EOF | ||
| $ cat > parser/grammar.mly <<EOF | ||
| > %token EOF | ||
| > %start <int> main | ||
| > %% | ||
| > main: EOF { Dep.value } | ||
| > EOF | ||
| $ cat > parser/helper.ml <<EOF | ||
| > let echo () = Dep.value | ||
| > EOF | ||
| $ cat > parser/helper.mli <<EOF | ||
| > val echo : unit -> int | ||
| > EOF | ||
|
|
||
| Initial build. | ||
|
|
||
| $ dune build @check 2>&1 | head -20 | ||
|
|
||
| The mock-compile invocation is recognisable by [-i] in its argv; | ||
| its target is [grammar__mock.mli.inferred]. The presence of this | ||
| event positively asserts the [--infer] code path ran: | ||
|
|
||
| $ dune trace cat | jq -s 'include "dune"; [.[] | progMatching("ocamlc") | select(.process_args | index("-i") != null) | .target_files]' | ||
| [ | ||
| [ | ||
| "_build/default/parser/grammar__mock.mli.inferred" | ||
| ] | ||
| ] | ||
|
|
||
| The mock's [-I] path includes [dep]'s objdir, so the grammar's | ||
| semantic action type-checks against [dep]: | ||
|
|
||
| $ dune trace cat | jq -s 'include "dune"; [.[] | progMatching("ocamlc") | select(.process_args | index("-i") != null) | .process_args | [.[] | select(startswith("dep/"))]]' | ||
| [ | ||
| [ | ||
| "dep/.dep.objs/byte" | ||
| ] | ||
| ] | ||
|
|
||
| Modify [dep]'s interface (add a value). Both consumers — the | ||
| menhir mock-compile and [helper]'s [.cmo] — must invalidate. | ||
|
|
||
| $ cat > dep/dep.mli <<EOF | ||
| > val value : int | ||
| > val extra : string | ||
| > EOF | ||
| $ cat > dep/dep.ml <<EOF | ||
| > let value = 42 | ||
| > let extra = "x" | ||
| > EOF | ||
|
|
||
| Second build. Assert independently that each of the two | ||
| invariants holds: the menhir mock-compile rebuilt, and the helper | ||
| [.cmo] rebuilt. The test stays robust whether other helper | ||
| artefacts (cmi/cmti) also rebuild — that is governed by | ||
| cctx-wide-vs-per-module dep filtering and isn't the property | ||
| under guard here. | ||
|
|
||
| $ dune build @check 2>&1 | head -20 | ||
|
robinbb marked this conversation as resolved.
Outdated
|
||
| $ dune trace cat | jq -s 'include "dune"; [.[] | targetsMatchingFilter(test("grammar__mock\\.mli\\.inferred"))]' | ||
| [ | ||
| { | ||
| "target_files": [ | ||
| "_build/default/parser/grammar__mock.mli.inferred" | ||
| ] | ||
| } | ||
| ] | ||
| $ dune trace cat | jq -s 'include "dune"; [.[] | targetsMatchingFilter(test("/parser__Helper\\.cmo$"))]' | ||
| [ | ||
| { | ||
| "target_files": [ | ||
| "_build/default/parser/.parser.objs/byte/parser__Helper.cmo", | ||
| "_build/default/parser/.parser.objs/byte/parser__Helper.cmt" | ||
| ] | ||
| } | ||
| ] | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.