Prohibit AI PR submit by youknowone · Pull Request #6813 · RustPython/RustPython
📝 Walkthrough
Walkthrough
This PR introduces three new bytecode instructions (DictMerge, ListExtend, SetUpdate) with corresponding VM frame handlers and compiler codegen support. Additionally, it adds stdlib directory path tracking throughout the VM's runtime configuration and sys module, refactors collection construction in the code generator to optimize starred/unstarred elements via threshold-based branching, and improves Windows path resolution robustness.
Changes
| Cohort / File(s) | Summary |
|---|---|
Configuration & Metadata .cspell.dict/cpython.txt, .gitattributes, crates/vm/src/vm/setting.rs |
Added three spell-check dictionary entries (kwnames, nkwelts, subkwargs), configured test resource attributes in git for importlib and email test data with binary/CRLF settings, and added new stdlib_dir: Option<String> field to Paths struct. |
Compiler Codegen crates/codegen/src/compile.rs |
Reworked collection construction with threshold-based branching to choose between fast single-build path (no stars, small collections) and streaming path (stars or large sizes). Introduced new codegen_subkwargs helper for efficient keyword argument emission, and updated call/class building to support the new strategies with improved MapAdd handling. |
Bytecode Instruction Definitions crates/compiler-core/src/bytecode/instruction.rs |
Updated stack effects for three instructions: DictMerge, ListExtend, and SetUpdate now have stack effect -1 (previously 0), reflecting the operations' consumption of values during execution. |
VM Frame Execution crates/vm/src/frame.rs |
Added three new instruction handlers (DictMerge, ListExtend, SetUpdate) with validation and type checking; DictMerge enforces string keys and detects duplicates, while ListExtend and SetUpdate safely downcast and extend/update collections. Extended BuildList with intermediate size variable and renamed indexing variables (i → idx) in LoadDeref and LoadFromDictOrDeref. |
Path Configuration & Initialization crates/vm/src/getpath.rs, crates/vm/src/stdlib/sys.rs, src/interpreter.rs |
Added new calculate_stdlib_dir function to compute platform-specific stdlib paths, exposed _stdlib_dir attribute in sys module, and refactored interpreter setup to move stdlib_dir configuration from sys module hacks to centralized state-based initialization for both frozen and dynamic stdlib scenarios. |
Windows Build Path Handling crates/pylib/build.rs |
Rewrote Windows Lib path resolution to handle two cases: text files containing relative paths and symlinks/directories, with proper canonicalization and extended-length prefix stripping for robustness in Git-enabled environments. |
Sequence Diagram(s)
sequenceDiagram
participant Compiler as Compiler<br/>(codegen)
participant Codegen as Codegen Helper<br/>(codegen_subkwargs)
participant Bytecode as Bytecode<br/>(DictMerge instr)
participant VM as VM Frame<br/>(Execution)
participant Dict as Target Dict
Compiler->>Codegen: compile dict merge<br/>with **kwargs
Codegen->>Codegen: choose fast or<br/>streaming path
alt Streaming Path (stars present)
Codegen->>Codegen: emit MapAdd ops
else Fast Path (no stars)
Codegen->>Codegen: build single map
end
Codegen->>Bytecode: emit DictMerge<br/>{index}
Bytecode->>Bytecode: stack effect: -1
VM->>VM: execute DictMerge
VM->>VM: validate source<br/>is mapping
VM->>Dict: iterate keys & merge<br/>with validation
VM-->>VM: return Ok(None)<br/>on success
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~50 minutes
Possibly related PRs
- Replace custom opcodes with CPython standard sequences #6794 — Implements the same codegen changes and VM instruction additions (DictMerge, ListExtend, SetUpdate, and codegen_subkwargs streaming patterns) for collection handling.
- Add sys._stdlib_dir #6798 — Adds and wires sys._stdlib_dir across build.rs, getpath.rs, vm settings, sys.rs, and interpreter state initialization.
- nt junction #6407 — Improves Windows Lib path handling by stripping the extended-length prefix and handling symlinks more robustly.
Suggested reviewers
- ShaharNaveh
Poem
🐰 A hop through bytecode, paths aligned!
DictMerge, ListExtend, SetUpdate designed,
Stdlib paths now tracked with care,
Fast paths chosen, streaming paths fair,
Windows paths robust, no more despair! 🌟
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Title check | The PR title 'Prohibit AI PR submit' is unrelated to the changeset, which contains CI fixes, opcode changes, stdlib_dir configuration, and keyword argument handling optimizations. | Update the title to reflect the actual changes, such as 'Fix CI test failures from PR 6798' or 'Add stdlib_dir support and fix CI test failures'. |
✅ Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Docstring Coverage | ✅ Passed | Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
✏️ 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.
Comment @coderabbitai help to get the list of available commands and usage tips.