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

Reading through pp_return confirmed my initial guess that the return opcode checks the calling context and performs the appropriate stack manipulations. I don't think you can avoid that, but I'm not completely certain.

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

    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.

      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.