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

Compiler front-end produces a broken CFG #86515

Closed
markshannon opened this issue Nov 13, 2020 · 4 comments
Closed

Compiler front-end produces a broken CFG #86515

markshannon opened this issue Nov 13, 2020 · 4 comments
Assignees
Labels
type-bug An unexpected behavior, bug, or error

Comments

@markshannon
Copy link
Member

BPO 42349
Nosy @markshannon, @1st1, @pablogsal, @isidentical, @sweeneyde
PRs
  • bpo-42349: Compiler clean up. More yak-shaving for PEP 626. #23267
  • 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 = 'https://github.com/markshannon'
    closed_at = <Date 2020-11-23.16:49:14.501>
    created_at = <Date 2020-11-13.17:23:56.612>
    labels = ['type-bug']
    title = 'Compiler front-end produces a broken CFG'
    updated_at = <Date 2021-06-07.10:46:33.760>
    user = 'https://github.com/markshannon'

    bugs.python.org fields:

    activity = <Date 2021-06-07.10:46:33.760>
    actor = 'Mark.Shannon'
    assignee = 'Mark.Shannon'
    closed = True
    closed_date = <Date 2020-11-23.16:49:14.501>
    closer = 'Mark.Shannon'
    components = []
    creation = <Date 2020-11-13.17:23:56.612>
    creator = 'Mark.Shannon'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 42349
    keywords = ['patch']
    message_count = 4.0
    messages = ['380911', '381279', '395127', '395261']
    nosy_count = 5.0
    nosy_names = ['Mark.Shannon', 'yselivanov', 'pablogsal', 'BTaskaya', 'Dennis Sweeney']
    pr_nums = ['23267']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue42349'
    versions = []

    @markshannon
    Copy link
    Member Author

    The front-end of the bytecode compiler produces a broken CFG.
    A number of "basic-block"s have terminators before their end.
    This makes the back-end optimizations unsafe as they rely of a well-formed CFG.

    The fix is simple. Insert a check that the CFG is well-formed before doing any optimizations, then fix up the front-end.

    Once done, we can be more aggressive with optimizations without worrying that things will break for no apparent reason.

    @markshannon markshannon self-assigned this Nov 13, 2020
    @markshannon markshannon added the type-bug An unexpected behavior, bug, or error label Nov 13, 2020
    @markshannon
    Copy link
    Member Author

    New changeset 266b462 by Mark Shannon in branch 'master':
    bpo-42349: Compiler clean up. More yak-shaving for PEP-626. (GH-23267)
    266b462

    @sweeneyde
    Copy link
    Member

    From https://devguide.python.org/compiler/#source-code-to-ast:

    Basic blocks themselves are a block of IR that has a single entry point but possibly multiple exit points.

    In particular, compile.c's label_exception_targets has the assertion (assert(i == b->b_iused -1);) that jumps only occur as the last instruction of a block.

    Does the devguide need updating, or do I have a misunderstanding?

    @markshannon
    Copy link
    Member Author

    Basic blocks have only a single exit, at the end.
    https://en.wikipedia.org/wiki/Basic_block

    If the devguide says otherwise it is wrong.

    @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
    type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants