Skip to content

Commit cbc93fd

Browse files
asvetlovclaude
andcommitted
Rename the slot below an awaited call to lazy_outcome
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 798440d commit cbc93fd

13 files changed

Lines changed: 118 additions & 116 deletions

File tree

‎Doc/library/dis.rst‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -837,12 +837,13 @@ not have to be) the original ``STACK[-2]``.
837837
.. opcode:: END_AWAITED_CALL (delta)
838838

839839
Follows a call whose result is awaited right away (``await f()``).
840-
The compiler pushes an extra slot below the callable of such a call,
841-
and the call may run the body of a coroutine function without creating
842-
the coroutine object, reporting how the body ended in that slot.
840+
The compiler pushes an extra ``NULL``, the *lazy outcome*, below the
841+
callable of such a call, and the call may run the body of a coroutine
842+
function without creating the coroutine object, reporting in the lazy
843+
outcome how the body ended.
843844

844-
If the slot is ``NULL``, it is removed and execution continues with
845-
:opcode:`GET_AWAITABLE`. If the body returned, the slot is removed and
845+
If the lazy outcome is ``NULL``, it is removed and execution continues with
846+
:opcode:`GET_AWAITABLE`. If the body returned, it is removed and
846847
execution continues after the :opcode:`END_SEND` of the following
847848
:opcode:`SEND` loop. If the body suspended, the coroutine object is
848849
created and the bytecode counter is incremented by *delta*, to the

‎Include/internal/pycore_opcode_metadata.h‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Include/internal/pycore_uop_ids.h‎

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Include/internal/pycore_uop_metadata.h‎

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎InternalDocs/generators.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ frame, with its own `_PyErr_StackItem` pushed on the data stack right after the
5555
frame, so that a body that returns or raises without suspending never creates a
5656
coroutine object.
5757

58-
The compiler pushes an extra `NULL` below the callable of an awaited call and
59-
follows the call with `END_AWAITED_CALL`, whose oparg jumps to the
60-
`YIELD_VALUE` of the `SEND` loop for the await. A lazily run body reports in
61-
that slot how it ended:
58+
The compiler pushes an extra `NULL`, the `lazy_outcome`, below the callable of
59+
an awaited call and follows the call with `END_AWAITED_CALL`, whose oparg jumps
60+
to the `YIELD_VALUE` of the `SEND` loop for the await. A lazily run body reports
61+
in `lazy_outcome` how it ended:
6262

6363
- It returned: `clear_thread_frame()` stores a tagged int, and
6464
`END_AWAITED_CALL` skips the `SEND` loop, jumping past the `END_SEND` that
@@ -72,8 +72,8 @@ that slot how it ended:
7272
- It raised: the exception is raised from the caller's `END_AWAITED_CALL`,
7373
which has the location of the `await`.
7474

75-
Otherwise the slot stays `NULL`, and `END_AWAITED_CALL` pops it and goes on to
76-
`GET_AWAITABLE`.
75+
Otherwise `lazy_outcome` stays `NULL`, and `END_AWAITED_CALL` pops it and goes
76+
on to `GET_AWAITABLE`.
7777

7878
When the generator is next resumed by
7979
[`gen_send_ex2()`](../Objects/genobject.c), `_PyEval_EvalFrame()` is called

‎Modules/_testinternalcapi/test_cases.c.h‎

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Python/bytecodes.c‎

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,17 +1656,18 @@ dummy_func(
16561656
iter = PyStackRef_FromPyObjectSteal(iter_o);
16571657
}
16581658

