← Back to Pull requests

Optimise away empty if{}, elsif{}. and else {} blocks #23367

Closed
unknown closed this pull request without merging on Jul 28, 2025 07:45 UTC
View on GitHub
unknown unknown commented on Jun 11, 2025 22:09 UTC
Author

Note: this is an (extended) replacement for https://github.com/Perl/perl5/pull/22745

These commits:
Change Perl_op_scope so that a bare OP_STUB is not wrapped in an OP_ENTER/OP_LEAVE pair.
Change Perl_rpeep to remove the that OP_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:

4     <;> nextstate(main 2 -e:1) v:{ ->5
-     <1> null vK/1 ->a
6        <|> cond_expr(other->7) vK/1 ->b
5           <0> padsv[$x:1,8] s ->6
-           <@> scope vK ->-
-              <;> ex-nextstate(main 4 -e:1) v ->7
9              <@> print vK ->a
7                 <0> pushmark s ->8
8                 <$> const[IV 1] s ->9
d           <@> leave vK ->a
b              <0> enter v ->c
c              <0> stub vP ->d

With these commits, it looks like:
4     <;> nextstate(main 2 -e:1) v:{ ->5
-     <1> null vK/1 ->a
6        <|> cond_expr(other->7) vK*/1 ->a
5           <0> padsv[$x:1,8] s ->6
-           <@> scope vK ->-
-              <;> ex-nextstate(main 4 -e:1) v ->7
9              <@> print vK ->a
7                 <0> pushmark s ->8
8                 <$> const[IV 1] s ->9

---------------------------------------------------------------------------------

  • I'm not sure if this set of changes requires a perldelta entry.
  • Diff: 181 lines (+135 / -46) across 2 files Reviewer: bulk88 Review duration: 66815m
    All Vouch review confidence checks passed
    Residual risk 0.14 = Change Risk (0.36) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.36 · 181 lines diff across 2 files
    0.36
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.311
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #23367"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 35.6% (MEDIUM) · Higher = larger blast radius
    35.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 14.1% · Safe to merge
    14.1%
    Repository