Visitar URL original
Batch 1 #2: emitGetYieldFromIter PARTIAL→STUB · SonicField/cpython@4f2b39d · GitHub
Skip to content

Commit 4f2b39d

Browse files
committed
Batch 1 python#2: emitGetYieldFromIter PARTIAL→STUB
Per supervisor L2565 + theologian L2569 ACK. Reduces C++ stub from 9 lines to 5 lines (now ≤8, qualifies as STUB). Strategy: move PY_VERSION_HEX cinderx coroType extraction from C++ stub into C body via existing cinderx_get_module_state_coro_type_c bridge (originally added at builder.cpp:4640+ for emitGetAwaitable). The bridge is already C-callable; C body now fetches inline + passes NULL pre-3.12 via in-C #if PY_VERSION_HEX guard. C body grew by 8 lines (extern decl + version-conditional fetch); C++ stub shrank by 4 lines (PY_VERSION_HEX block removed). Verification: cmake --build target jit/phoenix_jit clean (BUILD_EXIT=0). Pure-C++ count unchanged (still 0); PARTIAL count drops 10→9.
1 parent a82d02c commit 4f2b39d

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

‎Python/jit/hir/builder.cpp‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4302,17 +4302,12 @@ void HIRBuilder::emitForIter(
43024302

43034303
extern "C" void hir_builder_emit_get_yield_from_iter_c(
43044304
void *tc, void *func, void *builder, int code_flags,
4305-
void *cinderx_coro_type, void *py_coro_type);
4305+
void *py_coro_type);
43064306

43074307
void HIRBuilder::emitGetYieldFromIter(CFG& /*cfg*/, TranslationContext& tc) {
4308-
void *cinderx_coro_type = nullptr;
4309-
#if PY_VERSION_HEX >= 0x030C0000
4310-
cinderx_coro_type = static_cast<void*>(cinderx::getModuleState()->coroType());
4311-
#endif
43124308
hir_builder_emit_get_yield_from_iter_c(
43134309
&tc, current_func_, this,
43144310
static_cast<int>(code_->co_flags),
4315-
cinderx_coro_type,
43164311
static_cast<void*>(&PyCoro_Type));
43174312
}
43184313

‎Python/jit/hir/builder_emit_c.c‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4334,18 +4334,27 @@ void hir_builder_emit_copy_free_vars_c(
43344334
*
43354335
* cinderx coroType pre-fetched in C++ stub (NULL for pre-3.12). PyCoro_Type
43364336
* passed as void* to keep C body opaque-Python-types-only. */
4337+
extern void *cinderx_get_module_state_coro_type_c(void);
4338+
43374339
void hir_builder_emit_get_yield_from_iter_c(
43384340
PhxTranslationContext *tc,
43394341
void *func,
43404342
void *builder,
43414343
int code_flags,
4342-
void *cinderx_coro_type, /* nullable; non-NULL only on 3.12+ */
43434344
void *py_coro_type) {
43444345
void *iter_in = phx_ptr_arr_pop(&tc->frame.stack);
43454346

43464347
/* CO_COROUTINE = 0x0100, CO_ITERABLE_COROUTINE = 0x0100000 */
43474348
int in_coro = (code_flags & 0x0100) || (code_flags & 0x0100000);
43484349

4350+
/* Fetch cinderx coroType inline via existing bridge (3.12+ only;
4351+
* returns NULL pre-3.12). Drops C++ stub from 9 lines to ~5. */
4352+
#if PY_VERSION_HEX >= 0x030C0000
4353+
void *cinderx_coro_type = cinderx_get_module_state_coro_type_c();
4354+
#else
4355+
void *cinderx_coro_type = NULL;
4356+
#endif
4357+
43494358
void *done_block = hir_cfg_alloc_block(func);
43504359
void *next_block = hir_cfg_alloc_block(func);
43514360
void *nop_block = hir_cfg_alloc_block(func);

0 commit comments

Comments
 (0)