FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-107901: make compiler inline basic blocks with no line number and no fallthrough by iritkatriel · Pull Request #114750 · python/cpython · GitHub

/ cpython Public

gh-107901: make compiler inline basic blocks with no line number and no fallthrough - #114750

Merged
iritkatriel merged 4 commits into
python:mainfrom
iritkatriel:inline-blocks-without-lineno
Feb 2, 2024
Merged

iritkatriel merged 4 commits into
python:mainfrom
iritkatriel:inline-blocks-without-lineno

Conversation

iritkatriel commented Jan 30, 2024
edited
Loading

Copy link
Copy Markdown
Member

This pattern shows up in code like this:

def f():         
    for e in seq:
        try:
            X = 3
        except OSError:
            try:
                if C3:
                    X = 4
            except OSError:
                pass
    return 42

We have a block with no line number, and two predecessors, which contains a jump to another block that has no line number. The two-predecessor block is not an exit block so it is not duplicated. As a result, the end block remains with no line number, even if it needs one. This change inlines the first block to each of its predecessors, so that the jump can get a line number.

Copy link
Copy Markdown
Member

Two questions.

  • Does this fix handle triply nested try-excepts?
  • Is it feasible to add a test for this?

Copy link
Copy Markdown
Member Author
  • Does this fix handle triply nested try-excepts?

It does. The issue is not the nesting, but the multiple paths leading to the end of the except block. It needs to be nested in another except because otherwise the blocks get reordered and this impacts the situation. But with nesting all the blocks are cold, so they remain in this order. More nesting doesn't make a difference.

  • Is it feasible to add a test for this?

I'll try to add a unit test.

This PR makes the build pass with the assertion that all eval break checks have line numbers (there are 3 more test failures then, but at least we get through the build).

markshannon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Looks good

iritkatriel merged commit 2091fb2 into python:main Feb 2, 2024
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
fsc-eriker pushed a commit to fsc-eriker/cpython that referenced this pull request Feb 14, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL