Skip to content

A \hyphenation entry does not escape \lefthyphenmin and \righthyphenmin (tex.web:18159-18160) - #809

Merged
tannevaled merged 2 commits into
mainfrom
exceptions-obey-the-minima
Nov 17, 2026
Merged

tannevaled merged 2 commits into
mainfrom
exceptions-obey-the-minima

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

A \hyphenation entry does not escape the minima

tex.web:18145-18160 is one block:

@<Look for the word |hc[1..hn]| in the exception table, and |goto found| (with
  |hyf| containing the hyphens) if an entry is found@>;
if trie_char(cur_lang+1)<>qi(cur_lang) then return; {no patterns for |cur_lang|}
…the pattern scan…
found: for j:=0 to l_hyf-1 do hyf[j]:=0;
for j:=0 to r_hyf-1 do hyf[hn-j]:=0

The exception table is consulted first, and a hit does goto found — to the
same label the pattern scan falls through to. found is where the limits are
imposed. So \hyphenation{} says where a break may go, not that one must, and
\lefthyphenmin/\righthyphenmin refuse an exception's breaks exactly as they
refuse a pattern's.

⭐ The comment was right and the code was wrong

hyphexception.go's header has said so since it was written:

\lefthyphenmin and \righthyphenmin still apply, as they do to any word: an
exception says where a break MAY go, not that one must.

and nothing did it. lookup returned the entry's breaks and hyphenation.go
wrote them straight into breakAfter. That is the harder way round to find —
a reader checking the rule meets it stated correctly and moves on, and the usual
failure (a stale comment over correct code) trains you to distrust the comment,
not the code.

The pattern path was never affected: Hyphenator.Points applies the minima itself
(for t := h.lmin; t <= L-h.rmin, faithful to tex.web:17677's
for j:=l_hyf to hn-r_hyf do if odd(hyf[j])), which is why only exceptions
escaped.

Two decisions in the fix

⛔ Applied when the word is hyphenated, not when the entry is recorded. TeX
imposes the limits inside hyphenate. A document may declare \hyphenation{} in
a package and set \lefthyphenmin afterwards, or change it per language
mid-document; clipping at add time would freeze whichever value happened to be
in force when the entry was read. A test compiles exactly that document and
refuses the other implementation.

⛔ It does not alias the stored entry. The same exception is looked up once per
occurrence of the word, so writing the clipped list back into the slice the map
holds would narrow it permanently — the second paragraph of a document would
hyphenate differently from the first, for no reason a reader could see.
pts[:0:0], and a test that looks the word up again afterwards.

Witnesses, and the mutation that checked them

A 9-letter word whose entry offers breaks after 1, 4 and 8 letters:

TeX defaults (2, 3) only the break after 4 survives
opened to (1, 1) all three are offered again
minima wider than the word nothing, no panic, no negative bound

⛔ The middle row is the boundary from the other side, and it is why the first row
means anything: a rule that refused the ends unconditionally would be a
different bug wearing this fix's name, and a test checking only that 1 and 8 were
gone would pass it.

Plus the end-to-end one: \lefthyphenmin=1 when \hyphenation{photo-graphy} is
read and 6 when the word is set, so the word must come out whole — with its own
control, the same document left at 1, where the entry's break must still appear.

Run against the old behaviour (clipToMins returning pts unchanged):

--- FAIL  …/the_TeX_defaults_refuse_the_first_and_the_last
        clipToMins([1 4 8], 9, 2, 3) = [1 4 8], want [4]
--- PASS  …/opened_up,_every_break_the_entry_wrote_is_offered
--- FAIL  …/minima_wider_than_the_word_leave_no_break
        clipToMins([1 4 8], 9, 6, 6) = [1 4 8], want []
--- FAIL  TestTheMinimaAreReadWhenHyphenatingNotWhenTheEntryIsRecorded
        …: "Aphoto-graphyandamanuscriptfollowhere."

The control stays green, which is what makes it a control.

Not claimed

⚠ Any corpus effect. gotex-paramcensus has not been run for \hyphenation
over the measured list, so how many papers carry an entry whose breaks the minima
refuse is unknown. The change can only remove break opportunities, so a
paragraph that used one will set differently; whether that is nearer the reference
is the A/B's business, and the corpus is not reachable from this session.

⚠ No README change: this makes the behaviour match what hyphexception.go's
own header already documented, rather than adding a capability.

How it was found

A bibliography pass over go-typeset/hyphenation, which the engine depends on and
which has never been audited against tex.web — priorart reports its tracker
and branches clean on the subject. The library is 110 lines and has no exception
support at all
: New, AddPattern, Points, SetMins, Mins. So every
consumer must implement \hyphenation{} itself, above a library that already owns
the minima — and the first implementation put the two halves of one tex.web
block on opposite sides of an API boundary. Raised separately there.

Refs #765 — this is one of its nine, not the whole census.

🤖 Generated with Claude Code

…in (tex.web:18159-18160)

tex.web:18145-18160 is one block. The exception table is consulted FIRST and a
hit does `goto found` -- to the SAME label the pattern scan falls through to --
and `found` is where the limits are imposed:

	found: for j:=0 to l_hyf-1 do hyf[j]:=0;
	       for j:=0 to r_hyf-1 do hyf[hn-j]:=0

