-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Align psuedo ops to CPython 3.14.2 #6846
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,8 +34,8 @@ mod _opcode { | |
| } | ||
|
|
||
| impl Opcode { | ||
| // https://github.com/python/cpython/blob/bcee1c322115c581da27600f2ae55e5439c027eb/Include/opcode_ids.h#L238 | ||
| const HAVE_ARGUMENT: i32 = 44; | ||
| // https://github.com/python/cpython/blob/v3.14.2/Include/opcode_ids.h#L252 | ||
| const HAVE_ARGUMENT: i32 = 43; | ||
|
|
||
| pub fn try_from_pyint(raw: PyIntRef, vm: &VirtualMachine) -> PyResult<Self> { | ||
| let instruction = raw | ||
|
|
@@ -92,7 +92,7 @@ mod _opcode { | |
| | Instruction::StoreAttr { .. } | ||
| | Instruction::StoreGlobal(_) | ||
| | Instruction::StoreName(_) | ||
| ) | AnyInstruction::Pseudo(PseudoInstruction::LoadAttrMethod { .. })) | ||
| )) | ||
| ) | ||
| } | ||
|
|
||
|
|
@@ -148,8 +148,11 @@ mod _opcode { | |
| } | ||
| } | ||
|
|
||
| // prepare specialization | ||
| #[pyattr] | ||
| const ENABLE_SPECIALIZATION: i8 = 1; | ||
| #[allow(dead_code)] | ||
| const ENABLE_SPECIALIZATION_FT: i8 = 1; | ||
|
|
||
| #[derive(FromArgs)] | ||
| struct StackEffectArgs { | ||
|
|
@@ -303,6 +306,7 @@ mod _opcode { | |
| ("NB_INPLACE_SUBTRACT", "-="), | ||
| ("NB_INPLACE_TRUE_DIVIDE", "/="), | ||
| ("NB_INPLACE_XOR", "^="), | ||
| ("NB_SUBSCR", "[]"), | ||
| ] | ||
| .into_iter() | ||
| .map(|(a, b)| { | ||
|
|
@@ -314,8 +318,19 @@ mod _opcode { | |
| } | ||
|
|
||
| #[pyfunction] | ||
| fn get_executor(_code: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyObjectRef> { | ||
| // TODO | ||
| fn get_special_method_names(vm: &VirtualMachine) -> Vec<PyObjectRef> { | ||
| ["__enter__", "__exit__", "__aenter__", "__aexit__"] | ||
| .into_iter() | ||
| .map(|x| vm.ctx.new_str(x).into()) | ||
| .collect() | ||
| } | ||
|
Comment on lines
320
to
+326
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: cat -n crates/stdlib/src/_opcode.rs | sed -n '310,330p'Repository: RustPython/RustPython Length of output: 754 🏁 Script executed: cd crates/stdlib && cargo clippy --all-targets 2>&1 | head -100Repository: RustPython/RustPython Length of output: 174 🏁 Script executed: rg "get_special_method_names\|__enter__\|__exit__" crates/stdlib/src/_opcode.rs -A 2 -B 2Repository: RustPython/RustPython Length of output: 47 🏁 Script executed: rg "get_intrinsic1_descs|get_intrinsic2_descs" crates/stdlib/src/_opcode.rs -A 6Repository: RustPython/RustPython Length of output: 639 🏁 Script executed: rg "class.*Manager|__enter__|__exit__|__aenter__|__aexit__" --type rs | head -30Repository: RustPython/RustPython Length of output: 91 🏁 Script executed: cat -n crates/stdlib/src/_opcode.rs | sed -n '1,50p'Repository: RustPython/RustPython Length of output: 1893 🏁 Script executed: rg "get_special_method_names" crates/stdlib/Repository: RustPython/RustPython Length of output: 168 🏁 Script executed: rg "__enter__|__exit__|__aenter__|__aexit__" crates/stdlib/src/_opcode.rsRepository: RustPython/RustPython Length of output: 125 🏁 Script executed: git log --oneline -10 crates/stdlib/src/_opcode.rsRepository: RustPython/RustPython Length of output: 99 🏁 Script executed: find crates -name "*test*" -type f | xargs grep -l "special_method\|__enter__\|__exit__" 2>/dev/null | head -5Repository: RustPython/RustPython Length of output: 159 🏁 Script executed: rg "def get_special_method_names|special_method" crates/stdlib/src/_opcode.rs -B 5 -A 10Repository: RustPython/RustPython Length of output: 446 🏁 Script executed: cat -n crates/stdlib/src/_opcode.rs | sed -n '320,350p'Repository: RustPython/RustPython Length of output: 776 🌐 Web query:
💡 Result: In CPython, Implementation (CPython 3.14): it allocates a list of length API docstring in the generated clinic header: “Return a list of special method names.” [2] Use: import _opcode
names = _opcode.get_special_method_names()Sources: [1] [2] 🏁 Script executed: rg "ASYNC_WITH|WITH_CLEANUP|context.*manager" crates/ --type-list | head -10Repository: RustPython/RustPython Length of output: 454 🏁 Script executed: cat -n crates/stdlib/src/_opcode.rs | sed -n '280,330p'Repository: RustPython/RustPython Length of output: 2069 Incomplete implementation: Returns only context manager special methods, not all special methods. The function syntactically follows the established pattern (array → 🤖 Prompt for AI Agents |
||
|
|
||
| #[pyfunction] | ||
| fn get_executor( | ||
| _code: PyObjectRef, | ||
| _offset: i32, | ||
| vm: &VirtualMachine, | ||
| ) -> PyResult<PyObjectRef> { | ||
| Ok(vm.ctx.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.
🧩 Analysis chain
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 238
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 7418
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 8611
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 1779
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 13278
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 5623
Type safety for encoded LOAD_ATTR args is currently correct but could be improved.
All 2 emission sites (
emit_load_attr,emit_load_attr_method) properly useencode_load_attr_arg, and all 3 consumption sites (stack_effect, disassembly, load_attr runtime) properly decode before using the name index. However, the field typeArg<NameIdx>is misleading since it contains an encoded value, not a raw name index. SinceArg<u32>.get()just returns the raw u32 without decoding, a future maintainer could naively use it as a direct index. Consider introducing a dedicatedEncodedLoadAttrArgtype implementingOpArgTypeto make the encoding requirement explicit in the type system.🤖 Prompt for AI Agents