Front page | perl.perl5.porters |
Postings from April 2008
Re: Make built-in list functions continuous
Thread Previous
|
Thread Next
From:
Steffen Mueller
Date:
April 2, 2008 08:10
Subject:
Re: Make built-in list functions continuous
Message ID:
47F3A1C6.4040505@sneakemail.com
Hi Dave, hi all,
Dave Mitchell wrote:
> Generally, optimisations that involve examining an area of the optree looking
> for a particular pattern and replacing it with something else, are hard
> to do, and are very fragile - a slight change to the optree (something as
> trivial as an op_null added or removed by some other fix), and the
> optimisation gets inadvertently disabled, or worse, breaks things.
it's interesting that this discussion happens just now that I've been
playing with op trees. I've been doing that with Perl, B, and B::Utils.
Essentially, I just dumped the op tree, that I wanted to match, with
B::Concise and wrote a pattern recognized by B::Utils::opgrep(). As a
cheap optimization, I added op_or() to B::Utils to create disjunctions
for matching similar op trees.
Still, this was a tedious task prone to errors. Given that I was
experimenting, the pattern I created wasn't testing *all* properties of
the ops. Mostly just names and its descendants. I thought about trying
it against a large body of code to see if it gives any false positives,
but haven't convinced myself that's more important than other tasks.
If I was to make the matching just a bit stricter, I fancy it could be
safe enough to produce no false positives. Mind you, however, that I'm
looking at very simple trees. Right now, I'm hacking up a B::OP method
that dumps the underlying op tree as such an opgrep pattern according to
some options such as "match name and flags attributes", "recurse into
kids", etc. Then, I'd have to write some code to replace common sections
of two related patterns with disjunctions. With that done, it should be
reasonably simple to read-only match against op trees and construct new
patterns. (Just write the Perl code you want to match.)
This entirely disregards any *changes* to op trees. I have not used
B::Generate. In order for the matching procedure above to be useful, it
would have to provide more info than just "matches" or not. It would
need to be able to extract information from the op tree so you don't
have to walk it again when generating the replacement ops. This would
end up suspiciously like the set of modules related to Template::Extract ;)
Sorry for the barely on-topic rant, but this whole op code thing is
really fun and interesting.*
Oh, and the hacks mentioned above mostly ended up in AutoXS::Accessor on
CPAN.
Cheers,
Steffen
* I'm strange like that sometimes.
Thread Previous
|
Thread Next