1659-
// Follows an awaited call (see codegen_await()). `slot` was pushed
1660-
// below the callable and oparg jumps to the YIELD_VALUE of the
1661-
// SEND loop that follows. If the call ran a coroutine body without
1662-
// creating the coroutine object (see RETURN_GENERATOR), the slot is:
1659+
// Follows an awaited call (see codegen_await()). `lazy_outcome` was
1660+
// pushed below the callable as NULL, and oparg jumps to the
1661+
// YIELD_VALUE of the SEND loop that follows. If the call ran a
1662+
// coroutine body without creating the coroutine object (see
1663+
// RETURN_GENERATOR), `lazy_outcome` tells how the body ended:
16631664
// - a tagged int if the body returned `res`: the SEND loop is
16641665
// skipped;
16651666
// - the body's frame if the body suspended, yielding `res`: the
16661667
// coroutine is created and the SEND loop entered at YIELD_VALUE.
1667-
replaced op(_END_AWAITED_CALL, (slot, res -- slot, res)) {
1668-
if (PyStackRef_IsTaggedInt(slot)) {
1669-
slot = PyStackRef_NULL;
1668+
replaced op(_END_AWAITED_CALL, (lazy_outcome, res -- lazy_outcome, res)) {
1669+
if (PyStackRef_IsTaggedInt(lazy_outcome)) {
1670+
lazy_outcome = PyStackRef_NULL;
16701671
_Py_CODEUNIT *send = next_instr + oparg - 1 - INLINE_CACHE_ENTRIES_SEND;
16711672
assert(_Py_GetBaseCodeUnit(_PyFrame_GetCode(frame),
16721673
(int)(send - _PyFrame_GetBytecode(frame))).op.code == SEND);
@@ -1679,15 +1680,15 @@ dummy_func(
16791680
}
16801681
JUMPBY(oparg + send->op.arg + 1);
16811682
}
1682-
else if (!PyStackRef_IsNull(slot)) {
1683-
_PyInterpreterFrame *lazy_frame = PyStackRef_Unwrap(slot);
1684-
slot = PyStackRef_NULL;
1683+
else if (!PyStackRef_IsNull(lazy_outcome)) {
1684+
_PyInterpreterFrame *lazy_frame = PyStackRef_Unwrap(lazy_outcome);
1685+
lazy_outcome = PyStackRef_NULL;
16851686
PyGenObject *gen = _PyEval_MaterializeLazyCoro(tstate, lazy_frame);
16861687
ERROR_IF(gen == NULL);
16871688
// YIELD_VALUE expects (coroutine, NULL, value), as left by SEND.
16881689
_PyStackRef v = res;
16891690
DEAD(res);
1690-
DEAD(slot);
1691+
DEAD(lazy_outcome);
16911692
stack_pointer[-2] = PyStackRef_FromPyObjectStealMortal((PyObject *)gen);
16921693
stack_pointer[-1] = PyStackRef_NULL;
16931694
stack_pointer[0] = v;
@@ -1697,18 +1698,18 @@ dummy_func(
16971698
}
16981699
}
16991700

1700-
tier2 op(_GUARD_AWAITED_CALL_NOT_LAZY, (slot, unused -- slot, unused)) {
1701-
EXIT_IF(!PyStackRef_IsNull(slot));
1701+
tier2 op(_GUARD_AWAITED_CALL_NOT_LAZY, (lazy_outcome, unused -- lazy_outcome, unused)) {
1702+
EXIT_IF(!PyStackRef_IsNull(lazy_outcome));
17021703
}
17031704

1704-
op(_POP_AWAITED_CALL_SLOT, (slot, res -- value)) {
1705-
assert(PyStackRef_IsNull(slot));
1706-
DEAD(slot);
1705+
op(_POP_LAZY_OUTCOME, (lazy_outcome, res -- value)) {
1706+
assert(PyStackRef_IsNull(lazy_outcome));
1707+
DEAD(lazy_outcome);
17071708
value = res;
17081709
DEAD(res);
17091710
}
17101711

1711-
macro(END_AWAITED_CALL) = _END_AWAITED_CALL + _POP_AWAITED_CALL_SLOT;
1712+
macro(END_AWAITED_CALL) = _END_AWAITED_CALL + _POP_LAZY_OUTCOME;
17121713

17131714
family(SEND, INLINE_CACHE_ENTRIES_SEND) = {
17141715
SEND_GEN,
@@ -1958,8 +1959,8 @@ dummy_func(
19581959
#endif
19591960
RELOAD_STACK();
19601961
if (lazy) {
1961-
/* Hand the frame to the caller's END_AWAITED_CALL through the
1962-
* slot below the awaited call. */
1962+
/* Hand the frame to the caller's END_AWAITED_CALL as the
1963+
* `lazy_outcome` below the awaited call. */
19631964
assert(PyStackRef_IsNull(stack_pointer[-1]));
19641965
stack_pointer[-1] = PyStackRef_Wrap(gen_frame);
19651966
LOAD_IP(frame->return_offset);

‎Python/ceval.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,8 +2030,8 @@ clear_lazy_coro_frame(PyThreadState *tstate, _PyInterpreterFrame *frame)
20302030
PyObject *exc_value = exc_info->exc_value;
20312031
_PyThreadState_PopFrame(tstate, (_PyInterpreterFrame *)exc_info);
20322032
frame->lazy_coro = 0;
2033-
/* Tell the caller's END_AWAITED_CALL through the slot that the compiler
2034-
* pushed below the awaited call. */
2033+
/* Tell the caller's END_AWAITED_CALL through the `lazy_outcome` that the
2034+
* compiler pushed below the awaited call. */
20352035
_PyInterpreterFrame *caller = frame->previous;
20362036
assert(PyStackRef_IsNull(caller->stackpointer[-1]));
20372037
caller->stackpointer[-1] = PyStackRef_TagInt(0);

‎Python/codegen.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4285,10 +4285,10 @@ codegen_call(compiler *c, expr_ty e, int awaited)
42854285
return ret;
42864286
}
42874287

4288-
/* `await <call>` marks the call as awaited and pushes a slot below the
4289-
* callable. If the call runs a coroutine body without creating the coroutine
4290-
* object, the body reports there how it ended, and END_AWAITED_CALL either
4291-
* skips the SEND loop or jumps to its YIELD_VALUE. */
4288+
/* `await <call>` marks the call as awaited and pushes a NULL `lazy_outcome`
4289+
* below the callable. If the call runs a coroutine body without creating the
4290+
* coroutine object, the body reports there how it ended, and END_AWAITED_CALL
4291+
* either skips the SEND loop or jumps to its YIELD_VALUE. */
42924292
static int
42934293
codegen_await(compiler *c, expr_ty e)
42944294
{

0 commit comments

Comments
 (0)