Repository navigation
feat(layout): one diagnostics channel and an opt-in strict mode (#607) - #642
Merged
Merged
Conversation
A save keeps several inputs while it loses, misplaces or substitutes content, and the only reports were two unrelated lists. Document.Diagnostics now lists one item per code and subject with an occurrence count, bounded at 1,000 items with a sentinel counting what was dropped. Document.StrictDiagnostics, off by default, refuses a save that would report an error item, after the layout and before anything is written, from every save overload and from signing. The two older lists keep their content.
…ist marker in the tests (#607)
…ct docs (#607) The per-list visited set walked a subtree again for every list that reached it, which made a chain shared by many lists, or one list added many times, quadratic. A per-save memo keyed on the second-level item caches its counts. The strict-mode and marker documentation now says what holds, Diagnostics is a read-only view, and the members that can now trigger the refusal say so.
Four tests now kill mutants the first suite let survive (the marker pre-sync, per-element keying, a constant band subject, and the further-errors count). The default-bytes test hashes the whole file. The documentation states one rule for which substitutions Diagnostics lists, says what its order is, and no longer promises reports in the Kernel docs.
# Conflicts: # CHANGELOG.md # src/VellumPdf.Layout/PublicAPI.Unshipped.txt
…#607) The per-second-level-item memo still cost one subtree walk per distinct second-level item, so one list with 400 such items reaching a 100,000-item chain, or 10,000 chained second-level items, was quadratic. One visited set per save, carried on the layout context, makes the walk linear in the distinct items the caller built. A null text or null child is now counted once in the save, under the first list in drawing order that reaches it. Tests pin the nodes visited for the five measured shapes, the single count under the first list, and the order independence of the total. The documentation states that rule once and the FontRef note says which text is listed.
# Conflicts: # CHANGELOG.md # src/VellumPdf.Layout/PublicAPI.Unshipped.txt
…607) The walk ran when a list was laid out, so a list that starts at a later item, or that a caller's renderer lays out and never draws, used up the document-wide visited set and a later list that does report found nothing; strict mode then saved. The walk now runs when a list is drawn from its first item, through the document's context. The documentation says that only such a list takes part, and that the work is linear in the items and child links.
… item (#607) ListItem.Children, the NullGrandchild remarks and the walk summary now carry the condition that only a list the document draws from its first item takes part, and say what happens to a list that starts later or is measured and never drawn.
Tim81
added a commit
that referenced
this pull request
Nov 21, 2026
DocumentRenderer's page-counting pass and drawing pass were two copies of the same placement branching. One routine now runs both, so the too-tall refusal, the 50,000-continuation cap and every later placement rule are written once. Each pass keeps its side effects where it had them: the drawing pass commits the open page before a too-tall or cap throw; the counting pass creates no page. Internal only: no public API change and no output change. A renderer can report a key and a box for the result the loop accepted, in both passes; only HeadingRenderer reports, with the y its outline entry uses. Reports are collected only when something reads them. An internal plan (target to page and y, page count) feeds plan-dependent renderers through at most five measuring runs; past that the save throws InvalidOperationException naming the unstable targets. No public renderer is a dependent, so no existing document reaches the cap or the check that the drawing pass matches the last measuring run. Layout diagnostics (#642) are still reported from the drawing pass only: a cut footer is reported once whether or not measuring runs repeat. DocumentRenderer.PendingBookmarks and BookmarkEntry, never read, are removed. Document.CreateRenderer goes from private to internal for tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #607
What changed
Documentgains one diagnostics channel and an opt-in strict switch, inVellumPdf.Layoutonly.Document.DiagnosticslistsLayoutDiagnosticitems (Code,Severity,Message,Clause,ElementKind,ElementIndex,PageNumber,Count), one per code and subject, replaced by eachsave that succeeds. It is a read-only view. A strict refusal also fills it, because that layout is
the document's only one.
NullTextRunStyle(101),UnencodableCharacter(103, mirrorsTextEncodingWarnings),NullGrandchildText(201),NullGrandchild(202),BandTruncated(401,mirrors
BandTruncations, severityError) and the sentinelDiagnosticsDropped(901,Warning).The enum comment reserves 102, 104, 105, 203-206, 301, 302, 402, 601, one 7xx and the 8xx block.
LayoutElementKindand the code enum have explicit values and say not to switch exhaustively, soPreformattedand later codes append.DiagnosticsDroppedwhen it dropped any, whoseCountis the number of occurrences dropped. A repeat of a stored item adds to its count and, on theencoding path, allocates nothing.
Document.StrictDiagnostics(defaultfalse) refuses a save that would report an error item, withInvalidOperationException, after the layout and before anything is written, from every saveoverload and from signing. The check is one private method called inside the
tryof both layouthelpers, so the failure marks the document as failed and the two
SaveAsyncoverloads are covered.TextEncodingWarningsandBandTruncationskeep their content and order. The two "not an error"sentences about band truncation are rewritten.
(
ListWalkState, owned by the diagnostics sink). Each list item below the first level is visited atmost once per save, so the work is linear in the items and child links the caller built.
A.AddChild(A)and a graph with 2^40 paths save and terminate. The walk runs when a list is drawn,and only for a list the document draws from its first item, so a list that starts at a later item, or
that a caller's renderer measures and does not draw, leaves its items for the list that reports. A
null text or null child is counted once in the save, under the first such list in drawing order, so
the total does not depend on their order.
draws the list.
TextRun,ListItem) now name the codes.Two Kernel sentences that promised a report now state current behaviour only.
No default output changes, and nothing that saved on 2.3.3 starts throwing unless a caller sets the
new switch.
Evidence
Default bytes, whole file. A document with a null-style run, U+26B9, a level-3 null text and a cut
footer, saved with the switch off and a pinned timestamp and id, hashes to
8C5E33CA07812BF9C03B8974108D011FF136A6EB9AF019AD9DF981D43FD7D988over the whole file on this branch(net10.0 and net11.0) and on 2027421 (assembly
2.3.3+2027421a3be1574b9b0cfaab235d7840f23c93e5). Thetest pins it.
Font probe, base against head (PDF/A-2u document with embedded DejaVu, pinned timestamp and id):
E317A2C267FE05C9E317A2C267FE05C9A21068F44E914D0BA21068F44E914D0B370B0E4ED284DE29370B0E4ED284DE29TextEncodingWarnings1,000 / 10,000 / 100,000The Standard 14 allocation for 100,000 characters is 44,339,864 bytes on 2027421 and 44,341,680 on head.
Cost of the walk. Timings of one save with strict off, measured at 65d09f6 (where the walk still
ran at layout time; it has since moved to draw time and was not re-timed, and the tests pin its work),
for the five shapes the third review measured (a list's chain below its second level has 100,000 items):
The tests pin the work, not the time:
NodesVisitedequals the distinct item count for each shape at twosizes.
Review findings and what became of them
Early review of the first commit: H1 (test compile break) applied; M1 to M11 applied; the cheap LOWs
applied. For M5, marker substitutions are not mirrored, so a Standard 14 nested bullet does not trip
strict mode.
First review round (c6dd496):
Document,LayoutDiagnosticCode,ListItem.Childrenand the CHANGELOG; the rule forUnencodableCharacteris stated onceSaveAsynccancellation tags and the strict ordering list; a test for strict on and off<exception>tagsTextRun(type andStyle),ListItemconstructor and bothAddChild, andTextStyle.FontRefstartItem >= 1reports nothingAsReadOnly); testSecond review round (tests and prose):
TextEncodingWarningssentence, "further", order, comment, "Standard 14")Diagnosticslists, its order stated, the stale comment fixedPdfDocumentandJbig2ImageLoaderpromisesSavetag for dropped errors, "1,000 items" against 1,001,?wording for a non-BMP character, broken rewraps, over-long comment lines, a test that could not fail, the CHANGELOG bulletThird review round (961fa3d, the branch after merging main):
NodesVisitedand timed aboveListItem.Children, the CHANGELOG Attention, theDocumentRenderercomment and this body state the new ruleTextStyle.FontRef"each such character"UnencodableCharacterfor what it leaves outNullGrandchild,NullGrandchildText, the walk's remarks, theListRenderercomment and the CHANGELOGTimestampandDocumentIdin the pinned-hash testFourth review round (65d09f6):
ListItem,ListWalkState, the CHANGELOG and this bodyNullGrandchildText,ListWalkState, the CHANGELOG and this body.ListItem.Childrenstill lacked the "drawn from its first item" condition; it is added in the fifth round (below)Fifth review round (58e538b), prose only:
ListItem.Childrensaid a null below the first level is reported and strict refuses, without the "drawn from its first item" condition (a list started at a later item saves with no report)ListItem.Children; the earlier table row is correctedNullGrandchildremarks named only the start-item caseListWalkStatesummaryMutation proofs
Each mutant was applied to the committed head, the test project rebuilt, and
LayoutDiagnosticsTestsrun, then the source restored.
HundredThousandOccurrences_areOneItemWithTheirCount(both cases),TextEncodingWarnings_keepOneEntryPerSubstitutedCharacterLayOut(kept inLayOutThen)Strict_saveAsync_stream_throwsTheExactMessageAndWritesNothing,Strict_saveAsyncPath_leavesAnExistingFileUntouched_andCreatesNothingAtANewPathLayouton every callANullStyleParagraph_withAFooter_isStillCountedOnceand the tests that read the item's location_startLine == 0guard removedANullStyleParagraphThatSplitsOverTwoPages_isCountedOnceThousandAndOneDistinctSubjects_storeAThousandAndASentinelCountingTheRest,ADroppedSubjectThatRepeats_countsEveryDroppedReport,Strict_whenEveryDroppedReportWasAnError_saysSoWithTheirCountHeadingContinuation_isReportedAsAHeading_notAsTheParagraphItOverflowsIntoTheWalk_visitsEachDistinctItemOnce_andCountsTheNullOncefor holders-share-chain, holders-chained and lists-own-holder-share-chain,TwoSecondLevelItemsReachingOneNullTextItem_countItOnceUnderTheFirstList,TheTotalDoesNotDependOnTheOrderOfTheLists(9 in all)OneListAddedManyTimes_walksItsChainOnce, the two-second-level-items test and the order test (15 in all)CallerTextInAListItemThatIsNotTheLast_isReportedUnencodableCharacterkeyed per elementTheSameCharacterInTwoElements_isOneItemWithBothOccurrencesBandTruncatedsubject constantACutHeaderAndACutFooter_areTwoItemsTheStrictMessage_countsOnlyTheStoredErrorItems,Strict_whenEveryDroppedReportWasAnError_saysSoWithTheirCountAListStartingAtALaterItem_leavesItsNullsForTheListThatReports(both cases),AListMeasuredAndNeverDrawn_leavesItsNullsForTheListThatIsDrawnRows 7 and 7b were re-run on the fixed code and still fail 9 and 15 tests.
Mutant 4 first survived because overflow pieces did not carry the count, which made the guard redundant.
The null-style count is now carried to every piece of a split paragraph (
ParagraphRenderer). A list takes no per-piece count: its nulls are found when the first piece is drawn.Gates
dotnet build VellumPdf.slnx -c Release -m:2: 0 warnings.dotnet format --verify-no-changes, theclean-room check and
generate-roadmap.py --check: clean. Release,REQUIRE_ORACLES=1,REQUIRE_VERAPDF=1, veraPDF 1.30.4, qpdf 12.4.2, poppler withpdfsig, at the final head. Each countis net10.0 and net11.0 together, because the runner reports them as one; each TFM runs half.
LayoutDiagnosticsTestsalone is 65 tests on each TFM. Kernel gained tests from the merge of main.Differential against 2.3.3
2.3.3 is
2.3.3+1c61fa653ea4bb295140cf682f555c7a8655a440(printed by the runner for Layout and Kernel).The runner compared it against the branch point 2027421 and against the head of each commit batch (the 2027421 row is unchanged because that commit predates the merges of main, whose commits the later heads include, at 961fa3d and 0949ccc),
with the default seed and with
-Seed 2 -FuzzCount 1500.At 58e538b the one violation on seed 1 is
fuzz.1.269, a document of two headings, the first split overtwo pages: the content stream is identical and the file skeleton differs. It comes from main's change
to where a split heading's bookmark is written. The merge at 0949ccc brought in exactly one main
commit, 39e5fe0 (#637): 0949ccc..58e538b changes only
the list walk, the diagnostics sink and documentation, and no earlier head of this branch, run before
that merge, shows it. The runner's table of deliberate output changes does not list #637.
Between the branch point and the heads before that merge no row changes verdict, except
r6a-cancel|cancel-scan, a timing scanthat records at which points a cancelled token took effect. The other rows that differ between runs
differ only in the output directory printed in their message.
Not done
non-finite class and the "nothing reports" sites keep their "not reported" sentences.
Documentdocumentation state the order.
DocumentRenderer.Renderremarks say thatDocument.Savebuilds a renderer and callsRender. Thatwas already inaccurate before this PR and is unchanged.
report that quotes a token will need one.
UnencodableCharacterandBandTruncateddedupe document-wide on their subject, and the null-styleand list codes dedupe per element.