Skip to content

codegen: handle continuation PCs and nested callee yields#115

Closed
jlsandri wants to merge 3 commits intoran-j:mainfrom
jlsandri:pr/codegen-continuation-pcs
Closed

codegen: handle continuation PCs and nested callee yields#115
jlsandri wants to merge 3 commits intoran-j:mainfrom
jlsandri:pr/codegen-continuation-pcs

Conversation

@jlsandri
Copy link
Copy Markdown

@jlsandri jlsandri commented Apr 6, 2026

Stacked on #110 (codegen: remove dead else branch). Please merge #110 first — once it lands, this PR's diff shrinks to just the two commits below.

Problem

The recompiler's "continuation PC" model assumed a 1:1 mapping between continuation targets and emitted entry functions, and that calls into functions with continuation PCs would always yield back at the single expected fallthrough address.

Two related failure modes:

  1. Continuation targets without a separate entry function. When the analysis produced a continuation PC that did not have its own entry_... wrapper, the codegen path assumed the entry existed and produced a call that couldn't be dispatched.
  2. Nested callee yields. When callee A yielded internally and re-entered itself at a continuation PC, and callee B was called from inside A, B's own continuation yield would bubble up as a PC_MISMATCH in A's caller — a false positive, because A was still mid-execution and just hadn't reached its outer fallthrough yet.

Fix

Two commits:

  1. Handle continuation PCs without separate entry functions. Teach code_generator.cpp / ps2_recompiler.cpp to dispatch continuation targets directly when no entry wrapper exists, instead of assuming the wrapper is always present. Adds a new bookkeeping field to the codegen header.

  2. Add a continuation re-entry loop for nested callee yields. After a call, emit a while loop that keeps re-entering the callee while its yielded ctx->pc lies inside the callee's own range, only exiting to the caller when the real fallthrough PC is reached.

These go together — the re-entry loop depends on the first commit's bookkeeping to know where a continuation target lives.

Scope

  • ps2xRecomp/include/ps2recomp/code_generator.h: +3 / -0
  • ps2xRecomp/src/lib/code_generator.cpp: +124 / -6
  • ps2xRecomp/src/lib/ps2_recompiler.cpp: +41 / -17

Rationale

Continuation PCs were already a supported concept in the recompiler; this PR just makes the handling robust to the two edge cases above, which were producing false PC_MISMATCH aborts in otherwise well-formed code.

jlsandri added 3 commits April 6, 2026 18:55
When a callee yields at an internal continuation PC, the caller now
re-enters it in a while loop until it exits to the real fallthrough.
Prevents nested continuations from leaking as false PC_MISMATCH.
@jlsandri jlsandri force-pushed the pr/codegen-continuation-pcs branch from ab38ace to ffeaddc Compare April 6, 2026 08:56
@jlsandri
Copy link
Copy Markdown
Author

jlsandri commented Apr 6, 2026

Closing as part of a batch cleanup after #107 landed. The runtime ecosystem refactor in #107 substantially reworked the files this PR touched, and I would like to re-audit the underlying fix against the new code structure before putting it back in front of you. If the fix is still needed after that re-audit, I will re-open as a focused PR rebased onto current main. Thanks for your patience.

@jlsandri jlsandri closed this Apr 6, 2026
@jlsandri jlsandri deleted the pr/codegen-continuation-pcs branch April 6, 2026 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant