newarray, duparray, concatarray, and splatarray always leave an array at the top of the stack. expandarray does not, it takes an array from the top of the stack as input, and leaves individual elements on the stack. I assume no Ruby code generates the expandarray/splatarray sequence, or it could break. The only use of expandarray outside the peephole optimizer is in the masgn code, and it does not appear to generate splatarray directly after expandarray.
The splatarray/splatarray peephole optimization is probably also wrong in the following case:
putobject [1,2] splatarray false splatarray true
This instruction sequence should result in a duplicate of [1,2] at the top of the stack, but the peephole optimizer would remove the splatarray true, resulting in change that made [1,2] on top of the stack. I'm not sure Ruby code can generate splatarray false followed by splatarray true (I could get it to generate chains of splatarray true), so maybe this has no effect.
newarray, duparray, and concatarray all result in newly allocated arrays at the top of the stack, so they shouldn't have an issue with removing either splatarray true or splatarray false.
Remove expandarray/splatarray sequence peephole optimization
newarray, duparray, concatarray, and splatarray always leave an
array at the top of the stack. expandarray does not, it takes
an array from the top of the stack as input, and leaves individual
elements on the stack. I assume no Ruby code generates the
expandarray/splatarray sequence, or it could break. The only
use of expandarray outside the peephole optimizer is in the
masgn code, and it does not appear to generate splatarray
directly after expandarray.
The splatarray/splatarray peephole optimization is probably
also wrong in the following case:
This instruction sequence should result in a duplicate of
[1,2] at the top of the stack, but the peephole optimizer would
remove the
splatarray true, resulting in change that made[1,2] on top of the stack. I'm not sure Ruby code can generate
splatarray falsefollowed bysplatarray true(I could get itto generate chains of
splatarray true), so maybe this has noeffect.
newarray, duparray, and concatarray all result in newly allocated
arrays at the top of the stack, so they shouldn't have an issue
with removing either
splatarray trueorsplatarray false.