In perl.git, the branch sprout/lexsub has been created

<http://perl5.git.perl.org/perl.git/commitdiff/7efff9aefc573bf6be876992b871316bccafba75?hp=0000000000000000000000000000000000000000>

        at  7efff9aefc573bf6be876992b871316bccafba75 (commit)

- Log -----------------------------------------------------------------
commit 7efff9aefc573bf6be876992b871316bccafba75
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Mon Sep 10 23:09:53 2012 -0700

    Disable lexsubs outside of experimental.pm

M       lib/experimental.pm
M       lib/experimental.t
M       perl.h
M       pod/perldiag.pod
M       t/cmd/lexsub.t
M       toke.c

commit 94b00de9d04327c3b5b4de49efa146e25a8a6d99
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Mon Sep 10 22:59:53 2012 -0700

    experimental.pm

M       MANIFEST
M       Porting/Maintainers.pl
A       lib/experimental.pm
A       lib/experimental.t

commit 9cfcf6f58c571443c7eb08c7511ed0eda3aa3d4d
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Mon Sep 10 22:29:15 2012 -0700

    Allow lexical sub redefinition inside eval
    
    For non-clonable state subs, this already happened to work.
    
    For any clonable subs, we need to clone the sub as soon as it
    is defined.
    
    For redefined state subs, we need to apply the new sub to all recur-
    sion levels, as state subs are shared.

M       op.c
M       t/cmd/lexsub.t

commit ee646751817d9798ece3a4335493913f5404e28d
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Mon Sep 10 21:59:51 2012 -0700

    Move my sub prototype CVs to the pad names
    
    my subs are cloned on scope entry.  To make closures work, a stub
    stored in the pad (and closed over elsewhere) is cloned into.
    
    But we need somewhere to store the prototype from which the clone is
    made.  I was attaching the prototype via magic to the stub in the pad,
    since the pad is available at run time, but not the pad names.
    
    That leads to lots of little games all over the place to make sure
    the prototype isn’t lost when the pad is swiped on scope exit
    (SAVEt_CLEARSV in scope.c).  We also run the risk of losing it if an
    XS module replaces the sub with another.
    
    Instead, we should be storing it with the pad name.  The previous com-
    mit made the pad names available at run time, so we can move it there
    (still stuffed inside a magic box) and delete much code.
    
    This does mean that newMYSUB cannot rely on the behaviour of non-clon-
    able subs that close over variables (or subs) immediately.  Previ-
    ously, we would dig through outer scopes to find the stub in cases
    like this:
    
        sub y {
            my sub foo;
            sub x {
                sub {
                    sub foo { ... }
                }
            }
        }
    
    We would stop at x, which happens to have y’s stub in its pad, so
    that’s no problem.
    
    If we attach it to the pad name, we definitely have to dig past x to
    get to the pad name in y’s pad.
    
    Usually, immediate closures do not store the parent pad index, since
    it will never be used.  But now we do need to use it, so we modify the
    code in pad.c:S_pad_findlex to set it always for my/state.

M       op.c
M       pad.c
M       pp.c
M       scope.c

commit dd0e277a8847d38fb7534a7ff72994009e86e0b4
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Mon Sep 10 16:07:30 2012 -0700

    Set PL_comppad_name on sub entry
    
    This will allow future commits to access it at run time.

M       pad.h
M       scope.c
M       scope.h

commit 5262aedbd61e73a64d7d22fde3324a8b50bcf955
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Sun Sep 9 11:09:53 2012 -0700

    lexsub.t: Test state sub defined inside eval

M       t/cmd/lexsub.t

commit 6a5f86c3c1a9d00f65401d7f41c4a230b9925bd5
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Sat Sep 8 19:28:00 2012 -0700

    Honour lexical prototypes
    
    newCVREF is changed to return a PADCV op, not an RV2CV with a PADCV
    kid, to keep the rv2cv_op_cv changes to a minimum.  (For some reason,
    if newCVREF returns an RV2CV, we end up with two inside each other.)
    
    I also added a test for recursion, since I nearly broke it.

M       op.c
M       t/cmd/lexsub.t

commit de1e2f50cb6d06718b4e2ba6b687dc21c39533db
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Thu Sep 6 22:57:50 2012 -0700

    Don’t mention pkg in proto warnings for lex subs

M       t/lib/warnings/toke
M       toke.c

commit ed2edeacf2e3105a91062533db7891efe6d070b1
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Thu Sep 6 22:11:36 2012 -0700

    pad.c: Put unavailability warning in one spot

M       pad.c

commit 267306000b03b8ab8c2c8175767ff911b8d2553b
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Thu Sep 6 20:32:47 2012 -0700

    Use the same outside logic for mysubs and formats
    
    By using find_runcv_where both for formats and my subs nested in inner
    clonable subs, we can simplify the code.
    
    It happens to make this work ($x is visible):
    
    use 5.01;
    sub not_lexical8 {
      my sub foo;
      foo();
      sub not_lexical9 {
        my sub bar {
          my $x = 'khaki car keys for the khaki car';
          not_lexical8();
          sub foo { warn $x }
        }
        bar()
      }
    }
    not_lexical9();
    
    This is definitely iffy code, but if making it work makes the imple-
    mentation simpler, so why not?

