From cf1c1684ed07b27e1f6f0f1678f0de7120fb7761 Mon Sep 17 00:00:00 2001 From: Anatolii Date: Fri, 26 Jul 2019 16:22:43 +0200 Subject: [PATCH 1/2] Close lampepfl/dotty-knowledge#10: Remove dead code --- compiler/src/dotty/tools/dotc/core/Annotations.scala | 4 ---- 1 file changed, 4 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/Annotations.scala b/compiler/src/dotty/tools/dotc/core/Annotations.scala index 528852c02817..5943ad2c91bc 100644 --- a/compiler/src/dotty/tools/dotc/core/Annotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Annotations.scala @@ -120,10 +120,6 @@ object Annotations { tpd.applyOverloaded(New(atp.typeConstructor), nme.CONSTRUCTOR, args, targs, atp) } - def applyResolve(atp: Type, args: List[Tree])(implicit ctx: Context): Annotation = { - apply(resolveConstructor(atp, args)) - } - /** Create an annotation where the tree is computed lazily. */ def deferred(sym: Symbol)(treeFn: given Context => Tree)(implicit ctx: Context): Annotation = new LazyAnnotation { From b7a433cf88dda0e3bd58621ad47ac9b284151411 Mon Sep 17 00:00:00 2001 From: Anatolii Date: Fri, 26 Jul 2019 16:26:58 +0200 Subject: [PATCH 2/2] Close lampepfl/dotty-knowledge#11: Share code from Annotations --- .../src/dotty/tools/backend/sjs/JUnitBootstrappers.scala | 9 ++------- compiler/src/dotty/tools/dotc/ast/tpd.scala | 5 +++++ compiler/src/dotty/tools/dotc/core/Annotations.scala | 5 ----- .../tools/dotc/core/unpickleScala2/Scala2Unpickler.scala | 7 ++----- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/compiler/src/dotty/tools/backend/sjs/JUnitBootstrappers.scala b/compiler/src/dotty/tools/backend/sjs/JUnitBootstrappers.scala index d1a3139a3067..ef69b5e2f9d5 100644 --- a/compiler/src/dotty/tools/backend/sjs/JUnitBootstrappers.scala +++ b/compiler/src/dotty/tools/backend/sjs/JUnitBootstrappers.scala @@ -229,8 +229,7 @@ class JUnitBootstrappers extends MiniPhase { val testAnnot = test.getAnnotation(junitdefn.TestAnnotClass).get if (testAnnot.arguments.nonEmpty) ctx.error("@Test annotations with arguments are not yet supported in Scala.js for dotty", testAnnot.tree.sourcePos) - val noArgConstr = junitdefn.TestAnnotType.member(nme.CONSTRUCTOR).suchThat(_.info.paramInfoss.head.isEmpty).symbol.asTerm - val reifiedAnnot = New(junitdefn.TestAnnotType, noArgConstr, Nil) + val reifiedAnnot = resolveConstructor(junitdefn.TestAnnotType, Nil) New(junitdefn.TestMetadataType, List(name, ignored, reifiedAnnot)) } JavaSeqLiteral(metadata, TypeTree(junitdefn.TestMetadataType)) @@ -250,11 +249,7 @@ class JUnitBootstrappers extends MiniPhase { ValDef(castInstanceSym, instanceParamRef.cast(testClass.typeRef)) :: Nil, tests.foldRight[Tree] { val tp = junitdefn.NoSuchMethodExceptionType - val constr = tp.member(nme.CONSTRUCTOR).suchThat { c => - c.info.paramInfoss.head.size == 1 && - c.info.paramInfoss.head.head.isRef(defn.StringClass) - }.symbol.asTerm - Throw(New(tp, constr, nameParamRef :: Nil)) + Throw(resolveConstructor(tp, nameParamRef :: Nil)) } { (test, next) => If(Literal(Constant(test.name.toString)).select(defn.Any_equals).appliedTo(nameParamRef), genTestInvocation(testClass, test, ref(castInstanceSym)), diff --git a/compiler/src/dotty/tools/dotc/ast/tpd.scala b/compiler/src/dotty/tools/dotc/ast/tpd.scala index f9ad72454038..5338b9e356dd 100644 --- a/compiler/src/dotty/tools/dotc/ast/tpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/tpd.scala @@ -1362,5 +1362,10 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { } transformer.transform(tree) } + + def resolveConstructor(atp: Type, args:List[Tree])(implicit ctx: Context): Tree = { + val targs = atp.argTypes + tpd.applyOverloaded(New(atp.typeConstructor), nme.CONSTRUCTOR, args, targs, atp) + } } diff --git a/compiler/src/dotty/tools/dotc/core/Annotations.scala b/compiler/src/dotty/tools/dotc/core/Annotations.scala index 5943ad2c91bc..cc90e3bae56c 100644 --- a/compiler/src/dotty/tools/dotc/core/Annotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Annotations.scala @@ -115,11 +115,6 @@ object Annotations { def apply(atp: Type, args: List[Tree])(implicit ctx: Context): Annotation = apply(New(atp, args)) - private def resolveConstructor(atp: Type, args:List[Tree])(implicit ctx: Context): Tree = { - val targs = atp.argTypes - tpd.applyOverloaded(New(atp.typeConstructor), nme.CONSTRUCTOR, args, targs, atp) - } - /** Create an annotation where the tree is computed lazily. */ def deferred(sym: Symbol)(treeFn: given Context => Tree)(implicit ctx: Context): Annotation = new LazyAnnotation { diff --git a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index 34f01c86865f..b032b6f45593 100644 --- a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -934,11 +934,8 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas } t.toList } - // println(atp) - val targs = atp.argTypes - - tpd.applyOverloaded(tpd.New(atp.typeConstructor), nme.CONSTRUCTOR, args, targs, atp) -} + resolveConstructor(atp, args) + } /** Read an annotation and as a side effect store it into * the symbol it requests. Called at top-level, for all