Skip to content

Align _opcode.has_* functions with 3.14.4#7711

Merged
youknowone merged 3 commits into
RustPython:mainfrom
ShaharNaveh:align-dis
Apr 28, 2026
Merged

Align _opcode.has_* functions with 3.14.4#7711
youknowone merged 3 commits into
RustPython:mainfrom
ShaharNaveh:align-dis

Conversation

@ShaharNaveh
Copy link
Copy Markdown
Contributor

@ShaharNaveh ShaharNaveh commented Apr 28, 2026

Summary by CodeRabbit

  • Refactor
    • Enhanced bytecode instruction classification for improved recognition of Python variable operations, control flow branches, and exception handling.

@ShaharNaveh ShaharNaveh changed the title Align _opcode.has_* functions with CPython Align _opcode.has_* functions with 3.14.4 Apr 28, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 28, 2026

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • Lib/test/test_peepholer.py is excluded by !Lib/**

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: eebc4297-bff3-46d8-8613-42dda0773e87

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR updates CPython-compatibility opcode classification helpers in RustPython's stdlib module by expanding detection criteria for jump, free-variable, local-variable, and exception-handling opcodes to recognize additional variants, pseudo-opcodes, and instrumented versions.

Changes

Cohort / File(s) Summary
Opcode Classification Helpers
crates/stdlib/src/_opcode.rs
Updated has_name, has_jump, has_free, has_local, and has_exc helper functions to recognize additional opcodes: expanded jump detection to cover async-end loops and multiple forward/backward variants; broadened free-variable detection from LoadDeref to MakeCell; extended local-variable detection with LoadFast*, StoreFast*, LoadDeref, and closure-related pseudo opcodes; changed has_exc from constant false to conditional logic for setup pseudo opcodes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • RustPython/RustPython#7682: Complements opcode handling by replacing hardcoded descriptor lists with dynamic enum iteration while this PR updates the classification helper functions.

Suggested reviewers

  • youknowone

Poem

🐰 A rabbit hops through opcodes bright,
Sorting jumps and locals with delight,
Free variables dance, exceptions gleam,
Each helper function now supreme! ✨
CPython compatibility's in our sight!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly and specifically describes the main change: aligning the _opcode.has_* functions with CPython 3.14.4, which directly corresponds to the detailed modifications made to these functions in the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 28, 2026

📦 Library Dependencies

The following Lib/ modules were modified. Here are their dependencies:

(module 'dis test_peepholer' not found)

Legend:

  • [+] path exists in CPython
  • [x] up-to-date, [ ] outdated

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
crates/stdlib/src/_opcode.rs (1)

163-172: ⚠️ Potential issue | 🔴 Critical

Move LoadDeref to has_free to align with CPython 3.13.

The current placement of LoadDeref in has_local contradicts CPython 3.13+, where LOAD_DEREF is classified in dis.hasfree. Per CPython behavior, LOAD_DEREF accesses free variables (closure variables) and must be included in has_free(). While LoadFromDictOrDeref (a RustPython-specific optimization) correctly belongs in has_free, LoadDeref should also be classified there, not in has_local.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/stdlib/src/_opcode.rs` around lines 163 - 172, The opcode
classification is wrong: remove Opcode::LoadDeref from the has_local match and
add it to the has_free match so LOAD_DEREF is treated as a "free" access like
CPython 3.13; specifically, update the matches!() in has_free (the
AnyOpcode::Real(Opcode::... ) list) to include Opcode::LoadDeref (alongside
LoadFromDictOrDeref, DeleteDeref, MakeCell, StoreDeref) and delete
Opcode::LoadDeref from the has_local match to keep the two functions consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@crates/stdlib/src/_opcode.rs`:
- Around line 163-172: The opcode classification is wrong: remove
Opcode::LoadDeref from the has_local match and add it to the has_free match so
LOAD_DEREF is treated as a "free" access like CPython 3.13; specifically, update
the matches!() in has_free (the AnyOpcode::Real(Opcode::... ) list) to include
Opcode::LoadDeref (alongside LoadFromDictOrDeref, DeleteDeref, MakeCell,
StoreDeref) and delete Opcode::LoadDeref from the has_local match to keep the
two functions consistent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: ddcd032a-8c81-40b7-a0fe-c9d48ae834c8

📥 Commits

Reviewing files that changed from the base of the PR and between 1d42ee5 and d3279f0.

⛔ Files ignored due to path filters (1)
  • Lib/test/test_dis.py is excluded by !Lib/**
📒 Files selected for processing (1)
  • crates/stdlib/src/_opcode.rs

Copy link
Copy Markdown
Member

@youknowone youknowone left a comment

Choose a reason for hiding this comment

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

👍 good catch!

@youknowone youknowone enabled auto-merge (squash) April 28, 2026 12:13
@youknowone youknowone merged commit 3f718f9 into RustPython:main Apr 28, 2026
21 checks passed
ShaharNaveh added a commit to ShaharNaveh/RustPython that referenced this pull request Apr 28, 2026
ShaharNaveh added a commit to ShaharNaveh/RustPython that referenced this pull request Apr 28, 2026
ShaharNaveh added a commit to ShaharNaveh/RustPython that referenced this pull request Apr 29, 2026
ShaharNaveh added a commit to ShaharNaveh/RustPython that referenced this pull request Apr 30, 2026
ShaharNaveh added a commit to ShaharNaveh/RustPython that referenced this pull request May 1, 2026
youknowone pushed a commit that referenced this pull request May 5, 2026
* Remove unused rust impl for formatting dis output

* remove `examples/dis.rs`

* Added tests

* Update lock

* Try to set snapshot dir

* Remove verbose flag

* Regenerate snapshots after #7711

* Revert "Bump insta from 1.46.3 to 1.47.2 (#7706)"

This reverts commit e6d9ea6.

* Debug info

* Show diff as well

* Show debug faster

* CI: true env

* Recert CI

* Add `CI: true` in ci emv

* Reapply "Bump insta from 1.46.3 to 1.47.2 (#7706)"

This reverts commit 693ca8c.

* simplify macro

* trim on function side

* Force insta workspace root

* fix merge
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.

2 participants