◐ Shell
clean mode source ↗

Improve object traversal for heap types and mro by youknowone · Pull Request #6976 · RustPython/RustPython

📝 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.