Skip to content

Commit

Permalink
convert last small purpose of builtin.pm to C and NOOP require's I/O
Browse files Browse the repository at this point in the history
-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.
  • Loading branch information
bulk88 committed Oct 24, 2024
1 parent 0eda2a5 commit d5208db
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
10 changes: 10 additions & 0 deletions builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,9 @@ XS(XS_builtin_import)
void
Perl_boot_core_builtin(pTHX)
{
HV * inc_hv;
GV * ver_gv;
SV * ver_sv;
I32 i;
for(i = 0; builtins[i].name; i++) {
const struct BuiltinFuncDescriptor *builtin = &builtins[i];
Expand Down Expand Up @@ -807,6 +810,13 @@ Perl_boot_core_builtin(pTHX)
}

newXS_flags("builtin::import", &XS_builtin_import, __FILE__, NULL, 0);

inc_hv = GvHVn(PL_incgv);
hv_store(inc_hv, "builtin.pm", STRLENs("builtin.pm"), newSVpvs(__FILE__), 0);
ver_gv = gv_fetchpvs("builtin::VERSION", GV_ADDMULTI, SVt_PV);
ver_sv = GvSV(ver_gv);
/* Remember to keep $VERSION in this file and $VERSION in builtin.pm synced. */
sv_setpvs(ver_sv, "0.016");
}

/*
Expand Down
9 changes: 6 additions & 3 deletions lib/builtin.pm
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package builtin 0.015;
package builtin 0.016;

use v5.40;

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

__END__
Expand Down
7 changes: 7 additions & 0 deletions lib/builtin.t
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,13 @@ EOS
}
}

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

done_testing();
21 changes: 16 additions & 5 deletions pod/perldelta.pod
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,22 @@ XXX Remove this section if F<Porting/corelist-perldelta.pl> did not add any cont

=over 4

=item *

L<XXX> has been upgraded from version A.xx to B.yy.

XXX If there was something important to note about this change, include that here.
=item builtin.pm

L<builtin.pm|/builtin.pm> has been upgraded from version 0.015 to 0.016.
As an optimization the C<builtin::> package and module is now fully
implemented in C to save on file system I/O and startup time.

Specifically the C<use builtin;> statement and any permutations of
C<use builtin;> will not internally perform a per process first time
C<require;> anymore and C<$INC{'builtin.pm'}> is already filled in at
process startup. All C<.pm> functionality is embedded in the interpreter at
startup now. This optimization removes all I/O calls and time overhead of
parsing the C<builtin.pm> file. The C<builtin.pm> file will remain as
documentation.

C<builtin::>'s C<import()>, C<$VERSION>, and all available subroutines/APIs
have not changed. No changes are required to previously written code.

=back

Expand Down

0 comments on commit d5208db

Please sign in to comment.