Skip to content
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

Nested if/else gets phantom else trace again (3.10) #89003

Closed
nedbat opened this issue Aug 5, 2021 · 4 comments
Closed

Nested if/else gets phantom else trace again (3.10) #89003

nedbat opened this issue Aug 5, 2021 · 4 comments
Labels
3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@nedbat
Copy link
Member

nedbat commented Aug 5, 2021

BPO 44840
Nosy @nedbat, @markshannon, @skirpichev, @pablogsal
PRs
  • bpo-44840: Compiler: Move duplication of exit blocks with no line numbers to after CFG optimization. #27656
  • [3.10] bpo-44840: Compiler: Move duplication of exit blocks with no line numbers to after CFG optimization. (GH-27656) #27673
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-08-09.11:45:36.803>
    created_at = <Date 2021-08-05.13:11:40.354>
    labels = ['interpreter-core', 'type-bug', '3.10']
    title = 'Nested if/else gets phantom else trace again (3.10)'
    updated_at = <Date 2021-08-09.11:45:36.803>
    user = 'https://github.com/nedbat'

    bugs.python.org fields:

    activity = <Date 2021-08-09.11:45:36.803>
    actor = 'pablogsal'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-08-09.11:45:36.803>
    closer = 'pablogsal'
    components = ['Interpreter Core']
    creation = <Date 2021-08-05.13:11:40.354>
    creator = 'nedbat'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 44840
    keywords = ['patch', '3.10regression']
    message_count = 4.0
    messages = ['399003', '399251', '399253', '399255']
    nosy_count = 4.0
    nosy_names = ['nedbat', 'Mark.Shannon', 'Sergey.Kirpichev', 'pablogsal']
    pr_nums = ['27656', '27673']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue44840'
    versions = ['Python 3.10']

    @nedbat
    Copy link
    Member Author

    nedbat commented Aug 5, 2021

    Note: this is very similar to https://bugs.python.org/issue42810
    This was originally reported against coverage.py: nedbat/coveragepy#1205

    ---8<-------------

    import linecache, sys
    
    def trace(frame, event, arg):
        # The weird globals here is to avoid a NameError on shutdown...
        if frame.f_code.co_filename == globals().get("__file__"):
            lineno = frame.f_lineno
            print("{} {}: {}".format(event[:4], lineno, linecache.getline(__file__, lineno).rstrip()))
        return trace
    
    print(sys.version)
    sys.settrace(trace)
    
    def func():
        if A:
            if B:
                if C:
                    if D:
                        return False
            else:
                return False
        elif E and F:
            return True
    
    A = B = True
    C = False
    
    func()

    This produces this trace output:

    3.10.0rc1 (default, Aug 3 2021, 15:03:55) [Clang 12.0.0 (clang-1200.0.32.29)]
    call 13: def func():
    line 14: if A:
    line 15: if B:
    line 16: if C:
    line 21: elif E and F:
    retu 21: elif E and F:

    The elif on line 21 is not executed, and should not be traced.

    Also, if I change line 21 to `elif E:`, then the trace changes to:

    3.10.0rc1 (default, Aug 3 2021, 15:03:55) [Clang 12.0.0 (clang-1200.0.32.29)]
    call 13: def func():
    line 14: if A:
    line 15: if B:
    line 16: if C:
    line 22: return True
    retu 22: return True

    @nedbat nedbat added 3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Aug 5, 2021
    @markshannon
    Copy link
    Member

    New changeset b854557 by Mark Shannon in branch 'main':
    bpo-44840: Compiler: Move duplication of exit blocks with no line numbers to after CFG optimization. (GH-27656)
    b854557

    @pablogsal
    Copy link
    Member

    New changeset 762ef85 by Mark Shannon in branch '3.10':
    bpo-44840: Compiler: Move duplication of exit blocks with no line numbers to after CFG optimization. (GH-27656) (bpo-27673)
    762ef85

    @nedbat
    Copy link
    Member Author

    nedbat commented Aug 9, 2021

    This fix looks good, thanks.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants