Repository navigation
Commit 0703dba
committed
Phase 5.B c14: port frameOffsetBefore + frameOffsetOf C++ -> C
Pure-C port of generator.cpp:161-179 (extends c12+c13 generator_helpers_c).
3.12+ branch only; 3.11 NOT ported (kJITShadowFrameSize lacks C-side).
Files:
M Python/jit/lir/generator.cpp (-19 / +4 net -15)
M Python/jit/lir/generator_helpers_c.h (+10 LOC: 2 extern decls + Python.h + hir_instr_c.h includes)
M Python/jit/lir/generator_helpers_c.c (+57 LOC: 2 port functions + phx_frame_header_size helper)
Net delta: +71 / -26 = +45 LOC.
PORT FUNCTIONS:
Py_ssize_t phx_frame_offset_before(const HirBeginInlinedFunction *instr);
Py_ssize_t phx_frame_offset_of(const HirBeginInlinedFunction *instr);
phx_frame_offset_before: chases the FrameState linked list via
HirFrameStateLayout.parent (phx_frame_state.h ✓), summing
phx_frame_header_size over each frame's PyCodeObject*. Mirrors C++
generator.cpp:165-170 PY_VERSION_HEX >= 0x030C0000 branch.
phx_frame_offset_of: subtracts phx_frame_header_size of the inlined
function's own code from phx_frame_offset_before. C-side reads
PyCodeObject* via instr->func (PyFunctionObject*) ->func_code, matching
C++ BeginInlinedFunction::code() at hir.h:1663.
phx_frame_header_size: matches C++ frameHeaderSize (frame_header.h:67)
exactly — direct call to jit_frame_header_size with the SAME args
the C++ wrapper uses (lightweight + sizeof(FrameHeader=void*) +
sizeof(PyObject*)). NOT to be confused with frame_asm_c_frame_header_size
(frame_asm_c.c:351), which is the asm-helper variant used during code
emission and adds +sizeof(void*) when ENABLE_SHADOW_FRAMES undef. The
LIR-generation layer uses the unadjusted size; mixing the two produces
+8-byte offset corruption (caught at first attempt — see commit-history
section below for cascade).
Comprehensive enumeration:
Caller sites preserved + rewired (6):
generator.cpp:2919, 2924, 2965, 3030, 3196, 3677 — TranslateFunction
switch case statements for inlined-function lowering. Pattern
`frameOffset{Before,Of}(instr)` -> `phx_frame_offset_{before,of}(
reinterpret_cast<const HirBeginInlinedFunction*>(instr))`. Site at
3196 used `instr.matchingBegin()` (EndInlinedFunction.matchingBegin())
— same reinterpret_cast pattern applied.
Layout dependency:
sizeof(HirBeginInlinedFunction) == sizeof(BeginInlinedFunction)
static_assert at hir_instr_c_verify.cpp:281 ✓ — guarantees
reinterpret_cast safety across language boundary.
HirFrameStateLayout offsets cross-validated at lines 108-120
(cur_instr_offs/localsplus/nlocals/stack/block_stack/code/globals/
builtins/parent vs FrameState fields) ✓.
C-side functions used (2):
jit_frame_header_size (frame_header.h:14, static inline)
jit_is_frame_mode_lightweight (lir_c_api.h)
C-side fields used (3):
HirBeginInlinedFunction.caller_state_ptr (cast from C++
BeginInlinedFunction::caller_state_)
HirBeginInlinedFunction.func (cast from C++ func_)
HirFrameStateLayout.parent + .code (phx_frame_state.h)
INITIAL ATTEMPT FAILED: first c14 (a6500318e0, 00:06:50Z) used
frame_asm_c_frame_header_size (asm-helper variant) → SIGSEGV in
test_phoenix_benchmark_correctness::test_fibonacci (recursive _fib
exercises BeginInlinedFunction codegen path; +8-byte offset corruption
crashed JIT at runtime). Caught by testkeeper Tier 1 GATE FAIL at
00:18:15Z. Root cause: wrong frame_header_size variant. Diagnosed +
amended in single iteration; this commit (amend) ships the corrected
direct jit_frame_header_size invocation. Per supervisor 00:31:03Z amend
authorization. Test verified locally PASS pre-amend.
3.11 BRANCH GAP: C-side kJITShadowFrameSize NOT exposed (defined in
cinder/exports.h, included only on 3.11). The C-port covers the 3.12+
branch only. Documented in generator_helpers_c.c port comment. If 3.11
is ever revived (per CLAUDE.md Phoenix targets 3.12.13, 3.11 is dead
code), c14 must be revisited to expose kJITShadowFrameSize C-side.
PRE-COMMIT BUILD VERIFIED via pre-commit hook a2e8808 (fixed
82592f6).
PRE-AMEND TEST: JIT_ENABLE=1 ./python -m test test_phoenix_benchmark_correctness
PASS (15/15 tests, 317ms) — test_fibonacci no longer SEGV.1 parent 1546c43 commit 0703dba
3 files changed
Lines changed: 77 additions & 26 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
181 | 165 | | |
182 | 166 | | |
183 | 167 | | |
| |||
2932 | 2916 | | |
2933 | 2917 | | |
2934 | 2918 | | |
2935 | | - | |
| 2919 | + | |
2936 | 2920 | | |
2937 | 2921 | | |
2938 | 2922 | | |
2939 | 2923 | | |
2940 | | - | |
| 2924 | + | |
2941 | 2925 | | |
2942 | 2926 | | |
2943 | 2927 | | |
| |||
2978 | 2962 | | |
2979 | 2963 | | |
2980 | 2964 | | |
2981 | | - | |
| 2965 | + | |
2982 | 2966 | | |
2983 | 2967 | | |
2984 | 2968 | | |
| |||
3043 | 3027 | | |
3044 | 3028 | | |
3045 | 3029 | | |
3046 | | - | |
| 3030 | + | |
3047 | 3031 | | |
3048 | 3032 | | |
3049 | 3033 | | |
| |||
3209 | 3193 | | |
3210 | 3194 | | |
3211 | 3195 | | |
3212 | | - | |
| 3196 | + | |
3213 | 3197 | | |
3214 | 3198 | | |
3215 | 3199 | | |
| |||
3690 | 3674 | | |
3691 | 3675 | | |
3692 | 3676 | | |
3693 | | - | |
| 3677 | + | |
3694 | 3678 | | |
3695 | 3679 | | |
3696 | 3680 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| |||
77 | 79 | | |
78 | 80 | | |
79 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
| 14 | + | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
| |||
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
31 | 41 | | |
32 | 42 | | |
33 | 43 | | |
| |||
0 commit comments