Skip to content

Keep the stacks aligned on their top in PSStackToTree - #22417

Merged
calixteman merged 1 commit into
mozilla:masterfrom
zerotohero3:ps-type4-stack-alignment
Nov 6, 2026
Merged

calixteman merged 1 commit into
mozilla:masterfrom
zerotohero3:ps-type4-stack-alignment

Conversation

@zerotohero3

Copy link
Copy Markdown
Contributor

Fixes #22415

When the two paths of a stack-growing if, or the two branches of an ifelse, end with different stack depths, the shorter stack was padded with zeros on its top, so the following operators used these zeros instead of the actual values. The shorter stack is now padded at its bottom.

And when a function leaves more values on the stack than it has outputs, the Wasm/JS compilers now use the ones at the top, as the interpreter does.

The first row of the new reference test uses the tint transform from issue5470.pdf, which is currently only right for a tint of 1.

@calixteman calixteman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall it LGTM, but your LLM missed a caller in src/core/internal_viewer_utils.js.

When the two paths of a stack-growing `if`, or the two branches of an
`ifelse`, end with different stack depths, the shorter stack was padded
with zeros on its top. The following operators then used these zeros
instead of the actual values: for example the tint transform in
issue5470.pdf is only correct when its guard fires, i.e. for a tint of 1,
and any other tint is rendered in a darker red instead of red.

Pad the bottom of the shorter stack instead. And when a function leaves
more values on the stack than it has outputs, use the ones at the top, as
the interpreter does, instead of the ones at the bottom.
@zerotohero3
zerotohero3 force-pushed the ps-type4-stack-alignment branch from 91e2135 to 0aaac44 Compare November 2, 2026 16:51
@zerotohero3

Copy link
Copy Markdown
Contributor Author

Good catch, thanks. postScriptToJSCode was taking the outputs from the bottom of the stack too; it's fixed now, as well as the usage example in the PSStackToTree comment.

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Viewer preview

🗑️ Viewer previews removed.

@codecov-commenter

codecov-commenter commented Nov 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.57%. Comparing base (6a12ce7) to head (0aaac44).
⚠️ Report is 64 commits behind head on master.

Files with missing lines Patch % Lines
src/core/postscript/ast.js 75.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #22417      +/-   ##
==========================================
- Coverage   90.58%   90.57%   -0.01%     
==========================================
  Files         278      278              
  Lines       68586    68665      +79     
==========================================
+ Hits        62126    62193      +67     
- Misses       6460     6472      +12     
Flag Coverage Δ
fonttest 8.99% <ø> (ø)
integrationtest 69.59% <41.66%> (-0.01%) ⬇️
unittest 61.28% <83.33%> (+0.01%) ⬆️
unittestcli 59.02% <83.33%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codspeed

codspeed Bot commented Nov 6, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 0.45%

⚡ 1 improved benchmark
❌ 1 regressed benchmark
✅ 86 untouched benchmarks
⏩ 174 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ EvaluatorPreprocessor.read: paths (bug1743245.pdf) 56.1 ms 63.9 ms -12.27%
⚡ Pattern.parseShading: radial (radial_gradients.pdf) 7.1 ms 6.2 ms +12.97%

Tip

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


Comparing zerotohero3:ps-type4-stack-alignment (0aaac44) with master (f70fabb)

Open in CodSpeed

Footnotes

  1. 174 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. ↩

@calixteman calixteman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you.

@calixteman
calixteman merged commit ce50f71 into mozilla:master Nov 6, 2026
26 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Wrong colors with Type 4 functions whose paths end with different stack depths

4 participants