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: remove NEXT_BLOCK() from compile.c
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: iritkatriel Nosy List: Mark.Shannon, brandtbucher, iritkatriel
Priority: normal Keywords: patch

Created on 2022-02-20 14:48 by iritkatriel, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 31448 merged iritkatriel, 2022-02-20 14:50
Messages (3)
msg413589 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-02-20 14:48
The compiler currently requires the code-generation functions to explicitly specify where basic blocks end, with a NEXT_BLOCK().

If you get that wrong, you get an exception about "malformed control flow graph" later, in the cfg analysis stage. It is not obvious then where the error is, and it makes it difficult to make changes in the compiler. 

We can instead make the compiler implicitly create a new block when this is needed (which is after specific opcodes).
msg413615 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-02-20 23:06
The patch in PR31448 delays the creation of an implicit block to when it is needed (do if we begin using another block before a new instruction is added, the implicit block is never created). 

I counted how many empty blocks are being detected by the optimizer during "python -m test" and this number went down from 41798 (for main) to 35405 (for my PR), which shows that it is not only a theoretical possibility but actually happens. It would be things like:

NEXT_BLOCK()
VISIT_SEQ(c, stmt, s->v.Try.orelse);
compiler_use_next_block(c, end);

where the orelse block is empty.


In summary, the patch simplifies the code as well as making it more efficient.
msg413989 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2022-02-25 12:17
New changeset c579243eb62d3182c84004cd72dcf6ef59100643 by Irit Katriel in branch 'main':
bpo-46808: remove NEXT_BLOCK() from compile.c (GH-31448)
https://github.com/python/cpython/commit/c579243eb62d3182c84004cd72dcf6ef59100643
History
Date User Action Args
2022-04-11 14:59:56adminsetgithub: 90964
2022-02-28 19:44:10iritkatrielsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2022-02-25 18:34:34brandtbuchersetnosy: + brandtbucher
2022-02-25 12:17:54Mark.Shannonsetnosy: + Mark.Shannon
messages: + msg413989
2022-02-20 23:06:31iritkatrielsetmessages: + msg413615
2022-02-20 14:50:39iritkatrielsetkeywords: + patch
stage: patch review
pull_requests: + pull_request29576
2022-02-20 14:48:48iritkatrielcreate