Skip to content

Commit b28fc61

Browse files
committed
Remove redundant CPython-referencing comments
Clean up comments that unnecessarily mention CPython per project convention. Replace with concise descriptions of the behavior itself.
1 parent ccc95f6 commit b28fc61

File tree

4 files changed

+15
-24
lines changed

4 files changed

+15
-24
lines changed

crates/codegen/src/compile.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2374,16 +2374,14 @@ impl Compiler {
23742374
}
23752375
}
23762376
ast::Stmt::Break(_) => {
2377-
// Match CPython line-tracing behavior (codegen_break emits NOP).
2378-
emit!(self, Instruction::Nop);
2377+
emit!(self, Instruction::Nop); // NOP for line tracing
23792378
// Unwind fblock stack until we find a loop, emitting cleanup for each fblock
23802379
self.compile_break_continue(statement.range(), true)?;
23812380
let dead = self.new_block();
23822381
self.switch_to_block(dead);
23832382
}
23842383
ast::Stmt::Continue(_) => {
2385-
// Match CPython line-tracing behavior (codegen_continue emits NOP).
2386-
emit!(self, Instruction::Nop);
2384+
emit!(self, Instruction::Nop); // NOP for line tracing
23872385
// Unwind fblock stack until we find a loop, emitting cleanup for each fblock
23882386
self.compile_break_continue(statement.range(), false)?;
23892387
let dead = self.new_block();
@@ -2456,8 +2454,7 @@ impl Compiler {
24562454
}
24572455
}
24582456
ast::Stmt::Pass(_) => {
2459-
// Match CPython line-tracing behavior (Pass_kind emits NOP).
2460-
emit!(self, Instruction::Nop);
2457+
emit!(self, Instruction::Nop); // NOP for line tracing
24612458
}
24622459
ast::Stmt::TypeAlias(ast::StmtTypeAlias {
24632460
name,

crates/codegen/src/ir.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ impl CodeInfo {
255255

256256
// Convert pseudo ops and remove resulting NOPs (keep line-marker NOPs)
257257
convert_pseudo_ops(&mut blocks, varname_cache.len() as u32);
258-
// Remove redundant NOPs (CPython basicblock_remove_redundant_nops):
259-
// keep line-marker NOPs only when they are needed to preserve tracing.
258+
// Remove redundant NOPs, keeping line-marker NOPs only when
259+
// they are needed to preserve tracing.
260260
let mut block_order = Vec::new();
261261
let mut current = BlockIdx(0);
262262
while current != BlockIdx::NULL {
@@ -283,9 +283,12 @@ impl CodeInfo {
283283
}
284284
// Remove if the next instruction has same line or no line.
285285
else if src < src_instructions.len() - 1 {
286-
let next_lineno = src_instructions[src + 1]
287-
.lineno_override
288-
.unwrap_or_else(|| src_instructions[src + 1].location.line.get() as i32);
286+
let next_lineno =
287+
src_instructions[src + 1]
288+
.lineno_override
289+
.unwrap_or_else(|| {
290+
src_instructions[src + 1].location.line.get() as i32
291+
});
289292
if next_lineno == lineno {
290293
remove = true;
291294
} else if next_lineno < 0 {
@@ -344,7 +347,6 @@ impl CodeInfo {
344347
// This is the index into the final instructions array, including EXTENDED_ARG and CACHE
345348
let mut block_to_index = vec![0u32; blocks.len()];
346349
// The offset (in code units) of END_SEND from SEND in the yield-from sequence.
347-
// Matches CPython's END_SEND_OFFSET in Python/assemble.c.
348350
const END_SEND_OFFSET: u32 = 5;
349351
loop {
350352
let mut num_instructions = 0;
@@ -373,9 +375,8 @@ impl CodeInfo {
373375
let mut op = info.instr.expect_real();
374376
let old_arg_size = info.arg.instr_size();
375377
let old_cache_entries = info.cache_entries;
376-
// Keep offsets fixed within this pass, like CPython's
377-
// resolve_jump_offsets(): changes in jump arg/cache sizes only
378-
// take effect in the next pass.
378+
// Keep offsets fixed within this pass: changes in jump
379+
// arg/cache sizes only take effect in the next iteration.
379380
let offset_after = current_offset + old_arg_size as u32 + old_cache_entries;
380381

381382
if target != BlockIdx::NULL {
@@ -448,7 +449,6 @@ impl CodeInfo {
448449
};
449450
linetable_locations.extend(core::iter::repeat_n(lt_loc, info.arg.instr_size()));
450451
// CACHE entries inherit parent instruction's location
451-
// (matches CPython assemble_location_info: instr_size includes caches)
452452
if cache_count > 0 {
453453
linetable_locations.extend(core::iter::repeat_n(lt_loc, cache_count));
454454
}
@@ -702,7 +702,6 @@ impl CodeInfo {
702702
}
703703
}
704704

705-
/// CPython flowgraph.c:
706705
/// LOAD_GLOBAL <even> + PUSH_NULL -> LOAD_GLOBAL <odd>, NOP
707706
fn optimize_load_global_push_null(&mut self) {
708707
for block in &mut self.blocks {
@@ -1547,8 +1546,7 @@ fn normalize_jumps(blocks: &mut [Block]) {
15471546
}
15481547
}
15491548

1550-
// Resolve JUMP/JUMP_NO_INTERRUPT pseudo instructions before offset fixpoint,
1551-
// matching CPython's resolve_unconditional_jumps().
1549+
// Resolve JUMP/JUMP_NO_INTERRUPT pseudo instructions before offset fixpoint.
15521550
let mut block_order = vec![0u32; blocks.len()];
15531551
for (pos, &block_idx) in visit_order.iter().enumerate() {
15541552
block_order[block_idx.idx()] = pos as u32;

crates/compiler-core/src/bytecode/instruction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ impl InstructionMetadata for Instruction {
11981198
Self::GetYieldFromIter => w!(GET_YIELD_FROM_ITER),
11991199
Self::BuildTemplate => w!(BUILD_TEMPLATE),
12001200
Self::BuildInterpolation { oparg } => w!(BUILD_INTERPOLATION, oparg),
1201-
_ => write!(f, "{self:?}"),
1201+
_ => w!(RUSTPYTHON_PLACEHOLDER),
12021202
}
12031203
}
12041204
}

crates/vm/src/frame.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2651,7 +2651,6 @@ impl ExecutingFrame<'_> {
26512651
}
26522652
Instruction::InstrumentedJumpForward => {
26532653
let src_offset = (self.lasti() - 1) * 2;
2654-
// JumpForward: 0 caches, forward
26552654
let target_idx = self.lasti() + u32::from(arg);
26562655
let target = bytecode::Label(target_idx);
26572656
self.jump(target);
@@ -2662,7 +2661,6 @@ impl ExecutingFrame<'_> {
26622661
}
26632662
Instruction::InstrumentedJumpBackward => {
26642663
let src_offset = (self.lasti() - 1) * 2;
2665-
// JumpBackward: 1 cache, backward
26662664
let target_idx = self.lasti() + 1 - u32::from(arg);
26672665
let target = bytecode::Label(target_idx);
26682666
self.jump(target);
@@ -2673,7 +2671,6 @@ impl ExecutingFrame<'_> {
26732671
}
26742672
Instruction::InstrumentedForIter => {
26752673
let src_offset = (self.lasti() - 1) * 2;
2676-
// ForIter: 1 cache, forward relative
26772674
let target = bytecode::Label(self.lasti() + 1 + u32::from(arg));
26782675
let continued = self.execute_for_iter(vm, target)?;
26792676
if continued {
@@ -2720,7 +2717,6 @@ impl ExecutingFrame<'_> {
27202717
}
27212718
Instruction::InstrumentedPopJumpIfTrue => {
27222719
let src_offset = (self.lasti() - 1) * 2;
2723-
// PopJumpIfTrue: 1 cache, forward
27242720
let target_idx = self.lasti() + 1 + u32::from(arg);
27252721
let obj = self.pop_value();
27262722
let value = obj.try_to_bool(vm)?;

0 commit comments

Comments
 (0)