Skip to content

Commit 3c4fdf9

Browse files
committed
Eliminate toDenot conversions in Symbols
They would be skipped when Symbol becomes an opaque type alias, since inside Symbols it is known that Symbol == SymDenotation
1 parent 40dc06c commit 3c4fdf9

File tree

2 files changed

+54
-9
lines changed

2 files changed

+54
-9
lines changed

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

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import StdNames._
2020
import NameOps._
2121
import transform.SymUtils._
2222
import NameKinds.LazyImplicitName
23+
import Annotations.Annotation
2324
import ast.tpd
2425
import tpd.{Tree, TreeProvider, TreeOps, EmptyTree, NameTree}
2526
import ast.TreeTypeMap
@@ -180,6 +181,9 @@ object Symbols {
180181
/** The last known denotation of this symbol, without going through `current` */
181182
def lastKnownDenotation: SymDenotation = lastDenot
182183

184+
def classDenot(using Context): ClassDenotation =
185+
_self.denot.asInstanceOf[ClassDenotation]
186+
183187
private[core] def defRunId: RunId =
184188
lastDenot.validFor.runId
185189

@@ -270,18 +274,18 @@ object Symbols {
270274
case owner: ClassSymbol =>
271275
if owner.is(Package) then
272276
d.validFor |= InitialPeriod
273-
if d.is(Module) then d.moduleClass.validFor |= InitialPeriod
277+
if d.is(Module) then d.moduleClass.denot.validFor |= InitialPeriod
274278
else
275-
owner.ensureFreshScopeAfter(phase)
279+
owner.classDenot.ensureFreshScopeAfter(phase)
276280
assert(isPrivate || phase.changesMembers, i"$_self entered in $owner at undeclared phase $phase")
277281
_self.entered
278282
case _ => _self
279283

280284
/** Remove symbol from scope of owning class */
281285
final def drop()(using Context): Unit =
282286
val d = denot
283-
d.owner.asClass.delete(_self)
284-
if d.is(Module) then d.owner.asClass.delete(d.moduleClass)
287+
d.owner.classDenot.delete(_self)
288+
if d.is(Module) then d.owner.classDenot.delete(d.moduleClass)
285289

286290
/** Remove symbol from scope of owning class after given `phase`. Create a fresh
287291
* denotation for its owner class if the class does not already have one that starts being valid after `phase`.
@@ -293,7 +297,7 @@ object Symbols {
293297
else
294298
val d = denot
295299
assert(!d.owner.is(Package))
296-
d.owner.asClass.ensureFreshScopeAfter(phase)
300+
d.owner.classDenot.ensureFreshScopeAfter(phase)
297301
assert(isPrivate || phase.changesMembers, i"$_self deleted in ${d.owner} at undeclared phase $phase")
298302
drop()
299303

@@ -365,6 +369,39 @@ object Symbols {
365369
else
366370
_self
367371

372+
def exists(using Context): Boolean = _self.denot.exists
373+
def owner(using Context): Symbol = _self.denot.owner
374+
def typeParams(using Context): List[TypeSymbol] = _self.denot.typeParams
375+
def thisType(using Context): Type = _self.denot.thisType
376+
def typeRef(using Context): TypeRef = _self.denot.typeRef
377+
def termRef(using Context): TermRef = _self.denot.termRef
378+
def isCompleted(using Context): Boolean = _self.denot.isCompleted
379+
def isCompleting(using Context): Boolean = _self.denot.isCompleting
380+
def ensureCompleted()(using Context): Unit = _self.denot.ensureCompleted()
381+
def unforcedDecls(using Context): Scope = _self.denot.unforcedDecls
382+
def appliedRef(using Context): Type = _self.denot.appliedRef
383+
def namedType(using Context): NamedType = _self.denot.namedType
384+
def unforcedAnnotation(cls: Symbol)(using Context): Option[Annotation] = _self.denot.unforcedAnnotation(cls)
385+
def children(using Context): List[Symbol] = _self.denot.children
386+
def topLevelClass(using Context): Symbol = _self.denot.topLevelClass
387+
def moduleClass(using Context): Symbol = _self.denot.moduleClass
388+
def sourceModule(using Context): Symbol = _self.denot.sourceModule
389+
def underlyingSymbol(using Context): Symbol = _self.denot.underlyingSymbol
390+
def ownersIterator(using Context): Iterator[Symbol] = _self.denot.ownersIterator
391+
def enclosingClass(using Context): Symbol = _self.denot.enclosingClass
392+
def enclosingMethod(using Context): Symbol = _self.denot.enclosingMethod
393+
def typeParamCreationFlags(using Context): FlagSet = _self.denot.typeParamCreationFlags
394+
//def is(flag: Flag)(using Context): Boolean = _self.denot.is(flag)
395+
//def is(flag: Flag, butNot: FlagSet)(using Context): Boolean = _self.denot.is(flag, butNot)
396+
//def isOneOf(fs: FlagSet)(using Context): Boolean = _self.denot.isOneOf(fs)
397+
//def isOneOf(fs: FlagSet, butNot: FlagSet)(using Context): Boolean = _self.denot.isOneOf(fs, butNot)
398+
//def isAllOf(fs: FlagSet)(using Context): Boolean = _self.denot.isAllOf(fs)
399+
//def isAllOf(fs: FlagSet, butNot: FlagSet)(using Context): Boolean = _self.denot.isAllOf(fs, butNot)
400+
// !!! Dotty problem: overloaded extension methods here lead to failures like
401+
// Assertion failed: data race? overwriting method isAllOf with method isAllOf in type TermRef(TermRef(TermRef(ThisType(TypeRef(NoPrefix,module class dotc)),object core),object Symbols),isAllOf),
402+
// |last sym id = 10301, new sym id = 10299,
403+
// |last owner = module class Symbols$, new owner = module class Symbols$,
404+
368405
// SrcPos types and methods // !!! make them use lastDenot?
369406
def span: Span = self.span
370407
def sourcePos(using Context): SourcePosition = self.sourcePos
@@ -411,6 +448,8 @@ object Symbols {
411448
def showName(using Context): String = ctx.printer.nameString(_self)
412449
def showFullName(using Context): String = ctx.printer.fullNameString(_self)
413450

451+
def debugString: String = self.debugString
452+
414453
end extension
415454

416455
type TreeOrProvider = TreeProvider | Tree
@@ -474,7 +513,7 @@ object Symbols {
474513

475514
def sourceOfClass(using Context): SourceFile =
476515
val common = _self.lastKnownDenotation.common.asClass
477-
if !common.source.exists && !_self.denot.is(Package) then
516+
if !common.source.exists && !_self.is(Package) then
478517
// this allows sources to be added in annotations after `sourceOfClass` is first called
479518
val file = _self.associatedFile
480519
if file != null && file.extension != "class" then
@@ -491,8 +530,10 @@ object Symbols {
491530
}
492531
common.source
493532

494-
def classDenot(using Context): ClassDenotation =
495-
_self.denot.asInstanceOf[ClassDenotation]
533+
private def enter(sym: Symbol, scope: Scope = EmptyScope)(using Context): Unit =
534+
_self.classDenot.enter(sym, scope)
535+
536+
def classInfo(using Context): ClassInfo = _self.classDenot.classInfo
496537

497538
end extension
498539

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2501,6 +2501,7 @@ object Types {
25012501
s"""data race? overwriting $lastSym with $sym in type $this,
25022502
|last sym id = ${lastSym.id}, new sym id = ${sym.id},
25032503
|last owner = ${lastSym.owner}, new owner = ${sym.owner},
2504+
|last info = ${lastSym.infoOrCompleter}, new info = ${sym.infoOrCompleter}
25042505
|period = ${ctx.phase} at run ${ctx.runId}""" })
25052506
}
25062507

@@ -2785,7 +2786,10 @@ object Types {
27852786
override def isOverloaded(using Context): Boolean = denot.isOverloaded
27862787

27872788
def alternatives(using Context): List[TermRef] =
2788-
denot.alternatives.map(withDenot(_))
2789+
try denot.alternatives.map(withDenot(_))
2790+
catch case ex: AssertionError =>
2791+
println(i"error while alts ${denot.alternatives}")
2792+
throw ex
27892793

27902794
def altsWith(p: Symbol => Boolean)(using Context): List[TermRef] =
27912795
denot.altsWith(p).map(withDenot(_))

0 commit comments

Comments
 (0)