From eeb314f2aa9e22002e0d8e3e22ec4434a3996898 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Mon, 28 Jan 2019 02:23:01 +0100 Subject: [PATCH 1/2] TreeUnpickler: avoid forcing annotations early This sometimes lead to cycles when compiling the 2.13 stdlib and shouldn't be necessary anymore (all the tests pass). --- .../src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala | 7 ------- 1 file changed, 7 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index 65b9a2fe55ce..1f7a1632fbb4 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -839,13 +839,6 @@ class TreeUnpickler(reader: TastyReader, DefDef(Nil, Nil, tpt) } } - val mods = - if (sym.annotations.isEmpty) untpd.EmptyModifiers - else untpd.Modifiers(annotations = sym.annotations.map(_.tree)) - tree.withMods(mods) - // record annotations in tree so that tree positions can be filled in. - // Note: Once the inline PR with its changes to positions is in, this should be - // no longer necessary. goto(end) setSpan(start, tree) if (!sym.isType) { // Only terms might have leaky aliases, see the documentation of `checkNoPrivateLeaks` From f858b8431e781e5a6093f3a705ef7b3b8a226943 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Mon, 28 Jan 2019 12:58:14 +0100 Subject: [PATCH 2/2] Fix compiling with the 2.13 collections - Always rely on -Ynew-collections to change our behavior, attempting to automatically detect which version we're on leads to cycles. - In the new collections, the scala.Serializable class has been replaced by a type alias of java.io.Serializable - The `<:<` class was moved from the Predef object to the scala package. --- .../dotty/tools/dotc/core/Definitions.scala | 18 ++++++++++++------ .../src/dotty/tools/dotc/typer/Implicits.scala | 4 +++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index c215f382bcbe..710ecb7fd219 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -347,9 +347,6 @@ class Definitions { lazy val ScalaPredefModuleRef: TermRef = ctx.requiredModuleRef("scala.Predef") def ScalaPredefModule(implicit ctx: Context): Symbol = ScalaPredefModuleRef.symbol - - lazy val Predef_ConformsR: TypeRef = ScalaPredefModule.requiredClass("<:<").typeRef - def Predef_Conforms(implicit ctx: Context): Symbol = Predef_ConformsR.symbol lazy val Predef_conformsR: TermRef = ScalaPredefModule.requiredMethodRef(nme.conforms_) def Predef_conforms(implicit ctx: Context): Symbol = Predef_conformsR.symbol lazy val Predef_classOfR: TermRef = ScalaPredefModule.requiredMethodRef(nme.classOf) @@ -357,6 +354,12 @@ class Definitions { lazy val Predef_undefinedR: TermRef = ScalaPredefModule.requiredMethodRef(nme.???) def Predef_undefined(implicit ctx: Context): Symbol = Predef_undefinedR.symbol + def SubTypeClass(implicit ctx: Context): Symbol = + if (isNewCollections) + ctx.requiredClass("scala.<:<") + else + ScalaPredefModule.requiredClass("<:<") + lazy val ScalaRuntimeModuleRef: TermRef = ctx.requiredModuleRef("scala.runtime.ScalaRunTime") def ScalaRuntimeModule(implicit ctx: Context): Symbol = ScalaRuntimeModuleRef.symbol def ScalaRuntimeClass(implicit ctx: Context): ClassSymbol = ScalaRuntimeModule.moduleClass.asClass @@ -397,8 +400,7 @@ class Definitions { def newArrayMethod(implicit ctx: Context): TermSymbol = DottyArraysModule.requiredMethod("newArray") // TODO: Remove once we drop support for 2.12 standard library - lazy val isNewCollections: Boolean = ctx.settings.YnewCollections.value || - ctx.base.staticRef("scala.collection.IterableOnce".toTypeName).exists + lazy val isNewCollections: Boolean = ctx.settings.YnewCollections.value def getWrapVarargsArrayModule: Symbol = if (isNewCollections) ScalaRuntimeModule else ScalaPredefModule @@ -585,7 +587,11 @@ class Definitions { lazy val ThrowableType: TypeRef = ctx.requiredClassRef("java.lang.Throwable") def ThrowableClass(implicit ctx: Context): ClassSymbol = ThrowableType.symbol.asClass - lazy val SerializableType: TypeRef = ctx.requiredClassRef("scala.Serializable") + lazy val SerializableType: TypeRef = + if (isNewCollections) + JavaSerializableClass.typeRef + else + ctx.requiredClassRef("scala.Serializable") def SerializableClass(implicit ctx: Context): ClassSymbol = SerializableType.symbol.asClass lazy val StringBuilderType: TypeRef = ctx.requiredClassRef("scala.collection.mutable.StringBuilder") def StringBuilderClass(implicit ctx: Context): ClassSymbol = StringBuilderType.symbol.asClass diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index 6bb41b258f91..72817e23ce26 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -140,7 +140,9 @@ object Implicits { ctx.scala2Mode && tpw.derivesFrom(defn.FunctionClass(1)) && ref.symbol != defn.Predef_conforms val isImplicitConverter = tpw.derivesFrom(defn.Predef_ImplicitConverter) val isConforms = // An implementation of <:< counts as a view, except that $conforms is always omitted - tpw.derivesFrom(defn.Predef_Conforms) && ref.symbol != defn.Predef_conforms + tpw.derivesFrom(defn.SubTypeClass) && + (defn.isNewCollections || // In 2.13, the type of `$conforms` changed from `A <:< A` to `A => A` + ref.symbol != defn.Predef_conforms) val hasExtensions = resType match { case SelectionProto(name, _, _, _) => tpw.memberBasedOnFlags(name, required = ExtensionMethod).exists