Allow c functions in tp_new type slot#8346
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (11)
🚧 Files skipped from review as they are similar to previous changes (11)
📝 WalkthroughWalkthrough
ChangesNew slot dispatch
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant BuiltinVectorcall
participant NewFunc
participant TypeDispatch
BuiltinVectorcall->>NewFunc: Load slots.new and invoke(cls, args, vm)
TypeDispatch->>NewFunc: Invoke resolved __new__ slot
NewFunc-->>BuiltinVectorcall: Return PyResult
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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. Comment |
00b1ca8 to
69d97b0
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
crates/vm/src/types/slot.rs (1)
316-329: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDerive
PartialEq, Eqto simplify identity checks.Function pointers natively implement
PartialEqandEq. Deriving these traits onNewFuncallows direct equality comparisons (==and!=) on the variants, entirely eliminating the need for the manualidentity()method and the verbose mapping at all call sites.
crates/vm/src/types/slot.rs#L316-L329: Add#[derive(PartialEq, Eq)]toNewFuncand remove theidentitymethod entirely.crates/vm/src/types/slot.rs#L909-L911: Replace the comparison withcls.slots.new.load() == Some(NewFunc::Rust(new_wrapper as _)).crates/vm/src/builtins/type.rs#L2835-L2835: Replace the condition withslot_new != crate::types::NewFunc::Rust(crate::types::new_wrapper as _).crates/vm/src/builtins/type.rs#L3072-L3072: Replace the check withif typ_new != staticbase_new {.crates/vm/src/class.rs#L207-L208: Replace the inheritance check with!is_object_itself && object_new == Some(slot_new).crates/vm/src/frame.rs#L9243-L9243: Replace the identity comparison withcls_new_fn == obj_new_fn.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/vm/src/types/slot.rs` around lines 316 - 329, Derive PartialEq and Eq for NewFunc and remove its identity method, then replace all identity-based comparisons with direct NewFunc equality checks: update crates/vm/src/types/slot.rs lines 316-329 and 909-911, crates/vm/src/builtins/type.rs lines 2835 and 3072, crates/vm/src/class.rs lines 207-208, and crates/vm/src/frame.rs line 9243 as specified, preserving the existing comparison semantics.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/vm/src/types/slot.rs`:
- Around line 316-320: Preserve lock-free access for PyTypeSlots::new by
avoiding the two-variant NewFunc representation in AtomicCell<Option<NewFunc>>.
Update NewFunc and the associated new-slot storage/access paths to use a
pointer-sized representation compatible with the target atomic width, while
retaining support for both Rust and C constructors.
---
Nitpick comments:
In `@crates/vm/src/types/slot.rs`:
- Around line 316-329: Derive PartialEq and Eq for NewFunc and remove its
identity method, then replace all identity-based comparisons with direct NewFunc
equality checks: update crates/vm/src/types/slot.rs lines 316-329 and 909-911,
crates/vm/src/builtins/type.rs lines 2835 and 3072, crates/vm/src/class.rs lines
207-208, and crates/vm/src/frame.rs line 9243 as specified, preserving the
existing comparison semantics.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: b97f0fc2-eccf-40ed-878e-0572a321a7a8
📒 Files selected for processing (11)
crates/derive-impl/src/pyclass.rscrates/vm/src/builtins/bool.rscrates/vm/src/builtins/float.rscrates/vm/src/builtins/int.rscrates/vm/src/builtins/set.rscrates/vm/src/builtins/str.rscrates/vm/src/builtins/tuple.rscrates/vm/src/builtins/type.rscrates/vm/src/class.rscrates/vm/src/frame.rscrates/vm/src/types/slot.rs
69d97b0 to
f884722
Compare
This is my first draft of allowing C functions in type slots. I started with the
NewFuncslot and would love some feedback on my approach before converting the other slots.@youknowone Could you please share your opinion.
Summary by CodeRabbit
Bug Fixes
__new__constructor dispatch across built-in types (bool, int, float, str, tuple, set) by invoking the resolved constructor target more reliably.__initfast-path specialization, improving when the optimized path is selected.__new__wrappers and inherited constructor behavior for classes/types.Compatibility
__new__variants.