Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit d6efd6f

Browse files
Reini Urbanrurban
Reini Urban
authored andcommitted
proto: activate sub inlining without () proto
See [cperl #87] We have two ways to constant fold subs. fold to a fast CONSTSUB without entersub and fold to a dummy XS call with returning the value immediately. there’s no semantic visibility of those 3 variants, other than the required () proto or the usage of use constant pragma. there’s no semantic distinction of constant folded to CONSTSUB, dummy_xs or not constant folded subs, other than improved run-time performance and a different internal representation. dropping the requirement to use the () seems 1. fair, and 2. even other prototypes should be allowed to fold if those parameters are ignored in the body, when at compile-time the body folds to a constant sv. WIP: but I am getting prototype mismatches CHANGE: set the proto of the created dummy XS to "" or "$" if a method.
1 parent 7bec5ab commit d6efd6f

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

op.c

+23-3
Original file line numberDiff line numberDiff line change
@@ -12308,7 +12308,17 @@ Perl_newMYSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
1230812308
CvSTASH_set(cv, PL_curstash);
1230912309
*spot = cv;
1231012310
}
12311-
SvPVCLEAR(MUTABLE_SV(cv)); /* prototype is "" */
12311+
if (*ps) {
12312+
SvPV_set(MUTABLE_SV(cv), ps);
12313+
SvCUR_set(MUTABLE_SV(cv), ps_len);
12314+
if (ps_utf8)
12315+
SvUTF8_on(MUTABLE_SV(cv));
12316+
}
12317+
else
12318+
if (CvMETHOD(cv))
12319+
sv_setpvs(MUTABLE_SV(cv), "$"); /* prototype for $self */
12320+
else
12321+
SvPVCLEAR(MUTABLE_SV(cv)); /* prototype is "" */
1231212322
CvXSUBANY(cv).any_ptr = const_sv;
1231312323
CvXSUB(cv) = S_const_sv_xsub;
1231412324
CvCONST_on(cv);
@@ -12796,7 +12806,7 @@ Perl_newATTRSUB_x(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs,
1279612806
}
1279712807

1279812808
if (!block
12799-
#ifndef USE_CPERL_not_yet
12809+
#ifndef USE_CPERL
1280012810
/* allow inlining of constant bodies on cperl even without empty proto*/
1280112811
|| !ps || *ps /* perl5: sub x{1} => no proto, so not inlinable */
1280212812
#endif
@@ -12898,7 +12908,17 @@ Perl_newATTRSUB_x(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs,
1289812908
the any_ptr as value*/
1289912909
assert(!CvROOT(cv) && !CvCONST(cv));
1290012910
cv_forget_slab(cv);
12901-
SvPVCLEAR(MUTABLE_SV(cv)); /* prototype is "" */
12911+
if (*ps) {
12912+
SvPV_set(MUTABLE_SV(cv), ps);
12913+
SvCUR_set(MUTABLE_SV(cv), ps_len);
12914+
if (ps_utf8)
12915+
SvUTF8_on(MUTABLE_SV(cv));
12916+
}
12917+
else
12918+
if (CvMETHOD(cv))
12919+
sv_setpvs(MUTABLE_SV(cv), "$"); /* prototype for $self */
12920+
else
12921+
SvPVCLEAR(MUTABLE_SV(cv)); /* prototype is "" */
1290212922
CvXSUBANY(cv).any_ptr = const_sv;
1290312923
CvXSUB(cv) = S_const_sv_xsub;
1290412924
CvCONST_on(cv);

0 commit comments

Comments
 (0)