summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Ragwitz <rafl@debian.org>2010-08-16 00:16:00 +0200
committerFlorian Ragwitz <rafl@debian.org>2010-08-16 00:18:20 +0200
commit666e7765a1af9c81577039073e9ff43b19d9110f (patch)
treeff72f5d3cf5cbe011e1115e67bbe74dfd153b114
parent874cd4e1c18d04983efb99e1366ac237240dcd07 (diff)
downloadperl-666e7765a1af9c81577039073e9ff43b19d9110f.tar.gz
Revert "Make the peep recurse via PL_peepp"
This reverts commit 65bfe90c4b4ea5706a50067179e60d4e8de6807a. While it made a few of the things I wanted possible, a couple of other things one might need to do and I thought this change would enable don't actually work. Thanks Zefram for pointing out my mistake. Conflicts: ext/XS-APItest/APItest.xs op.c
-rw-r--r--MANIFEST1
-rw-r--r--embed.fnc2
-rw-r--r--embed.h2
-rw-r--r--ext/XS-APItest/APItest.xs47
-rw-r--r--ext/XS-APItest/t/peep.t39
-rw-r--r--op.c27
-rw-r--r--perl.h8
-rw-r--r--pod/perl5134delta.pod8
-rw-r--r--pod/perlguts.pod60
-rw-r--r--proto.h6
10 files changed, 15 insertions, 185 deletions
diff --git a/MANIFEST b/MANIFEST
index 0946e2474e..4744efd5b6 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -3290,7 +3290,6 @@ ext/XS-APItest/t/my_cxt.t XS::APItest: test MY_CXT interface
ext/XS-APItest/t/my_exit.t XS::APItest: test my_exit
ext/XS-APItest/t/Null.pm Helper for ./blockhooks.t
ext/XS-APItest/t/op.t XS::APItest: tests for OP related APIs
-ext/XS-APItest/t/peep.t Test hooking PL_peepp
ext/XS-APItest/t/pmflag.t Test removal of Perl_pmflag()
ext/XS-APItest/t/printf.t XS::APItest extension
ext/XS-APItest/t/ptr_table.t Test ptr_table_* APIs
diff --git a/embed.fnc b/embed.fnc
index 38e1d27e94..1e27e88bc7 100644
--- a/embed.fnc
+++ b/embed.fnc
@@ -888,7 +888,7 @@ sd |void |pad_reset
: Used in op.c
pd |void |pad_swipe |PADOFFSET po|bool refadjust
: FIXME
-p |void |peep |NULLOK OP* o|NN peep_next_t *next_peep
+p |void |peep |NULLOK OP* o
: Defined in doio.c, used only in pp_hot.c
dopM |PerlIO*|start_glob |NN SV *tmpglob|NN IO *io
#if defined(USE_REENTRANT_API)
diff --git a/embed.h b/embed.h
index 4eb163187d..51be599588 100644
--- a/embed.h
+++ b/embed.h
@@ -3152,7 +3152,7 @@
#endif
#ifdef PERL_CORE
#define pad_swipe(a,b) Perl_pad_swipe(aTHX_ a,b)
-#define peep(a,b) Perl_peep(aTHX_ a,b)
+#define peep(a) Perl_peep(aTHX_ a)
#endif
#if defined(USE_REENTRANT_API)
#define reentrant_size() Perl_reentrant_size(aTHX)
diff --git a/ext/XS-APItest/APItest.xs b/ext/XS-APItest/APItest.xs
index 8dce9db805..23ce3edea5 100644
--- a/ext/XS-APItest/APItest.xs
+++ b/ext/XS-APItest/APItest.xs
@@ -17,8 +17,6 @@ typedef struct {
AV *cscav;
AV *bhkav;
bool bhk_record;
- peep_t orig_peep;
- AV *peep_record;
} my_cxt_t;
START_MY_CXT
@@ -329,23 +327,6 @@ blockhook_test_eval(pTHX_ OP *const o)
STATIC BHK bhk_csc, bhk_test;
-STATIC void
-my_peep (pTHX_ OP *o, peep_next_t *next_peep)
-{
- dMY_CXT;
-
- if (!o)
- return;
-
- CALL_FPTR(MY_CXT.orig_peep)(aTHX_ o, next_peep);
-
- for (; o; o = o->op_next) {
- if (o->op_type == OP_CONST && cSVOPx_sv(o) && SvPOK(cSVOPx_sv(o))) {
- av_push(MY_CXT.peep_record, newSVsv(cSVOPx_sv(o)));
- }
- }
-}
-
#include "const-c.inc"
MODULE = XS::APItest:Hash PACKAGE = XS::APItest::Hash
@@ -742,8 +723,6 @@ BOOT:
BhkENTRY_set(&bhk_csc, start, blockhook_csc_start);
BhkENTRY_set(&bhk_csc, pre_end, blockhook_csc_pre_end);
Perl_blockhook_register(aTHX_ &bhk_csc);
-
- MY_CXT.peep_record = newAV();
}
void
@@ -756,7 +735,6 @@ CLONE(...)
MY_CXT.cscav = NULL;
MY_CXT.bhkav = get_av("XS::APItest::bhkav", GV_ADDMULTI);
MY_CXT.bhk_record = 0;
- MY_CXT.peep_record = newAV();
void
print_double(val)
@@ -1136,31 +1114,6 @@ bhk_record(bool on)
if (on)
av_clear(MY_CXT.bhkav);
-void
-peep_enable ()
- PREINIT:
- dMY_CXT;
- CODE:
- av_clear(MY_CXT.peep_record);
- MY_CXT.orig_peep = PL_peepp;
- PL_peepp = my_peep;
-
-AV *
-peep_record ()
- PREINIT:
- dMY_CXT;
- CODE:
- RETVAL = MY_CXT.peep_record;
- OUTPUT:
- RETVAL
-
-void
-peep_record_clear ()
- PREINIT:
- dMY_CXT;
- CODE:
- av_clear(MY_CXT.peep_record);
-
BOOT:
{
HV* stash;
diff --git a/ext/XS-APItest/t/peep.t b/ext/XS-APItest/t/peep.t
deleted file mode 100644
index fa61dc3420..0000000000
--- a/ext/XS-APItest/t/peep.t
+++ /dev/null
@@ -1,39 +0,0 @@
-#!perl -w
-
-BEGIN {
- push @INC, "::lib:$MacPerl::Architecture:" if $^O eq 'MacOS';
- require Config; import Config;
- if ($Config{'extensions'} !~ /\bXS\/APItest\b/) {
- # Look, I'm using this fully-qualified variable more than once!
- my $arch = $MacPerl::Architecture;
- print "1..0 # Skip: XS::APItest was not built\n";
- exit 0;
- }
-}
-
-use strict;
-use warnings;
-
-BEGIN {
- require '../../t/test.pl';
- plan(6);
- use_ok('XS::APItest')
-};
-
-my $record = XS::APItest::peep_record;
-
-XS::APItest::peep_enable;
-
-# our peep got called and remembered the string constant
-eval q[my $foo = q/affe/];
-is(scalar @{ $record }, 1);
-is($record->[0], 'affe');
-
-XS::APItest::peep_record_clear;
-
-# peep got called for each root op of the branch
-$::moo = $::moo = 0;
-eval q[my $foo = $::moo ? q/x/ : q/y/];
-is(scalar @{ $record }, 2);
-is($record->[0], 'x');
-is($record->[1], 'y');
diff --git a/op.c b/op.c
index 08b795416a..5a0962bbb3 100644
--- a/op.c
+++ b/op.c
@@ -103,16 +103,7 @@ recursive, but it's recursive on basic blocks, not on tree nodes.
#include "perl.h"
#include "keywords.h"
-#define CALL_A_PEEP(peep, o) CALL_FPTR((peep)->fn)(aTHX_ o, peep)
-
-#define CALL_PEEP(o) \
- STMT_START { \
- peep_next_t _next_peep; \
- _next_peep.fn = PL_peepp; \
- _next_peep.user_data = NULL; \
- CALL_A_PEEP(&_next_peep, o); \
- } STMT_END
-
+#define CALL_PEEP(o) CALL_FPTR(PL_peepp)(aTHX_ o)
#define CALL_OPFREEHOOK(o) if (PL_opfreehook) CALL_FPTR(PL_opfreehook)(aTHX_ o)
#if defined(PL_OP_SLAB_ALLOC)
@@ -8524,13 +8515,11 @@ S_is_inplace_av(pTHX_ OP *o, OP *oright) {
* peep() is called */
void
-Perl_peep(pTHX_ register OP *o, peep_next_t *next_peep)
+Perl_peep(pTHX_ register OP *o)
{
dVAR;
register OP* oldop = NULL;
- PERL_ARGS_ASSERT_PEEP;
-
if (!o || o->op_opt)
return;
ENTER;
@@ -8725,7 +8714,7 @@ Perl_peep(pTHX_ register OP *o, peep_next_t *next_peep)
sop = fop->op_sibling;
while (cLOGOP->op_other->op_type == OP_NULL)
cLOGOP->op_other = cLOGOP->op_other->op_next;
- CALL_A_PEEP(next_peep, cLOGOP->op_other); /* Recursive calls are not replaced by fptr calls */
+ peep(cLOGOP->op_other); /* Recursive calls are not replaced by fptr calls */
stitch_keys:
o->op_opt = 1;
@@ -8776,20 +8765,20 @@ Perl_peep(pTHX_ register OP *o, peep_next_t *next_peep)
case OP_ONCE:
while (cLOGOP->op_other->op_type == OP_NULL)
cLOGOP->op_other = cLOGOP->op_other->op_next;
- CALL_A_PEEP(next_peep, cLOGOP->op_other); /* Recursive calls are not replaced by fptr calls */
+ peep(cLOGOP->op_other); /* Recursive calls are not replaced by fptr calls */
break;
case OP_ENTERLOOP:
case OP_ENTERITER:
while (cLOOP->op_redoop->op_type == OP_NULL)
cLOOP->op_redoop = cLOOP->op_redoop->op_next;
- CALL_A_PEEP(next_peep, cLOOP->op_redoop);
+ peep(cLOOP->op_redoop);
while (cLOOP->op_nextop->op_type == OP_NULL)
cLOOP->op_nextop = cLOOP->op_nextop->op_next;
- CALL_A_PEEP(next_peep, cLOOP->op_nextop);
+ peep(cLOOP->op_nextop);
while (cLOOP->op_lastop->op_type == OP_NULL)
cLOOP->op_lastop = cLOOP->op_lastop->op_next;
- CALL_A_PEEP(next_peep, cLOOP->op_lastop);
+ peep(cLOOP->op_lastop);
break;
case OP_SUBST:
@@ -8798,7 +8787,7 @@ Perl_peep(pTHX_ register OP *o, peep_next_t *next_peep)
cPMOP->op_pmstashstartu.op_pmreplstart->op_type == OP_NULL)
cPMOP->op_pmstashstartu.op_pmreplstart
= cPMOP->op_pmstashstartu.op_pmreplstart->op_next;
- CALL_A_PEEP(next_peep, cPMOP->op_pmstashstartu.op_pmreplstart);
+ peep(cPMOP->op_pmstashstartu.op_pmreplstart);
break;
case OP_EXEC:
diff --git a/perl.h b/perl.h
index 74fb62ecb7..1def000bf7 100644
--- a/perl.h
+++ b/perl.h
@@ -4841,13 +4841,7 @@ struct perl_debug_pad {
PERL_DEBUG_PAD(i))
/* Enable variables which are pointers to functions */
-struct peep_next;
-typedef void (CPERLscope(*peep_t))(pTHX_ OP* o, struct peep_next *next);
-typedef struct peep_next {
- peep_t fn;
- void *user_data;
-} peep_next_t;
-
+typedef void (CPERLscope(*peep_t))(pTHX_ OP* o);
typedef regexp*(CPERLscope(*regcomp_t)) (pTHX_ char* exp, char* xend, PMOP* pm);
typedef I32 (CPERLscope(*regexec_t)) (pTHX_ regexp* prog, char* stringarg,
char* strend, char* strbeg, I32 minend,
diff --git a/pod/perl5134delta.pod b/pod/perl5134delta.pod
index b7398e33d7..dfd73c1b49 100644
--- a/pod/perl5134delta.pod
+++ b/pod/perl5134delta.pod
@@ -532,14 +532,6 @@ contains a more specific escape hatch:
This can be used for modules that have not been upgraded to 5.6 naming
conventions (and really should be completely obsolete by now).
-=item Make extending the peephole optimizer easier
-
-As of version 5.8, extension authors were allowed to replace perl's peephole
-optimizer function. However, this was B<very> hard to do, as there was no way to
-add new optimizations without having to copy large parts of perl's original
-optimizer. This problem is now solved by a rework of the optimizer extension
-API. See L<perlguts/"Compile pass 3: peephole optimization"> for details.
-
=item C<Perl_grok_bslash_o> and C<Perl_grok_bslash_c> may change in future
The functions C<Perl_grok_bslash_o> and C<Perl_grok_bslash_c>, which are public
diff --git a/pod/perlguts.pod b/pod/perlguts.pod
index 6a244b7d79..62e99bd386 100644
--- a/pod/perlguts.pod
+++ b/pod/perlguts.pod
@@ -1821,63 +1821,9 @@ of free()ing (i.e. their type is changed to OP_NULL).
After the compile tree for a subroutine (or for an C<eval> or a file)
is created, an additional pass over the code is performed. This pass
is neither top-down or bottom-up, but in the execution order (with
-additional complications for conditionals). Optimizations performed
-at this stage are subject to the same restrictions as in the pass 2.
-
-Peephole optimizations are done by calling the function pointed to by
-the global variable C<PL_peepp>. By default, C<PL_peepp> points to the
-function C<Perl_peep>. However, extensions may provide their own
-peephole optimizers, like this:
-
- peep_t original_peep;
-
- void my_peep (pTHX_ OP *o, peep_next_t *next_peep)
- {
- /* Delegate perl's original optimizer. The function pointer
- * in next_peep->fn will point to the optimizer function
- * initially invoked, so when perl's peep recurses into some
- * branch of the optree, it'll call back to my_peep.
- */
- CALL_FPTR(original_peep)(aTHX_ o, next_peep);
-
- if (!o)
- return;
-
- for (; o; o = o->op_next) {
- /* custom optimisations */
- }
- }
-
- /* later, for example in a BOOT section */
- original_peep = PL_peepp;
- PL_peepp = my_peep;
-
-Do note that the peephole optimizer is called for each root of an
-optree. It has to traverse that optree itself, if necessary.
-
-However, it is not normally necessary for peep extensions to walk into
-branches of conditions. Perl's original optimizer, which extensions should
-always delegate to, already implements that and will call the optimizer
-pointed to by C<next_peep> for each root OP of branches. By default,
-C<next_peep> points to whatever is in C<PL_peepp>, but it is also possible
-to make the default optimizer call back to different optimizers:
-
- void my_peep (pTHX_ OP *o, peep_next_t *next_peep)
- {
- peep_next_t other_peep = { my_other_peep, NULL };
-
- /* call the original peep, and have it call my_other_peep when
- * recursing into branches */
- CALL_FPTR(original_peep)(aTHX_ o, &other_peep);
- }
-
-The second member of C<peep_next_t>, C<user_data>, which is just set to
-C<NULL> in the above example, may be used to pass along arbitrary data to
-later invocations of peep functions.
-
-Also note that, under some conditions, the peephole optimizer will be
-called with a C<NULL> opcode. That is perfectly normal and optimizer
-functions need to accomodate for that.
+additional complications for conditionals). These optimizations are
+done in the subroutine peep(). Optimizations performed at this stage
+are subject to the same restrictions as in the pass 2.
=head2 Pluggable runops
diff --git a/proto.h b/proto.h
index 39b88c57be..17c32129d9 100644
--- a/proto.h
+++ b/proto.h
@@ -2571,11 +2571,7 @@ PERL_CALLCONV void Perl_pad_free(pTHX_ PADOFFSET po);
STATIC void S_pad_reset(pTHX);
#endif
PERL_CALLCONV void Perl_pad_swipe(pTHX_ PADOFFSET po, bool refadjust);
-PERL_CALLCONV void Perl_peep(pTHX_ OP* o, peep_next_t *next_peep)
- __attribute__nonnull__(pTHX_2);
-#define PERL_ARGS_ASSERT_PEEP \
- assert(next_peep)
-
+PERL_CALLCONV void Perl_peep(pTHX_ OP* o);
PERL_CALLCONV PerlIO* Perl_start_glob(pTHX_ SV *tmpglob, IO *io)
__attribute__nonnull__(pTHX_1)
__attribute__nonnull__(pTHX_2);