Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert last small purpose of builtin.pm to C and NOOP require's I/O #22699

Open
wants to merge 2 commits into
base: blead
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ static OP *ck_builtin_func1(pTHX_ OP *entersubop, GV *namegv, SV *ckobj)

entersubop = ck_entersub_args_proto(entersubop, namegv, prototype);

OPCODE opcode = builtin->ckval;
OPCODE opcode = (OPCODE)builtin->ckval;
if(!opcode)
return entersubop;

Expand Down Expand Up @@ -752,7 +752,7 @@ XS(XS_builtin_import)
if(!S_parse_version(sympv + 1, sympv + symlen, &vmajor, &vminor))
Perl_croak(aTHX_ "Invalid version bundle %" SVf_QUOTEDPREFIX, sym);

U16 want_ver = SHORTVER(vmajor, vminor);
U16 want_ver = (U16)SHORTVER(vmajor, vminor);

if(want_ver < SHORTVER(5,39) ||
/* round up devel version to next major release; e.g. 5.39 => 5.40 */
Expand Down Expand Up @@ -789,7 +789,7 @@ Perl_boot_core_builtin(pTHX)
SV *name = newSVpvs_flags("builtin::", SVs_TEMP);
sv_catpv(name, builtin->name);
CV *cv = newXS_flags(SvPV_nolen(name), builtin->xsub, __FILE__, proto, 0);
XSANY.any_i32 = builtin->ckval;
XSANY.any_i32 = (I32)builtin->ckval;

if ( builtin->xsub == &XS_builtin_func1_void
|| builtin->xsub == &XS_builtin_func1_scalar)
Expand All @@ -807,6 +807,14 @@ Perl_boot_core_builtin(pTHX)
}

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

HV * inc_hv = GvHVn(PL_incgv);
hv_stores(inc_hv, "builtin.pm", newSVpvs(__FILE__));

GV * ver_gv = gv_fetchpvs("builtin::VERSION", GV_ADDMULTI, SVt_PV);
SV * ver_sv = GvSV(ver_gv);
/* Remember to keep $VERSION in this file and $VERSION in builtin.pm synced. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to have a test for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the test is in this patch already. Change either side to 0.017 and test fails.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, I missed that.

sv_setpvs(ver_sv, "0.016");
}

/*
Expand Down
12 changes: 9 additions & 3 deletions lib/builtin.pm
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
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.
#
# Remember to keep $VERSION in this file and $VERSION in builtin.c synced!


__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
Loading