Skip to content

Commit 84c4fe0

Browse files
committed
Cache isType in SymDenotations
isType also made up for a significant part of vtable stubs. We now compute it when a Symbol is created and keep it around as a field.
1 parent 9f13e56 commit 84c4fe0

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
@@ -1147,9 +1144,9 @@ object Denotations {
11471144
acc(false, symbol.info)
11481145
}
11491146

1150-
abstract class NonSymSingleDenotation(symbol: Symbol, initInfo: Type, override val prefix: Type) extends SingleDenotation(symbol, initInfo) {
1147+
abstract class NonSymSingleDenotation(symbol: Symbol, initInfo: Type, override val prefix: Type)
1148+
extends SingleDenotation(symbol, initInfo, initInfo.isInstanceOf[TypeType]) {
11511149
def infoOrCompleter: Type = initInfo
1152-
def isType: Boolean = infoOrCompleter.isInstanceOf[TypeType]
11531150
}
11541151

11551152
class UniqueRefDenotation(
@@ -1245,11 +1242,10 @@ object Denotations {
12451242

12461243
/** An overloaded denotation consisting of the alternatives of both given denotations.
12471244
*/
1248-
case class MultiDenotation(denot1: Denotation, denot2: Denotation) extends Denotation(NoSymbol, NoType) with MultiPreDenotation {
1245+
case class MultiDenotation(denot1: Denotation, denot2: Denotation) extends Denotation(NoSymbol, NoType, isType = false) with MultiPreDenotation {
12491246
validFor = denot1.validFor & denot2.validFor
1250-
1247+
12511248
final def infoOrCompleter: Type = multiHasNot("info")
1252-
final def isType: Boolean = false
12531249
final def hasUniqueSym: Boolean = false
12541250
final def name(using Context): Name = denot1.name
12551251
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

@@ -2574,7 +2571,6 @@ object SymDenotations {
25742571

25752572
@sharable object NoDenotation
25762573
extends SymDenotation(NoSymbol, NoSymbol, "<none>".toTermName, Permanent, NoType) {
2577-
override def isType: Boolean = false
25782574
override def isTerm: Boolean = false
25792575
override def exists: Boolean = false
25802576
override def owner: Symbol = throw new AssertionError("NoDenotation.owner")

0 commit comments

Comments
 (0)