Skip to content

Conversation

@youknowone
Copy link
Member

@youknowone youknowone commented Feb 3, 2026

  • Fix heap type instance traversal to include type reference (enables correct cycle detection for instance ↔ type references)
  • Enable mro traversal in PyType (was previously disabled)

Summary by CodeRabbit

  • Refactor
    • Improved garbage collection traversal for type objects to ensure proper memory management of type hierarchies and heap-allocated types.

- Fix heap type instance traversal to include type reference
  (enables correct cycle detection for instance ↔ type references)
- Enable mro traversal in PyType (was previously disabled)
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 3, 2026

📝 Walkthrough

Walkthrough

This PR enhances garbage collection tracing in the RustPython VM by re-enabling MRO traversal in PyType and adding explicit heap-type reference tracing in PyInner object traversal. These changes ensure complete marking of type relationships during GC cycles.

Changes

Cohort / File(s) Summary
GC Traversal Enablement
crates/vm/src/builtins/type.rs
Re-enabled MRO traversal in PyType's traverse implementation by uncommenting self.mro.traverse(tracer_fn), ensuring all MRO entries are visited during GC tracing.
Heap Type Reference Tracing
crates/vm/src/object/traverse_object.rs
Added explicit tracing of heap-type references in both PyInner and PyInner paths. When a type is a heap type, the type object is now converted to PyObject and traced before dict/slots traversal continues.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Poem

🐰 Hop, hop, the MRO flows,
No more gaps in traces that the garbage knows,
Heap types shine with reference bright,
GC cycles now collect all in sight!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Improve object traversal for heap types and mro' directly and accurately summarizes the main changes: enabling MRO traversal in PyType and improving heap type instance traversal to include type references.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

@youknowone youknowone marked this pull request as ready for review February 3, 2026 08:10
@youknowone youknowone merged commit d6aab01 into RustPython:main Feb 3, 2026
13 checks passed
@youknowone youknowone deleted the traverse-improvements branch February 3, 2026 08:54
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