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

Commit

Permalink
proto: activate sub inlining without () proto
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Reini Urban authored and rurban committed Apr 30, 2019
1 parent d858dc8 commit b694160
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions op.c
Original file line number Diff line number Diff line change
Expand Up @@ -11561,7 +11561,17 @@ Perl_newMYSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
CvSTASH_set(cv, PL_curstash);
*spot = cv;
}
SvPVCLEAR(MUTABLE_SV(cv)); /* prototype is "" */
if (*ps) {
SvPV_set(MUTABLE_SV(cv), ps);
SvCUR_set(MUTABLE_SV(cv), ps_len);
if (ps_utf8)
SvUTF8_on(MUTABLE_SV(cv));
}
else
if (CvMETHOD(cv))
sv_setpvs(MUTABLE_SV(cv), "$"); /* prototype for $self */
else
SvPVCLEAR(MUTABLE_SV(cv)); /* prototype is "" */
CvXSUBANY(cv).any_ptr = const_sv;
CvXSUB(cv) = S_const_sv_xsub;
CvCONST_on(cv);
Expand Down Expand Up @@ -12045,7 +12055,7 @@ Perl_newATTRSUB_x(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs,
}

if (!block
#ifndef USE_CPERL_not_yet
#ifndef USE_CPERL
/* allow inlining of constant bodies on cperl even without empty proto*/
|| !ps || *ps /* perl5: sub x{1} => no proto, so not inlinable */
#endif
Expand Down Expand Up @@ -12147,7 +12157,17 @@ Perl_newATTRSUB_x(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs,
the any_ptr as value*/
assert(!CvROOT(cv) && !CvCONST(cv));
cv_forget_slab(cv);
SvPVCLEAR(MUTABLE_SV(cv)); /* prototype is "" */
if (*ps) {
SvPV_set(MUTABLE_SV(cv), ps);
SvCUR_set(MUTABLE_SV(cv), ps_len);
if (ps_utf8)
SvUTF8_on(MUTABLE_SV(cv));
}
else
if (CvMETHOD(cv))
sv_setpvs(MUTABLE_SV(cv), "$"); /* prototype for $self */
else
SvPVCLEAR(MUTABLE_SV(cv)); /* prototype is "" */
CvXSUBANY(cv).any_ptr = const_sv;
CvXSUB(cv) = S_const_sv_xsub;
CvCONST_on(cv);
Expand Down

0 comments on commit b694160

Please sign in to comment.