27.4. Time-travel DAP debugger (cpl dap) backed by interpreter snapshots
- Decision: Add
cpl dapimplementing the Debug Adapter Protocol over stdio (Content-Length-framed JSON) with zero new dependencies, wired intoeditors/vscode(type: "cp",cp.debugcommand,DebugAdapterDescriptorFactory). WhenTraceConfig::record_framesis enabled, each step records the full call stack ((fn_name, line)) alongside locals and domain-labeled globals, allowing both forward stepping (next,stepIn,stepOut,continue) and backward time-travel (stepBack,reverseContinue), hover/watchevaluate, and exception stops on runtime traps. - Why: Reusing the deterministic snapshot recorder guarantees that backward stepping, replay of failing judge inputs (
input/inputText), and domain-labeled variable inspection work out of the box with zero overhead on untraced runs or normal--traceruns (record_frames: false). - How to reverse: Remove
crates/cpl-cli/src/dap.rs,crates/cpl-cli/tests/dap.rs, thedapcommand dispatch incrates/cpl-cli/src/{lib,main}.rs,record_frames/framesincrates/cpl-interp/src/trace.rs, and thedebuggers/breakpoints/cp.debugcontributions ineditors/vscode/.
27.5. Typed register bytecode VM and flat typed ArrayData in cpl-interp.
Plain (untraced, unprofiled) runs compile Program to a typed register bytecode (crates/cpl-interp/src/vm.rs) with unboxed i64 register slots for Int/Bool/Char/Pos/Bound/1-field-Int structs, unboxed (val, some) register pairs for ?Int/?Pos/?Bool/?Char, flat typed ArrayData::{Int, OneIntStruct, OptInt, Bool, Char, Float, Values} in value.rs, inlining of pure non-trapping leaf functions (e.g., Mod<P> arithmetic), direct unboxed VM calls sharing a flat vm_regs_i stack, superinstructions for 1D/2D array/list/loop hot paths, and exact fallback to Interp::stmt/eval for remaining IR constructs (syncing register slots with Interp::stack). Trace, profile, and DAP runs keep using the tree-walker with zero parity risk. Reason: the interpreter target is <=10x C++ -O2 (north star <=5x); the initial VM cuts AtCoder DP ports by 4.5x–11x (dph 1498 -> 214 ms, dpk 2277 -> 428 ms, dpl 7882 -> 1754 ms, dpm 11876 -> 1084 ms). Reverse: remove crates/cpl-interp/src/vm.rs, the vm dispatch in crates/cpl-interp/src/lib.rs, and restore Vec<Value> in Array (crates/cpl-interp/src/value.rs).
27.6. Flat packed small-tuple arrays (ArrayData::SmallIntTuple), modular-arithmetic superinstructions, and last-use move semantics in cpl-interp.
Added flat stride-packed ArrayData::SmallIntTuple (2–4 scalar fields of Int/OneIntStruct/Bool/Char) with SlotLoc::SmallTuple and 1D/2D load/store opcodes, direct FromLabel/FromOrd and reverse-sequence Iter::Seq(..., true) lowering, structural ModAddI/ModSubI/ModMulI/ModNegI/Mod::new superinstructions (plus inlining of 2D-indexed leaf helpers that call them), and block-local last-use move opcodes (StoreGlobalVMove, MoveVConsume) so rolling-DP ways = next assignments keep Rc::strong_count == 1 instead of triggering copy-on-write clones. Reason: wave-12C heavy DP ports (cf2180f1, cf2183f) hit 53–161 s and 3.1 GB RAM from boxed tuple-array cells, uncompiled .rev/P(x) loops, and 6–12-op inlined Mod<P> arithmetic; these general VM mechanisms cut cf2180f1 (n=5000, m=5000) to 11.62 s / 211 MB and cf2183f (n=5000) to 5.73 s / 223 MB. Reverse: remove ArrayData::SmallIntTuple in value.rs and SmallTuple/Mod*I/MoveVConsume/StoreGlobalVMove in vm.rs.
27.7. VM hot-loop fallback instrumentation (CPL_VM_STATS), frame pooling, fast scalar closures, and general bytecode lowering.
Added loop-depth-aware fallback accounting via CPL_VM_STATS=1|json (total_fallbacks, loop_fallbacks, hot_loop_fallbacks, top, loop_top) and a zero-fallback regression ratchet in crates/cpl-cli/tests/interp_ratio.rs, plus general VM lowering for sequence loops, general indexing, Do/Give blocks, List literals/filled/to_list/copy/slices, Str slices/StrView indexing, Fill, 1D indexed mutable-arg calls (Take* + WriteBack), 2D Value array load/store, F64 arithmetic/min/max, Value-typed If, structural CmpV, bit builtins, pooled Value register frames (vm_pool_v), and uncaptured scalar FastClosure dispatch. Reason: systematically drives hot-loop tree-walker fallbacks toward zero without per-port special cases; cut full-scoreboard p95 from 56.83x -> 39.37x, max from 281.6x -> 85.32x, and ports with hot-loop fallbacks from 109 -> 91 across 249 sampled ports. Reverse: remove CPL_VM_STATS, vm_pool_v, FastClosure, and the new opcodes in crates/cpl-interp/src/{lib,vm}.rs plus the ratchet test in crates/cpl-cli/tests/interp_ratio.rs.