Skip to content

Commit 0a1cb62

Browse files
committed
Fix CI: clippy warnings and module-scope comprehension inlining
- Add #[allow(dead_code)] for combine_store_fast_load_fast placeholder - Use Copy instead of clone for InstructionInfo - Disable PEP 709 comprehension inlining at module/class scope: restore in_func() guard in is_inlined_comprehension_context, remove fast_hidden NAME→FAST override and module-scope fast_hidden population that caused for-loop variables to be invisible to lambdas
1 parent 1001420 commit 0a1cb62

2 files changed

Lines changed: 10 additions & 44 deletions

File tree

crates/codegen/src/compile.rs

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,8 +1039,9 @@ impl Compiler {
10391039
if comprehension_type == ComprehensionType::Generator {
10401040
return false;
10411041
}
1042-
// CPython inlines comprehensions at ALL scopes (module, class, function, lambda)
1043-
// — only generator expressions and annotation scopes nested in class are excluded.
1042+
if !self.ctx.in_func() {
1043+
return false;
1044+
}
10441045
self.symbol_table_stack
10451046
.last()
10461047
.and_then(|t| t.sub_tables.get(t.next_sub_table))
@@ -2113,20 +2114,6 @@ impl Compiler {
21132114
SymbolScope::Unknown => NameOp::Name,
21142115
};
21152116

2116-
// PEP 709: Override NAME → FAST for comprehension-local variables at non-function scope
2117-
let op_type = if matches!(op_type, NameOp::Name)
2118-
&& self
2119-
.current_code_info()
2120-
.metadata
2121-
.fast_hidden
2122-
.get(name.as_ref())
2123-
.is_some_and(|&v| v)
2124-
{
2125-
NameOp::Fast
2126-
} else {
2127-
op_type
2128-
};
2129-
21302117
// Generate appropriate instructions based on operation type
21312118
match op_type {
21322119
NameOp::Deref => {
@@ -7484,20 +7471,12 @@ impl Compiler {
74847471
left, op, right, ..
74857472
}) => {
74867473
// optimize_format_str: 'format' % (args,) → f-string bytecode
7487-
if matches!(op, ast::Operator::Mod) {
7488-
if let ast::Expr::StringLiteral(s) = left.as_ref() {
7489-
if let ast::Expr::Tuple(ast::ExprTuple { elts, .. }) =
7490-
right.as_ref()
7491-
{
7492-
if self.try_optimize_format_str(
7493-
&s.value.to_str(),
7494-
elts,
7495-
range,
7496-
)? {
7497-
return Ok(());
7498-
}
7499-
}
7500-
}
7474+
if matches!(op, ast::Operator::Mod)
7475+
&& let ast::Expr::StringLiteral(s) = left.as_ref()
7476+
&& let ast::Expr::Tuple(ast::ExprTuple { elts, .. }) = right.as_ref()
7477+
&& self.try_optimize_format_str(s.value.to_str(), elts, range)?
7478+
{
7479+
return Ok(());
75017480
}
75027481
self.compile_expression(left)?;
75037482
self.compile_expression(right)?;
@@ -8626,20 +8605,6 @@ impl Compiler {
86268605
}
86278606
}
86288607

8629-
// PEP 709: For non-function scopes (module/class), mark comprehension-local
8630-
// variables in fast_hidden so compile_name uses FAST instead of NAME.
8631-
if !self.ctx.in_func() {
8632-
for (name, comp_sym) in &comp_table.symbols {
8633-
if comp_sym.flags.contains(SymbolFlags::PARAMETER) {
8634-
continue;
8635-
}
8636-
if comp_sym.scope == SymbolScope::Local || comp_sym.scope == SymbolScope::Cell {
8637-
let info = self.current_code_info();
8638-
info.metadata.fast_hidden.insert(name.clone(), true);
8639-
}
8640-
}
8641-
}
8642-
86438608
// Step 2: Save local variables that will be shadowed by the comprehension.
86448609
// For each variable, we push the fast local value via LoadFastAndClear.
86458610
// For merged CELL variables, LoadFastAndClear saves the cell object from

crates/codegen/src/ir.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,6 +1480,7 @@ impl CodeInfo {
14801480
/// Combine STORE_FAST + LOAD_FAST → STORE_FAST_LOAD_FAST.
14811481
/// Must run AFTER optimize_load_fast_borrow so that STORE_FAST + LOAD_FAST_BORROW
14821482
/// pairs are NOT combined (matching CPython's flowgraph.c behavior).
1483+
#[allow(dead_code)]
14831484
fn combine_store_fast_load_fast(&mut self) {
14841485
for block in &mut self.blocks {
14851486
let mut i = 0;

0 commit comments

Comments
 (0)