| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
📝 Walkthrough
WalkthroughMoved TypeZoo and ExceptionZoo extension into Context::genesis and changed many builtin init/extend APIs to accept a &'static Context; class construction now derives a &'static Context via an unsafe cast and uses that context's slot_new_wrapper when building bound new methods, with added safety comments. Changes
Sequence Diagram(s)sequenceDiagram
participant Genesis as Context::genesis
participant TypeZoo as TypeZoo
participant ExceptionZoo as ExceptionZoo
participant MakeClass as make_class / extend_class
participant Builtin as builtin::init
Genesis->>TypeZoo: TypeZoo::extend(&ctx)
Genesis->>ExceptionZoo: ExceptionZoo::extend(&ctx)
Note right of Genesis: genesis returns Context (now populated)
Builtin->>MakeClass: call make_class(ctx)
MakeClass->>MakeClass: unsafe cast ctx -> &'static Context
MakeClass->>MakeClass: use ctx.slot_new_wrapper to build bound __new__
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem🚥 Pre-merge checks | ✅ 2 | ❌ 1 ❌ Failed checks (1 warning)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches 🧪 Generate unit tests (beta)
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. ❤️ ShareComment @coderabbitai help to get the list of available commands and usage tips. |
Sorry, something went wrong.
|
Code has been automatically formatted The code in this PR has been formatted using:
git pull origin genesis-extend |
Sorry, something went wrong.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agentsVerify each finding against the current code and only fix it if needed. Inline comments: In `@crates/vm/src/class.rs`: - Around line 191-196: The unsafe cast to &'static PyMethodDef (using ctx.slot_new_wrapper) is unsound because extend_class takes ctx: &Context; change the trait signature to require static lifetimes (e.g., fn extend_class(ctx: &'static Context, class: &'static Py<PyType>)) so the compiler encodes the invariant, update all impls/call sites accordingly, then remove the unsafe &'static cast and use wrapper = &ctx.slot_new_wrapper directly (or keep wrapper as &'static if callers now supply &'static Context); reference symbols: extend_class, Context, ctx.slot_new_wrapper, PyMethodDef, build_bound_method, and class.set_attr to locate and modify the code.
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📥 CommitsReviewing files that changed from the base of the PR and between 0a6a6f8 and 050ca62.
📒 Files selected for processing (3)
Sorry, something went wrong.
There was a problem hiding this comment.
crates/vm/src/class.rs (1)209-217: ⚠️ Potential issue | 🔴 Critical
make_class still allows non-static input before forcing 'static via unsafe cast.
Line 217 casts &Context to &'static Context, but Line 209 still accepts any borrowed context. If a non-genesis context reaches this path, this is undefined behavior.
Suggested fix- fn make_class(ctx: &Context) -> PyTypeRef + fn make_class(ctx: &'static Context) -> PyTypeRef where Self: StaticType + Sized, { (*Self::static_cell().get_or_init(|| { let typ = Self::create_static_type(); - // SAFETY: Context is heap-allocated via PyRc and stored in a static cell - // (Context::genesis), so it lives for 'static. - let ctx: &'static Context = unsafe { &*(ctx as *const Context) }; Self::extend_class(ctx, unsafe { // typ will be saved in static_cell let r: &Py<PyType> = &typ;#!/bin/bash set -euo pipefail echo "== Check make_class signature and unsafe cast ==" rg -nP --type=rust -C2 'fn\s+make_class\s*\(\s*ctx:\s*&Context\s*\)|unsafe\s*\{\s*&\*\(ctx as \*const Context\)\s*\}' crates/vm/src/class.rs echo echo "== List make_class call sites ==" rg -nP --type=rust -C2 '\bmake_class\s*\(' echo echo "== Inspect Context construction/entrypoints ==" rg -nP --type=rust -C3 'impl\s+Context|fn\s+genesis\s*\(|fn\s+new\s*\(' crates/vm/src/vm/context.rsAs per coding guidelines "Follow Rust best practices for error handling and memory management".
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📥 CommitsReviewing files that changed from the base of the PR and between 8df31f9 and 072c495.
📒 Files selected for processing (53)
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary by CodeRabbit