Skip to content

Merge PyInner into Py - #8820

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowone:merge-pyinner-into-py
Sep 25, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
youknowone:merge-pyinner-into-py

Conversation

@youknowone

@youknowone youknowone commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Py<T> was a #[repr(transparent)] newtype over the private PyInner<T>, which held the object header and payload. This renames PyInner<T> to Py<T> and makes it the public type, so there is one struct for the object layout.

  • Header fields (ref_count, vtable, gc_*, typ, payload) stay pub(super), so nothing new is exposed outside object.
  • PyObject is now PyObject(Py<Erased>).
  • Py<T> accesses drop the .0 hop.
  • The delegating Traverse for Py<T> impl is gone; the former Traverse for PyInner<T> impl now serves Py<T>.
  • Debug for PyInner<T> is gone; debug_obj writes the same [PyObject ...] output itself.
  • PyWeak::drop_inner uses Py::from_payload_ptr instead of recomputing the payload offset.

No layout or behavior change intended.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Updated the runtime’s internal handling of objects, including allocation, memory management, and garbage collection. These changes do not alter application behavior or add user-facing features. No other user-visible changes are included.

Rename the object layout struct `PyInner<T>` to `Py<T>` and make it the
public type, replacing the `#[repr(transparent)]` newtype
`Py<T>(PyInner<T>)`. Header fields stay `pub(super)`. `PyObject` now
wraps `Py<Erased>`.

- Drop the `.0` hop on `Py<T>` accesses.
- Remove the delegating `Traverse for Py<T>` impl; the former
  `Traverse for PyInner<T>` impl now serves `Py<T>`.
- Remove `Debug for PyInner<T>`; `debug_obj` writes the
  `[PyObject ...]` form itself.
- Use `Py::from_payload_ptr` in `PyWeak::drop_inner` and drop its
  now-stale `allow(dead_code)`.

Assisted-by: Claude Code:claude-opus-5-5
@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: RustPython/RustPython/.coderabbit.yml

Review profile: CHILL

Plan: Advanced

Run ID: 1f2bc120-b3ec-4017-b528-1cf2b5091e12

📥 Commits

Reviewing files that changed from the base of the PR and between 05103e8 and 867c262.

📒 Files selected for processing (6)
  • crates/vm/src/builtins/tuple.rs
  • crates/vm/src/frame.rs
  • crates/vm/src/gc_state.rs
  • crates/vm/src/object/core.rs
  • crates/vm/src/object/payload.rs
  • crates/vm/src/object/traverse_object.rs

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The object header and payload now reside directly in Py<T>, replacing the PyInner<T> backing representation. Allocation, deallocation, pointer access, reference counting, weakref handling, freelist reuse, traversal, and bootstrap code now use the direct representation.

Changes

Py object representation

Layer / File(s) Summary
Define the Py object layout
crates/vm/src/object/core.rs
Py<T> now contains the object header and payload directly. Prefix offsets, payload access, and pointer casts use the Py<T> layout.
Update allocation and object lifecycle
crates/vm/src/object/core.rs, crates/vm/src/builtins/tuple.rs, crates/vm/src/frame.rs, crates/vm/src/gc_state.rs, crates/vm/src/object/payload.rs
Allocation, deallocation, reference counting, weakref handling, and freelist reuse access Py<T> fields directly. Related comments describe pointers and allocations using Py<T>.
Adapt traversal and bootstrap code
crates/vm/src/object/core.rs, crates/vm/src/object/traverse_object.rs
Traversal implementations and bootstrap allocations use Py<T> pointers. The typed Py<T> traversal implementation was removed.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Suggested reviewers: shaharnaveh

Merge Risk: ⚪ Minimal · up to 867c2

No actionable merge-blocking risk is identified; this change is ready for normal validation.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 867c2

The object-layout change affects a central VM component, but the reviewed paths preserve the existing ownership and lifecycle controls. No introduced security failure was established; some downstream and runtime coverage remains incomplete.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — A layout or lifetime error here could affect Python objects throughout a hosting VM, including their weak-reference and garbage-collection paths; this is potential scope, not an observed failure.

Trust Boundaries and Controls

  • observed — Header fields remain pub(super), payload-pointer recovery remains unsafe and crate-scoped, and published objects continue to avoid freelist reuse while readers may retain pointers.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ❓ Inconclusive Docstring coverage is 59.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 47 functions across 5 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title, “Merge PyInner into Py,” clearly describes the main change: replacing PyInner with Py as the object-layout type.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 59.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 47 functions across 5 files. (1 skipped: 1 too large.)

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

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.

@youknowone
youknowone marked this pull request as ready for review September 25, 2026 18:30
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@youknowone
youknowone merged commit 393689d into RustPython:main Sep 25, 2026
30 checks passed
@youknowone
youknowone deleted the merge-pyinner-into-py branch September 25, 2026 18:56
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