Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Address code review feedback from #7481
- Set is_generator flag for generator expressions in scan_comprehension
- Fix posonlyargs priority in collect_static_attributes first param
- Add match statement support to scan_store_attrs
- Fix stale decorator stack comment
- Reorder NOP removal after fold_unary_negative for better collection folding
  • Loading branch information
youknowone committed Mar 25, 2026
commit 296eaa1e96bbefb71c209a4a00facbf2273e6024
11 changes: 8 additions & 3 deletions crates/codegen/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2775,7 +2775,7 @@ impl Compiler {
}

/// Push decorators onto the stack in source order.
/// For @dec1 @dec2 def foo(): stack becomes [dec1, NULL, dec2, NULL]
/// For @dec1 @dec2 def foo(): stack becomes [dec1, dec2]
fn prepare_decorators(&mut self, decorator_list: &[ast::Decorator]) -> CompileResult<()> {
for decorator in decorator_list {
self.compile_expression(&decorator.expression)?;
Expand Down Expand Up @@ -4547,9 +4547,9 @@ impl Compiler {
}
let first_param = f
.parameters
.args
.posonlyargs
.first()
.or(f.parameters.posonlyargs.first())
.or(f.parameters.args.first())
.map(|p| &p.parameter.name);
let Some(self_name) = first_param else {
continue;
Expand Down Expand Up @@ -4632,6 +4632,11 @@ impl Compiler {
ast::Stmt::With(s) => {
Self::scan_store_attrs(&s.body, name, attrs);
}
ast::Stmt::Match(s) => {
for case in &s.cases {
Self::scan_store_attrs(&case.body, name, attrs);
}
}
_ => {}
}
}
Expand Down
3 changes: 2 additions & 1 deletion crates/codegen/src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,11 @@ impl CodeInfo {
) -> crate::InternalResult<CodeObject> {
// Constant folding passes
self.fold_unary_negative();
self.remove_nops(); // remove NOPs from unary folding so tuple/list/set see contiguous LOADs
self.fold_tuple_constants();
self.fold_list_constants();
self.fold_set_constants();
self.remove_nops(); // remove NOPs from folding before iterable optimization
self.remove_nops(); // remove NOPs from collection folding
self.fold_const_iterable_for_iter();
self.convert_to_load_small_int();
self.remove_unused_consts();
Expand Down
2 changes: 2 additions & 0 deletions crates/codegen/src/symboltable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2136,6 +2136,8 @@ impl SymbolTableBuilder {
CompilerScope::Comprehension,
self.line_index_start(range),
);
// Generator expressions need the is_generator flag
self.tables.last_mut().unwrap().is_generator = is_generator;

// PEP 709: Mark non-generator comprehensions for inlining,
// but only inside function-like scopes (fastlocals).
Expand Down