This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Compiler front-end produces a broken CFG
Type: behavior Stage: resolved
Components: Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Mark.Shannon Nosy List: BTaskaya, Dennis Sweeney, Mark.Shannon, pablogsal, yselivanov
Priority: normal Keywords: patch

Created on 2020-11-13 17:23 by Mark.Shannon, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 23267 merged Mark.Shannon, 2020-11-13 17:27
Messages (4)
msg380911 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2020-11-13 17:23
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.
msg381279 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2020-11-17 19:30
New changeset 266b462238bddec0213effad3650f19c56511e9f by Mark Shannon in branch 'master':
bpo-42349: Compiler clean up. More yak-shaving for PEP 626. (GH-23267)
https://github.com/python/cpython/commit/266b462238bddec0213effad3650f19c56511e9f
msg395127 - (view) Author: Dennis Sweeney (Dennis Sweeney) * (Python committer) Date: 2021-06-04 21:54
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?
msg395261 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2021-06-07 10:46
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.
History
Date User Action Args
2022-04-11 14:59:38adminsetgithub: 86515
2021-06-07 10:46:33Mark.Shannonsetmessages: + msg395261
2021-06-04 21:54:58Dennis Sweeneysetnosy: + Dennis Sweeney
messages: + msg395127
2020-11-23 16:49:14Mark.Shannonsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-11-17 19:30:25Mark.Shannonsetmessages: + msg381279
2020-11-13 17:27:22Mark.Shannonsetkeywords: + patch
stage: patch review
pull_requests: + pull_request22163
2020-11-13 17:23:56Mark.Shannoncreate