In perl.git, the branch smoke-me/davem/contextsB4 has been created

<http://perl5.git.perl.org/perl.git/commitdiff/4a3130e5e0f72f1c1732ba0cb8fa73c4ed1169dc?hp=0000000000000000000000000000000000000000>

        at  4a3130e5e0f72f1c1732ba0cb8fa73c4ed1169dc (commit)

- Log -----------------------------------------------------------------
commit 4a3130e5e0f72f1c1732ba0cb8fa73c4ed1169dc
Author: David Mitchell <[email protected]>
Date:   Mon Jan 4 09:16:52 2016 +0000

    make gimme consistently U8
    
    The value of gimme stored in the context stack is U8.
    Make all other uses in the main core consistent with this.
    
    My primary motivation on this was that the new function cx_pushblock(),
    which I gave a 'U8 gimme' parameter, was generating warnings where callers
    were passing I32 gimme vars to it. Rather than play whack-a-mole, it
    seemed simpler to just uniformly use U8 everywhere.
    
    Porting/bench.pl shows a consistent reduction of about 2 instructions on
    the loop and sub benchmarks, so this change isn't harming performance.

M       cop.h
M       doop.c
M       embed.fnc
M       gv.c
M       pod/perlcall.pod
M       pod/perlguts.pod
M       pp.c
M       pp.h
M       pp_ctl.c
M       pp_hot.c
M       pp_pack.c
M       pp_sort.c
M       pp_sys.c
M       proto.h
M       regexec.c
M       universal.c

commit 9286c4e749b513b3ce2fd4a3dfac397a8c81d651
Author: David Mitchell <[email protected]>
Date:   Sun Jan 3 19:38:13 2016 +0000

    fix -DPERL_GLOBAL_STRUCT_PRIVATE
    
    Perl_leave_adjust_stacks() needed a dVAR

M       pp_hot.c

commit 76ce8d0ad41664ef0a25927c2ec005a82a18e143
Author: David Mitchell <[email protected]>
Date:   Sun Jan 3 17:28:06 2016 +0000

    perlfunc: say what block types 'return' recognises
    
    'return' recognises these blocks
    
        sort { ...; return } ...
        /(?{ ...; return })/;
    
    but ignores these:
    
        grep { ...; return } ...;
        map  { ...; return } ...;

M       pod/perlfunc.pod

commit 2021b39b05b5ad1e953610f9264cf88412e90416
Author: David Mitchell <[email protected]>
Date:   Sun Jan 3 15:23:56 2016 +0000

    perlguts: add section on context stack

M       pod/perlguts.pod

commit 5d67df92d3f3c075422406f71c87aa9d62b0cbc3
Author: David Mitchell <[email protected]>
Date:   Sun Jan 3 15:17:40 2016 +0000

    fix cx_dup for CXt_LOOP_PLAIN
    
    The context stack duplication code tries to duplicate the loop var
    even for CXt_LOOP_PLAIN, which doesn't have a loop var. This didn't
    use to matter, since PUSHLOOP_PLAIN() used to set the field to NULL;
    for efficiency its now left untouched. So don't try to use it.
    
    Also update the debugging context names since the ordering of the
    CXt_LOOP_* has changed recently.

M       perl.h
M       sv.c

commit 9ec9aec671ca0984b9543b0b0fdd6aa967001a0d
Author: David Mitchell <[email protected]>
Date:   Thu Dec 31 10:39:17 2015 +0000

    MULTICALL *shouldn't* clear savestack
    
    About 25 commits ago in this branch I added a commit:
    
        MULTICALL should clear scope after each call
    
    To fix RT #116577, which reported that lexicals were only being freed
    at the end of the MULTICALL, not after each individual call to the sub.
    
    In that commit, I added a LEAVE_SCOPE() to the end of the MULTICALL()
    definition. However, after further thought I realise that's wrong.  If a
    multicall sub does something like { my $x = $_*2; $x }, then the returned
    value would be freed before the XS code which calls MULTICALL() has a
    chance to do anything with it (e.g. test for truth, or add it to the return
    args or whatever).
    
    So I think popping the save stack should be the responsibility of the
    caller of MULTICALL(), rather than of MULTICALL() itself.

M       cop.h
M       ext/XS-APItest/t/multicall.t
M       regexec.c

commit f08f3cb3faa78bd5a141afad4a8a38777c168221
Author: David Mitchell <[email protected]>
Date:   Wed Dec 30 15:48:52 2015 +0000

    add blk_old_tmpsfloor shortcut
    
    Add
    
        #define blk_old_tmpsfloor cx_u.cx_blk.blku_old_tmpsfloor
    
    to match all the other 'struct block' fields which have similar short cuts

M       cop.h
M       inline.h

commit 0a8fffa6915fbd464ae4d197d00ca9f450007236
Author: David Mitchell <[email protected]>
Date:   Wed Dec 30 15:20:41 2015 +0000

    dMULTICALL: remove unused vars
    
    dMULTICALL declares several vars that are used either to maintain
    state across multiple calls, or to pass values to PUSHSUB etc, where
    those macros expected to obtain some of their args by values being
    implicitly passed via local vars. Since PUSHSUB has been replaced by
    cx_pushsub() which now has all parameters explicitly passed, there is
    no longer any need for those vars. So this commit eliminates them:
    
        newsp
        hasargs
    
    There are also a couple vars which are no longer used due to changes to
    the implementation over time; these can also be eliminated:
    
        cx multicall_cv
    
    Finally, this branch introduced a new var, saveix_floor; rename it to
    multicall_saveix_floor for consistency with other dMULTICALL vars.
    
    Although none of these vars are listed in the documentation, its possible
    that some code out there may rely on them in some way, and will need to be
    fixed up.

M       cop.h
M       ext/XS-APItest/APItest.xs
M       regexec.c

commit c9eed1abd0181f3f42b479e61532a8ab24bc571b
Author: David Mitchell <[email protected]>
Date:   Wed Dec 30 14:33:51 2015 +0000

    convert CX_{PUSH|POP}{WHEN|GIVEN} to inline fns
    
    Replace CX_PUSHGIVEN() with cx_pushgiven() etc.

M       cop.h
M       embed.fnc
M       embed.h
M       inline.h
M       pp_ctl.c
M       proto.h

commit 93d95af2e873e96b73759a74571118bf0b03b8b2
Author: David Mitchell <[email protected]>
Date:   Wed Dec 30 14:18:05 2015 +0000

    convert CX_PUSHLOOP*/POPLOOP to inline fns
    
    Replace CX_PUSHLOOP_FOR() with cx_pushfloop_for() etc.

M       cop.h
M       embed.fnc
M       embed.h
M       inline.h
M       pp_ctl.c
M       proto.h

commit 67e75756db51472604d971c663508dc3517871db
Author: David Mitchell <[email protected]>
Date:   Wed Dec 30 13:23:47 2015 +0000

    convert CX_PUSHEVAL/POPEVAL to inline fns
    
    Replace CX_PUSHEVAL() with cx_pusheval() etc.
    
    No functional changes.

M       cop.h
M       embed.fnc
M       embed.h
M       inline.h
M       op.h
M       perl.c
M       pp_ctl.c
M       proto.h

commit ee0d05ea0d551c66e7050a8dc6e49c57470de9b5
Author: David Mitchell <[email protected]>
Date:   Wed Dec 30 13:09:36 2015 +0000

    convert CX_PUSHFORMAT/POPFORMAT to inline fns
    
    Replace CX_PUSHFORMAT() with cx_pushformat() etc.
    
    No functional changes.

M       cop.h
M       embed.fnc
M       embed.h
M       inline.h
M       pp_ctl.c
M       pp_sys.c
M       proto.h

commit 3a7e4303116ccc4dc16626a44570e4333ec5d47b
Author: David Mitchell <[email protected]>
Date:   Wed Dec 30 12:33:48 2015 +0000

    convert CX_PUSHSUB/POPSUB to inline fns
    
    Replace CX_PUSHSUB() with cx_pushsub() etc.
    
    No functional changes.

M       cop.h
M       embed.fnc
M       embed.h
M       inline.h
M       pp.c
M       pp_ctl.c
M       pp_hot.c
M       pp_sort.c
M       proto.h
M       t/op/args.t

commit 78572c6a11d5de28173d4317de1b747e4143fc8f
Author: David Mitchell <[email protected]>
Date:   Wed Dec 30 11:46:22 2015 +0000

    convert  CX_PUSH/POP/TOPBLOCK to inline fns
    
    Replace CX_PUSHBLOCK() with cx_pushblock() etc.
    
    No functional changes.

M       cop.h
M       embed.fnc
M       embed.h
M       ext/XS-APItest/APItest.xs
M       inline.h
M       op.c
M       perl.c
M       pp_ctl.c
M       pp_hot.c
M       pp_sort.c
M       pp_sys.c
M       proto.h

commit 4ebb9ea90629451031134134fe7a700b4e2d079b
Author: David Mitchell <[email protected]>
Date:   Tue Dec 29 10:05:29 2015 +0000

    add a few grep and map benchmarks

M       t/perf/benchmarks

commit a5302e22e9dbc9c9e9e7f6d6ec88efffecad0313
Author: David Mitchell <[email protected]>
Date:   Sun Dec 27 14:07:02 2015 +0000

    offset PL_savestack_max by SS_MAXPUSH
    
    The newer SS_ADD macros expect there to always be SS_MAXPUSH slots
    free on the savestack; so they can push multiple items, then only check
    once at the end whether stack needs expanding.
    
    This commit makes savestack_grow() set PL_savestack_max to SS_MAXPUSH
    short of what has actually been allocated. This makes the tests
    to see whether the stack needs growing slightly simpler, i.e.
    
        PL_savestack_ix > PL_savestack_max
    
    rather than
    
        PL_savestack_ix + SS_MAXPUSH > PL_savestack_max

M       perl.c
M       scope.c
M       scope.h

commit c57d35f69325d18487e0ff8c0224549a3df19569
Author: David Mitchell <[email protected]>
Date:   Sun Dec 27 10:41:41 2015 +0000

    add SAVEt_TMPSFLOOR save type and Perl_savetmps()
    
    By making SAVETMPS have its own dedicated save type, it avoids having to
    push the address of PL_tmps_floor onto the save stack each time.
    By also giving it a dedicated save function, the function can do
    the PL_tmpsfloor = PL_tmps_ix step too, making the binary slightly more
    compact.

M       embed.fnc
M       proto.h
M       scope.c
M       scope.h
M       sv.c

commit 2c9f9e9f9a0c4a3a6c08a07f5e2ed23c7b9c0f1c
Author: David Mitchell <[email protected]>
Date:   Sat Dec 26 22:28:59 2015 +0000

    rename PUSHBLOCK,PUSHSUB etc to CX_PUSHBLOCK etc
    
    Earlier all the POPFOO macros were renamed to CX_POPFOO to reflect
    the changed API (like POPBLOCK no longer decremented cxstack_ix).
    
    Now rename the PUSH ones for consistency.

M       cop.h
M       op.h
M       perl.c
M       pp_ctl.c
M       pp_hot.c
M       pp_sort.c
M       pp_sys.c
M       scope.c

commit 393d60101ad46aaedcbd610a2119f873162e9ae4
Author: David Mitchell <[email protected]>
Date:   Sat Dec 26 22:14:00 2015 +0000

    eliminate PUSH/POPBASICBLK macros
    
    These are both NOOPs now, and were introduced within this branch
    as a temporary measure while extra stuff needed doing when pushing or
    popping a CXt_BOCK (pp_enter/pp_leave).

M       cop.h
M       pp_ctl.c

commit 762f45e882ece96803e8bb126d1f296fcf8aa9a7
Author: David Mitchell <[email protected]>
Date:   Sat Dec 26 21:49:28 2015 +0000

    pp_enteriter: add comment about setting cxt type

M       pp_ctl.c

commit 24ed55e12bc627f0efd22c192e9e5a9ac1909980
Author: David Mitchell <[email protected]>
Date:   Sat Dec 26 13:48:43 2015 +0000

    consolidate common code in PUSHLOOP_FOR,_PLAIN

M       cop.h

commit 4652e7199675b407915ef46da3f5d955d629b7ae
Author: David Mitchell <[email protected]>
Date:   Sat Dec 26 12:45:01 2015 +0000

    PUSHEVAL: make n param an SV rather than a string
    
    Rather than doing
    
        cx->blk_eval.old_namesv = (n ? newSVpv(n,0) : NULL);
    
    make the caller responsible for creating and passing in the SV. Since
    only only place (pp_require) passes a non-null value, this saves the
    other places having to test for nullness.

M       cop.h
M       pp_ctl.c

commit 481ef2e0e4f7105a0c83363ef21ce717dbaa4f3a
Author: David Mitchell <[email protected]>
Date:   Sat Dec 26 12:37:30 2015 +0000

    PUSHSUB: make retop a parameter
    
    Rather than doing cx->blk_sub.retop = NULL in PUSHSUB, then relying on
    the caller to subsequently change it to something more useful, make it an
    arg to PUSHSUB.

M       cop.h
M       pp_ctl.c
M       pp_hot.c
M       pp_sort.c

commit 5ff8bad7d0d0c03a0716f4cd33ff4335bb79d6f1
Author: David Mitchell <[email protected]>
Date:   Sat Dec 26 12:30:25 2015 +0000

    PUSHEVAL: make retop a parameter
    
    Rather than doing cx->blk_eval.retop = NULL in PUSHEVAL, then relying on
    the caller to subsequently change it to something more useful, make it an
    arg to PUSHEVAL.

M       cop.h
M       embed.fnc
M       embed.h
M       op.c
M       perl.c
M       pp_ctl.c
M       proto.h

commit ba800efe7ac729c562e3e029952a7f02c96d6d85
Author: David Mitchell <[email protected]>
Date:   Sat Dec 26 12:07:50 2015 +0000

    PUSHFORMAT: don't use implicit args
    
    Make cv and gv explicit parameters of PUSHFORMAT(), rather than just
    assuming that there are such vars in scope.

M       cop.h
M       pp_sys.c

commit 2b62fade11b29ee9f10b2048ad9d7beab54f80f5
Author: David Mitchell <[email protected]>
Date:   Sat Dec 26 11:52:33 2015 +0000

    PUSHSUB: don't use implicit args
    
    Make cv and hasargs explicit parameters of PUSHSUB(), rather than just
    assuming that there are such vars in scope.

M       cop.h
M       pp_ctl.c
M       pp_hot.c
M       pp_sort.c

commit 17b7a75f425b268fd393b93f1d216624d729c740
Author: David Mitchell <[email protected]>
Date:   Sat Dec 26 11:39:30 2015 +0000

    PUSHBLOCK: don't use implicit args
    
    Make gimme a parameter of PUSHBLOCK() rather than just assuming that
    there's a 'gimme' var in scope.

M       cop.h
M       pp_ctl.c
M       pp_hot.c
M       pp_sort.c
M       pp_sys.c

commit 7240fadb22c0c97765569bc149c7865131aa75ee
Author: David Mitchell <[email protected]>
Date:   Fri Dec 25 23:54:23 2015 +0000

    move PL_savestack_ix saving into PUSHBLOCK
    
    Currently blku_oldsaveix was being set by the various PUSHFOO macros,
    except for PUSHSUB and PUSHEVAL which expected their caller to do it
    manually.
    
    Now that all the main context state is stored on the context stack
    rather than than some on the save stack too, things are a lot simpler,
    and this messy transitional state can now be rationalised, whereby
    blku_oldsaveix is now always set by PUSHBLOCK; the exact value being
    specified by a new arg to PUSHBLOCK.

