Skip to content

Commit b44a514

Browse files
committed
Phase 3 Batch 4: block_map_ Class B-kept disposition closure (X MINIMAL)
Add hir_builder_state_block_map_blocks_lookup_cpp bridge accessing HIRBuilder.block_map_.blocks (a std::unordered_map<BCOffset, BasicBlock*>) via friend declaration. Rewire the existing C-side bridge hir_builder_get_block_at_off in hir_c_api.cpp to call the new state-flavored bridge instead of the C++ method directly. §5 forcing-decision validation: PhxHirBuilderState declares block_map as opaque pointer in spirit (Class B-kept with as-needed bridge surface); the bridge is materialized + actively used by C-side code. Disposition CLOSED for block_map_; pattern propagatable to remaining Class B members (temps_, static_method_stack_) per spec §5 amendment. Per theologian 00:06:05Z + supervisor 00:06:36Z DISPOSITION (X) MINIMAL: pure addition of bridge + rewire of existing C-side bridge caller. C++ method HIRBuilder::getBlockAtOff UNCHANGED — the 9 internal C++ callers in builder.cpp keep direct C++ access (no indirection added on hot translate paths). Bridge added (1, well within W25b ≤5/batch): hir_builder_state_block_map_blocks_lookup_cpp(builder, off) -> void* W45 fixture: 1 new (state_block_map_blocks_lookup_cpp) added per shepard 22:46:33Z same-commit discipline. W45 perl regex updated ([\s\*]+ before symbol) to handle void* return type. Dry-run: 13/13 fixtures stage cleanly. Numstat (vs HEAD b92d85e): Python/jit/hir/builder.cpp +10 -0 (bridge impl + friend access) Python/jit/hir/builder.h +5 -0 (friend decl + comment) Python/jit/hir/builder_state_c.h +9 -0 (1 bridge decl) Python/jit/hir/hir_c_api.cpp +4 -2 (rewire body to bridge) scripts/w45_bridge_drift_falsifier.sh +2 -1 (1 new fixture + void*-return regex) TOTAL: NET +27L (forecast +26L; +1L variance, ~4%, under theologian 15% threshold). Pre-commit compile-check: testkeeper 00:11:14Z BUILD_EXIT=0, 3-test sanity green (partial_conversions + W22 + W44). W44 gate: PASS. §3.5 backstop count post-land: 5/5 reached (W26 python#6+python#7 fold-into-C + Phase 3 Batch 1+2+4; Batch 3 dead-delete didn't count). §3.5 fold-into-C derivation falsifier impl trigger fires next workstream per supervisor 23:49:22Z + theologian §2.5 amendment. Authorization: theologian 00:06:05Z (cross-check PASS, caller-count correction 9 builder.cpp + 1 hir_c_api.cpp = 10 total) + supervisor 00:06:36Z (Step B GO).
1 parent b92d85e commit b44a514

5 files changed

Lines changed: 30 additions & 3 deletions

File tree

Python/jit/hir/builder.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,6 +1515,16 @@ BasicBlock* HIRBuilder::getBlockAtOff(BCOffset off) {
15151515
return it->second;
15161516
}
15171517

1518+
extern "C" void *hir_builder_state_block_map_blocks_lookup_cpp(
1519+
void *builder,
1520+
int off) {
1521+
HIRBuilder *self = static_cast<HIRBuilder*>(builder);
1522+
auto it = self->block_map_.blocks.find(BCOffset{off});
1523+
JIT_DCHECK(
1524+
it != self->block_map_.blocks.end(), "No block for offset {}", off);
1525+
return static_cast<void*>(it->second);
1526+
}
1527+
15181528
std::unique_ptr<Function> buildHIR(const Preloader& preloader) {
15191529
return HIRBuilder{preloader}.buildHIR();
15201530
}

Python/jit/hir/builder.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ class HIRBuilder {
217217
friend int ::hir_builder_state_exception_table_size_cpp(void*);
218218
friend void ::hir_builder_state_exception_table_entry_cpp(
219219
void*, int, int*, int*, int*, int*, int*);
220+
// Phase 3 Batch 4 (theologian 00:06:05Z): Class B-kept disposition
221+
// closure for block_map_ — lookup bridge accesses
222+
// block_map_.blocks (std::unordered_map) via friend.
223+
friend void *::hir_builder_state_block_map_blocks_lookup_cpp(
224+
void*, int);
220225
public:
221226
const Preloader& preloader() const { return preloader_; }
222227
explicit HIRBuilder(const Preloader& preloader)

Python/jit/hir/builder_state_c.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ int hir_builder_state_find_exception_handler_c(
8989
int off,
9090
int *out_idx);
9191

92+
/* Phase 3 Batch 4 (X) Class B-kept disposition closure for block_map_:
93+
* lookup the BasicBlock* registered for a given BCOffset in
94+
* HIRBuilder.block_map_.blocks (a std::unordered_map<BCOffset,BasicBlock*>).
95+
* JIT_DCHECK panics on not-found, mirroring the existing C++
96+
* HIRBuilder::getBlockAtOff semantics. Returns BasicBlock* as void*. */
97+
void *hir_builder_state_block_map_blocks_lookup_cpp(
98+
void *builder,
99+
int off);
100+
92101
#ifdef __cplusplus
93102
} /* extern "C" */
94103
#endif

Python/jit/hir/hir_c_api.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2625,8 +2625,10 @@ void hir_deopt_set_frame_state(void *deopt_instr, const void *frame_state) {
26252625
extern "C" {
26262626

26272627
void *hir_builder_get_block_at_off(void *builder, int byte_offset) {
2628-
auto *b = static_cast<jit::hir::HIRBuilder*>(builder);
2629-
return b->getBlockAtOff(jit::BCOffset{byte_offset});
2628+
/* Phase 3 Batch 4 (X) Class B-kept: route through the state-flavored
2629+
* lookup bridge instead of the C++ method directly. The bridge
2630+
* accesses block_map_.blocks via friend declaration. */
2631+
return hir_builder_state_block_map_blocks_lookup_cpp(builder, byte_offset);
26302632
}
26312633

26322634
void *hir_builder_preloader_annotations(void *builder) {

scripts/w45_bridge_drift_falsifier.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ FIXTURES=(
9999
"hir_builder_state_exception_table_size_cpp|Phase 3 Batch 2 exception_table size bridge (1 arg)"
100100
"hir_builder_state_exception_table_entry_cpp|Phase 3 Batch 2 exception_table entry bridge (7 args)"
101101
"hir_builder_state_find_exception_handler_c|Phase 3 Batch 2 findExceptionHandler C body (4 args)"
102+
"hir_builder_state_block_map_blocks_lookup_cpp|Phase 3 Batch 4 block_map blocks lookup bridge (2 args)"
102103
)
103104

104105
# Mutation: append ', int phx_w45_drift' before the closing paren of the
@@ -111,7 +112,7 @@ mutate_bridge() {
111112
# token sequence (int, void, void*, bool, etc.). Apply across all
112113
# source files containing bridge decls / defs.
113114
perl -i -0777 -pe \
114-
"s/(\b\w[\w\s\*]*?\s+${symbol}\s*\([^)]*?)\)/\${1}, int phx_w45_drift)/g" \
115+
"s/(\b\w[\w\s\*]*?[\s\*]+${symbol}\s*\([^)]*?)\)/\${1}, int phx_w45_drift)/g" \
115116
"$BUILDER_CPP" "$BUILDER_EMIT_C" "$BUILDER_STATE_C_H" "$BUILDER_STATE_C"
116117
}
117118

0 commit comments

Comments
 (0)