@@ -265,12 +265,21 @@ object Symbols {
265
265
266
266
/** The source or class file from which this class or
267
267
* the class containing this symbol was generated, null if not applicable.
268
- * Note that this the returned classfile might be the top-level class
268
+ * Note that the returned classfile might be from the top-level class
269
269
* containing this symbol instead of the directly enclosing class.
270
- * Overridden in ClassSymbol
271
270
*/
272
271
def associatedFile (using Context ): AbstractFile | Null =
273
- lastDenot.topLevelClass.associatedFile
272
+ val compUnitInfo = compilationUnitInfo
273
+ if compUnitInfo == null then (null : AbstractFile | Null )
274
+ else compUnitInfo.associatedFile
275
+
276
+ /** The compilation unit info (associated file, tasty versions, ...).
277
+ * Note that the returned CompilationUnitInfo might be from the top-level class
278
+ * containing this symbol instead of the directly enclosing class.
279
+ * Overridden in ClassSymbol
280
+ */
281
+ def compilationUnitInfo (using Context ): CompilationUnitInfo | Null =
282
+ lastDenot.topLevelClass.compilationUnitInfo
274
283
275
284
/** The class file from which this class was generated, null if not applicable. */
276
285
final def binaryFile (using Context ): AbstractFile | Null = {
@@ -353,7 +362,7 @@ object Symbols {
353
362
def paramRef (using Context ): TypeRef = denot.typeRef
354
363
355
364
/** Copy a symbol, overriding selective fields.
356
- * Note that `coord` and `associatedFile ` will be set from the fields in `owner`, not
365
+ * Note that `coord` and `compilationUnitInfo ` will be set from the fields in `owner`, not
357
366
* the fields in `sym`. */
358
367
def copy (using Context )(
359
368
owner : Symbol = this .owner,
@@ -362,13 +371,14 @@ object Symbols {
362
371
info : Type = this .info,
363
372
privateWithin : Symbol = this .privateWithin,
364
373
coord : Coord = NoCoord , // Can be `= owner.coord` once we bootstrap
365
- associatedFile : AbstractFile | Null = null // Can be `= owner.associatedFile` once we bootstrap
374
+ compUnitInfo : CompilationUnitInfo | Null = null // Can be `= owner.associatedFile` once we bootstrap
366
375
): Symbol = {
367
376
val coord1 = if (coord == NoCoord ) owner.coord else coord
368
- val associatedFile1 = if (associatedFile == null ) owner.associatedFile else associatedFile
377
+ val compilationUnitInfo1 = if (compilationUnitInfo == null ) owner.compilationUnitInfo else compilationUnitInfo
378
+
369
379
370
380
if isClass then
371
- newClassSymbol(owner, name.asTypeName, flags, _ => info, privateWithin, coord1, associatedFile1 )
381
+ newClassSymbol(owner, name.asTypeName, flags, _ => info, privateWithin, coord1, compilationUnitInfo1 )
372
382
else
373
383
newSymbol(owner, name, flags, info, privateWithin, coord1)
374
384
}
@@ -396,7 +406,7 @@ object Symbols {
396
406
type TermSymbol = Symbol { type ThisName = TermName }
397
407
type TypeSymbol = Symbol { type ThisName = TypeName }
398
408
399
- class ClassSymbol private [Symbols ] (coord : Coord , val assocFile : AbstractFile | Null , id : Int , nestingLevel : Int )
409
+ class ClassSymbol private [Symbols ] (coord : Coord , val compUnitInfo : CompilationUnitInfo | Null , id : Int , nestingLevel : Int )
400
410
extends Symbol (coord, id, nestingLevel) {
401
411
402
412
type ThisName = TypeName
@@ -456,9 +466,9 @@ object Symbols {
456
466
}
457
467
458
468
/** The source or class file from which this class was generated, null if not applicable. */
459
- override def associatedFile (using Context ): AbstractFile | Null =
460
- if assocFile != null || this .is(Package ) || this .owner.is(Package ) then assocFile
461
- else super .associatedFile
469
+ override def compilationUnitInfo (using Context ): CompilationUnitInfo | Null =
470
+ if compUnitInfo != null || this .is(Package ) || this .owner.is(Package ) then compUnitInfo
471
+ else super .compilationUnitInfo
462
472
463
473
private var mySource : SourceFile = NoSource
464
474
@@ -488,7 +498,7 @@ object Symbols {
488
498
}
489
499
490
500
@ sharable object NoSymbol extends Symbol (NoCoord , 0 , 0 ) {
491
- override def associatedFile (using Context ): AbstractFile | Null = NoSource .file
501
+ override def compilationUnitInfo (using Context ): CompilationUnitInfo | Null = CompilationUnitInfo ( NoSource .file)
492
502
override def recomputeDenot (lastd : SymDenotation )(using Context ): SymDenotation = NoDenotation
493
503
}
494
504
@@ -537,9 +547,9 @@ object Symbols {
537
547
infoFn : ClassSymbol => Type ,
538
548
privateWithin : Symbol = NoSymbol ,
539
549
coord : Coord = NoCoord ,
540
- assocFile : AbstractFile | Null = null )(using Context ): ClassSymbol
550
+ compUnitInfo : CompilationUnitInfo | Null = null )(using Context ): ClassSymbol
541
551
= {
542
- val cls = new ClassSymbol (coord, assocFile , ctx.base.nextSymId, ctx.nestingLevel)
552
+ val cls = new ClassSymbol (coord, compUnitInfo , ctx.base.nextSymId, ctx.nestingLevel)
543
553
val denot = SymDenotation (cls, owner, name, flags, infoFn(cls), privateWithin)
544
554
cls.denot = denot
545
555
cls
@@ -555,11 +565,11 @@ object Symbols {
555
565
selfInfo : Type = NoType ,
556
566
privateWithin : Symbol = NoSymbol ,
557
567
coord : Coord = NoCoord ,
558
- assocFile : AbstractFile | Null = null )(using Context ): ClassSymbol =
568
+ compUnitInfo : CompilationUnitInfo | Null = null )(using Context ): ClassSymbol =
559
569
newClassSymbol(
560
570
owner, name, flags,
561
571
ClassInfo (owner.thisType, _, parents, decls, selfInfo),
562
- privateWithin, coord, assocFile )
572
+ privateWithin, coord, compUnitInfo )
563
573
564
574
/** Same as `newCompleteClassSymbol` except that `parents` can be a list of arbitrary
565
575
* types which get normalized into type refs and parameter bindings.
@@ -572,15 +582,15 @@ object Symbols {
572
582
selfInfo : Type = NoType ,
573
583
privateWithin : Symbol = NoSymbol ,
574
584
coord : Coord = NoCoord ,
575
- assocFile : AbstractFile | Null = null )(using Context ): ClassSymbol = {
585
+ compUnitInfo : CompilationUnitInfo | Null = null )(using Context ): ClassSymbol = {
576
586
def completer = new LazyType {
577
587
def complete (denot : SymDenotation )(using Context ): Unit = {
578
588
val cls = denot.asClass.classSymbol
579
589
val decls = newScope
580
590
denot.info = ClassInfo (owner.thisType, cls, parentTypes.map(_.dealias), decls, selfInfo)
581
591
}
582
592
}
583
- newClassSymbol(owner, name, flags, completer, privateWithin, coord, assocFile )
593
+ newClassSymbol(owner, name, flags, completer, privateWithin, coord, compUnitInfo )
584
594
}
585
595
586
596
def newRefinedClassSymbol (coord : Coord = NoCoord )(using Context ): ClassSymbol =
@@ -598,15 +608,15 @@ object Symbols {
598
608
infoFn : (TermSymbol , ClassSymbol ) => Type , // typically a ModuleClassCompleterWithDecls
599
609
privateWithin : Symbol = NoSymbol ,
600
610
coord : Coord = NoCoord ,
601
- assocFile : AbstractFile | Null = null )(using Context ): TermSymbol
611
+ compUnitInfo : CompilationUnitInfo | Null = null )(using Context ): TermSymbol
602
612
= {
603
613
val base = owner.thisType
604
614
val modclsFlags = clsFlags | ModuleClassCreationFlags
605
615
val modclsName = name.toTypeName.adjustIfModuleClass(modclsFlags)
606
616
val module = newSymbol(
607
617
owner, name, modFlags | ModuleValCreationFlags , NoCompleter , privateWithin, coord)
608
618
val modcls = newClassSymbol(
609
- owner, modclsName, modclsFlags, infoFn(module, _), privateWithin, coord, assocFile )
619
+ owner, modclsName, modclsFlags, infoFn(module, _), privateWithin, coord, compUnitInfo )
610
620
module.info =
611
621
if (modcls.isCompleted) TypeRef (owner.thisType, modcls)
612
622
else new ModuleCompleter (modcls)
@@ -627,12 +637,12 @@ object Symbols {
627
637
decls : Scope ,
628
638
privateWithin : Symbol = NoSymbol ,
629
639
coord : Coord = NoCoord ,
630
- assocFile : AbstractFile | Null = null )(using Context ): TermSymbol =
640
+ compUnitInfo : CompilationUnitInfo | Null = null )(using Context ): TermSymbol =
631
641
newModuleSymbol(
632
642
owner, name, modFlags, clsFlags,
633
643
(module, modcls) => ClassInfo (
634
644
owner.thisType, modcls, parents, decls, TermRef (owner.thisType, module)),
635
- privateWithin, coord, assocFile )
645
+ privateWithin, coord, compUnitInfo )
636
646
637
647
/** Same as `newCompleteModuleSymbol` except that `parents` can be a list of arbitrary
638
648
* types which get normalized into type refs and parameter bindings.
@@ -646,7 +656,7 @@ object Symbols {
646
656
decls : Scope ,
647
657
privateWithin : Symbol = NoSymbol ,
648
658
coord : Coord = NoCoord ,
649
- assocFile : AbstractFile | Null = null )(using Context ): TermSymbol = {
659
+ compUnitInfo : CompilationUnitInfo | Null = null )(using Context ): TermSymbol = {
650
660
def completer (module : Symbol ) = new LazyType {
651
661
def complete (denot : SymDenotation )(using Context ): Unit = {
652
662
val cls = denot.asClass.classSymbol
@@ -657,7 +667,7 @@ object Symbols {
657
667
newModuleSymbol(
658
668
owner, name, modFlags, clsFlags,
659
669
(module, modcls) => completer(module),
660
- privateWithin, coord, assocFile )
670
+ privateWithin, coord, compUnitInfo )
661
671
}
662
672
663
673
/** Create a package symbol with associated package class
@@ -697,17 +707,17 @@ object Symbols {
697
707
/** Create a stub symbol that will issue a missing reference error
698
708
* when attempted to be completed.
699
709
*/
700
- def newStubSymbol (owner : Symbol , name : Name , file : AbstractFile | Null = null )(using Context ): Symbol = {
710
+ def newStubSymbol (owner : Symbol , name : Name , compUnitInfo : CompilationUnitInfo | Null = null )(using Context ): Symbol = {
701
711
def stubCompleter = new StubInfo ()
702
712
val normalizedOwner = if (owner.is(ModuleVal )) owner.moduleClass else owner
703
- typr.println(s " creating stub for ${name.show}, owner = ${normalizedOwner.denot.debugString}, file = $file " )
713
+ typr.println(s " creating stub for ${name.show}, owner = ${normalizedOwner.denot.debugString}, compilation unit = $compUnitInfo " )
704
714
typr.println(s " decls = ${normalizedOwner.unforcedDecls.toList.map(_.debugString).mkString(" \n " )}" ) // !!! DEBUG
705
715
// if (base.settings.debug.value) throw new Error()
706
716
val stub = name match {
707
717
case name : TermName =>
708
- newModuleSymbol(normalizedOwner, name, EmptyFlags , EmptyFlags , stubCompleter, assocFile = file )
718
+ newModuleSymbol(normalizedOwner, name, EmptyFlags , EmptyFlags , stubCompleter, compUnitInfo = compUnitInfo )
709
719
case name : TypeName =>
710
- newClassSymbol(normalizedOwner, name, EmptyFlags , stubCompleter, assocFile = file )
720
+ newClassSymbol(normalizedOwner, name, EmptyFlags , stubCompleter, compUnitInfo = compUnitInfo )
711
721
}
712
722
stub
713
723
}
0 commit comments