M       cop.h
M       pp_ctl.c
M       pp_hot.c
M       pp_sort.c
M       pp_sys.c

commit f9bcda4a66be511e15d0a7441a5b8eddf2c1a30a
Author: David Mitchell <[email protected]>
Date:   Fri Dec 25 23:12:29 2015 +0000

    PUSH_MULTICALL: use SAVEOP()
    
    SAVEOP() should be more efficient than SAVEVPTR(PL_op), since it
    uses the dedicated SAVEt_OP.

M       cop.h

commit 1c5f652eb11308fc0aa130f4a6f89beb12653e85
Author: David Mitchell <[email protected]>
Date:   Fri Dec 25 22:41:21 2015 +0000

    eliminate PERL_STACK_OVERFLOW_CHECK
    
    This macro is defined as NOOP on all platforms except for MacOS classic,
    where it was added as a hook to allow for OSes that have a small CPU
    stack size. Since pp_entersub et al don't actually use the CPU stack,
    this hook looks misconceived from the beginning. So remove all
    uses of it in the core.

M       cop.h
M       perl.h
M       pp_ctl.c
M       pp_hot.c
M       pp_sort.c
M       pp_sys.c

commit 17c321c253e5aa74322a260eeb72616032f16356
Author: David Mitchell <[email protected]>
Date:   Fri Dec 25 22:28:14 2015 +0000

    sort compare subs: don't do unnecessary scope work
    
    The 3 functions S_sortcv(), S_sortcv_stacked(), S_sortcv_xsub(),
    which call a comparison function to compare $a and $b, do unnecessary work
    with the scope and save stacks.
    
    First, they pop any excess scope stack entries; but there shouldn't
    be, since exiting the sort sub should have already pooped any inner
    scopes. Indeed, running with an assert that PL_scopestack_ix == oldscopeix
    didn't trigger any failures.
    
    Secondly replace the unconditional leave_scope(oldsaveix) with
    LEAVE_SCOPE(), which only calls the function if PL_savestack_ix >
    oldsaveix.

M       pp_sort.c

commit 722dacbbf8393a33b7db864a495c121e312282a6
Author: David Mitchell <[email protected]>
Date:   Fri Dec 25 22:03:10 2015 +0000

    MULTICALL should clear scope after each call
    
    RT #116577
    
    Lexicals etc were only being freed at the end of the MULTICALL, not
    after each individual call to the sub.

M       cop.h
M       ext/XS-APItest/t/multicall.t
M       regexec.c

commit 0ba0e8ca01d3def742fd1fb5ff8bf8594e7ef251
Author: David Mitchell <[email protected]>
Date:   Fri Dec 25 12:03:00 2015 +0000

    Document CxLVAL()

M       cop.h

commit c29be9066e9a6b29234e4fe044abbf3b5c38bf00
Author: David Mitchell <[email protected]>
Date:   Fri Dec 25 11:51:37 2015 +0000

    CX_POPFOO(): assert cx is of the right type
    
    At the start of each CX_POPFOO(cx) macro, add an assertion that cx is of
    type CXt_FOO.

M       cop.h

commit a9bc4df3773b0adbb0551bf470036bd1d085ba0e
Author: David Mitchell <[email protected]>
Date:   Fri Dec 25 11:07:28 2015 +0000

    rename POPFOO() to CX_POPFOO()
    
    Rename all the context-popping macros such as POPBLOCK and POPSUB, by
    giving them a CX_ prefix. (Do TOPBLOCK too).
    
    This is principally to  deliberately break any existing non-core use of
    these non-API macros, as their behaviour has changed in this branch.
    In particular, POPBLOCK(cx) no longer decrements the cxt stack pointer
    nor sets cx; instead, cx is now expected to already point to the stack
    frame which POPBLOCK should process.
    
    At the same time, giving them a CX_ prefix makes it clearer that these
    are all part of a family of macros that manipulate the context stack.
    
    The PUSHFOO() macros will be renamed in a later commit.

M       cop.h
M       ext/XS-APItest/APItest.xs
M       op.c
M       perl.c
M       pp.c
M       pp_ctl.c
M       pp_hot.c
M       pp_sort.c
M       pp_sys.c
M       scope.c
M       t/op/args.t

commit f9c026c6d118657b835dbc9757a11dd1e25a0dc8
Author: David Mitchell <[email protected]>
Date:   Thu Dec 24 23:12:37 2015 +0000

    pp_redo()): reorder some stuff
    
    It probably doesn't make any difference, but reorder the FREETMPS,
    CX_LEAVE_SCOPE and TOPBLOCK so it matches the order we do things when
    leaving a scope.

M       pp_ctl.c

commit f60013960c2c5f22df425ba7505e4b4b702cb649
Author: David Mitchell <[email protected]>
Date:   Thu Dec 24 22:37:48 2015 +0000

    optimise bare 'next'
    
    If a 'next' without a label appears directly in the scope of the current
    loop, then skip searching the context stack for a suitable LOOP context.

M       pp_ctl.c
M       t/perf/benchmarks

commit f56eb11bc41766a7799952f2f376c05681e3fcc4
Author: David Mitchell <[email protected]>
Date:   Thu Dec 24 21:48:23 2015 +0000

    S_unwind_loop(): remove opname param
    
    This is only used for error messages, and can be derived from
    OP_NAME(PL_op); so for efficiency, don't pass it.

M       pp_ctl.c

commit d9ff928c999fb994a47ed4c39deeead4047159f6
Author: David Mitchell <[email protected]>
Date:   Thu Dec 24 21:33:49 2015 +0000

    S_unwind_loop(): return pointer rather than index
    
    return &cxstack[cxix] rather than cxix, since this is what the caller
    actually needs.

M       pp_ctl.c

commit 5982c1a91692b63d5a6493c95129c51cf884ad7d
Author: David Mitchell <[email protected]>
Date:   Thu Dec 24 20:30:15 2015 +0000

    factor out common actions in TOPBLOCK and POPBLOCK

M       cop.h

commit e662286c7c2c069a2d279a795325832f23b2a454
Author: David Mitchell <[email protected]>
Date:   Thu Dec 24 19:44:05 2015 +0000

    dounwind(): do a POPBLOCK for final cx frame.
    
    Previously dounwind() relied on the caller to a TOPBLOCK or POPBLOCK
    following the call to dounwind(). It's debatable who should be
    responsible. Arguably its more efficient for dounwind() not to do a
    POPBLOCK, since the caller will probably immediately follow on with
    POPFOO; POPBLOCK for the next context frame anyway.
    
    Logically however, dounwind() should do this, and its not possible
    for the caller to do so retrospectively, as context frame cxstack_ix + 1
    may have been overwritten by the time dounwind returns.
    
    Also, the changes in this branch mean that the old PL_tmps_floor is now
    saved in the context struct rather than on the save stack, so code that
    does C<dounwind(-1); LEAVE_SCOPE();> will no longer automatically
    restore PL_tmps_floor. With thiis commit, it will.
    
    The change to pp_return reflects that we now need to copy any return args
    *before* donwind() is called, so that "return $1" will mg_get($1) while
    the correct (inner) PL_curpm is still in scope.

M       pp_ctl.c
M       t/op/sub.t

commit e9d5fafee69f9c6547f6de7308a233c32b6547ac
Author: David Mitchell <[email protected]>
Date:   Mon Dec 21 16:33:57 2015 +0000

    pp_break(): don't use TOPBLOCK
    
    It appears to be using TOPBLOCK purely for its effect of resetting
    PL_stack_sp. Since the next op will be pp_leavegiven which will do a
    POPBLOCK, the other actions of TOPBLOCK are redundant. So just set
    PL_stack_sp directly.

M       pp_ctl.c

commit 7698c1711e40f093560b93ac34ed2d72e844a141
Author: David Mitchell <[email protected]>
Date:   Mon Dec 21 16:00:59 2015 +0000

    tweak POPLOOP and CXt_LOOP_* order
    
    Re-arrange the order of the CXt_LOOP_* to make it easier for compilers
    to produce efficient code, and tweak POPLOOP so that the code for
    freeing ary and cur is shared (as they occupy the same position in the
    union).

M       cop.h

commit 94917558ca9ea26aa7f105b5d69f20084663d1c9
Author: David Mitchell <[email protected]>
Date:   Mon Dec 21 15:45:57 2015 +0000

    fix CxFOREACH
    
    It wasn't detecting CXt_LOOP_LAZYIV as a 'for' loop type. This only
    affected 'given' and 'break' (which need to distinguish between being
    in a 'given' block and being in a 'for' block).

M       cop.h
M       t/op/switch.t

commit b0b8365b2ab367a8942e24e73b0e0f1e364d95c6
Author: David Mitchell <[email protected]>
Date:   Mon Dec 21 13:32:13 2015 +0000

    only set CXp_FOR_DEF with CXp_FOR_GV
    
    C<for (...)> is a special-case of C<for $pkg_var (...)>, so CXp_FOR_DEF
    should only be set when CXp_FOR_GV also is. So in pp_enteriter(), only
    test for (PL_op->op_private & OPpITER_DEF) in the GV branch and assert
    that it's otherwise unset. This is slightly more efficient in the non-GV
    branches.
    
    Also add some more commentary to the CXp_FOR_* flag definitions.

M       cop.h
M       pp_ctl.c

commit b7504285ab318f30c98d992e454ae738bf979b26
Author: David Mitchell <[email protected]>
Date:   Fri Dec 18 22:09:58 2015 +0000

    give POP_SAVEARRAY() macro a cx arg
    
    rather than just assuming that there's a 'cx' var in scope

M       cop.h
M       pp_ctl.c

