Visitar URL original
Improve super() optimization documentation · RustPython/RustPython@6614dac · GitHub
Skip to content

Commit 6614dac

Browse files
youknowoneclaude
andcommitted
Improve super() optimization documentation
- Document first-parameter assumption in load_args_for_super - Clarify stack pop order comment in frame.rs Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 270df4b commit 6614dac

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

‎crates/codegen/src/compile.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,9 @@ impl Compiler {
802802
};
803803
self.emit_arg(idx, Instruction::LoadDeref);
804804

805-
// Load first parameter (typically 'self')
805+
// Load first parameter (typically 'self').
806+
// Safety: can_optimize_super_call() ensures argcount > 0, and
807+
// parameters are always added to varnames first (see symboltable.rs).
806808
let first_param = {
807809
let info = self.code_stack.last().unwrap();
808810
info.metadata.varnames.first().cloned()

‎crates/vm/src/frame.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2535,7 +2535,8 @@ impl ExecutingFrame<'_> {
25352535
let (name_idx, load_method, has_class) = bytecode::decode_load_super_attr_arg(oparg);
25362536
let attr_name = self.code.names[name_idx as usize];
25372537

2538-
// Pop [super, class, self] from stack
2538+
// Stack layout (bottom to top): [super, class, self]
2539+
// Pop in LIFO order: self, class, super
25392540
let self_obj = self.pop_value();
25402541
let class = self.pop_value();
25412542
let global_super = self.pop_value();

0 commit comments

Comments
 (0)