Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upLexical subs used for AUTOLOAD #13392
Comments
This comment has been minimized.
This comment has been minimized.
From @cpansproutperlsub says: The fully qualified name That means the $AUTOLOAD used is the one in the same package where Since lexical subs are not defined in any package, what should lexical This is what they actually do: $ ./perl -Ilib -XMfeature=:all -e 'my sub foo {} *AUTOLOAD = \&foo; bar()' My initial thought was to use the package of the *AUTOLOAD glob. But Lexical subs just happen to record which package they were declared my sub AUTOLOAD_to_be { -- Father Chrysostomos |
This comment has been minimized.
This comment has been minimized.
From PeterCMartini@GMail.comOn Sat, Nov 2, 2013 at 9:34 AM, Father Chrysostomos
Compare to regular subs: perl -e ' #### Output: $VAR1 = 'B::Test'; So, I think it makes the most sense to use the package of the AUTOLOAD |
This comment has been minimized.
This comment has been minimized.
The RT System itself - Status changed from 'new' to 'open' |
This comment has been minimized.
This comment has been minimized.
From PeterCMartini@GMail.comOn Sat, Nov 2, 2013 at 9:49 AM, Peter Martini <petercmartini@gmail.com> wrote:
Can we just dummy up the lexical subs into the __ANON__ package like |
This comment has been minimized.
This comment has been minimized.
From @dmcbrideOn Saturday November 2 2013 9:49:29 AM Peter Martini wrote:
Isn't that showing the opposite? The $AUTOLOAD variable being used is |
This comment has been minimized.
This comment has been minimized.
From PeterCMartini@GMail.comOn Sat, Nov 2, 2013 at 9:56 AM, Darin McBride <dmcbride@cpan.org> wrote:
Doh, too early for me, you're right |
This comment has been minimized.
This comment has been minimized.
From PeterCMartini@GMail.comOn Sat, Nov 2, 2013 at 9:58 AM, Peter Martini <petercmartini@gmail.com> wrote:
The more I think about it, the more I like the idea of just using the |
This comment has been minimized.
This comment has been minimized.
From PeterCMartini@GMail.comOn Sat, Nov 2, 2013 at 10:36 AM, Peter Martini <petercmartini@gmail.com> wrote:
Bah, I'm sure I mangled the details, I hope I got the gist across. |
This comment has been minimized.
This comment has been minimized.
From perl5-porters@perl.orgPeter Martini wrote:
That doesn’t sound too bad. But note that the package for anonymous SV = IV(0x7ffa898060d8) at 0x7ffa898060e8 Having my sub foo be __ANON__::foo would make things easier, though, (Note that anonymous subs are in a package, so $AUTOLOAD is set on the |
This comment has been minimized.
This comment has been minimized.
From PeterCMartini@GMail.comOn Sat, Nov 2, 2013 at 10:43 AM, Father Chrysostomos <sprout@cpan.org> wrote:
Yeah, I know, it just always felt like an implementation detail to me. |
This comment has been minimized.
This comment has been minimized.
From @rurbanAnonymous subs must only belong to a class, but not necessarily to a package. The AUTOLOAD magic needs to ignore lexical subs as lexical subs should On Sat, Nov 2, 2013 at 10:12 AM, Peter Martini <petercmartini@gmail.com> wrote:
-- |
This comment has been minimized.
This comment has been minimized.
From PeterCMartini@GMail.comOn Sat, Nov 2, 2013 at 11:25 AM, Reini Urban <rurban@x-ray.at> wrote:
That's all implementation details though, and specifically
The question becomes, why should lexical subs not support name lookup,
|
This comment has been minimized.
This comment has been minimized.
From PeterCMartini@GMail.comOn Sat, Nov 2, 2013 at 10:43 AM, Father Chrysostomos <sprout@cpan.org> wrote:
Actually - would it be possible to create a GV referencing the stash, We have spare cv_flags bits :-) |
This comment has been minimized.
This comment has been minimized.
From perl5-porters@perl.orgPeter Martini wrote:
*AUTOLOAD = sub { ... $AUTOLOAD ... }; |
This comment has been minimized.
This comment has been minimized.
From PeterCMartini@GMail.com
I know :-) Whats the difference between that and lexical subs, philosophically? They're both accessing variables in an outer, package scope at the point of definition, is there a reason a lexical sub shouldnt just keep a reference to the package where it was declared as well? |
This comment has been minimized.
This comment has been minimized.
From perl5-porters@perl.orgPeter Martini wrote:
That would bloat the memory usage of lexical subs, making them match Lexical subs already have a CvSTASH pointer BTW. In fact, maybe we |
This comment has been minimized.
This comment has been minimized.
From perl5-porters@perl.orgPeter Martini asked:
They do. :-) Via CvSTASH. Is your question in reponse to my statement, ‘In fact, I was hoping at In that case, I see your point. The only difference between lexical subs and anonymous subs (apart |
This comment has been minimized.
This comment has been minimized.
From PeterCMartini@GMail.comOn Sat, Nov 2, 2013 at 12:58 PM, Father Chrysostomos <sprout@cpan.org> wrote:
perl -XMfeature=:all -E ' Am I still missing something obvious? It looks like lexical subs are |
This comment has been minimized.
This comment has been minimized.
From PeterCMartini@GMail.comOn Sat, Nov 2, 2013 at 1:31 PM, Father Chrysostomos <sprout@cpan.org> wrote:
Ah, okay :-) So ignore my last email, this one answers it - I think. |
This comment has been minimized.
This comment has been minimized.
From perl5-porters@perl.orgPeter Martini wrote:
That is because every statement is compiled into some package. That is unrelated to the $AUTOLOAD problem, as ‘package foo; sub bar::AUTOLOAD { $AUTOLOAD }’ will not work, since the body of the sub is not in the same package the sub is defined in.
But the whole problem (the reason for this thread) is that perl needs What is CvSTASH for, apart from? As you may have noticed, I haven’t really thought anything through in |
This comment has been minimized.
This comment has been minimized.
From perl5-porters@perl.orgPeter Martini wrote:
I suppose so. As I said in my previous message, I have not really Do we want CvGV to vivify and cache a GV? Then we can use the lexical To avoid vivifying GVs unnecessarily, we can add the cv_name function (We have no convention for indicating the return type in a function BTW, here is another victim of this problem: $ ./perl -Ilib -XMfeature=:all -e 'state sub foo {} use overload "%{}"=>\&foo; %{bless+[]}' Again, it’s a null CvGV. |
This comment has been minimized.
This comment has been minimized.
From PeterCMartini@GMail.comSent from my iPhone On Nov 2, 2013, at 14:18, Father Chrysostomos <sprout@cpan.org> wrote:
ISA?
Ditto :-) |
This comment has been minimized.
This comment has been minimized.
From perl5-porters@perl.orgPeter Martini wrote:
I don’t understand your response. It makes about as much sense as my What I meant to write was: What is CvSTASH for, apart from providing I was about to say it’s not used in care, but I now see it is used to Then there is also the XS AUTOLOAD hack, which we may well simply have Those are the only uses. Most of the time we have GvSTASH(GvCV(cv)), |
This comment has been minimized.
This comment has been minimized.
From zefram@fysh.orgFather Chrysostomos wrote:
They can be different, and we have backcompat to think of.
Almost nothing. As far as I can see, the main effect is that subroutines -zefram |
This comment has been minimized.
This comment has been minimized.
From zefram@fysh.orgFather Chrysostomos wrote:
How legitimate is "sub OtherPackage::foo {}"? -zefram |
This comment has been minimized.
This comment has been minimized.
From perl5-porters@perl.orgZefram wrote:
That shows I misunderstood the code that sets CvSTASH, as does $ ./perl -Ilib -e 'use Devel::Peek; sub foo::bar {} Dump \&foo::Bar' |
This comment has been minimized.
This comment has been minimized.
From @maukeOn 02.11.2013 22:29, Father Chrysostomos wrote:
I don't know if it makes any difference but you defined foo::bar but you -- |
This comment has been minimized.
This comment has been minimized.
From perl5-porters@perl.orgLukas Mai wrote:
Oops! In this case, the stub was vivified in the main stash, so it |
This comment has been minimized.
This comment has been minimized.
From perl5-porters@perl.orgPeter Martini wrote:
Nevertheless, this conversion has given me ideas I would not have come Proposed solution: • Lexical subs get an extra flag indicating that the stash name must The first stage would be to switch lexical subs over to the new system. Then we can optimise other subs by making sub foo {} put a code ref in $::{foo}. |
This comment has been minimized.
This comment has been minimized.
From @cpansproutOn Sat Nov 02 17:32:46 2013, perl5-porters@perl.org wrote:
Oh boy! I had completely forgotten about this thread. I have just fixed the original issue with 1869162 (before finding this thread again), but the other things in the quoted message (which would make for cleaner code) have not been addressed. -- Father Chrysostomos |
This comment has been minimized.
This comment has been minimized.
From @cpansproutOn Thu Aug 28 12:31:56 2014, sprout wrote:
Now they have. See commit f9d9e96. -- Father Chrysostomos |
This comment has been minimized.
This comment has been minimized.
@cpansprout - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#120441 (status was 'resolved')
Searchable as RT120441$