M       pad.c
M       t/cmd/lexsub.t

commit 58031fd37133ce194f8f163806649da72bced1b8
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Thu Sep 6 18:05:35 2012 -0700

    Fix subroutine unavailability during cloning
    
    sub foo {
      my $x;
      format =
    @
    $x||'#'
    .
    }
    write;
    __END__
    Variable "$x" is not available at - line 9.
    
    That one’s OK.
    
    sub foo {
      my sub x {};
      format =
    @
    &x
    .
    }
    write;
    __END__
    Variable "&x" is not available at - line 9.
    Assertion failed: (SvTYPE(_svmagic) >= SVt_PVMG), function 
S_mg_findext_flags, file mg.c, line 404.
    Abort trap
    
    That should say ‘Subroutine’.  And it shouldn’t crash.
    
    The my-sub-cloning code was not taking this case into account.  The
    value in the proto pad is an undef scalar.

M       pad.c
M       t/cmd/lexsub.t

commit f992c62bd7a14139f0536a38601fa68d65b7797a
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Thu Sep 6 16:03:20 2012 -0700

    ‘Subroutine "&x" is not available’ during compilation
    
    sub {
      my $x;
      sub { eval '$x' }
    }->()()
    __END__
    Variable "$x" is not available at (eval 1) line 2.
    
    That one’s OK (though I wonder about the line number).
    
    sub {
      my sub x {};
      sub { eval '\&x' }
    }->()()
    __END__
    Variable "&x" is not available at (eval 1) line 1.
    
    That should say ‘Subroutine’.

M       pad.c
M       pod/perldiag.pod
M       t/cmd/lexsub.t
M       t/porting/diag.t

commit a4939974627523b11e3798853251045a1a00babb
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Tue Sep 4 10:24:57 2012 -0700

    In cv_clone, use pad ID to identify mysub outside
    
    This code prints ARRAY(0x802e10), whereas it should print
    SCALAR(0xfedbee):
    
    undef &bar;
    eval 'sub bar { my @x }';
    {
      my sub foo;
      foo();
      sub bar {
        CORE::state $x;
        sub foo { warn \$x }
      }
    }
    
    The foo sub has a strong CvOUTSIDE pointer, but what it points to
    can still be undefined and redefined.  So we need to identify it
    by its pad.

M       pad.c
M       t/cmd/lexsub.t

commit cf8cc759ca5eb9e0a29b2070dc39165260111034
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Mon Sep 3 21:26:37 2012 -0700

    CvOUTSIDE should be strong for lexsub declared in inner pack sub
    
    PadnameOUTER (SvFAKE) entries in pads of clonable subs contain the
    offset in the parent pad where the closed-over entry is to be found.
    The pad itself does not reference the outer lexical until the sub is
    cloned at run time.
    
    newMYSUB had to account for that by following CvOUTSIDE for
    PadnameOUTER entries, to account for cases like this:
    
        my sub foo;
        my sub bar { sub foo {} }
    
    The sub foo{} definition would have to find the my sub foo declaration
    from outside and store the sub there.
    
    That code was not accounting for named package subs, which close over
    variables at compile time, so they don’t need (and don’t) store a par-
    ent offset.
    
    So outcv would point to bar in this case:
    
        my sub foo;
        sub bar { sub foo {} }
    
    If outcv matched CvOUTSIDE(foo), then CvOUTSIDE was made weak.
    
    That does not help in cases like this:
    
        undef *bar;
        {
            my sub foo;
            sub bar { sub foo {} }
        }
    
    If foo has a weak CvOUTSIDE pointer, then it will still point to bar
    after bar is freed, which does not help when the sub is cloned and
    tries to look at CvROOT(CvOUTSIDE).
    
    If the pad name is marked PadnameOUTER, even if it has no parent pad
    index, newMYSUB needs to leave the CvOUTSIDE pointer strongc.
    
    Also, pad_fixup_inner_anons did not account for subs with strong
    CvOUTSIDE pointers whose CvOUTSIDE point to the sub whose pad is being
    iterated through.

M       op.c
M       pad.c
M       t/cmd/lexsub.t

commit 1dc5c26b1f7bbf703c49763b181a2a35ec25dca7
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Tue Aug 14 18:10:40 2012 -0700

    Use the right outside for my subs defined in inner subs
    
    In this example,
    
    {
      my sub foo;
      sub bar {
        sub foo { }
      }
    }
    
    the foo sub is cloned when the scope containing the ‘my sub’ declara-
    tion is entered, but foo’s CvOUTSIDE pointer points to something other
    than the active sub.  cv_clone assumes that the currently-running sub
    is the right sub to close over (at least for subs; formats are another
    matter).  That was true in the absence of my subs.  This commit
    changes it to account.
    
    I had to tweak the test, which was wrong, because sub foo was closing
    over a stale var.

M       pad.c
M       t/cmd/lexsub.t

commit cb2215007d7c6453a24e3f89cc1dc0e0eff4d586
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Tue Aug 14 12:24:43 2012 -0700

    Fix Peek.t

