Skip to content

Commit

Permalink
Don't force info to get signature in TreeChecker
Browse files Browse the repository at this point in the history
When we are reading a new definition from tasty and setting `info` of
a symbol in `readNewDef`:

          sym.info = methodType(paramss, resType)

The line above will reach `TreeChecker.transformSym`:

          assert(symd.signature == initial.signature

At the time, the `symd` is not yet completed. Getting signature of the
denotation will force the symbol and trigger completion of the info,
which reaches the `PositionTree` in `readIndexedDef.
  • Loading branch information
liufengyun committed May 31, 2021
1 parent c54faa0 commit 83d1883
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
15 changes: 7 additions & 8 deletions compiler/src/dotty/tools/dotc/core/NamerOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ import ast.untpd
/** Operations that are shared between Namer and TreeUnpickler */
object NamerOps:

/** The given type, unless `sym` is a constructor, in which case the
* type of the constructed instance is returned
/** The type of the constructed instance is returned
*
* @param ctor the constructor
*/
def effectiveResultType(sym: Symbol, paramss: List[List[Symbol]], givenTp: Type)(using Context): Type =
if sym.name == nme.CONSTRUCTOR then
paramss match
case TypeSymbols(tparams) :: _ => sym.owner.typeRef.appliedTo(tparams.map(_.typeRef))
case _ => sym.owner.typeRef
else givenTp
def effectiveResultType(ctor: Symbol, paramss: List[List[Symbol]])(using Context): Type =
paramss match
case TypeSymbols(tparams) :: _ => ctor.owner.typeRef.appliedTo(tparams.map(_.typeRef))
case _ => ctor.owner.typeRef

/** if isConstructor, make sure it has one leading non-implicit parameter list */
def normalizeIfConstructor(paramss: List[List[Symbol]], isConstructor: Boolean)(using Context): List[List[Symbol]] =
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ class TreePickler(pickler: TastyPickler) {

def pickleDef(tag: Int, mdef: MemberDef, tpt: Tree, rhs: Tree = EmptyTree, pickleParams: => Unit = ())(using Context): Unit = {
val sym = mdef.symbol

assert(symRefs(sym) == NoAddr, sym)
registerDef(sym)
writeByte(tag)
Expand Down
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,11 @@ class TreeUnpickler(reader: TastyReader,
val tpt = readTpt()(using localCtx)
val paramss = normalizeIfConstructor(
paramDefss.nestedMap(_.symbol), name == nme.CONSTRUCTOR)
val resType = effectiveResultType(sym, paramss, tpt.tpe)
val resType =
if name == nme.CONSTRUCTOR then
effectiveResultType(sym, paramss)
else
tpt.tpe
sym.info = methodType(paramss, resType)
DefDef(paramDefss, tpt)
case VALDEF =>
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/TreeChecker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class TreeChecker extends Phase with SymTransformer {
// until erasure, see the comment above `Compiler#phases`.
if (ctx.phaseId <= erasurePhase.id) {
val initial = symd.initial
assert(symd.signature == initial.signature,
assert(symd == initial || symd.signature == initial.signature,
i"""Signature of ${sym.showLocated} changed at phase ${ctx.base.fusedContaining(ctx.phase.prev)}
|Initial info: ${initial.info}
|Initial sig : ${initial.signature}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,7 @@ class Semantic {

// follow constructor
if cls.hasSource then
printer.println("init super class " + cls.show)
val res2 = thisV.call(ctor, superType = NoType, source)(using heap, ctx, trace.add(source))
errorBuffer ++= res2.errors

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1680,7 +1680,7 @@ class Namer { typer: Typer =>
if (isConstructor) {
// set result type tree to unit, but take the current class as result type of the symbol
typedAheadType(ddef.tpt, defn.UnitType)
wrapMethType(effectiveResultType(sym, paramSymss, NoType))
wrapMethType(effectiveResultType(sym, paramSymss))
}
else valOrDefDefSig(ddef, sym, paramSymss, wrapMethType)
}
Expand Down

0 comments on commit 83d1883

Please sign in to comment.