commit 7988f624e360ca6058325a4d4229ea945b88102a
Author: David Mitchell <[email protected]>
Date:   Fri Dec 18 22:07:25 2015 +0000

    clarify code comment in pp_goto(()

M       pp_ctl.c

commit b8a80b5ccf32f879d798bd9da13c84e2663d5ee2
Author: David Mitchell <[email protected]>
Date:   Fri Dec 18 21:33:10 2015 +0000

    APItest.xs: fixup clone_with_stack()
    
    Make the unwinding and freeing of the old interpreter up to date
    with the latest handling of PL_scopestack.

M       ext/XS-APItest/APItest.xs

commit cf297d4677f5710bc09304d35117388903be187b
Author: David Mitchell <[email protected]>
Date:   Fri Dec 18 20:18:13 2015 +0000

    fixup cx_dup()
    
    By visual inspection, tweak bits of the context stack duplicating code
    to reflect recent changes in this branch, especially new fields, or
    whether fields hold a reference count or not.
    
    Since I don't use Windows, this has largely been done blind.

M       sv.c

commit c77250db922f97dfe36d9dd6799ace1776b42728
Author: David Mitchell <[email protected]>
Date:   Fri Dec 18 16:36:54 2015 +0000

    pp_iter: optimise integer setting in for (1..10) {}
    
    If the target SV is a simple SVt_IV, which it is likely to be,
    just update it directly rather than calling sv_setiv()

M       pp_hot.c

commit 955ca0632c19424b6007bb6003c99e18850ca95c
Author: David Mitchell <[email protected]>
Date:   Fri Dec 18 15:09:42 2015 +0000

    fix *_ = "" for 0 .. 1;
    
    RT #123994
    
    pp_iter couldn't handle GvSv(gv) being NULL.
    
    In that ticket, Tony Cook suggested two possible fixes. First,
    always instantiate the GvSV slot at the start of pp_iter by using
    GvSVn rather than GvSV in the CxITERVAR() macro;
    
    Second, test for it being null within the two 'range' branches,
    (for(1..9), for('a'..'z')), and if so create it. One advantage of doing
    it there is that there's already code for (re)creating the SV if the
    reference count is != 1. It also means that the list and array cases
    (for(@a), for(1,3,5)) which always put the next iterated SV into the
    pad/GvSV slot don't waste time creating and then immediately discarding an
    SV if GvSV was NULL.
    
    I went for the second fix.
    
    It also means that's there's no longer any need in pp_enteriter to
    initially poulate GvSV is it was null, as this will be detected during
    the first pp_iter() anyway.

M       pp_ctl.c
M       pp_hot.c
M       t/op/for.t

commit 27f60522743d1ddc806477cf073524ef494bb9ff
Author: David Mitchell <[email protected]>
Date:   Fri Dec 18 12:34:37 2015 +0000

    pp_enteriter: use efficient SvREFCNT_inc variant
    
    replace a couple of SvREFCNT_inc() with SvREFCNT_inc_simple_void_NN().
    
    Also add a couple of code comments.

M       pp_ctl.c

commit 2edf925a51feea16c0d32630f361d7db0c4e4ec2
Author: David Mitchell <[email protected]>
Date:   Thu Dec 17 17:50:52 2015 +0000

    provide some basic documentation for Perl_dounwind

M       pp_ctl.c

commit 0a2cfce90b825541a51ae38389e0b7f97e73a216
Author: David Mitchell <[email protected]>
Date:   Thu Dec 17 17:34:36 2015 +0000

    TOPBLOCK: make comment clear its used by goto too

M       cop.h

commit 9078bbc3bfdaa6a6ca0a9df75760e6dc82b0e4aa
Author: David Mitchell <[email protected]>
Date:   Thu Dec 17 17:30:48 2015 +0000

    POPSUB_ARGS: move a code comment to the right line

M       cop.h

commit d057f6d50fd15830023dff76e2daa3adf1a4b491
Author: David Mitchell <[email protected]>
Date:   Thu Dec 17 12:37:17 2015 +0000

    pp_ctl.c: s/newsp/oldsp/g
    
    There are various pp_leavefoo() functions that have similar code along the
    lines of
    
        SV **newsp;
        newsp = PL_stack_base + cx->blk_oldsp;
    
    Rename all these vars to 'oldsp' to reduce the cognitive dissonance.
    The name 'newsp' was a hangover from when POPBLOCK used to implicitly
    set a var called 'newsp.

M       pp_ctl.c

commit 44cb2f6c37fc04e0020d90380405c1401ff0344f
Author: David Mitchell <[email protected]>
Date:   Thu Dec 17 12:13:09 2015 +0000

    replace leave_common() with leave_adjust_stacks()
    
    Make the remaining callers of S_leave_common() use leave_adjust_stacks()
    instead, then delete this static function.
    
    This brings the benefits of freeing TEMPS on all scope exists that
    has already been introduced on sub exits; uses the optimised code for
    creating mortal copies; and finally unifies all the different 'process
    return args on scope exit' implementations into single function.

M       embed.fnc
M       embed.h
M       pp_ctl.c
M       pp_hot.c
M       proto.h
M       t/op/do.t
M       t/op/grep.t

commit e3cd45fb36fe771d29bee48265b7b87caec7fbb5
Author: David Mitchell <[email protected]>
Date:   Wed Dec 16 14:52:22 2015 +0000

    make pp_return() use leave_adjust_stacks()
    
    It was using S_leave_common(), but that's shortly to be removed.  It also
    required adding an extra arg to leave_adjust_stacks() to indicate where to
    shift the return args to. This will also be needed for when we replace the
    remaining uses of  S_leave_common() with leave_adjust_stacks().

M       embed.fnc
M       embed.h
M       pp_ctl.c
M       pp_hot.c
M       proto.h

commit 14bfc73714bd3b964a5844f999459db73f4b28bf
Author: David Mitchell <[email protected]>
Date:   Wed Dec 16 12:30:01 2015 +0000

    make pp_leavesublv use S_leavesub_adjust_stacks()
    
    Currently S_leavesub_adjust_stacks() is just used by pp_leavesub.
    Rename it to Perl_leave_adjust_stacks(), extend its functionality
    slightly, then make pp_leavesublv() use it too.
    
    This means that lvalue sub exit gains the benefit of FREETMPS being done,
    and (where mortal copying needs doing) the optimised copying code.
    It also means there is now one less version of the "process args on scope
    exit" code.
    
    pp_leavesublv() still does a scan of its return args looking for things to
    croak() on, but leaves everything else to leave_adjust_stacks().
    
    leave_adjust_stacks() is intended shortly to be used in place of
    S_leave_common() too, thus unifying all args-on-scope-exit code.
    
    The changes to leave_adjust_stacks() in this commit (apart from the
    renaming and doc changes) are:
    * a new arg to indicate what condition to use to decide whether to
      pass or copy the arg;
    * a new branch to mortalise and ref count bump an arg

M       embed.fnc
M       embed.h
M       pp_ctl.c
M       pp_hot.c
M       proto.h

commit a153e211b36d5b05a163d6f0829f8ea82656ee48
Author: David Mitchell <[email protected]>
Date:   Mon Dec 14 12:10:45 2015 +0000

    pp_leavesublv(): document PL_sv_undef exception

M       pp_ctl.c

commit bcf00dbb2c7677256d86ad355bd8def25f1ab774
Author: David Mitchell <[email protected]>
Date:   Mon Dec 14 11:55:14 2015 +0000

    pp_leavesublv(): croak on *all* PADTMPs
    
    pp_leavesublv() generally croaks on returned PADTMPs when called in lvalue
    context. However, an exception was made in scalar context if the PADTMP
    had set magic. This was to allow for things like
    
        sub :lvalue { $tied{foo} }
    and
        sub :lvalue { substr($foo,1,2) }
    
    However, it was later found that in places like pp_substr(), when
    returning a PVLV, it should return a new mortal rather than upgrading
    its pad target to PVLV, because the PVLV holds a reference to $foo which
    then gets delayed being freed indefinitely.
    
    Since places like pp_susbtr() no longer return lvalue PADTMPs, there's
    no longer any need to make a special exception in pp_leavesublv().
    
    I've added an assertion to the effect that PADTMPs don't have set
    container magic, but I've added the assert to pp_leavesub() rather than
    pp_leavesublv(), since the former is much likely to be used in many weird
    situations and edge cases that would quickly flush out any false
    assumptions.
    
    If this assumption is wrong and the exception needs to be re-instated in
    pp_leavesublv(), then presumably it needs adding to the ARRAY context
    branch too - I'm assuming that its previous absence there was an oversight;
    i.e.
    
        sub foo :lvalue { $tied{foo}, substr($foo,1,2) }
        foo() = (1,2);
    
    should work too.

M       pp_ctl.c
M       pp_hot.c

commit 51418a30438a0b756385c3aba0dfe695d76986dd
Author: David Mitchell <[email protected]>
Date:   Sun Nov 8 15:16:09 2015 +0000

    pp_leavesub(): call FREETMPS and optimise
    
    Currently pp_leavesub() doesn't call FREETMPS. Presumably this is due to
    the danger of freeing temps that need to exist beyond the return, such
    as the mortal copies we make of return args, or return args that are
    already temps.
    
    The down side of this is that temps aren't freed until the next nextstate
    is executed following the function call. If the function isn't near a
    statement boundary, then it may be a while before temps are freed; e.g.
    in f(g()), when g() returns, its temps continue to exist during the call
    to f(). For recursive subs it gets worse, although there is a specific
    hack already in pp_leavesub() that says in scalar context if CvDEPTH > 1,
    then temporarily RC++ the single return value then do a FREETMPS. This
    can in theory leak if something dies during the FREETMPS.
    
    This commit provides a more general solution. During the course of
    processing (usually mortal copying) the return args, it divides the
    current temps stack frame into two halves, with the temps that need
    keeping migrating to the bottom half. It then does a FREETMPS equivalent
    only of the top half.
    
    This is actually more efficient than it sounds; but in addition, the code
    has been heavily optimised: in particular the call to sv_mortalcopy()
    has been unrolled and inlined, and within that code common cases (such as
    IV, RV) handled directly, and the mortal stack is only checked/extended
    once, rather than for every arg.
    
    Also, the arg adjust / freetmps code has been moved out of pp_leavesub()
    and into a separate static function.

M       pp_hot.c
M       t/op/sub.t
M       t/perf/benchmarks

commit ec8f4c8f5840de7e339f660f47ae8077aa74fe26
Author: David Mitchell <[email protected]>
Date:   Fri Dec 4 15:50:54 2015 +0000

    move SET_SVANY_FOR_BODYLESS_IV() from sv.c to sv.h
    
    Ditto for SET_SVANY_FOR_BODYLESS_NV.
    
    The IV variant will shortly be needed in pp_hot.c, so make it
    available outside sv.c. For now, protect with #ifdef PERL_CORE,
    so as little as possible is changed by this commit.

M       sv.c
M       sv.h

commit 40916c8e1993a3dc43f4772a2e65823bd1901bbf
Author: David Mitchell <[email protected]>
Date:   Mon Nov 16 14:40:04 2015 +0000

    Perl_runops_debug(): do FREETMPS
    
    In runops_debug() wrap the optional printing of next op, arg stack
    etc with ENTER/SAVETMPS, FREETMPS/LEAVE - so that temporaries created by
    the dump output are promptly freed, and thus don't alter the tmps stack.
    
    (I'm trying to debug some tmps stack corruption, and running with -Dst
    made the problem go away).

M       dump.c

commit aa56bfe47bf4d6c4e2feedca8937d7c348b2c906
Author: David Mitchell <[email protected]>
Date:   Mon Nov 9 21:11:58 2015 +0000

    optimise sv_setsv_flags()
    
    This commit does two things.
    
    First, it streamlines and re-orders some of the initial tests,
    such as 'is sstr already freed?'.
    
    Second, it looks for a reasonably common case where both sstr and dstr are
    SVt_NULL/SVt_IV. This covers undef, int and refs, where the SV hasn't
    previously been used for other things (like strings).
    
    With just SVt_NULL/SVt_IV, we know that the SV won't have a real body, and
    won't need one and can be very quick.
    
    The check for SVt_NULL/SVt_IV is a single compare-and-branch, so
    has a minimal effect on users of sv_setsv_flags() that have more complex
    types.

M       sv.c
M       t/perf/benchmarks

commit 78dd8cdaee6da31adccf0bf656248a7bb795592d
Author: David Mitchell <[email protected]>
Date:   Sun Nov 8 20:08:20 2015 +0000

    intrvar.h: document PL_tmps_max
    
    Its name implies that it's the top allocated element; in fact it's top+1.

M       intrpvar.h

commit c7acfd3b803ad8064ec9744a0c645e41838f58aa
Author: David Mitchell <[email protected]>
Date:   Sun Nov 8 15:05:01 2015 +0000

    pp_leavesub: reset SP in void context
    
    In void context, pp_leavesub() doesn't bother resetting SP to the
    base; either as an efficiency measure, or as an oversight (the other
    pp_leavefoo functions do reset).
    
    This is mostly harmless, as being void context, it's likely to immediately
    execute pp_nextstate or similar, which will reset the stack anyway.
    However with attributes, something like
    
        my @foo :attr = ()
    
    causes attributes::import() to be called in void context, and whatever
    dross it leaves on the stack becomes part of the assign, i.e. that assign
    becomes the equivalent of:
    
        my (@foo, dross) = ()
    
    which again is fairly harmless, if slightly inefficient.
    
    However, the next commit should make pp_leavesub() call FRETMPS,
    which means that 'dross' may now include freed SVs, which will make
    pp_aassign choke.
    
    This commit also requires ext/XS-APItest/t/call.t to be fixed.
    Some tests in there (added years ago by myself) test the statu quo; that
    is, it expects that calling call_sv(G_VOID) will leave return args on the
    stack. Now it doesn't.

M       ext/XS-APItest/t/call.t
M       pp_hot.c

commit 8a4f3efe74c9085b92a96a0d0e77e1979bfd82e1
Author: David Mitchell <[email protected]>
Date:   Sun Nov 8 19:19:02 2015 +0000

    Perl_free_tmps(): don't test for PL_sv_undef
    
    Each sv being popped off the tmps stack is compared against PL_sv_undef,
    and if so, the SvTEMP_off(sv); SvREFCNT_dec_NN(sv); is skipped.
    
    This condition was added by 8aacddc1 back in 2001, as part of a commit
    to add support for hash placeholders. Initially it used &PL_sv_undef in
    HE value slots to indicate a placeholder. In a later commit, that was
    changed to &PL_sv_placeholder, but the test in free_tmps() continued
    to test against &PL_sv_undef.
    
    Im not sure what the original intent was, but I strongly suspect that
    whatever purpose it may have originally served, it no longer served that
    after the switch to PL_sv_placeholder.
    
    On a purely pragmatic note, I can't see any harm in untemping PL_sv_undef;
    at worst its ref count will occasionally reach 0, and the special code in
    sv_free2() will reset its count to SvREFCNT_IMMORTAL. And no tests
    fail....

M       scope.c

commit ac6d408dcc7ded84cec6b8b4cc6e776199df2300
Author: David Mitchell <[email protected]>
Date:   Wed Oct 28 08:28:56 2015 +0000

    restore PL_tmps_floor on exit
    
    A couple of places were expecting dounwind(-1); LEAVE_SCOPE(0);
    to restore PL_tmps_floor, since its old value was saved on the savestack.
    Since that's now stored in the context struct instead, do
    a POPBLOCK(&cxstack[0]).
    
    This problem only showed up on 'make test' rather than 'make
    test_harness', since only the former sets PERL_DESTRUCT_LEVEL.

M       ext/XS-APItest/APItest.xs
M       perl.c

commit bb5334239ea5ffa1a7868e3f710690db7b7953cf
Author: David Mitchell <[email protected]>
Date:   Wed Oct 21 19:10:34 2015 +0100

    extend magic copy test to all scope exit types
    
    Commit v5.15.6-387-g6f48390 forced leavesub to copy returned items
    if they were get-magical. Normally rvalue subs  are supposed to return a
    copy of their return args, but that copy is sometimes skipped if leavesub
    thinks the side-effects will never be visible. Tied elements was an
    example where the implementation leaked.
    
    However, this applies equally well to other leave types, such as
    do { ....}, so test for get magic in those too.

M       pp_ctl.c
M       t/op/gmagic.t

commit 32b5aced9040f25e11c5644cad1376e829e2209a
Author: David Mitchell <[email protected]>
Date:   Wed Oct 21 17:54:29 2015 +0100

    test that pp_leavesub copies returned PADTMPs.
    
    Although pp_leavesub() has in fact always done this, it was never actually
    tested for.

M       t/op/sub.t

commit 10f287f362f99381232cc23fbab66a3c91fa61ca
Author: David Mitchell <[email protected]>
Date:   Wed Oct 21 13:10:44 2015 +0100

    Always copy return values when exiting scope
    
    v5.14.0-642-g3ed94dc fixed certain instances where returning from a sub
    incorrectly returned the actual value rather than a copy, e.g.
    
        sub f { delete $foo{bar} }
    
    This was because if the value(s) being returned had SvTEMP set, copying
    was skipped. That commit added an extra condition to the skip test,
    SvREFCNT(sv) == 1.
    
    However, this applies equally well to other scope exits, for example
    
        do { ...; delete $foo{bar} }
    
    So this commits adds the RC==1 test to S_leave_common() too, which handles
    all the non-sub scope exits. As well as adding a test to do.t, it adds an
    additional test to sub.t, since the original tests, although they
    *detected* a non-copied return, didn't actually demonstrate a case where
    it was actually harmful.
    
    Note that S_leave_common() also sometimes skips on PADTMPs as well as
    TEMPs, so this commit as a side-effect also makes it copy PADTMPs unless
    their RC ==1. But since their RC should in fact almost always be 1 anyway,
    in practice it makes no difference.

M       pp_ctl.c
M       t/op/do.t
M       t/op/sub.t

commit 4b4154db8302ccae096b03173ee16a71462c2fee
Author: David Mitchell <[email protected]>
Date:   Wed Oct 21 12:28:35 2015 +0100

    op/sub.t: fix ticket number in comment
    
    Took me a while to track down that non-existent ticket!

M       t/op/sub.t

commit 77faa2e19c97d54b50c1f3ffce940d4258edb97d
Author: David Mitchell <[email protected]>
Date:   Wed Oct 21 09:47:21 2015 +0100

    make TOPBLOCK(cx) not set cx
    
    i.e. replace
    
        TOPBLOCK(cx);
    
    with
    
         cx = CX_CUR();
         TOPBLOCK(cx);
    
    This is part of general trend of separating out the cx/cxstack_ix
    setting/manipulation from the save/restore actions

M       cop.h
M       pp_ctl.c

commit 68de5822e4ef5801f370df8ca60afcdf3d96c81d
Author: David Mitchell <[email protected]>
Date:   Wed Oct 21 09:41:52 2015 +0100

    rename DEBUG_CX() to CX_DEBUG()
    
    For consistency with the new naming convention for context-stack macros.
    Also, give it a cx arg rather than using CX_CUR()

M       cop.h
M       pp_ctl.c

commit 976f4da66a5c2b1728a77ad0d0e08daca107c0f1
Author: David Mitchell <[email protected]>
Date:   Wed Oct 21 09:28:52 2015 +0100

    add CX_CUR() macro
    
    This is simply
    
        #define CX_CUR() (&cxstack[cxstack_ix])

M       cop.h
M       op.c
M       perl.c
M       pp.c
M       pp_ctl.c
M       pp_hot.c
M       pp_sort.c
M       pp_sys.c
M       toke.c

commit 7594eec76bc1876f31d54dbb598d188bc00175e6
Author: David Mitchell <[email protected]>
Date:   Mon Oct 19 17:21:58 2015 +0100

    make POPSUBST re-entrant safe

M       cop.h

commit 6f658f90d155e07253006b30d18ac11fa7952423
Author: David Mitchell <[email protected]>
Date:   Mon Oct 19 17:14:58 2015 +0100

    make POPGIVEN re-entrant safe

M       cop.h

commit 8b76ed925b7f1df3e4152ca9b884ba82d2c821c0
Author: David Mitchell <[email protected]>
Date:   Mon Oct 19 17:04:02 2015 +0100

    make POPSUB re-entrant safe

M       cop.h

commit cd4aa33b8f9120d2e16d7c504cb1a28067469d81
Author: David Mitchell <[email protected]>
Date:   Mon Oct 19 16:46:06 2015 +0100

    make POPEVAL safe against re-entrancy

M       cop.h

commit ce845b2b9c1b6227bb9fd5d4e27d6e9031c87a68
Author: David Mitchell <[email protected]>
Date:   Mon Oct 19 16:12:33 2015 +0100

    make POPSUB and POPFORMAT re-entrant safe
    
    In code like
    
        sub DESTROY { exit }
        sub f { push @_, bless [] }
        f()
    
    While leaving f, POPSUB will attempt to clear @_. This triggers the
    destructor, which calls exit, which unwinds the context stack, calling
    POPSUB again on thr same context stack entry.
    
    Thus we need to to be careful that POPSUB can be called multiple times
    on the same CX stack entry.
    
    The general way of doing this is to NULL or update pointers *before*
    calling SvREFCNT_dec() on the old value.
    
    This commit also removes the old CxPOPSUB_DONE mechanism which was a poor
    bandaid added at the last minute to 5.22 to try and achieve the basics
    of what this commit does comprehensively (hopefully). Also, CxPOPSUB_DONE
    was mainly a protection against re-entrantly calling LEAVE_SCOPE(). Since
    that's now done before POPSUB rather than in the middle of it, it has
    become reentrant-safe by default.

M       cop.h
M       pp_hot.c
M       pp_sys.c

commit 560c1c10421cd7ae11b014a7290331f7e748c565
Author: David Mitchell <[email protected]>
Date:   Sat Oct 17 15:22:05 2015 +0100

    reorder 'struct block' fields.
    
    On 64-bit builds, there was a 32-bit hole near the beginning. Shuffle this
    towards the middle of the struct (just before the blk_u union).
    
    Unfortunately this (moved) hole can't be filled by having an I32 at the
    start of each union member, since struct block_eval is already the largest
    and has no 32-bit fields.
    
    Still, moving further on than some of the hotter fields can't hurt.

M       cop.h

commit f2260c8459bf2eaa6be5f4200acb974f7cdfffe7
Author: David Mitchell <[email protected]>
Date:   Sat Oct 17 14:52:50 2015 +0100

    move and rename cx_old_savestack_ix
    
    Earlier on in this branch I temporarily added cx_old_savestack_ix
    as the first element in the context struct. This commit moves it down
    32 bits so it now follows type/gimme/u16 in the sbu and blku unions.
    
    This means that type is now back as the first item in the struct.
    
    I've also renamed it blku_oldsaveix to be more in keeping with similar
    field names.

M       cop.h
M       pp_ctl.c
M       pp_hot.c
M       pp_sort.c
M       scope.c

commit c24341c316ffddf4f47192083e6daa465057800f
Author: David Mitchell <[email protected]>
Date:   Sat Oct 17 13:24:30 2015 +0100

    simplify two conditions in pp_iter:
    
        -        if (UNLIKELY(SvMAGICAL(av) || AvREIFY(av))) {
        +        if (UNLIKELY(SvRMAGICAL(av))) {
    
    This condition is deciding whether to call av_fetch or cheat and do
    sv = AvARRAY(av)[ix].
    
    The magic test is too broad: av_fetch() only handles the specially on
    RMG, not all magic.
    
    The AvREIFY condition was originally added by 64138690 in 2001. It was
    an attempt to paper over the cracks if function args are deleted, then
    iterate over @_, which now contains freed elements. Since pp_iter now
    includes a 'freed sv' check itself, there's no need to call into av_fetch
    which has a similar check.
    
    This makes a slight functional change - previously if @_ contained a freed
    element, av_fetch would silently return NULL; now instead, pp_iter
    croaks with "Use of freed value in iteration", the same as it does with
    all other cases involving freed elements being iterated over.

M       pp_hot.c
M       t/run/fresh_perl.t

commit 4ddb4b2f782d619f5eea4f5fc938bae47b0ad9ca
Author: David Mitchell <[email protected]>
Date:   Sat Oct 17 13:15:06 2015 +0100

    PUSHLOOP_PLAIN: don't set unused fields
    
    Currently PUSHLOOP_PLAIN sets a whole unch of fields that it isn't going
    to ue to NULL or 0, e.g. blk_loop.itersave.
    
    Skip this and leave them wild. Make cx_dump() not try to dump them for
    CXt_LOOP_PLAIN

M       cop.h
M       scope.c

commit e6420bc8557e015cf142e9378d3b16a93c9fac28
Author: David Mitchell <[email protected]>
Date:   Sat Oct 17 12:56:15 2015 +0100

    Eliminate cx->blk_loop.resetsp
    
    Of all the loop types, only CXt_LOOP_LIST, i.e. for (1,2,3) {},
    needs to keep anything on the stack, i.e. for all the others,
    cx->blk_loop.resetsp can always equal cx->blk_oldsp.
    For CXt_LOOP_LIST, the same value as resetsp is stored as
    blk_loop.state_u.stack.basesp.
    
    So we can eliminate the resetsp field. This is good as the loop substruct
    is the largest (ITHREADS) or joint largest with eval (non-threaded).
    
    Also, we now don't have to store that value for non-CXt_LOOP_LIST loops.
    The downside is we now have to choose between basesp and oldsp in
    pp_leaveloop and pp_last, based on CX type.

M       cop.h
M       pp_ctl.c
M       scope.c

commit 8ce4265243ac1802308879063d31a8db45092164
Author: David Mitchell <[email protected]>
Date:   Sat Oct 17 10:53:10 2015 +0100

    pp_iter(): optimise stack handling
    
    Make pp_enteriter() do EXTEND(SP,1); then there's no need for pp_iter() to
    check for space to push PL_sv_yes/no each time round the loop.
    
    Since the only stack manipulation in pp_iter is now just pushing a boolean
    at the end, remove dSP etc and just directly push to PL_stack_sp at the
    end.

M       pp_ctl.c
M       pp_hot.c

commit d8e5f977fd1e0fb5b60a68aa9f1b5cf07554c2ad
Author: David Mitchell <[email protected]>
Date:   Sat Oct 17 00:18:44 2015 +0100

    split CXt_LOOP_FOR into CXt_LOOP_LIST,CXt_LOOP_ARY
    
    Create a new context type so that "for (1,2,3)" and "for (@ary)"
    are now two separate types.
    
    For the list type, we store the index of the base stack element in the
    state union rather than having an array pointer. Currently this is just
    the same as blk_resetsp, but this will shortly allow us to eliminate the
    resetsp field from the struct block_loop - which is currently the largest
    sub-struct within the block union.
    
    Having two separate types also allows the two cases to be handled directly
    in the main switch in the hot pp_iter code, rather than having extra
    conditionals.

M       cop.h
M       lib/B/Op_private.pm
M       opcode.h
M       perl.h
M       pp_ctl.c
M       pp_hot.c
M       regen/op_private
M       scope.c
M       sv.c

commit d0b42ed907aeabe097b6fc4da8e1dc1a49604e35
Author: David Mitchell <[email protected]>
Date:   Fri Oct 16 16:20:47 2015 +0100

    benchmarks: add some 'for' array iterating

M       t/perf/benchmarks

commit bab39479b464cd15a059faaa9b2efd482adbe4c4
Author: David Mitchell <[email protected]>
Date:   Fri Oct 16 14:32:26 2015 +0100

    stop S_undo_inc_then_croak() doing CX_POP
    
    I added this static function several commits commits ago but in hindsight
    I don't like that a cx is passed to it and it does a CX_POP(cx). This is
    too much like action at a distance. Instead make the caller save
    cx->blk_eval.old_namesv and do the CX_POP itself, then pass namesv as an
    arg.

M       pp_ctl.c

commit 77e4185f92f34e61328e390f3e405929c2f357ba
Author: David Mitchell <[email protected]>
Date:   Fri Oct 16 13:31:57 2015 +0100

    pp_leaveeval: reset stack in VOID context
    
        $ perl -Dst -e'eval"1"'
    
    Gives:
        ....
        ((eval 1):1)    leaveeval
            =>  (FREED)
    
    Change it so that like all the other pp_leavefoo() functions, it does
    
        if (gimme == G_VOID)
            PL_stack_sp = newsp;
    
    I can't think of any (non-debugging) perl-level badness the old behaviour
    can be shown to demonstrate, but best not to have freed values left
    dangling.
    
    This also allows pp_leaveeval() to (like the other pp_leavefoo functions)
    avoid doing a dSP with the associated unnecessary PUTBACKs and SPAGAINs.
    
    Finally, the code to detect a false require is moved to earlier in the
    function where it's in the same place as the rest of the stack arg
    processing code.

M       ext/XS-APItest/t/call.t
M       pp_ctl.c

commit 4eef65344a2138abb1957df40c57aae98d0fd746
Author: David Mitchell <[email protected]>
Date:   Fri Oct 16 13:07:23 2015 +0100

    rename S_doeval() to S_doeval_compile()
    
    This makes it a bit more obvious what niche in the "eval" ecosystem
    that it occupies.

M       cop.h
M       embed.fnc
M       embed.h
M       pp_ctl.c
M       proto.h
M       t/op/eval.t

commit a22a4a77eb2bdba00b682faacbdb8e45fd076f98
Author: David Mitchell <[email protected]>
Date:   Fri Oct 16 12:19:44 2015 +0100

    S_doeval(): tidy up comments
    
    Also, replace
    
        if (...) {
            ...
            return;
        }
        else
            B
    
    with
    
        if (...) {
            ...
            return;
        }
        B

M       pp_ctl.c

commit 1ce53cfb4928dbe1c2f79752dcc7cc243c3baa7e
Author: David Mitchell <[email protected]>
Date:   Fri Oct 16 12:00:46 2015 +0100

    remove obsolete panic from die_unwind()
    
    It panics if the context it has just popped back to isn't a CXt_EVAL.
    Since we have just called dopoptoeval() which can only pop to an eval, and
    since we assert that its an eval, this seems such an unlikely "this can
    can never happen" that it doesn't really seem worth testing for.
    
    It was added in perl5.000, and may have made slightly more sense then, as
    there used to be a POPBLOCK just before it.

M       pod/perldiag.pod
M       pp_ctl.c

commit baa9476f442e7c147daeb5818d88074e32de2420
Author: David Mitchell <[email protected]>
Date:   Fri Oct 16 11:33:43 2015 +0100

    pp_return: avoid potential CX stack realloc prob

M       pp_ctl.c

commit 7457e60ef4743a13380fe6ae17b3db9d0f1ae2a9
Author: David Mitchell <[email protected]>
Date:   Fri Oct 16 11:25:42 2015 +0100

    Perl_die_unwind(): remove unneeded assert
    
    Now that the order of things has changed, PL_curcop will always have just
    been restored at this point. So there's no longer any needs to assert that
    its the correct value.

M       pp_ctl.c

commit 55b5f8c11ba64d637cd5e15a55e2c956b1bda1da
Author: David Mitchell <[email protected]>
Date:   Fri Oct 16 00:03:00 2015 +0100

    add S_undo_inc_then_croak()
    
    Consolidate into a single static function, code in 3 functions that all
    'undo' an added %INC entry on failure, then croak.

M       pp_ctl.c

commit eb4164106ca8df759ba2473f3c465ba458852c49
Author: David Mitchell <[email protected]>
Date:   Thu Oct 15 22:27:03 2015 +0100

    POPEVAL: don't set optype
    
    don't quietly set the local var optype; instead explicitly set it
    in the couple of places its actually needed. This allows us to
    get rid of a bunch of PERL_UNUSED_VAR(optype);

M       cop.h
M       pp_ctl.c

commit eed69deabbfa8bf8d39fe21345dd98f2e66d2e13
Author: David Mitchell <[email protected]>
Date:   Thu Oct 15 17:46:31 2015 +0100

    add CX_POP(cx) macro: glorified cxstack_ix--
    
    but with extra checking goodness on debugging builds.

M       cop.h
M       pp_ctl.c
M       pp_hot.c
M       pp_sort.c
M       pp_sys.c

commit d5a9433ceb786cd467665fb66ae380a100477a28
Author: David Mitchell <[email protected]>
Date:   Thu Oct 15 16:59:19 2015 +0100

    simplify CHANGE_MULTICALL_FLAGS
    
    But using POPSUB_COMMON(), we achieve commonality. This incurs the extra
    overhead of restoring PL_comppad/PL_curpad, which is compensated for by
    not having to temporarily protect PL_comppad in the following PUSHSUB.

M       cop.h

commit 775adf572383d836e2c413b4d4c99623c8c11ff9
Author: David Mitchell <[email protected]>
Date:   Thu Oct 15 16:03:34 2015 +0100

    remove redundant croak code in pp_leavesublv
    
    Just before a code path that croaks, it does a POPSUB etc.
    Since this will be done by the unwind following the croak anyway, it's
    redundant.

M       pp_ctl.c

commit cde1a1907e9a1b041f4b9b43e855621c949b819a
Author: David Mitchell <[email protected]>
Date:   Thu Oct 15 15:50:08 2015 +0100

    factor common code into POPSUB_ARGS()
    
    Some code that is common to POPSUB() and pp_coreargs, extract out
    into a common macro. (There's some almost identical code in pp_goto,
    so add a note there).
    
    This makes pp_coreargs slightly less efficient, since it now tests for
    AvREAL(av), when that should never be true. But it's not exactly hot code.

M       cop.h
M       pp.c
M       pp_ctl.c

commit 462bd17f298ea27cc8ca266a8f2e91a7f9bab94b
Author: David Mitchell <[email protected]>
Date:   Thu Oct 15 15:39:42 2015 +0100

    pp_coreargs: rationalise @_ code
    
    Make the code in pp_coreargs that cleans up @_ more like the code in
    POPSUB, so that the two can eventually be extracted out into a common
    macro.

M       pp.c

commit 0e1dbf6705f50ded655dd7a6803cf16c63b94bdd
Author: David Mitchell <[email protected]>
Date:   Thu Oct 15 14:58:35 2015 +0100

    split some common POPSUB code into a macro
    
    POP_MULTICALL duplicates some of the code in POPSUB, so extract it
    out into a common macro.

M       cop.h

commit 4f4e68501aae6cc7c9b286f6c1fb600f00effa9b
Author: David Mitchell <[email protected]>
Date:   Thu Oct 15 14:36:59 2015 +0100

    make POPSUBST not cxstack_ix--
    
    For consistency with with the new POPBLOCK, make POPSUBST(cx) no longer
    set c nor decrement cxstack_ix. This also makes dounwind more consistent.

M       cop.h
M       pp_ctl.c

commit f21268e64fb597f403479f8857f7a7eb20c84421
Author: David Mitchell <[email protected]>
Date:   Thu Oct 15 14:28:28 2015 +0100

    dowinwind(): move common CX_LEAVE_SCOPE() outside
    
    Now the every branch in the switch does CX_LEAVE_SCOPE(cx), hoist it
    above the satrt of the switch.

M       pp_ctl.c

commit 88b6038e04d497c901a462baf6c4bc408535fa73
Author: David Mitchell <[email protected]>
Date:   Thu Oct 15 14:26:21 2015 +0100

    dounwind: CX_LEAVE_SCOPE for CXt_SUBST too
    
    This was the only branch that didn't clear up the context stack as
    part of a context stack unwind.

M       pp_ctl.c

commit a926e1bd1d3cf4c546b5c6e42fa35100a1f417e1
Author: David Mitchell <[email protected]>
Date:   Thu Oct 15 14:15:57 2015 +0100

    move blku_old_savestack_ix to base of cxt struct
    
    The previous commit moved the "old savestack" field of substitution
    contexts into the shared root of the context union. This commit does the
    same for all other context types

M       cop.h
M       pp_ctl.c
M       pp_hot.c
M       pp_sort.c

commit f5de70ca29d71bc8add496f96cae59fd63bf4c13
Author: David Mitchell <[email protected]>
Date:   Thu Oct 15 14:04:09 2015 +0100

    move sbu_oldsave into base of CX struct
    
    the context struct is a union of two basic types: the substitution context
    and everything else.
    
    This commit moves the sbu_oldsave field from the substitution context
    into the base of the context struct, so that the next commit will allow
    the same field (and macros) to be used by *all* context types.

M       cop.h
M       pp_ctl.c

commit f678605c099db31ec962b88d7fa4ddbaf26d7695
Author: David Mitchell <[email protected]>
Date:   Thu Oct 15 13:48:25 2015 +0100

    move CX_LEAVE_SCOPE outside the POPFOO's
    
    Currently every POPFOO macro has CX_LEAVE_SCOPE(cx) as its first action.
    Since this is common code and not specific to a particular POPFOO type,
    remove it from each POPFOO macro and make each caller of POPFOO explicitly
    call CX_LEAVE_SCOPE() instead.
    
    This should make no functional difference (but will help if you're
    single-stepping the code in a debugger :-)

M       cop.h
M       pp_ctl.c
M       pp_hot.c
M       pp_sort.c
M       pp_sys.c

commit 4bb21f9417d541036f56dda100ca2be682ad5b31
Author: David Mitchell <[email protected]>
Date:   Thu Oct 15 11:47:07 2015 +0100

    do PL_tmps_floor save in PUSHBLOCK
    
    Currently every individual PUSHFOO type does
    
        cx->cx_u.cx_blk.blku_old_tmpsfloor = PL_tmps_floor;
        PL_tmps_floor = PL_tmps_ix;
    
    Move all these into PUSHBLOCK instead, which usually immediately precedes
    the PUSHFOO.

M       cop.h
M       pp_sort.c

commit 921b43abd3c62db636d70433350c3c89923e23d8
Author: David Mitchell <[email protected]>
Date:   Thu Oct 15 11:34:41 2015 +0100

    do PL_tmps_floor restore in POPBLOCK
    
    Currently every individual POPFOO type does
    
        PL_tmps_floor = cx->cx_u.cx_blk.blku_old_tmpsfloor
    
    as its last action.
    
    Move all these into POPBLOCK instead, which always immediately follows
    the  POPFOO.

M       cop.h
M       pp_sort.c

commit f3908fd69e4502485c3f370b214cdb99606a22fd
Author: David Mitchell <[email protected]>
Date:   Thu Oct 15 11:16:14 2015 +0100

    sort(!) out CXt_NULL and CXp_MULTICALL
    
    A sort BLOCK is done using a CXt_NULL context type. Currently it has
    the CXp_MULTICALL flag set. Remove this flag so that CXp_MULTICALL is
    only set on CXt_SUB contexts.
    
    Also add code comments in various places explainging that CXt_NULL is
    likely to a sort BLOCK, and fix the comments in pp_return which said
    a particular code path was only taken by sort BLOCK; it's also taken
    be (?{...}) too.

M       cop.h
M       pp_ctl.c
M       pp_sort.c
M       sv.c
M       t/re/re_tests

commit b87ad0f3e63e8b9601e52b5d39ffa40e421f3920
Author: David Mitchell <[email protected]>
Date:   Thu Oct 15 08:52:18 2015 +0100

    pp_sort: add missing CX_LEAVE_SCOPE()
    
    The branch that does POPSUB has an implicit CX_LEAVE_SCOPE; the
    other branch didn't; do add one for consistency. It's fairly harmless,
    as pp_sort shortly afterwards does a LEAVE() anyway.
    
    Also add an assertion to POPBLOCK that the save stack has been popped;
    this is how I discovered the sort issue in the first place.

M       cop.h
M       pp_sort.c

commit 71e8772a223d52830b26aa0e446bc32d03fd9ffe
Author: David Mitchell <[email protected]>
Date:   Mon Oct 12 15:33:56 2015 +0100

    remove newpm param from POPBLOCK() macro.
    
    Since all core usage of POPBLOCK now immediately restores PL_curpm,
    there's no need to copy the old value to a temp var specified by the
    caller; just make POPBLOCK itself restore PL_curpm in the same way that
    it restores all the other PL_ vars.

M       cop.h
M       pp_ctl.c
M       pp_hot.c
M       pp_sort.c
M       pp_sys.c

commit fb3e01d3ee86f57d655714a139c51c05d40e40fd
Author: David Mitchell <[email protected]>
Date:   Mon Oct 12 14:56:35 2015 +0100

    reverse the order of POPBLOCK; POPFOO
    
    Currently most pp_leavefoo subs have something along the lines of
    
        POPBLOCK(cx);
        POPFOO(cx);
    
    where POPBLOCK does cxstack_ix-- and sets cx to point to the top CX stack
    entry. It then restores a bunch of PL_ vars saved in the CX struct.
    
    Then POPFOO does any type-specific restoration, e.g. POPSUB decrements the
    ref count of the cv that was just executed.
    
    However, this is logically the wrong order. When we *enter* a scope, we do
    
        PUSHBLOCK;
        PUSHFOO;
    
    so undoing the PUSHBLOCK should be the last thing we do.  As it happens,
    it doesn't really make any difference to the running, which is why we've
    never fixed it before.
    
    Reordering it has two advantages.
    
    First, it allows the steps for scope exit to be the exact logical reverse
    of scope exit, which makes understanding what's going on and debugging
    easier.
    
    It allows us to make the code cleaner.
    
    This commit also removes the cxstack_ix-- and setting cx steps from
    POPBLOCK; now we already expect cx to be set (which it usually already is)
    and we do the cxstack_ix-- ourselves. This also means we can remove a
    whole bunch of cxstack_ix++'s that were added immediately after the
    POPBLOCK in order to prevent the context being inadvertently overwritten
    before we've finished using it.
    
    So in full,
    
        POPBLOCK(cx);
        POPFOO(cx);
    
    is now implemented as:
    
        cx = &cxstack[cxstack_ix];
        ... other stuff done with cx ...
        POPFOO(cx);
        POPBLOCK(cx);
        cxstack_ix--;
    
    Finally, this commit also tweaks PL_curcop in pp_leaveeval, since
    otherwise PL_curcop could temporarily be NULL when debugging code is
    called in the presence of 'use re Debug'. It also stops the debugging code
    crashing if PL_curcop is still NULL.

M       cop.h
M       pp_ctl.c
M       pp_hot.c
M       pp_sort.c
M       pp_sys.c
M       regcomp.h

commit 53611498e8a0b1019ed6f39af26ad9d63d8b6cef
Author: David Mitchell <[email protected]>
Date:   Mon Oct 12 12:02:05 2015 +0100

    make PL_tmps_floor restore consistent
    
    On scope exit this is done:
    
        PL_tmps_floor = cx->cx_u.cx_blk.blku_old_tmpsfloor;
    
    This is mostly contained within the POPFOO macros; for those,
    make it consistently the last entry in the macro. POPEVAL
    didn't include this line; move it into the macro and out of the
    various places where it's done explicitly.
    
    This will allow us to move it into a revamped POPBLOCK macro shortly.

M       cop.h
M       pp_ctl.c

commit c27e574484c27c05988a5501e1ed8d7b7d66d3d4
Author: David Mitchell <[email protected]>
Date:   Sun Oct 11 15:58:06 2015 +0100

    simplify S_leave_common() and callers
    
    Currently one of the args to S_leave_common() is supposed to be the
    current stack pointer; it returns an updated sp. Instead make it get/set
    PL_stack_sp directly.
    
    e.g. in the caller, replace
    
        dSP;
        SP = S_leave_common(..., SP, ...);
        PUTBACK;
    
    with
        S_leave_common(..., ...);
    
    and in S_leave_common(), make it initially get PL_stack_sp, and before
    returning, update PL_stack_sp.

M       embed.fnc
M       embed.h
M       pp_ctl.c
M       proto.h

commit fd7ddcf54e62db9979922e8e07866ba590cdbbe2
Author: David Mitchell <[email protected]>
Date:   Sat Oct 10 23:41:15 2015 +0100

    eliminate weird gimme calc in pp_leave()
    
    Some code in pp_leave that's been around in one form or another since
    5.000, calculates the value of gimme in a complicated way, rather than
    just using the saved value in the current context, like all the other
    pp_leave* functions do.
    
    I think this code is redundant; running the test suite with an assert that
    the extra calculation doesn't change anything, doesn't produce any failures.
    So out it goes.
    
    (In particular. cxstack_ix can never be < 0 here.)

M       pp_ctl.c

commit 630b24f37a552c7174904be14284065d49c7304e
Author: David Mitchell <[email protected]>
Date:   Sat Oct 10 23:22:30 2015 +0100

    eliminate LEAVESUB() macro
    
    Many years ago, POPSUB was split into two parts, with a final cleanup
    being done by the LEAVESUB() macro. After the previous commit, LEAVESUB
    now always immediately follows POPSUB, so roll its action into the
    last line of POPSUB and eliminate it.
    
    This also allows us to remove the 'sv' parameter from POPSUB(), which
    was needed purely to communicate to LEAVESUB() which var to process

M       cop.h
M       pp_ctl.c
M       pp_hot.c
M       pp_sort.c

commit 616cf11225c1b1bda3e4754c6267c4d472c6f981
Author: David Mitchell <[email protected]>
Date:   Sat Oct 10 23:10:23 2015 +0100

    make LEAVESUB() always immediately follow POPSUB()
    
    Many years ago, POPSUB was split into two parts, with a final cleanup
    being done by the LEAVESUB() macro. This is no longer needed;
    shuffle LEAVESUB up a bit in various places so that it always immediately
    follows POPSUB. Then the next commit will eliminate it altogether.

M       cop.h
M       pp_ctl.c
M       pp_hot.c

commit cb655a64b703edaede0cf57432925ffd2385361e
Author: David Mitchell <[email protected]>
Date:   Sat Oct 10 23:01:55 2015 +0100

    move CX_LEAVE_SCOPE into POPEVAL
    
    All the other POPFOO types have CX_LEAVE_SCOPE as their first action.
    Add it as the first action of POPEVAL too, and remove all the explicit
    calls to CX_LEAVE_SCOPE dotted around near POPEVALs.
    
    Note that this causes a slight change in behaviour in dounwind:
    the CX_LEAVE_SCOPE is now done as the first action of POPEVAL there
    rather than being done afterwards. This is now consistence will all other
    uses of POPEVAL.

M       cop.h
M       pp_ctl.c

commit bff8f8b10ba72cb4a86fed39f76bf87274f41a63
Author: David Mitchell <[email protected]>
Date:   Sat Oct 10 22:49:46 2015 +0100

    add CX_LEAVE_SCOPE(cx) macro
    
    which is shorthand for
    
        LEAVE_SCOPE(cx->cx_u.cx_blk.blku_old_savestack_ix)
    
    This is the start of a new breed of macros designed to manipulate the
    conetect stack, that have a CX_ prefix, that will eventually superede
    the (PUSH/POP)(BLOCK/SUB/ETC) system.

M       cop.h
M       pp_ctl.c
M       pp_hot.c

commit f66b8327ed6030f3d3094e34bd389fce02fcf451
Author: David Mitchell <[email protected]>
Date:   Sat Oct 10 22:38:54 2015 +0100

    call LEAVE_SCOPE() before POPEVAL()
    
    All the other POPFOO() types have
    
        LEAVE_SCOPE(cx->cx_u.cx_blk.blku_old_savestack_ix);
    
    as their first action.
    
    POPEVAL doesn't include this. Instead, each place that does POPEVAL()
    currently does a LEAVE_SCOPE() sometime shortly afterwards.
    This commit moves all those LEAVE_SCOPE()s to just before each POPEVAL()
    to make the behaviour like all the other context types.
    
    This is the logically correct order: process all the savestack items
    accumulated during the eval before popping the eval itself.

M       pp_ctl.c

commit f2f4034159c49fb302ff458eb7a8cae46925b023
Author: David Mitchell <[email protected]>
Date:   Sat Oct 10 22:23:19 2015 +0100

    POPBLOCK: don't set newsp and gimme
    
    This macro used to set these two vars as a side-effect.
    Since we now usually access those values before we call POPBLOCK,
    it's wasteful to set them again.

M       cop.h
M       pp_ctl.c
M       pp_sort.c
M       pp_sys.c

commit b88db8c5744368ef8429a7891fe0fb2794e71267
Author: David Mitchell <[email protected]>
Date:   Sat Oct 10 16:31:28 2015 +0100

    move POPBLOCK after arg stack munging
    
    In various places where scope is left (pp_leave, pp_leavesub etc)
    the perl argument stack is processed: a combination of shifting return
    args down and mortalising or copying them. This is typically done in
    S_leave_common() (although pp_leavesub(lv) roll their own).
    
    Normally POPBLOCK() is called just before this, which
    a) initialises cx;
    b) sets newsp, gimme etc which are needed by S_leave_common()
    c) restores a bunch of PL_ vars from the saved values in cx.
    
    Logically, (c) should be the last thing done in the various pp_leave*
    functions, as saving the vars is the first thing done in the various
    pp_enter* functions.
    
    This commit moves POPBLOCK after S_leave_common() as a first step towards
    migrating it towards the end of the various functions.
    
    It shouldn't make any functional difference, as the values of the various
    restored vars aren't used by the arg munging code.

