Skip to content

Commit 1a3aeb1

Browse files
committed
Resume suspensions also when reading from classfiles
Make treatment in Scala2Unpickler and Namer the same and factor out common functionality.
1 parent c37185d commit 1a3aeb1

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

src/dotty/tools/dotc/core/TypeOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
374374
if (argSym is BaseTypeArg)
375375
forwardRef(argSym, from, to, cls, decls)
376376
pref.info match {
377-
case info: TempClassInfo => info.suspensions = (() => forward()) :: info.suspensions // !!! dotty deviation `forward` alone does not eta expand
377+
case info: TempClassInfo => info.addSuspension(forward)
378378
case _ => forward()
379379
}
380380
}

src/dotty/tools/dotc/core/Types.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3049,12 +3049,20 @@ object Types {
30493049
/** A class for temporary class infos where `parents` are not yet known. */
30503050
final class TempClassInfo(prefix: Type, cls: ClassSymbol, decls: Scope, selfInfo: DotClass)
30513051
extends CachedClassInfo(prefix, cls, Nil, decls, selfInfo) {
3052-
3052+
30533053
/** A list of actions that were because they rely on the class info of `cls` to
30543054
* be no longer temporary. These actions will be performed once `cls` gets a real
30553055
* ClassInfo.
30563056
*/
3057-
var suspensions: List[() => Unit] = Nil
3057+
private var suspensions: List[() => Unit] = Nil
3058+
3059+
def addSuspension(suspension: () => Unit): Unit = suspensions ::= suspension
3060+
3061+
/** Install classinfo with known parents in `denot` and resume all suspensions */
3062+
def finalize(denot: SymDenotation, parents: List[TypeRef])(implicit ctx: Context) = {
3063+
denot.info = derivedClassInfo(classParents = parents)
3064+
suspensions.foreach(_())
3065+
}
30583066
}
30593067

30603068
object ClassInfo {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ object Scala2Unpickler {
106106
// `denot.sourceModule.exists` provision i859.scala crashes in the backend.
107107
denot.owner.thisType select denot.sourceModule
108108
else selfInfo
109-
denot.info = new TempClassInfo(denot.owner.thisType, denot.classSymbol, decls, ost) // first rough info to avoid CyclicReferences
109+
val tempInfo = new TempClassInfo(denot.owner.thisType, denot.classSymbol, decls, ost)
110+
denot.info = tempInfo // first rough info to avoid CyclicReferences
110111
var parentRefs = ctx.normalizeToClassRefs(parents, cls, decls)
111112
if (parentRefs.isEmpty) parentRefs = defn.ObjectType :: Nil
112113
for (tparam <- tparams) {
@@ -132,8 +133,7 @@ object Scala2Unpickler {
132133
registerCompanionPair(scalacCompanion, denot.classSymbol)
133134
}
134135

135-
denot.info = ClassInfo( // final info, except possibly for typeparams ordering
136-
denot.owner.thisType, denot.classSymbol, parentRefs, decls, ost)
136+
tempInfo.finalize(denot, parentRefs) // install final info, except possibly for typeparams ordering
137137
denot.ensureTypeParamsInCorrectOrder()
138138
}
139139
}

src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,8 @@ class Namer { typer: Typer =>
688688
else createSymbol(self)
689689

690690
// pre-set info, so that parent types can refer to type params
691-
val tempClassInfo = new TempClassInfo(cls.owner.thisType, cls, decls, selfInfo)
692-
denot.info = tempClassInfo
691+
val tempInfo = new TempClassInfo(cls.owner.thisType, cls, decls, selfInfo)
692+
denot.info = tempInfo
693693

694694
// Ensure constructor is completed so that any parameter accessors
695695
// which have type trees deriving from its parameters can be
@@ -705,8 +705,7 @@ class Namer { typer: Typer =>
705705
typr.println(s"completing $denot, parents = $parents, parentTypes = $parentTypes, parentRefs = $parentRefs")
706706

707707
index(rest)(inClassContext(selfInfo))
708-
denot.info = ClassInfo(cls.owner.thisType, cls, parentRefs, decls, selfInfo)
709-
tempClassInfo.suspensions.foreach(_())
708+
tempInfo.finalize(denot, parentRefs)
710709

711710
Checking.checkWellFormed(cls)
712711
if (isDerivedValueClass(cls)) cls.setFlag(Final)

0 commit comments

Comments
 (0)