develooper Front page | perl.perl5.porters | Postings from July 2010

Re: [perl #76438] peephole optimiser could prune more dead code

Thread Previous | Thread Next
From:
James Mastros
Date:
July 11, 2010 02:35
Subject:
Re: [perl #76438] peephole optimiser could prune more dead code
Message ID:
AANLkTikDutBxsTELrJ4js8Yb7ltQLRA2rBPmRSLHYU6a@mail.gmail.com
On 11 July 2010 00:25, Leon Timmermans <fawaka@gmail.com> wrote:
> On Sat, Jul 10, 2010 at 9:16 PM, Ben Morrow <ben@morrow.me.uk> wrote:
>> Quoth fawaka@gmail.com (Leon Timmermans):
>> Most of those forms of magic don't have meaningful side-effects, though,
>> at least on mg_get. (That is, they may have side-effects, but it doesn't
>> matter if they aren't invoked. Tainting is the obvious exception.) This
>> is what really matters from the pov of optimisation.
>
> If you're only ignoring get magic and not set magic, I guess it's
> possible if you special-case special variables with get magic such as
> $!. @_ elements should probably also be exempt or else passing a tied
> argument will break very confusingly. I'm not entirely sure what the
> consequences of ignoring substr, pos and $#array and autovivication
> get magic. I suspect they'll work in the common case, but will break
> in corner cases.

I think what Nick was getting at, and certainly what I was getting at,
was not that we should bypass get magic, but rather that, in marked
blocks, it should be acceptable to not call get magic *when the output
is not relevant*, and to cache the value of the get magic during that
lexical scope, each execution.  That is, we assume that values act
like values, and not like hidden accessors.  $! would still work, so
long as we don't look at $! twice and expect it to change.  That is:

  {
    use less 'magic'; # best name I've seen, we aren't not using it,
just using less of it.
    if ($!) {
      die "Rock me, Amadeus: $!"
    }
  }

is OK.  We invoke the get magic, once, and assume the value hasn't
changed by the second time we want it, possibly, but it shouldn't
anyway.

@_ elements is probably a matter of "don't do that, then".  However,
it's only a problem if the thing passed in has get magic that make it
not act like a normal value during the period the pragma is in effect.

   -=- James Mastros / theorbtwo

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About