@@ -37,34 +37,32 @@ import scala.reflect.TypeTest
37
37
38
38
object Symbols {
39
39
40
- implicit def eqSymbol : CanEqual [Symbol , Symbol ] = CanEqual .derived
41
-
42
40
/** Tree attachment containing the identifiers in a tree as a sorted array */
43
41
val Ids : Property .Key [Array [String ]] = new Property .Key
44
42
45
- opaque type Symbl <: ParamInfo & SrcPos & Named & printing.Showable
43
+ opaque type Symbol <: ParamInfo & SrcPos & Named & printing.Showable
46
44
= SymDenotation
47
-
48
- opaque type ClassSymbl <: Symbl
45
+ opaque type ClassSymbol <: TypeSymbol
49
46
= ClassDenotation
50
47
51
48
object TypeTests :
52
49
53
- given SymTest : TypeTest [AnyRef , Symbol ] with
54
- def unapply (x : AnyRef ): Option [x.type & Symbol ] = x match
55
- case sd : SymDenotation => Some (sd.asInstanceOf )
50
+ given SymTest : TypeTest [Any , Symbol ] with
51
+ def unapply (x : Any ): Option [x.type & Symbol ] = x match
52
+ case sd : SymDenotation => Some (sd.asInstanceOf [x. type & Symbol ] )
56
53
case _ => None
57
54
58
- given ClsTest : TypeTest [AnyRef , ClassSymbol ] with
59
- def unapply (x : AnyRef ): Option [x.type & ClassSymbol ] = x match
60
- case cd : ClassDenotation => Some (cd.asInstanceOf )
55
+ given ClsTest : TypeTest [Any , ClassSymbol ] with
56
+ def unapply (x : Any ): Option [x.type & ClassSymbol ] = x match
57
+ case cd : ClassDenotation => Some (cd.asInstanceOf [x. type & ClassSymbol ] )
61
58
case _ => None
62
59
end TypeTests
63
60
61
+ implicit def eqSymbol : CanEqual [Symbol , Symbol ] = CanEqual .derived
62
+
64
63
/** A Symbol represents a Scala definition/declaration or a package.
65
64
* @param coord The coordinates of the symbol (a position or an index)
66
65
* @param id A unique identifier of the symbol (unique per ContextBase)
67
- */
68
66
class Symbol private[Symbols] ()
69
67
extends ParamInfo, SrcPos, Named, printing.Showable {
70
68
@@ -95,6 +93,7 @@ object Symbols {
95
93
96
94
override def hashCode(): Int = Symbols.id(this) // for debugging.
97
95
}
96
+ */
98
97
99
98
type TermSymbol = Symbol { type ThisName = TermName }
100
99
type TypeSymbol = Symbol { type ThisName = TypeName }
@@ -104,7 +103,7 @@ object Symbols {
104
103
inline def asSymbol : Symbol = x.asInstanceOf [Symbol ]
105
104
106
105
extension (_self : Symbol )
107
- def self = _self.initialDenot
106
+ def self : SymDenotation = _self
108
107
109
108
private def lastDenot : SymDenotation = self.lastDenot
110
109
private def lastDenot_= (d : SymDenotation ): Unit = self.lastDenot = d
@@ -154,20 +153,14 @@ object Symbols {
154
153
private [core] def denot_= (d : SymDenotation ): Unit =
155
154
util.Stats .record(" Symbol.denot_=" )
156
155
lastDenot = d
157
- self.checkedPeriod = Nowhere
158
156
159
157
/** The current denotation of this symbol */
160
158
def denot (using Context ): SymDenotation =
161
159
util.Stats .record(" Symbol.denot" )
162
160
val lastd = lastDenot
163
- if self.checkedPeriod.code == ctx.period.code then lastd
164
- else computeDenot(lastd)
165
-
166
- def computeDenot (lastd : SymDenotation )(using Context ): SymDenotation =
167
- util.Stats .record(" Symbol.computeDenot" )
168
- val now = ctx.period
169
- self.checkedPeriod = now
170
- if lastd.validFor contains now then lastd else recomputeDenot(lastd)
161
+ if lastd.validFor.code.containsSinglePhasePeriod(ctx.period.code)
162
+ then lastd
163
+ else recomputeDenot(lastd)
171
164
172
165
private def recomputeDenot (lastd : SymDenotation )(using Context ): SymDenotation =
173
166
util.Stats .record(" Symbol.recomputeDenot" )
@@ -454,16 +447,16 @@ object Symbols {
454
447
end extension
455
448
456
449
type TreeOrProvider = TreeProvider | Tree
457
-
450
+ /*
458
451
class ClassSymbol private[Symbols] extends Symbol {
459
452
460
453
util.Stats.record("ClassSymbol")
461
454
462
455
type ThisName = TypeName
463
456
}
464
-
457
+ */
465
458
extension (_self : ClassSymbol )
466
- def self = _self.initialDenot
459
+ def self : ClassDenotation = _self
467
460
468
461
/** If this is a top-level class and `-Yretain-trees` (or `-from-tasty`) is set.
469
462
* Returns the TypeDef tree (possibly wrapped inside PackageDefs) for this class, otherwise EmptyTree.
@@ -535,16 +528,7 @@ object Symbols {
535
528
536
529
end extension
537
530
538
- @ sharable object NoSymbol extends Symbol {
539
- // override def coord = NoCoord
540
- // override def id = 0
541
- // override def nestingLevel = 0
542
- // override def defTree = tpd.EmptyTree
543
- // override def associatedFile(using Context): AbstractFile | Null = NoSource.file
544
- // override def recomputeDenot(lastd: SymDenotation)(using Context): SymDenotation = NoDenotation
545
- }
546
-
547
- NoDenotation // force it in order to set `denot` field of NoSymbol
531
+ def NoSymbol : Symbol = NoDenotation
548
532
549
533
/** Makes all denotation operations available on symbols */
550
534
implicit def toDenot (sym : Symbol )(using Context ): SymDenotation = sym.denot
@@ -579,11 +563,9 @@ object Symbols {
579
563
privateWithin : Symbol = NoSymbol ,
580
564
coord : Coord = NoCoord ,
581
565
nestingLevel : Int = ctx.nestingLevel): Symbol { type ThisName = N } = {
582
- val sym = new Symbol ().asInstanceOf [Symbol { type ThisName = N }]
583
- val denot = SymDenotation (sym, SymCommon (coord, ctx.base.nextSymId, nestingLevel), owner, name, flags, info, privateWithin)
584
- sym.initialDenot = denot
585
- sym.denot_=(denot)
586
- sym
566
+ val sym = SymDenotation (null , SymCommon (coord, ctx.base.nextSymId, nestingLevel), owner, name, flags, info, privateWithin)
567
+ sym.denot_=(sym)
568
+ sym.asInstanceOf [Symbol { type ThisName = N }]
587
569
}
588
570
589
571
/** Create a class symbol from its non-info fields and a function
@@ -598,11 +580,9 @@ object Symbols {
598
580
coord : Coord = NoCoord ,
599
581
assocFile : AbstractFile | Null = null )(using Context ): ClassSymbol
600
582
= {
601
- val cls = new ClassSymbol ()
602
- val denot = SymDenotation (cls, ClassCommon (coord, ctx.base.nextSymId, ctx.nestingLevel, assocFile), owner, name, flags, NoType , privateWithin)
603
- cls.initialDenot = denot
604
- cls.denot_=(denot)
605
- denot.info = infoFn(cls)
583
+ val cls = SymDenotation (null , ClassCommon (coord, ctx.base.nextSymId, ctx.nestingLevel, assocFile), owner, name, flags, NoType , privateWithin).asClass
584
+ cls.denot_=(cls)
585
+ cls.info = infoFn(cls)
606
586
cls
607
587
}
608
588
0 commit comments