From 9ff7c66ddf579c825e8a823c1e2364ec380509d7 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 8 Oct 2021 10:10:21 +0200 Subject: [PATCH] Remove RenameLifted phase This phase was added to compensate for limitations of the unique names implementation. Local fresh names where numbered globally, now they are numbered by compilation unit. Fixes #12759 --- compiler/src/dotty/tools/dotc/Compiler.scala | 1 - .../tools/dotc/transform/RenameLifted.scala | 46 ------------------- .../backend/jvm/DottyBytecodeTests.scala | 6 +-- tests/run/i12759.scala | 15 ++++++ tests/run/i12759b.scala | 39 ++++++++++++++++ tests/run/i2738.check | 2 +- tests/run/i2964.check | 4 +- tests/run/i2964b.check | 4 +- tests/run/i2964c.check | 4 +- tests/run/i2964d.check | 8 ++-- tests/run/i2964e.check | 4 +- tests/run/i3000b.check | 2 +- tests/run/i3006.check | 4 +- tests/run/i3006b.check | 2 +- 14 files changed, 74 insertions(+), 67 deletions(-) delete mode 100644 compiler/src/dotty/tools/dotc/transform/RenameLifted.scala create mode 100644 tests/run/i12759.scala create mode 100644 tests/run/i12759b.scala diff --git a/compiler/src/dotty/tools/dotc/Compiler.scala b/compiler/src/dotty/tools/dotc/Compiler.scala index aeb63d9ff291..736e1b08d1e7 100644 --- a/compiler/src/dotty/tools/dotc/Compiler.scala +++ b/compiler/src/dotty/tools/dotc/Compiler.scala @@ -126,7 +126,6 @@ class Compiler { List(new DropOuterAccessors, // Drop unused outer accessors new CheckNoSuperThis, // Check that supercalls don't contain references to `this` new Flatten, // Lift all inner classes to package scope - new RenameLifted, // Renames lifted classes to local numbering scheme new TransformWildcards, // Replace wildcards with default values new MoveStatics, // Move static methods from companion to the class itself new ExpandPrivate, // Widen private definitions accessed from nested classes diff --git a/compiler/src/dotty/tools/dotc/transform/RenameLifted.scala b/compiler/src/dotty/tools/dotc/transform/RenameLifted.scala deleted file mode 100644 index 60327d59be88..000000000000 --- a/compiler/src/dotty/tools/dotc/transform/RenameLifted.scala +++ /dev/null @@ -1,46 +0,0 @@ -package dotty.tools.dotc.transform - -import dotty.tools.dotc.core.Contexts._ -import dotty.tools.dotc.core.Decorators._ -import dotty.tools.dotc.core.DenotTransformers.SymTransformer -import dotty.tools.dotc.core.Flags._ -import dotty.tools.dotc.core.NameKinds._ -import dotty.tools.dotc.core.Names._ -import dotty.tools.dotc.core.SymDenotations.SymDenotation -import dotty.tools.dotc.core.Symbols._ -import dotty.tools.dotc.transform.MegaPhase.MiniPhase - -/** Renames lifted classes to local numbering scheme */ -class RenameLifted extends MiniPhase with SymTransformer { - - override def phaseName: String = "renameLifted" - - // Not clear why this should run after restoreScopes - // override def runsAfterGroupsOf = Set(RestoreScopes.name) - - def transformSym(ref: SymDenotation)(using Context): SymDenotation = - if (needsRefresh(ref.symbol)) ref.copySymDenotation(name = refreshedName(ref.symbol)) - else ref - - /** If the name of the symbol with a unique name needs to be refreshed - * - if it is a lifted class - * - if it is a lifted method - */ - private def needsRefresh(sym: Symbol)(using Context): Boolean = - (sym.isClass || sym.isOneOf(Private | Method | JavaStatic)) && sym.name.is(UniqueName) - - /** Refreshes the number of the name based on the full name of the symbol */ - private def refreshedName(sym: Symbol)(using Context): Name = { - def rewriteUnique: PartialFunction[Name, Name] = { - case name: DerivedName if name.info.kind == UniqueName => - val fullName = (sym.owner.fullName.toString + name.underlying).toTermName - val freshName = UniqueName.fresh(fullName) - val info = freshName.asInstanceOf[DerivedName].info - DerivedName(name.underlying.replace(rewriteUnique), info) - case DerivedName(underlying, info: QualifiedInfo) => - underlying.replace(rewriteUnique).derived(info) - } - - sym.name.replace(rewriteUnique) - } -} diff --git a/compiler/test/dotty/tools/backend/jvm/DottyBytecodeTests.scala b/compiler/test/dotty/tools/backend/jvm/DottyBytecodeTests.scala index 2b1b5b57b1fa..0fa91c3b6879 100644 --- a/compiler/test/dotty/tools/backend/jvm/DottyBytecodeTests.scala +++ b/compiler/test/dotty/tools/backend/jvm/DottyBytecodeTests.scala @@ -699,7 +699,7 @@ class TestBCode extends DottyBytecodeTest { """.stripMargin) @Test def objectsInObjDefAreFinal = - checkFinalClass("Test$Foo$1$.class", + checkFinalClass("Test$Foo$2$.class", """ |object Test { | def bar() = { @@ -709,7 +709,7 @@ class TestBCode extends DottyBytecodeTest { """.stripMargin) @Test def objectsInClassDefAreFinal = - checkFinalClass("Test$Foo$1$.class", + checkFinalClass("Test$Foo$2$.class", """ |class Test { | def bar() = { @@ -719,7 +719,7 @@ class TestBCode extends DottyBytecodeTest { """.stripMargin) @Test def objectsInObjValAreFinal = - checkFinalClass("Test$Foo$1$.class", + checkFinalClass("Test$Foo$2$.class", """ |class Test { | val bar = { diff --git a/tests/run/i12759.scala b/tests/run/i12759.scala new file mode 100644 index 000000000000..2c5fcded46ac --- /dev/null +++ b/tests/run/i12759.scala @@ -0,0 +1,15 @@ +package example { + + trait Foo { + val (a2, a3) = ("", "") + val (x1, x2, x3) = ("", "", "") + } + + class A extends Foo +} + +object Test { + def main(args: Array[String]): Unit = { + new example.A + } +} diff --git a/tests/run/i12759b.scala b/tests/run/i12759b.scala new file mode 100644 index 000000000000..c7480575f86b --- /dev/null +++ b/tests/run/i12759b.scala @@ -0,0 +1,39 @@ +package example { + + class A1 + class A2 + class A3 + + class TypeClass[A](val value: A) + + object TypeClass { + def apply[A](implicit a: TypeClass[A]): TypeClass[A] = a + + def get2[X1: TypeClass, X2: TypeClass]: (X1, X2) = { + (TypeClass[X1].value, TypeClass[X2].value) + } + + def get3[X1: TypeClass, X2: TypeClass, X3: TypeClass]: (X1, X2, X3) = { + (TypeClass[X1].value, TypeClass[X2].value, TypeClass[X3].value) + } + + implicit def a1: TypeClass[A1] = new TypeClass[A1](new A1) + implicit def a2: TypeClass[A2] = new TypeClass[A2](new A2) + implicit def a3: TypeClass[A3] = new TypeClass[A3](new A3) + } + + trait Foo { + + val (a2, a3) = TypeClass.get2[A2, A3] + + val (x1, x2, x3) = TypeClass.get3[A1, A2, A3] + + } + +} + +object Test { + def main(args: Array[String]): Unit = { + new example.Foo {} + } +} \ No newline at end of file diff --git a/tests/run/i2738.check b/tests/run/i2738.check index b54b3d840cf0..5954c1afefc9 100644 --- a/tests/run/i2738.check +++ b/tests/run/i2738.check @@ -1,4 +1,4 @@ -Test$qux$1$ Test$qux$2$ +Test$qux$4$ bar$1 bar$2 diff --git a/tests/run/i2964.check b/tests/run/i2964.check index 748b2a47faf1..ac42be082812 100644 --- a/tests/run/i2964.check +++ b/tests/run/i2964.check @@ -1,4 +1,4 @@ class Foo$$anon$1 -class Bar$$anon$1 class Bar$$anon$2 -class Baz$$anon$1 +class Bar$$anon$3 +class Baz$$anon$4 diff --git a/tests/run/i2964b.check b/tests/run/i2964b.check index 748b2a47faf1..ac42be082812 100644 --- a/tests/run/i2964b.check +++ b/tests/run/i2964b.check @@ -1,4 +1,4 @@ class Foo$$anon$1 -class Bar$$anon$1 class Bar$$anon$2 -class Baz$$anon$1 +class Bar$$anon$3 +class Baz$$anon$4 diff --git a/tests/run/i2964c.check b/tests/run/i2964c.check index f7cc0f12df69..729b24dcb9f3 100644 --- a/tests/run/i2964c.check +++ b/tests/run/i2964c.check @@ -1,4 +1,4 @@ class Foo$Inner$1 -class Bar$Inner$1 class Bar$Inner$2 -class Baz$Inner$1 +class Bar$Inner$3 +class Baz$Inner$4 diff --git a/tests/run/i2964d.check b/tests/run/i2964d.check index f1a0e8bb51c4..32a719a2630c 100644 --- a/tests/run/i2964d.check +++ b/tests/run/i2964d.check @@ -1,4 +1,4 @@ -class Foo$Inner$1$ -class Bar$Inner$1$ -class Bar$Inner$2$ -class Baz$Inner$1$ +class Foo$Inner$2$ +class Bar$Inner$4$ +class Bar$Inner$6$ +class Baz$Inner$8$ diff --git a/tests/run/i2964e.check b/tests/run/i2964e.check index a42348b97b00..ccffda6bc06b 100644 --- a/tests/run/i2964e.check +++ b/tests/run/i2964e.check @@ -1,4 +1,4 @@ class foo.bar.Foo$$anon$1 class foo.bar.Foo$$anon$2 -class foo.Foo$$anon$1 -class Foo$$anon$1 +class foo.Foo$$anon$3 +class Foo$$anon$4 diff --git a/tests/run/i3000b.check b/tests/run/i3000b.check index c5980c545f33..605021c9b2c0 100644 --- a/tests/run/i3000b.check +++ b/tests/run/i3000b.check @@ -1,2 +1,2 @@ Foo$$anon$1 -bar.Bar$$anon$1 +bar.Bar$$anon$2 diff --git a/tests/run/i3006.check b/tests/run/i3006.check index 8f4e653138b7..a2d3b474408c 100644 --- a/tests/run/i3006.check +++ b/tests/run/i3006.check @@ -1,5 +1,5 @@ f$1 f$2 f$3 -f$1 -f$2 +f$4 +f$5 diff --git a/tests/run/i3006b.check b/tests/run/i3006b.check index 3698829ef115..ec64184dc80c 100644 --- a/tests/run/i3006b.check +++ b/tests/run/i3006b.check @@ -1,3 +1,3 @@ bar$1 bar$2 -bar$1 +bar$3