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

Re: compile time AUTOLOAD calling (constant folding)

Thread Previous | Thread Next
Dave Mitchell
October 24, 2016 11:03
Re: compile time AUTOLOAD calling (constant folding)
Message ID:
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.

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

    commit 70e590749aafa6e0e67a2220f53f1568bf4e16de
    Author:     Nicholas Clark <>
    AuthorDate: Fri Dec 23 12:01:29 2005 +0000
    Commit:     Nicholas Clark <>
    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
> 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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About