◐ Shell
clean mode source ↗

traverse for generator by youknowone · Pull Request #6760 · RustPython/RustPython

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This PR adds manual garbage collection traversal support by implementing the Traverse trait for async generators, coroutines, generators, and the core Coro struct, while marking their pyclass definitions with traverse = "manual" to enable explicit GC tracing of contained fields.

Changes

Cohort / File(s) Summary
Async Generator Traversal
crates/vm/src/builtins/asyncgenerator.rs
Added unsafe impl Traverse for PyAsyncGen, PyAsyncGenWrappedValue, PyAsyncGenASend, PyAsyncGenAThrow, and PyAnextAwaitable; each implementation traverses its inner fields (Coro, finalizer, wrapped values). Updated all five pyclass definitions with traverse = "manual".
Coroutine and Wrapper Traversal
crates/vm/src/builtins/coroutine.rs
Added unsafe impl Traverse for PyCoroutine (delegates to self.inner) and PyCoroutineWrapper (delegates to self.coro). Updated both pyclass definitions with traverse = "manual".
Generator Traversal
crates/vm/src/builtins/generator.rs
Added unsafe impl Traverse for PyGenerator delegating to self.inner.traverse(tracer_fn). Updated pyclass definition with traverse = "manual". Added imports for Traverse and TraverseFn.
Core Coro Traversal
crates/vm/src/coroutine.rs
Added unsafe impl Traverse for Coro struct that traverses frame, name, qualname, and exception fields.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • sys.set_asyncgen_hook #6439 — Modifies the same async generator types (PyAsyncGen, PyAnextAwaitable, PyAsyncGenASend/AThrow/WrappedValue) with lifecycle methods and state management
  • PyAnextAwaitable  #6427 — Introduces or modifies PyAnextAwaitable and async generator types alongside GC traversal additions

Poem

🐰 A rabbit hops through memory lanes,
Tracing coroutines' flowing chains,
Generators yield their GC care,
Traverse marks what's hiding there!
Cleanup bound, no leaks remain ✨

✨ Finishing touches
  • 📝 Generate docstrings

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.