`x 1 idiv` was simplified to `x`, so the Wasm and JS compilers returned a
non-integer x unchanged (e.g. 7.5), whereas the interpreter truncates it
(7). It's now simplified to `truncate(x)`.
`x -1 exp` was rewritten as `1 x div`, which gives 0 for x = 0 since a
division by zero returns 0, whereas the interpreter computes Infinity,
which is then clipped to the range. This rewrite is removed.
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.
Cap expression depth to bound recursive comparison, sharing analysis and
code generation. The JS builder interprets deeper expressions. Reject
excessive procedure nesting during parsing.
Stack-growing `if` forks and comparisons of distinct DAGs can take
exponential work. Limit instruction and comparison work and fork depth;
the JS builder uses the interpreter when conversion exceeds a limit.
`OP.drop` wasn't defined, so the dividend was followed by a 0x00 byte
(`unreachable`) and the function trapped when called, dropping the rest of
the page. Since the result is 0 whatever the dividend is, just emit 0.
The rule rewrites `Math.max(C, Math.min(A, B))` to `MathClamp(A, C, B)`, always
taking the inner call's first operand as the value. `Math.min` is commutative,
so the value is just as often the second one, and then the fixer swaps it with
the upper bound: the result is `Math.min(C, v)`, which no longer applies the
lower bound at all. Both call sites the fixer rewrote hit that case, so the
max-outer patterns are now reported without a fix.
Reporting them still needs its own message. `Math.max(C, Math.min(A, B))` is
only `MathClamp(A, C, B)` when `C <= B`, and the rule can't know whether that
holds, so telling the reader to "use MathClamp" is wrong advice. The message
states the condition instead, and `useClamp` is left to the min-outer patterns,
which are exact.
In `PSStackBasedInterpreter.build` the outputs were therefore never clamped up
to the Range minimum. The interpreter runs whenever `PSStackToTree` can't turn
the program into a tree — a stack-shrinking `if`, or a `copy`/`index`/`roll`
whose operand isn't a constant — and it then let a Type 4 function return e.g.
-1.5 for a component declared as `/Range [0 1]`.
In `SplitView.#clampFirstSize` the first pane's size was never clamped up to
`#minSize`: dragging the resizer past it wrote a negative `flexGrow`.
The existing range-clamping test only checked the upper bound, which is the one
the wrong operand order preserves.
Currently we mostly use `toThrow()`, which seems intended for things that throw non-Errors (something that we "forbid" with ESLint).
Hence `toThrowError()` seems more appropriate, and it also simplifies things slightly; see https://jasmine.github.io/api/edge/matchers.html#toThrowError
The Type-4 PostScript -> Wasm compiler emitted i32.const immediates with the
unsigned LEB128 encoder (_emitULEB128). Wasm decodes i32.const as a *signed*
LEB128, so any immediate whose final 7-bit group has bit 0x40 set is
mis-decoded (e.g. 64 -> single byte 0x40 -> read back as -64).
The output-store address for the i-th result is emitted as i32.const (i*8).
For a function with >= 9 outputs the 9th offset is 64, which decodes as -64, so
f64.store targets 0xFFFFFFC0 and traps (memory access out of bounds). The module
still validates and instantiates, so the JS fallback in function.js is not
engaged; the trap only surfaces at render time (the affected shading / tint
transform silently fails to render). The same mis-encoding affects the constant
bitshift amount.
Add a signed-LEB128 emitter (_emitSLEB128) and use it for the three i32.const
immediate sites; local/import/type indices remain unsigned (correct). Add a unit
test covering functions with 9+ outputs, and a reference test rendering a shading
whose colour function has 9 outputs.
The main goal is to remove the eval-based interpreter.
In order to have some good performances, the new parser performs some optimizations
on the AST (similar to the ones in the previous implementation),
and the Wasm compiler generates code for the optimized AST.
For now, in case of errors or unsupported features, the Wasm compiler returns null
and the old interpreter is used as a fallback.
Few things are still missing:
- a wasm-based interpreter using a stack (in case the ps code isn't stack-free);
- a better js implementation in case of disabled wasm.
but they will be added in follow-up patches.