Skip to content

compiler: boxed arguments and letter \ps no longer leave phantom paragraph leadings - #517

Merged
GoKubar merged 3 commits into
mainfrom
agent/daniel-parent/parleading-assert
Sep 15, 2026
Merged

GoKubar merged 3 commits into
mainfrom
agent/daniel-parent/parleading-assert

Conversation

@d-q222

@d-q222 d-q222 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

What

Two compiler fixes that bring block_par_leading back into step with the parsed blocks. The render-pipeline's debug_assert_eq!(leadings.len(), parsed.blocks.len()) in adapter.rs stops firing in debug builds once vendor/compiler is re-pinned past this PR.

  • Underline family (\underline, \uline, \sout) and xcolor boxes: the temporary box_inlines parse in parser/colors.rs restored block_dependencies but not block_par_leading, so each boxed argument left a phantom leading. It is now truncated the same way (colors.rs:235).
  • letter class \ps: \ps called finish_block_dependencies() after flush_paragraph, recording a block entry that was never pushed (letter fixture 14 leadings vs 13 blocks). The extra call is removed (parser.rs:2114).

Counts before → after: underline family 2 vs 1 → 1 vs 1; fixtures/real-world/letter 14 vs 13 → 13 vs 13.

Why

The debug assertion was reported on #2 by daniel-muse-lead-2 (credit for isolating both triggers). Release builds skip the check, but the misaligned list means a later block can get the wrong paragraph leading.

Overlap check

Checked open PRs and claims for par_leading, box_inlines, \ps and letter. There is no overlap. The claim is GH-PARLEADING-DEBUG-ASSERT. daniel-muse-lead-2's #505 \marginpar is told to stay out of this path.

Test results

  • New crates/compiler/tests/par_leading.rs regressions (underline, \sout, \uline, letter 13/13): 11 passed; 0 failed for par_leading.
  • Compiler full test gate: passed.
  • Render-pipeline: the four targets failing in debug fail identically on clean origin/main (vendor baseline, fixed only by re-pin).
  • git diff --check: passed.

Not done

  • Needs a vendor/compiler re-pin (integration lane) before render-pipeline debug tests go green. This PR does not touch vendor/. The adapter assertion is intentionally kept.
  • Independent review is pending (daniel-parent will post it).

🤖 Generated with Claude Code

https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

What changed:
- Discard block-leading metadata from temporary boxed inline parses.
- Stop \ps from recording metadata without a block.
- Add underline, sout, and letter fixture alignment regressions.

What was run:
- CARGO_TARGET_DIR=/Users/dqi26/flashtex/target-parlead cargo test --manifest-path crates/compiler/Cargo.toml -> exit 0; all reported test-result lines passed; doc-tests passed.
- CARGO_TARGET_DIR=/Users/dqi26/flashtex/target-parlead cargo test --manifest-path crates/compiler/Cargo.toml --test par_leading -- --nocapture -> test result: ok. 11 passed; 0 failed.

Next step:
- Re-pin render-pipeline/vendor/compiler to this compiler fix before the render-pipeline debug gate.

Implementation-Agent: codex gpt-5.6-luna (max)
Commit-Executor: codex (this session)
Lane-Owner: daniel-parent (mac-m5pro-dq222)
@d-q222

d-q222 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

daniel-parent independent review (subagent)

Verdict: CHANGES NEEDED

Both fixes actually in this diff are correct, and both are verified independently below. But the PR's own framing ("stops firing in debug builds once vendor/compiler is re-pinned") is not true: there is a third site with the identical bug pattern that this PR does not touch, with a concrete reproducing input (finding 2).

1. parser.rs \ps fix (removing finish_block_dependencies() after flush_paragraph): correct, no tracking lost.

flush_paragraph → flush_list_item (parser.rs:6598-6693) already calls finish_block_dependencies() itself, exactly once, exactly when it actually pushes a block (line 6692) — pushing one entry each to both block_dependencies and block_par_leading. When the paragraph is empty and there's no pending item label, flush_list_item returns early (line 6606-6608) and pushes nothing and calls nothing.

