From 7cf78eaa6d8061613edbe66e8b76b74d0ea37352 Mon Sep 17 00:00:00 2001 From: Empa Date: Wed, 17 Jan 2024 18:53:47 +0100 Subject: [PATCH] Don't output noops --- crates/saft-bytecode/src/compiler.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/saft-bytecode/src/compiler.rs b/crates/saft-bytecode/src/compiler.rs index 4b94edf..60e927b 100644 --- a/crates/saft-bytecode/src/compiler.rs +++ b/crates/saft-bytecode/src/compiler.rs @@ -303,13 +303,20 @@ impl Compiler { #[allow(unused)] fn exit_scope(&mut self, chunk: &mut Chunk, span: impl Borrow) { let env = self.scopes.pop().unwrap(); - chunk.emit(Op::PopN(self.stack_i - env.stack_base), span); + + let to_pop = self.stack_i - env.stack_base; + if 0 < to_pop { + chunk.emit(Op::PopN(to_pop), span); + } } fn exit_scope_trailing(&mut self, chunk: &mut Chunk, span: impl Borrow) { let env = self.scopes.pop().unwrap(); let decls = self.stack_i - env.stack_base; - chunk.emit(Op::TrailPop(decls), span) + + if 0 < decls { + chunk.emit(Op::TrailPop(decls), span) + } } fn binary(