Skip to content

Conversation

@youknowone
Copy link
Member

@youknowone youknowone commented Jan 17, 2026

Summary by CodeRabbit

  • Chores
    • Improved garbage collection handling for async generators, coroutines, and generators to enable more efficient memory management.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 17, 2026

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.

@github-actions
Copy link
Contributor

Code has been automatically formatted

The code in this PR has been formatted using:

  • cargo fmt --all
    Please pull the latest changes before pushing again:
git pull origin traverse

@youknowone youknowone marked this pull request as ready for review January 18, 2026 00:35
@youknowone youknowone merged commit abea6bd into RustPython:main Jan 18, 2026
11 of 13 checks passed
@youknowone youknowone deleted the traverse branch January 18, 2026 00:36
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