Skip to content

Commit 8233f89

Browse files
Devirtualize Denotation.info
1 parent 94df23b commit 8233f89

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
@@ -673,7 +681,7 @@ object Denotations {
673681
}
674682

675683
/** A non-overloaded denotation */
676-
abstract class SingleDenotation(symbol: Symbol) extends Denotation(symbol) {
684+
abstract class SingleDenotation(symbol: Symbol, initInfo: Type) extends Denotation(symbol, initInfo) {
677685
protected def newLikeThis(symbol: Symbol, info: Type): SingleDenotation
678686

679687
final def name(implicit ctx: Context): Name = symbol.name
@@ -1097,34 +1105,32 @@ object Denotations {
10971105
}
10981106
}
10991107

1100-
abstract class NonSymSingleDenotation(symbol: Symbol) extends SingleDenotation(symbol) {
1101-
def infoOrCompleter: Type
1102-
def info(implicit ctx: Context) = infoOrCompleter
1108+
abstract class NonSymSingleDenotation(symbol: Symbol, initInfo: Type) extends SingleDenotation(symbol, initInfo) {
1109+
def infoOrCompleter: Type = initInfo
11031110
def isType = infoOrCompleter.isInstanceOf[TypeType]
11041111
}
11051112

11061113
class UniqueRefDenotation(
11071114
symbol: Symbol,
1108-
val infoOrCompleter: Type,
1109-
initValidFor: Period) extends NonSymSingleDenotation(symbol) {
1115+
initInfo: Type,
1116+
initValidFor: Period) extends NonSymSingleDenotation(symbol, initInfo) {
11101117
validFor = initValidFor
11111118
override def hasUniqueSym: Boolean = true
11121119
protected def newLikeThis(s: Symbol, i: Type): SingleDenotation = new UniqueRefDenotation(s, i, validFor)
11131120
}
11141121

11151122
class JointRefDenotation(
11161123
symbol: Symbol,
1117-
val infoOrCompleter: Type,
1118-
initValidFor: Period) extends NonSymSingleDenotation(symbol) {
1124+
initInfo: Type,
1125+
initValidFor: Period) extends NonSymSingleDenotation(symbol, initInfo) {
11191126
validFor = initValidFor
11201127
override def hasUniqueSym = false
11211128
protected def newLikeThis(s: Symbol, i: Type): SingleDenotation = new JointRefDenotation(s, i, validFor)
11221129
}
11231130

1124-
class ErrorDenotation(implicit ctx: Context) extends NonSymSingleDenotation(NoSymbol) {
1131+
class ErrorDenotation(implicit ctx: Context) extends NonSymSingleDenotation(NoSymbol, NoType) {
11251132
override def exists = false
11261133
override def hasUniqueSym = false
1127-
def infoOrCompleter = NoType
11281134
validFor = Period.allInRun(ctx.runId)
11291135
protected def newLikeThis(s: Symbol, i: Type): SingleDenotation = this
11301136
}
@@ -1200,9 +1206,8 @@ object Denotations {
12001206

12011207
/** An overloaded denotation consisting of the alternatives of both given denotations.
12021208
*/
1203-
case class MultiDenotation(denot1: Denotation, denot2: Denotation) extends Denotation(NoSymbol) with MultiPreDenotation {
1209+
case class MultiDenotation(denot1: Denotation, denot2: Denotation) extends Denotation(NoSymbol, NoType) with MultiPreDenotation {
12041210
final def infoOrCompleter = multiHasNot("info")
1205-
final def info(implicit ctx: Context) = infoOrCompleter
12061211
final def validFor = denot1.validFor & denot2.validFor
12071212
final def isType = false
12081213
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
@@ -123,7 +123,7 @@ object SymDenotations {
123123
final val name: Name,
124124
initFlags: FlagSet,
125125
initInfo: Type,
126-
initPrivateWithin: Symbol = NoSymbol) extends SingleDenotation(symbol) {
126+
initPrivateWithin: Symbol = NoSymbol) extends SingleDenotation(symbol, initInfo) {
127127

128128
//assert(symbol.id != 4940, name)
129129

@@ -139,7 +139,6 @@ object SymDenotations {
139139
// ------ Getting and setting fields -----------------------------
140140

141141
private[this] var myFlags: FlagSet = adaptFlags(initFlags)
142-
private[this] var myInfo: Type = initInfo
143142
private[this] var myPrivateWithin: Symbol = initPrivateWithin
144143
private[this] var myAnnotations: List[Annotation] = Nil
145144

@@ -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)