◐ Shell
reader mode source ↗
Skip to content

Align psuedo ops to CPython 3.14.2#6846

Merged
youknowone merged 2 commits into
RustPython:mainfrom
youknowone:pseudo-ops
Jan 24, 2026
Merged

Align psuedo ops to CPython 3.14.2#6846
youknowone merged 2 commits into
RustPython:mainfrom
youknowone:pseudo-ops

Conversation

@youknowone

@youknowone youknowone commented Jan 23, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for special method optimization and executor specialization.
  • Refactor

    • Simplified internal attribute access compilation and bytecode emission.
    • Updated opcode support for Python 3.14.2 alignment.
    • Removed redundant instruction variants for streamlined bytecode generation.

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

@coderabbitai

coderabbitai Bot commented Jan 23, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This PR refactors attribute and super attribute load instructions across the compiler stack. It introduces encoded opargs for LoadAttr/LoadSuperAttr operations, consolidates multiple pseudo-instruction variants into single encoded forms, removes public re-exports of encoding helpers, and updates bytecode instruction definitions accordingly.

Changes

Cohort / File(s) Summary
Compiler Codegen Emission
crates/codegen/src/compile.rs
Added 6 new private helper methods (emit_load_attr, emit_load_attr_method, emit_load_super_attr, emit_load_super_method, emit_load_zero_super_attr, emit_load_zero_super_method) that encode opargs and emit LoadAttr/LoadSuperAttr instructions. Replaced all direct instruction emissions with corresponding helper calls throughout the file. Added imports for encode_load_attr_arg and encode_load_super_attr_arg.
IR Instruction Finalization
crates/codegen/src/ir.rs
Removed public re-exports of encode_load_attr_arg and encode_load_super_attr_arg. Simplified CodeInfo::finalize_code to skip per-instruction encoding for already-encoded real instructions. Removed handling of LoadAttrMethod/LoadSuperMethod/LoadZeroSuper\* pseudo-instruction variants.
Bytecode Instruction Definitions
crates/compiler-core/src/bytecode/instruction.rs
Extended label_arg matching to include PopJumpIfNone/PopJumpIfNotNone. Modified LoadAttr stack_info to dynamically compute stack effect using decoded oparg. Removed RustPython-specific pseudo-instruction variants (LoadAttrMethod, LoadSuperMethod, LoadZeroSuperAttr, LoadZeroSuperMethod) from PseudoInstruction enum. Updated enum bounds and InstructionMetadata implementations accordingly.
Opcode Module
crates/stdlib/src/_opcode.rs
Changed HAVE_ARGUMENT constant from 44 to 43. Removed LoadAttrMethod from has_name pattern matching. Added ENABLE_SPECIALIZATION_FT constant and get_special_method_names() function. Extended get_nb_ops list and modified get_executor signature to include _offset: i32 parameter.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • Pseudo ops #6678: Directly related—both PRs introduce encode_load_attr_arg/decode_load_attr_arg helpers and consolidate LoadAttrMethod encoding into LoadAttr with encoded opargs across codegen/IR/bytecode layers.
  • Bytecode pseudo opcodes #6715: Directly related—both modify pseudo-instruction removal (LoadAttrMethod, LoadSuperMethod, LoadZeroSuper\* variants) and introduce encoded oparg handling in compile.rs/ir.rs/instruction.rs.
  • instruction improvements #6829: Directly related—both refactor attribute/super-attribute instruction representation by removing pseudo-instruction variants and switching to encoded LoadAttr/LoadSuper handling across the compilation pipeline.

Suggested reviewers

  • ShaharNaveh

Poem

🐰 Attributes now encode so tight,
No pseudo bloat, just bytes so right,
From compile through IR we weave,
Consolidation that we believe! ✨