The removed second call in the "ps" arm was unconditional, so it always added one extra block_dependencies/block_par_leading entry with no matching block, in both cases:

  • Non-empty paragraph: flush_paragraph already pushed 1 block + 1 dependency/leading pair; the old code then pushed a 2nd phantom pair → 2 pairs for 1 block.
  • Empty paragraph (the actual fixture case): flush_paragraph pushes nothing (early return); the old code still unconditionally pushed 1 phantom pair → 1 pair for 0 blocks.

The real fixtures/real-world/letter/main.tex hits the empty-paragraph path: \ps{...} follows \closing{...} (line 39/43), and letter_closing pushes its own Block::LetterBlock directly without touching para, so para is empty when \ps runs. Removing the extra call fixes both cases; no dependency information is lost since flush_list_item already records it whenever a block is actually pushed.

2. parser/colors.rs box_inlines fix (truncating block_par_leading alongside block_dependencies): correct.

Symmetric with the existing, already-correct pattern in argument_inlines (parser.rs:6521-6528, footnotes), which has truncated both lists together all along. Confirmed by test (below).

3. Finding — NOT fixed by this PR: crates/compiler/src/parser/tabular.rs, tabular_cell_inlines (fn starts line 1473).

I enumerated every site that manipulates block_dependencies for a temporary sub-parse (grep for block_dependencies.truncate\|.drain( and for parse_stream(&mut) and found exactly 4 parse_stream call sites total:

  • parser.rs:1837 — the real top-level document() parse (not temporary, no truncation needed).
  • parser.rs:6525 (argument_inlines) — truncates both block_dependencies (6527) and block_par_leading (6528). Correct, pre-existing.
  • parser/colors.rs:237 (box_inlines) — now truncates both, per this PR. Correct.
  • parser/tabular.rs:1497 (tabular_cell_inlines) — saves dependency_count = self.block_dependencies.len() (line 1493), runs self.parse_stream(&mut blocks, &mut para) into a local, discarded blocks vector, then at line 1522 does self.block_dependencies.drain(dependency_count..).flatten() to fold macro dependencies back into current_dependencies — but never touches self.block_par_leading. Any table cell whose content triggers this function's own "block-level content ... is not supported inside a table entry" warning (i.e. parse_stream pushed at least one real block into the local, discarded blocks) leaves that many phantom entries in self.block_par_leading with no matching entries in the real self.blocks.

Concrete reproduction (verified empirically — added a temporary probe test at PR head, ran it, then reverted the test file with git checkout, so nothing was left behind):

\documentclass{article}
\begin{document}
\begin{tabular}{c}
\begin{itemize}\item x\end{itemize}
\end{tabular}
\end{document}

Result at PR head (8619bf80): parsed.blocks.len() == 1, parsed.block_par_leading.len() == 2. This is the exact same class of misalignment as findings (1)/(2) above, and it means the render-pipeline debug_assert_eq!(leadings.len(), parsed.blocks.len()) in adapter.rs will still fire on documents like this one after the vendor/compiler re-pin — contradicting the PR description's claim that the assertion "stops firing... once re-pinned past this PR." Suggest either truncating block_par_leading the same way at tabular.rs:1522 (mirroring the drain, e.g. also self.block_par_leading.truncate(dependency_count-equivalent) — needs its own saved length since block_par_leading and block_dependencies share length only while nothing has diverged) plus a regression test, or narrowing the PR's claim about the assertion.

4. Regression check against origin/main (36fe7ec, detached worktree, CARGO_TARGET_DIR=target-review-517, removed after):

Copied the PR's new test file (crates/compiler/tests/par_leading.rs from PR head 8619bf80, unmodified) onto origin/main's compiler source and ran it: 4 of 11 tests fail exactly as the PR claims —

an_underline_argument_does_not_add_a_block_leading: left 2, right 1  -> FAILED
a_sout_argument_does_not_add_a_block_leading:        left 2, right 1  -> FAILED
a_uline_argument_does_not_add_a_block_leading:       left 2, right 1  -> FAILED
the_letter_fixture_has_one_leading_per_block:        left 14, right 13 -> FAILED

The other 7 pre-existing tests in that file pass on origin/main too. Matches the PR description's "before" counts exactly.

5. Full compiler test suite at PR head (8619bf80625967ac0762300f3ef57ba3bbb9834f):

CARGO_TARGET_DIR=target-review-517 cargo test --manifest-path crates/compiler/Cargo.toml — every test binary reports test result: ok, 0 failed across 57 result lines (unit tests, all tests/*.rs integration files, doc-tests). Matches the PR's "Compiler full test gate: passed."

Summary: the two committed changes are both correct and necessary, and are independently verified. Recommend also closing tabular_cell_inlines (finding 3) before merge, or at minimum striking/qualifying the "the assertion stops firing once re-pinned" claim in the PR description, since it's currently false for table cells with block-level content.

…ehind

What changed:
- tabular_cell_inlines truncates block_par_leading after its temporary
  sub-parse, the third sub-parse site alongside box_inlines and
  argument_inlines (found by the independent review on #517).
- Regression test: an itemize inside a tabular entry keeps 1 block / 1 leading.

What was run:
- cargo test --test par_leading: test result: ok. 12 passed; 0 failed
- same test without the tabular.rs change: 1 failed (2 leadings vs 1 block)

Next step:
- re-pin render-pipeline/vendor/compiler past #517 (integration lane).

Implementation-Agent: claude-opus-5 (daniel-parent)
Commit-Executor: daniel-parent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
@d-q222

d-q222 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

Addressed review finding 3: tabular_cell_inlines now truncates block_par_leading (commit baf6d33), with a regression test that fails without it (2 leadings vs 1 block). All three temporary sub-parse sites (box_inlines, argument_inlines, tabular_cell_inlines) are consistent now. The PR claim about the debug assert holds for known inputs.

…ixture

What changed:
- par_leading.rs: regression tests for the constructs that leaked phantom
  block_par_leading entries on main: \colorbox, \fcolorbox, and a \par
  inside a box argument (\colorbox, \underline), all via box_inlines.
- PR #42's extended/graphics-transform-color case, verbatim: 5 blocks and
  5 leadings (main gave 7 vs 5, the render-pipeline debug_assert at
  adapter.rs:1261; the two extras are the \colorbox and \fcolorbox args).
- A guard for the argument_inlines path (\rotatebox, \scalebox,
  \reflectbox, \resizebox, \footnote with \par), which already truncated.
- A property test: every .tex under fixtures/real-world and
  fixtures/divergence-probes has blocks.len() == block_par_leading.len().
- No source change: the three sub-parse sites (box_inlines,
  argument_inlines, tabular_cell_inlines) are the only local-vector
  parse_stream callers, all truncate on this branch, and all 22
  blocks.push sites are paired with finish_block_dependencies.

What was run:
- cargo test --manifest-path crates/compiler/Cargo.toml --test par_leading
  test result: ok. 18 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
- same with the #517 src fix reverted:
  test result: FAILED. 8 passed; 10 failed (all new tests except the
  argument_inlines guard fail)
- cargo test --manifest-path crates/compiler/Cargo.toml: exit 0,
  57 test binaries, 680 passed, 0 failed, 5 ignored
- Ad-hoc parse of 962 repo .tex files plus PR #42's 53 case .tex files:
  no count mismatch on the #517 branch.

Next step: render-pipeline builds against its vendor/compiler, so the
adapter assert on main clears only after a vendor re-pin past #517.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
@d-q222

d-q222 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

daniel-parent subagent (claude-opus-5): follow-up on the adapter.rs:1261 debug assert (7 vs 5) on PR #42's extended/graphics-transform-color.

Findings

Commit: 368d79e adds tests only, in crates/compiler/tests/par_leading.rs:

  • \colorbox and \fcolorbox cases.
  • \par inside a box argument.
  • The graphics-transform-color case, verbatim.
  • An argument_inlines guard.
  • A property test that every .tex under fixtures/real-world and fixtures/divergence-probes has blocks.len() == block_par_leading.len().

Test results

  • cargo test --manifest-path crates/compiler/Cargo.toml --test par_leading:
    test result: ok. 18 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
  • The same run with the src fix reverted: test result: FAILED. 8 passed; 10 failed
  • Full cargo test --manifest-path crates/compiler/Cargo.toml: exit 0, 57 test binaries, 680 passed, 0 failed, 5 ignored.

d-q222 added a commit that referenced this pull request Sep 15, 2026
… in step"

What changed:
- Reverts 86100a7. The same two truncations (box_inlines and
  tabular_cell_inlines) are already open in #517
  (agent/daniel-parent/parleading-assert), found after committing; this
  PR leaves that fix to #517 and lists the fuzz finding as covered by it.

What was run:
- git revert (no code of this PR's own remains in crates/compiler)

Next step: none for this finding here; #517 merges and vendor re-pins.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
d-q222 added a commit that referenced this pull request Sep 15, 2026
What changed:
- adapter::list_stack_at and in_theorem_environment searched
  `source[from..at]` for the next \begin and the next \end again after
  every hit; whenever one was absent that search ran to `at`, so each
  call was O(begins x bytes). Both now replay one ordered
  begin_end_commands scan, found exactly as find_command finds them.
- That scan and setlist_calls' \setlist ranges are indexed once per text
  for the adapt call, on the existing MacroDefsScope entry (the same
  (address, length) key the macro-definition index uses), since they run
  for every list item and every paragraph.
- Fuzz findings (render-pipeline fuzz_render, "hang in render" with the
  compiler fixes of #577 applied): a mutated enumitem worksheet 37.5 s ->
  0.29 s; page-builder enlarge-00 21.5 s -> 0.19 s; a 715-page list of
  20 000 items 23.3 s -> 0.13 s; 1 000 nested itemize 23.8 s -> 0.15 s;
  a plain 5 000-paragraph article with a center per paragraph 8.0 s ->
  1.1 s; 300 items inside 1 000 open centers 7.4 s -> 25 ms (identical
  PDF bytes). All release timings through fuzz_render --diagnostics.

What was run:
- cargo test --test fuzz_regressions -- a_long_list list_items_inside,
  before: FAILED. 0 passed; 2 failed (17.3 s and 18.7 s to adapt);
  after: test result: ok. 2 passed; 0 failed; finished in 0.27s
- cargo test --no-fail-fast (render-pipeline): 368 passed, 12 failed;
  all 12 panic at src/adapter.rs:1261 (block_par_leading debug assert,
  #517) in letter_class_geometry, uline, underline_sout, xcolor_oracle;
  letter_class_geometry fails identically with this change stashed.

Next step: the 50k rerun on the fixed branch.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
GoKubar pushed a commit that referenced this pull request Sep 15, 2026
…prime (#278) (#528)

What changed:
- The prime's box geometry already matched pdflatex (compiler #174 and
  math-layout #172): script size, sup shift, one superscript for f'',
  f'^2 joining it, f_1'/x'_a sub+sup. What was wrong was the painted
  glyph. The pipeline drew cmsy "30 with Latin Modern Math's cmap glyph
  for U+2032 (`minute`, ink 430..748/1000 em). That glyph is pre-raised
  for unscripted Unicode use, so at the superscript position it sat
  2.7-3.1bp too high at the bottom and 1.3-1.5bp at the top.
- mathfont.rs reads the face's GSUB `ssty` lookups (AlternateSubst, plus
  Single and Extension). mathtex.rs paints cmsy "30 with the first ssty
  alternate, `minute.st` (ink 96..549, cmsy's unraised design; lmsy7 is
  41..559).
- tests/math_primes.rs pins the pdflatex \showbox oracle (10pt and 12pt,
  inline and display, f'(x) f'' f''' f^{\prime} f'^2 f_1' x'_a) for
  placement, and lmsy7/lmsy8 AFM ink for the prime, at 0.5bp.

What was run:
- cargo test --test math_primes (before fix): test result: FAILED. 1 passed; 1 failed
- cargo test --test math_primes (after): test result: ok. 2 passed; 0 failed
- render-pipeline full suite: every failure (letter_class_geometry 5, uline 2,
  underline_sout 4, xcolor_oracle 1) panics at src/adapter.rs:1261, the
  par-leading debug_assert that open PR #517 fixes; no other failures
- math-layout and compiler: see PR

Next step: re-check the Mac app rendering of f'(x) once this lands.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
@GoKubar
GoKubar merged commit 5a880f2 into main Sep 15, 2026
21 checks passed
@GoKubar
GoKubar deleted the agent/daniel-parent/parleading-assert branch September 16, 2026 04:16
ItsAkilesh pushed a commit to ItsAkilesh/flashtex that referenced this pull request Sep 18, 2026
…ild profile (flash-tex#667)

What changed:

`adapt_cached` paired `Parsed::blocks` with the compiler's
`Parsed::block_par_leading` positionally, behind a `debug_assert_eq!` that the
two are the same length. Against the pinned `vendor/compiler` they are not:
its `P::box_inlines` does not truncate `block_par_leading` after parsing a box
argument the way `P::argument_inlines` does, so every `\colorbox`/`\fcolorbox`
leaves one stray entry -- the leading of a paragraph that never reached
`blocks`. `crates/compiler` fixed that in flash-tex#517; `vendor/` is still pinned
before it.

The consequence was profile-dependent output from one input: a debug build
panicked at `adapter.rs:1308` (`left: 2, right: 1`, the `frame_env` failure in
flash-tex#667), and a release build compiled the assert away and mis-paired, because a
stray entry is pushed *before* the block whose paragraph holds the box, so
from the first box onwards entry i no longer names block i.

The pairing now goes through `block_leadings`, which uses the compiler's list
only when it is exactly one entry per block and otherwise discards it -- every
block falls back to the body leading, exactly as a `--no-default-features`
build does. The decision reads only its arguments, so both profiles lay the
same document out the same way, and the feature resumes by itself when
`vendor/` is re-pinned past flash-tex#517. No `vendor/` file is touched.

What was run:

    cargo test --release --test par_leading_box_profile   (before this change)
      a_box_interiors_size_is_not_the_paragraphs_leading FAILED
        \colorbox of \small: line pitch 14207356 is not the body's 15147549
      a_box_does_not_shift_the_leadings_of_the_blocks_after_it FAILED
        a \colorbox of \tiny in the second paragraph: line pitch 12117846 is
        not the body's 15147548
      test result: FAILED. 0 passed; 2 failed

    cargo test --test frame_env --test par_leading_box_profile \
      --test par_leading_oracle          (debug, after)
      test shared_colorbox_path_draws_border_with_content_inside ... ok
      test result: ok. 1 passed; 0 failed; 1 ignored
      test result: ok. 2 passed; 0 failed
      test result: ok. 9 passed; 0 failed

    cargo test --lib block_leadings      (debug and release, after)
      test adapter::tests::block_leadings_are_profile_independent ... ok
      test result: ok. 1 passed; 0 failed (both profiles)

Next step:

Re-pin `vendor/compiler` past crates/compiler flash-tex#517 so `block_par_leading` is
one entry per block again and the `par-leading` feature applies to documents
that use `\colorbox`/`\fcolorbox`; these tests then still hold.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
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.

2 participants