Avoid creating GVs when subs are declared
This patch changes ‘sub foo {...}’ declarations to store subroutine
references in the stash, to save memory.
Typeglobs still notionally exist. Accessing CvGV(cv) will reify them.
Hence, currently the savings are lost when a sub call is compiled.
$ ./miniperl -e 'sub foo{} BEGIN { warn $::{foo} } foo(); BEGIN { warn $::{foo} }'
CODE(0x7f8ef082ad98) at -e line 1.
*main::foo at -e line 1.
This optimisation is skipped if the subroutine declaration contains a
package separator.
Concerning the changes in caller.t, this code:
sub foo { print +(caller(0))[3],"\n" }
my $fooref = delete $::{foo};
$fooref -> ();
used to crash in 5.7.3 or thereabouts. It was fixed by 16658 (aka
07b8c804e8) to produce ‘(unknown)’ instead. Then in 5.13.3 it was
changed (by 803f274) to produce ‘main::__ANON__’ instead. So the
tests are really checking that we don’t get a crash. I think it is
acceptable that it has now changed to ‘main::foo’.