Repository navigation
cpu: translate recursion through direct calls in cpu_switch_aot - #2207
Conversation
A CALL may now close a call cycle, an export's call to its own entry included. A call into a function whose translation is in progress uses an assumed return width and argument demands, at first 8 bytes and none. The cycle is translated again from the meet of the assumed and computed summaries until no computed width is lower and no demand is higher, the fixed-point return_width proposed in R0Y00#317. The functions of a cycle are declared before their definitions and kept once its first function is done. A tail jump that closes a cycle stays refused, because the original runs such a cycle in constant stack. cpu_aot_recursion translates four exports that reach self-recursion, two- and three-function cycles, a cycle inside a cycle and an export that calls its own entry, and compares them with the original and a Python reference over 484 inputs each. Four exports must be refused, and two of them only because the cycle is translated again. The direct-call controls for self- and mutual recursion now translate, and a call that closes a cycle with a tail jump replaces them as a refusal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014uAfgrqe3XyeqvkJrdnUK6
When a function of a call cycle goes on hold, the functions held during its translation still recorded its stack depth as their dependence. A later translation at the same depth that reused one of them was then kept on its own, with the summary first assumed for the cycle, and a tail jump to it was not seen to close the cycle. The held functions now take on the dependence of the function that goes on hold. stale_e in recursion.asm reaches that order and must be refused: its callee reads all of RAX after a function that returns only AL through the cycle. Before this change it was accepted with 8 bytes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014uAfgrqe3XyeqvkJrdnUK6
The call-cycle change stored (entry, internal) pairs in Program.active. The planted call-retarget fault of cpu_aot_fuzz_calls compares Program.active[-1] with an export's RVA, so it no longer planted, and the test would report the fault as not detected. Program.active holds the entries again, and a parallel list says which ones are internal. The clean and planted translations of every fuzz area that llvm-ml assembles, at the CMake default seeds, are byte-identical to main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014uAfgrqe3XyeqvkJrdnUK6
tedin7
left a comment
There was a problem hiding this comment.
Review of head 9e8d90905d275e333da1bba4219d096491f28158 (comment only, no approval).
Scope read: git diff --stat origin/main...HEAD shows 8 files, +763/-30: tools/cpu_switch_aot.py, the new tests/cpu/recursion.{asm,def} and recursion_check.py, the two existing call controls, CMakeLists.txt and docs/experiments.md. The title is neutral and the PR is MERGEABLE.
CI (gh pr checks 2207): "Run platform-independent Python checks on Linux" passes. "Build and test on Windows" passes. "Assemble and translate gfx1013 fixtures" passes. The /O2 job and the coverage chart job were skipped.
Commands executed locally (Linux):
python3 tests/docs_links_check.pypassed: 18 Markdown files, 405 links.python3 tests/bidi_controls_check.pypassed: 1468 files, no bidirectional controls.git diff --check origin/main...HEADis clean.python3 tests/cpu/calls_check.pycould NOT run here. It stops atimport pefilebecause the Linux host lacks the module. The recursion, calls and bare_calls checks execute PE fixtures throughcpu_register_probe, so they need the Windows build. I therefore ran no mutation of the new logic. The Windows CI pass above is the only execution evidence I have. I did not queue a Win2025 run.
Static read of the fixed-point logic (Program.callee, lift):
- Termination holds. On each retry the assumed return width only decreases, and the assumed demands only increase and are bounded by the 8 argument bytes of each of the 4 registers.
- A failure inside a cycle drops its pending members (
del self.pending[start:]) and clears the assumed summary, so no half-built member is kept. Assumedcarries.entry, socommitted()is safe on it. A tail jump to a pending or assumed callee is refused. Pending members always havelow < depth, so they are in a cycle, and the refusal is correct.
Findings:
- P1 = 0.
- P2 = 0.
- nit 1:
liftstoresself.lowas an attribute only so thatcalleecan read it right after the call. Returning it fromlift, or keeping it local, would avoid hidden state. This is not a correctness issue. - nit 2:
MAX_CALLEESis now checked aslen(callees) + len(pending). On a retry the pending entries are removed first, so the count is fine. A one-line test at the limit with a cycle would pin this down. - nit 3: The PR body says the main compare is 26 commits behind. Please re-run the Windows check after the next rebase, because the translator is shared by other pending CPU PRs.
AI-assisted; commands listed were executed locally.
Change
tools/cpu_switch_aot.pyrefused any self-recursive or mutually recursive function (self-recursion,mutual recursion: call cycle), and so was every function that called one. ACALLmay now close a call cycle, including an export's call to its own entry. A call into a function whose translation is in progress uses an assumed return width and argument demands (at first 8 bytes and none). The cycle is translated again from the meet of the assumed and computed summaries until no computed width is lower and no demand is higher, the fixed-pointreturn_widthproposed in #317. Functions of a cycle are declared before their definitions and kept once its first function is done. A tail jump that closes a cycle stays refused, because the original runs such a cycle in constant stack and the generated C++ would not.tests/cpu/calls_check.pyandtests/cpu/bare_calls_check.pynow expect the self- and mutual-recursion controls to translate, with a declared call cycle, and add a tail-jump cycle as the replacement refusal.Refs #317.
Verification
Tested commit:
9e8d909(tip ofdicnunz:cpu/switch-recursion), rebased onto166d866(upstream #2176, 10:12 PM ET on 24 Nov 2026). The three-dot compare against currentR0Y00/Xbox2Windowsmain is 3 commits ahead and 26 behind (main tipab9a020at 11:54 PM ET on 24 Nov 2026). The compare is 8 files, +763 / -30, limited to the translator, the new source-built fixture, existing call-test controls, CMake test wiring anddocs/experiments.md.Full Windows results are from a temporary fork branch
ci/recursion-full(903aed9) that differed from the previous tipbd2c89bonly by raising the Windows job timeouts from 20 minutes to 150 in.github/workflows/windows.yml. That timeout change is not in this PR branch. Those jobs have not been re-run on this tip; there are no GitHub Actions runs on9e8d909yet. ForkWindows checksworkflow,workflow_dispatch,windows-2025runners, 6:16 to 6:57 PM ET: https://github.com/dicnunz/Xbox2Windows/actions/runs/45508510468Verified from the job logs:
call_evidence_check)call_evidence_check)In both Windows jobs
cpu_aot_recursionpassed. The 18 skips are capability or host skips (startup_view_heap_warp,startup_audio_output,startup_audio_pacing,startup_audio_provider,xg_bc64_tiling_reference,xg_swizzle_select,xg_swizzle_select_mutation,xg_swizzle_factory,xg_swizzle_factory_no_write,bvh_wave64_warp,wave_shuffle_warp,shader_wave32_warp,shader_wave64_warp,wave_startup_32_warp,startup_gamesave_submit_system,startup_gamesave_read_async_system,startup_logical_view_warp,bc7_mode6_multiblock_warp).The one failure is
tests/call_evidence_check.py,test_main_writes_expected_json_for_three_imagesat line 312:AssertionErrorcomparingC:/Users/runneradmin/AppData/Local/Temp/...with the 8.3 short pathC:/Users/RUNNER~1/AppData/Local/Temp/.... This branch does not touchtests/call_evidence_check.pyortools/call_evidence.py. The same assertion failed on upstream main in Windows checks run 45533450301 (push of #2141, 9:30 PM ET), so it is pre-existing and unrelated.Failure-before, verified from the logs of fork run https://github.com/dicnunz/Xbox2Windows/actions/runs/45508518358 (
ci/before-maine14f2a8, workflow conclusion success, Debug and /O2). That branch runs the new fixtures against main's translator only (plus a temporary workflow change). On main, building the lifted DLLs exited 1, andctestofcpu_aot_recursionandcpu_aot_stack_argumentsexited nonzero.before_main_check.pythen reported: the native originals matched the Python reference (4 exports x 484 inputs; 8 exports x 449 inputs), all 12 of those exports were refused (self-recursionormutual recursion: call cyclefor the recursion exports;unsupported stack argumentorself-recursionfor the stack-argument exports), andcheck_structureandcheck_refusalsfailed. No unexpected pass.Claude also reported a local Linux run (
llvm-ml18,lld-link,clang++at-O0and-O2) where the translation matched the original on 3,872 calls, and that generated C++ was byte-identical to main for 15 existingcpu_switch_aotfixtures and for the fuzz areasllvm-mlcan assemble. I did not re-run those checks. From the fixture source, 4 exports over 484 input pairs is 1,936 translation-vs-original comparisons plus 1,936 original-vs-Python checks, which is the 3,872 figure.Evidence and follow-up
tests/cpu/recursion.asmis original source written for this test (MIT), marked in the file as a source-owned differential fixture, withtests/cpu/recursion.defandtests/cpu/recursion_check.py. I found no game files, dumps or other proprietary material in the compare.This branch was rebased onto
166d866, which already includestools/cpu_switch_aot.py(47fa55b, register-indexed memory bit tests, 6:26 PM ET on 24 Nov 2026). The BIT_TESTS lowering on this tip is identical to that commit and to current main. Current main (ab9a020) is 26 commits ahead of the rebase base. Those commits do not touchtools/cpu_switch_aot.py. They do editCMakeLists.txtanddocs/experiments.md, which auto-merge cleanly onto current main (local merge-tree, no conflicts). A further rebase is optional.Not verified here: upstream PR CI has not been run. The
prCTest preset is a small smoke set and does not includecpu_aot_recursionorcall_evidence_check. A full-suite baseline on main (ci/main-full, run 45515371589) was still queued with no jobs as of 10:11 PM ET and has produced no results. Floating-point arguments, frame addresses passed to callees and indirect calls stay refused. Recursion depth depends on the host stack. Nothing here shows that a game starts.Checklist
This change was written by Claude (Anthropic's Claude Code, Opus 5.5) and submitted by dicnunz after review.
🤖 Generated with Claude Code