M       ext/Devel-Peek/t/Peek.t

commit 4694aa251e0f747577c6eab8f2c86a8c7852fab3
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Mon Aug 13 22:56:05 2012 -0700

    Preserve outside pointers of my subs with string eval
    
    The CvHASEVAL flag lets cv_clone know that the clone needs to have its
    CvOUTSIDE pointer set, for the sake of string evals’ being able to
    look up variables.
    
    It was only being set on anonymous subs.  It should be set for all
    clonable subs.  It doesn’t actually hurt to set it on all types of
    subs, whether clonable or not, since it has no effect on non-clon-
    able subs.

M       pad.c
M       t/cmd/lexsub.t

commit 2ef0a7e96fa04566b7b17d2213f5628489adf884
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Sun Aug 12 17:57:35 2012 -0700

    Fix up outside pointers for my subs
    
    I had not yet fixed Perl_pad_fixup_inner_anons to account for the
    fact that my sub prototype CVs are stored in magic attached to
    the SV slot in the pad, rather than directly in the pad.  It also
    did not like & entries that close over subs defined in outer
    or inner subs (‘my sub foo; sub bar; sub bar { &foo } }’ and
    ‘sub bar; sub bar { my sub foo; sub { sub foo { } } }’ respectively).
    
    This was resulting in assertion failures, unsurprisingly.
    
    Some of the tests I added, which were causing assertion failures, are
    now failing for other reasons, and are marked as to-do.

M       pad.c
M       t/cmd/lexsub.t

commit 0f49d0f7c3f14fd48e6d7d2eb59b0b4be26fd6f8
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Fri Aug 3 18:01:06 2012 -0700

    perly.y: Remove MYSUB
    
    This token is not used any more.

M       perly.act
M       perly.h
M       perly.tab
M       perly.y
M       toke.c

commit d47d4495e1b348af976d2fd96f3ef818ffbd9eec
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Fri Aug 3 12:41:11 2012 -0700

    CvNAME_HEK_set

M       cv.h
M       op.c
M       pad.c
M       scope.c

commit 9cc7a436a08bf24da5ae3aa2eae1b2bbcdb6d5fe
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Fri Aug 3 09:23:15 2012 -0700

    Clone my subs on scope entry
    
    The pad slot for a my sub now holds a stub with a prototype CV
    attached to it by proto magic.
    
    The prototype is cloned on scope entry.  The stub in the pad is used
    when cloning, so any code that references the sub before scope entry
    will be able to see that stub become defined, making these behave
    similarly:
    
        our $x;
        BEGIN { $x = \&foo }
        sub foo { }
    
        our $x;
        my sub foo { }
        BEGIN { $x = \&foo }
    
    Constants are currently not cloned, but that may cause bugs in
    pad_push.  I’ll have to look into that.
    
    On scope exit, lexical CVs go through leave_scope’s SAVEt_CLEARSV sec-
    tion, like lexical variables.  If the sub is referenced elsewhere, it
    is abandoned, and its proto magic is stolen and attached to a new stub
    stored in the pad.  If the sub is not referenced elsewhere, it is
    undefined via cv_undef.
    
    To clone my subs on scope entry, we create a sequence of introcv and
    clonecv ops.  See the huge comment in block_end that explains why we
    need two separate ops for each CV.
    
    To allow my subs to be defined in inner subs (my sub foo; sub { sub
    foo {} }), pad_add_name_pvn and S_pad_findlex now upgrade the entry
    for a my sub to a CV to begin with, so that fake entries added to pads
    (fake entries are those that reference outer pads) can share the same
    CV.  Otherwise newMYSUB would have to add the CV to every pad that
    closes over the ‘my sub’ declaration.  newMYSUB no longer throws away
    the initial value replacing it with a new one.
    
    Prototypes are not currently visible to sub calls at compile time,
    because the lexer sees the empty stub.  A future commit will
    solve that.
    
    When I added name heks to CV’s I made mistakes in a few places, by not
    turning on the CVf_NAMED flag, or by not clearing the field when free-
    ing the hek.  Those code paths were not exercised enough by state
    subs, so the problems did not show up till now.  So this commit fixes
    those, too.
    
    One of the tests in lexsub.t, involving foreach loops, was incorrect,
    and has been fixed.  Another test has been added to the end for a par-
    ticular case of state subs closing over my subs that I broke when ini-
    tially trying to get sibling my subs to close over each other, before
    I had separate introcv and clonecv ops.

M       embed.fnc
M       embed.h
M       op.c
M       pad.c
M       perly.act
M       perly.h
M       perly.tab
M       perly.y
M       pp.c
M       proto.h
M       scope.c
M       t/cmd/lexsub.t

commit 28a36b2b60e370851e9f2dbec33426c4f3538570
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Fri Aug 3 09:29:38 2012 -0700

    cv_clone: panic for no pad
    
    cv_clone has serendipitously gained the ability to clone CVs without
    pads.  It is not clear that we want to add this ability to this API
    function, because we would be stuck supporting it, even if we came up
    with a better interface.  It used to crash or fail an assertion if
    there was no pad.

M       pad.c

