Skip to content

🐛 fix(relaxng): keep one branch per closed tail - #2448

Merged
gaborbernat merged 6 commits into
tox-dev:mainfrom
gaborbernat:fix/rng-2382-closed-tail
Nov 17, 2026
Merged

gaborbernat merged 6 commits into
tox-dev:mainfrom
gaborbernat:fix/rng-2382-closed-tail

Conversation

@gaborbernat

Copy link
Copy Markdown
Member

A RELAX NG group whose tail is closed and whose elements share one content now drops the right side of its derivative when the left side covers the tail. Repeated blocks of optional elements kept one alternative per place a later element could start, so the alternatives grew with each block until they hit the choice cap and raised too ambiguous on a valid document.

The tail's weak and uniform answers are computed on first use and kept on the node. Compiled nodes are settled before a schema is shared, so validation never writes to them.

The routing reach cache keys on the names' code points instead of pointers into the document, so elements that spell the same name share one walk up. Before, each element walked up again.

Work steps for the block family at T=100, 200, 400, 800 are 48,757, 96,783, 194,017 and 394,658 (exponent 1.01). Scaling the number of blocks from 8 to 128 at T=50 gives exponent 0.82. Both linearity tests in tests/validate/test_relaxng.py pass.

Fixes #2382

@gaborbernat gaborbernat added the bug Something isn't working label Nov 17, 2026
@gaborbernat
gaborbernat enabled auto-merge (squash) November 17, 2026 15:27
@codspeed

codspeed Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Merging this PR will regress 2 benchmarks

2 warnings

⚠️ 8 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚠️ 8 benchmarks with a significant change ran in a different software environment

Their base and head results were measured with a different OS or toolchain, such as compiler, runtime or library versions, so the changes might come from this difference rather than from the code. Open an affected benchmark to see what changed.

See affected benchmarks

⚡ 6 improved benchmarks
❌ 2 regressed benchmarks
✅ 573 untouched benchmarks
⏩ 90 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_feature[select-relative-sibling] 1.1 ms 1.2 ms -6.42%
❌ test_feature[select-relative-child] 1.1 ms 1.2 ms -6.38%
⚡ test_feature[canonicalize] 6.5 ms 6 ms +7.69%
⚡ test_feature[text-content] 2.8 ms 2.6 ms +6.92%
⚡ test_feature[encode-inner] 7.1 ms 6.7 ms +6.89%
⚡ test_feature[encode-inner-indent] 7.5 ms 7 ms +6.64%
⚡ test_feature[serialize-inner] 5.8 ms 5.5 ms +5.57%
⚡ test_feature[serialize-inner-indent] 6.2 ms 5.9 ms +5.31%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing gaborbernat:fix/rng-2382-closed-tail (f11ce6e) with main (d4bd25b)

Open in CodSpeed

Footnotes

  1. 90 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@gaborbernat
gaborbernat force-pushed the fix/rng-2382-closed-tail branch from 6a850cf to 5a86974 Compare November 17, 2026 15:39
@gaborbernat
gaborbernat disabled auto-merge November 17, 2026 15:53
gaborbernat and others added 2 commits November 17, 2026 08:07
A RELAX NG group whose tail is closed (removing any one item from a match
keeps a match) and whose elements all share one content now drops the
right side of its derivative when the left side covers the tail. Repeated
blocks of optional elements kept one branch per place a later element
could start, so the count grew with every block until it hit the choice
cap and raised "too ambiguous" on valid documents.

The tail's weak and uniform answers are computed on first use and kept on
the node. Compiled nodes are settled before a schema is shared, so no
validation writes to them.

The routing reach cache keys on the names' code points instead of
pointers into the document, so consecutive elements that spell the same
name reuse the walk up they would otherwise repeat.

Fixes tox-dev#2382
@gaborbernat
gaborbernat force-pushed the fix/rng-2382-closed-tail branch from 5a86974 to 26fd255 Compare November 17, 2026 16:07
A block family whose tail elements each carry an attribute keeps one
alternative per place: each element has its own content, so no single
content covers the tail. The event work then passes its limit and
validation raises "too ambiguous" at depths 5 and 7, the path the removed
past-cap test covered.
The ladder test's rungs collapse under the closed-tail rule, so a list
tail is entered with budget left and the budget-exhausted arm of the list
derivative never runs. Rungs that hold an optional value are not weak, so
the crossed places stay and the text run spends its budget before the
list. The new test runs the list tails of the ladder table with those
rungs, in both orders.

The distinct-content halves case checks that elements with their own
attributes decide the same as the shared ones.
A text derivative of a choice whose other branch needs two elements keeps the shared text node next to a group over both texts. Route adoption places that pair with the left side at the first text unit and the right side covering the whole halves, the overlap that the route placement check rejects. The new text-or-pair rows cover that arm, and the decision of the mirrored rows is unchanged.
@gaborbernat
gaborbernat merged commit 3f6f1eb into tox-dev:main Nov 17, 2026
47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 fix(relaxng): reject valid documents with repeated optional blocks

1 participant