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

<http://perl5.git.perl.org/perl.git/commitdiff/8b0f87ff0f2384e87c8fdccbf2dc26349154cc03?hp=0000000000000000000000000000000000000000>

        at  8b0f87ff0f2384e87c8fdccbf2dc26349154cc03 (commit)

- Log -----------------------------------------------------------------
commit 8b0f87ff0f2384e87c8fdccbf2dc26349154cc03
Author: David Mitchell <[email protected]>
Date:   Fri Jun 12 09:56:16 2015 +0100

    optimise Perl_block_gimme()
    
    Check for the reasonably common case of the current top context being a
    CXt_SUB and if so skip calling dopoptosub(). Also, the switch statement
    was fairly pointless, as it was just a bunch of
    
        case G_VOID:
           return G_VOID;
    
    so replace the switch with a simple "croak if 0, otherwise return the
    value".

M       pp_ctl.c

commit 7c6ec93848736e50e650593de168975bc2449aa8
Author: David Mitchell <[email protected]>
Date:   Thu Jun 11 11:11:19 2015 +0100

    pp_return: optimise a couple of conditions
    
    Change:
    
        if (cxix < 0) {
            A; return;
        }
        if (cxix < cxstack_ix)
            B;
    
    to
    
        if (cxix < cxstack_ix) {
            if (cxix < 0) {
                A; return;
            }
            B;
        }
    
    This is functionally the same, since cxstack_ix is always positive at
    this point, and makes for a quicker code path (one less test and branch)
    in the reasonably common case of a return from a sub which doesn't
    have any extra nested contexts to pop.

M       pp_ctl.c

commit 5543abd0010e3142343605b8d83e837a7247914f
Author: David Mitchell <[email protected]>
Date:   Thu Jun 11 11:05:50 2015 +0100

    pp_return: reindent
    
    Re-indent a code block that got stranded after the previous commit.
    Whitespace-only change.

M       pp_ctl.c

commit 788093efaf901734395642dff19a79eaf0fb714f
Author: David Mitchell <[email protected]>
Date:   Thu Jun 11 10:54:12 2015 +0100

    pp_return(): tail call pp_leavewrite()
    
    When 'return'ing from a format, rather than handling it ourselves, fall
    through to pp_leavewrite(). pp_return() is now only responsible for
    popping any extra contexts and junk from the stack.
    
    With this commit, *all* types of return are now handled by tail-calling
    the appropriate pp_leaveFOO() function, so this commit also cuts out big
    chunks of dead code.
    
    Note that the behaviour on using 'return' in a format is completely
    undocumented, and almost completely untested. In fact there is only a
    single format in the test suite that does a return, and the tests which
    use that are mainly there to ensure that extra stuff on the stack doesn't
    leak into the value(s) returned by write().
    
    In particular, its not clear whether a return half-way through a format
    should cause the lines processed so far to be output, or to be discarded;
    currently it discards. Also, its not clear what (if anything) should be
    done with any args to the 'return' call. Currently they're just discarded.
    Also, the format in the test suite which does a return only does a
    'return;', not a 'return x,y,z'. So that's still untested.
    
    So I decided to keep the current behaviour of return in format as close
    as possible rather than trying to change of fix anything.

M       pp_ctl.c
M       pp_sys.c

commit 4ff56480ce8f2ff9b648b9affb14d03759e7f6e3
Author: David Mitchell <[email protected]>
Date:   Thu Jun 11 10:30:48 2015 +0100

    pp_return(): tail call pp_leaveeval()
    
    When 'return'ing from an eval STRING, rather than handling it
    ourselves, fall through to pp_leaveeval(). pp_return() is now only
    responsible for popping any extra contexts and junk from the stack.
    
    This helps avoid two different blocks of code doing roughly the same
    thing.
    
    The functional changes caused by this commit signify the divergence over
    time between pp_leaveeval and the try-ish parts of pp_return. After this
    commit, a return will:
    
        * now do an PERL_ASYNC_CHECK();
        * be smarter about not unnecessarily creating mortal copies
          of returned args;
        * restore PL_curpm *before* the LEAVE() rather than after.
    
    The first two are probably good things; I'm not sure about the latter; it
    may well be a regression, but nothing tests for it. At least it's
    consistent now.

M       pp_ctl.c

