Skip to content

jit: #369 S4 — retire the pyre-local resume-coordinate twins#550

Merged
youknowone merged 4 commits into
mainfrom
rewrite-tracer
Jul 14, 2026
Merged

jit: #369 S4 — retire the pyre-local resume-coordinate twins#550
youknowone merged 4 commits into
mainfrom
rewrite-tracer

Conversation

@youknowone

Copy link
Copy Markdown
Owner

#369 S4 — retire the pyre-local resume-coordinate twins

Follows up #536 (which merged the P1–P5 pc-word flip: the resume frame now
holds RPython's single 2-word (jitcode_index, pc) header where pc is the
JitCode byte offset). #536 left two pyre-local twin coordinates outside the
rd_numb wire — on ReconstructRecipe and BridgeInlineCarrier. This branch
retires them, so every resume coordinate in the tracer is the single JitCode
offset, back-translated to a Python pc only where a py_pc-keyed consumer needs
it.

Commits

  • S4a — delete the recipe/carrier jitcode_pc twins (2996ef697be)
    Deletes ReconstructRecipe.pc and BridgeInlineCarrier.root_jitcode_pc.
    recipe.pc was definitionally backxlat_py_pc(index, jitcode_pc), so recipe
    readers re-derive it; carrier readers repoint to root_pc. Carried-offset
    parameters drop out. Byte-identical: internal census gates
    (PYRE_S4_RECIPE_AUDIT / PYRE_S4_CARRIER_AUDIT) certified 0 divergences,
    0 sentinel-reach
    over the corpus on both backends (299 recipe + 1495 carrier
    asserts/backend).

  • S4.5 — consume the carrier resume coordinate in Python-pc space
    (afd52b416db)
    After S4a the carrier holds one JitCode-offset coordinate. Several
    py_pc-keyed consumers (set_last_instr, result_color_at_pc_at,
    make/set_green_key, resume_jitcode_pc_for, the frame-liveness pc argument,
    the WalkContext.entry_py_pc / parent resume_py_pc fields) were reading that
    offset as if it were a Python bytecode pc. Back-translate at each of those
    sinks with backxlat_py_pc; add BridgeInlineCarrier.root_jitcode_index as
    the translation key at the one sink that runs before a body index is otherwise
    in scope. The raw offset is preserved where genuinely needed (walker-driver
    start_pc, the carried select_recipe_entry argument, root_word, the
    frame-liveness carried argument). This addresses the jit: #369 pc-word flip — resume frame collapses to RPython 2-word shape #536 codex review finding
    "Translate root pc before building bridge carrier" via consume-side inversion.

    Byte-behaviour-neutral on the current corpus: the multi-frame carrier walk
    still declines (P2Framestack::OuterNonTerminate) for an unrelated,
    non-coordinate reason, so no compile is newly enabled. The change makes the
    un-exercised multi-frame path coordinate-correct; the remaining
    OuterNonTerminate blocker is separate future work.

  • guard backxlat_py_pc against negative pc words (227b07d2205)
    Addresses the jit: #369 pc-word flip — resume frame collapses to RPython 2-word shape #536 coderabbit review finding: the i32→usize casts in the
    pc-translation helpers would wrap a negative word (sentinel / branch-orgpc tag)
    to a huge offset. Return the decoded fallback directly for negative input.

Verification

  • check.py: 181/181 dynasm + 181/181 cranelift.
  • S4.5 got two independent adversarial diff reviews (completeness + coordinate
    correctness), both clean: all 12 inversions + the field + the debug_assert
    present, every inverted/leave-raw sink coordinate-verified against re-derived
    helper signatures, no over/under-inversion.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@youknowone, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 47 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6a61a192-ef18-41ce-8128-a1cc07134069

📥 Commits

Reviewing files that changed from the base of the PR and between e593b6a and f1d6783.

📒 Files selected for processing (6)
  • majit/majit-metainterp/src/trace_ctx.rs
  • pyre/pyre-jit-trace/src/jitcode_dispatch.rs
  • pyre/pyre-jit-trace/src/pyjitcode.rs
  • pyre/pyre-jit-trace/src/state.rs
  • pyre/pyre-jit-trace/src/trace.rs
  • pyre/pyre-jit/src/eval.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch rewrite-tracer

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown

🤖 Codex parity review

Static analysis of this diff vs the local RPython/PyPy sources (commit 347cac6).

Files in the reviewed diff
majit/majit-metainterp/src/trace_ctx.rs
pyre/pyre-jit-trace/src/jitcode_dispatch.rs
pyre/pyre-jit-trace/src/pyjitcode.rs
pyre/pyre-jit-trace/src/state.rs
pyre/pyre-jit-trace/src/trace.rs
pyre/pyre-jit/src/eval.rs

1. Regressions to PyPy parity introduced by this patch

None.

2. Other mismatches introduced by this patch

None.

3. Pre-existing mismatches (already present before this patch)

  • pyre/pyre-jit-trace/src/state.rs:795 ↔ rpython/jit/metainterp/pyjitpl.py:1878: backxlat_py_pc(-1) does not “pass through” the sentinel as its new comment claims. It casts -1 to usize, maps it as a JitCode offset, and can select the final emitted Python instruction; PyPy preserves the resume PC verbatim (self.pc = pc). This implementation predates the patch; eval.rs:7678 now correctly screens this caller.

