@@ -14,7 +14,7 @@ import effekt.{Template, core, symbols}
1414 *
1515 * @param C the context is used to copy annotations from old symbols to fresh symbols
1616 */
17- class TestRenamer (names : Names = Names (Map .empty), prefix : String = " $" ) extends core.Tree .Rewrite {
17+ class TestRenamer (names : Names = Names (Map .empty), prefix : String = " $" , preserveUserAnnotatedPrefix : Boolean = true ) extends core.Tree .Rewrite {
1818
1919 // list of scopes that map bound symbols to their renamed variants.
2020 private var scopes : List [Map [Id , Id ]] = List .empty
@@ -39,14 +39,18 @@ class TestRenamer(names: Names = Names(Map.empty), prefix: String = "$") extends
3939 } else {
4040 id.name.name
4141 }
42+ // For many purposes, we would like to include the user-annotated name in the fresh id,
43+ // so that printed terms are more readable.
44+ // However, we do not want to include it when checking for alpha-equivalence in tests.
45+ val userPart = if preserveUserAnnotatedPrefix then userName else " "
4246 // HACK: This is an unfortunate hack.
4347 // TestRenamer is often used to check for alpha-equivalence by renaming both sides of a comparison.
4448 // However, Effekt requires globally unique Barendregt indices for all symbols, so just creating fresh
4549 // Ids is not sufficient. We also need to cache these fresh Ids, so that both sides of an alpha-equivalence
4650 // comparison get the same fresh Id for a given original Id.
4751 // This is achieved by generating a deterministic string `uniqueName` on both sides, and looking it up in `names`,
4852 // which generates a unique Id for it once and reuses it on subsequent lookups.
49- val uniqueName = userName + prefix + suffix.toString
53+ val uniqueName = userPart + prefix + suffix.toString
5054 suffix = suffix + 1
5155 names.idFor(uniqueName)
5256
0 commit comments