commit e75b6d9c85e3524559e16c9017d1161c4f3a6e26
Author: David Mitchell <[email protected]>
Date:   Thu Jun 11 10:06:02 2015 +0100

    pp_return: set eval CV depth to 0
    
    In pp_leaveval, the CvDEPTH of the eval is set to 0. This doesn't
    seem to be actually necessary (no tests fail if its removed),
    but for consistency, add the same step to pp_return, which currently
    doesn't do this. This is so that shortly we can make pp_return tail call
    pp_leaveval.

M       pp_ctl.c

commit 46b9154d90629779608548cd5264e45eff034e24
Author: David Mitchell <[email protected]>
Date:   Thu Jun 11 09:57:43 2015 +0100

    pp_return: move 'die on require fail' later
    
    In pp_leaveeval the test to die on require not returning a true value
    is done late, after the return args have been processed, while in
    pp_return it is checked *before* the args are processed. Move the test in
    pp_return to after the args to make it more like pp_leaveeval. This is a
    preparatory step in making pp_return eventually tail call pp_leaveeval.
    
    It probably doesn't make any difference whether it's done early or late
    (although arguably dying early is infinitesimally more efficient); but
    since pp_leaveeval is going to be overwhelmingly a more common way of
    returning from a require than pp_return, its seems prudent to to not mess
    with the most widely used code path.

M       pp_ctl.c

commit 5ae489fa915f11837ade9bd93dd31b67cd84e685
Author: David Mitchell <[email protected]>
Date:   Tue Jun 9 17:11:06 2015 +0100

    pp_leaveeval: use EVAL_KEEPERR
    
    In order shortly to allow pp_return to tail call pp_leaveval,
    make pp_leaveval use the EVAL_KEEPERR flag bit of PL_in_eval
    to decide whether to call CLEAR_ERRSV() rather than testing the
    OPf_SPECIAL flag bit on the OP_LEAVEEVAL op (since we may no longer be
    that op).
    
    The two are equivalent (I checked this by running test test suite with
    an assert that they were the same).
    
    Note that pp_return already uses the EVAL_KEEPERR flag test, so this
    commit makes the pp_return and pp_leavesub code blocks more similar.
    
    I've also added some more tests, as I initially got the logic of this
    wrong, and no core tests failed - only cpan/ ones.  In particular, no core
    tests checked whether eval-string actually cleared $@ on success!

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

commit c141acae122bf928a338302d115261283d81ea1d
Author: David Mitchell <[email protected]>
Date:   Wed Jun 10 16:20:00 2015 +0100

    XS-APItest/t/call.t: make loops more flexible
    
    There's a loop which tests eval_pv, eval_sv, call_sv with various
    types of argument. Currently the argument is determined by an integer
    in a loop (0..3) with various values derived on an ad-hoc basis
    from that index. Instead put all the data into an array of arrays
    and iterate over that instead.
    
    Similarly for the function names (eval_pv et al), loop over the names
    rather than over 0..2.
    
    This should make no functional change to what is tested, but makes the
    test code clearer and more expandable.

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

commit dd63e08eadf0d2fc44937a14aa176d3ff0c9501b
Author: David Mitchell <[email protected]>
Date:   Tue Jun 9 15:48:15 2015 +0100

    pp_return(): tail call pp_leavetry()
    
    When 'return'ing from an eval { BLOCK }, rather than handling it
    ourselves, fall through to pp_leavetry(). pp_return() is now only
    responsible for popping any extra contexts and junk from the stack.
    
    This helps avoid two different blocks of code doing roughly the same
    thing.
    
    The functional changes caused by this commit signify the divergence over
    time between pp_leavetry and the try-ish parts of pp_return. After this
    commit, a return will:
    
        * now do an PERL_ASYNC_CHECK();
        * be smarter about not unnecessarily creating mortal copies
          of returned args;
        * restore PL_curpm *before* the LEAVE() rather than after.
    
    The first two are probably good things; I'm not sure about the latter; it
    may well be a regression, but nothing tests for it. At least it's
    consistent now.

M       pp_ctl.c

commit cd3c8faa081c9a6413820fe064147709e843a5cb
Author: David Mitchell <[email protected]>
Date:   Tue Jun 9 11:17:44 2015 +0100

    make MULTICALL handle list context
    
    Currently in something like
    
        for (1,2) { return 3,4 }
    
    the user of MULTICALL will see 1,2,3,4 returned, because in pp_return,
    MULTICALL is handled as a special case, and that special-case code doesn't
    handle list context.
    
    A simple fix is just to remove the special handling in pp_return.
    Allow a MULTICALL return to pass through the normal pp_return stack
    manging code, then tail call pp_leavesub or pp_leavesublv as approriate.
    Both those subs do an immeidate 'return 0' if CxMULTICALL().
    
    As well as fixing list context MULTICALL, it removes one extra condition
    in the path of a normal return.

