Skip to content

Commit fdfa308

Browse files
committed
Cache hot fields in Symbols, and some refactorings
1 parent 9bf6974 commit fdfa308

File tree

5 files changed

+200
-70
lines changed

5 files changed

+200
-70
lines changed

compiler/src/dotty/tools/backend/jvm/CollectEntryPoints.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ object CollectEntryPoints{
6161
val StringType = d.StringType
6262
// The given class has a main method.
6363
def hasJavaMainMethod(sym: Symbol): Boolean =
64-
(toDenot(sym).info member nme.main).alternatives exists(x => isJavaMainMethod(x.symbol))
64+
(sym.info member nme.main).alternatives exists(x => isJavaMainMethod(x.symbol))
6565

6666
def fail(msg: String, pos: Position = sym.pos) = {
6767
ctx.warning( sym.name +
68-
s" has a main method with parameter type Array[String], but ${toDenot(sym).fullName} will not be a runnable program.\n Reason: $msg",
68+
s" has a main method with parameter type Array[String], but ${sym.fullName} will not be a runnable program.\n Reason: $msg",
6969
sourcePos(sym.pos)
7070
// TODO: make this next claim true, if possible
7171
// by generating valid main methods as static in module classes
@@ -77,7 +77,7 @@ object CollectEntryPoints{
7777
def failNoForwarder(msg: String) = {
7878
fail(s"$msg, which means no static forwarder can be generated.\n")
7979
}
80-
val possibles = if (sym.flags is Flags.Module) (toDenot(sym).info nonPrivateMember nme.main).alternatives else Nil
80+
val possibles = if (sym.flags is Flags.Module) (sym.info nonPrivateMember nme.main).alternatives else Nil
8181
val hasApproximate = possibles exists { m =>
8282
m.info match {
8383
case MethodTpe(_, p :: Nil, _) => p.typeSymbol == defn.ArrayClass
@@ -94,7 +94,7 @@ object CollectEntryPoints{
9494

9595
if (hasJavaMainMethod(companion))
9696
failNoForwarder("companion contains its own main method")
97-
else if (toDenot(companion).info.member(nme.main) != NoDenotation)
97+
else if (companion.info.member(nme.main) != NoDenotation)
9898
// this is only because forwarders aren't smart enough yet
9999
failNoForwarder("companion contains its own main method (implementation restriction: no main is allowed, regardless of signature)")
100100
else if (companion.flags is Flags.Trait)
@@ -103,7 +103,7 @@ object CollectEntryPoints{
103103
// attempts to be java main methods.
104104
else (possibles exists(x=> isJavaMainMethod(x.symbol))) || {
105105
possibles exists { m =>
106-
toDenot(m.symbol).info match {
106+
m.symbol.info match {
107107
case t: PolyType =>
108108
fail("main methods cannot be generic.")
109109
case MethodTpe(paramNames, paramTypes, resultType) =>

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
143143
val externalEqualsNumNum: Symbol = defn.BoxesRunTimeModule.requiredMethod(nme.equalsNumNum)
144144
val externalEqualsNumChar: Symbol = NoSymbol // ctx.requiredMethod(BoxesRunTimeTypeRef, nme.equalsNumChar) // this method is private
145145
val externalEqualsNumObject: Symbol = defn.BoxesRunTimeModule.requiredMethod(nme.equalsNumObject)
146-
val externalEquals: Symbol = defn.BoxesRunTimeClass.info.decl(nme.equals_).suchThat(toDenot(_).info.firstParamTypes.size == 2).symbol
146+
val externalEquals: Symbol = defn.BoxesRunTimeClass.info.decl(nme.equals_).suchThat(_.info.firstParamTypes.size == 2).symbol
147147
val MaxFunctionArity: Int = Definitions.MaxImplementedFunctionArity
148148
val FunctionClass: Array[Symbol] = defn.FunctionClassPerRun()
149149
val AbstractFunctionClass: Array[Symbol] = defn.AbstractFunctionClassPerRun()
@@ -169,9 +169,9 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
169169
}
170170

171171
def isBox(sym: Symbol): Boolean =
172-
Erasure.Boxing.isBox(sym) && sym.denot.owner != defn.UnitModuleClass
172+
Erasure.Boxing.isBox(sym) && sym.owner != defn.UnitModuleClass
173173
def isUnbox(sym: Symbol): Boolean =
174-
Erasure.Boxing.isUnbox(sym) && sym.denot.owner != defn.UnitModuleClass
174+
Erasure.Boxing.isUnbox(sym) && sym.owner != defn.UnitModuleClass
175175

176176
val primitives: Primitives = new Primitives {
177177
val primitives = new DottyPrimitives(ctx)
@@ -256,24 +256,24 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
256256
av.visitEnum(name, edesc, evalue)
257257
}
258258
case t: TypeApply if (t.fun.symbol == Predef_classOf) =>
259-
av.visit(name, t.args.head.tpe.classSymbol.denot.info.toTypeKind(bcodeStore)(innerClasesStore).toASMType)
259+
av.visit(name, t.args.head.tpe.classSymbol.info.toTypeKind(bcodeStore)(innerClasesStore).toASMType)
260260
case t: tpd.Select =>
261-
if (t.symbol.denot.owner.is(Flags.Enum)) {
261+
if (t.symbol.owner.is(Flags.Enum)) {
262262
val edesc = innerClasesStore.typeDescriptor(t.tpe.asInstanceOf[bcodeStore.int.Type]) // the class descriptor of the enumeration class.
263263
val evalue = t.symbol.name.mangledString // value the actual enumeration value.
264264
av.visitEnum(name, edesc, evalue)
265265
} else {
266-
// println(i"not an enum: ${t.symbol} / ${t.symbol.denot.owner} / ${t.symbol.denot.owner.isTerm} / ${t.symbol.denot.owner.flags}")
267-
assert(toDenot(t.symbol).name.is(DefaultGetterName),
268-
s"${toDenot(t.symbol).name.debugString}") // this should be default getter. do not emmit.
266+
// println(i"not an enum: ${t.symbol} / ${t.symbol.owner} / ${t.symbol.owner.isTerm} / ${t.symbol.owner.flags}")
267+
assert(t.symbol.name.is(DefaultGetterName),
268+
s"${t.symbol.name.debugString}") // this should be default getter. do not emmit.
269269
}
270270
case t: SeqLiteral =>
271271
val arrAnnotV: AnnotationVisitor = av.visitArray(name)
272272
for (arg <- t.elems) { emitArgument(arrAnnotV, null, arg, bcodeStore)(innerClasesStore) }
273273
arrAnnotV.visitEnd()
274274

275275
case Apply(fun, args) if fun.symbol == defn.ArrayClass.primaryConstructor ||
276-
toDenot(fun.symbol).owner == defn.ArrayClass.linkedClass && fun.symbol.name == nme_apply =>
276+
fun.symbol.owner == defn.ArrayClass.linkedClass && fun.symbol.name == nme_apply =>
277277
val arrAnnotV: AnnotationVisitor = av.visitArray(name)
278278

279279
var actualArgs = if (fun.tpe.isImplicitMethod) {
@@ -304,7 +304,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
304304
} // for the lazy val in ScalaSigBytes to be GC'ed, the invoker of emitAnnotations() should hold the ScalaSigBytes in a method-local var that doesn't escape.
305305
*/
306306
case t @ Apply(constr, args) if t.tpe.derivesFrom(JavaAnnotationClass) =>
307-
val typ = t.tpe.classSymbol.denot.info
307+
val typ = t.tpe.classSymbol.info
308308
val assocs = assocsFromApply(t)
309309
val desc = innerClasesStore.typeDescriptor(typ.asInstanceOf[bcodeStore.int.Type]) // the class descriptor of the nested annotation class
310310
val nestedVisitor = av.visitAnnotation(name, desc)
@@ -521,7 +521,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
521521

522522
if (!valid) {
523523
ctx.error(
524-
i"""|compiler bug: created invalid generic signature for $sym in ${sym.denot.owner.showFullName}
524+
i"""|compiler bug: created invalid generic signature for $sym in ${sym.owner.showFullName}
525525
|signature: $sig
526526
|if this is reproducible, please report bug at https://github.com/lampepfl/dotty/issues
527527
""".trim, sym.pos)
@@ -540,7 +540,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
540540
def getGenericSignature(sym: Symbol, owner: Symbol): String = {
541541
ctx.atPhase(ctx.erasurePhase) { implicit ctx =>
542542
val memberTpe =
543-
if (sym.is(Flags.Method)) sym.denot.info
543+
if (sym.is(Flags.Method)) sym.info
544544
else owner.denot.thisType.memberInfo(sym)
545545
getGenericSignature(sym, owner, memberTpe).orNull
546546
}
@@ -555,14 +555,14 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
555555

556556
val memberTpe = ctx.atPhase(ctx.erasurePhase) { implicit ctx => moduleClass.denot.thisType.memberInfo(sym) }
557557
val erasedMemberType = TypeErasure.erasure(memberTpe)
558-
if (erasedMemberType =:= sym.denot.info)
558+
if (erasedMemberType =:= sym.info)
559559
getGenericSignature(sym, moduleClass, memberTpe).orNull
560560
else null
561561
}
562562

563563
private def getGenericSignature(sym: Symbol, owner: Symbol, memberTpe: Type)(implicit ctx: Context): Option[String] =
564564
if (needsGenericSignature(sym)) {
565-
val erasedTypeSym = sym.denot.info.typeSymbol
565+
val erasedTypeSym = sym.info.typeSymbol
566566
if (erasedTypeSym.isPrimitiveValueClass) {
567567
None
568568
} else {
@@ -655,7 +655,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
655655
def fullName(sep: Char): String = sym.showFullName
656656
def fullName: String = sym.showFullName
657657
def simpleName: Name = sym.name
658-
def javaSimpleName: String = toDenot(sym).name.mangledString // addModuleSuffix(simpleName.dropLocal)
658+
def javaSimpleName: String = sym.name.mangledString // addModuleSuffix(simpleName.dropLocal)
659659
def javaBinaryName: String = javaClassName.replace('.', '/') // TODO: can we make this a string? addModuleSuffix(fullNameInternal('/'))
660660
def javaClassName: String = toDenot(sym).fullName.mangledString // addModuleSuffix(fullNameInternal('.')).toString
661661
def name: Name = sym.name
@@ -665,8 +665,8 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
665665
}
666666

667667
// types
668-
def info: Type = toDenot(sym).info
669-
def tpe: Type = toDenot(sym).info // todo whats the differentce between tpe and info?
668+
def info: Type = sym.info
669+
def tpe: Type = sym.info // todo whats the differentce between tpe and info?
670670
def thisType: Type = toDenot(sym).thisType
671671

672672
// tests
@@ -746,7 +746,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
746746

747747

748748
// navigation
749-
def owner: Symbol = toDenot(sym).owner
749+
def owner: Symbol = sym.owner
750750
def rawowner: Symbol = {
751751
originalOwner
752752
}
@@ -760,7 +760,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
760760
val r = toDenot(sym)(shiftedContext).maybeOwner.lexicallyEnclosingClass(shiftedContext)
761761
r
762762
} else NoSymbol
763-
def parentSymbols: List[Symbol] = toDenot(sym).info.parents.map(_.typeSymbol)
763+
def parentSymbols: List[Symbol] = sym.info.parents.map(_.typeSymbol)
764764
def superClass: Symbol = {
765765
val t = toDenot(sym).asClass.superClass
766766
if (t.exists) t
@@ -803,7 +803,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
803803
private def definedClasses(phase: Phase) =
804804
if (sym.isDefinedInCurrentRun)
805805
ctx.atPhase(phase) { implicit ctx =>
806-
toDenot(sym).info.decls.filter(_.isClass)
806+
sym.info.decls.filter(_.isClass)
807807
}
808808
else Nil
809809

@@ -815,10 +815,10 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
815815
else Nil
816816
}
817817
def fieldSymbols: List[Symbol] = {
818-
toDenot(sym).info.decls.filter(p => p.isTerm && !p.is(Flags.Method))
818+
sym.info.decls.filter(p => p.isTerm && !p.is(Flags.Method))
819819
}
820820
def methodSymbols: List[Symbol] =
821-
for (f <- toDenot(sym).info.decls.toList if f.isMethod && f.isTerm && !f.isModule) yield f
821+
for (f <- sym.info.decls.toList if f.isMethod && f.isTerm && !f.isModule) yield f
822822
def serialVUID: Option[Long] = None
823823

824824

@@ -856,7 +856,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
856856
*/
857857
def isTopLevelModuleClass: Boolean = sym.isModuleClass &&
858858
ctx.atPhase(ctx.flattenPhase) { implicit ctx =>
859-
toDenot(sym).owner.is(Flags.PackageClass)
859+
sym.owner.is(Flags.PackageClass)
860860
}
861861

862862
/**
@@ -874,7 +874,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
874874
def addRemoteRemoteExceptionAnnotation: Unit = ()
875875

876876
def samMethod(): Symbol =
877-
toDenot(sym).info.abstractTermMembers.headOption.getOrElse(toDenot(sym).info.member(nme.apply)).symbol
877+
sym.info.abstractTermMembers.headOption.getOrElse(sym.info.member(nme.apply)).symbol
878878
}
879879

880880

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

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -289,35 +289,6 @@ object Denotations {
289289
denot.symbol
290290
}
291291

292-
def requiredMethod(name: PreName)(implicit ctx: Context): TermSymbol =
293-
info.member(name.toTermName).requiredSymbol(_ is Method).asTerm
294-
def requiredMethodRef(name: PreName)(implicit ctx: Context): TermRef =
295-
requiredMethod(name).termRef
296-
297-
def requiredMethod(name: PreName, argTypes: List[Type])(implicit ctx: Context): TermSymbol = {
298-
info.member(name.toTermName).requiredSymbol { x =>
299-
(x is Method) && {
300-
x.info.paramInfoss match {
301-
case paramInfos :: Nil => paramInfos.corresponds(argTypes)(_ =:= _)
302-
case _ => false
303-
}
304-
}
305-
}.asTerm
306-
}
307-
def requiredMethodRef(name: PreName, argTypes: List[Type])(implicit ctx: Context): TermRef =
308-
requiredMethod(name, argTypes).termRef
309-
310-
def requiredValue(name: PreName)(implicit ctx: Context): TermSymbol =
311-
info.member(name.toTermName).requiredSymbol(_.info.isParameterless).asTerm
312-
def requiredValueRef(name: PreName)(implicit ctx: Context): TermRef =
313-
requiredValue(name).termRef
314-
315-
def requiredClass(name: PreName)(implicit ctx: Context): ClassSymbol =
316-
info.member(name.toTypeName).requiredSymbol(_.isClass).asClass
317-
318-
def requiredType(name: PreName)(implicit ctx: Context): TypeSymbol =
319-
info.member(name.toTypeName).requiredSymbol(_.isType).asType
320-
321292
/** The alternative of this denotation that has a type matching `targetType` when seen
322293
* as a member of type `site`, `NoDenotation` if none exists.
323294
*/

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,16 @@ object SymDenotations {
170170
}
171171

172172
/** Set given flags(s) of this denotation */
173-
final def setFlag(flags: FlagSet): Unit = { myFlags |= flags }
173+
final def setFlag(flags: FlagSet): Unit = {
174+
myFlags |= flags
175+
symbol.updateFlagsCache(this, myFlags)
176+
}
174177

175178
/** Unset given flags(s) of this denotation */
176-
final def resetFlag(flags: FlagSet): Unit = { myFlags &~= flags }
179+
final def resetFlag(flags: FlagSet): Unit = {
180+
myFlags &~= flags
181+
symbol.updateFlagsCache(this, myFlags)
182+
}
177183

178184
/** Set applicable flags from `flags` which is a subset of {NoInits, PureInterface} */
179185
final def setNoInitsFlags(flags: FlagSet): Unit = {
@@ -232,7 +238,7 @@ object SymDenotations {
232238
indent += 1
233239

234240
if (myFlags is Touched) throw CyclicReference(this)
235-
myFlags |= Touched
241+
setFlag(Touched)
236242

237243
// completions.println(s"completing ${this.debugString}")
238244
try completer.complete(this)(ctx.withPhase(validFor.firstPhaseId))
@@ -248,7 +254,7 @@ object SymDenotations {
248254
}
249255
else {
250256
if (myFlags is Touched) throw CyclicReference(this)
251-
myFlags |= Touched
257+
setFlag(Touched)
252258
completer.complete(this)(ctx.withPhase(validFor.firstPhaseId))
253259
}
254260

@@ -456,8 +462,10 @@ object SymDenotations {
456462
def isError: Boolean = false
457463

458464
/** Make denotation not exist */
459-
final def markAbsent(): Unit =
465+
final def markAbsent(): Unit = {
460466
myInfo = NoType
467+
symbol.updateInfoCache(this, NoType)
468+
}
461469

462470
/** Is symbol known to not exist, or potentially not completed yet? */
463471
final def unforcedIsAbsent(implicit ctx: Context): Boolean =

0 commit comments

Comments
 (0)