Fix reduce to preserve its input across init backtracking (#3633)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
`reduce f as $x (init; update)` evaluated `f` against a stack slot that forkpoints created while evaluating `init` restore. Both the `DUPN` opening the reduction loop and the `LOADVN` retrieving the result pop that slot destructively, nulling it out, so an `init` that backtracks (e.g. `0, 0`) made `f` see `null` and fail with "Cannot iterate over null". Duplicate the input before the `FORK` instead of inside the loop, and drop the leftover copy with `POP` once the loop is exhausted. The slot left live at the `FORK` is then a block pushed after `init` completed, which no earlier forkpoint can reach, so nulling it is harmless. This is the same approach `gen_foreach` has used since c70ae1a. `DUPN` had no other user, so remove the opcode.
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+10 added−11 removed
- tests:+7 added−1 removed
- other:+3 added−10 removed