Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -832,11 +832,16 @@ not have to be) the original ``STACK[-2]``.

.. opcode:: GET_ANEXT

Implement ``STACK.append(get_awaitable(STACK[-1].__anext__()))`` to the stack.
Implement ``STACK.append(get_awaitable(STACK[-1].__anext__()))`` to the stack,
then push ``NULL`` and ``None``, ready for :opcode:`SEND`.
See ``GET_AWAITABLE`` for details about ``get_awaitable``.

.. versionadded:: 3.5

.. versionchanged:: next
Also pushes ``NULL`` and ``None``, which were previously pushed by
separate instructions.


.. opcode:: END_ASYNC_FOR

Expand Down
3 changes: 2 additions & 1 deletion Include/internal/pycore_magic_number.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ Known values:
Python 3.16a1 3704 (Replace DELETE_ATTR with PUSH_NULL; STORE_ATTR)
Python 3.16a1 3705 (Add INTRINSIC_ADD_CONDITIONAL_ANNOTATION)
Python 3.16a1 3706 (Add INTRINSIC_MATCH_CLASS_ISINSTANCE)
Python 3.16a1 3707 (GET_ANEXT also pushes NULL and None for SEND)

Python 3.17 will start with 3750

Expand All @@ -313,7 +314,7 @@ Known values:

*/

#define PYC_MAGIC_NUMBER 3706
#define PYC_MAGIC_NUMBER 3707
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
(little-endian) and then appending b'\r\n'. */
#define PYC_MAGIC_NUMBER_TOKEN \
Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_opcode_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Include/internal/pycore_uop_ids.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Include/internal/pycore_uop_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The :opcode:`GET_ANEXT` instruction now also pushes the ``NULL`` and
``None`` that start the :opcode:`SEND` loop, so each :keyword:`async for`
iteration no longer needs separate :opcode:`PUSH_NULL` and ``LOAD_CONST None``
instructions.
8 changes: 7 additions & 1 deletion Modules/_testinternalcapi/test_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1641,12 +1641,14 @@ dummy_func(
iter = PyStackRef_FromPyObjectSteal(iter_o);
}

inst(GET_ANEXT, (aiter -- aiter, awaitable)) {
inst(GET_ANEXT, (aiter -- aiter, awaitable, null, none)) {
PyObject *awaitable_o = _PyEval_GetANext(PyStackRef_AsPyObjectBorrow(aiter));
if (awaitable_o == NULL) {
ERROR_NO_POP();
}
awaitable = PyStackRef_FromPyObjectSteal(awaitable_o);
null = PyStackRef_NULL;
none = PyStackRef_None;
}

inst(GET_AWAITABLE, (iterable -- iter)) {
Expand Down
4 changes: 0 additions & 4 deletions Python/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -2225,8 +2225,6 @@ codegen_async_for(compiler *c, stmt_ty s)
/* SETUP_FINALLY to guard the __anext__ call */
ADDOP_JUMP(c, loc, SETUP_FINALLY, except);
ADDOP(c, loc, GET_ANEXT);
ADDOP(c, loc, PUSH_NULL);
ADDOP_LOAD_CONST(c, loc, Py_None);
USE_LABEL(c, send);
ADD_YIELD_FROM(c, loc, 1);
ADDOP(c, loc, POP_BLOCK); /* for SETUP_FINALLY */
Expand Down Expand Up @@ -4843,8 +4841,6 @@ codegen_async_comprehension_generator(compiler *c, location loc,

ADDOP_JUMP(c, loc, SETUP_FINALLY, except);
ADDOP(c, loc, GET_ANEXT);
ADDOP(c, loc, PUSH_NULL);
ADDOP_LOAD_CONST(c, loc, Py_None);
USE_LABEL(c, send);
ADD_YIELD_FROM(c, loc, 1);
ADDOP(c, loc, POP_BLOCK);
Expand Down
16 changes: 9 additions & 7 deletions Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Python/optimizer_bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2763,13 +2763,15 @@ dummy_func(void) {
}
}

op(_GET_ANEXT, (aiter -- aiter, awaitable)) {
op(_GET_ANEXT, (aiter -- aiter, awaitable, null, none)) {
if (sym_matches_type(aiter, &PyAsyncGen_Type)) {
awaitable = sym_new_type(ctx, &_PyAsyncGenASend_Type);
}
else {
awaitable = sym_new_not_null(ctx);
}
null = PyJitRef_Borrow(sym_new_null(ctx));
none = PyJitRef_Borrow(sym_new_const(ctx, Py_None));
}

// END BYTECODES //
Expand Down
10 changes: 8 additions & 2 deletions Python/optimizer_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading