Skip to content

Commit 790337f

Browse files
Devirtualize Denotation.info
1 parent d15d1c8 commit 790337f

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
@@ -657,7 +665,7 @@ object Denotations {
657665
}
658666

659667
/** A non-overloaded denotation */
660-
abstract class SingleDenotation(symbol: Symbol) extends Denotation(symbol) {
668+
abstract class SingleDenotation(symbol: Symbol, initInfo: Type) extends Denotation(symbol, initInfo) {
661669
protected def newLikeThis(symbol: Symbol, info: Type): SingleDenotation
662670

663671
final def name(implicit ctx: Context): Name = symbol.name
@@ -1081,34 +1089,32 @@ object Denotations {
10811089
}
10821090
}
10831091

1084-
abstract class NonSymSingleDenotation(symbol: Symbol) extends SingleDenotation(symbol) {
1085-
def infoOrCompleter: Type
1086-
def info(implicit ctx: Context) = infoOrCompleter
1092+
abstract class NonSymSingleDenotation(symbol: Symbol, initInfo: Type) extends SingleDenotation(symbol, initInfo) {
1093+
def infoOrCompleter: Type = initInfo
10871094
def isType = infoOrCompleter.isInstanceOf[TypeType]
10881095
}
10891096

10901097
class UniqueRefDenotation(
10911098
symbol: Symbol,
1092-
val infoOrCompleter: Type,
1093-
initValidFor: Period) extends NonSymSingleDenotation(symbol) {
1099+
initInfo: Type,
1100+
initValidFor: Period) extends NonSymSingleDenotation(symbol, initInfo) {
10941101
validFor = initValidFor
10951102
override def hasUniqueSym: Boolean = true
10961103
protected def newLikeThis(s: Symbol, i: Type): SingleDenotation = new UniqueRefDenotation(s, i, validFor)
10971104
}
10981105

10991106
class JointRefDenotation(
11001107
symbol: Symbol,
1101-
val infoOrCompleter: Type,
1102-
initValidFor: Period) extends NonSymSingleDenotation(symbol) {
1108+
initInfo: Type,
1109+
initValidFor: Period) extends NonSymSingleDenotation(symbol, initInfo) {
11031110
validFor = initValidFor
11041111
override def hasUniqueSym = false
11051112
protected def newLikeThis(s: Symbol, i: Type): SingleDenotation = new JointRefDenotation(s, i, validFor)
11061113
}
11071114

1108-
class ErrorDenotation(implicit ctx: Context) extends NonSymSingleDenotation(NoSymbol) {
1115+
class ErrorDenotation(implicit ctx: Context) extends NonSymSingleDenotation(NoSymbol, NoType) {
11091116
override def exists = false
11101117
override def hasUniqueSym = false
1111-
def infoOrCompleter = NoType
11121118
validFor = Period.allInRun(ctx.runId)
11131119
protected def newLikeThis(s: Symbol, i: Type): SingleDenotation = this
11141120
}
@@ -1190,9 +1196,9 @@ object Denotations {
11901196

11911197
/** An overloaded denotation consisting of the alternatives of both given denotations.
11921198
*/
1193-
case class MultiDenotation(denot1: Denotation, denot2: Denotation) extends Denotation(NoSymbol) with MultiPreDenotation {
1199+
case class MultiDenotation(denot1: Denotation, denot2: Denotation) extends Denotation(NoSymbol, NoType) with MultiPreDenotation {
11941200
final def infoOrCompleter = multiHasNot("info")
1195-
final def info(implicit ctx: Context) = infoOrCompleter
1201+
// final def info(implicit ctx: Context) = infoOrCompleter
11961202
final def validFor = denot1.validFor & denot2.validFor
11971203
final def isType = false
11981204
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
@@ -127,7 +127,7 @@ object SymDenotations {
127127
final val name: Name,
128128
initFlags: FlagSet,
129129
initInfo: Type,
130-
initPrivateWithin: Symbol = NoSymbol) extends SingleDenotation(symbol) {
130+
initPrivateWithin: Symbol = NoSymbol) extends SingleDenotation(symbol, initInfo) {
131131

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

@@ -143,7 +143,6 @@ object SymDenotations {
143143
// ------ Getting and setting fields -----------------------------
144144

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

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

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

@@ -222,7 +210,7 @@ object SymDenotations {
222210
case _ => Some(myInfo)
223211
}
224212

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

0 commit comments

Comments
 (0)