develooper Front page | perl.perl5.porters | Postings from July 2012

[perl #49594] A bug on constant overloading

Thread Previous
Jesse Luehrs via RT
July 2, 2012 02:25
[perl #49594] A bug on constant overloading
Message ID:
So I tracked this through the lexer, and this is what I've come up with:

When perl is reading a string, the first pass doesn't handle
interpolation. It first just reads the string verbatim (except that it
unescapes all escaped delimiters), and then checks to see if it has any
characters in that buffer which could require interpolation (either
variable or escape sequence interpolation). If it does, it goes through
to try to break down the string and do whatever interpolation it can,
and then sticks a stringify op on top of that.

In the case of "$foo", this just builds an optree of stringify(padsv),
and nothing else is done.

In the case of "foo $bar baz", this is broken down into "foo " . $bar .
" baz", and the "foo " and " baz" bits are fed to overload::constant.
Then, when that optree goes through the optimizer, it sees
stringify(concat(concat(const, padsv), const)), and realizes that
stringify(concat(...)) is redundant, and optimizes the stringify away
(so the const ops are never modified from what the overload::constant
sub returned).

In the case of "foo\tbar", it reads through the string, replaces \t with
a literal tab, and passes the resulting string to overload::constant as
before. Then, when that optree goes through the optimizer, it sees just
stringify(const), which is able to be constant folded, and so it does
so, leaving a const op containing the stringified form of whatever the
overload::constant sub returned.

I really have no idea where to go from here, I've gotten to the point
where I can read the lexer, but not to the point where I'm capable of
modifying it yet (without breaking things all over the place).

via perlbug:  queue: perl5 status: open

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About