Skip to content

Commit 9775736

Browse files
Devirtualize Denotation.info
1 parent 6acaa1b commit 9775736

File tree

2 files changed

+24
-30
lines changed

2 files changed

+24
-30
lines changed

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

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import config.Config
2323
import util.common._
2424
import collection.mutable.ListBuffer
2525
import Decorators.SymbolIteratorDecorator
26+
import SymDenotations.LazyType
2627

2728
/** Denotations represent the meaning of symbols and named types.
2829
* The following diagram shows how the principal types of denotations
@@ -171,12 +172,19 @@ object Denotations {
171172
*
172173
* @param symbol The referencing symbol, or NoSymbol is none exists
173174
*/
174-
abstract class Denotation(val symbol: Symbol) extends PreDenotation with printing.Showable {
175-
175+
abstract class Denotation(val symbol: Symbol, protected var myInfo: Type) extends PreDenotation with printing.Showable {
176176
type AsSeenFromResult <: Denotation
177177

178-
/** The type info of the denotation, exists only for non-overloaded denotations */
179-
def info(implicit ctx: Context): Type
178+
/** The type info.
179+
* The info is an instance of TypeType iff this is a type denotation
180+
* Uncompleted denotations set myInfo to a LazyType.
181+
*/
182+
final def info(implicit ctx: Context): Type = {
183+
def completeInfo = { // Written this way so that `info` is small enough to be inlined
184+
this.asInstanceOf[SymDenotation].completeFrom(myInfo.asInstanceOf[LazyType]); info
185+
}
186+
if (myInfo.isInstanceOf[LazyType]) completeInfo else myInfo
187+
}
180188

181189
/** The type info, or, if this is a SymDenotation where the symbol
182190
* is not yet completed, the completer
@@ -646,7 +654,7 @@ object Denotations {
646654
}
647655

648656
/** A non-overloaded denotation */
649-
abstract class SingleDenotation(symbol: Symbol) extends Denotation(symbol) {
657+
abstract class SingleDenotation(symbol: Symbol, initInfo: Type) extends Denotation(symbol, initInfo) {
650658
protected def newLikeThis(symbol: Symbol, info: Type): SingleDenotation
651659

652660
final def name(implicit ctx: Context): Name = symbol.name
@@ -1076,34 +1084,32 @@ object Denotations {
10761084
}
10771085
}
10781086

1079-
abstract class NonSymSingleDenotation(symbol: Symbol) extends SingleDenotation(symbol) {
1080-
def infoOrCompleter: Type
1081-
def info(implicit ctx: Context) = infoOrCompleter
1087+
abstract class NonSymSingleDenotation(symbol: Symbol, initInfo: Type) extends SingleDenotation(symbol, initInfo) {
1088+
def infoOrCompleter: Type = initInfo
10821089
def isType = infoOrCompleter.isInstanceOf[TypeType]
10831090
}
10841091

10851092
class UniqueRefDenotation(
10861093
symbol: Symbol,
1087-
val infoOrCompleter: Type,
1088-
initValidFor: Period) extends NonSymSingleDenotation(symbol) {
1094+
initInfo: Type,
1095+
initValidFor: Period) extends NonSymSingleDenotation(symbol, initInfo) {
10891096
validFor = initValidFor
10901097
override def hasUniqueSym: Boolean = true
10911098
protected def newLikeThis(s: Symbol, i: Type): SingleDenotation = new UniqueRefDenotation(s, i, validFor)
10921099
}
10931100

10941101
class JointRefDenotation(
10951102
symbol: Symbol,
1096-
val infoOrCompleter: Type,
1097-
initValidFor: Period) extends NonSymSingleDenotation(symbol) {
1103+
initInfo: Type,
1104+
initValidFor: Period) extends NonSymSingleDenotation(symbol, initInfo) {
10981105
validFor = initValidFor
10991106
override def hasUniqueSym = false
11001107
protected def newLikeThis(s: Symbol, i: Type): SingleDenotation = new JointRefDenotation(s, i, validFor)
11011108
}
11021109

1103-
class ErrorDenotation(implicit ctx: Context) extends NonSymSingleDenotation(NoSymbol) {
1110+
class ErrorDenotation(implicit ctx: Context) extends NonSymSingleDenotation(NoSymbol, NoType) {
11041111
override def exists = false
11051112
override def hasUniqueSym = false
1106-
def infoOrCompleter = NoType
11071113
validFor = Period.allInRun(ctx.runId)
11081114
protected def newLikeThis(s: Symbol, i: Type): SingleDenotation = this
11091115
}
@@ -1185,9 +1191,9 @@ object Denotations {
11851191

11861192
/** An overloaded denotation consisting of the alternatives of both given denotations.
11871193
*/
1188-
case class MultiDenotation(denot1: Denotation, denot2: Denotation) extends Denotation(NoSymbol) with MultiPreDenotation {
1194+
case class MultiDenotation(denot1: Denotation, denot2: Denotation) extends Denotation(NoSymbol, NoType) with MultiPreDenotation {
11891195
final def infoOrCompleter = multiHasNot("info")
1190-
final def info(implicit ctx: Context) = infoOrCompleter
1196+
// final def info(implicit ctx: Context) = infoOrCompleter
11911197
final def validFor = denot1.validFor & denot2.validFor
11921198
final def isType = false
11931199
final def hasUniqueSym = false

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

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ object SymDenotations {
126126
final val name: Name,
127127
initFlags: FlagSet,
128128
initInfo: Type,
129-
initPrivateWithin: Symbol = NoSymbol) extends SingleDenotation(symbol) {
129+
initPrivateWithin: Symbol = NoSymbol) extends SingleDenotation(symbol, initInfo) {
130130

131131
//assert(symbol.id != 4940, name)
132132

@@ -142,7 +142,6 @@ object SymDenotations {
142142
// ------ Getting and setting fields -----------------------------
143143

144144
private[this] var myFlags: FlagSet = adaptFlags(initFlags)
145-
private[this] var myInfo: Type = initInfo
146145
private[this] var myPrivateWithin: Symbol = initPrivateWithin
147146
private[this] var myAnnotations: List[Annotation] = Nil
148147

@@ -201,17 +200,6 @@ object SymDenotations {
201200
final def is(fs: FlagConjunction, butNot: FlagSet)(implicit ctx: Context) =
202201
(if (isCurrent(fs) && isCurrent(butNot)) myFlags else flags) is (fs, butNot)
203202

204-
/** The type info.
205-
* The info is an instance of TypeType iff this is a type denotation
206-
* Uncompleted denotations set myInfo to a LazyType.
207-
*/
208-
final def info(implicit ctx: Context): Type = {
209-
def completeInfo = { // Written this way so that `info` is small enough to be inlined
210-
completeFrom(myInfo.asInstanceOf[LazyType]); info
211-
}
212-
if (myInfo.isInstanceOf[LazyType]) completeInfo else myInfo
213-
}
214-
215203
/** The type info, or, if symbol is not yet completed, the completer */
216204
final def infoOrCompleter = myInfo
217205

@@ -221,7 +209,7 @@ object SymDenotations {
221209
case _ => Some(myInfo)
222210
}
223211

224-
private def completeFrom(completer: LazyType)(implicit ctx: Context): Unit =
212+
final def completeFrom(completer: LazyType)(implicit ctx: Context): Unit =
225213
if (Config.showCompletions) {
226214
println(i"${" " * indent}completing ${if (isType) "type" else "val"} $name")
227215
indent += 1

0 commit comments

Comments
 (0)