This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Stop constant inlining from countermanding ‘use subs’
authorFather Chrysostomos <sprout@cpan.org>
Sun, 2 Jun 2013 07:31:27 +0000 (00:31 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 2 Jun 2013 07:38:06 +0000 (00:38 -0700)
commit70e5f2b56cbcbdf658cf4172827db4611d322148
tree6988b09f1791ebd508c0db88f953f77d9092f904
parentd8b87a9b781df570fca05131b8d4e8855eb8c5e3
Stop constant inlining from countermanding ‘use subs’

Ever since

commit f7461760003db2ce68155c97ea6c1658e96fcd27
Author: Zefram <zefram@fysh.org>
Date:   Sun Nov 8 15:03:45 2009 +0100

    Bareword sub lookups
    ...

this has failed:

$ perl5.10 -le 'use subs "abs";  sub abs() {44}; print abs + abs'
88
$ perl5.12 -le 'use subs "abs";  sub abs() {44}; print abs + abs'
44

A GV holding a single constant is a candidate for downgrading after
it uhas been used.  The GV gets downgraded after the first ‘abs’ is
inlined.  In the process, the CV-imported flag, which is stored in the
GV, not the CV, is lost, preventing &abs from overriding the built-in
function on the second mention.

There is a special flag for RVs, namely SVprv_PCS_IMPORTED,
which indicates that, when expanded to GVs, they should have the
GVf_IMPORTED_CV flag set.  But gv_try_downgrade wasn‘t setting
that flag.
gv.c
t/op/override.t