From 8f78d082091e76f4688aaf626e2d2b927e69dc16 Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu <23022326+d0cd@users.noreply.github.com> Date: Fri, 27 Oct 2023 09:52:19 -0400 Subject: [PATCH 1/2] Implement fix --- compiler/passes/src/code_generation/visit_program.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/passes/src/code_generation/visit_program.rs b/compiler/passes/src/code_generation/visit_program.rs index 9c92ec6cb6..b18b9fadd2 100644 --- a/compiler/passes/src/code_generation/visit_program.rs +++ b/compiler/passes/src/code_generation/visit_program.rs @@ -266,6 +266,9 @@ impl<'a> CodeGenerator<'a> { writeln!(function_string, " await {register};").expect("failed to write to string"); } + // Clear the futures. + self.futures.clear(); + // Construct and append the finalize block body, if it exists. if let Some(finalize) = &function.finalize { function_string.push_str(&self.visit_block(&finalize.block)); From dc4668b50def8587fca94c0d7f7e30117c76b882 Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu <23022326+d0cd@users.noreply.github.com> Date: Fri, 27 Oct 2023 10:07:08 -0400 Subject: [PATCH 2/2] Refactor --- compiler/passes/src/code_generation/visit_program.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/compiler/passes/src/code_generation/visit_program.rs b/compiler/passes/src/code_generation/visit_program.rs index b18b9fadd2..ae2d479c6a 100644 --- a/compiler/passes/src/code_generation/visit_program.rs +++ b/compiler/passes/src/code_generation/visit_program.rs @@ -225,7 +225,7 @@ impl<'a> CodeGenerator<'a> { // If the function contained calls that produced futures, then we need to add the futures to the finalize block as input. // Store the new future registers. let mut future_registers = Vec::new(); - for (_, future_type) in &self.futures { + for (_, future_type) in self.futures.drain(..) { let register_string = format!("r{}", self.next_register); writeln!(function_string, " input {register_string} as {future_type}.future;") .expect("failed to write to string"); @@ -266,9 +266,6 @@ impl<'a> CodeGenerator<'a> { writeln!(function_string, " await {register};").expect("failed to write to string"); } - // Clear the futures. - self.futures.clear(); - // Construct and append the finalize block body, if it exists. if let Some(finalize) = &function.finalize { function_string.push_str(&self.visit_block(&finalize.block));