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

GH-128534: Fix behavior of branch monitoring for `async for` by markshannon · Pull Request #130847 · python/cpython · GitHub

Repository navigation

GH-128534: Fix behavior of branch monitoring for async for - #130847

Merged
markshannon merged 10 commits into
python:mainfrom
faster-cpython:co-branch-async-for
Mar 7, 2025
Merged

markshannon merged 10 commits into
python:mainfrom
faster-cpython:co-branch-async-for

Conversation

markshannon commented Mar 4, 2025 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

This PR:

  • Makes sure that both the "left" and "right" branches have a common source
  • Adds the branches to co_branches.

@@ -0,0 +1,2 @@
Ensure that both and left branches have same source for ``async for`` loops.

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

grammar

Comment thread Python/assemble.c


// The offset (in code units) of the END_SEND from the SEND in the `yield from` sequence.
#define END_SEND_OFFSET 5

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

What is this 5? Is it related to the size of the RESUME and JUMP instructions between the YIELD and END_SEND?

markshannon Mar 6, 2025 •
edited
Loading

Copy link
Copy Markdown
Member Author

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

It's the distance from the SEND to the END_SEND in the instructions code units in the yield from/await sequence

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

Can we assert that the instruction at that distance is a SEND?

Comment thread Python/assemble.c Outdated
instr->i_oparg = target->i_offset;
if (instr->i_oparg < offset) {
if (instr->i_opcode == END_ASYNC_FOR) {
// Monitoring needs the target to be the END_SEND

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

I think this comment can be made clearer. We are not setting the target here, so I think what the comment is saying is "since the target is the end_send, we set the offset differently in this case". Right?

Comment thread Python/flowgraph.c
}
maxdepth = Py_MAX(maxdepth, depth + effects.max);
if (HAS_TARGET(instr->i_opcode)) {
if (HAS_TARGET(instr->i_opcode) && instr->i_opcode != END_ASYNC_FOR) {

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

Are you skipping END_ASYNC_FOR here because its target is not instr->i_target? Apart from that the assertion should hold.

Copy link
Copy Markdown
Member Author

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

Its skipped because there is no flow control edge from the END_ASYNC_FOR to its "target". The "target" is where the control flow comes from, which makes sense for co_branches but not otherwise.

markshannon merged commit 89df62c into python:main Mar 7, 2025
markshannon deleted the co-branch-async-for branch March 7, 2025 14:30
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL