Skip to content

Odoc merge word runs - #1488

Open
jonludlam wants to merge 5 commits into
ocaml:masterfrom
jonludlam:odoc-merge-word-runs
Open

Odoc merge word runs#1488
jonludlam wants to merge 5 commits into
ocaml:masterfrom
jonludlam:odoc-merge-word-runs

Conversation

@jonludlam

Copy link
Copy Markdown
Member

Rather than storing comments as [`Word "rather"; `Space; `Word "than"; `Space; `Word "storing";...] each of which actually also carries a location, store them as just one: [`Word "rather than storing ..."]

This is built on top of #1480 so we can be sure it doesn't clobber the memoizing.

jonludlam and others added 5 commits September 1, 2026 19:36
OxCaml's ppx_template-heavy libraries attach the same comment text to
thousands of monomorphised copies (Container_intf in OxCaml's base:
~155K comments, 33 unique). Cache parse results keyed on the text —
but only parses that produced no warnings and contain no
location-sensitive constructs (headings, references, {!modules ...}),
since the AST bakes in absolute locations from the first occurrence.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
comment_docs rebuilt every docs element even though linking only
changes references, headings and {!modules ...} lists. Return the
input unchanged when none are present.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Comments are parsed into one `Word`/`Space` node per token, and those
per-word locations dominate .odoc and .odocl size while the backends only
read the values. Coalesce each maximal run into a single `Word`, on the
Ast so that Doc_attr's parse cache holds the merged form and repeated
comments share it.

The whitespace is kept verbatim, so offsets into a merged `Word` still
map back to the source; `Space` carries its string for the same reason.
The document layer collapses it for rendering, as does
generate_heading_label when hyphenating, leaving anchors unchanged.
Frontmatter tags are left unmerged: they report warnings against
individual words.

The markdown fixtures lose escapes that were never needed: `-` and `1.`
matter only at the start of a line, and the escaper keys off the start of
the string it is given, which used to be a single word.

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