Skip to content

test: regression guard for menhir grammars referencing library deps - #14391

Merged
robinbb merged 1 commit into
ocaml:mainfrom
robinbb:robinbb-test-menhir-with-library-deps
May 3, 2026
Merged

robinbb merged 1 commit into
ocaml:mainfrom
robinbb:robinbb-test-menhir-with-library-deps

Conversation

@robinbb

@robinbb robinbb commented May 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds a regression guard for menhir grammars whose semantic actions reference values from libraries declared in the parent library's (libraries ...) field. Menhir's --infer pass invokes ocamlc -i on a generated mock module to infer types, and dune must wire the parent library's library deps onto that mock compile's -I search path for the inference to succeed. The new test exercises the smallest such shape: a library with (libraries dep) whose grammar's semantic action references Dep.value.

Coverage gap

Of 61 files under test/blackbox-tests/test-cases/menhir/ on main, none combines (menhir ...), (library ...), and a non-empty (libraries some_dep) whose grammar references the dep from a semantic action. The closest existing tests are:

  • library-interface.t — (library (name foo)) with (menhir ...), but M.x is referenced from a sibling module of the same library, not from a library dep.
  • menhir-include-subdirs.t/bar/dune, general.t/src/dune — (menhir ...) inside a library or executable with no (libraries ...).
  • menhir-dynamic-modules.t, include-subdirs-menhir-github1372.t — (library (name foo)) + (menhir ...) with no library-dep reference in the grammar.

A regression in dune's wiring of (libraries ...) onto the menhir --infer ocamlc -i rule would not be caught by any existing test.

@robinbb robinbb self-assigned this May 1, 2026
@robinbb
robinbb requested a review from Copilot May 1, 2026 18:06

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 regression test to ensure Menhir’s --infer type-inference step can resolve library dependencies declared via a parent library’s (libraries ...) field, by exercising a minimal setup where a grammar semantic action references Dep.value.

Changes:

  • Introduce a new Menhir blackbox test case covering semantic actions that reference a parent library dependency.
  • Create a minimal two-library project in the test (dep + parser) and assert dune build @check succeeds.

@robinbb
robinbb marked this pull request as ready for review May 2, 2026 15:26
@robinbb

robinbb commented May 2, 2026

Copy link
Copy Markdown
Collaborator Author

@rgrinberg I think this is probably safe to merge, but I wonder if you think a review is merited from someone who understands the (using menhir) and (menhir ...) directives better than I?

@rgrinberg

Copy link
Copy Markdown
Member

Looks ok. Maybe you can add some trace events to demonstrate that we run ocamlc -i?

Adds [test-cases/menhir/with-library-deps.t]. A menhir grammar's semantic actions can reference values from libraries declared in the parent library's [(libraries ...)] field; menhir's [--infer] pass invokes [ocamlc -i] on a generated mock module to infer types, and dune must wire the parent library's library deps onto that mock compile's [-I] search path for the inference to succeed. The test exercises the smallest such shape: a library with [(libraries dep)] whose grammar's semantic action references [Dep.value].

The existing tests under [test-cases/menhir/] cover [(menhir ...)] inside libraries with no [(libraries ...)] deps, or with deps unused by the grammar. None exercises this exact combination, so a regression in the menhir [--infer] / library-deps wiring would not be caught.

Signed-off-by: Robin Bate Boerop <[email protected]>
@robinbb
robinbb force-pushed the robinbb-test-menhir-with-library-deps branch from 1391306 to 9b0f223 Compare May 3, 2026 02:57
@robinbb

robinbb commented May 3, 2026

Copy link
Copy Markdown
Collaborator Author

Done in 9b0f223. The test now adds two dune trace cat | jq assertions after dune build @check:

  1. Filters trace events for ocamlc invocations carrying -i and asserts the target is grammar__mock.mli.inferred — menhir's mock-inference output. This positively asserts the --infer path ran rather than being silently skipped.

  2. From the same ocamlc -i invocation, asserts dep/.dep.objs/byte appears among the args — confirming dune wired the parent library's (libraries ...) onto the mock compile's -I flags, which is exactly the property the regression guards.

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.

@robinbb
robinbb requested a review from rgrinberg May 3, 2026 03:05
@robinbb
robinbb merged commit 04467af into ocaml:main May 3, 2026
33 checks passed
@robinbb
robinbb deleted the robinbb-test-menhir-with-library-deps branch May 3, 2026 14:22
@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