Skip to content

Commit d94a62b

Browse files
committed
Cache isType in SymDenotations
1 parent b5a923c commit d94a62b

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ object Denotations {
175175
*
176176
* @param symbol The referencing symbol, or NoSymbol is none exists
177177
*/
178-
abstract class Denotation(val symbol: Symbol, protected var myInfo: Type) extends PreDenotation with printing.Showable {
178+
abstract class Denotation(val symbol: Symbol, protected var myInfo: Type, val isType: Boolean) extends PreDenotation with printing.Showable {
179179
type AsSeenFromResult <: Denotation
180180

181181
/** The type info.
@@ -194,9 +194,6 @@ object Denotations {
194194
*/
195195
def infoOrCompleter: Type
196196

197-
/** Is this a reference to a type symbol? */
198-
def isType: Boolean
199-
200197
/** Is this a reference to a term symbol? */
201198
def isTerm: Boolean = !isType
202199

@@ -577,7 +574,7 @@ object Denotations {
577574
end infoMeet
578575

579576
/** A non-overloaded denotation */
580-
abstract class SingleDenotation(symbol: Symbol, initInfo: Type) extends Denotation(symbol, initInfo) {
577+
abstract class SingleDenotation(symbol: Symbol, initInfo: Type, isType: Boolean) extends Denotation(symbol, initInfo, isType) {
581578
protected def newLikeThis(symbol: Symbol, info: Type, pre: Type, isRefinedMethod: Boolean): SingleDenotation
582579

583580
final def name(using Context): Name = symbol.name
@@ -1150,9 +1147,9 @@ object Denotations {
11501147
acc(false, symbol.info)
11511148
}
11521149

1153-
abstract class NonSymSingleDenotation(symbol: Symbol, initInfo: Type, override val prefix: Type) extends SingleDenotation(symbol, initInfo) {
1150+
abstract class NonSymSingleDenotation(symbol: Symbol, initInfo: Type, override val prefix: Type)
1151+
extends SingleDenotation(symbol, initInfo, initInfo.isInstanceOf[TypeType]) {
11541152
def infoOrCompleter: Type = initInfo
1155-
def isType: Boolean = infoOrCompleter.isInstanceOf[TypeType]
11561153
}
11571154

11581155
class UniqueRefDenotation(
@@ -1248,11 +1245,10 @@ object Denotations {
12481245

12491246
/** An overloaded denotation consisting of the alternatives of both given denotations.
12501247
*/
1251-
case class MultiDenotation(denot1: Denotation, denot2: Denotation) extends Denotation(NoSymbol, NoType) with MultiPreDenotation {
1248+
case class MultiDenotation(denot1: Denotation, denot2: Denotation) extends Denotation(NoSymbol, NoType, isType = false) with MultiPreDenotation {
12521249
validFor = denot1.validFor & denot2.validFor
1253-
1250+
12541251
final def infoOrCompleter: Type = multiHasNot("info")
1255-
final def isType: Boolean = false
12561252
final def hasUniqueSym: Boolean = false
12571253
final def name(using Context): Name = denot1.name
12581254
final def signature(using Context): Signature = Signature.OverloadedSignature

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ object SymDenotations {
3939
final val name: Name,
4040
initFlags: FlagSet,
4141
initInfo: Type,
42-
initPrivateWithin: Symbol = NoSymbol) extends SingleDenotation(symbol, initInfo) {
42+
initPrivateWithin: Symbol = NoSymbol) extends SingleDenotation(symbol, initInfo, name.isTypeName) {
4343

4444
//assert(symbol.id != 4940, name)
4545

@@ -576,9 +576,6 @@ object SymDenotations {
576576

577577
// ----- Tests -------------------------------------------------
578578

579-
/** Is this denotation a type? */
580-
override def isType: Boolean = name.isTypeName
581-
582579
/** Is this denotation a class? */
583580
final def isClass: Boolean = isInstanceOf[ClassDenotation]
584581

@@ -2570,7 +2567,6 @@ object SymDenotations {
25702567

25712568
@sharable object NoDenotation
25722569
extends SymDenotation(NoSymbol, NoSymbol, "<none>".toTermName, Permanent, NoType) {
2573-
override def isType: Boolean = false
25742570
override def isTerm: Boolean = false
25752571
override def exists: Boolean = false
25762572
override def owner: Symbol = throw new AssertionError("NoDenotation.owner")

0 commit comments

Comments
 (0)