Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
c09c475
Align CFG cleanup bytecode with CPython
youknowone Apr 28, 2026
fe64200
remove test
youknowone Apr 30, 2026
94e2ae3
Align bytecode CFG cleanup with CPython
youknowone May 5, 2026
a743ffc
fix
youknowone May 5, 2026
c998628
Align named-except borrow deopts with CPython
youknowone May 5, 2026
68610b9
Remove duplicated Lib test codegen cases
youknowone May 5, 2026
c82c43f
Cache CFG layout predecessors during NOP cleanup
youknowone May 6, 2026
cd9a711
Address bytecode parity review feedback
youknowone May 7, 2026
15a88df
Align nested with cleanup bytecode
youknowone May 7, 2026
4bd27be
Align conditional raise loop backedge ordering
youknowone May 7, 2026
9b257b1
Align percent format optimization with CPython preprocess
youknowone May 7, 2026
8fbe367
Preserve shared finally reraises in CFG cleanup
youknowone May 7, 2026
3ccda96
Align CFG cleanup with CPython finally layout
youknowone May 7, 2026
2aa954f
Align loop CFG anchors with CPython
youknowone May 7, 2026
742ff9b
Preserve loop false-path CFG bodies
youknowone May 7, 2026
6cfa6f2
Align protected store-subscript CFG bytecode
youknowone May 7, 2026
cc59c46
Align borrow deopts with CPython CFG
youknowone May 7, 2026
891e972
Align delete-loop CFG with CPython
youknowone May 7, 2026
19b7427
Align CFG inlining with CPython jumps
youknowone May 7, 2026
d734c06
Align protected CFG jump threading
youknowone May 7, 2026
0e2b226
Narrow handler resume borrow deopt
youknowone May 7, 2026
3bb0430
Preserve branch-local implicit continue targets
youknowone May 7, 2026
55ec30d
Avoid duplicating boolop continue backedges
youknowone May 7, 2026
95c4492
Preserve same-line assert message borrows
youknowone May 7, 2026
8ce6677
Handle nested handler update tail borrows
youknowone May 7, 2026
d37b510
Align terminal handler borrow deopts with CPython CFG
youknowone May 7, 2026
ac086bf
Refine borrow deopts for reraise handler continuations
youknowone May 7, 2026
644d3e3
Refine try-else terminal handler borrow deopts
youknowone May 7, 2026
7adc9f4
Refine protected tail borrow parity
youknowone May 7, 2026
33ec4a6
Refine exception borrow deopt parity
youknowone May 7, 2026
de00801
Align while loop CFG layout with CPython
youknowone May 7, 2026
309b936
Align loop backedge CFG with CPython
youknowone May 7, 2026
f3b8ba1
Handle multi-block scope-exit CFG segments
youknowone May 7, 2026
aa2ca06
Preserve CPython-normalized call-body CFG
youknowone May 7, 2026
cea61f2
Preserve CPython empty if-end return anchor
youknowone May 7, 2026
8be2a54
Match CPython borrow CFG boundaries
youknowone May 7, 2026
f155436
Match CPython tuple unpack constant folding
youknowone May 7, 2026
85c3367
Match CPython implicit continue CFG layout
youknowone May 7, 2026
bb7be66
Keep implicit continue CFG targets in layout
youknowone May 7, 2026
058bc6d
Align try-except end label location with CPython
youknowone May 7, 2026
e4eb97c
Remove folded operand NOPs before line propagation
youknowone May 8, 2026
b022111
Align no-location return exit handling
youknowone May 8, 2026
5e4c096
Align nested protected import bytecode
youknowone May 8, 2026
f7d8240
Align conditional loop backedge layout
youknowone May 8, 2026
5001df7
Align protected loop exit duplication
youknowone May 8, 2026
6b604df
Preserve protected jump-back duplicates
youknowone May 8, 2026
83f109e
Align loop call-body backedge layout
youknowone May 8, 2026
3e11e1f
Align future annotation setup ordering
youknowone May 8, 2026
88ec625
Align named-except cleanup and borrow parity
youknowone May 8, 2026
e24a9b7
Align redundant jump removal with CPython
youknowone May 8, 2026
7f1376b
Preserve finally cleanup jump NOPs
youknowone May 8, 2026
6f95452
Align finally cleanup CFG with CPython
youknowone May 8, 2026
1d078e3
Fix finally cleanup CFG regression
youknowone May 8, 2026
85c70ca
Align async cleanup CFG marker handling
youknowone May 8, 2026
606e816
Preserve CPython continue CFG layout before conditional bodies
youknowone May 8, 2026
b340ca8
Refine protected CFG bytecode parity
youknowone May 8, 2026
330c44c
Align protected CFG cleanup layout
youknowone May 8, 2026
9c737eb
Align CFG cleanup and peephole parity
youknowone May 8, 2026
d35c13d
Align nested loop conditional CFG layout
youknowone May 8, 2026
bba340b
Align named expression comprehension scope
youknowone May 8, 2026
ea757cf
Align CFG cleanup with CPython line markers
youknowone May 8, 2026
555e8fc
Align CFG line marker cleanup with CPython
youknowone May 8, 2026
8abe32a
Align loop CFG fallthrough with CPython
youknowone May 8, 2026
05d96e4
Align conditional CFG fallthrough cases with CPython
youknowone May 8, 2026
a891818
Align protected CFG layout with CPython
youknowone May 8, 2026
24dde16
Align CFG cleanup and type-param calls with CPython
youknowone May 8, 2026
93e8bc4
Align annotation and super call bytecode parity
youknowone May 8, 2026
1b414fe
Align finally reraise tail inlining
youknowone May 8, 2026
7268983
Align protected loop CFG cleanup
youknowone May 8, 2026
a24a791
Align loop CFG bytecode layout with CPython
youknowone May 9, 2026
0941b7a
Align nested loop jump-back layout
youknowone May 9, 2026
448e1f2
Align conditional jump threading with CPython
youknowone May 9, 2026
a448fb6
fix
youknowone May 9, 2026
b3b8329
Skip test_stack_overflow under -u cpu
youknowone May 11, 2026
7790e54
Fix CI lint and clippy errors
youknowone May 12, 2026
19bf583
Speed up CFG cleanup for large compile inputs
youknowone May 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Align CFG line marker cleanup with CPython
  • Loading branch information
