-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Instruction::Resume #5944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Instruction::Resume #5944
Conversation
WalkthroughThe changes introduce a new Changes
Sequence Diagram(s)sequenceDiagram
participant Compiler
participant Bytecode
participant VM
Compiler->>Bytecode: Emit function body
Compiler->>Bytecode: Emit Resume(AtFuncStart)
Compiler->>Bytecode: Emit YieldValue/YieldFrom/Await
Compiler->>Bytecode: Emit Resume(AfterYield/AfterYieldFrom/AfterAwait)
VM->>Bytecode: Fetch Instruction
alt Instruction is Resume
VM->>VM: (Currently no-op, signal check commented out)
end
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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (2)
compiler/core/src/bytecode.rs (2)
27-35
: Consider implementing OpArgType for ResumeType for better type safety.The ResumeType enum is well-defined with appropriate variants and representation. However, to improve type safety and consistency with other instruction-specific enums, consider implementing OpArgType for ResumeType.
+impl OpArgType for ResumeType { + fn from_op_arg(x: u32) -> Option<Self> { + match x { + 0 => Some(Self::AtFuncStart), + 1 => Some(Self::AfterYield), + 2 => Some(Self::AfterYieldFrom), + 3 => Some(Self::AfterAwait), + _ => None, + } + } + fn to_op_arg(self) -> u32 { + self as u32 + } +}
577-581
: Consider using Arg instead of Arg for better type safety.The Resume instruction is well-implemented, but using
Arg<u32>
instead ofArg<ResumeType>
reduces type safety and consistency with other instruction designs. This would require implementing OpArgType for ResumeType (see previous comment).Resume { - arg: Arg<u32>, + arg: Arg<ResumeType>, },
📜 Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
compiler/codegen/src/compile.rs
(10 hunks)compiler/core/src/bytecode.rs
(4 hunks)vm/src/frame.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 fmt
to 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/frame.rs
compiler/core/src/bytecode.rs
compiler/codegen/src/compile.rs
🧠 Learnings (1)
compiler/core/src/bytecode.rs (1)
Learnt from: CR
PR: RustPython/RustPython#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-06-30T10:08:48.858Z
Learning: Applies to **/*.rs : Follow Rust best practices for error handling and memory management
⏰ 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 rust tests (macos-latest)
- GitHub Check: Run snippets and cpython tests on wasm-wasi
- GitHub Check: Run snippets and cpython tests (macos-latest)
- GitHub Check: Run snippets and cpython tests (windows-latest)
- GitHub Check: Run snippets and cpython tests (ubuntu-latest)
- GitHub Check: Check the WASM package and demo
- GitHub Check: Run tests under miri
- GitHub Check: Check Rust code with rustfmt and clippy
- GitHub Check: Run rust tests (ubuntu-latest)
- GitHub Check: Ensure compilation on various targets
- GitHub Check: Run rust tests (windows-latest)
🔇 Additional comments (10)
compiler/core/src/bytecode.rs (2)
1344-1344
: LGTM - Correct stack effect for Resume instruction.The stack effect of 0 is appropriate for the Resume instruction as it's a no-op operation that doesn't modify the stack.
1539-1539
: LGTM - Consistent formatting implementation.The fmt_dis implementation for Resume follows the standard pattern and is consistent with other instructions.
compiler/codegen/src/compile.rs (8)
1531-1537
: Correct placement of Resume instruction at function start.The Resume instruction is properly emitted at the function entry point after the None constant insertion.
3522-3527
: Proper Resume instruction after yield expressions.The Resume instruction with
AfterYield
type is correctly placed after the YieldValue instruction.
3537-3542
: Correct Resume instruction after await expressions.The Resume instruction with
AfterAwait
type is properly emitted after the YieldFrom instruction in await expressions.
3559-3564
: Appropriate Resume instruction for yield from expressions.The Resume instruction correctly uses
AfterYieldFrom
type to distinguish yield from operations from await operations, even though both use the YieldFrom instruction.
1954-1959
: Consistent Resume instructions in async with statements.Both the async with enter and cleanup sections correctly emit Resume instructions with
AfterAwait
type after their respective YieldFrom operations.Also applies to: 2001-2006
2045-2050
: Proper Resume instruction in async for loops.The Resume instruction with
AfterAwait
type is correctly emitted after the YieldFrom operation in async iteration.
1691-1696
: Correct Resume instruction in generator expressions.The Resume instruction with
AfterYield
type is properly placed after the YieldValue instruction in generator expressions.
4092-4097
: Consistent Resume instructions in async comprehensions.Resume instructions with
AfterAwait
type are correctly emitted after YieldFrom operations in both async generator comprehensions and async list/set/dict comprehensions.Also applies to: 4176-4181
vm/src/frame.rs
Outdated
bytecode::Instruction::Resume { arg: resume_arg } => { | ||
// Resume execution after yield, await, or at function start | ||
// In CPython, this checks instrumentation and eval breaker | ||
// For now, we just check for signals/interrupts | ||
let _resume_type = resume_arg.get(arg); | ||
|
||
// Temporarily disable signal checking to debug the issue | ||
// Check for interrupts if not resuming from yield_from | ||
// if resume_type < bytecode::ResumeType::AfterYieldFrom as u32 { | ||
// vm.check_signals()?; | ||
// } | ||
Ok(None) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Complete the Resume instruction implementation or document the temporary nature.
The current implementation is essentially a no-op with critical signal checking logic commented out. This could lead to missing important interrupt handling during resume operations.
Issues identified:
- Unused variable:
_resume_type
is extracted but never used - Commented-out logic: The signal checking is disabled "to debug the issue"
- Incomplete functionality: The instruction doesn't perform its intended purpose
Consider these approaches:
Option 1: Implement proper signal checking
bytecode::Instruction::Resume { arg: resume_arg } => {
// Resume execution after yield, await, or at function start
- // In CPython, this checks instrumentation and eval breaker
- // For now, we just check for signals/interrupts
- let _resume_type = resume_arg.get(arg);
+ let resume_type = resume_arg.get(arg);
- // Temporarily disable signal checking to debug the issue
- // Check for interrupts if not resuming from yield_from
- // if resume_type < bytecode::ResumeType::AfterYieldFrom as u32 {
- // vm.check_signals()?;
- // }
+ // Check for interrupts if not resuming from yield_from
+ if resume_type < bytecode::ResumeType::AfterYieldFrom as u32 {
+ vm.check_signals()?;
+ }
Ok(None)
}
Option 2: Document the temporary nature
bytecode::Instruction::Resume { arg: resume_arg } => {
+ // TODO: Temporary no-op implementation while debugging signal issues
+ // This instruction should check for interrupts and handle instrumentation
// Resume execution after yield, await, or at function start
- // In CPython, this checks instrumentation and eval breaker
- // For now, we just check for signals/interrupts
let _resume_type = resume_arg.get(arg);
- // Temporarily disable signal checking to debug the issue
// Check for interrupts if not resuming from yield_from
// if resume_type < bytecode::ResumeType::AfterYieldFrom as u32 {
// vm.check_signals()?;
// }
Ok(None)
}
What specific issue is being debugged that requires disabling signal checking? This context would help determine the appropriate approach.
🏁 Script executed:
#!/bin/bash
# Search for ResumeType definition and usages
rg "ResumeType" -n .
# Search for check_signals method to see its typical usage
rg "fn check_signals" -n .
# Search for other occurrences of vm.check_signals to understand context
rg "check_signals" -n vm
Length of output: 2053
Implement signal checking in the Resume handler or document its temporary no-op
The new Instruction::Resume
arm in vm/src/frame.rs
currently ignores its resume_type
and has all interrupt checks commented out. This placeholder will silently skip important vm.check_signals()
calls and leave an unused variable.
Issues to address:
_resume_type
is never used.- Critical
vm.check_signals()?
logic is disabled. - No indication of why signal checking is temporarily removed or when it’ll be restored.
Please update one of the following:
• Option A – Restore proper signal checks:
vm/src/frame.rs
@@ -896,13 +896,15 @@ impl Frame {
bytecode::Instruction::Resume { arg: resume_arg } => {
- let _resume_type = resume_arg.get(arg);
+ let resume_type = resume_arg.get(arg);
- // Temporarily disable signal checking to debug the issue
- // Check for interrupts if not resuming from yield_from
- // if resume_type < bytecode::ResumeType::AfterYieldFrom as u32 {
- // vm.check_signals()?;
- // }
+ // Check for interrupts unless we’re resuming from a yield_from
+ if resume_type < bytecode::ResumeType::AfterYieldFrom as u32 {
+ vm.check_signals()?;
+ }
Ok(None)
}
• Option B – Clearly mark as temporary:
vm/src/frame.rs
@@ -896,6 +896,10 @@ impl Frame {
bytecode::Instruction::Resume { arg: resume_arg } => {
+ // TODO: temporary no-op while debugging signal issues.
+ // This handler must later:
+ // 1) perform instrumentation/eval breaker checks
+ // 2) re-enable vm.check_signals()
let _resume_type = resume_arg.get(arg);
Ok(None)
}
Also, please clarify “what specific issue is being debugged” that required disabling check_signals()
, and when you plan to restore full behavior.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
bytecode::Instruction::Resume { arg: resume_arg } => { | |
// Resume execution after yield, await, or at function start | |
// In CPython, this checks instrumentation and eval breaker | |
// For now, we just check for signals/interrupts | |
let _resume_type = resume_arg.get(arg); | |
// Temporarily disable signal checking to debug the issue | |
// Check for interrupts if not resuming from yield_from | |
// if resume_type < bytecode::ResumeType::AfterYieldFrom as u32 { | |
// vm.check_signals()?; | |
// } | |
Ok(None) | |
} | |
bytecode::Instruction::Resume { arg: resume_arg } => { | |
// Resume execution after yield, await, or at function start | |
// In CPython, this checks instrumentation and eval breaker | |
// For now, we just check for signals/interrupts | |
let resume_type = resume_arg.get(arg); | |
// Check for interrupts unless we’re resuming from a yield_from | |
if resume_type < bytecode::ResumeType::AfterYieldFrom as u32 { | |
vm.check_signals()?; | |
} | |
Ok(None) | |
} |
🤖 Prompt for AI Agents
In vm/src/frame.rs around lines 896 to 908, the Resume instruction handler
currently disables signal checking and leaves the resume_type variable unused,
which can cause missed interrupt handling and unclear code intent. To fix this,
either restore the vm.check_signals()? call with the appropriate condition on
resume_type to ensure signals are checked as intended, or if signal checking is
temporarily disabled for debugging, add a clear comment explaining the specific
issue being debugged, why check_signals() is disabled, and when full signal
checking will be restored. Also, remove the unused _resume_type variable if not
used or rename it to _ to avoid warnings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
jit/src/instructions.rs (1)
615-618
: Placeholder implementation is appropriate for current development phase.The TODO comment clearly indicates the pending work for implementing the Resume instruction. This placeholder approach allows the JIT compiler to recognize the instruction while core functionality is developed elsewhere first.
Would you like me to help implement the Resume instruction functionality for the JIT compiler? I can generate a solution that handles the different resume types (
AtFuncStart
,AfterYield
,AfterYieldFrom
,AfterAwait
) mentioned in the broader codebase changes.
📜 Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
compiler/codegen/src/snapshots/rustpython_codegen__compile__tests__nested_double_async_with.snap
is excluded by!**/*.snap
📒 Files selected for processing (4)
compiler/codegen/src/compile.rs
(11 hunks)compiler/core/src/bytecode.rs
(5 hunks)jit/src/instructions.rs
(1 hunks)vm/src/frame.rs
(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
- vm/src/frame.rs
- compiler/core/src/bytecode.rs
- compiler/codegen/src/compile.rs
🧰 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 fmt
to 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:
jit/src/instructions.rs
⏰ 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: Check Rust code with rustfmt and clippy
- GitHub Check: Run snippets and cpython tests on wasm-wasi
- GitHub Check: Run snippets and cpython tests (macos-latest)
- GitHub Check: Run rust tests (ubuntu-latest)
- GitHub Check: Run snippets and cpython tests (windows-latest)
- GitHub Check: Run tests under miri
- GitHub Check: Check the WASM package and demo
- GitHub Check: Ensure compilation on various targets
- GitHub Check: Run rust tests (windows-latest)
- GitHub Check: Run rust tests (macos-latest)
Summary by CodeRabbit
New Features
Bug Fixes
Chores