4. Structural adaptations

  • pyre/pyre-jit-trace/src/trace.rs:403 ↔ rpython/jit/metainterp/resume.py:1049: PyPy’s resumed pc is directly usable by its MIFrame because it executes JitCode. Pyre must translate the resumed JitCode offset to a CPython/Python-bytecode instruction coordinate before calling PyFrame::set_last_instr_from_next_instr; this patch makes that conversion explicit.

  • pyre/pyre-jit-trace/src/jitcode_dispatch.rs:2817 ↔ rpython/jit/metainterp/pyjitpl.py:174: PyPy uses its JitCode PC directly for liveness. Pyre has separate JitCode and Python-PC coordinate spaces, so the patch translates to Python PC for result-color/liveness metadata while retaining the original JitCode offset as the carried resume marker (jitcode_dispatch.rs:2844).

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 227b07d220

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pyre/pyre-jit-trace/src/state.rs Outdated
Comment on lines +794 to +795
if pc_word < 0 {
return fallback;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid returning negative PCs from back-translation

When this helper is called with NO_JITCODE_PC or a branch-orgpc tag, decode_resume_pc leaves the word negative, so this new early return exposes that negative value as the “Python pc”. Several resume consumers immediately cast backxlat_py_pc(...) to usize/u32 (for example the guard-failure rd_numb_pc path in pyre/pyre-jit/src/eval.rs), so a no-snapshot or tagged frame can become usize::MAX/a huge pc and corrupt the resumed frame position instead of declining or expanding the tag. The guard needs to avoid the internal wrap without returning a negative coordinate to callers.

Useful? React with 👍 / 👎.

Remove ReconstructRecipe.pc and BridgeInlineCarrier.root_jitcode_pc, the two
pyre-local resume-coordinate twins left after S5. Post-flip both twins already
hold the JitCode offset, and recipe.pc is definitionally
backxlat_py_pc(recipe.jitcode_index, recipe.jitcode_pc), so every reader
re-derives its value from the surviving coordinate: recipe readers call
backxlat_py_pc; carrier readers use root_pc directly and drop the carried
offset parameters. The recipe and carrier resume frames now store a single
JitCode-offset coordinate.

Byte-identical: a gated census over the corpus on both backends certified
0 recipe divergences, 0 carrier divergences, and 0 sentinel-reaching readers
before the fields were removed.

Assisted-by: Claude
Assisted-by: Codex
…pace

After S4a the BridgeInlineCarrier carries a single JitCode-offset coordinate
(root_pc). Several consumers fed that offset into Python-pc-keyed machinery
(set_last_instr_from_next_instr, result_color_at_pc_at, make_green_key /
set_green_key, resume_jitcode_pc_for, the frame-liveness pc argument, and the
WalkContext entry_py_pc / parent resume_py_pc fields), i.e. they read a JitCode
offset as if it were a Python bytecode pc.

Back-translate the offset with backxlat_py_pc(jitcode_index, root_pc) at each
of those py_pc-keyed sinks so the single coordinate is consumed in its correct
space, and add BridgeInlineCarrier.root_jitcode_index (= frames[0].jitcode_index)
as the back-translation key at the one sink (set_last_instr) that runs before a
body index is otherwise in scope; every other sink uses its co-located body
index. The raw offset is preserved wherever it is genuinely needed: the walker
drivers' start_pc, the carried select_recipe_entry argument, root_word, and the
frame-liveness carried argument.

Byte-behaviour-neutral on the current corpus: the multi-frame carrier walk still
declines (P2Framestack::OuterNonTerminate) for an unrelated reason, so no compile
is newly enabled; calls_closures.py (the 299-carrier reproducer) stays stdout
byte-identical to the interpreter and check.py holds 180/180 on both backends.

Assisted-by: Claude
Assisted-by: Codex
python_pc_for_jitcode_pc_public and skip_python_trivia_forward_public cast
their i32 pc inputs to usize without a sign check, so a negative pc word
(a sentinel or branch-orgpc tag) wraps to a huge offset before reaching the
jitcode metadata lookup. Return the decode_resume_pc fallback directly when
the word is negative, preserving the existing fallback behaviour without
relying on every caller to pre-screen.

Addresses the PR #536 review finding on backxlat_py_pc.

Assisted-by: Claude
The rd_numb_pc computation in rebuild_typed_from_rd_numb passed the outer
frame's pc to backxlat_py_pc and cast the result to usize without screening the
`pc == -1` no-snapshot sentinel, so a sentinel frame produced `usize::MAX`. Its
two siblings walking the same rebuilt-frame chain already screen it
(build_resumed_frames `frame.pc >= 0`, the carrier construction
`frames[0].pc >= 0`); mirror that here so the sentinel yields `rd_numb_pc =
None`.

Revert the backxlat_py_pc internal `pc < 0` guard added in the previous commit:
it returned the negative word unchanged (decode_resume_pc passes negatives
through), so it did not protect the usize-casting caller, and the internal
metadata lookups are bounds-checked and never index with the word. The screen
belongs at the caller, per the decode_resume_pc contract.

Addresses the PR #550 review finding on backxlat_py_pc.

Assisted-by: Claude
Assisted-by: Codex
@youknowone youknowone merged commit 6176753 into main Jul 14, 2026
30 checks passed
@youknowone youknowone deleted the rewrite-tracer branch July 14, 2026 23:01
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