Skip to content

Commit e2bf342

Browse files
mbovelWojciechMazur
authored andcommitted
Make compilationUnitInfo of TastyLoader lazy
[Cherry-picked 4140995]
1 parent 2401232 commit e2bf342

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,25 @@ package dotty.tools.dotc.core
33
import dotty.tools.io.AbstractFile
44
import dotty.tools.tasty.TastyVersion
55

6-
/** Information about the compilation unit of a class symbol.
7-
*
8-
* @param associatedFile The source or class file from which this class or
9-
* the class containing this symbol was generated,
10-
* null if not applicable.
11-
* @param tastyInfo Information about the TASTy from which this class was loaded.
12-
* None if not loaded from TASTy,
13-
*/
14-
case class CompilationUnitInfo(
6+
/** Information about the compilation unit of a class symbol. */
7+
trait CompilationUnitInfo:
8+
/** The source or class file from which this class or the class containing
9+
* this symbol was generated, null if not applicable. */
10+
def associatedFile: AbstractFile
11+
12+
/** Information about the TASTy from which this class was loaded.
13+
* [[None]] if not loaded from TASTy. */
14+
def tastyInfo: Option[TastyInfo]
15+
16+
private case class ConcreteCompilationUnitInfo(
1517
associatedFile: AbstractFile,
16-
tastyInfo: Option[TastyInfo],
17-
)
18+
tastyInfo: Option[TastyInfo]
19+
) extends CompilationUnitInfo
1820

1921
object CompilationUnitInfo:
2022
def apply(assocFile: AbstractFile | Null): CompilationUnitInfo | Null =
2123
if assocFile == null then null
22-
else new CompilationUnitInfo(assocFile, tastyInfo = None)
24+
else ConcreteCompilationUnitInfo(assocFile, tastyInfo = None)
25+
26+
def apply(assocFile: AbstractFile, tastyInfo: Option[TastyInfo]): CompilationUnitInfo =
27+
ConcreteCompilationUnitInfo(assocFile, tastyInfo)

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,12 +473,17 @@ class ClassfileLoader(val classfile: AbstractFile) extends SymbolLoader {
473473

474474
class TastyLoader(val tastyFile: AbstractFile) extends SymbolLoader {
475475
val isBestEffortTasty = tastyFile.hasBetastyExtension
476-
private val unpickler: tasty.DottyUnpickler =
476+
477+
lazy val tastyBytes = tastyFile.toByteArray
478+
479+
private lazy val unpickler: tasty.DottyUnpickler =
477480
handleUnpicklingExceptions:
478-
val tastyBytes = tastyFile.toByteArray
479481
new tasty.DottyUnpickler(tastyFile, tastyBytes, isBestEffortTasty) // reads header and name table
480482

481-
val compilationUnitInfo: CompilationUnitInfo | Null = unpickler.compilationUnitInfo
483+
val compilationUnitInfo: CompilationUnitInfo =
484+
new CompilationUnitInfo:
485+
def associatedFile: AbstractFile = tastyFile
486+
def tastyInfo: Option[TastyInfo] = unpickler.compilationUnitInfo.tastyInfo
482487

483488
def description(using Context): String =
484489
if isBestEffortTasty then "Best Effort TASTy file " + tastyFile.toString
@@ -488,7 +493,6 @@ class TastyLoader(val tastyFile: AbstractFile) extends SymbolLoader {
488493
handleUnpicklingExceptions:
489494
val (classRoot, moduleRoot) = rootDenots(root.asClass)
490495
if (!isBestEffortTasty || ctx.withBestEffortTasty) then
491-
val tastyBytes = tastyFile.toByteArray
492496
unpickler.enter(roots = Set(classRoot, moduleRoot, moduleRoot.sourceModule))(using ctx.withSource(util.NoSource))
493497
if mayLoadTreesFromTasty || isBestEffortTasty then
494498
classRoot.classSymbol.rootTreeOrProvider = unpickler

compiler/src/dotty/tools/dotc/core/tasty/DottyUnpickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class DottyUnpickler(
7373
import unpickler.header.{majorVersion, minorVersion, experimentalVersion}
7474
val tastyVersion = TastyVersion(majorVersion, minorVersion, experimentalVersion)
7575
val tastyInfo = TastyInfo(tastyVersion, tastyAttributes)
76-
new CompilationUnitInfo(tastyFile, Some(tastyInfo))
76+
CompilationUnitInfo(tastyFile, Some(tastyInfo))
7777

7878
private val posUnpicklerOpt = unpickler.unpickle(new PositionsSectionUnpickler)
7979
private val commentUnpicklerOpt = unpickler.unpickle(new CommentsSectionUnpickler)

0 commit comments

Comments
 (0)