commit d602f700025273012e92cbb0dabcf85179b23070
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Thu Aug 2 13:45:31 2012 -0700

    pad.c: Let S_cv_clone clone stubs
    
    This will be used by cv_clone_into (which does not exist yet) in a
    later commit.  pp_clonecv will use cv_clone_into.
    
    Teasing out the pad-related and non-pad-related parts of cv_clone
    was the easiest way to do this.  Now the pad stuff is in a separate
    function.

M       pad.c

commit c8ab718f7f085a47ee39c71791a5e7a5478b7a93
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Sun Jul 29 18:47:48 2012 -0700

    op.c: Remove proto storage optimisation for lex subs
    
    It was already #if 0’d out.  This optimisation, copied from package
    subs, only makes sense when there is autoloading, which lexical subs
    don’t do.  Hence, lexical stubs will be rare indeed, so having an
    optimisation for those just creates more nooks to hide bugs.

M       op.c

commit 78aec44bfffad63f3dd2ca1af2dead74c8dfac97
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Thu Aug 2 22:11:08 2012 -0700

    Add clonecv op type
    
    This will be used for cloning a ‘my’ sub on scope entry.
    I was going to use pp_padcv for this, but it would end up having a
    top-level if/else.

M       ext/Opcode/Opcode.pm
M       opcode.h
M       opnames.h
M       pp.c
M       pp_proto.h
M       regen/opcode.pl
M       regen/opcodes

commit 1ac1ceb792b04947eaaa3e3913e705a0d3325cc8
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Thu Jul 26 18:21:02 2012 -0700

    Add introcv op type
    
    This will be used for introducing ‘my’ subs on scope entry, by turning
    off the stale flag.

M       ext/Opcode/Opcode.pm
M       opcode.h
M       opnames.h
M       pp.c
M       pp_proto.h
M       regen/opcode.pl
M       regen/opcodes

commit 2ea254d3e94e16696af47dcbdf232d696e0fad5d
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Thu Jul 26 12:38:14 2012 -0700

    Let state sub fwd decls and nested subs work in anons
    
    I had this working:
    
    state sub foo;
    sub other {
        sub foo { # defines the state sub declared outside
            ...
        }
    }
    
    But it failed inside an anonymous subroutine:
    
    sub {
        state sub foo;
        sub other {
            sub foo { # defines the state sub declared outside
                ...
            }
        }
    }
    
    When an anonymous (or otherwise clonable) sub is cloned, any state
    vars, and, likewise, any state subs, inside it are cloned, too.
    
    In the first example above the state sub forward declaration creates
    a subroutine stub.  The ‘other’ sub’s ‘sub foo’ declaration 
creates a
    pad entry in other’s pad that closes over the outer foo immediately,
    so the same stub is visible in two pads.  The sub foo {} declaration
    uses that stub.
    
    When the outer sub containing the forward declaration is clonable,
    the pad entry is not closed over immediately at compile time, because
    the pad entry is just a prototype, not the actual value that will be
    shared by the clone and its nested subs.  So the inner pad entry does
    not contain the sub.
    
    So the actual creation of the sub, if it only looks at the inner
    pad (other’s pad), will not see the stub, and will not attach a
    body to it.
    
    This was the result:
    
    $ ./miniperl -e 'CORE::state sub foo; CORE::state sub bar { sub foo {warn 
called} }; foo()'
    called at -e line 1.
    $ ./miniperl -e 'sub { CORE::state sub foo; CORE::state sub bar { sub foo 
{warn called} }; foo() }->()'
    Undefined subroutine &foo called at -e line 1.
    
    This commit fixes that by having newMYSUB follow the CvOUTSIDE chain
    to find the original pad entry where it defines the sub, if the for-
    ward declaration is occurs outside and has not been closed over yet.

M       op.c
M       t/cmd/lexsub.t

commit b330fc52a68ae30d44168f9ffd0027610596db1b
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Thu Jul 12 23:31:52 2012 -0700

    Add proto magic type
    
    This will be used for storing the prototype CV of a ‘my’ sub.  The
    clone needs to occupy the pad entry so that padcv ops will be able to
    find it.  That means the clone has to displace its prototype.  In case
    the same sub is called recursively, we still need to be able to access
    the prototype.

M       mg_names.c
M       mg_raw.h
M       mg_vtable.h
M       pod/perlguts.pod
M       regen/mg_vtable.pl

commit 3e31e6b5649e957505fa69c569e795d3eb4790d4
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Tue Jul 10 20:18:48 2012 -0700

    First stab at my sub
    
    This does just enough to get things to compile.
    
    They currently do weird things in edge cases, including ‘Bizarre
    copy of CODE’.
    
    ‘my sub’ now produces a SUB token, and goes through the same grammar
    rule as ‘state sub’ and just plain ‘sub’.  The separate MYSUB branch
    of the barestmt rule will go soon, as it is now unused.

M       op.c
M       t/cmd/lexsub.t
M       t/lib/croak/op
M       toke.c

