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

GH-112354: `END_FOR` instruction to only pop one value. by markshannon · Pull Request #114247 · python/cpython · GitHub

/ cpython Public

GH-112354: END_FOR instruction to only pop one value. - #114247

Merged
markshannon merged 8 commits into
python:mainfrom
faster-cpython:split-end-for
Jan 24, 2024
Merged

GH-112354: END_FOR instruction to only pop one value.#114247
markshannon merged 8 commits into
python:mainfrom
faster-cpython:split-end-for

Conversation

markshannon commented Jan 18, 2024
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

In order to support tier 2 side-exits from FOR_ITER variants, we need a target that has the same stack as the exhaustion guard.
Currently we can either jump to the END_FOR, as we do for generators or the instruction afterwards, which we do for FOR_ITER.
In order to exit a guard we need a target in between those instructions, that pops the iterator, but not the value.
The compiler emits END_FOR; POP_TOP instead of END_FOR.
Previously:

   END_FOR (Pops two values) <- FOR_ITEN_GEN targets this
   ...                       <- FOR_ITER targets this

Now:

   END_FOR (Pops one value)  <- FOR_ITEN_GEN targets this
   POP_TOP (Pops one value)  <- _GUARD_NOT_EXHAUSTED can target this
   ...                       <- FOR_ITER targets this

gvanrossum commented Jan 18, 2024
edited
Loading

Copy link
Copy Markdown
Member

Maybe we can do without a separate END_FOR opcode and instead just generate a POP_TOP?

EDIT: Never mind, it's needed for instrumentation.

gvanrossum left a comment

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

Looks good, never mind my premature commend about END_FOR/POP_TOP.

Comment on lines +672 to +674
string = &_Py_ID(alias);
assert(_PyUnicode_CheckConsistency(string, 1));
_PyUnicode_InternInPlace(interp, &string);

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

(The updates to this file (and a few other generated files) are spurious and will disappear after merging the latest main.)

Copy link
Copy Markdown
Member Author

The benchmarks show no performance impact.

Copy link
Copy Markdown
Member Author

EDIT: Never mind, it's needed for instrumentation.

That's evidently not clear. The order of the POP_TOP and END_FOR is important as well.
I'll add some comments.

gvanrossum left a comment

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

Thanks!

brettcannon removed their request for review January 19, 2024 18:31

Copy link
Copy Markdown
Member

Oh, fun stuff. Windows compilation error. :-(

markshannon merged commit 981d172 into python:main Jan 24, 2024
markshannon deleted the split-end-for branch February 1, 2024 19:50
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
…GH-114247)

* Compiler emits END_FOR; POP_TOP instead of END_FOR. To support tier 2 side exits in loops.
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
…GH-114247)

* Compiler emits END_FOR; POP_TOP instead of END_FOR. To support tier 2 side exits in loops.
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.

3 participants


Back | FazBrowse Home | New Git URL