diff --git a/compiler/gen_dev/src/lib.rs b/compiler/gen_dev/src/lib.rs index df76cd03f3..0bc6a20315 100644 --- a/compiler/gen_dev/src/lib.rs +++ b/compiler/gen_dev/src/lib.rs @@ -741,6 +741,8 @@ trait Backend<'a> { /// scan_ast runs through the ast and fill the last seen map. /// This must iterate through the ast in the same way that build_stmt does. i.e. then before else. fn scan_ast(&mut self, stmt: &Stmt<'a>) { + // Join map keeps track of join point paramaters so that we can keep them around while they still might be jumped to. + let mut join_map: MutMap]> = MutMap::default(); match stmt { Stmt::Let(sym, expr, _, following) => { self.set_last_seen(*sym, stmt); @@ -829,8 +831,10 @@ trait Backend<'a> { parameters, body: continuation, remainder, + id, .. } => { + join_map.insert(*id, parameters); for param in *parameters { self.set_last_seen(param.symbol, stmt); } @@ -838,6 +842,12 @@ trait Backend<'a> { self.scan_ast(remainder); } Stmt::Jump(JoinPointId(sym), symbols) => { + if let Some(parameters) = join_map.get(&JoinPointId(*sym)) { + // Keep the parameters around. They will be overwritten when jumping. + for param in *parameters { + self.set_last_seen(param.symbol, stmt); + } + } self.set_last_seen(*sym, stmt); for sym in *symbols { self.set_last_seen(*sym, stmt);