Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
1,275 changes: 925 additions & 350 deletions crates/codegen/src/compile.rs

Large diffs are not rendered by default.

1,202 changes: 1,051 additions & 151 deletions crates/codegen/src/ir.rs

Large diffs are not rendered by default.

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

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

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

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

22 changes: 5 additions & 17 deletions crates/codegen/src/symboltable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1595,22 +1595,7 @@ impl SymbolTableBuilder {
self.scan_expression(target, ExpressionContext::Store)?;
}
}
// Only scan annotation in annotation scope for simple name targets.
// Non-simple annotations (subscript, attribute, parenthesized) are
// never compiled into __annotate__, so scanning them would create
// sub_tables that cause mismatch in the annotation scope's sub_table index.
let is_simple_name = *simple && matches!(&**target, Expr::Name(_));
if is_simple_name {
self.scan_ann_assign_annotation(annotation)?;
} else {
// Still validate annotation for forbidden expressions
// (yield, await, named) even for non-simple targets.
let was_in_annotation = self.in_annotation;
self.in_annotation = true;
let result = self.scan_expression(annotation, ExpressionContext::Load);
self.in_annotation = was_in_annotation;
result?;
}
self.scan_ann_assign_annotation(annotation)?;
if let Some(value) = value {
self.scan_expression(value, ExpressionContext::Load)?;
}
Expand Down Expand Up @@ -1639,6 +1624,10 @@ impl SymbolTableBuilder {
let saved_in_conditional_block = self.in_conditional_block;
self.in_conditional_block = true;
self.scan_statements(body)?;
self.scan_statements(orelse)?;
// Keep nested scope collection in the same order that codegen
// compiles try/except, since the compiler currently consumes
// sub_tables through a linear cursor.
for handler in handlers {
let ExceptHandler::ExceptHandler(ast::ExceptHandlerExceptHandler {
type_,
Expand All @@ -1654,7 +1643,6 @@ impl SymbolTableBuilder {
}
self.scan_statements(body)?;
}
self.scan_statements(orelse)?;
self.scan_statements(finalbody)?;
self.in_conditional_block = saved_in_conditional_block;
}
Expand Down
4 changes: 2 additions & 2 deletions crates/compiler-core/src/bytecode/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1513,11 +1513,11 @@ impl InstructionMetadata for PseudoInstruction {
/// SETUP_FINALLY: +1 (exc)
/// SETUP_CLEANUP: +2 (lasti + exc)
/// SETUP_WITH: +1 (pops __enter__ result, pushes lasti + exc)
fn stack_effect_jump(&self, _oparg: u32) -> i32 {
fn stack_effect_jump(&self, oparg: u32) -> i32 {
match self {
Self::SetupFinally { .. } | Self::SetupWith { .. } => 1,
Self::SetupCleanup { .. } => 2,
_ => self.stack_effect(_oparg),
_ => self.stack_effect(oparg),
}
}

Expand Down
Loading
Loading