Skip to content

Separate constructor and instance vectorcall dispatch - #9320

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:cpython-315-vectorcall-dispatch-roles
Oct 23, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:cpython-315-vectorcall-dispatch-roles

Conversation

@youknowdot

Copy link
Copy Markdown
Contributor

Summary

Separate constructor vectorcall from instance-call capability, and distinguish retained raw support from automatic vectorcall eligibility.

  • Keep builtin constructor implementations on their own non-inherited slot, with a separate type-instance resolver.
  • Inherit instance capability and eligibility under their respective conditions. A generic Python __call__ revokes automatic eligibility without deleting raw support.
  • Make the existing PyVectorcall_Call entry point use retained raw support directly, without an artificial tp_call fallback/precondition.
  • Recheck eligibility when a retained callable wrapper invokes cached vectorcall support. This handles a partial subclass changing __call__ between two regex replacement calls.
  • Update builtin registrations, constructor specialization and partial dispatch consistently. No new test namespace or Lib changes.

This is a Python 3.15 upgrade prerequisite, not the complete _testcapi fixture integration.

Validation

Tested commit 0624705569dff7c3954f9129ba8b9d04469872d7 on base e5554e23abfbaee85508c32fc22e5074f88aebdd, Linux x86-64, Rust 1.99.1:

  • CLI build: passed.
  • Strict VM Clippy, default and threading: passed.
  • VM no-default-features library check: passed.
  • Strict derive-impl library Clippy: passed.
  • Strict C API library Clippy from its configured crate directory: passed.
  • Normal repository commit hooks: passed.

A separately built CPython 3.15.0 final (d220409a13b77de7a6c30abe16ea90db01528edc) was compared with the source-bound RustPython binary in fresh processes:

  • 37 constructor/builtin plus 14 partial records: all 51 portable results agree.
  • 26 capability/flag records: 25 agree. RustPython's wrapper_descriptor retains its genuine native vectorcall capability, whereas CPython does not expose that flag for its implementation. Immutable-type and method-descriptor flags agree. This is not reported as universal flag parity.
  • The bounded two-substitution callback case returns AB on both interpreters after __call__ changes during the first call.
  • 19 selected existing canonical test_functools/test_call tests: 19 ordinary passes, zero failures, errors, skips, expected failures or unexpected successes.

No baseline runtime comparison, benchmark, full test suite, external C ABI runtime, PyO3 bridge runtime, or non-Linux execution is claimed. C API validation here is source review plus compilation/linting.

Integration boundaries

Raw storage and automatic eligibility are now distinct. Related call-slot inheritance work in #6301 must preserve that distinction rather than mechanically transplanting the old architecture. For a plain-metaclass adaptation that intentionally disables automatic vectorcall, the current mechanism is slots.flags.remove(PyTypeFlags::HAVE_VECTORCALL), not deleting retained raw storage. This is an unvalidated downstream integration note, not a claim about that PR's broader compatibility.

This patch does not implement arbitrary concurrent native slot replacement, cached-None/ArgCallable redesign, C API kwargs error-precedence changes, or the custom-MRO missing-call/fresh-dispatch edge. It does not change lifecycle ownership or the #8944 retirement contract.

Implementation, review and automated validation were AI-assisted. The model version identifier is unavailable. Automated validation is not human verification.

Keep constructor fast paths separate from per-instance vectorcall support.
Track automatic eligibility without discarding raw support required by
PyVectorcall_Call, and recheck eligibility in retained callable wrappers.

Implementation and source review were AI-assisted. The model version
identifier is unavailable; automated checks are not human verification.

Assisted-by: OpenAI Codex:model version unavailable
@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between e5554e2 and 0624705.

📒 Files selected for processing: 19
  • crates/capi/src/abstract_.rs
  • crates/derive-impl/src/pyclass.rs
  • crates/vm/src/builtins/bool.rs
  • crates/vm/src/builtins/builtin_func.rs
  • crates/vm/src/builtins/descriptor.rs
  • crates/vm/src/builtins/dict.rs
  • crates/vm/src/builtins/float.rs
  • crates/vm/src/builtins/function.rs
  • crates/vm/src/builtins/int.rs
  • crates/vm/src/builtins/list.rs
  • crates/vm/src/builtins/set.rs
  • crates/vm/src/builtins/str.rs
  • crates/vm/src/builtins/tuple.rs
  • crates/vm/src/builtins/type.rs
  • crates/vm/src/frame.rs
  • crates/vm/src/protocol/callable.rs
  • crates/vm/src/stdlib/_functools.rs
  • crates/vm/src/types/slot.rs
  • crates/vm/src/types/slot_defs.rs
+------------------------------------------------------------------+
| Fine-tuning the Enterprise's warp drive to avoid BSOD at warp 9. |
+------------------------------------------------------------------+
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@youknowone
youknowone marked this pull request as ready for review October 23, 2026 08:59
@youknowone
youknowone merged commit afe5d90 into RustPython:main Oct 23, 2026
30 checks passed
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T09:11:38.712437Z 0624705 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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.

2 participants