Skip to content

Commit 238d1e7

Browse files
committed
Address review feedback on slice folding, fallthrough, attr-chain
- try_fold_constant_slice now delegates to try_fold_constant_expr so slice bounds accept the same constants other folding paths do (unary-folded values, __debug__, etc.). - remove_nops resolves fallthrough predecessors through empty blocks via next_nonempty_block before checking ends_with_for_cleanup. - should_deopt_borrowed_attr_chain ReturnIter matcher now accepts Instruction::CallKw alongside Instruction::Call, matching the Call/CallKw treatment in the surrounding deopt trigger check.
1 parent 23c689d commit 238d1e7

2 files changed

Lines changed: 7 additions & 33 deletions

File tree

crates/codegen/src/compile.rs

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10172,33 +10172,6 @@ impl Compiler {
1017210172
self.emit_arg(idx, |consti| Instruction::LoadConst { consti })
1017310173
}
1017410174

10175-
fn try_fold_slice_constant_part(
10176-
&mut self,
10177-
expr: &ast::Expr,
10178-
) -> CompileResult<Option<ConstantData>> {
10179-
Ok(Some(match expr {
10180-
ast::Expr::NumberLiteral(num) => match &num.value {
10181-
ast::Number::Int(int) => ConstantData::Integer {
10182-
value: ruff_int_to_bigint(int).map_err(|e| self.error(e))?,
10183-
},
10184-
ast::Number::Float(f) => ConstantData::Float { value: *f },
10185-
ast::Number::Complex { real, imag } => ConstantData::Complex {
10186-
value: Complex::new(*real, *imag),
10187-
},
10188-
},
10189-
ast::Expr::StringLiteral(s) => ConstantData::Str {
10190-
value: self.compile_string_value(s),
10191-
},
10192-
ast::Expr::BytesLiteral(b) => ConstantData::Bytes {
10193-
value: b.value.bytes().collect(),
10194-
},
10195-
ast::Expr::BooleanLiteral(b) => ConstantData::Boolean { value: b.value },
10196-
ast::Expr::NoneLiteral(_) => ConstantData::None,
10197-
ast::Expr::EllipsisLiteral(_) => ConstantData::Ellipsis,
10198-
_ => return Ok(None),
10199-
}))
10200-
}
10201-
1020210175
fn try_fold_constant_slice(
1020310176
&mut self,
1020410177
lower: Option<&ast::Expr>,
@@ -10207,7 +10180,7 @@ impl Compiler {
1020710180
) -> CompileResult<Option<ConstantData>> {
1020810181
let start = match lower {
1020910182
Some(expr) => {
10210-
let Some(constant) = self.try_fold_slice_constant_part(expr)? else {
10183+
let Some(constant) = self.try_fold_constant_expr(expr)? else {
1021110184
return Ok(None);
1021210185
};
1021310186
constant
@@ -10216,7 +10189,7 @@ impl Compiler {
1021610189
};
1021710190
let stop = match upper {
1021810191
Some(expr) => {
10219-
let Some(constant) = self.try_fold_slice_constant_part(expr)? else {
10192+
let Some(constant) = self.try_fold_constant_expr(expr)? else {
1022010193
return Ok(None);
1022110194
};
1022210195
constant
@@ -10225,7 +10198,7 @@ impl Compiler {
1022510198
};
1022610199
let step = match step {
1022710200
Some(expr) => {
10228-
let Some(constant) = self.try_fold_slice_constant_part(expr)? else {
10201+
let Some(constant) = self.try_fold_constant_expr(expr)? else {
1022910202
return Ok(None);
1023010203
};
1023110204
constant

crates/codegen/src/ir.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2562,8 +2562,9 @@ impl CodeInfo {
25622562
let jump_targets = compute_target_predecessor_flags(&self.blocks).jump;
25632563
let mut fallthrough_predecessors = vec![None; self.blocks.len()];
25642564
for (pred_idx, block) in self.blocks.iter().enumerate() {
2565-
if block.next != BlockIdx::NULL {
2566-
fallthrough_predecessors[block.next.idx()] = Some(pred_idx);
2565+
let next = next_nonempty_block(&self.blocks, block.next);
2566+
if next != BlockIdx::NULL {
2567+
fallthrough_predecessors[next.idx()] = Some(pred_idx);
25672568
}
25682569
}
25692570
let starts_after_for_cleanup: Vec<_> = fallthrough_predecessors
@@ -4407,7 +4408,7 @@ impl CodeInfo {
44074408
Some(Instruction::GetIter) => Some(DeoptKind::ReturnIter {
44084409
tail_start_idx: cursor + 1,
44094410
}),
4410-
Some(Instruction::Call { .. }) => real_instrs
4411+
Some(Instruction::Call { .. } | Instruction::CallKw { .. }) => real_instrs
44114412
.get(cursor + 1)
44124413
.and_then(|(_, info)| info.instr.real())
44134414
.and_then(|instr| {

0 commit comments

Comments
 (0)