Skip to content

Add per-type vectorcall for builtin constructors#7407

Draft
youknowone wants to merge 2 commits intoRustPython:mainfrom
youknowone:vectorcall
Draft

Add per-type vectorcall for builtin constructors#7407
youknowone wants to merge 2 commits intoRustPython:mainfrom
youknowone:vectorcall

Conversation

@youknowone
Copy link
Member

close #7362

Add vectorcall dispatch in vectorcall_type to check each type's own slots.vectorcall before falling back to PyType::call. Clear vectorcall when init or new is overridden in update_slot to ensure subclass correctness.

Implement per-type vectorcall for 12 builtin types:

  • Pattern A (skip args.clone): dict, set, list, bytearray
  • Pattern B (skip dispatch): int, float, str, bool, tuple, frozenset, bytes, complex

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 12, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 6a6ddad2-7511-47c6-8afa-3dc984d8c3c6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan for PR comments
  • Generate coding plan

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.

Add vectorcall dispatch in vectorcall_type to check each type's
own slots.vectorcall before falling back to PyType::call.
Only dispatch when slots.call is None, to avoid misinterpreting
callable-instance vectorcalls (e.g. vectorcall_function) as
constructor vectorcalls.

Clear vectorcall when __init__ or __new__ is overridden in
update_slot to ensure subclass correctness.

Implement per-type vectorcall for 12 builtin types:
- Pattern A (skip args.clone): dict, set, list, bytearray
- Pattern B (skip dispatch): int, float, str, bool, tuple,
  frozenset, bytes, complex
@github-actions
Copy link
Contributor

📦 Library Dependencies

The following Lib/ modules were modified. Here are their dependencies:

[x] lib: cpython/Lib/poplib.py
[x] test: cpython/Lib/test/test_poplib.py (TODO: 1)

dependencies:

  • poplib

dependent tests: (1 tests)

  • poplib: test_poplib

Legend:

  • [+] path exists in CPython
  • [x] up-to-date, [ ] outdated

Pattern B vectorcall functions now call through zelf.slots.new
instead of calling PyXxx::slot_new directly. This ensures Rust-level
subclasses with custom slot_new (e.g. stat_result subclassing tuple)
get their own constructor called correctly.

Fix PyStatResult::slot_new to use struct_sequence_new for proper
length validation and hidden field padding, matching structseq_new
behavior. Derive st_atime/st_mtime/st_ctime and their _ns variants
from integer time fields when not explicitly provided.
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.

vectercall per type

1 participant