M       pp_ctl.c
M       pp_hot.c

commit 6b8b507db495d2ef3fd42d3c8a6754a76767c1d3
Author: David Mitchell <[email protected]>
Date:   Sat Oct 10 15:39:53 2015 +0100

    add PUSH/POPBASICBLK macros.
    
    Most contexts types have a pair, e.g. PUSHSUB/POPSUB for CXt_SUB.
    Add them for a basic block too, CXt_BLOCK, i.e. pp_enter/pp_leave.
    It makes things slightly more regular ahead of future refactoring.

M       cop.h
M       pp_ctl.c

commit 278c561fc57e0212e0c8caffd3cc142fb24e7361
Author: David Mitchell <[email protected]>
Date:   Mon Oct 5 16:59:05 2015 +0100

    pp_leavewhen(): skip POPWHEN()
    
    pp_leavewhen at some point will do an unconditional dounwind()
    to pop the WHEN, BLOCK, and any other intermediate contexts, till it
    returns to the enclosing FOR or GIVEN context. Thus there is no need to do
    an initial POPBLOCK()/POPWHEN(), as this will be done by dounwind.
    We just need to grab a couple of values from the top (GIVEN) context
    to go arg stack processing correctly.

M       pp_ctl.c

commit 815dde1c63c8a55d9f42fed4fbaffdefb5f9fd3d
Author: David Mitchell <[email protected]>
Date:   Mon Oct 5 16:23:07 2015 +0100

    pp_leavewhen: simply for() handling
    
    when returning control to an enclosing for loop, the next op to execute
    (i.e. my_op->op_nextop) will be an OP_UNSTACK, which handles popping stuff
    of stacks and doing PERL_ASYNC_CHECK(); so no need to do it here too.

