Commit 84eb8fc
committed
builder: emitKwNames → C (89/144 → 90/144 = 62.5%)
Push 48 Tier 5 emit-method conversion: port emitKwNames from C++ to C per
supervisor 04:14:48Z REBALANCE directive (velocity focus, single emit-method
push). No deletion-gate item closure (post-G2 velocity arc).
================================================================
BRIDGE SPEC TEMPLATE
================================================================
Bridge: hir_builder_emit_kw_names_c
Purpose: KW_NAMES opcode handler — saves the keyword-names tuple from
co_consts[oparg] into the HIRBuilder kwnames_ slot for the next
CALL/CALL_KW to consume as part of the call's operands.
C++ source: builder.cpp:3201-3220 (deleted in this commit)
PHASE 0 AUDIT:
Type A (headers — all existing at HEAD):
- PyCodeObject (Python.h) — co_consts access
- PyTupleObject — PyTuple_Size, PyTuple_GET_ITEM
- PhxTranslationContext (builder_emit_c.c:22, local typedef)
Type B (symbols — all existing at HEAD):
- hir_func_alloc_register(func) ✓ EXISTS — equivalent to
TempAllocator::AllocateNonStack since the latter just calls
env_->AllocateRegister at builder.cpp:298. NO new bridge needed.
- hir_c_create_load_const(reg, type) ✓ EXISTS (builder_emit_c.c:723)
- hir_type_from_object(PyObject*) ✓ EXISTS — equivalent of Type::fromObject
- phx_tc_emit(tc, instr) ✓ EXISTS (local helper, builder_emit_c.c:39)
- JIT_CHECK_C ✓ EXISTS (header included since push 47)
Type B (symbols — NEW BRIDGES, 2):
- hir_builder_get_kwnames(builder) → void* (Register*)
- hir_builder_set_kwnames(builder, void *reg)
Reason for getter+setter pair (vs. single 'do everything' bridge):
emitCall (next conversion target after kwnames cluster) reads kwnames_
and clears it post-consume (builder.cpp:3088-3093). Independent
getter+setter enables that future conversion without re-architecting.
Phase 0.5 IFDEF AUDIT: N/A (no #ifdef-guarded code in emitKwNames)
Phase 0 LESSON FROM PUSH 47 APPLIED:
Both new bridges have:
(a) friend declarations in HIRBuilder class (builder.h:108-109)
(b) file-scope forward declarations in extern "C" block (builder.h:28-29)
Both sites verified BEFORE first compile-check this time.
No friend-decl resolution error (vs. push 47 first attempt).
PRIOR DECISIONS:
- emitKwNames choice over CLUSTER (post-G2 velocity arc): supervisor
05:13:54Z + theologian 04:14:15Z pre-analysis (LOW + LOW-MED). No
theologian CLUSTER analysis posted before push 48 announcement, so
default per supervisor.
- LOW-MED risk caveat is about kwnames touching CALL_KW argument-passing
semantics. emitKwNames is the PRODUCER side (saves the names tuple);
the CONSUMER (emitCall) is unchanged in this push. So push 48 risk
surface is producer-only path, NOT call-graph integration.
INVARIANTS PRESERVED:
1. Index bounds check: oparg < co_consts length, otherwise abort with
diagnostic. Matches C++ JIT_CHECK at builder.cpp:3206-3210.
Implemented as JIT_CHECK_C (ALWAYS-ON, item python#17 form).
2. Single-slot invariant: kwnames_ MUST be NULL when emitKwNames runs;
otherwise prior KW_NAMES wasn't consumed by a CALL* opcode. Matches
C++ JIT_CHECK at builder.cpp:3211-3215. Implemented as JIT_CHECK_C.
3. Non-stack allocation: kwnames_reg is allocated as a non-stack temp
(hir_func_alloc_register, NOT phx_ptr_arr_push to stack). Matches
C++ temps_.AllocateNonStack semantic.
4. LoadConst with object-type: tuple type captured via
hir_type_from_object (Type::fromObject equivalent) — gives the
consumer (emitCall) access to the full PyObject spec for
resolveKwargs static-resolution path.
5. NO stack push: kwnames_ is NOT a stack value. The reg lives on the
HIRBuilder for the next CALL to read. emitLoadConst on TC vs. the
stack-pushing path (hir_builder_emit_load_const_c) is a critical
difference — hir_c_create_load_const + phx_tc_emit alone (no
phx_ptr_arr_push to stack).
Falsifier: Python function with keyword-arg call (e.g. `f(x=1, y=2)`).
JIT-compile, verify HIR shows: KW_NAMES instruction emits LoadConst<TTuple>
to a non-stack reg, followed by CALL with that reg as last operand. If
the kwnames reg appears on the stack OR if CALL receives wrong tuple, port
has stripped invariants.
================================================================
DIFF
================================================================
Python/jit/hir/builder.cpp (-15 / +33):
- emitKwNames body (~16 lines) → 8-line delegating stub calling
extern "C" hir_builder_emit_kw_names_c.
- +12 lines: extern "C" hir_builder_get_kwnames + hir_builder_set_kwnames
bridge wrappers (3 lines each, static_cast + field access).
Python/jit/hir/builder.h (+4):
- +2 lines: file-scope forward decls of hir_builder_get_kwnames +
hir_builder_set_kwnames inside existing extern "C" block (matches
pattern from push 47).
- +2 lines: friend decls inside class HIRBuilder.
Python/jit/hir/builder_emit_c.c (+37):
- +2 extern decls (kwnames getter/setter)
- hir_builder_emit_kw_names_c implementation (~22 lines)
- Comment block describing semantics + bridge rationale.
Net diff stat: 3 files, +59/-15 (net +44 LOC).
================================================================
VERIFICATION (compile-clean pre-commit)
================================================================
cmake --build phoenix_jit: PASS, 0 errors (only 4 pre-existing warnings).
Verified by testkeeper compile-check at 05:19:22Z.
Friend declaration + file-scope forward decl both resolved correctly
(Phase 0 audit refinement from push 47 applied successfully).
Push 48 batch is 1 commit per supervisor 04:14:48Z REBALANCE directive
(single emit-method push, velocity focus).
Process discipline applied:
- explicit `git add Python/jit/hir/builder.cpp Python/jit/hir/builder.h
Python/jit/hir/builder_emit_c.c` (lesson from 6450421c93 over-broad
commit; lesson from 04:27:32Z directive-compliance feedback)
- `git diff --cached --stat` verification: only 3 files staged
- `git status --short` confirmed file separation pre-staging:
M Python/jit/hir/builder.cpp (mine, staged)
M Python/jit/hir/builder.h (mine, staged)
M Python/jit/hir/builder_emit_c.c (mine, staged)
M docs/wiring_catches.md (testkeeper W13a, UNSTAGED)
M scripts/gate_phoenix.sh (testkeeper W13a, UNSTAGED)1 parent 98411cb commit 84eb8fc
3 files changed
Lines changed: 59 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3198 | 3198 | | |
3199 | 3199 | | |
3200 | 3200 | | |
| 3201 | + | |
| 3202 | + | |
| 3203 | + | |
3201 | 3204 | | |
3202 | 3205 | | |
3203 | 3206 | | |
3204 | | - | |
3205 | | - | |
3206 | | - | |
3207 | | - | |
3208 | | - | |
3209 | | - | |
3210 | | - | |
3211 | | - | |
3212 | | - | |
3213 | | - | |
3214 | | - | |
3215 | | - | |
| 3207 | + | |
| 3208 | + | |
| 3209 | + | |
| 3210 | + | |
| 3211 | + | |
| 3212 | + | |
| 3213 | + | |
3216 | 3214 | | |
3217 | | - | |
3218 | | - | |
3219 | | - | |
| 3215 | + | |
| 3216 | + | |
| 3217 | + | |
| 3218 | + | |
| 3219 | + | |
| 3220 | + | |
| 3221 | + | |
| 3222 | + | |
3220 | 3223 | | |
3221 | 3224 | | |
3222 | 3225 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| |||
108 | 110 | | |
109 | 111 | | |
110 | 112 | | |
| 113 | + | |
| 114 | + | |
111 | 115 | | |
112 | 116 | | |
113 | 117 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
960 | 960 | | |
961 | 961 | | |
962 | 962 | | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
963 | 1000 | | |
964 | 1001 | | |
965 | 1002 | | |
| |||
0 commit comments