in reply to Re: Why isn't return removed from optree?
in thread Why isn't return removed from optree?

I don't think you can avoid that, but I'm not completely certain.

You might have to remove the pushmark along with the return. When you do that, you get exactly the same opcode tree as if you hadn't used the return keyword, so it's obviously safe.

Replies are listed 'Best First'.
Re^3: Why isn't return removed from optree?
by ikegami (Patriarch) on Dec 29, 2008 at 08:45 UTC

    Ah-ha! I found a situation where return can't simply be omitted.

    >perl -MO=Concise,f -e"sub f { return ($x,$y) }" main::f: 6 <1> leavesub[1 ref] K/REFC,1 ->(end) - <@> lineseq KP ->6 1 <;> nextstate(main 1 -e:1) v ->2 5 <@> return KP ->6 2 <0> pushmark s ->3 - <1> ex-rv2sv sK/1 ->4 3 <#> gvsv[*x] s ->4 - <1> ex-rv2sv sK/1 ->5 4 <#> gvsv[*y] s ->5 -e syntax OK >perl -MO=Concise,f -e"sub f { ($x,$y) }" main::f: 6 <1> leavesub[1 ref] K/REFC,1 ->(end) - <@> lineseq KP ->6 1 <;> nextstate(main 1 -e:1) v ->2 5 <@> list KP ->6 2 <0> pushmark s ->3 - <1> ex-rv2sv sK/1 ->4 3 <#> gvsv[*x] s ->4 - <1> ex-rv2sv sK/1 ->5 4 <#> gvsv[*y] s ->5 -e syntax OK

    That gives me something to look at.

      But how are they different? Those both do exactly the same thing in both a scalar and list context, as far as I could tell.

        Are you suggesting that the optimizer should replace the return with list? I don't remember seeing it replace one op for another except in constant folding.