cpu: translate recursion through direct calls in cpu_switch_aot #2199
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2207"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by dicnunz on 2026-11-25T05:11:48Z.
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
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T05:20:58Z.
Review: COMMENTED
Review of head
9e8d90905d275e333da1bba4219d096491f28158(comment only, no approval).Scope read:
git diff --stat origin/main...HEADshows 8 files, +763/-30:tools/cpu_switch_aot.py, the newtests/cpu/recursion.{asm,def}andrecursion_check.py, the two existing call controls,CMakeLists.txtanddocs/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):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:
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.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.AI-assisted; commands listed were executed locally.