Skip to content

Avoid cycles when unpickling the stdlib from TASTY #5901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ class ClassfileParser(
classRoot.registerCompanion(moduleRoot.symbol)
moduleRoot.registerCompanion(classRoot.symbol)

setClassInfo(classRoot, classInfo)
setClassInfo(moduleRoot, staticInfo)
setClassInfo(classRoot, classInfo, fromScala2 = false)
setClassInfo(moduleRoot, staticInfo, fromScala2 = false)
} else if (result == Some(NoEmbedded)) {
for (sym <- List(moduleRoot.sourceModule, moduleRoot.symbol, classRoot.symbol)) {
classRoot.owner.asClass.delete(sym)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ class TreeUnpickler(reader: TastyReader,
case _ => readTpt()(parentCtx)
}
}
val parentTypes = defn.adjustForTuple(cls, cls.typeParams, parents.map(_.tpe.dealias))
val parentTypes = parents.map(_.tpe.dealias)
val self =
if (nextByte == SELFDEF) {
readByte()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ object Scala2Unpickler {
cls.enter(constr, scope)
}

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