commit 81726e862ddef63a83f44cc9ddace9961acb8a91
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Mon Jul 9 22:25:24 2012 -0700

    op.c:newMYSUB: Pop scope after creating sub
    
    I was popping the scope before creating the sub in order to expose the
    parent pad, where the new sub is to be stored.
    
    That can cause problems, since ops may still be created that get
    attached to the new sub.  Those ops will end up using the parent sub’s
    slab in that case.  If the parent sub does not finish compiling, due
    to an error, it may clean out its slab, freeing ops that the inner sub
    is using, so the inner sub, when freed, will try to free ops that are
    no longer in allocated memory, as the slab is gone.  Most of the time,
    the inner ops won’t have been reused for anything, so the op type will
    still be OP_FREED, and op_free will do nothing (except a single bad
    read).  But debugging builds detect that and fail an assertion.
    
    Popping the scope afterwards actually does simplify things, surpris-
    ingly enough.
    
    I was able to produce this bug with a one-liner, but it did not fail
    as part of the test suite.  So this fix includes no test.
    
    Since the o variable in newMYSUB is a padop, it can only be freed when
    its pad is active.  It is created before the sub, so it cannot be
    freed until the scope has been popped, so it has to go at the bot-
    tom.  If an error occurs during newMYSUB, opslab_force_free will take
    care of it.

M       op.c

commit e85e4129481c4f7643cb273b9bbfbb4a5803e32a
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Mon Jul 9 18:02:33 2012 -0700

    dump.c: Dump CvNAME_HEK

M       dump.c

commit d09f95bbec75d943a31b4b3445f72c481dcf4fae
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Mon Jul 9 13:00:28 2012 -0700

    Remove & from redef warnings for lex subs
    
    I started to write this, creating a special SV to hold the name with-
    out the ampersand, but then never used that SV.
    
    This is just for consistency with package subs.
    
    I also made this slightly more efficient when warnings are off.

M       op.c
M       t/cmd/lexsub.t

commit bfafb6338b5e93a5e4ec1fee7e8e4ba148f6614e
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Mon Jul 9 12:52:48 2012 -0700

    lexsub.t: Fix another test
    
    The problem with writing to-do tests is that it is very easy to get
    the tests wrong, such that they continue to fail even when the prob-
    lems they test for are fixed.

M       t/cmd/lexsub.t

commit 9930d3d0eda616476996791cd0561fab0e2d5f9c
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Mon Jul 9 06:29:09 2012 -0700

    Clone state subs in anon subs
    
    Since state variables are not shared between closures, but only
    between invocations of the same closure, state subs should behave
    the same way.
    
    This was a little tricky.  When we clone a sub, we now clone inner
    state subs at the same time.  When walking through the pad, cloning
    items, we cannot simply clone the inner sub when we see it, because it
    may close over things we haven’t cloned yet:
    
        sub {
            state sub foo;
            my $x
            sub foo { $x }
        }
    
    We can’t just delay cloning it and do it afterwards, because they may
    be multiple subs closing over each other:
    
        sub {
           state sub foo;
           state sub bar;
           sub foo { \&bar }
           sub bar { \&foo }
        }
    
    So *all* the entries in the new pad must be filled before any inner
    subs can be cloned.
    
    So what we do is put a stub in place of the cloned sub.   And then
    in a second pass clone the inner subs, reusing the stubs from the
    first pass.

M       pad.c
M       perly.act
M       perly.h
M       perly.tab
M       perly.y
M       t/cmd/lexsub.t

commit 2b17f1ec21e98bd3ede85a3071f15b4a2fb69b5c
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Sun Jul 8 14:51:10 2012 -0700

    perldiag: closure referents → closure references
    
    This goes back to 2ba9eb46.

M       pod/perldiag.pod

commit e3c73e4e181246e0685b01bff1b13e7ba6aa96e0
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Sun Jul 8 14:42:39 2012 -0700

    Don’t say ‘variable &foo’ in warnings
    
    It should be ‘subroutine &foo’.  (It could be ‘subroutine foo’, but 
we
    use both forms elsewhere, and &foo is the easier to implement, the &
    already being contained in the pad name.)

M       pad.c
M       pod/perldiag.pod
M       t/cmd/lexsub.t

commit 68a4b2c0f6168349087499036c730758c1cc6d00
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Sun Jul 8 14:28:22 2012 -0700

    lexsub.t: Fix some tests
    
    I got this working a few commits ago, but the tests mentioned the
    wrong sub name.

M       t/cmd/lexsub.t

commit 735a5958f5cce9d72f37a3c5a70b4ba90b73658c
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Sun Jul 8 14:18:43 2012 -0700

    Make pad_fixup_inner_anons cope with closed-over subs
    
    When a sub starts being parsed, a new CV is created.  When it fin-
    ishes, it is stored in its final location.  If there is a stub there
    already, the pad is copied to the stub and the body attached thereto.
    
    Since there may be closures inside the sub whose CvOUTSIDE
    pointers point to the temporary CV used during compilation,
    pad_fixup_inner_anons is called, to reassign all those
    CvOUTSIDE pointers.
    
    This happens in cases like this:
    
        sub f;
        sub f { sub { } }
    
    When a sub closes over a lexical item in an outer sub, the inner sub
    gets its own pad entry with the same value as the outer pad entry.
    
    This means that, now that we have lexical subs (currently just state
    subs), we can end up with a pad entry (&s) holding a sub whose
    CvOUTSIDE does not point to the sub (f) that owns the pad:
    
        state sub s { }
        sub f { s() }
    
    If the f sub has to reuse a stub, then pad_fixup_inner_anons gets to
    see that, and complains bitterly:
    
    $ ./perl -Ilib -E 'state sub s; sub f; sub f { s() }'
    Assertion failed: (CvOUTSIDE(innercv) == old_cv), function 
