@@ -43,37 +43,45 @@ object Symbols {
43
43
* @param coord The coordinates of the symbol (a position or an index)
44
44
* @param id A unique identifier of the symbol (unique per ContextBase)
45
45
*/
46
- class Symbol private [Symbols ] (private var myCoord : Coord , val id : Int , val nestingLevel : Int )
46
+ class Symbol private [Symbols ] ()
47
47
extends ParamInfo , SrcPos , printing.Showable {
48
48
49
49
type ThisName <: Name
50
50
51
+ util.Stats .record(s " new ${getClass}" )
52
+
53
+ var initialDenot : SymDenotation = _
54
+
51
55
// assert(id != 723)
52
56
53
- def coord : Coord = myCoord
57
+ /** A unique identifier of the symbol (unique per ContextBase) */
58
+ def id = initialDenot.common.id
59
+
60
+ def nestingLevel = initialDenot.common.nestingLevel
61
+
62
+ /** The coordinates of the symbol (a position or an index) */
63
+ def coord : Coord = initialDenot.common.coord
54
64
55
65
/** Set the coordinate of this class, this is only useful when the coordinate is
56
66
* not known at symbol creation. This is the case for root symbols
57
67
* unpickled from TASTY.
58
68
*
59
69
* @pre coord == NoCoord
60
70
*/
61
- private [core] def coord_= (c : Coord ): Unit = {
71
+ private [core] def coord_= (c : Coord ): Unit =
62
72
// assert(myCoord == NoCoord)
63
73
// This assertion fails for CommentPickling test.
64
74
// TODO: figure out what's wrong in the setup of CommentPicklingTest and re-enable assertion.
65
- myCoord = c
66
- }
67
-
68
- private var myDefTree : Tree | Null = null
75
+ initialDenot.common.coord = c
69
76
70
77
/** The tree defining the symbol at pickler time, EmptyTree if none was retained */
71
78
def defTree : Tree =
72
- if (myDefTree == null ) tpd.EmptyTree else myDefTree.nn
79
+ val dt = initialDenot.common.defTree
80
+ if dt == null then tpd.EmptyTree else dt.nn
73
81
74
82
/** Set defining tree if this symbol retains its definition tree */
75
83
def defTree_= (tree : Tree )(using Context ): Unit =
76
- if ( retainsDefTree) myDefTree = tree
84
+ if retainsDefTree then initialDenot.common.defTree = tree
77
85
78
86
/** Does this symbol retain its definition tree?
79
87
* A good policy for this needs to balance costs and benefits, where
@@ -266,7 +274,7 @@ object Symbols {
266
274
* Overridden in ClassSymbol
267
275
*/
268
276
def associatedFile (using Context ): AbstractFile | Null =
269
- lastDenot.topLevelClass. associatedFile
277
+ lastDenot.associatedFile
270
278
271
279
/** The class file from which this class was generated, null if not applicable. */
272
280
final def binaryFile (using Context ): AbstractFile | Null = {
@@ -392,22 +400,21 @@ object Symbols {
392
400
type TermSymbol = Symbol { type ThisName = TermName }
393
401
type TypeSymbol = Symbol { type ThisName = TypeName }
394
402
395
- class ClassSymbol private [Symbols ] (coord : Coord , val assocFile : AbstractFile | Null , id : Int , nestingLevel : Int )
396
- extends Symbol (coord, id, nestingLevel) {
403
+ class ClassSymbol private [Symbols ] extends Symbol {
404
+
405
+ util.Stats .record(" ClassSymbol" )
397
406
398
407
type ThisName = TypeName
399
408
400
409
type TreeOrProvider = tpd.TreeProvider | tpd.Tree
401
410
402
- private var myTree : TreeOrProvider = tpd.EmptyTree
403
-
404
411
/** If this is a top-level class and `-Yretain-trees` (or `-from-tasty`) is set.
405
412
* Returns the TypeDef tree (possibly wrapped inside PackageDefs) for this class, otherwise EmptyTree.
406
413
* This will force the info of the class.
407
414
*/
408
415
def rootTree (using Context ): Tree = rootTreeContaining(" " )
409
416
410
- /** Same as `tree ` but load tree only if `id == ""` or the tree might contain `id`.
417
+ /** Same as `rootTree ` but load tree only if `id == ""` or the tree might contain `id`.
411
418
* For Tasty trees this means consulting whether the name table defines `id`.
412
419
* For already loaded trees, we maintain the referenced ids in an attachment.
413
420
*/
@@ -416,11 +423,11 @@ object Symbols {
416
423
case _ : NoCompleter =>
417
424
case _ => denot.ensureCompleted()
418
425
}
419
- myTree match {
426
+ rootTreeOrProvider match {
420
427
case fn : TreeProvider =>
421
428
if (id.isEmpty || fn.mightContain(id)) {
422
429
val tree = fn.tree
423
- myTree = tree
430
+ rootTreeOrProvider = tree
424
431
tree
425
432
}
426
433
else tpd.EmptyTree
@@ -429,10 +436,10 @@ object Symbols {
429
436
}
430
437
}
431
438
432
- def rootTreeOrProvider : TreeOrProvider = myTree
439
+ def rootTreeOrProvider : TreeOrProvider = initialDenot.common.asClass.treeOrProvider
433
440
434
441
private [dotc] def rootTreeOrProvider_= (t : TreeOrProvider )(using Context ): Unit =
435
- myTree = t
442
+ initialDenot.common.asClass.treeOrProvider = t
436
443
437
444
private def mightContain (tree : Tree , id : String )(using Context ): Boolean = {
438
445
val ids = tree.getAttachment(Ids ) match {
@@ -451,30 +458,26 @@ object Symbols {
451
458
ids.binarySearch(id) >= 0
452
459
}
453
460
454
- /** The source or class file from which this class was generated, null if not applicable. */
455
- override def associatedFile (using Context ): AbstractFile | Null =
456
- if assocFile != null || this .is(Package ) || this .owner.is(Package ) then assocFile
457
- else super .associatedFile
458
-
459
- private var mySource : SourceFile = NoSource
461
+ def assocFile : AbstractFile | Null = initialDenot.common.asClass.assocFile
460
462
461
463
final def sourceOfClass (using Context ): SourceFile = {
462
- if ! mySource.exists && ! denot.is(Package ) then
464
+ val common = initialDenot.common.asClass
465
+ if ! common.source.exists && ! denot.is(Package ) then
463
466
// this allows sources to be added in annotations after `sourceOfClass` is first called
464
467
val file = associatedFile
465
468
if file != null && file.extension != " class" then
466
- mySource = ctx.getSource(file)
469
+ common.source = ctx.getSource(file)
467
470
else
468
- mySource = defn.patchSource(this )
469
- if ! mySource .exists then
470
- mySource = atPhaseNoLater(flattenPhase) {
471
+ common.source = defn.patchSource(this )
472
+ if ! common.source .exists then
473
+ common.source = atPhaseNoLater(flattenPhase) {
471
474
denot.topLevelClass.unforcedAnnotation(defn.SourceFileAnnot ) match
472
475
case Some (sourceAnnot) => sourceAnnot.argumentConstant(0 ) match
473
476
case Some (Constant (path : String )) => ctx.getSource(path)
474
477
case none => NoSource
475
478
case none => NoSource
476
479
}
477
- mySource
480
+ common.source
478
481
}
479
482
480
483
final def classDenot (using Context ): ClassDenotation =
@@ -483,7 +486,11 @@ object Symbols {
483
486
override protected def prefixString : String = " ClassSymbol"
484
487
}
485
488
486
- @ sharable object NoSymbol extends Symbol (NoCoord , 0 , 0 ) {
489
+ @ sharable object NoSymbol extends Symbol {
490
+ override def coord = NoCoord
491
+ override def id = 0
492
+ override def nestingLevel = 0
493
+ override def defTree = tpd.EmptyTree
487
494
override def associatedFile (using Context ): AbstractFile | Null = NoSource .file
488
495
override def recomputeDenot (lastd : SymDenotation )(using Context ): SymDenotation = NoDenotation
489
496
}
@@ -517,8 +524,9 @@ object Symbols {
517
524
privateWithin : Symbol = NoSymbol ,
518
525
coord : Coord = NoCoord ,
519
526
nestingLevel : Int = ctx.nestingLevel): Symbol { type ThisName = N } = {
520
- val sym = new Symbol (coord, ctx.base.nextSymId, nestingLevel).asInstanceOf [Symbol { type ThisName = N }]
521
- val denot = SymDenotation (sym, owner, name, flags, info, privateWithin)
527
+ val sym = new Symbol ().asInstanceOf [Symbol { type ThisName = N }]
528
+ val denot = SymDenotation (sym, SymCommon (coord, ctx.base.nextSymId, nestingLevel), owner, name, flags, info, privateWithin)
529
+ sym.initialDenot = denot
522
530
sym.denot = denot
523
531
sym
524
532
}
@@ -535,9 +543,11 @@ object Symbols {
535
543
coord : Coord = NoCoord ,
536
544
assocFile : AbstractFile | Null = null )(using Context ): ClassSymbol
537
545
= {
538
- val cls = new ClassSymbol (coord, assocFile, ctx.base.nextSymId, ctx.nestingLevel)
539
- val denot = SymDenotation (cls, owner, name, flags, infoFn(cls), privateWithin)
546
+ val cls = new ClassSymbol ()
547
+ val denot = SymDenotation (cls, ClassCommon (coord, ctx.base.nextSymId, ctx.nestingLevel, assocFile), owner, name, flags, NoType , privateWithin)
548
+ cls.initialDenot = denot
540
549
cls.denot = denot
550
+ denot.info = infoFn(cls)
541
551
cls
542
552
}
543
553
0 commit comments