Skip to content

Commit 51853d6

Browse files
authored
Merge pull request #5901 from dotty-staging/stdlib-tasty
Avoid cycles when unpickling the stdlib from TASTY
2 parents eff7014 + 2c25b88 commit 51853d6

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ class ClassfileParser(
171171
classRoot.registerCompanion(moduleRoot.symbol)
172172
moduleRoot.registerCompanion(classRoot.symbol)
173173

174-
setClassInfo(classRoot, classInfo)
175-
setClassInfo(moduleRoot, staticInfo)
174+
setClassInfo(classRoot, classInfo, fromScala2 = false)
175+
setClassInfo(moduleRoot, staticInfo, fromScala2 = false)
176176
} else if (result == Some(NoEmbedded)) {
177177
for (sym <- List(moduleRoot.sourceModule, moduleRoot.symbol, classRoot.symbol)) {
178178
classRoot.owner.asClass.delete(sym)

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ class TreeUnpickler(reader: TastyReader,
893893
case _ => readTpt()(parentCtx)
894894
}
895895
}
896-
val parentTypes = defn.adjustForTuple(cls, cls.typeParams, parents.map(_.tpe.dealias))
896+
val parentTypes = parents.map(_.tpe.dealias)
897897
val self =
898898
if (nextByte == SELFDEF) {
899899
readByte()

compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ object Scala2Unpickler {
9191
cls.enter(constr, scope)
9292
}
9393

94-
def setClassInfo(denot: ClassDenotation, info: Type, selfInfo: Type = NoType)(implicit ctx: Context): Unit = {
94+
def setClassInfo(denot: ClassDenotation, info: Type, fromScala2: Boolean, selfInfo: Type = NoType)(implicit ctx: Context): Unit = {
9595
val cls = denot.classSymbol
9696
val (tparams, TempClassInfoType(parents, decls, clazz)) = info match {
9797
case TempPolyType(tps, cinfo) => (tps, cinfo)
@@ -106,9 +106,11 @@ object Scala2Unpickler {
106106
else selfInfo
107107
val tempInfo = new TempClassInfo(denot.owner.thisType, cls, decls, ost)
108108
denot.info = tempInfo // first rough info to avoid CyclicReferences
109+
val parents1 = if (parents.isEmpty) defn.ObjectType :: Nil else parents.map(_.dealias)
110+
// Add extra parents to the tuple classes from the standard library
109111
val normalizedParents =
110-
defn.adjustForTuple(cls, tparams,
111-
if (parents.isEmpty) defn.ObjectType :: Nil else parents.map(_.dealias))
112+
if (fromScala2) defn.adjustForTuple(cls, tparams, parents1)
113+
else parents1 // We are setting the info of a Java class, so it cannot be one of the tuple classes
112114
for (tparam <- tparams) {
113115
val tsym = decls.lookup(tparam.name)
114116
if (tsym.exists) tsym.setFlag(TypeParam)
@@ -553,7 +555,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
553555
denot match {
554556
case denot: ClassDenotation =>
555557
val selfInfo = if (atEnd) NoType else readTypeRef()
556-
setClassInfo(denot, tp, selfInfo)
558+
setClassInfo(denot, tp, fromScala2 = true, selfInfo)
557559
case denot =>
558560
val tp1 = translateTempPoly(tp)
559561
denot.info =

0 commit comments

Comments
 (0)