typing TypeAlias#5945
Conversation
WalkthroughThe changes refactor the compilation and execution of PEP 695 type alias and type parameter constructs. Direct bytecode instructions for these constructs are removed and replaced by intrinsic function calls. The stack manipulation and argument passing are updated accordingly. Additionally, new Python properties and a Changes
Sequence Diagram(s)sequenceDiagram
participant Compiler
participant VM
participant Typing
Compiler->>VM: Emit CallIntrinsic1(TypeAlias, [name, type_params, value])
VM->>Typing: TypeAliasType::new(name, type_params, value)
Typing-->>VM: TypeAliasType instance
VM-->>Compiler: Push TypeAliasType to stack
sequenceDiagram
participant Compiler
participant VM
participant Typing
Compiler->>VM: Emit CallIntrinsic1(TypeVar/ParamSpec/TypeVarTuple, args)
VM->>Typing: Create TypeVar/ParamSpec/TypeVarTuple
Typing-->>VM: Typing object
VM-->>Compiler: Push typing object to stack
Possibly related PRs
Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
Sorry, something went wrong.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
vm/src/frame.rs (1)
2235-2240: Improve error message to specify expected arguments.The error message could be more descriptive about what the 3 arguments should be.
if tuple.len() != 3 { return Err(vm.new_type_error(format!( - "TypeAlias expects exactly 3 arguments, got {}", + "TypeAlias expects exactly 3 arguments (name, type_params, value), got {}", tuple.len() ))); }
📜 Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
Lib/test/test_typing.pyis excluded by!Lib/**
📒 Files selected for processing (4)
compiler/codegen/src/compile.rs(4 hunks)compiler/core/src/bytecode.rs(3 hunks)vm/src/frame.rs(2 hunks)vm/src/stdlib/typing.rs(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.rs`: Follow the default rustfmt code style (`cargo fmt` to format) Always ...
**/*.rs: Follow the default rustfmt code style (cargo fmtto format)
Always run clippy to lint code (cargo clippy) before completing tasks. Fix any warnings or lints that are introduced by your changes
Follow Rust best practices for error handling and memory management
Use the macro system (pyclass,pymodule,pyfunction, etc.) when implementing Python functionality in Rust
📄 Source: CodeRabbit Inference Engine (.github/copilot-instructions.md)
List of files the instruction was applied to:
vm/src/stdlib/typing.rsvm/src/frame.rscompiler/core/src/bytecode.rscompiler/codegen/src/compile.rs
🧬 Code Graph Analysis (1)
vm/src/frame.rs (3)
vm/src/stdlib/typing.rs (1)
new(109-115)vm/src/protocol/sequence.rs (1)
tuple(279-289)vm/src/builtins/genericalias.rs (1)
type_params(626-626)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: Run snippets and cpython tests (ubuntu-latest)
- GitHub Check: Run snippets and cpython tests on wasm-wasi
- GitHub Check: Run snippets and cpython tests (macos-latest)
- GitHub Check: Run tests under miri
- GitHub Check: Check the WASM package and demo
- GitHub Check: Run rust tests (windows-latest)
- GitHub Check: Ensure compilation on various targets
- GitHub Check: Run rust tests (ubuntu-latest)
- GitHub Check: Check Rust code with rustfmt and clippy
- GitHub Check: Run snippets and cpython tests (windows-latest)
- GitHub Check: Run rust tests (macos-latest)
🔇 Additional comments (11)
vm/src/stdlib/typing.rs (3)
117-120: LGTM!The property getter correctly exposes the name field to Python.
122-125: LGTM!The property getter correctly exposes the value field to Python.
127-130: LGTM!The property getter correctly exposes the type_params tuple to Python.
compiler/core/src/bytecode.rs (3)
385-392: LGTM!The intrinsic functions for type parameter handling are properly defined with sequential discriminant values.
401-403: LGTM!The intrinsic functions for bounded and constrained type variables are properly defined.
660-660: Confirmed LAST_INSTRUCTION updateExtendedArg is the final variant in the
Instructionenum, so setting
const LAST_INSTRUCTION: Instruction = Instruction::ExtendedArg;
is correct. Approving the change.
- Location: compiler/core/src/bytecode.rs (lines 655–660)
compiler/codegen/src/compile.rs (3)
1070-1104: Well-structured refactoring to use intrinsic functions.The changes correctly refactor the TypeAlias compilation to use intrinsic function calls instead of direct bytecode instructions. The addition of stack state comments improves code clarity and maintainability.
1257-1272: Consistent refactoring of TypeVar compilation.The TypeVar and TypeVarWithBound compilation correctly uses the new intrinsic function pattern, maintaining the same functionality while aligning with the architectural shift.
1295-1327: Uniform refactoring of remaining type parameter constructs.ParamSpec and TypeVarTuple compilation follows the same intrinsic function pattern, completing the consistent refactoring of all PEP 695 type parameter constructs.
vm/src/frame.rs (2)
2210-2228: LGTM! Clean implementation of typing intrinsics.The TypeVar, ParamSpec, and TypeVarTuple intrinsic functions are implemented correctly, following the expected pattern for creating these typing constructs.
2277-2290: LGTM! TypeVar variants implemented correctly.The TypeVarWithBound and TypeVarWithConstraint intrinsic functions properly handle the two-argument variants of TypeVar creation.
Sorry, something went wrong.
0ae6b45
into
RustPython:main
Jul 11, 2025
Summary by CodeRabbit
New Features
__name__,__value__, and__type_params__.__repr__) for type aliases.Refactor