Skip to content

Commit 121d6b8

Browse files
Do not include user-annotated name when checking for alpha conversion
1 parent 6fb4be9 commit 121d6b8

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

effekt/jvm/src/test/scala/effekt/core/CoreTests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ trait CoreTests extends munit.FunSuite {
4747
expected: ModuleDecl,
4848
clue: => Any = "values are not alpha-equivalent",
4949
names: Names = Names(defaultNames))(using Location): Unit = {
50-
val renamer = TestRenamer(names)
50+
val renamer = TestRenamer(names, preserveUserAnnotatedPrefix=false)
5151
val obtainedRenamed = renamer(obtained)
5252
val expectedRenamed = renamer(expected)
5353
val obtainedPrinted = effekt.core.ReparsablePrettyPrinter.format(obtainedRenamed).layout
@@ -59,7 +59,7 @@ trait CoreTests extends munit.FunSuite {
5959
expected: Stmt,
6060
clue: => Any = "values are not alpha-equivalent",
6161
names: Names = Names(defaultNames))(using Location): Unit = {
62-
val renamer = TestRenamer(names)
62+
val renamer = TestRenamer(names, preserveUserAnnotatedPrefix=false)
6363
shouldBeEqual(renamer(obtained), renamer(expected), clue)
6464
}
6565
def parse(input: String,

effekt/shared/src/main/scala/effekt/core/TestRenamer.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)