-
Notifications
You must be signed in to change notification settings - Fork 584
Optimise away empty if{}, elsif{}. and else {} blocks #23367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: blead
Are you sure you want to change the base?
Conversation
This is a replacement for Perl#22745, which aimed to prevent the associated `OP_STUB` from being created in `Perl_newCONDOP` and subsequently removed in peep.c. However, doing that turned out to be unavoidable, since it is not safe to omit the `OP_STUB` if it is in scalar context, but `Perl_newCONDOP` runs before context is applied. This commit: * Re-adds the logic in `Perl_op_scope` to not wrap a bare `OP_STUB` in an `ENTER/LEAVE` pair. * Removes any relevant `OP_STUB`s in non-scalar context in `Perl_rpeep`. * Adds B::Deparse support * Adds a test based on the failures seen in Perl#22866
This commit optimises away the OP_STUB associated with an empty `true` branch of an `OP_COND_EXPR`. The `OPf_SPECIAL` flag has been brought into use on the `OP_COND_EXPR` to indicate that it is the `else`, not the `if`, block that has been optimised away. This is purely for the benefit of B::Deparse.
e6e5fef
to
326e2e2
Compare
troll argument: will this "break" or change flaky PP single stepping to extra crispy flaky PP single stepping? I don't have the time to compile this PR and do a deep dive on how Komodo's red dots and yellow arrow behave B4/AF when Im rapid tapping F11. The yellow arrow has never been perfect for me, 5.10 thru blead, its good enough for me, its not perfect. The yellow arrow has always gotten weird around constant folded if elsif {} braces and loop open loop close {} braces since I wrote PP hello world. Update: BBQ glazed step rolls argument: Will this PR break https://metacpan.org/pod/Enbugger ? @bulk88 last used https://metacpan.org/pod/Enbugger in 2016. After 2016 he reverse engineered Komodo's PP DBR's PP DBR injector code, along with rev engineering and synthesizing cmd line Even better is CPAN authors who have a secure coding policy of |
Also, more seriously, would this optimization degrade or break NYTProf? ? |
I'll try to check at the weekend. I haven't used Komodo in yonks. |
Note: this is an (extended) replacement for #22745
These commits:
Perl_op_scope
so that a bareOP_STUB
is not wrapped in anOP_ENTER/OP_LEAVE
pair.Perl_rpeep
to remove the thatOP_STUB
when it is safe to do so (not in scalar context).Tests and
B::Deparse
support are included.For example, given
my $x; if ($x) {print 1} else {}
, the relevant piece of the optree looked like this before:With these commits, it looks like: