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

Commit 32d8499

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 c495c3e commit 32d8499

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
@@ -11497,7 +11497,17 @@ Perl_newMYSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
1149711497
CvSTASH_set(cv, PL_curstash);
1149811498
*spot = cv;
1149911499
}
11500-
SvPVCLEAR(MUTABLE_SV(cv)); /* prototype is "" */
11500+
if (*ps) {
11501+
SvPV_set(MUTABLE_SV(cv), ps);
11502+
SvCUR_set(MUTABLE_SV(cv), ps_len);
11503+
if (ps_utf8)
11504+
SvUTF8_on(MUTABLE_SV(cv));
11505+
}
11506+
else
11507+
if (CvMETHOD(cv))
11508+
sv_setpvs(MUTABLE_SV(cv), "$"); /* prototype for $self */
11509+
else
11510+
SvPVCLEAR(MUTABLE_SV(cv)); /* prototype is "" */
1150111511
CvXSUBANY(cv).any_ptr = const_sv;
1150211512
CvXSUB(cv) = S_const_sv_xsub;
1150311513
CvCONST_on(cv);
@@ -11981,7 +11991,7 @@ Perl_newATTRSUB_x(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs,
1198111991
}
1198211992

1198311993
if (!block
11984-
#ifndef USE_CPERL_not_yet
11994+
#ifndef USE_CPERL
1198511995
/* allow inlining of constant bodies on cperl even without empty proto*/
1198611996
|| !ps || *ps /* perl5: sub x{1} => no proto, so not inlinable */
1198711997
#endif
@@ -12083,7 +12093,17 @@ Perl_newATTRSUB_x(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs,
1208312093
the any_ptr as value*/
1208412094
assert(!CvROOT(cv) && !CvCONST(cv));
1208512095
cv_forget_slab(cv);
12086-
SvPVCLEAR(MUTABLE_SV(cv)); /* prototype is "" */
12096+
if (*ps) {
12097+
SvPV_set(MUTABLE_SV(cv), ps);
12098+
SvCUR_set(MUTABLE_SV(cv), ps_len);
12099+
if (ps_utf8)
12100+
SvUTF8_on(MUTABLE_SV(cv));
12101+
}
12102+
else
12103+
if (CvMETHOD(cv))
12104+
sv_setpvs(MUTABLE_SV(cv), "$"); /* prototype for $self */
12105+
else
12106+
SvPVCLEAR(MUTABLE_SV(cv)); /* prototype is "" */
1208712107
CvXSUBANY(cv).any_ptr = const_sv;
1208812108
CvXSUB(cv) = S_const_sv_xsub;
1208912109
CvCONST_on(cv);

0 commit comments

Comments
 (0)