add JoinPointId tracking for parameters

This commit is contained in:
Brendan Hansknecht 2022-02-17 23:17:17 -08:00
parent fb589f7dc5
commit b00ef5ea4f

View file

@ -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<JoinPointId, &'a [Param<'a>]> = 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);