◐ Shell
reader mode source ↗
Skip to content

Instruction::Resume#5944

Merged
youknowone merged 2 commits into
RustPython:mainfrom
youknowone:resume
Jul 11, 2025
Merged

Instruction::Resume#5944
youknowone merged 2 commits into
RustPython:mainfrom
youknowone:resume

Conversation

@youknowone

@youknowone youknowone commented Jul 11, 2025

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Introduced explicit resume points in bytecode execution, marking function start and positions after yield, yield from, and await expressions.
    • Added a new instruction to represent these resume points, enhancing bytecode clarity.
    • Replaced star import handling with an intrinsic function call for improved import behavior.
  • Bug Fixes

    • No user-facing bugs addressed.
  • Chores

    • Updated internal handling for new resume instructions, with signal checking logic prepared but currently disabled.

@coderabbitai

coderabbitai Bot commented Jul 11, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes introduce a new Resume instruction and associated ResumeType enum to the bytecode system. The compiler now emits Resume instructions at function starts and after yield/await points. The VM is updated to recognize and handle the Resume instruction, though its logic is currently a no-op with signal checking commented out. Additionally, the ImportStar instruction is replaced by an intrinsic call.

Changes

File(s) Change Summary
compiler/codegen/src/compile.rs Replaces ImportStar with intrinsic call; emits Resume instructions at function start, after YieldValue, YieldFrom, and await-related instructions.
compiler/core/src/bytecode.rs Adds ResumeType enum and Instruction::Resume variant; removes ImportStar variant; updates formatting and stack effect logic accordingly; adds IntrinsicFunction1::ImportStar.
vm/src/frame.rs Removes ImportStar instruction handling; adds intrinsic function handling for ImportStar; adds handling for Instruction::Resume (currently no-op, signal check commented out).
jit/src/instructions.rs Adds placeholder match arm for Instruction::Resume in JIT instruction addition, currently no-op.

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
Loading

Poem

In bytecode fields where rabbits leap,
New Resume points are sown so deep.
At function start, or after yield,
Each pause and hop is now revealed.
The VM sniffs, but takes no fright—
Awaiting signals, not tonight!
🐇✨

✨ 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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hide comment

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 of Arg<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

📥 Commits

Reviewing files that changed from the base of the PR and between 8b6c78c and 1469300.

📒 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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hide comment

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

📥 Commits

Reviewing files that changed from the base of the PR and between 92e8735 and 0b22971.

⛔ 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)

Hide details View details @youknowone youknowone merged commit 392f9c2 into RustPython:main Jul 11, 2025
12 checks passed
@youknowone youknowone deleted the resume branch July 11, 2025 08:25
@coderabbitai coderabbitai Bot mentioned this pull request Mar 27, 2026
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