Skip to content

Commit 9b7c639

Browse files
committed
Make Namer completers complete type params without doing a full completion
1 parent 9a3dbf9 commit 9b7c639

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,6 +1782,9 @@ object SymDenotations {
17821782
def apply(sym: Symbol) = this
17831783
def apply(module: TermSymbol, modcls: ClassSymbol) = this
17841784

1785+
/** The type parameters computed by the completer before completion has finished */
1786+
def completerTypeParams(sym: Symbol)(implicit ctx: Context): List[TypeSymbol] = Nil
1787+
17851788
private var myDecls: Scope = EmptyScope
17861789
private var mySourceModuleFn: Context => Symbol = NoSymbolFn
17871790
private var myModuleClassFn: Context => Symbol = NoSymbolFn

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,13 @@ class TypeApplications(val self: Type) extends AnyVal {
240240
case self: TypeRef =>
241241
val tsym = self.symbol
242242
if (tsym.isClass) tsym.typeParams
243-
else if (tsym.isAliasType) self.underlying.typeParams
244-
else if (tsym.isCompleting)
243+
//else if (tsym.isAliasType) self.underlying.typeParams
244+
else if (tsym.isCompleting) tsym.completer.completerTypeParams(tsym)
245245
// We are facing a problem when computing the type parameters of an uncompleted
246246
// abstract type. We can't access the bounds of the symbol yet because that
247247
// would cause a cause a cyclic reference. So we return `Nil` instead
248248
// and try to make up for it later. The acrobatics in Scala2Unpicker#readType
249249
// for reading a TypeRef show what's neeed.
250-
Nil
251250
else tsym.info.typeParams
252251
case self: RefinedType =>
253252
// inlined and optimized version of

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
3535
* Instead we produce an annotated type that marks the prefix as unsafe:
3636
*
3737
* (x: (C @ UnsafeNonvariant)#T)C#T
38-
38+
3939
* We also set a global state flag `unsafeNonvariant` to the current run.
4040
* When typing a Select node, typer will check that flag, and if it
4141
* points to the current run will scan the result type of the select for

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,27 @@ class Namer { typer: Typer =>
482482

483483
protected def localContext(owner: Symbol) = ctx.fresh.setOwner(owner).setTree(original)
484484

485+
private var myTypeParams: List[TypeSymbol] = null
486+
private var nestedCtx: Context = null
487+
488+
override def completerTypeParams(sym: Symbol)(implicit ctx: Context): List[TypeSymbol] = {
489+
if (myTypeParams == null) {
490+
//println(i"completing type params of $sym in ${sym.owner}")
491+
myTypeParams = original match {
492+
case tdef: TypeDef =>
493+
nestedCtx = localContext(sym).setNewScope
494+
locally {
495+
implicit val ctx: Context = nestedCtx
496+
completeParams(tdef.tparams)
497+
tdef.tparams.map(symbolOfTree(_).asType)
498+
}
499+
case _ =>
500+
Nil
501+
}
502+
}
503+
myTypeParams
504+
}
505+
485506
private def typeSig(sym: Symbol): Type = original match {
486507
case original: ValDef =>
487508
if (sym is Module) moduleValSig(sym)
@@ -492,7 +513,7 @@ class Namer { typer: Typer =>
492513
typer1.defDefSig(original, sym)(localContext(sym).setTyper(typer1))
493514
case original: TypeDef =>
494515
assert(!original.isClassDef)
495-
typeDefSig(original, sym)(localContext(sym).setNewScope)
516+
typeDefSig(original, sym, completerTypeParams(sym))(nestedCtx)
496517
case imp: Import =>
497518
try {
498519
val expr1 = typedAheadExpr(imp.expr, AnySelectionProto)
@@ -840,9 +861,7 @@ class Namer { typer: Typer =>
840861
else valOrDefDefSig(ddef, sym, typeParams, paramSymss, wrapMethType)
841862
}
842863

843-
def typeDefSig(tdef: TypeDef, sym: Symbol)(implicit ctx: Context): Type = {
844-
completeParams(tdef.tparams)
845-
val tparamSyms = tdef.tparams map symbolOfTree
864+
def typeDefSig(tdef: TypeDef, sym: Symbol, tparamSyms: List[TypeSymbol])(implicit ctx: Context): Type = {
846865
val isDerived = tdef.rhs.isInstanceOf[untpd.DerivedTypeTree]
847866
//val toParameterize = tparamSyms.nonEmpty && !isDerived
848867
//val needsLambda = sym.allOverriddenSymbols.exists(_ is HigherKinded) && !isDerived

0 commit comments

Comments
 (0)