M       pp_ctl.c

commit 120a9e8fa6d958ccffc35a863f0c56d9e2c986b3
Author: David Mitchell <[email protected]>
Date:   Mon Oct 5 15:50:18 2015 +0100

    rename S_dopoptogiven() to S_dopoptogivenfor()
    
    Since it searches the context stack for the next GIVEN *or* FOR LOOP
    context, make the name better express its purpose.

M       embed.fnc
M       embed.h
M       pp_ctl.c
M       proto.h

commit 347c3e2caefd7298e3810f13873e744447700774
Author: David Mitchell <[email protected]>
Date:   Mon Oct 5 14:48:35 2015 +0100

    add loop benchmark tests

M       t/perf/benchmarks

commit b78b8a1582e379808c94aae30aa319333010de00
Author: David Mitchell <[email protected]>
Date:   Fri Aug 28 16:11:50 2015 +0100

    Make remaining context types avoid ENTER/LEAVE
    
    Previous commits have made the 'subbish' context types like SUB, EVAL
    use the context stack to save the old values of PL_savestack_ix and
    PL_tmps_floor rather than using ENTER/SAVETMPS/LEAVE; extend this
    to the remaining contexts types; specifically loops, bare blocks and
    given/when.
    
    Note that this means that during context stack unwinding (e.g. in
    dounwind()), LEAVE_SCOPE() is called for every context popped, whereas
    before it was only done for each subbish context type.
    
    This makes the ordering of the actions in scope unwinding match much more
    closely the reverse order in which things were done during scope pushing;
    for example entering and leaving a for loop will now do:
    
        PUSHLOOP_FOR();
        ...
        ... code within loop which pushes stuff on the savestack
        ...
        LEAVE_SCOPE(); /* pops the stuff from above */
        POPLOOP();
    
    The main reason for this commit (apart from increased consistency)
    is that its a lot faster.

