GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Remove `ImportNameless` bytecode by ShaharNaveh · Pull Request #6325 · RustPython/RustPython

Conversation

@ShaharNaveh

@ShaharNaveh ShaharNaveh commented Dec 2, 2025 •
edited by coderabbitai Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

This is CPython does it:
https://github.com/python/cpython/blob/8183fa5e3f78ca6ab862de7fb8b14f3d929421e0/Python/compile.c#L3960-L3961

Summary by CodeRabbit

Release Notes

  • Refactor
    • Simplified import handling by consolidating the import instruction implementation. Import operations now use a unified approach across all scenarios, reducing code complexity and maintenance overhead.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ShaharNaveh
Remove ImportNameless bytecode
a8a489e
@coderabbitai

coderabbitai Bot commented Dec 2, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Walkthrough

The changes remove the ImportNameless instruction variant from the import handling pipeline. The codegen module now unconditionally emits ImportName with an empty string for the module name when no module is present, eliminating the previous conditional branching between ImportName and ImportNameless.

Changes

Cohort / File(s) Summary
Import Instruction Removal
crates/compiler-core/src/bytecode.rs
Removed ImportNameless enum variant from Instruction and deleted related branches in stack_effect and fmt_dis functions.
Codegen Compilation Update
crates/codegen/src/compile.rs
Replaced conditional emission of ImportName or ImportNameless with uniform ImportName emission; uses empty string as module name when module is absent.
VM Execution Path Removal
crates/vm/src/frame.rs
Removed ImportNameless instruction branch from ExecutingFrame::execute_instruction.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Verify that empty string module names in the codegen change are correctly handled throughout the runtime execution
  • Confirm all references to ImportNameless have been removed across the codebase
  • Validate that the uniform ImportName approach with empty module strings doesn't introduce edge case regressions

Possibly related PRs

  • Sort Instruction enum & related match arms #6322 — Directly related changes to Instruction enum and import opcode handling; modifies the same ImportNameless/ImportName code paths.

Suggested reviewers

  • youknowone

Poem

🐰 A nameless import hops away,
One path remains, no more the fray,
Empty strings now do the trick,
Clean and simple, very slick!
The code flows smooth, no branches tangled,
Import logic, nicely wrangled. ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Remove ImportNameless bytecode' directly and specifically summarizes the main change: removing the ImportNameless bytecode variant and its associated handling across three files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d287d1e and a8a489e.

📒 Files selected for processing (3)
  • crates/codegen/src/compile.rs (1 hunks)
  • crates/compiler-core/src/bytecode.rs (1 hunks)
  • crates/vm/src/frame.rs (0 hunks)
💤 Files with no reviewable changes (1)
  • crates/vm/src/frame.rs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.rs: Follow the default rustfmt code style by running cargo fmt to format Rust code
Always run clippy to lint Rust code (cargo clippy) before completing tasks and fix any warnings or lints introduced by 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

Files:

  • crates/compiler-core/src/bytecode.rs
  • crates/codegen/src/compile.rs
🧬 Code graph analysis (1)
crates/codegen/src/compile.rs (3)
crates/derive-impl/src/pymodule.rs (1)
  • module_name (437-439)
crates/derive-impl/src/util.rs (1)
  • module (428-457)
crates/codegen/src/ir.rs (1)
  • idx (35-37)
⏰ 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 (windows-latest)
  • GitHub Check: Check the WASM package and demo
  • GitHub Check: Run snippets and cpython tests (macos-latest)
  • GitHub Check: Run snippets and cpython tests on wasm-wasi
  • GitHub Check: Ensure compilation on various targets
  • GitHub Check: Run snippets and cpython tests (ubuntu-latest)
  • GitHub Check: Check Rust code with clippy
  • GitHub Check: Run tests under miri
  • GitHub Check: Run rust tests (windows-latest)
  • GitHub Check: Run rust tests (ubuntu-latest)
  • GitHub Check: Run rust tests (macos-latest)
🔇 Additional comments (2)
crates/codegen/src/compile.rs (1)

1354-1365: Unified ImportName handling for nameless from imports looks correct

Using module.as_ref().map_or("", |s| s.as_str()) and always emitting ImportName keeps the stack contract identical to CPython: level and from_list are consumed and the module object is pushed, with nameless from-imports represented by an empty-string entry in co_names. This removes the need for a separate ImportNameless opcode while preserving observable behavior, assuming the VM’s ImportName now treats "" the same way the old nameless variant did.

Please double‑check that the updated ImportName execution path in crates/vm/src/frame.rs explicitly handles the empty‑string name in the same way the removed ImportNameless variant did, and that there are tests (or disassembly snapshots) covering from . import x / from ... import x cases.

crates/compiler-core/src/bytecode.rs (1)

1604-1611: ImportName stack effect -1 matches its two-arg import usage

Defining ImportName { .. } => -1 is consistent with the compiler pushing level and from_list before the opcode and expecting a single module object afterward (net 2 pops, 1 push). Combined with ImportFrom { .. } => 1, this keeps the import stack discipline coherent after removing ImportNameless.

If you have a stack‑effect test or disassembly snapshot suite for import opcodes, it’s worth re‑running/expanding it to confirm the computed effects for import x and from ... import y still match CPython’s behavior.


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
  • X
  • Mastodon
  • Reddit
  • LinkedIn

Comment @coderabbitai help to get the list of available commands and usage tips.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

youknowone
youknowone approved these changes Dec 2, 2025
View reviewed changes
@youknowone
youknowone merged commit 305fb48 into RustPython:main Dec 2, 2025
13 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@coderabbitai coderabbitai Bot mentioned this pull request Dec 3, 2025
Move PrintExpr to IntristicFunction1 #6324
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@youknowone youknowone youknowone approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@ShaharNaveh @youknowone
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.