This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
pessimise pp_argelem, pp_argdefelem
authorDavid Mitchell <davem@iabyn.com>
Thu, 28 Jul 2016 09:18:26 +0000 (10:18 +0100)
committerDavid Mitchell <davem@iabyn.com>
Wed, 3 Aug 2016 19:54:41 +0000 (20:54 +0100)
commitf6ca42c773b76d4df15c9f344fae751bf4f53e2e
tree5aa806b806453aedc7d894c15c8590355ea3204f
parent6daeaaa3123e456674380042544721b5f7a41f69
pessimise pp_argelem, pp_argdefelem

These two ops assumed that, since they occur at the start of a
function, weird tricks with goto and closures can't be used to
cause the new lexical vars to already have a value, so the assign code
can be simpler and quicker than that found in pp_sassign and pp_aassign.

However Father Chrysostomos demonstrated that this wasn't the case,
using e.g. code that does strange things in signature default expressions.

In particular we can not assume:

    * that scalar lexicals will be undef
    * that array and hash lexicals will be empty
    * that lexicals and @_ can't be magical or tied;
    * that @_ remains unchanged (especially in relation to its number of
      elements)
    * that there are no common elements, since with aliases and closures,
      my @a = @_ can be equivalent to my @a = (...); @a = ($a_[0],...)

So this commit removes the short-cuts, and for aggregates, if the
new lexical array or hash may be non-empty, makes a copy of each @_
element first.

It is intended in the near future that normal runs of OP_ARGELEM
will be replaced by OP_SIGNATURE, which will be able to do a better job of
knowing when its safe to optimise.
pp.c
t/op/signatures.t