diff --git a/hercules_cg/src/rt.rs b/hercules_cg/src/rt.rs index 313f7c10ad8b4d56c8b5a45bc7aca315aab0f807..cbf70eec682be6dff91016e0f1b3722ce1fea0fa 100644 --- a/hercules_cg/src/rt.rs +++ b/hercules_cg/src/rt.rs @@ -138,6 +138,7 @@ struct RTContext<'a> { #[derive(Debug, Clone, Default)] struct RustBlock { prologue: String, + arc_clones: String, data: String, phi_tmp_assignments: String, phi_assignments: String, @@ -268,8 +269,9 @@ impl<'a> RTContext<'a> { } else { write!( w, - "{}{}{}{}{}", + "{}{}{}{}{}{}", block.prologue, + block.arc_clones, block.data, block.phi_tmp_assignments, block.phi_assignments, @@ -566,12 +568,14 @@ impl<'a> RTContext<'a> { assert_eq!(control, bb); // The device backends ensure that device functions have the // same interface as AsyncRust functions. - let block = &mut blocks.get_mut(&bb).unwrap().data; + let block = &mut blocks.get_mut(&bb).unwrap(); + let arc_clones = &mut block.arc_clones; + let block = &mut block.data; let is_async = func.schedules[id.idx()].contains(&Schedule::AsyncCall); if is_async { for arg in args { if let Some(arc) = self.clone_arc(*arg) { - write!(block, "{}", arc)?; + write!(arc_clones, "{}", arc)?; } } } @@ -580,11 +584,13 @@ impl<'a> RTContext<'a> { (Device::AsyncRust, false) | (_, false) => { format!("{} = ", self.get_value(id, bb, true)) } - (_, true) => format!( - "{}*async_call_{}.lock().await = Some(::async_std::task::spawn(async move {{ ", - self.clone_arc(id).unwrap(), - id.idx(), - ), + (_, true) => { + write!(arc_clones, "{}", self.clone_arc(id).unwrap())?; + format!( + "*async_call_{}.lock().await = Some(::async_std::task::spawn(async move {{ ", + id.idx(), + ) + } }; let postfix = match (device, is_async) { (Device::AsyncRust, false) => ".await",