Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
40cbc39
Emit TO_BOOL before conditional jumps, fix class/module prologue
youknowone Mar 20, 2026
f52276e
Emit MAKE_CELL and COPY_FREE_VARS before RESUME
youknowone Mar 20, 2026
7a9c29d
Emit __static_attributes__ at end of class bodies
youknowone Mar 20, 2026
f8f7fbf
Remove expectedFailure from DictProxyTests iter tests
youknowone Mar 20, 2026
e3fa83e
Use 1-based stack indexing for LIST_EXTEND, SET_UPDATE, etc.
youknowone Mar 20, 2026
18c23e5
Use plain LOAD_ATTR + PUSH_NULL for calls on imported names
youknowone Mar 20, 2026
b2995bc
Duplicate return-None epilogue for fall-through blocks
youknowone Mar 20, 2026
35ac45d
Run cargo fmt on ir.rs
youknowone Mar 20, 2026
1092110
Remove expectedFailure from test_intrinsic_1 in test_dis
youknowone Mar 20, 2026
cc23051
Emit TO_BOOL before conditional jumps for all expressions including C…
youknowone Mar 20, 2026
643861b
Add __classdict__ cell for classes with function definitions
youknowone Mar 21, 2026
a4753e8
Emit __classdictcell__ store in class body epilogue
youknowone Mar 21, 2026
50eaae4
Always run DCE to remove dead code after terminal instructions
youknowone Mar 21, 2026
fdcccad
Restrict LOAD_ATTR plain mode to module/class scope imports
youknowone Mar 21, 2026
83a548e
Eliminate unreachable blocks after jump normalization
youknowone Mar 21, 2026
6a592dd
Fold BUILD_TUPLE 0 into LOAD_CONST empty tuple
youknowone Mar 21, 2026
1d83df2
Handle __classcell__ and __classdictcell__ in type.__new__
youknowone Mar 21, 2026
e1bf8d1
Revert __classdict__ cell and __classdictcell__ changes
youknowone Mar 21, 2026
add881c
Fix unreachable block elimination with fixpoint reachability
youknowone Mar 21, 2026
3181725
Check enclosing scopes for IMPORTED flag in LOAD_ATTR mode
youknowone Mar 22, 2026
c345999
Add __classdict__ cell for classes with function definitions
youknowone Mar 22, 2026
11b4b18
Store __classdictcell__ in class body epilogue
youknowone Mar 22, 2026
0793cb2
Fix clippy collapsible_if warnings and cargo fmt
youknowone Mar 22, 2026
d29b2a9
Revert __classdict__ and __classdictcell__ changes (cause import fail…
youknowone Mar 22, 2026
d5afad9
Revert type.__new__ __classcell__ removal and __classdictcell__ handling
youknowone Mar 22, 2026
c921c8b
Re-add __classdict__ cell and __classdictcell__ store
youknowone Mar 22, 2026
60103dc
Reorder MakeFunctionFlag to match CPython's SET_FUNCTION_ATTRIBUTE
youknowone Mar 22, 2026
560d8ae
Use CPython-compatible power-of-two encoding for SET_FUNCTION_ATTRIBUTE
youknowone Mar 22, 2026
16ce7fb
Remove expectedFailure from test_elim_jump_after_return1 and test_no_…
youknowone Mar 22, 2026
9820993
Remove __classcell__ and __classdictcell__ from class dict in type.__…
youknowone Mar 22, 2026
35a8f7e
Remove expectedFailure from test___classcell___expected_behaviour, ca…
youknowone Mar 22, 2026
e0c7326
Handle MakeCell and CopyFreeVars as no-ops in JIT
youknowone Mar 22, 2026
c958739
Remove expectedFailure from test_load_fast_known_simple
youknowone Mar 23, 2026
926a984
Restore expectedFailure for test_load_fast_known_simple
youknowone Mar 23, 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
Eliminate unreachable blocks after jump normalization
Split DCE into two phases: (1) within-block truncation after
terminal instructions (always runs), (2) whole-block elimination
for blocks only reachable via fall-through from terminal blocks
(runs after normalize_jumps when dead jump instructions exist).
  • Loading branch information
youknowone committed Mar 22, 2026
commit 83a548eace3bde36b3e9264e01944bdfa0c1bf1c
41 changes: 41 additions & 0 deletions crates/codegen/src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ impl CodeInfo {
label_exception_targets(&mut self.blocks);
push_cold_blocks_to_end(&mut self.blocks);
normalize_jumps(&mut self.blocks);
self.eliminate_unreachable_blocks();
duplicate_end_returns(&mut self.blocks);
self.optimize_load_global_push_null();

Expand Down Expand Up @@ -548,6 +549,7 @@ impl CodeInfo {
}

fn dce(&mut self) {
// Truncate instructions after terminal instructions within each block
for block in &mut self.blocks {
let mut last_instr = None;
for (i, ins) in block.instructions.iter().enumerate() {
Expand All @@ -562,6 +564,45 @@ impl CodeInfo {
}
}

/// Clear blocks that are unreachable (not entry, not a jump target,
/// and only reachable via fall-through from a terminal block).
fn eliminate_unreachable_blocks(&mut self) {
let mut reachable = vec![false; self.blocks.len()];
reachable[0] = true;
// Mark blocks reachable via jump targets and exception handlers
for block in &self.blocks {
for ins in &block.instructions {
if ins.target != BlockIdx::NULL {
reachable[ins.target.idx()] = true;
}
if let Some(eh) = &ins.except_handler {
reachable[eh.handler_block.idx()] = true;
}
}
}
// Mark blocks reachable via fall-through from non-terminal blocks
let mut current = BlockIdx(0);
while current != BlockIdx::NULL {
let next = self.blocks[current.idx()].next;
if next != BlockIdx::NULL
&& !self.blocks[current.idx()]
.instructions
.last()
.is_some_and(|ins| {
ins.instr.is_scope_exit() || ins.instr.is_unconditional_jump()
})
{
reachable[next.idx()] = true;
}
current = next;
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
for (i, block) in self.blocks.iter_mut().enumerate() {
if !reachable[i] {
block.instructions.clear();
}
}
}

/// Constant folding: fold LOAD_CONST/LOAD_SMALL_INT + BUILD_TUPLE into LOAD_CONST tuple
/// fold_tuple_of_constants
fn fold_tuple_constants(&mut self) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.