youknowone committed May 11, 2026
commit 555e8fca93bab4d9fbdcaa162395896bef4a799b
103 changes: 103 additions & 0 deletions crates/codegen/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12126,6 +12126,43 @@ mod tests {
stack_top.debug_late_cfg_trace().unwrap()
}

#[test]
#[ignore = "debug helper"]
fn debug_trace_nested_continue_after_optional_body() {
let trace = compile_single_function_late_cfg_trace(
"\
def f(names, show_empty, keywords, args_buffer, args, cls, object, level):
for name in names:
value = getattr(cls, name)
if not show_empty:
if value == []:
field_type = cls._field_types.get(name, object)
if getattr(field_type, '__origin__', ...) is list:
if not keywords:
args_buffer.append(repr(value))
continue
if not keywords:
args.extend(args_buffer)
args_buffer = []
value, simple = _format(value, level)
if keywords:
args.append('%s=%s' % (name, value))
else:
args.append(value)
",
"f",
);
for (label, dump) in trace {
if label == "after_reorder"
|| label == "after_remove_redundant_nops_and_jumps"
|| label == "after_final_cfg_cleanup"
|| label == "after_borrow_deopts"
{
eprintln!("=== {label} ===\n{dump}");
}
}
}

#[test]
#[ignore = "debug helper"]
fn debug_trace_make_dataclass_borrow_tail() {
Expand Down Expand Up @@ -23576,6 +23613,72 @@ def f(done=False):
);
}

#[test]
fn test_for_else_pass_keeps_line_marker_after_pop_iter() {
let code = compile_exec(
"\
def f():
for item in ():
pass
else:
pass
marker = 1
return marker
",
);
let f = find_code(&code, "f").expect("missing f code");
let instructions: Vec<_> = f
.instructions
.iter()
.filter(|unit| !matches!(unit.op, Instruction::Cache))
.collect();

assert!(
instructions.windows(2).any(|window| matches!(
window,
[
CodeUnit {
op: Instruction::PopIter,
..
},
CodeUnit {
op: Instruction::Nop,
..
}
]
)),
"for-else pass should keep CPython-style else-line NOP after POP_ITER, got instructions={instructions:?}"
);
}

#[test]
fn test_folded_if_chain_after_previous_chain_keeps_final_elif_line_marker() {
let code = compile_exec(
"\
def f():
if 0: pass
elif 0: pass
if 0: pass
elif 0: pass
elif 0: pass
elif 0: pass
else: pass
",
);
let f = find_code(&code, "f").expect("missing f code");
let nop_count = f
.instructions
.iter()
.filter(|unit| matches!(unit.op, Instruction::Nop))
.count();

assert_eq!(
nop_count, 6,
"folded if chains should preserve CPython-style line-marker NOPs, got instructions={:?}",
f.instructions
);
}

#[test]
fn test_handler_resume_before_later_loop_keeps_borrowed_tail_loads() {
let code = compile_exec(
Expand Down
13 changes: 4 additions & 9 deletions crates/codegen/src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,14 +498,7 @@ impl CodeInfo {
if matches!(instr.instr.real(), Some(Instruction::Nop)) {
if instr.preserve_redundant_jump_as_nop {
remove = false;
} else if lineno < 0
|| prev_lineno == lineno
|| (src > 0
&& matches!(
src_instructions[src - 1].instr.real(),
Some(Instruction::PopIter)
))
{
} else if lineno < 0 || prev_lineno == lineno {
remove = true;
} else if src < src_instructions.len() - 1 {
if src_instructions[src + 1].instr.is_block_push() {
Expand Down Expand Up @@ -15700,7 +15693,9 @@ fn duplicate_end_returns(blocks: &mut Vec<Block>, metadata: &CodeUnitMetadata) {
.last()
.map(|instr| (instr.location, instr.end_location));
let mut cloned_return = return_insts.clone();
if let Some((location, end_location)) = propagated_location {
if !instruction_has_lineno(&cloned_return[0])
&& let Some((location, end_location)) = propagated_location
{
for instr in &mut cloned_return {
overwrite_location(instr, location, end_location);
}
Expand Down