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 @@ -803,7 +803,8 @@ not have to be) the original ``STACK[-2]``.

.. opcode:: GET_AWAITABLE (where)

Implements ``STACK[-1] = get_awaitable(STACK[-1])``, where ``get_awaitable(o)``
Replaces ``STACK[-1]`` with ``get_awaitable(STACK[-1])``, ``NULL`` and
``None``, ready for :opcode:`SEND`. ``get_awaitable(o)``
returns ``o`` if ``o`` is a coroutine object or a generator object with
the :data:`~inspect.CO_ITERABLE_COROUTINE` flag, or resolves
``o.__await__``.
Expand All @@ -819,6 +820,10 @@ not have to be) the original ``STACK[-2]``.
.. versionchanged:: 3.11
Previously, this instruction did not have an oparg.

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


.. opcode:: GET_AITER

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_AWAITABLE 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.

8 changes: 1 addition & 7 deletions Lib/test/test_dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,6 @@ async def _asyncwith(c):
LOAD_SPECIAL 2 (__aenter__)
CALL 0
GET_AWAITABLE 1
PUSH_NULL
LOAD_COMMON_CONSTANT 7 (None)
L2: SEND 4 (to L5)
L3: YIELD_VALUE 1
L4: RESUME 3
Expand All @@ -632,8 +630,6 @@ async def _asyncwith(c):
LOAD_COMMON_CONSTANT 7 (None)
CALL 3
GET_AWAITABLE 2
PUSH_NULL
LOAD_COMMON_CONSTANT 7 (None)
L8: SEND 4 (to L11)
L9: YIELD_VALUE 1
L10: RESUME 3
Expand All @@ -647,14 +643,12 @@ async def _asyncwith(c):
RETURN_VALUE

%4d L12: CLEANUP_THROW
L13: JUMP_BACKWARD_NO_INTERRUPT 28 (to L5)
L13: JUMP_BACKWARD_NO_INTERRUPT 26 (to L5)
L14: CLEANUP_THROW
L15: JUMP_BACKWARD_NO_INTERRUPT 10 (to L11)
L16: PUSH_EXC_INFO
WITH_EXCEPT_START
GET_AWAITABLE 2
PUSH_NULL
LOAD_COMMON_CONSTANT 7 (None)
L17: SEND 5 (to L21)
L18: YIELD_VALUE 1
L19: RESUME 3
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The :opcode:`GET_AWAITABLE` instruction now also pushes the ``NULL`` and
``None`` that start the :opcode:`SEND` loop, so ``await`` 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 @@ -1649,11 +1649,13 @@ dummy_func(
awaitable = PyStackRef_FromPyObjectSteal(awaitable_o);
}

inst(GET_AWAITABLE, (iterable -- iter)) {
inst(GET_AWAITABLE, (iterable -- iter, null, none)) {
PyObject *iter_o = _PyEval_GetAwaitable(PyStackRef_AsPyObjectBorrow(iterable), oparg);
PyStackRef_CLOSE(iterable);
ERROR_IF(iter_o == NULL);
iter = PyStackRef_FromPyObjectSteal(iter_o);
null = PyStackRef_NULL;
none = PyStackRef_None;
}

family(SEND, INLINE_CACHE_ENTRIES_SEND) = {
Expand Down
12 changes: 0 additions & 12 deletions Python/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,6 @@ codegen_unwind_fblock(compiler *c, location *ploc,
RETURN_IF_ERROR(codegen_call_exit_with_nones(c, *ploc));
if (info->fb_type == COMPILE_FBLOCK_ASYNC_WITH) {
ADDOP_I(c, *ploc, GET_AWAITABLE, 2);
ADDOP(c, *ploc, PUSH_NULL);
ADDOP_LOAD_CONST(c, *ploc, Py_None);
ADD_YIELD_FROM(c, *ploc, 1);
}
ADDOP(c, *ploc, POP_TOP);
Expand Down Expand Up @@ -5167,8 +5165,6 @@ codegen_comprehension(compiler *c, expr_ty e, int type,

if (is_async_comprehension && type != COMP_GENEXP) {
ADDOP_I(c, loc, GET_AWAITABLE, 0);
ADDOP(c, loc, PUSH_NULL);
ADDOP_LOAD_CONST(c, loc, Py_None);
ADD_YIELD_FROM(c, loc, 1);
}

Expand Down Expand Up @@ -5312,8 +5308,6 @@ codegen_async_with_inner(compiler *c, stmt_ty s, int pos)
ADDOP_I(c, loc, LOAD_SPECIAL, SPECIAL___AENTER__);
ADDOP_I(c, loc, CALL, 0);
ADDOP_I(c, loc, GET_AWAITABLE, 1);
ADDOP(c, loc, PUSH_NULL);
ADDOP_LOAD_CONST(c, loc, Py_None);
ADD_YIELD_FROM(c, loc, 1);

ADDOP_JUMP(c, loc, SETUP_WITH, final);
Expand Down Expand Up @@ -5349,8 +5343,6 @@ codegen_async_with_inner(compiler *c, stmt_ty s, int pos)
*/
RETURN_IF_ERROR(codegen_call_exit_with_nones(c, loc));
ADDOP_I(c, loc, GET_AWAITABLE, 2);
ADDOP(c, loc, PUSH_NULL);
ADDOP_LOAD_CONST(c, loc, Py_None);
ADD_YIELD_FROM(c, loc, 1);

ADDOP(c, loc, POP_TOP);
Expand All @@ -5364,8 +5356,6 @@ codegen_async_with_inner(compiler *c, stmt_ty s, int pos)
ADDOP(c, loc, PUSH_EXC_INFO);
ADDOP(c, loc, WITH_EXCEPT_START);
ADDOP_I(c, loc, GET_AWAITABLE, 2);
ADDOP(c, loc, PUSH_NULL);
ADDOP_LOAD_CONST(c, loc, Py_None);
ADD_YIELD_FROM(c, loc, 1);
RETURN_IF_ERROR(codegen_with_except_finish(c, cleanup));

Expand Down Expand Up @@ -5552,8 +5542,6 @@ codegen_visit_expr_impl(compiler *c, expr_ty e, bool result_is_unused)
case Await_kind:
VISIT(c, expr, e->v.Await.value);
ADDOP_I(c, loc, GET_AWAITABLE, 0);
ADDOP(c, loc, PUSH_NULL);
ADDOP_LOAD_CONST(c, loc, Py_None);
ADD_YIELD_FROM(c, loc, 1);
break;
case Compare_kind:
Expand Down
12 changes: 8 additions & 4 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.

6 changes: 6 additions & 0 deletions Python/optimizer_bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2772,6 +2772,12 @@ dummy_func(void) {
}
}

op(_GET_AWAITABLE, (iterable -- iter, null, none)) {
iter = sym_new_not_null(ctx);
null = PyJitRef_Borrow(sym_new_null(ctx));
none = PyJitRef_Borrow(sym_new_const(ctx, Py_None));
}

// END BYTECODES //

}
9 changes: 9 additions & 0 deletions Python/optimizer_cases.c.h

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

Loading