cucapra/dahlia

UnrollBank doesn't re-write same local variable names in different definitions.

Closed this issue · 0 comments

Given:

def A() = {
  let k: ubit<2> = 0;
  k := k + 1;
}

def B() = {
  let k: ubit<2> = 0;
  k := k + 1;
}

In the Lower unroll and bank pass, we see the following name re-write:

def A() = {
  let k_: ubit<2> = 0;
  ---
  k_ := (k_ + 1);
}
def B() = {
  let k: ubit<2> = 0; // <-- re-write never occurs.
  ---
  k_ := (k_ + 1);
}

This results in:

[Type error] [Line 10, Column 3] `k_' is not bound in scope.
  k_ := (k_ + 1);
  ^

Offending code (or at least part of it). My "hot" fix is removing the suffix.

val suf = env.idxMap.toList.sortBy(_._1.v).map(_._2).mkString("_")
val newName = id.copy(s"${id.v}_${suf}")