[perl #113710] Make __SUB__ work in sort block
When the peephole optimiser encounters a __SUB__, it looks to see
whether the current sub is clonable. If it is not, it inlines the
__SUB__ as a const op.
This works most of the time. A forward declaration will cause the sub
definition to reuse the existing stub. When that happens, the sub
visible during compilation in PL_compcv is not the sub that the
op tree will finally be attached to. But the peephole optimiser
is called after that, with PL_compcv set to the other CV (what
was a stub).
ck_sort was calling the peephole optimiser on the sort block ahead of
time. So this caused __SUB__ to point to the wrong subroutine.
By removing the CALL_PEEP call from ck_sort and adding logic to the
peephole optimiser itself to traverse the sort block (it is not in the
usual op_next chain), this bug is eliminated.
I modified the DEFER macro to work as a single statement. You don’t
want to know how much time I spent debugging the bus errors that were
occurring because if(foo) DEFER; didn’t do what I though.
It turns out that grepstart and mapstart, which also use ck_sort,
had their blocks go through the peephole optimiser twice, because
grepwhile already has special-casing in the peephole optimiser.
This also has the side-effect of making map and grep slightly more
efficient, in that they no longer execute a scope op (which is just
pp_null). By temporarily disconnecting the subtree before running the
optimiser, ck_sort was hiding a possible optimisation (skipping the
scope op).