develooper Front page | perl.perl5.porters | Postings from August 2018

Re: [perl #133301] Evalulation order during concat changed

Thread Previous | Thread Next
Dave Mitchell
August 24, 2018 08:38
Re: [perl #133301] Evalulation order during concat changed
Message ID:
On Thu, Aug 23, 2018 at 02:39:08PM -0500, David Nicol wrote:
>  Binary C<"."> concatenates two strings.
> +
> +A series of terms joined by  C<"."> operators are evaluated prior to
> +all getting concatenated in a single operation.  Prior to version 5.28,
> +aliasing issues only affected the value of the first term in a series
> +of concatenations, as the left side of the second and later operations
> +was the intermediate result of the previous binary operation.

What this documentation patch does, is change what was undefined
behaviour (or at least that was my feeling of where the discussion ended
up) into defined behaviour, which we are now committed to support.

I don't want the internal (and possibly changeable) details of an
optimisation to become a straight jacket.

But the actual details of the ordering are much more complicated than
implied by the text of your patch. For example in 5.28.0 onwards, which
order do you think these functions are called and the concatenations done:

    ( f1() . f2() )   .   ( f3() . f4() )

The order is actually equivalent to

    $tmp1   = f1();
    $tmp2   = f2();
    $tmp3   = f3();
    $tmp4   = f4();
    $tmp5   = $tmp3 . $tmp4;
    $result = $tmp1 . $tmp2 . $tmp5;

Would you have predicted that? Does your text describe that? Could you
come up with some text that could always describe what happens.

In conclusion, I don't think the pod for the concatenation op should
specify anything about order. I think that we should however fix the text
recently added to perlop which implied a guarantee about the ordering of
arg evaluation in general which we shouldn't have given.

"I used to be with it, but then they changed what ‘it’ was, and now what
I’m with isn’t it. And what’s ‘it’ seems weird and scary to me."
  -- Grandpa Simpson
(It will happen to you too.)

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About