Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions compiler/src/dotty/tools/dotc/core/CompilationUnitInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@ package dotty.tools.dotc.core
import dotty.tools.io.AbstractFile
import dotty.tools.tasty.TastyVersion

/** Information about the compilation unit of a class symbol.
*
* @param associatedFile The source or class file from which this class or
* the class containing this symbol was generated,
* null if not applicable.
* @param tastyInfo Information about the TASTy from which this class was loaded.
* None if not loaded from TASTy,
*/
case class CompilationUnitInfo(
/** Information about the compilation unit of a class symbol. */
trait CompilationUnitInfo:
/** The source or class file from which this class or the class containing
* this symbol was generated, null if not applicable. */
def associatedFile: AbstractFile

/** Information about the TASTy from which this class was loaded.
* [[None]] if not loaded from TASTy. */
def tastyInfo: Option[TastyInfo]

private case class ConcreteCompilationUnitInfo(
associatedFile: AbstractFile,
tastyInfo: Option[TastyInfo],
)
tastyInfo: Option[TastyInfo]
) extends CompilationUnitInfo

object CompilationUnitInfo:
def apply(assocFile: AbstractFile | Null): CompilationUnitInfo | Null =
if assocFile == null then null
else new CompilationUnitInfo(assocFile, tastyInfo = None)
else ConcreteCompilationUnitInfo(assocFile, tastyInfo = None)

def apply(assocFile: AbstractFile, tastyInfo: Option[TastyInfo]): CompilationUnitInfo =
ConcreteCompilationUnitInfo(assocFile, tastyInfo)
12 changes: 8 additions & 4 deletions compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala
Original file line number Diff line number Diff line change
Expand Up @@ -473,12 +473,17 @@ class ClassfileLoader(val classfile: AbstractFile) extends SymbolLoader {

class TastyLoader(val tastyFile: AbstractFile) extends SymbolLoader {
val isBestEffortTasty = tastyFile.hasBetastyExtension
private val unpickler: tasty.DottyUnpickler =

lazy val tastyBytes = tastyFile.toByteArray

private lazy val unpickler: tasty.DottyUnpickler =
handleUnpicklingExceptions:
val tastyBytes = tastyFile.toByteArray
new tasty.DottyUnpickler(tastyFile, tastyBytes, isBestEffortTasty) // reads header and name table

val compilationUnitInfo: CompilationUnitInfo | Null = unpickler.compilationUnitInfo
val compilationUnitInfo: CompilationUnitInfo =
new CompilationUnitInfo:
def associatedFile: AbstractFile = tastyFile
def tastyInfo: Option[TastyInfo] = unpickler.compilationUnitInfo.tastyInfo

def description(using Context): String =
if isBestEffortTasty then "Best Effort TASTy file " + tastyFile.toString
Expand All @@ -488,7 +493,6 @@ class TastyLoader(val tastyFile: AbstractFile) extends SymbolLoader {
handleUnpicklingExceptions:
val (classRoot, moduleRoot) = rootDenots(root.asClass)
if (!isBestEffortTasty || ctx.withBestEffortTasty) then
val tastyBytes = tastyFile.toByteArray
unpickler.enter(roots = Set(classRoot, moduleRoot, moduleRoot.sourceModule))(using ctx.withSource(util.NoSource))
if mayLoadTreesFromTasty || isBestEffortTasty then
classRoot.classSymbol.rootTreeOrProvider = unpickler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class DottyUnpickler(
import unpickler.header.{majorVersion, minorVersion, experimentalVersion}
val tastyVersion = TastyVersion(majorVersion, minorVersion, experimentalVersion)
val tastyInfo = TastyInfo(tastyVersion, tastyAttributes)
new CompilationUnitInfo(tastyFile, Some(tastyInfo))
CompilationUnitInfo(tastyFile, Some(tastyInfo))

private val posUnpicklerOpt = unpickler.unpickle(new PositionsSectionUnpickler)
private val commentUnpicklerOpt = unpickler.unpickle(new CommentsSectionUnpickler)
Expand Down
Loading