Perl_pad_fixup_inner_anons, file pad.c, line 2095.
    Abort trap

M       pad.c
M       t/cmd/lexsub.t

commit ee08150f3a1bdbc22a03e82491089c4be77ffb68
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Sat Jul 7 23:46:52 2012 -0700

    ‘Undefined subroutine &foo called’ for lex subs
    
    instead of just ‘Undefined subroutine called’ without the name.

M       pp_hot.c
M       t/cmd/lexsub.t

commit e93129702c44a42ddee16d371a8fc794cf07c064
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Sat Jul 7 23:12:20 2012 -0700

    op.c:newMYSUB: Remove unused vars

M       op.c

commit ffdf4d25f255b0fb4540ddef6d766f5febec3834
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Sat Jul 7 23:11:23 2012 -0700

    op.c:newMYSUB: inline var used only once
    
    as of the previous commit

M       op.c

commit 230a7f96b676b128914cad8cbb2e8ad8793d7826
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Sat Jul 7 23:07:55 2012 -0700

    Lexical stubs should not AUTOLOAD
    
    There is a feature that allows stubs to fall back to their GVs’
    CVs when called.  If I reference a stub, e.g., \&bar, and then
    bar is autoloaded, the AUTOLOAD sub assigning *bar = *foo or
    *bar = sub {...}, I can still call the stub to which I have a refer-
    ence, and it will fall back to the overloaded sub.
    
    That is all fine and dandy, but it causes any stub that references a
    GV via its CvGV pointer to call that GV’s CV.  If we name a lexical
    sub by pointing its CvGV pointer at the GV whose name we want it to
    have, then the lexical sub, if undefined, will try to fall back to an
    autoloaded sub.
    
    That causes things to gang agley in cases like this:
    
        use 5.01;
        sub foo { } # package sub
        state sub foo;
        foo(); # calls lexical sub; falls back to package sub
    
    While we could fix this by flagging the sub and checking for the flag
    in pp_entersub (as we do with anonymous subs), it is better simply to
    use a HEK, instead of a GV.  Since a GV is quite heavyweight for stor-
    ing just a name, I was going to do that anyway, eventually.  Doing it
    now fixes a bug.

M       op.c

commit 351735d4ff9e5480a296c0c07142cdbd771d7578
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Sat Jul 7 17:35:10 2012 -0700

    Allow CVs to point to HEKs rather than GVs
    
    This will allow named lexical subs to exist independent of GVs.

M       cv.h
M       ext/B/B.xs
M       gv.c
M       pad.c
M       pp.c
M       sv.c
M       sv.h

commit e2bd4bc2eda195b3b5b2119e432a6a24223818f1
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Sat Jul 7 12:18:49 2012 -0700

    Implement padcv
    
    State subs can now be referenced and called.  Most of the tests in
    lexsub.t are now passing.  I noticed mistakes in a couple of the
    tests and corrected them.  In doing so I got an assertion failure
    during compilation, so the tests in question I wrapped in a skipped
    string eval.
    
    State subs are now mostly working, but there are a few things to
    clean up still.

M       op.c
M       pp.c
M       t/cmd/lexsub.t

commit dc58b0d16c19e4237e0e78ed5c32f7f3c6f95891
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Thu Jul 5 23:28:43 2012 -0700

    Test state subs
    
    Most of these tests are still to-do.  The previous commit got every-
    thing compiling at least.  Then I went through putting eval{} around
    all the dying tests and marking the failing tests as to-do.
    
    At least this way I don’t have to do everything at once (even though
    that was how I wrote the tests).
    
    About the only thing that works is constant inlining, of all things.

M       t/cmd/lexsub.t

commit 365434c3bf9bdb73747df40288a3bfc69e0940ae
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Fri Jul 6 23:35:15 2012 -0700

    Look up state subs in the pad
    
    This commit does just enough to get things compiling.  The padcv op
    is still unimplemented (in fact, converting the padany to a padcv is
    still not done), so you can’t actually run the code yet.
    
    Bareword lookup in yylex now produces PRIVATEREF tokens for state
    subs, so the grammar has been adjusted to accept a ‘subname’ in sub
    calls (PRIVATEREF or WORD) where previously only a WORD was permitted.

M       perly.act
M       perly.h
M       perly.tab
M       perly.y
M       toke.c

commit d3674c5eab6ed294b3531423839c9422239daec4
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Fri Jul 6 14:31:31 2012 -0700

    op.c:newMYSUB: disable stub optimisation
    
    It will be a lot easier to get things working without this, for now.
    It can be reënabled later.  It might not be worth it, though, as
    AUTOLOADing will ignore lexical subs, and this optimisation is mainly
    for AUTOLOAD stubs that are rarely used.

