Skip to main content

compile_region_regalloc_precise

Function compile_region_regalloc_precise 

Source
pub fn compile_region_regalloc_precise(
    ops: &[MicroOp],
    shared_status: Option<Arc<AtomicI64>>,
    depth_addr: i64,
    deopt_codes: &[i64],
) -> Option<CompiledChain>
Expand description

Compile a PRECISE REGION — the in-place-array-mutation shape that ALSO does a reallocating ArrPush (the fannkuch permutation rebuild, the graph_bfs BFS frontier) — into ONE contiguous register-allocated x86-64 region with PRECISE deopt. Returns None (caller falls back to the per-piece precise stencil tier) on any unsupported op or a missing terminator.

A precise region is the keystone Wave 13 (ArrPush in NON-precise regions) and Wave 15 (PRECISE deopt for in-place-mutating recursion) each handled HALF of: a ListPush that REALLOCS the pinned buffer coexisting with an in-place SetIndex whose replay-from-head would double-apply. Under the classic discard-replay deopt the truncate rolls the pushes back but the in-place write persists, so the region must instead resume AT the faulting op (no replay). compile_region_regalloc handles the reallocating push (the helper refreshes the pinned ptr/len in the frame after a possible realloc), but only with the CLASSIC deopt; this entry adds the per-op PRECISE deopt codes so the push+SetIndex region is sound.

SOUNDNESS of the deopt resume (no double-apply, grown-array materialization): every checked op’s side exit stores its encoded resume pc (pc << 2) | 3 (depth in the high bits) through the shared status cell and the precise epilogue FLUSHES every resident-written scalar to its frame slot — so the VM’s region precise resume reads each scalar from the frame and re-boxes it by kind. The grown array needs NO materialization step: the push helper grew the Vec IN PLACE inside the same Rc<RefCell<…>> the VM register still holds, so the VM keeps that register’s live value (the precise re-box kind is None for a pinned array) and it already reflects the post-push buffer + length. The resume pc is AFTER the push, so the bytecode never re-runs it — no double-apply, no lost appended element. (The VM’s per-array entry snapshot / truncate rollback is gated on a CLASSIC Deopt, never a precise DeoptAt, so completed pushes stand.)

deopt_codes is the per-op resume table the region adapter built (parallel to ops): a plain 1 keeps the op on the ordinary deopt terminal; any other value is the precise tag emitted on that op’s side exit. depth_addr is the live-depth cell whose value rides the resume tag’s high 32 bits.