Skip to content

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

Open
zerotohero3 wants to merge 1 commit into
mozilla:masterfrom
zerotohero3:ps-type4-stack-alignment
Open

zerotohero3 wants to merge 1 commit into
mozilla:masterfrom
zerotohero3:ps-type4-stack-alignment

Conversation

@zerotohero3

Copy link
Copy Markdown

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
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.

This branch has not been deployed

No deployments
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.

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

2 participants