M       cop.h
M       pp_ctl.c
M       pp_hot.c

commit 04bc5729e4aa5bb9685186a4a04cb9f07acd3d59
Author: David Mitchell <[email protected]>
Date:   Mon Oct 5 10:57:09 2015 +0100

    Consistently call leave_common() before POPFOO
    
    In some places the code does
    
        POPBLOCK(); POPFOO(); leave_common();
    
    while in other places it does
    
        POPBLOCK(); leave_common(); POPFOO();
    
    Make it do the latter consistently. This is because the next commit
    will make *all* context types do a LEAVE_SCOPE(), not just the 'subish'
    ones as now. This means that any context type that can return args needs
    to preserve its args before doing the LEAVE_SCOPE()/POPFOO(), not just the
    sub ones.
    
    For example this lexical var is declared within a LOOP_PLAIN:
    
        sub foo {
            {
                my $x = 1;
                $x;
            }
        }
    
    where the return value of the loop block ($x) is also the return value of
    the sub. So let leave_common() make a mortal copy of $x before POPLOOP
    frees the lexicals in the inner scope.
    
    Similar comments apply to calling leave_common() before calling
    dounwind().
    
    Note that where the LEAVE_SCOPE() is located it not yet consistent;
    sometimes it's part of the POPFOO macro, sometimes it's not, and so has to
    be done explicitly just before calling POPBAR.

M       pp_ctl.c

commit 86abf643ce7ceecb46b973eb9780fbeddfa1f2d4
Author: David Mitchell <[email protected]>
Date:   Fri Oct 2 17:28:00 2015 +0100

    pp_given: avoid using savestack for old var
    
    Add a new field, defsv_save, to struct block_givwhen, and use this
    to save the previous $_ in 'when(expr)' rather than saving it on the save
    stack.
    
    Also add POPWHEN and POPGIVEN macros. The former is a no-op for now.

M       cop.h
M       pp_ctl.c

commit f4cc02ef2c08847eb26284c1db8d69efccf92e36
Author: David Mitchell <[email protected]>
Date:   Fri Aug 28 15:37:23 2015 +0100

    context: move couple of fields into block struct
    
    A few of the block_foo substructs within the context struct have the
    same two fields, old_savestack_ix and old_tmpsfloor. Move these into the
    basic block struct so they can be used by all blockish context types.
    
    This is basically a big renaming exercise and should make no functional
    difference.

M       cop.h
M       pp_ctl.c
M       pp_hot.c
M       pp_sort.c

commit 343a99832313d4ee12dda6b84f4e06b6e8afb0bb
Author: David Mitchell <[email protected]>
Date:   Fri Aug 28 08:37:42 2015 +0100

    pp_enteriter, POPLOOP: simplify some code
    
    merge some common code from branch arms and tidy up. Shouldn't make
    any functional difference.

M       cop.h
M       pp_ctl.c

commit c4982845947fcdfb0404a793c78483a452d144ed
Author: David Mitchell <[email protected]>
Date:   Fri Aug 28 08:21:05 2015 +0100

    pp_enteriter: don't create new SV for GvSV slot
    
    Currently in
    
        for $pkg_var (...) {}
    
    pp_enteriter() saves the current SV that's in the GvSV  slot, then
    replaces it with a newSV(0). Instead, leave it untouched. In the range
    cases:
    
        for $pkg_var (1..10) {}
        for $pkg_var ('a'..'z') {}
    
    a new SV will be created anyway in the first call to pp_iter(), since each
    time round the loop it checks whether the refcount of the iterator vars is
    greater than 1 and if so abandons it.
    
    For the list case, e.g.
    
        for $pkg_var (1,3,5) {}
        for $pkg_var (@foo) {}
    
    each call to pp_iter updates the GvSV slot to point to the current var,
    so sticking a null SV in there initially, and freeing it the end is just
    pointless extra work.
    
    The only slight proviso is when the GvSV slot is initially NULL. In this
    rare case we still create the SV, as it will be needed for the range
    cases.

M       pp_ctl.c
M       t/op/for.t

commit 98eb1b598fd795859c8904cae499138da9b863d0
Author: David Mitchell <[email protected]>
Date:   Thu Aug 27 16:03:42 2015 +0100

    add CXp_FOR_PAD, CXp_FOR_GV flags
    
    These indicate that the loop is a for loop, with a lexical or package
    iterator variable.
    
    These flags make various tests simpler and more efficient.
    
    This commit also fixes a bug introduced a couple of commits ago;
    I was assuming that in POPLOOP, itersave being non-NULL indicated a
    'for $lex' or 'for $pkg', but something like
    
        local *x;
        for $x (..) {}
    
    leaves the loop with itersave set to NULL. Instead we can use the new
    flags to indicate that itersave is valid.

M       cop.h
M       pp_ctl.c
M       t/op/for.t

commit 8c9d902036e8e30701b28f986102a0e7f804e855
Author: David Mitchell <[email protected]>
Date:   Thu Aug 27 14:45:13 2015 +0100

    pp_enteriter: tidy itervar-setting code
    
    rename itervar to itervarp since it's more like an SV** than an SV*,
    and set itersave earlier so that it can be used directly rather than
    repeatedly dereffing itervarp.
    
    Shouldn't be any functional change.

M       pp_ctl.c

commit 4562d9eda7cf40319e33a17b4d01db0db00e5957
Author: David Mitchell <[email protected]>
Date:   Thu Aug 27 13:43:49 2015 +0100

    for loops: don't refcount bump orig var
    
    In something like
    
        for $pkg_var (...)
    
    pp_enteriter() bumps the reference count or $pkg_var before making
    itersave point to it. POPLOOP later decrements this ref count.
    
    This bump is unnecessary; since we are effectively transferring ownership
    (and thus ref count contribution) of the $pkg_var SV from the GvSV slot of
    *pkg_var to the itersave slot of the context struct, the overall ref count
    of the var should remain unchanged.
    
    So skip the bump and later undo. This should make no functional difference;
    it's just more efficient.

M       cop.h
M       pp_ctl.c

commit 57bdf1df3f6e359b05a158d28b1d2caa050b0157
Author: David Mitchell <[email protected]>
Date:   Thu Aug 27 13:40:20 2015 +0100

    POPLOOP(): no need to mortalise current item
    
    Now that pp_return() protects its return arg(s) against premature freeing
    before calling dounwind(), there's no need for POPLOOP to mortalise the
    current item.

M       cop.h

commit c95cda284bf61b6583851605dabc4bb5907b42b7
Author: David Mitchell <[email protected]>
Date:   Wed Aug 19 12:33:24 2015 +0100

    Add itersave field to LOOP context struct
    
    When entering a for loop, rather than saving the original loop variable on
    the save stack, save it in the context struct. Quicker and simpler.
    
    Note that as of this commit, entering a for loop no longer saves anything
    on the save stack.

M       cop.h
M       pp_ctl.c

commit fa4b0c40dc0581cd7d5dcd242586b9ac881f3d3b
Author: David Mitchell <[email protected]>
Date:   Thu Aug 27 12:13:58 2015 +0100

    POPLOOP: call LEAVE_SCOPE()
    
    in PUSHLOOP, save the current PL_savestack_ix, and in POPLOOP, do
        LEAVE_SCOPE(cx->blk_loop.old_savestack_ix);
    This is in preparation for shortly not wrapping loops in ENTER/LEAVE.

M       cop.h

commit 2bef51276d6d0172d03d2c3e7bbbb11a6201ea40
Author: David Mitchell <[email protected]>
Date:   Thu Aug 27 12:02:27 2015 +0100

    pp_return(): reindent following previous commit
    
    whitespace-only change

M       pp_ctl.c

commit 4fb0d0008dd10e6da54dba39ff670747fe50c1bd
Author: David Mitchell <[email protected]>
Date:   Tue Aug 25 13:57:55 2015 +0100

    pp_return(): handle dounwind() freeing args
    
    Currently only POPSUB (and other sub-like contexts, such as POPEVAL) do a
    LEAVE_SCOPE() as well as restoring things from the context struct. This
    means that if pp_return() does a dounwind() to pop back to the next
    SUB/EVAL/FORMAT context, LEAVE_SCOPE() won't get called, and any return
    values aren't prematurely freed, e.g. in the following
    
        sub f {
            for (...) {
                my $x = 1;
                return $x;
            }
        }
    
    POPLOOP() won't call LEAVE_SCOPE(), so $x doesn't get freed.
    
    The next commit is about to change that: POPLOOP() will indeed call
    LEAVE_SCOPE(), (and later commits may make other POPFOO() types do that
    too). So in preparation, this commit makes pp_return() preserve any return
    args before calling dounwind().

M       pp_ctl.c
M       t/op/sub.t
M       t/op/sub_lval.t

commit 65aa0164f06cef180b15f6bd094f0d8ae38cb436
Author: David Mitchell <[email protected]>
Date:   Wed Aug 26 11:34:59 2015 +0100

    pp_leaveloop: use SVs_PADTMP|SVs_TEMP
    
    When calling leave_common(), most callers specify the "safe" return SVs
    that don't need copying as being those with SVs_PADTMP or SVs_TEMP
    set (leaveeval is a correct exception to this this).
    
    pp_leaveloop() specified no flags, meaning that it always copies. This
    appears to be just be an oversight rather than being for any good reason.

M       pp_ctl.c

commit 73b9759186d400066db02e3b4cd4315cf1916129
Author: David Mitchell <[email protected]>
Date:   Wed Aug 26 09:53:09 2015 +0100

    S_leave_common(): simplify SVs_PADTMP handling
    
    Now that SVs_PADTMP is a simple flag again (at one point its meaning was
    inferred from the state of two flags) it no longer needs special handling
    in S_leave_common().

M       pp_ctl.c

commit 720325c49670f0da0c7475b5db241533aaf4b9ba
Author: David Mitchell <[email protected]>
Date:   Sun Jul 19 10:51:38 2015 +0100

    for my $x (...): $x is always stale
    
    Remove the code in pp_enteriter that turns $x's staleness off and schedules
    on the save stack for it to be turned back on at scope exit.
    
    Since 'for my $x' works by making $x's pad slot temporarily point to
    each item in turn, the "real" $x which lives in the pad outside of loop
    time can never be accessed by the usual closure tricks (BEGIN, eval,
    nested named subs etc) during a loop, so doesn't need to be marked as not
    stale.
    
    Skipping this step is one less thing to be pushed onto the save stack
    on each for loop entry.

M       pp_ctl.c

commit 275c6e1f52521cb052f548732d3a541ba50403d7
Author: David Mitchell <[email protected]>
Date:   Fri Jul 17 23:22:29 2015 +0100

    pp_last: use debugging LEAVE variant
    
    Make the two LEAVEs in pp_last() be instead
    
        LEAVE_with_name("loop2");
        LEAVE_with_name("loop1");
    
    which is more self-documenting and will trap mistakes on DEBUGGING builds

M       pp_ctl.c

commit c49092994a1075672715c155d68f52144d2c5026
Author: David Mitchell <[email protected]>
Date:   Fri Jul 17 22:49:40 2015 +0100

    only call leave_common in non-void context
    
    A lot of the pp_leave* functions call S_leave_common() to process
    any return args. Since many of these tend to be used in void context
    (e.g. plain blocks {; ... }, for loops etc) tst gimme and only call
    these function is non-void. For void context the function is mostly
    a noop anyway; the only thing we're skipping is TAINT_NOT, which
    doesn't matter in void context.

M       pp_ctl.c

commit d3b82d01ee4203ea8cd1be18d86c06d34bc84a72
Author: David Mitchell <[email protected]>
Date:   Fri Jul 17 22:23:51 2015 +0100

    CXt_EVAL: save savestack_ix and tmps_floor in CX
    
    In the various places that do PUSHEVAL (eval, require etc), eliminate
    
        ENTER; SAVETMPS
    
    and instead save the old values of PL_savestack_ix and PL_tmps_floor
    directly in the eval context frame, similarly to how subs have been
    recently changed.
    
    This is faster and cleaner.

M       cop.h
M       pp_ctl.c

commit d0c97dc4877bc5e729b09331ace78328caee0ba0
Author: David Mitchell <[email protected]>
Date:   Fri Jul 17 21:51:25 2015 +0100

    move SAVETMPS next to PUSHEVAL
    
    In the various places where PUSHEVAL() is used, a SAVETMPS appears
    shortly before it. Move each occurrence of SAVETMPS to just after the
    SAVETMPS, in preparation shortly for making PUSHEVAL responsible for
    saving PL_tmps_floor.
    
    In theory this could make certain temporary items created during
    eval/require startup to be freed slightly later. I don't know whether
    this is is an issue or not. No tests fail ;-)

M       pp_ctl.c

commit 66dddd6218f4531fd3816b717b8ed4097fbb96f0
Author: David Mitchell <[email protected]>
Date:   Fri Jul 17 14:44:32 2015 +0100

    call_sv(), fold_const(): different CX pop test
    
    Perl_call_sv() and S_fold_constants() both have similar code that:
    pushes an EVAL context, does a JMPENV_PUSH() and CALLRUNOPS(), then
    optionally pops the EVAL context.
    
    The optionally part depends on whether what's doing the dying
    has already popped the context before long-jumping. Currently the decision
    on whether to pop is based on whether the scope stack has already been
    popped.
    
    This commit changes that to whether the context stack has already been
    popped, since shortly we're going to change eval contexts so that the old
    savestack_ix is stored in the CX struct rather than on the scope stack.
    
    I ran this code with some asserts that the two conditions were identical,
    and nothing failed.

M       op.c
M       perl.c

commit da2ea97b863067b6a7a9044fe3c3c4d6713c9061
Author: David Mitchell <[email protected]>
Date:   Thu Jul 16 14:44:06 2015 +0100

    CXt_FORMAT: save ss_ix and tmps_floor in CX struct
    
    To match the recent work in this branch on CXt_SUB, make CXt_FORMAT save
    PL_savestack_ix and PL_tmps_floor in the context structure rather than
    doing ENTER/SAVETMPS. It's more efficient and more consistent.

M       cop.h
M       pp_sys.c

commit 0b3d2fc832504c5911965751244529a225f050d5
Author: David Mitchell <[email protected]>
Date:   Mon Jul 13 16:31:20 2015 +0100

    pp_entersub(): reduce life of padlist var
    
    only set it when it's needed

M       pp_hot.c

commit 01cba1c32245615c1bad66d1eed6db92f2132a94
Author: David Mitchell <[email protected]>
Date:   Mon Jul 13 16:25:36 2015 +0100

    pp_entersub: unroll some CvFLAGS(cv) tests
    
    Do a single bit comparison rather than two conditionals. Slightly faster.

M       pp_hot.c

commit 24c3447103c8532d8c9ac9079eadae07342a9a5c
Author: David Mitchell <[email protected]>
Date:   Mon Jul 13 16:18:55 2015 +0100

    pp_entersub(): reduce scope of gimme
    
    Only calculate the gimme var where its needed.

M       pp_hot.c

commit 46e44bce2eae3ea539c12aac0ebdc71a5c9b3224
Author: David Mitchell <[email protected]>
Date:   Mon Jul 13 13:11:01 2015 +0100

    pp_entersub(): don't prematurely calc hasargs
    
    Currently at the top of pp_entersub() is:
    
        const bool hasargs = (PL_op->op_flags & OPf_STACKED) != 0;
    
    Defer testing this flag and/or saving it to a local var until
    its actually needed. This is a micro-optimisation.

M       pp_hot.c

