Skip to content

Commit d5208db

Browse files
committed
convert last small purpose of builtin.pm to C and NOOP require's I/O
-builtin.pm is now primarily for POD and .pm indexing tools, core, CPAN or user written. It also is a backup mechanism for very strange %INC localization, clearing, or manipulation done by users, probably in a .t, and whatever %INC manipulation is being done is probably developer error. -This removes all the libc/kernel I/O calls for builtin.pm, and Perl code parser overhead. -A large benefit is, this commit is 50% of the work, to make perl -E 'say "hi";' "/lib"-less or not dependent on any file I/O. perl.bin, libperl.so, and miniperl.bin should be able to execute as a standalone binary. If perl -e "1;" doesn't need a dozen separate library files, perl -E "1;" also shouldn't need a dozen files. perl -E "say 'Hello world';" should work, even with a broken perl installation or unreachable "/lib/*.pm"s or broken "portable" perls. Only a feature.pm dep is left, for -E to be lib-less. That is for another patch and PR in the the future.
1 parent 0eda2a5 commit d5208db

File tree

4 files changed

+39
-8
lines changed

4 files changed

+39
-8
lines changed

builtin.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,9 @@ XS(XS_builtin_import)
774774
void
775775
Perl_boot_core_builtin(pTHX)
776776
{
777+
HV * inc_hv;
778+
GV * ver_gv;
779+
SV * ver_sv;
777780
I32 i;
778781
for(i = 0; builtins[i].name; i++) {
779782
const struct BuiltinFuncDescriptor *builtin = &builtins[i];
@@ -807,6 +810,13 @@ Perl_boot_core_builtin(pTHX)
807810
}
808811

809812
newXS_flags("builtin::import", &XS_builtin_import, __FILE__, NULL, 0);
813+
814+
inc_hv = GvHVn(PL_incgv);
815+
hv_store(inc_hv, "builtin.pm", STRLENs("builtin.pm"), newSVpvs(__FILE__), 0);
816+
ver_gv = gv_fetchpvs("builtin::VERSION", GV_ADDMULTI, SVt_PV);
817+
ver_sv = GvSV(ver_gv);
818+
/* Remember to keep $VERSION in this file and $VERSION in builtin.pm synced. */
819+
sv_setpvs(ver_sv, "0.016");
810820
}
811821

812822
/*

lib/builtin.pm

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
package builtin 0.015;
1+
package builtin 0.016;
22

33
use v5.40;
44

55
# All code, including &import, is implemented by always-present
6-
# functions in the perl interpreter itself.
7-
# See also `builtin.c` in perl source
6+
# functions in the perl interpreter itself in `builtin.c`.
7+
#
8+
# $builtin::VERSION and %INC are also set by the interpreter in `builtin.c`
9+
# since this file is a NOOP. Therefore this file is unlikely to ever execute
10+
# and primarily serves as POD.
811

912
__END__
1013

lib/builtin.t

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,13 @@ EOS
645645
}
646646
}
647647

648+
like($INC{'builtin.pm'}, qr/builtin\.c/, 'check that \'builtin.pm\' is in %INC');
649+
{
650+
my $xsv = $builtin::VERSION;
651+
delete $INC{'builtin.pm'};
652+
eval "use builtin;";
653+
is($xsv, $builtin::VERSION, 'XS $VERSION matches PP $VERSION');
654+
}
648655
# vim: tabstop=4 shiftwidth=4 expandtab autoindent softtabstop=4
649656

650657
done_testing();

pod/perldelta.pod

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,22 @@ XXX Remove this section if F<Porting/corelist-perldelta.pl> did not add any cont
123123

124124
=over 4
125125

126-
=item *
127-
128-
L<XXX> has been upgraded from version A.xx to B.yy.
129-
130-
XXX If there was something important to note about this change, include that here.
126+
=item builtin.pm
127+
128+
L<builtin.pm|/builtin.pm> has been upgraded from version 0.015 to 0.016.
129+
As an optimization the C<builtin::> package and module is now fully
130+
implemented in C to save on file system I/O and startup time.
131+
132+
Specifically the C<use builtin;> statement and any permutations of
133+
C<use builtin;> will not internally perform a per process first time
134+
C<require;> anymore and C<$INC{'builtin.pm'}> is already filled in at
135+
process startup. All C<.pm> functionality is embedded in the interpreter at
136+
startup now. This optimization removes all I/O calls and time overhead of
137+
parsing the C<builtin.pm> file. The C<builtin.pm> file will remain as
138+
documentation.
139+
140+
C<builtin::>'s C<import()>, C<$VERSION>, and all available subroutines/APIs
141+
have not changed. No changes are required to previously written code.
131142

132143
=back
133144

0 commit comments

Comments
 (0)