GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Allow c functions in tp_new type slot by bschoenmaeckers · Pull Request #8346 · RustPython/RustPython Conversation
|
📝 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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
00b1ca8 to
69d97b0
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 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.
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.
Fix all unresolved CodeRabbit comments on this PR:
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: b97f0fc2-eccf-40ed-878e-0572a321a7a8
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
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
69d97b0 to
f884722
Compare
| Rust(fn(PyTypeRef, FuncArgs, &VirtualMachine) -> PyResult), | ||
| C(unsafe extern "C" fn(*mut PyObject, *mut PyObject, *mut PyObject) -> *mut PyObject), |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'd like not to introduce an enum for this.
let me try do this by adding a bridge in capi side.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We might need a Box<dyn Fn> for this. As in my testing I could not store ar c fn in a fn slot.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
If you need a testbed, please try to fix this TODO here: https://github.com/bschoenmaeckers/RustPython/blob/880999db85bd14f497e48e07e74b3745dd484994/crates/capi/src/object/pytype.rs#L194-L198
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
this is more complicated than my first expectation. i am trying another way
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
could you check if this way work? #8435
Sorry, something went wrong.
There was an error while loading. Please reload this page.
f884722 to
8c53827
Compare
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.