Skip to content

Conversation

@youknowone
Copy link
Member

@youknowone youknowone commented Jan 18, 2026

Summary by CodeRabbit

  • Refactor
    • Internal optimizations to function call handling and bytecode processing for improved code efficiency and simplified control flow.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 18, 2026

📝 Walkthrough

Walkthrough

The PR simplifies keyword argument handling in function calls by removing a per-call has_kwargs flag from the CallFunctionEx bytecode instruction. Instead, the system now relies on stack state: when kwargs are absent, a Null value is pushed onto the stack, enabling uniform CallFunctionEx invocation logic across compiler and VM execution layers.

Changes

Cohort / File(s) Summary
CallFunctionEx Instruction Simplification
crates/compiler-core/src/bytecode/instruction.rs
Changed CallFunctionEx enum variant from struct-like with has_kwargs: Arg<bool> field to unit-like variant CallFunctionEx = 54. Updated stack-effect computation to use fixed value instead of variable logic. Simplified display/formatting code.
Compiler Codegen Updates
crates/codegen/src/compile.rs
Replaced conditional has_kwargs presence checks with direct branching: compiles kwargs via compile_keywords(...) when present, or pushes Null when absent. Removed has_kwargs parameter passing to CallFunctionEx emission calls.
VM Frame Execution Updates
crates/vm/src/frame.rs
Updated CallFunctionEx instruction dispatch to remove has_kwargs deconstruction. Changed collect_ex_args signature from flag-driven to stack-driven via pop_value_opt. Added iterate_mapping_keys helper to preserve key order when extracting kwargs from mapping objects.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Sort Instruction enum & related match arms #6322: Both PRs modify the Instruction::CallFunctionEx shape and its handling throughout the codebase, with this PR removing the per-call has_kwargs field entirely.
  • Replace CallMethod/LoadMethod opcodes with plain Call #6674: Both PRs modify CallFunctionEx opcode and call-handling paths; the referenced PR introduced centralized CallFunctionEx with has_kwargs, while this PR removes the flag and converts to stack-driven kwargs via PushNull.
  • Pseudo ops #6678: Both PRs touch the CallFunctionEx and kwargs codepath, modifying how keyword arguments are represented and handled across compiler and VM layers.

Suggested reviewers

  • ShaharNaveh

Poem

🐰 No more flags upon the stack, just Nulls to light the way,
Where kwargs once were whispered true, now silence wins the day,
The CallFunctionEx hops along, so simple and so clean,
From flag-driven dreams to stack-based streams—the best refactor seen! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Align CallFunctionEx to 3.14' directly corresponds to the main refactoring described in all three modified files: removing the per-call has_kwargs flag from CallFunctionEx and aligning its behavior.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

@youknowone youknowone marked this pull request as ready for review January 18, 2026 15:16
@youknowone youknowone merged commit 0717b53 into RustPython:main Jan 18, 2026
13 checks passed
@youknowone youknowone deleted the CallFunctionEx branch January 18, 2026 15:37
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.

1 participant