New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove Devel::BeginLift #51
Conversation
…Lift. Rather than using Devel::BeginLift or declaring things with a BEGIN block, we simply rewrite "func foo {...}" to be "sub foo {...}" and the rest happens magically. The one caveat is Devel::Declare expects `func` and `method` to get the code ref being generated. Rather than fight this, we go along with it. Only four tests fail. Fixes on the way.
Devel::Declare::MethodInstaller::Simple will add "sub $attrs" to $before in inject_if_block() if it sees attributes. This messes with our custom inject_if_block(). So just ignore anything already on $before and handle attributes ourselves.
Method::Signatures::Modifiers always defines methods at runtime. It was doing this by overriding code_for(), but the compile time logic has moved. Overriding _do_compile_at_BEGIN() is safer.
Check that the resulting list is what we expect it to be. Otherwise func() might swallow everything in the list.
This was necessary when we were doing more complicated things to work around Devel::BeginLift. Now its just a copy of the one from Devel::Declare::Context::Simple.
Juuuust to make sure.
For some odd reason I don't understand, Devel::Declare only wants you to inject "sub" for named routines. Anon routines don't get a sub nor do they need to pass attributes. *shrug*
Okay, I've had a chance to go over the code more closely now. Here are the comments I have:
And I think that's all I can see that needs your counter-comment. As I say, next I will set up a little perlbrew farm and test this on some different Perl versions. If that all looks good, I'm going to play around with removing the Thoughts? |
Conflicts: lib/Method/Signatures.pm
Buddy also thought the way anonymous functions with attributes were handled is fishy. Figured out why Devel::Declare::MethodInstaller::Simple->parser will only add the "sub" for attributes. It has to do with a quirk in how prototypes are parsed. Here's two versions of what a compiled anon func might look like. # If we leave out the "sub". sub func(&) { return shift; }; my $a = [ func { 123 }, 1 ]; # If we always put in a "sub". sub func(&) { return shift; }; my $a = [ func sub { 123 }, 1 ]; The top one works, the bottom one fails "too many arguments for main::func". The prototype must be getting confused. This may be why it fixed a 5.10 bug, there may have been a prototype glitch. Or maybe this behavior is a prototype glitch. Either way it works now on 5.10.0 and 5.14.1. The t/larna.t tests catch this problem. There's no need to replicate the Devel::Declare logic, only in the case of a BEGIN lift. I can no longer replicate a 5.10 bug. It's possible the bug was tickled by Devel::BeginLift. Signed-off-by: Michael G. Schwern <schwern@pobox.com>
Sorry I dropped off the Internet for a while. I was confused about how that works, too, but I just figured it out and found my $foo = func { ... }; it compiles into something like this... sub func(&) { return shift; }; func() has a & prototype, so there's no need for the "sub" part. It would sub func(&) { return shift; }; sub func(&) { return shift; }; The top one works, the bottom one fails "too many arguments for main::func". The bug it revealed is I got the logic backwards, so the code wasn't applying |
Okay, I mostly followed all that. I guess my main question, though, is why do we need
when it seems like
would work just as well? And also not engender the problem you describe from larna.t ... Still planning on jumping on merging-and-releasing this branch next, BTW. JIC you thought I was falling down on the job over here. :-D |
On 2012.10.26 8:11 PM, Buddy Burden wrote:
You'll have to ask the DD folks about that. I suspect its because DD stops
Nope, you seem to be well on top of things.
|
Seems to work on all Perl's I tried it on (5.8.9, 5.10.1, 5.12.4, 5.14.2, 5.16.1). The change you made now makes it so that the |
This patch series eliminates Devel::BeginLift per #39.
Instead of using BeginLift it simply rewrites "method foo {...}" as "method &foo; sub foo { ... }".
Tested with Strawberry Perl 5.16.1 64 bit. That's what I have on my VM. Needs more Windows testing, but it can't be any worse than the shape we're currently in.