Skip to content

Commit 592eee4

Browse files
Devirtualize Denotation.info
1 parent dc2dafb commit 592eee4

File tree

2 files changed

+23
-30
lines changed

2 files changed

+23
-30
lines changed

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

Lines changed: 21 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
@@ -676,7 +684,7 @@ object Denotations {
676684
}
677685

678686
/** A non-overloaded denotation */
679-
abstract class SingleDenotation(symbol: Symbol) extends Denotation(symbol) {
687+
abstract class SingleDenotation(symbol: Symbol, initInfo: Type) extends Denotation(symbol, initInfo) {
680688
protected def newLikeThis(symbol: Symbol, info: Type): SingleDenotation
681689

682690
final def name(implicit ctx: Context): Name = symbol.name
@@ -1100,34 +1108,32 @@ object Denotations {
11001108
}
11011109
}
11021110

1103-
abstract class NonSymSingleDenotation(symbol: Symbol) extends SingleDenotation(symbol) {
1104-
def infoOrCompleter: Type
1105-
def info(implicit ctx: Context) = infoOrCompleter
1111+
abstract class NonSymSingleDenotation(symbol: Symbol, initInfo: Type) extends SingleDenotation(symbol, initInfo) {
1112+
def infoOrCompleter: Type = initInfo
11061113
def isType = infoOrCompleter.isInstanceOf[TypeType]
11071114
}
11081115

11091116
class UniqueRefDenotation(
11101117
symbol: Symbol,
1111-
val infoOrCompleter: Type,
1112-
initValidFor: Period) extends NonSymSingleDenotation(symbol) {
1118+
initInfo: Type,
1119+
initValidFor: Period) extends NonSymSingleDenotation(symbol, initInfo) {
11131120
validFor = initValidFor
11141121
override def hasUniqueSym: Boolean = true
11151122
protected def newLikeThis(s: Symbol, i: Type): SingleDenotation = new UniqueRefDenotation(s, i, validFor)
11161123
}
11171124

11181125
class JointRefDenotation(
11191126
symbol: Symbol,
1120-
val infoOrCompleter: Type,
1121-
initValidFor: Period) extends NonSymSingleDenotation(symbol) {
1127+
initInfo: Type,
1128+
initValidFor: Period) extends NonSymSingleDenotation(symbol, initInfo) {
11221129
validFor = initValidFor
11231130
override def hasUniqueSym = false
11241131
protected def newLikeThis(s: Symbol, i: Type): SingleDenotation = new JointRefDenotation(s, i, validFor)
11251132
}
11261133

1127-
class ErrorDenotation(implicit ctx: Context) extends NonSymSingleDenotation(NoSymbol) {
1134+
class ErrorDenotation(implicit ctx: Context) extends NonSymSingleDenotation(NoSymbol, NoType) {
11281135
override def exists = false
11291136
override def hasUniqueSym = false
1130-
def infoOrCompleter = NoType
11311137
validFor = Period.allInRun(ctx.runId)
11321138
protected def newLikeThis(s: Symbol, i: Type): SingleDenotation = this
11331139
}
@@ -1203,9 +1209,8 @@ object Denotations {
12031209

12041210
/** An overloaded denotation consisting of the alternatives of both given denotations.
12051211
*/
1206-
case class MultiDenotation(denot1: Denotation, denot2: Denotation) extends Denotation(NoSymbol) with MultiPreDenotation {
1212+
case class MultiDenotation(denot1: Denotation, denot2: Denotation) extends Denotation(NoSymbol, NoType) with MultiPreDenotation {
12071213
final def infoOrCompleter = multiHasNot("info")
1208-
final def info(implicit ctx: Context) = infoOrCompleter
12091214
final def validFor = denot1.validFor & denot2.validFor
12101215
final def isType = false
12111216
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
@@ -125,7 +125,7 @@ object SymDenotations {
125125
final val name: Name,
126126
initFlags: FlagSet,
127127
initInfo: Type,
128-
initPrivateWithin: Symbol = NoSymbol) extends SingleDenotation(symbol) {
128+
initPrivateWithin: Symbol = NoSymbol) extends SingleDenotation(symbol, initInfo) {
129129

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

@@ -141,7 +141,6 @@ object SymDenotations {
141141
// ------ Getting and setting fields -----------------------------
142142

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

@@ -203,17 +202,6 @@ object SymDenotations {
203202
final def is(fs: FlagConjunction, butNot: FlagSet)(implicit ctx: Context) =
204203
(if (isCurrent(fs) && isCurrent(butNot)) myFlags else flags) is (fs, butNot)
205204

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

@@ -223,7 +211,7 @@ object SymDenotations {
223211
case _ => Some(myInfo)
224212
}
225213

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

0 commit comments

Comments
 (0)