M       op.c

commit a8dd6944307a0b75b9f8ef92ce26009d69489d34
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Thu Jul 5 23:22:21 2012 -0700

    Store state subs in the pad
    
    In making ‘sub foo’ respect previous ‘our sub’ declarations in a
    recent commit, I actually made ‘state sub foo’ into a syntax error.
    (At the time, I patched up MYSUB in perly.y to keep the tests for ‘"my
    sub" not yet implemented’ still working.)  Basically, it was creat-
    ing an empty pad entry, but returning something that perly.y was not
    expecting.
    
    This commit adjusts the grammar to allow the SUB branch of barestmt to
    accept a PRIVATEREF for its subname, in addition to a WORD.  It reuses
    the subname rule that SUB used to use (before our subs were added),
    gutting it to remove the special block handling, which SUB now tokes
    care of.  That means the MYSUB rule will no longer turn on CvSPECIAL
    on the PL_compcv that is going to be thrown away anyway.
    
    The code for special blocks (BEGIN, END, etc.) that turns on CvSPECIAL
    now checks for state subs and skips those.  It only applies to our
    subs and package subs.
    
    newMYSUB has now actually been written.  It basically duplicates
    newATTRSUB, except for GV-specific things.  It does currently vivify a
    GV and set CvGV, but I am hoping to change that later.  I also hope to
    merge some of the code later, too.
    
    I changed the prototype of newMYSUB to make it easier to use.  It is
    not used anywhere on CPAN and has always simply died, so that should
    be all right.

M       embed.fnc
M       embed.h
M       op.c
M       perly.act
M       perly.h
M       perly.tab
M       perly.y
M       proto.h

commit 3af0785dc244e8d8e8b36ade1ba89ffcc65829aa
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Thu Jul 5 10:41:05 2012 -0700

    lexsub.t: Add test name, test override from another pkg
    
    The bareword logic in toke.c looks up GVs in various places.  This
    tests that we are bypassing those correctly.

M       t/cmd/lexsub.t

commit e99f5c81b84688a2634ce9a0ebcfb3286ec2e9b9
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Wed Jul 4 23:18:32 2012 -0700

    Let barewords look up our subs
    
    These take precedence over built-in keywords (just as my $AUTOLOAD
    shadows the package var), but not the keyword plugin, as the latter
    takes precedence over labels, and these don’t.

M       t/cmd/lexsub.t
M       toke.c

commit aebbc999d52e4958f8fba3e1495781de84dee1f5
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Wed Jul 4 14:09:46 2012 -0700

    toke.c:yylex:KEY_sub can use PL_tokenbuf to begin with
    
    There is no need to allocate a separate ‘tmpbuf’ and then copy it into
    PL_tokenbuf afterwards.

M       toke.c

commit 7ef47c7f4d313e7596999a8a3745dcf28038050e
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Wed Jul 4 09:13:17 2012 -0700

    Make ‘sub foo{}’ respect ‘our foo’
    
    This commit switches all sub definitions, whether with ‘our’ or not,
    to using S_force_ident_maybe_lex (formerly known as S_pending_ident).
    
    This means that an unqualified (no our/my/state or package prefix)
    ‘sub foo’ declaration does a pad lookup, just like $foo.
    
    It turns out that the vivification that I added to the then
    S_pending_ident for CVs was unnecessary and actually buggy.  We
    *don’t* want to autovivify GVs for CVs, because they might be con-
    stants or forward declarations, which are stored in a simpler form.
    
    I also had to change the subname rule used by MYSUB in perly.y, since
    it can now be fed a PRIVATEREF, which it does not expect.  This may
    prove to be temporary, but it keeps current tests passing.

M       perly.act
M       perly.h
M       perly.tab
M       perly.y
M       t/cmd/lexsub.t
M       toke.c

commit 839f3e4fc1a0e6a1934e36289312b960282aa2cb
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Wed Jul 4 00:17:55 2012 -0700

    Fix our sub with proto
    
    yylex must emit exactly one token each time it is called.  Some-
    times yylex needs to parse several tokens at once.  That’s what
    the various force functions are for.  But that is also what
    PL_pending_ident is for.
    
    The various force_next, force_word, force_ident, etc., functions keep
    a stack of tokens (PL_nextval/PL_nexttype) that yylex will check imme-
    diately when called.
    
    PL_pending_ident is used to track a single identifier that yylex will
    hand off to S_pending_ident to handle.
    
    S_pending_ident is the only piece of code for resolving an identi-
    fier that could be lexical but could also be a package variable.
    force_ident assumes it is looking for a package variable.
    
    force_* takes precedence over PL_pending_ident.
    
    All this means that, if an identifier needs to be looked up in the pad
    on the next yylex invocation, it has to use PL_pending_ident, and the
    force_* functions cannot be used at the same time.
    
    Not realising that, when I made ‘our sub foo’ store the sub in the
    pad I also made ‘our sub foo ($)’ into a syntax error, because it
    was being parsed as ‘our sub ($) foo’ (the prototype being 
‘forced’);
    i.e., the pending tokens were being pulled out of the ‘queue’ in the
    wrong order.  (I put queue in quotes, because one queue and one unre-
    lated buffer together don’t exactly count as ‘a queue’.)
    
    Changing PL_pending_ident to have precedence over the force stack
    breaks ext/XS-APItest/t/swaptwostmts.t, because the statement-parsing
    interface does not localise PL_pending_ident.  It could be changed to
    do that, but I don’t think it is the right solution.
    
    Having two separate pending token mechanisms makes things need-
    lessly fragile.
    
    This commit eliminates the PL_pending_ident mechanism and
    modifies S_pending_ident (renaming it in the process to
    S_force_ident_maybe_lex) to work with the force mechanism.  I was
    going to merge it with force_ident, but the two make incompatible
    assumptions that just complicate the code if merged.  S_pending_ident
    needs the sigil in the same string buffer, to pass to the pad inter-
    face.  force_ident needs to be able to work without a sigil present.
    
    So now we only have one queue for pending tokens and the order is more
    predictable.

M       embed.fnc
M       parser.h
M       proto.h
M       sv.c
M       t/cmd/lexsub.t
M       toke.c

commit a7f8af94d0cd564a0989c2398f828356084af25f
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Mon Jul 2 21:26:13 2012 -0700

    Make do sub() respect our declarations

M       t/cmd/lexsub.t
M       toke.c

commit 18d6db415debe68533b6b7d1972374b2d96293fd
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Mon Jul 2 12:29:48 2012 -0700

    lexsub.t: Fix a test
    
    This is not testing what I meant it to test: that ‘sub d’ will respect
    a preceding ‘our sub d;’.  If ‘sub d’ is in the same package, it 
makes
    no difference, so the test tests nothing.
    
    It turns out this does not work yet.

M       t/cmd/lexsub.t

commit 7568babd6d59ce0ab28f8c8815bb98c66bf63bd4
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Mon Jul 2 09:07:31 2012 -0700

    Use test.pl in lexsub.t
    
    I thought cmd/ couldn’t use test.pl, but was mistaken.

M       t/cmd/lexsub.t

commit 4edc17cc2a33c410cba8810338f52d8cc0425392
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Sun Jul 1 22:53:41 2012 -0700

    Make &foo respect our sub
    
    This changes &foo to go through S_pending_ident (by setting
    PL_pending_ident, which causes yylex to defer to S_pending_ident for
    the next token) the way $foo and %foo do.
    
    This necessitated reducing the maximum identifier length of &foo from
    252 to 251, making it match @foo, $foo, etc.  So somebody’s JAPH might
    break. :-)