commit edadea54c9eafdb9ba99c9596813a716fd4b3ac4
Author: David Mitchell <[email protected]>
Date:   Mon Jul 13 12:48:17 2015 +0100

    revamp pp_entersub()'s CV locating code
    
    The big switch statement at the top of pp_entersub() is intended
    to extract the CV from the passed argument, which might be a CV, a GV,
    a ref to a CV, etc etc.
    
    In 5.22.0, an optimisation was added to stashes such that if an entry
    contained only a CV, then a ref to the CV was stored in the stash, rather
    than a GV. This means that in the common case for a plain sub call, sv is
    now a ref to a CV rather than a GV. So update the code to:
    
    1) remove the special-casing of GVs;
    2) add special casing for the sv being a non-magical, non-overloaded RV
       pointing to a CV;
    3) add special casing for the sv being a CV (true on method calls);
    3) move the rare "sv == &PL_sv_yes" test further down the condition chain;
    4) generally rearrange the switch cases so that common things fall though
       and uncommon things do a goto;
    5) sprinkle more LIKELY() pixie dust.
    
    Part of the intention of special-casing is to avoid doing an indirect
    branch by avoiding the switch statement completely.

M       pp_hot.c

commit 5cdb62fd6b3da29f6e227251f1c4c893ad65666e
Author: David Mitchell <[email protected]>
Date:   Mon Jul 13 11:48:04 2015 +0100

    tweak POPSUB()
    
    re-order things slightly in POPSUB() so that values aren't being
    read into local vars before they're needed (so the compiler doesn't
    have to write the values back out to the local stack frame if it runs out
    of spare registers).
    
    Also, re-order the fields in struct block_sub so that they roughly
    correspond with the order in which they are accessed by POPSUB. This is on
    the voodoo theory that if the struct straddles a cache line, we may
    trigger a prefetch of the second line, so the extra data will be ready for
    us when we need it.

M       cop.h

commit 11c44fcdfc52c364fd537852b869458cb6c9e0c0
Author: David Mitchell <[email protected]>
Date:   Sat Jul 11 22:13:51 2015 +0100

    Eliminate ENTER/LEAVE from sub calls
    
    Every sub call is wrapped in an ENTER/LEAVE pair, which uses the next
    free slot on the scope stack to save and then restore the old value of
    PL_savestack_ix. Instead, store the old value in a new field in the
    context structure, old_savestack_ix. This is quicker and simpler.
    
    Not that we keep the ENTER/LEAVE for XS sub calls, as they don't push a
    context frame, and so have nowhere else to remember PL_savestack_ix.
    
    As a side-effect, this commit fixes a TODO test in t/op/sub.t,
    which was related to dying while popping a context, then re-popping that
    context. For the second pop, the scopestack has since been overwritten
    and so too much was getting popped from the savestack. Since we no longer
    use the scopestack, it's no longer an issue.

M       cop.h
M       pp_ctl.c
M       pp_hot.c
M       pp_sort.c
M       t/op/sub.t

commit e76b46d89140080a8260b8597d19f8b82f7960c3
Author: David Mitchell <[email protected]>
Date:   Sat Jul 11 16:43:25 2015 +0100

    pp_hot.c: skip unnecessary test
    
    This condition:
    
        !CvROOT(cv) && !CvXSUB(cv)
    
    can be simplified because those two cv fields are actually
    the same slot in a union.

M       pp_hot.c

commit ede6b7eea062877727c8c0e3173578de5dd805f2
Author: David Mitchell <[email protected]>
Date:   Sat Jul 11 15:37:11 2015 +0100

    pp_entersub(): simplify autoload logic
    
    eliminate a label and goto by by just setting cv to null on failure,
    and have a single "if (!cv) croak()" test at the end of the loop.

M       pp_hot.c

commit acb8e8bcb4d0ae6fd664518db0c620e2713061dc
Author: David Mitchell <[email protected]>
Date:   Sat Jul 11 15:30:38 2015 +0100

    pp_entersub(): eliminate a label
    
    replace:
    
      retry:
        if (A) die;
        if (B) {
            ...;
            goto retry;
        }
    
    with
    
        while (B) {
            ...;
        }
    
        if (A) die;
    
    it's functionally equivalent except that the A test is now only
    tried after we have been successful at B. This is ok, because
    A is testing for an uncloned closure prototype, while B is looking
    for a CV stub which needs autoloading,and it doesn't rally matter
    which we test for first.

M       pp_hot.c

commit 77e41e6121a2ae060f3039290aed5e2180c8cdc1
Author: David Mitchell <[email protected]>
Date:   Sat Jul 11 14:42:56 2015 +0100

    add old_tmpsfloor field to CXt_SUB context frame
    
    Rather than saving and restoring PL_tmps_floor on subroutine entry/exit
    by using SAVETMPS and the save stack, store the old value directly
    in the context struct and make PUSHSUB/POPSUB handle the saving and
    restoring.

M       cop.h
M       pp_ctl.c
M       pp_hot.c
M       pp_sort.c

commit bc02aaaba346e86990bdd0876418e9d2c44c70f5
Author: David Mitchell <[email protected]>
Date:   Sat Jul 11 14:16:29 2015 +0100

    PUSH_MULTICALL: move SAVETMPS later
    
    Move the SAVETMPS to just after the PUSHSUB. This should make no
    functional difference, because nothing should have affected the TMPS stack
    between the old and the new code positions.

M       cop.h

commit 4b60c86e59c8f858a2e471241aebaf0e678574f1
Author: David Mitchell <[email protected]>
Date:   Sat Jul 11 14:04:59 2015 +0100

    pp_dbstate: do SAVETMPS etc in both branches
    
    pp_dbstate() does an XS or non-XS subroutine call to &DB::DB;
    move the SAVETMPS from before the (if CvISXSUB(cv)) test to the head of
    both branches. This duplication of code is currently a noop, but will
    shortly allow us to handle things differently in the two branches.

M       pp_ctl.c

commit c0dea1792c843d089425260cc7827f0dbc916825
Author: David Mitchell <[email protected]>
Date:   Sat Jul 11 13:58:47 2015 +0100

    pp_sort: move SAVETMPS later
    
    Move the SAVETMPS to just after the PUSHSUB. This should make no
    functional difference, because nothing should have affected the TMPS stack
    between the old and the new code positions.
    
    For the OPf_SPECIAL/ CXt_NULL case, which doesn't do a PUSHSUB,
    do another SAVETMPS there too.

M       pp_sort.c

commit 400d16fd70805adcdf1d486d99f9349f0d6693ec
Author: David Mitchell <[email protected]>
Date:   Sat Jul 11 13:45:01 2015 +0100

    pp_goto: do SAVETMPS etc in XS and non-XS branches
    
    Move a SAVETMPS;SAVEFREESV(cv); from before the "if (CvISXSUB(cv))" test
    to the head of both branches. This duplication of code is currently
    a NOOP, but will shortly allow us to handle things differently in the two
    branches.

M       pp_ctl.c

commit 02d732b3c76d821391ea9275d62ac214d58b526b
Author: David Mitchell <[email protected]>
Date:   Sat Jul 11 13:32:03 2015 +0100

    pp_entersub(): move SAVETMPS next to PUSHSUB
    
    It it intended that eventually PUSHSUB() will do the SAVETMPS itself,
    so move the SAVETMPS up so that it's next to the PUSHSUB.
    There should be nothing between those two points that use the TEMPS stack,
    so this commit should have no functional effect.

M       pp_hot.c

commit 95760e8c0609a5f15bcf2e9cf810ba72b0ea44e7
Author: David Mitchell <[email protected]>
Date:   Sat Jul 11 13:10:00 2015 +0100

    pp_entersub(): remove an unnecessary condition
    
    The code that scans the args list making mortal copies is protected by an
    
        if (LIKELY(hasargs)) {
    
    However, a sub called as "&foo;" (which is how hasargs is determined)
    won't have pushed anything on the stack, so the first part of that code
    block, "while (svp < SP)", will drop out immediately.
    
    So skip doing the hasargs test.
    
    NB - it's possible in theory for XS code to call call_sv() jn such a way
    as to both have !hasargs but with stuff on the stack; in this worst case,
    we just waste a bit of time making some mortal copies of those args.

M       pp_hot.c

commit af3da171ab88f2889fced445d607fb5d8422d3da
Author: David Mitchell <[email protected]>
Date:   Sat Jul 11 12:43:43 2015 +0100

    pp_entersub(): mortal-copy args earlier
    
    Move the code earlier which makes a mortal copy of any PADTMP args.
    This should make no functional difference, but will shortly allow
    us to move the SAVETMPS earlier too (while still coming after the
    mortal copying).

M       pp_hot.c

commit a9353ce91808f4c0b4d11f914336c8d31f449f37
Author: David Mitchell <[email protected]>
Date:   Sat Jul 11 11:49:13 2015 +0100

    pp_leavesub: simplify recursion test
    
    Part of pp_leavesub() tests whether we're in recursion by looking
    at CvDEPTH(cx->blk_sub.cv). Instead, just directly check
    cx->blk_sub.olddepth, which is equivalent (allowing for an offset of 1)
    but faster.

M       pp_hot.c

commit 417c71efc01c772b29f4917a410b9f7598d36b45
Author: David Mitchell <[email protected]>
Date:   Sat Jul 11 11:05:55 2015 +0100

    clear_defarray(): clear @_ if possible
    
    clear_defarray() is called during sub exit to clean up @_ in the
    less common case where @_ has somehow gotten reified.
    
    At the moment it just frees the old @_, then creates a new AV and
    sticks it in pad[0].
    
    This commit changes it so that for the reasonably common case of a reified
    @_ where it's not magical and only has a reference count of 1, just call
    av_clear() on it, rather than freeing and recreating.
    
    Typical code that will benefit from this change is be something like:
    
        sub f { push @_, ...; ... }
    
    which causes the AV to be reified, but not to become otherwise visible.

M       pp_hot.c

commit c4ae48ade440bab6d0fc6f3e3c0e7b8cc43c5913
Author: David Mitchell <[email protected]>
Date:   Sat Jul 11 10:52:49 2015 +0100

    pp_goto(): use clear_defarray()
    
    In pp_goto(), use the newly-added clear_defarray() function
    to the clear the old @_. This ensures that POPSUB() and pp_goto()
    do the same thing. Note that clear_defarray() is actually better than
    the old pp_goto() code, in that it pre-sizes the newly-created array
    to match the size of the array being abandoned.

M       pp_ctl.c

commit 697decb54576ade8d74a845fa250abd4fc67e22e
Author: David Mitchell <[email protected]>
Date:   Sat Jul 11 10:40:23 2015 +0100

    add Perl_clear_defarray()
    
    This function implements the less commonly used branch in the POPSUB()
    macro that clears @_ in place, or abandons it and creates a new array
    in pad slot 0 of the function (the common branch is where @_ hasn't been
    reified, and so can be clered simply by setting fill to -1).
    
    By moving this out to a separate function we can avoid repeating the same
    code everywhere the POPSUB macro is used; but since its only used
    in the less frequent cases, the extra overall of a function call doesn't
    matter.
    
    It has a currently unused arg, 'abandon', which will be used shortly.

M       cop.h
M       embed.fnc
M       embed.h
M       pp_hot.c
M       proto.h

commit b0dfa73156d057655f0ce7dd819b470d52cd8786
Author: David Mitchell <[email protected]>
Date:   Sat Jul 11 10:06:39 2015 +0100

    avoid leaking @_ in goto
    
    pp_goto temporarily bumps the reference count of @_ while doing
    LEAVE_SCOPE(), to stop it getting prematurelly freed. If something
    dies during the save stack unwinding, it will leak.
    Instead, make it mortal.

M       pp_ctl.c
M       t/op/svleak.t

commit 7b0d0918837eb2270dbd0482a0acda9fee34cd25
Author: David Mitchell <[email protected]>
Date:   Thu Jul 9 09:22:38 2015 +0100

    goto.t: add freeing CV test
    
    This code SEGVed in a cpan/ module while I was messing with pp_goto.
    Add it to t/op/goto.t so that it can SEGV there instead.

M       t/op/goto.t

commit 56d1f8f68283b7054ddd0a7a4d0e1c021d6c08ba
Author: David Mitchell <[email protected]>
Date:   Sun Jul 5 10:21:14 2015 +0100

    pp_goto: do the DIEing before the POPing
    
    Rearrange the beginning of the 'goto &func' part of pp_goto so that it
    does most of its error checks (e.g. "Can't goto subroutine from an eval")
    before it starts doing "return-ish" stuff. This makes the code slightly
    cleaner, especially as it doesn't have to undo the SvREFCNT_inc(cv) guard
    in every die branch.

M       pp_ctl.c

commit cc23b153369ea0ca3df7b396b659f5a4a17f81a5
Author: David Mitchell <[email protected]>
Date:   Sun Jul 5 10:08:25 2015 +0100

    eliminate a goto in pp_goto (!)
    
    Replace a C-level goto with a while loop: logically equivalent,
    but doesn't use a goto. (I know, I know, this is in pp_goto, but even
    so...)

M       pp_ctl.c

commit 02b1665fec1ae9571c39b50e69cb6469326eb8a5
Author: David Mitchell <[email protected]>
Date:   Fri Jul 3 11:40:01 2015 +0100

    pp_goto: a couple of cosmetic changes
    
    had a lable outdented 2, not 4 chars, and move a comment describing
    what a branch does from before to after the 'if'.

M       pp_ctl.c

commit 6ea3f810f0a0d523e702db1998a208b12451631d
Author: David Mitchell <[email protected]>
Date:   Fri Jul 3 11:14:30 2015 +0100

    make POP_SAVEARRAY() safe
    
    POP_SAVEARRAY() frees the current @_ and restores it to the callers value.
    As currently defined, it frees the old AV then updates GvAV(PL_defgv). If
    the free old the old AV triggers a destructor for example, then in
    theory something bad could happen.
    
    I couldn't actually find a simple failure case, but I suspect that
    something like
    
        sub f { *_ = bless [], 'Foo' }
    
    where Foo::DESTROY is an XS sub that messes with GvAV(PL_defgv), could do
    it.
    
    Anyway to play safe, this commit updates the GvAV() slot and *then* frees
    the old AV. This our normal modus operandi in other places anyway.
    
    The equivalent code in pp_goto already does this the safe way. This commit
    also updates pp_goto to use the (now equivalent) POP_SAVEARRAY() macro.

M       cop.h
M       pp_ctl.c

commit ea7dd23e56515223206fe4a832dd68856a6b4753
Author: David Mitchell <[email protected]>
Date:   Thu Jul 2 10:14:14 2015 +0100

    t/perf/benchmarks: add a few sub and goto tests

M       t/perf/benchmarks

commit 46f0e2e86534615136404de1647f05ebe52c884d
Author: David Mitchell <[email protected]>
Date:   Wed Jul 1 20:19:23 2015 +0100

    pp_entersub: skip resetting @_
    
    Whenever we leave a sub by whatever means (pp_leavesub, pp_return,
    pp_goto, die etc) it is the responsibility of the code that pops
    the SUB context to clean up the private @_ of that sub (i.e pad[0])
    so that it's empty and not real.
    
    There's some code in pp_entersub that duplicates this check. I believe
    this check is unnecessary and so this commit removes it and replaces it
    with an assert. It was added by 221373f04 in 1999 to fix the issue
    described in
    
        Subject: [ID 19991015.010] [BUG 5.005_62 Assertation failed:
                "pp_ctl.c" line 2443]
        Message-Id: <[email protected]>
    
    There were two fixes applied for this issue; the other was
    0253cb4. I think the second commit actually fixed the issue and the
    first fix was a red herring.
    
    If my newly-added assert fails, it implies that something needs fixing in
    the context-popping code, rather than in pp_entersub.
    
    In fact the new assert showed up one issue: the special-case handling
    of @_ for &CORE::undef in pp_coreargs wasn't emptying the array,
    so I added a CLEAR_ARGARRAY().

