From b69416024cb4c70f428a28aa0e22c86b2494d3bd Mon Sep 17 00:00:00 2001 From: Reini Urban Date: Fri, 26 Jun 2015 13:58:08 +0200 Subject: [PATCH] proto: activate sub inlining without () proto MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- op.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/op.c b/op.c index 4779741ae7e..463de0cbefd 100644 --- a/op.c +++ b/op.c @@ -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); @@ -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 @@ -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);