This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
(perl #108276) remove recursion from optimize_op()
authorTony Cook <tony@develop-help.com>
Tue, 29 Jan 2019 05:29:04 +0000 (16:29 +1100)
committerTony Cook <tony@develop-help.com>
Mon, 4 Feb 2019 23:02:26 +0000 (10:02 +1100)
commite76010b6a580610b68e389d4bfcdf53d64dbbdea
treecd82993080a40529415a33af97eb519616fc03d4
parent3d5b2488ead2c20cc64174fabd97bb7a32da097f
(perl #108276) remove recursion from optimize_op()

The prevented code like:

  ./miniperl -e 'my $line = "\$cond ? \$a : \n"; my $code = ($line x 100000) . "\$b;\n"; eval $code;'

from crashing due to stack overflow.

It does however take a long time to compile.

Because it doesn't strictly recurse through the op tree (due
to OP_SUBST), I couldn't use traverse_op_tree().

I considered wrapping a traverse_op_tree() loop inside a defer op
loop, so OP_SUBST would defer its op, but processing order is
somewhat important from setting PL_curcop.

This also processes the child ops in reverse order, I'm not sure if
that's a real problem (no tests failed), but the next commit fixes
that order.
op.c