M       ext/XS-APItest/APItest.pm
M       ext/XS-APItest/APItest.xs
M       ext/XS-APItest/t/multicall.t
M       pp_ctl.c
M       pp_hot.c

commit e47e915f5ff01f131717809277cc6bc026df2c43
Author: David Mitchell <[email protected]>
Date:   Tue Jun 9 10:59:52 2015 +0100

    eliminate S_return_lvalues()
    
    After the previous commit, pp_leavesublv was just an empty wrapper
    around S_return_lvalues() (which is also called from pp_return).
    
    So just rename S_return_lvalues to pp_leavesublv, and make pp_return
    call pp_leavesublv directly.

M       pp_ctl.c

commit 95fa619b2d093b208b06b161859e87a93db242ce
Author: David Mitchell <[email protected]>
Date:   Tue Jun 9 10:51:15 2015 +0100

    move multicall check to S_return_lvalues
    
    Currently pp_leavesublv has a check at the top:
    
        if (CxMULTICALL(&cxstack[cxstack_ix]))
           return 0;
    
    Move this instead into S_return_lvalues(), which pp_leavesublv immediately
    calls. This has no effect on the pp_leavesublv code path, and also
    has no effect on the pp_return code path, because although pp_return
    calls S_return_lvalues, it doesn't in the case of MULTICALL, which it has
    already checked for earlier.
    
    So it shouldn't change anything functionally.
    
    This will allow us to eliminate S_return_lvalues in the next commit.

M       pp_ctl.c

commit 485596200417f49493c0cec02459135e9ace83cd
Author: David Mitchell <[email protected]>
Date:   Tue Jun 9 10:46:17 2015 +0100

    reindent code block in pp_return
    
    Just a whitespace change.

M       pp_ctl.c

commit fab0a99d7daa442273b09459c96081db4b8f22b4
Author: David Mitchell <[email protected]>
Date:   Tue Jun 9 10:31:10 2015 +0100

    Simplify S_return_lvalues()
    
    S_return_lvalues() was written to handle both pp_leavesublv and pp_return;
    in the latter case there could be junk on the stack that needs skipping;
    e.g.
    
        for (1,2) { return 3,4 }
    
    leaves 1,2,3,4 on the stack, and in list context the 3,4 needs shifting
    down two places. After the previous commit, any return-specific processing
    is now handled by pp_return itself, so S_return_lvalues only has to
    worry about mortalising its args and grabbing the last arg in scalar
    context.
    
    Formerly there were two vars: newsp, which pointed to the slot before the
    '1', and MARK, which pointed to the slot before the '3'. They now both
    point to just before the '1'. So we only need to use one of them. Here
    I've standardised on MARK, to make the code as similar as possible to that
    in pp_leavesub, from which this code was forked back in 1999. For the same
    reason I've set MARK to point to the '1' slot rather than the slot before
    it, since that's what pp_leavesub does.

M       pp_ctl.c

commit 8d47dcccf0d44a03661b95dda134f7d5d6589699
Author: David Mitchell <[email protected]>
Date:   Tue Jun 9 08:23:18 2015 +0100

    lval subs: do arg shifting in pp_return
    
    When an lvalue sub does an explicit return, currently pp_return
    doesn't touch the args stack and instead tail calls S_return_lvalues()
    which does both the leavesuby stuff (e.g. mortalise args) and the returny
    stuff (e.g. shift the args down in list context).
    
    Move the call to S_return_lvalues() further down in pp_return so that
    the arg shifty stuff is done in pp_return now (like it is for non-lvalue
    returns). This will allow us shortly to simply S_return_lvalues.

M       pp_ctl.c

commit 6560f75b4e75052d9bbce43a4c063196e5881ebc
Author: David Mitchell <[email protected]>
Date:   Mon Jun 8 18:46:50 2015 +0100

    pp_return: simplify arg handling code
    
    pp_return() only needs to do the extra arg handling associated
    with the args not being at the base of the stack frame. For example
    
        for (1,2) { return 3,4 }
    
    has to cope with 1,2,3,4 being on the stack.
    Apart from handling junk, everything else  - in particular pushing
    &PL_sv_undef in scalar context if there are no return args - is already
    done by Perl_pp_leavesub, which pp_return tail calls.
    
    So reduce what pp_return does to the bare minimum. This makes one less
    conditional branch in a few cases.

