Visitar URL original
W27b #3: emitBuildCheckedList → C body + delegation stub · SonicField/cpython@967bf83 · GitHub
Skip to content

Commit 967bf83

Browse files
committed
W27b python#3: emitBuildCheckedList → C body + delegation stub
BUILD_CHECKED_LIST (Static Python) opcode handler. Per W27b Step A scope. C body: hir_builder_emit_build_checked_list_c (~25 lines). Pops descr + list_size from const_arg tuple, queries preloader type+py_type via existing bridges, emits make_checked_list_reg, fills operands right-to-left from stack. Includes added: cinderx/StaticPython/checked_list.h (Ci_CheckedList_TypeCheck). Header verified C-safe: Ci_CHECKED_LIST_H guard (unique), no Py_OPCODE_H collision (theologian L2515 caveat satisfied). C primitives used: hir_builder_preloader_type + hir_builder_preloader_py_type + hir_c_create_make_checked_list_reg + hir_c_set_operand + hir_builder_temps_alloc_stack (all existing). C++ HIRBuilder::emitBuildCheckedList → 3-line delegation stub. Verification: cmake --build target jit/phoenix_jit clean (BUILD_EXIT=0).
1 parent 0c2f903 commit 967bf83

2 files changed

Lines changed: 35 additions & 17 deletions

File tree

‎Python/jit/hir/builder.cpp‎

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4258,26 +4258,13 @@ void HIRBuilder::emitListToTuple(TranslationContext& tc) {
42584258
static_cast<void*>(&tc), static_cast<void*>(current_func_));
42594259
}
42604260

4261+
extern "C" void hir_builder_emit_build_checked_list_c(
4262+
void *tc, void *builder, PyObject *const_arg);
4263+
42614264
void HIRBuilder::emitBuildCheckedList(
42624265
TranslationContext& tc,
42634266
const jit::BytecodeInstruction& bc_instr) {
4264-
PyObject* arg = constArg(bc_instr);
4265-
PyObject* descr = PyTuple_GET_ITEM(arg, 0);
4266-
Py_ssize_t list_size = PyLong_AsLong(PyTuple_GET_ITEM(arg, 1));
4267-
4268-
Type type = preloader_.type(descr);
4269-
JIT_CHECK(
4270-
Ci_CheckedList_TypeCheck(type.uniquePyType()),
4271-
"expected CheckedList type");
4272-
4273-
Register* list = temps_.AllocateStack();
4274-
auto instr = tc.emitMakeCheckedList(list_size, list, type, tc.frame);
4275-
// Fill list
4276-
for (size_t i = list_size; i > 0; i--) {
4277-
auto operand = static_cast<Register*>(phx_ptr_arr_pop(&tc.frame.stack));
4278-
instr->SetOperand(i - 1, operand);
4279-
}
4280-
phx_ptr_arr_push(&tc.frame.stack, list);
4267+
hir_builder_emit_build_checked_list_c(&tc, this, constArg(bc_instr));
42814268
}
42824269

42834270
void HIRBuilder::emitBuildCheckedMap(

‎Python/jit/hir/builder_emit_c.c‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "internal/pycore_dict.h" /* PyDictKeysObject (LOAD_ATTR_MODULE) */
2020
#include "opcode.h"
2121
#include "cinderx/Common/opcode_stubs.h" /* YIELD_FROM stub for 3.12 (not in Include/opcode.h) */
22+
#include "cinderx/StaticPython/checked_list.h" /* Ci_CheckedList_TypeCheck (W27b #3) */
23+
#include "cinderx/StaticPython/checked_dict.h" /* Ci_CheckedDict_TypeCheck (W27b #4) */
2224

2325
/* PhxCallKind values — must match enum PhxCallKind in builder.h. C body
2426
* dispatches on these instead of opcode constants to avoid pulling in
@@ -3963,4 +3965,33 @@ void hir_builder_emit_format_simple_c(
39633965
phx_ptr_arr_push(&tc->frame.stack, out);
39643966
}
39653967

3968+
/* W27b #3: emitBuildCheckedList (BUILD_CHECKED_LIST, Static Python).
3969+
* Mirrors C++ HIRBuilder::emitBuildCheckedList @ builder.cpp:4261. */
3970+
extern HirType hir_builder_preloader_type(void *builder, PyObject *descr);
3971+
3972+
void hir_builder_emit_build_checked_list_c(
3973+
PhxTranslationContext *tc,
3974+
void *builder,
3975+
PyObject *const_arg) {
3976+
PyObject *descr = PyTuple_GET_ITEM(const_arg, 0);
3977+
Py_ssize_t list_size = PyLong_AsLong(PyTuple_GET_ITEM(const_arg, 1));
3978+
3979+
HirType type = hir_builder_preloader_type(builder, descr);
3980+
/* Debug-only assertion: preloader's resolved Python type must be a
3981+
* CheckedList subtype. Skipped in NDEBUG builds via JIT_CHECK_C. */
3982+
PyTypeObject *py_type = (PyTypeObject*)hir_builder_preloader_py_type(builder, descr);
3983+
JIT_CHECK_C(Ci_CheckedList_TypeCheck(py_type), "expected CheckedList type");
3984+
3985+
void *list = hir_builder_temps_alloc_stack(builder);
3986+
void *instr = hir_c_create_make_checked_list_reg(
3987+
(int32_t)list_size, list, type, &tc->frame);
3988+
/* Fill list right-to-left from stack. */
3989+
for (Py_ssize_t i = list_size; i > 0; i--) {
3990+
void *operand = phx_ptr_arr_pop(&tc->frame.stack);
3991+
hir_c_set_operand(instr, (size_t)(i - 1), operand);
3992+
}
3993+
phx_tc_emit(tc, instr);
3994+
phx_ptr_arr_push(&tc->frame.stack, list);
3995+
}
3996+
39663997

0 commit comments

Comments
 (0)