M       pp.c
M       pp_hot.c

commit 62c6d8705d822eefc93d99474013b236e067fa7f
Author: David Mitchell <[email protected]>
Date:   Wed Jul 1 16:50:53 2015 +0100

    improve @_ commentary in pp_goto
    
    Following on from the previous commit which removed cx.argarray,
    remove 'argarray' from the comments about @_, and at the same time
    generally overhaul those comments; in particular, explaining how
    it's a two part process of donating the current @_ to the new sub.

M       pp_ctl.c

commit 3f6f365e81aea3fc8cd5d2a8c357e2f0b32fb9fe
Author: David Mitchell <[email protected]>
Date:   Wed Jul 1 13:37:32 2015 +0100

    eliminate the argarray field from the CX struct
    
    At the end of a normal sub call there are often 3 AVs of interest
    associated with @_; these are:
    
        cx->blk_sub.savearray  the caller's @_
        GvAV(PL_defgv)         the current sub's current @_
        cx->blk_sub.argarray   the current sub's original @_
    
    Note that those last two can differ: if for example the sub does
    
        local *_ = [];
    
    Each sub's arg array is created and stored in pad slot 0 at the time
    the sub is created. When a sub is called, pp_entersub() does
    
        cx->blk_sub.argarray = PL_curpad[0]
    
    The argarray field is used in two main places:
    
    * at subroutine exit, to clear/abandon the sub's original @_;
    * in pp_caller, to set @DB::args to the caller(n)'s args.
    
    In the first case, the last few commits have arranged things so that at
    that point, PL_curpad always points to the current pad of the sub being
    exited from. So we can just use PL_curpad[0] rather than
    cx->blk_sub.argarray.
    
    In the second case (which is not performance critical), we can just use
        cx->blk_sub.cv
    and
        cx->blk_sub.olddepth+1
    to find the pad of that call frame's CV.
    
    So we can eliminate the argarray field. This saves a write during
    a sub call, and potentially reduces the size of the context struct.
    
    It also makes the code marginally less confusing: there are now 3 arrays
    pointed to from 3 places, rather than 3 arrays pointed to from 4 places.
    
    The asserts added in the previous commit confirmed that using argarray
    is the same as using PL_curpad[0]; They also confirmed that the current
    PL_curpad matches the current CV at the current depth. Those latter
    asserts are kept for now.

M       cop.h
M       pp.c
M       pp_ctl.c
M       pp_hot.c
M       pp_sort.c
M       sv.c

commit ddf99704afcceba3595018a8d435e7432f5ba74d
Author: David Mitchell <[email protected]>
Date:   Wed Jul 1 12:21:06 2015 +0100

    assert that it's safe to remove CX.argarray field
    
    This commit adds assertions that demonstrate that the next commit is safe.
    See the description of that commit for details.

M       cop.h
M       pp.c
M       pp_ctl.c

commit 2c24a4f079d7fcc0a885418477dad48581253abd
Author: David Mitchell <[email protected]>
Date:   Wed Jul 1 09:57:51 2015 +0100

    Unwind save stack in sync with POPEVAL
    
    During normal exit from an eval, both POPEVAL and LEAVE are done,
    meaning that the context stack and save stack are unwound in lockstep.
    
    However, during an exception, dounwind() does the POPEVAL but not the
    LEAVE, leaving them temporarily out of step.
    
    About a 2 years ago, with v5.19.3-139-g2537512, subs and formats were
    changed so that the save stack popping was done in sync in dounwind.
    
    This commit extends that to evals too.
    
    I'm doing this principally so that PL_compad will always be restored at
    the correct moment, which will shortly allow me to eliminate the argarray
    field from the context struct.
    
    NB: unlike POPSUB and POPFORMAT, I've added the LEAVE_SCOPE to dounwind
    rather than directly adding to the POPEVAL macro - this is because the
    various places that use POPEVAL typically use it earlier than the
    comparable places with POPSUB, which means they aren't ready to pop the
    save stack yet.
    
    NNB: The LEAVE_SCOPE can't be extended to all context types in dounwind(),
    only to sub-ish types - specifically the types that can be 'return'ed from.
    This is because if you 'return' from a sub or eval, pp_return will
    unwind all contexts down to the next sub or eval (discarding all the loops
    etc that it escaping out of), but the args it is returning shouldn't
    be prematurely freed.

M       pp_ctl.c

commit 79d478f65174cff63bd9505650265137d0e04e90
Author: David Mitchell <[email protected]>
Date:   Wed Jul 1 07:56:39 2015 +0100

    pp_goto: skip restoring PL_comppad
    
    Now that PL_comppad is saved in the context struct rather than on the save
    stack, we can better control when and how it is restored. In the case of
    pp_goto, there's no need to restore the caller's PL_comppad in the non-XS
    case, since we will be immediately setting it to the new function's pad.
    
    AS well as being slightly more efficient, this avoids restoring PL_comppad
    too early, where if we subsequently croak we re-process the CXt_SUB block
    in dounwind, but this time with the wrong pad.
    
    In particular, by having always PL_curpad[0] == cx.argarray at sub exit
    time, we can shortly eliminate the argarray field.

M       pp_ctl.c

commit ee79ac3f8883c92fde3496aaa7b4bdc765c3b327
Author: David Mitchell <[email protected]>
Date:   Tue Jun 30 08:03:43 2015 +0100

    undef *_; goto &f: update cx.argarray
    
    In something like
    
        sub f { goto &g }
    
    normally g's pad[0] is updated to hold the passed-across @_, and the
    context block's argarray field is updated to point to g's @_ too.
    
    However in the case of
    
        sub f { undef *_; goto &g }
    
    cx.argarray isn't being updated. This is probably harmless (I couldn't
    come up with a test case that fails), but for consistency, update it too.
    
    This is mainly so that over the next few commits, this condition will come
    to apply consistently:
    
        cx.argarray == PL_curpad[0]
    
    and so the argarray field can be eliminated.

M       pp_ctl.c

commit d0479a7196e726ddaf526e4df4a0852a03ccbd46
Author: David Mitchell <[email protected]>
Date:   Mon Jun 29 12:33:35 2015 +0100

    make "for my $lex {}" faster under ITHREADS
    
    Normally at the start of a 'for' iteration (pp_enteriter), we store the
    address of the GV or the address of the pad slot of the iteration variable
    in the CX struct, so we can quickly access and update it in pp_iter.  For
    the ITHREADS case however, the pad may change if the thread is cloned, so
    instead the address of PL_comppad was stored, and then updated during
    cloning. This meant that on each iter, we would have to retrieve the saved
    PL_comppad address from the ctx struct, retrieve the targ from the saved
    my_op, and do a (perlish) array indexing.
    
    Thuis commit makes this faster by, for the ITHREADS case, storing both
    PL_comppad and svp = &PLcurpad[targ]. In pp_iter(), we're fast by directly
    accessing *svp; while storing PL_comppad allows us to update both it and
    svp during thread cloning.
    
    This requires one extra pointer in the block_loop part of the context
    union under threads, but this is already smaller than some other parts of
    the union, so has no effect.
    
    Note that the oldcomppad field was formerly part of the itervar_u union,
    but is now a separate field within the larger block_loop struct (but only
    on threaded builds).
    
    Note also that the tests I've added I retrieved from an old WIP private
    branch that contained a forerunner of this commit, so they may not be
    entirely relevant to the current form of this commit. But extra tests
    can never hurt, so I've included them.

M       cop.h
M       ext/XS-APItest/t/clone-with-stack.t
M       pp_ctl.c
M       sv.c
M       t/op/for.t
M       t/perf/benchmarks

commit 457e2d60b59aa0710974ce3f27f429f6af7f0111
Author: David Mitchell <[email protected]>
Date:   Mon Jun 29 12:02:18 2015 +0100

    eliminate cx->blk_sub.oldcomppad
    
    In the CXt_SUB sub-struct of the context struct, there is a field
    called oldcomppad. Despite the "old" in its name, this field actually
    stores the value of PL_comppad of the new sub, not of the caller.
    
    It's only use currently is in POPSUB() when abandoning a reified @_, to
    locate PL_curpad[0] of the current sub in order to stick a new empty AV
    there.  This is a relatively rare occurrence, and the pad slot can be
    found (slightly less efficiently) from the saved CV and its depth.

M       cop.h
M       pp_ctl.c
M       pp_hot.c
M       pp_sort.c
M       sv.c

commit 647696e3c7c5c3177d1dadb95295aa1886249997
Author: David Mitchell <[email protected]>
Date:   Mon Jun 29 11:36:27 2015 +0100

    document unrolled PUSHSUB/POPSUB
    
    some places in the code do some or all of the same activities as
    PUSHSUB() and POPSUB(). Add comments in those places pointing out that
    it's a partially unrolled PUSH/POPSUB(). This will also help if someone
    greps the code looking for all the places in core that supposedly does
    a PUSH/POPSUB.

M       cop.h
M       pp_ctl.c

commit 99c98dc276e713760156798c446d1853548912a9
Author: David Mitchell <[email protected]>
Date:   Mon Jun 29 11:27:36 2015 +0100

    save old PL_comppad in CXt_SUB/FORMAT block
    
    Currently when we call a sub, the old value of PL_comppad is
    saved on the save stack using SAVECOMPPAD(). Instead, save it in
    a new field in the context struct, called prevcomppad. This is simpler
    and more efficient.
    
    Note that there is already a confusingly-named field in the CXt_SUB
    context struct called oldcomppad, which holds the value of PL_comppad for
    the *current* sub, not for its caller. So the new field had to be called
    something else.
    
    One side effect of this is that an existing bug  - which causes too much
    to be popped off the savestack when dieing while leaving a sub scope - is
    now more noticeable, since PL_curpad and SAVEt_CLEARSV are now out of
    sync: formerly, the unwinding of the save stack restored PL_curpad in
    lockstep. The fix for this will come later in this branch, when the whole
    issue of context stack popping order and reentrancy is addressed; for
    now, a TODO test has been added.

M       cop.h
M       pp_ctl.c
M       pp_hot.c
M       pp_sort.c
M       pp_sys.c
M       regexec.c
M       sv.c
M       t/op/sub.t

commit e7afd249a6c6d92a0ab81d005fbdc3a8450ba50a
Author: David Mitchell <[email protected]>
Date:   Fri Jun 26 12:17:59 2015 +0100

    pp_entersub:  remove extraneous SAVETMPS
    
    The branch that handles "no cv, try autoload" does a SAVETMPS.
    This serves no purpose, since we will shortly be doing another SAVETMPS
    anyway with no intervening ENTER.

M       pp_hot.c

commit 8e2abe941835ae1d8016ede6cec62ea16bf4ceb2
Author: David Mitchell <[email protected]>
Date:   Thu Jun 25 16:08:02 2015 +0100

    pp_goto: SvREFCNT_dec(oldcv) *after* undef test
    
    pp_goto does a LEAVE, then checks that the new CV hasn't been undefed
    by the LEAVE. If it has, it croaks.
    
    Move the decrementing of the old CV's ref count and depth to *after*
    this check, since the POPSUB done during the croak unwind will do the
    decrement also. Otherwise the old sub will be doubly freed.

M       pp_ctl.c
M       t/op/goto.t

commit 66b0283cbbc1a4848e5333aa4745df05fa44a1e2
Author: David Mitchell <[email protected]>
Date:   Thu Jun 25 15:18:25 2015 +0100

    pp_goto(): reorder LEAVE_SCOPE for consistency
    
    pp_leavesub (via POPSUB()) does a LEAVE_SCOPE before decrementing the CV's
    ref count and depth; pp_goto does it after. Reorder it for consistency
    with leavesub.
    
    At this point I make no assertion as to which way round is the most
    correct.

M       pp_ctl.c

commit d83887c7c936f4b65c50d4aa451b6620c3d2387e
Author: David Mitchell <[email protected]>
Date:   Thu Jun 25 15:08:37 2015 +0100

    pp_goto: use cx->blk_oldscopesp
    
    POPSUB() does:
    
        LEAVE_SCOPE(PL_scopestack[cx->blk_oldscopesp - 1])
    
    while pp_goto(), which manually does the relevant actions from POPSUB(),
    does:
    
        LEAVE_SCOPE(PL_scopestack[PL_scopestack_ix - 1])
    
    For consistency, make pp_goto() use cx->blk_oldscopesp instead.  In fact
    at that point they should both hold the same value (and I've added an
    assert to that effect), since we should have just popped any nested
    scopes.

M       pp_ctl.c

commit 2a98abd17c55d105475605cc01f06b4f273eccb2
Author: David Mitchell <[email protected]>
Date:   Thu Jun 25 12:05:50 2015 +0100

    SvREFCNT_inc(cv) recursive subs
    
    A CXt_SUB context frame owns 1 reference count to the CV being called,
    but only if it's the bottom-level call to that CV; recursive calls don't
    count.
    
    This commit changes it so that every CXt_SUB frame owns a reference count.
    
    This removes a lot of "if (CvDEPTH(cv) < 2)" type tests from the code and
    makes things generally simpler and less bug-prone.
    
    For ordinary (non-recursive) sub calls it will now be slightly faster, as
    it no longer has to do the CvDEPTH check on sub entry and exit; for subs
    being recursed into, it will probably be slightly slower, as although it
    no longer has to the CvDEPTH check on entry and exit, it now has to do a
    refcnt ++/-- instead.
    
    This also means that a deeply recursing sub will have a very high ref
    count; but there is no new additional danger of overflow, as sv_refcnt is
    U32 while xcv_depth is I32: so the latter will still overflow earlier
    anyway.

M       cop.h
M       pp_ctl.c
M       pp_sort.c
M       sv.c

commit e0696c4b8a44dee4d7f75e5e03ed0ccdcbb6711f
Author: David Mitchell <[email protected]>
Date:   Thu Jun 25 10:48:58 2015 +0100

    eliminate an SAVEFREESV(cv) from PUSHSUB
    
    When a CXt_SUB context is pushed, the reference count of the CV is
    increased (and is effectively owned by that context frame). It is
    decremented when the context frame is popped.
    
    There was an issue in that the POPSUB was done before the LEAVE,
    which meant that at sub exit, the sub could be freed before stuff that
    referred to that sub was done (such as lexicals being cleaned up by
    SAVEt_CLEARSV).
    
    This was fixed by perl-5.005_02-2095-gb0d9ce3, which split POPSUB
    into POPSUB and LEAVESUB with the latter responsible for the decrement.
    So for example code might do POPSUB; LEAVE; LEAVSUB.
    
    However this wasn't sufficient, because a similar thing happened during
    die, for example
    
        sub d {die}
        my $f;
        $f = sub {my $x=1; $f = 0; d};
        eval{ $f->() };
    
    since all *all* the CXt_SUB contexts were popped with POPSUB/LEAVSUB
    *before* LEAVE was called.
    
    I fixed this with perl-5.8.0-3206-gb36bdec, by adding another increment to
    the CV and doing a SAVEFREESV(cv), both in PUSHSUB. This meant that
    the save stack would hold at least one reference to the CV while being
    unwound.
    
    However, v5.19.3-139-g2537512 then changed things so that POPSUB also
    did a LEAVE. This means that now, die unwinds the context stack and the
    save stack in lockstep, so my second fix is now redundant. So this commit
    undoes it, saving an rc++/-- and SAVEFREE(cv) per sub call.

M       cop.h
-----------------------------------------------------------------------

--
Perl5 Master Repository

Reply via email to