Skip to content

Commit 10d722c

Browse files
committed
Partial revert of Optimize typeParams
(reverted from commit a1ce848) It turns out the previous typeParams is already fully optimized, no need to add a local function. We just keep the change to how typeParams are cached in type lambdas (fixing an accidental lazy val to a def).
1 parent 302c092 commit 10d722c

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import util.Positions.Position
1818
import config.Printers.{core, typr}
1919
import collection.mutable
2020
import dotty.tools.dotc.config.Config
21-
import annotation.tailrec
2221
import java.util.NoSuchElementException
2322

2423
object TypeApplications {
@@ -169,32 +168,31 @@ class TypeApplications(val self: Type) extends AnyVal {
169168
* any type parameter that is-rebound by the refinement.
170169
*/
171170
final def typeParams(implicit ctx: Context): List[TypeParamInfo] = /*>|>*/ track("typeParams") /*<|<*/ {
172-
@tailrec def recur(tp: Type): List[TypeParamInfo] = tp match {
171+
self match {
173172
case self: TypeRef =>
174173
val tsym = self.symbol
175174
if (tsym.isClass) tsym.typeParams
176-
else if (!tsym.exists) recur(self.info)
175+
else if (!tsym.exists) self.info.typeParams
177176
else tsym.infoOrCompleter match {
178177
case info: LazyType => info.completerTypeParams(tsym)
179-
case info => recur(info)
178+
case info => info.typeParams
180179
}
181180
case self: AppliedType =>
182181
if (self.tycon.typeSymbol.isClass) Nil
183-
else recur(self.superType)
182+
else self.superType.typeParams
184183
case self: ClassInfo =>
185184
self.cls.typeParams
186185
case self: HKTypeLambda =>
187186
self.typeParams
188187
case _: SingletonType | _: RefinedType | _: RecType =>
189188
Nil
190189
case self: WildcardType =>
191-
recur(self.optBounds)
190+
self.optBounds.typeParams
192191
case self: TypeProxy =>
193-
recur(self.superType)
192+
self.superType.typeParams
194193
case _ =>
195194
Nil
196195
}
197-
recur(self)
198196
}
199197

200198
/** If `self` is a higher-kinded type, its type parameters, otherwise Nil */

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3007,9 +3007,9 @@ object Types {
30073007

30083008
def newParamRef(n: Int) = new TypeParamRef(this, n) {}
30093009

3010-
private var myTypeParams: List[LambdaParam] = null
3010+
private[this] var myTypeParams: List[LambdaParam] = null
30113011

3012-
lazy val typeParams: List[LambdaParam] = {
3012+
def typeParams: List[LambdaParam] = {
30133013
if (myTypeParams == null)
30143014
myTypeParams = paramNames.indices.toList.map(new LambdaParam(this, _))
30153015
myTypeParams

0 commit comments

Comments
 (0)