Skip to content

peep.c: Only remove expected empty if/else block structures #23512

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

Open
wants to merge 1 commit into
base: blead
Choose a base branch
from

Conversation

richardleach
Copy link
Contributor

#23367 expected that empty OP_COND_EXPR
branches would produce one of the following OP tree structures fit for removal:

  +-- stub

or

  +-- scope
    |
    +-- stub

GH #23505 showed that { BEGIN {} } blocks will also generate the likes of:

  +--scope
    |
    +--stub
    |
    +--null (ex-nextstate)

This commit does the minimal possible to fix this bug - the peephole optimizer
now checks for the expected cases and ignores anything else.

Future commits may extend the optimization to remove this additional type of
structure. Additional tests have been added now and give a useful structure for
future commit tests to fit into.


  • This set of changes does not require a perldelta entry.

The expected OP tree structures for empty blocks fit for removal was:
```
  +-- stub
```
or
```
  +-- scope
    |
    +-- stub
```

GH Perl#23505 showed that `{ BEGIN {} }` blocks will also generate the likes of:
```
  +--scope
    |
    +--stub
    |
    +--null (ex-nextstate)
```

This commit does the minimal possible to fix this bug - the peephole optimizer
now checks for the expected cases and ignores anything else.

Future commits may build on this to remove this additional type of structure.
Additional tests have been added now and give a useful structure for future
commit tests to fit into.
@richardleach richardleach linked an issue Jul 30, 2025 that may be closed by this pull request
@richardleach
Copy link
Contributor Author

Rather than handling the BEGIN {} case in the peephole optimizer, it seems tidier to handle it back in Perl_op_scope, ensuring that one of the expected OP_STUB patterns results.

However, initial work showed that Perl_pmruntime and S_regmatch (case EVAL:) would have to be amended to recognise bare OP_STUBs. (It would be nice if S_regmatch could be made to not execute OP trees that are functionally no-ops.)

I'll work on this a bit more in the background.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BBC: Blead Breaks Test::Inter
1 participant