Skip to content

Fix canonical chain search - #1483

Open
jonludlam wants to merge 3 commits into
ocaml:masterfrom
jonludlam:fix-canonical-chain-search
Open

Fix canonical chain search#1483
jonludlam wants to merge 3 commits into
ocaml:masterfrom
jonludlam:fix-canonical-chain-search

Conversation

@jonludlam

Copy link
Copy Markdown
Member

This is an enabling PR - it allows people to fix the problems that happen when you write your own wrapper module that doesn't contain all of the library's modules. You should be able to put @canonical tags in the appropriate places after this.

jonludlam and others added 3 commits September 2, 2026 19:47
Libraries using Dune's wrapping with a hand-written top-level module get
a canonical tag of Lib.M on every alias in the generated lib__.ml,
whether or not lib.ml re-exports M. Where it doesn't, that path doesn't
exist and references to M can't be resolved.

A library can correct this from the module's own preamble, naming a path
that does exist. This test shows that doesn't currently work: the
reference picks up the corrected path, but the module it names loses its
expansion, so no page is generated for it and the reference renders as
plain text rather than a link.

The expected output below records that broken behaviour.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
When resolving a canonical module path, handle_canonical_module_real
walks the alias chain looking for a module marked with the path being
resolved. The walk stopped at the first link carrying *any* canonical
tag, so an unrelated tag masked a matching one further down.

For the wrapped-library case in the previous commit, the bogus tag Dune
put on the intermediate alias stopped the search before it reached the
one the preamble corrected, and the canonical destination lost its
expansion.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`sed -i '1i ...'` is a GNU extension: BSD sed wants a backup suffix for
-i and a different form of the insert command, so the test failed on
macOS. Prepend the line with printf and cat instead.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

1 participant