M       pp_ctl.c

commit a597a25b3359ebaebbcb20687bbcb700abf81080
Author: David Mitchell <[email protected]>
Date:   Mon Jun 8 11:53:38 2015 +0100

    simplify sort sub return arg processing
    
    This commit:
    
    1) makes the  gimme of sort blocks, as specified by the pushed cx_gimme,
    be G_SCALAR. Formerly it was likely to be G_ARRAY, as it inherited
    whatever sort() was called as, and sort doesn't bother calling a sort
    block unless sort was called in list context.
    
    This change is largely cosmetic, as
        a) the sort block is already compiled in scalar context; and
        b) the code in S_sortcv() etc does its own return arg context
           processing anyway, and assumes scalar context.
    But it makes it consistent with sort SUB, which *does* set gimme to
    G_SCALAR.
    
    2) Makes use of the fact that a sort sub or block will always be
    called as the first context in a new stackinfo, and such stackinfos always
    have PL_stack_base[0] set to &PL_sv_undef as a guard.
    So handling scalar context return (where zero args returned needs to be
    converted into 1 PL_sv_undef arg) can be simplified by just always
    accessing the last arg, *PL_stack_sp, regardless of whether 0,1,2+ args
    were returned.
    Note that some code making use of MULTICALL (e.g. List::Util) has already
    been (possibly inadvertently) relying on this fact.
    
    3) Remove the "Sort subroutine didn't return single value" fatal error.
    This croak was removed from the sort BLOCK and sort NON-XS-SUB variants
    in v5.15.5-82-g1715fa6, but the croak was left for XS sort subs.
    That commit incorrectly asserted that for "sort BLOCK" and "sort
    NON-XS-SUB", more than 1 arg could never be returned, but:
    
        $ perl -e'sub f { return (1,2) } @a = sort f 1,2,3'
        perl: pp_sort.c:1789: S_sortcv: Assertion `PL_stack_sp ==
            PL_stack_base' failed.
    
    That has been fixed by (2) above. By removing the croak from the XS branch
    too, we make things consistent. This means that an XS sub which returns
    more than 1 arg will just gets its return args be evaluated in scalar
    context (so @return_args[-1] will be used), rather than being handled
    specially.

M       pod/perldiag.pod
M       pp_ctl.c
M       pp_sort.c
M       t/op/sort.t

commit 4ead544c85db3a4218bea3f29af2b0cea8ddbe3d
Author: David Mitchell <[email protected]>
Date:   Tue Jun 2 14:59:46 2015 +0100

    sort fns: simplify handing uninit warnings
    
    When a sort function or code block returns an undef value (rather than the
    typical -1,0,-1), you get the usual "Use of uninitialized value" warning.
    
    Originally the message didn't say " ... in sort" because at the end of
    running a sort sub, PL_op is NULL rather rather than pointing at the sort
    op.
    
    v5.15.3-364-gd4c6760 changed the sort sub return code in S_sortcv() et al
    to temporarily set PL_op to point to the sort OP, which made
    Perl_report_uninit() emit the desired " in sort" suffix.
    
    However, this meant that PL_op and PL_curpad briefly referenced two
    different CVs; since Perl_report_uninit() rummages around in pads looking
    for lexicals, consts etc, this could lead to SEGVs.
    
    v5.15.3-372-g1aa032b fixed that by temporarily setting PL_curpad to NULL
    at the same time. However that then caused problems if the code dies
    (e.g. if warnings are upgraded to errors) since the old PL_curpad value
    wasn't being restored.
    
    v5.17.6-7-g2f43ddf fixed that by wrapping the PL_curpad=NULL with
    appropriate ENTER/SAVEVPTR(PL_curpad)/..../LEAVE where necessary.
    
    However, this is starting to get quite complex, and in a hot piece of
    code, and the 3 sort functions S_sortcv/S_sortcv_stacked/S_sortcv_xsub
    are all diverging from each other in subtle and confusing ways.
    
    This commit takes a different approach. It effectively reverts those three
    commits (apart from the tests) and instead updates Perl_report_uninit()
    to say "if PL_op is NULL, but the context stack indicates that we're
    currently in a sort, then append " in sort" to the warning.
    
    This is a lot less messy, and moves all the clutter from the two hot
    functions S_sortcv/S_sortcv_stacked into a function that is only called
    when we're emitting warnings.

M       pp_sort.c
M       sv.c

commit 9a57f6bd3d64868f9e5d02f74813f9d23a16e1b5
Author: David Mitchell <[email protected]>
Date:   Tue Jun 2 13:50:06 2015 +0100

    Perl_report_uninit(): simplify code
    
    Simplify the code in this function a bit.
    It should have no functional effect, but will make the next commit
    easier.

M       sv.c

commit 1876fdc16604a8489bd91609bbcaf419c0e72323
Author: David Mitchell <[email protected]>
Date:   Tue Jun 2 11:51:44 2015 +0100

    add PERLSI_MULTICALL
    
    Currently when MULTICALL pushes a new stackinfo, it uses the si_type
    PERLSI_SORT. This is probably just a hangover from when the MULTICALL code
    was created from similar code used to implement sort.
    
    Change it to use the new PERLSI_MULTICALL si_type.
    
    The si_type value is mainly used for debugging/dumping purposes,
    apart from a few places where we check for whether this is
    the top stack (PERLSI_MAIN); or check for a sort BLOCK (cxix = 0,
    CXt_NULL, PERLSI_SORT).
    
    So this commit should have no immediate effect. It will in future
    however allow us to detect whether we have a sort or a true MULTICALL.

M       cop.h
M       deb.c

commit 0cdbcf9959ae661efa9b23219736e7435098413c
Author: David Mitchell <[email protected]>
Date:   Sun May 24 16:53:05 2015 +0100

    S_return_lvalues(): merge two similar blocks
    
    Two blocks of error-reporting code both clean up the context state and
    then croak with a similar message. Make the second block just goto the
    first block instead.

M       pp_ctl.c

commit df37bbaf3154ff9e645921b5a08faa27e1f3def6
Author: David Mitchell <[email protected]>
Date:   Sun May 24 16:42:29 2015 +0100

    S_return_lvalues(): consistent cxstack_ix--
    
    After merging in the functionality from pp_leavesublv and pp_return
    into S_return_lvalues(), there were two context stack pointer decrement
    conventions: before or after the POPSUB(). Both are wrong in different
    ways, and will be more generally fixed up in later commits. For now,
    standardise on a single form: that used by pp_leavesub and pp_leavesublv.

M       pp_ctl.c

commit 1fe87bb36d62b3392bea793016f3b23cb4e41ece
Author: David Mitchell <[email protected]>
Date:   Sun May 24 09:53:37 2015 +0100

    pp_return: re-indent after last commit
    
    whitespace-only change.

M       pp_ctl.c

commit e6383bc2a7383e5de775502e3ce24618d5cc7022
Author: David Mitchell <[email protected]>
Date:   Sun May 24 09:48:53 2015 +0100

    handle most of lvalue return in single place
    
    Currently about half the work involved in returning from an lvalue sub
    call is done by the shared sub S_return_lvalues() function, while the
    other half is duplicated in pp_leavesublv() and pp_return(). Move most of
    that duplicated code into S_return_lvalues().

M       pp_ctl.c

commit cf3dd2ae3579fb7d71c72705ec0e7f9f95e6fb42
Author: David Mitchell <[email protected]>
Date:   Sat May 23 11:12:18 2015 +0100

    pp_return: tail call pp_leavesub
    
    For returns within normal (rvalue) subs, handle the bulk of of the work by
    falling through into pp_leavesub, rather than repeating most of the code.
    So pp_return is now just responsible for popping any extra contexts and
    shifting any return args back down to the base of the stack.
    
    Return in lvalue subs, evals etc is unaffected.

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

commit c019abd52a89c71437493ffc76e2170b1f8925f2
Author: David Mitchell <[email protected]>
Date:   Sat May 23 20:25:45 2015 +0100

    pp_last: only handle loop context types
    
    pp_last pops to the next relevant loop context type, or croaks.
    Yet once it does this, it attempts to handle *all* context types
    (subs, evals etc), even those which can never be the current
    context.
    
    Rip all this dead code out, and replace with an assertion that the
    context is one of the loop types.
    
    This dead code has been there since 5.000.

M       pp_ctl.c
-----------------------------------------------------------------------

--
Perl5 Master Repository

Reply via email to