So \hyphenation{} says where a break MAY go, not that one must, and
\lefthyphenmin/\righthyphenmin refuse an exception's breaks exactly as they
refuse a pattern's.

⭐ THE COMMENT WAS RIGHT AND THE CODE WAS WRONG, which is the harder way round to
find. hyphexception.go's header has said "\lefthyphenmin and \righthyphenmin
still apply, as they do to any word" since it was written, and nothing did it:
lookup returned the entry's breaks and hyphenation.go wrote them straight into
breakAfter. A reader checking the rule meets it stated correctly and moves on.
The pattern path was never affected -- Hyphenator.Points applies the minima
itself (`for t := h.lmin; t <= L-h.rmin`), which is why only exceptions escaped.

clipToMins is in hyphexception.go, where the exception semantics live.

⛔ IT IS APPLIED WHEN THE WORD IS HYPHENATED, NOT WHEN THE ENTRY IS RECORDED. TeX
imposes the limits in `hyphenate`, and a document may write \hyphenation{} in a
package and set \lefthyphenmin afterwards, or change it per language
mid-document; clipping at `add` time would freeze whichever value happened to be
in force when the entry was read. A test compiles exactly that document and
refuses the other implementation.

⛔ AND IT DOES NOT ALIAS THE STORED ENTRY. The same exception is looked up once
per occurrence of the word; writing the clipped list back into the slice the map
holds would narrow it permanently, so the second paragraph of a document would
hyphenate differently from the first for no reason a reader could see. `pts[:0:0]`
and a test that looks the word up again.

## Witnesses, and the mutation that checked them

A 9-letter word whose entry offers breaks after 1, 4 and 8 letters:

  - at the TeX defaults (2, 3) only the break after 4 survives;
  - ⛔ with the minima opened to (1, 1) all three are offered again -- the
    boundary from the other side, because a rule that refused the ends
    unconditionally would be a different bug wearing this fix's name;
  - minima wider than the word leave nothing, with no panic and no negative
    bound.

Plus the end-to-end one: \lefthyphenmin=1 when \hyphenation{photo-graphy} is read
and 6 when the word is set, so the word must come out whole -- with its control,
the same document at 1, where the entry's break must still appear.

Run against the old behaviour (clipToMins returning pts unchanged), both change
rows go red with the right numbers and the end-to-end one prints the page text
that proves it -- "Aphoto-graphyandamanuscriptfollowhere." -- while the
"opened up" control stays GREEN, which is what makes it a control.

## Not claimed

Any corpus effect. gotex-paramcensus has not been run for \hyphenation over the
measured list, so how many papers carry an entry whose breaks the minima refuse is
unknown. The change can only REMOVE break opportunities, so a paragraph that used
one of them will set differently; whether that is nearer the reference is the A/B's
business and the corpus is not reachable from this session.

No README change: this makes the behaviour match what hyphexception.go's own
header already documented, rather than adding a capability.

Refs #765 -- this is one of its nine, not the whole census.

Co-Authored-By: Claude Opus 5 <[email protected]>
tannevaled added a commit that referenced this pull request Nov 17, 2026
…tor, because -race costs 6.65x (#811)

MEASURED (#799). Quiet machine, GOMAXPROCS=1 -parallel 1 -count=1, arms
INTERLEAVED and the order REVERSED so a drift during the pass shows up as a
disagreement between orders instead of reading as an effect:

	                run 1        run 2
	plain           17.486 s     18.175 s
	-race          116.361 s    121.046 s

	A1 -> B1  6.65x        B2 -> A2  6.66x     (agree to 0.2%)

windows-latest was failing at 1800.5 s against its own 1800 s bound, one push run
in four. That left `main` ITSELF red a quarter of the time, so "is main green?"
had no stable answer, ghrelease could not tag on its first try, and three open
pull requests (#807, #809, #810) were red on this lane and on nothing else --
#810 changes only a comment.

At 6.65x the lane was not 10% away from comfortable, it was most of an order of
magnitude away. #156 and #653 already raised this bound twice; a third raise buys
a few months and the same recurrence. Expected after this change: ~270 s.

⚠ AND THAT ESTIMATE IS PESSIMISTIC: the race detector's overhead on Windows is
commonly HIGHER than on darwin, and a higher multiplier means a bigger saving.

## What is given up, named

A data race reachable ONLY through Windows-specific code. A race is a property of
the Go program and Go's memory model is platform-independent, so everything else
is still caught on ubuntu and macos, on every push and every pull request.

The conformance ratchet and the 80% coverage floor still run on windows:
platform BEHAVIOUR is still covered there. Only the detector is dropped.

## Why the matrix and not a shell branch

The policy is declared in the matrix -- `{ os: windows-latest, race: '' }` --
rather than branched on inside the step, so that reading the matrix tells you
which lane guarantees what. A reader looking for "where does -race run" finds the
answer in one place.

## ⚠ What is NOT changed, deliberately

The 30m bound stays, although ~270 s is expected. The first green run on this
lane is what measures the new time, and changing two things at once would leave
nobody able to say which did it. Once that number exists the bound can come down
to something that would catch a real deadlock quickly.

Verified: wfaudit reads the workflow (1 read, 0 unreadable, no findings), and
`go test -count=1 ./...` is green on 11 packages at a 1-minute load of 3.16.

Closes #799.

Co-authored-by: Claude Opus 5 <[email protected]>
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