M       MANIFEST
A       t/cmd/lexsub.t
M       t/comp/parser.t
M       toke.c

commit d59d856f9b75a8afec5e1535273b0972ba5b530d
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Sat Jun 30 23:20:25 2012 -0700

    Allocate ‘our sub’ in the pad
    
    Currently the name is only allocated there.  Nothing fetches it yet.
    
    Notes on the implementation:
    
    S_pending_ident contains the logic for determining whether $foo or
    @foo refers to a lexical or package variable.
    
    yylex defers to S_pending_ident if PL_pending_ident is set.
    
    The KEY_sub case in yylex is changed to set PL_pending_ident instead
    of using force_word.  For package variables (including our),
    S_pending_ident returns a WORD token, which is the same thing that
    force_word produces.  So *that* aspect of this change does not affect
    the grammar.  However....
    
    The barestmt rule’s SUB branch begins with ‘SUB startsub subname’.
    startsub is a null rule that creates a new sub in PL_compcv via
    start_subparse().  subname is defined in terms of WORD and also checks
    whether this is a special block, turning on CvSPECIAL(PL_compcv) if
    it is.  That flag has to be visible during compilation of the sub.
    
    But for a lexical name, such as ‘our foo’, to be allocated in the
    right pad, it has to come *before* startsub, i.e., ‘SUB subname
    startsub’.
    
    But subname needs to modify the sub that startsub created, set-
    ting the flag.
    
    So I copied (not moved, because MYSUB still uses it) the name-checking
    code from the subname rule into the SUB branch of barestmt.  Now that
    uses WORD directly instead of invoking subname.  That allows the code
    there to set everything up in the right order.

M       perly.act
M       perly.h
M       perly.tab
M       perly.y
M       toke.c

commit b83c7c601ed122202faad674904dfb259bd74d12
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Sat Jun 30 23:00:11 2012 -0700

    Add padcv to Opcode.pm

M       ext/Opcode/Opcode.pm

commit a81fda7fa5d923dc42b3eca0c7669eab8161b62e
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Sat Jun 30 22:29:28 2012 -0700

    padcv op type

M       opcode.h
M       opnames.h
M       pp.c
M       pp_proto.h
M       regen/opcodes

commit 2ad2301c66cae3b3481637ffcc67df40674c7a43
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Sat Jun 30 17:31:32 2012 -0700

    Don’t allow name after our/state sub
    
    It was a mistake that this was ever allowed.

M       pod/perldiag.pod
M       t/lib/croak/toke
M       toke.c
-----------------------------------------------------------------------

--
Perl5 Master Repository

Reply via email to