develooper Front page | perl.perl5.porters | Postings from October 2016

Re: compile time AUTOLOAD calling (constant folding)

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
October 24, 2016 11:03
Subject:
Re: compile time AUTOLOAD calling (constant folding)
Message ID:
20161024110305.GH3128@iabyn.com
On Sat, Oct 22, 2016 at 02:10:31AM -0400, bulk88 wrote:
> I am thinking of somehow allowing the peephole optimizer or toke.c to call
> AUTOLOAD if AUTOLOAD CV promises to have no side effects from it being
> called at compile time. I found this commit, but it doesn't explain
> anything.
> 
> http://perl5.git.perl.org/perl.git/commitdiff/70e590749aafa6e0e67a2220f53f1568bf4e16de

For people reading along, that commit removes an entry from perltodo
as having been done:

    commit 70e590749aafa6e0e67a2220f53f1568bf4e16de
    Author:     Nicholas Clark <nick@ccl4.org>
    AuthorDate: Fri Dec 23 12:01:29 2005 +0000
    Commit:     Nicholas Clark <nick@ccl4.org>
    CommitDate: Fri Dec 23 12:01:29 2005 +0000

        inlining autoloaded constants is TODOne.
        
        p4raw-id: //depot/perl@26471


    Affected files ...
        M	pod/perltodo.pod

    Differences ...

    diff --git a/pod/perltodo.pod b/pod/perltodo.pod
    index 4058be4..2ab61f3 100644
    --- a/pod/perltodo.pod
    +++ b/pod/perltodo.pod
    @@ -556,16 +556,6 @@ program if you pass the process ID. It would be good to do this with the Perl
     debugger on a running Perl program, although I'm not sure how it would be
     done." ssh and screen do this with named pipes in /tmp. Maybe we can too.
     
    -=head2 inlining autoloaded constants
    -
    -Currently the optimiser can inline constants when expressed as subroutines
    -with prototype ($) that return a constant. Likewise, many packages wrapping
    -C libraries export lots of constants as subroutines which are AUTOLOADed on
    -demand. However, these have no prototypes, so can't be seen as constants by
    -the optimiser. Some way of cheaply (low syntax, low memory overhead) to the
    -perl compiler that a name is a constant would be great, so that it knows to
    -call the AUTOLOAD routine at compile time, and then inline the constant.


I too don't know to what Nicholas was referring.

> I'm thinking of modifying the gv_fetchsv() at http://perl5.git.perl.org/perl.git/blob/01b515d1d793fe9ee31ac67de850d943ce109686:/op.c#l9856
> to fall back to autoload sub if it exists, and if AUTOLOAD's CV has CvCONST
> flag, since I dont want to add a new flag, AUTOLOAD sub will be called at
> compile time, not runtime from pp_entersub. Any comments?

That doesn't sound very useful to me. I think it will very rare for the
AUTOLOAD sub to be a const sub (so all the autoloaded constants  are the
same value).

-- 
I before E. Except when it isn't.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About