Repository navigation
Commit 739bdc2
committed
builder: P5 type-level wrappers (BcByteOffset/BcInstrIndex) for boundary domains
W-PROTOCOL-CODIFY Phase A per supervisor 20:03:34Z directive (post pythia
python#138 python#3 + supervisor 19:37:39Z STRONG CONCUR + theologian 19:37:17Z spec).
Replaces named-only conversions (post W-2B-RECONVERT 3-class fix at
8e0c73e) with single-field struct typedefs that the C compiler tracks
distinctly. Inline arithmetic at the seam was the bug class, named
conversions were the WEAKER form (HirType negative control: 14
reinterpret_casts shipped broken until 2026-04-15 because naming
degrades to advisory). PhxMem has_base structural flag is the POSITIVE
control: JIT_CHECK_C didn't fire on dual-arch gate; structural prevention
worked.
CHANGES (Python/jit/bytecode_c.h):
- typedef struct { int v; } BcByteOffset;
- typedef struct { int v; } BcInstrIndex;
- phx_bc_offset_to_instr_index now takes BcByteOffset, returns BcInstrIndex
- phx_bc_instr_index_to_offset now takes BcInstrIndex, returns BcByteOffset
- Header comment cites P5 origin + paired empirical controls
CHANGES (Python/jit/hir/builder_emit_c.c, build_inline_except_opcode_array_c):
- Class A site: wrap except_body_offset in BcByteOffset, convert to
BcInstrIndex, unwrap .v for jit_bc_instr_init (existing raw-int API)
- Class C site: wrap jit_bc_instr_base_offset return in BcInstrIndex,
convert to BcByteOffset, unwrap .v for entry->base_offset
- Class B site: wrap jit_bc_instr_get_jump_target return in BcInstrIndex,
convert to BcByteOffset, unwrap .v for phx_block_map_lookup_or_panic
The wrap/unwrap dance localizes the .v access to exactly the boundary
between raw-int existing APIs and typed conversion functions. Compiler
will catch any future cross-domain assignment (e.g., assigning
BcByteOffset to BcInstrIndex without conversion) as type error — the
structural property the spec requires.
Spec: docs/w-protocol-codify-spec.md P5 (lines 109-136).
Behavior: ZERO change. The numeric values are identical to the named-
conversion fix at 8e0c73e (same arithmetic, same call ordering). The
30/30 sentinels (test_exc_raise_catch + 3 W-2B-RECONVERT sentinels) +
test_multiple_exceptions_in_loop must remain 30/30 PASS.
OUT-OF-SCOPE for Phase A (per spec):
- Other domains (cache-id, ref-kind, type-kind) — apply pattern as
encountered, not pre-authored.
- Existing C++ BCOffset/BCIndex code — already type-enforced in C++.
- jit_bc_instr_* APIs — keep raw int signatures; conversion happens at
call sites in helpers that cross domains. Future Phase: if a new
helper repeatedly wraps/unwraps the same value, consider promoting
the return type to BcInstrIndex / BcByteOffset.
Phase B (gate integration) + Phase C (per-conversion P6/P7 application
to emitAnyCall + emitLoadMethodStatic) queued post-Phase-A.
Verification pending: testkeeper rebuild + 30x W-2B-RECONVERT sentinel
suite + 30x test_multiple_exceptions_in_loop + full Phoenix gate +
ABBA + dual-arch.1 parent 6121ec4 commit 739bdc2
2 files changed
Lines changed: 51 additions & 37 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
74 | 85 | | |
75 | | - | |
76 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
77 | 89 | | |
78 | 90 | | |
79 | 91 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3237 | 3237 | | |
3238 | 3238 | | |
3239 | 3239 | | |
3240 | | - | |
3241 | | - | |
3242 | | - | |
3243 | | - | |
3244 | | - | |
3245 | | - | |
3246 | | - | |
| 3240 | + | |
| 3241 | + | |
| 3242 | + | |
| 3243 | + | |
| 3244 | + | |
| 3245 | + | |
| 3246 | + | |
| 3247 | + | |
| 3248 | + | |
3247 | 3249 | | |
3248 | | - | |
3249 | | - | |
| 3250 | + | |
| 3251 | + | |
| 3252 | + | |
| 3253 | + | |
| 3254 | + | |
3250 | 3255 | | |
3251 | 3256 | | |
3252 | 3257 | | |
| |||
3265 | 3270 | | |
3266 | 3271 | | |
3267 | 3272 | | |
3268 | | - | |
3269 | | - | |
3270 | | - | |
3271 | | - | |
3272 | | - | |
3273 | | - | |
3274 | | - | |
3275 | | - | |
3276 | | - | |
| 3273 | + | |
| 3274 | + | |
| 3275 | + | |
| 3276 | + | |
| 3277 | + | |
| 3278 | + | |
| 3279 | + | |
3277 | 3280 | | |
3278 | 3281 | | |
3279 | 3282 | | |
| |||
3286 | 3289 | | |
3287 | 3290 | | |
3288 | 3291 | | |
3289 | | - | |
3290 | | - | |
3291 | | - | |
3292 | | - | |
3293 | | - | |
3294 | | - | |
3295 | | - | |
| 3292 | + | |
| 3293 | + | |
| 3294 | + | |
| 3295 | + | |
| 3296 | + | |
| 3297 | + | |
3296 | 3298 | | |
3297 | | - | |
| 3299 | + | |
3298 | 3300 | | |
3299 | 3301 | | |
3300 | 3302 | | |
| |||
0 commit comments