🚥 Pre-merge checks | ✅ 3
✅ 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 directly describes the main objective of the PR, which is aligning pseudo operations to CPython 3.14.2 as evidenced by the removal of RustPython-specific pseudo-instruction variants and updates to match CPython standards.
Docstring Coverage ✅ Passed Docstring coverage is 91.67% which is sufficient. The required threshold is 80.00%.

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

✨ 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

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

@github-actions

github-actions Bot commented Jan 23, 2026

Copy link
Copy Markdown
Contributor

Code has been automatically formatted

The code in this PR has been formatted using:

  • ruff format
    Please pull the latest changes before pushing again:
git pull origin pseudo-ops

@youknowone youknowone changed the title Align psuedo ops to CPython Jan 23, 2026
@youknowone youknowone marked this pull request as ready for review January 23, 2026 16:10

@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: 2

🤖 Fix all issues with AI agents
In `@crates/compiler-core/src/bytecode/instruction.rs`:
- Around line 474-483: The Arg<NameIdx> used for the LoadAttr operand currently
holds an encoded value which is confusing and error-prone; introduce a new
OpArgType called EncodedLoadAttrArg and replace uses of Arg<NameIdx> for
LoadAttr so the type signals that decoding is required. Update the emitter sites
(emit_load_attr, emit_load_attr_method) to produce EncodedLoadAttrArg (using
encode_load_attr_arg), update consumers (stack_effect implementation for
LoadAttr, disassembly, and the load_attr runtime) to accept EncodedLoadAttrArg
and call decode_load_attr_arg before extracting the name index, and adjust any
trait impls or type aliases so Arg<EncodedLoadAttrArg> integrates with the
existing OpArgType system.

In `@crates/stdlib/src/_opcode.rs`:
- Around line 154-156: Remove the public exposure of the internal macro by
deleting or disabling the #[pyattr] export for ENABLE_SPECIALIZATION_FT (and any
ENABLE_SPECIALIZATION) so they are not added to the opcode module; keep the
internal constants locally if needed but do not annotate them with #[pyattr] (or
change to private/internal symbol) and ensure only CPython-public attributes
(e.g., cmp_op, stack_effect, hascompare, opname, opmap, HAVE_ARGUMENT,
EXTENDED_ARG, hasarg, hasconst, hasname, hasjump, hasjrel, hasjabs, hasfree,
haslocal, hasexc) remain exported from the module.
🧹 Nitpick comments (1)
crates/compiler-core/src/bytecode/instruction.rs (1)

932-967: Pseudo-op range alignment looks consistent; do a clean build to avoid stale bytecode artifacts.
Based on learnings, please run a clean build and clear any stale .pyc / target/debug/build/rustpython-* artifacts after bytecode instruction changes.

@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

🤖 Fix all issues with AI agents
In `@crates/stdlib/src/_opcode.rs`:
- Around line 320-326: The current get_special_method_names function only
returns the four context-manager names; replace or extend that array to match
CPython's full _Py_SpecialMethods list so callers receive the complete set of
special method names. Locate or create a static Rust slice/const (e.g.,
SPECIAL_METHODS or _PY_SPECIAL_METHODS) containing all CPython special method
strings, then change get_special_method_names to iterate over that slice (using
the existing .into_iter().map(|x| vm.ctx.new_str(x).into()).collect()) to
produce the Vec<PyObjectRef>; ensure the symbol name get_special_method_names
remains unchanged and the returned type stays Vec<PyObjectRef>.

@ShaharNaveh ShaharNaveh 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

LGTM!

@github-actions

Copy link
Copy Markdown
Contributor

📦 Library Dependencies

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

[+] lib: cpython/Lib/_opcode_metadata.py

dependencies:

  • _opcode_metadata

dependent tests: (13 tests)
- [ ] opcode: test__opcode test_code test_dis test_peepholer
- [ ] dis: test_ast test_compile test_compiler_assemble test_dtrace test_fstring test_inspect test_opcache test_patma test_positional_only_arg

Legend:

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

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