Skip to content

Commit

Permalink
Add TASTyInfo abstraction (scala#19089)
Browse files Browse the repository at this point in the history
  • Loading branch information
bishabosha committed Nov 27, 2023
2 parents 55c2002 + eeb994c commit b730be1
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 30 deletions.
25 changes: 8 additions & 17 deletions compiler/src/dotty/tools/dotc/core/CompilationUnitInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,15 @@ import dotty.tools.tasty.TastyVersion
* @param associatedFile The source or class file from which this class or
* the class containing this symbol was generated,
* null if not applicable.
* @param tastyVersion The TASTy version (major, minor, experimental)
* @param explicitNulls This compilation unit has explicit nulls enabled?
* @param tastyInfo Information about the TASTy from which this class was loaded.
* None if not loaded from TASTy,
*/
class CompilationUnitInfo(
val associatedFile: AbstractFile,
val tastyVersion: Option[TastyVersion],
val explicitNulls: Boolean
) {

override def toString(): String =
s"CompilationUnitInfo($associatedFile, $tastyVersion)"
}
case class CompilationUnitInfo(
associatedFile: AbstractFile,
tastyInfo: Option[TastyInfo],
)

object CompilationUnitInfo:
def apply(assocFile: AbstractFile | Null, explicitNulls: Boolean = false): CompilationUnitInfo | Null =
def apply(assocFile: AbstractFile | Null): CompilationUnitInfo | Null =
if assocFile == null then null
else new CompilationUnitInfo(
assocFile,
tastyVersion = None,
explicitNulls = explicitNulls,
)
else new CompilationUnitInfo(assocFile, tastyInfo = None)
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,7 @@ class TastyLoader(val tastyFile: AbstractFile) extends SymbolLoader {
val attributes = unpickler.tastyAttributes
new CompilationUnitInfo(
tastyFile,
tastyVersion = Some(tastyVersion),
explicitNulls = attributes.explicitNulls,
tastyInfo = Some(TastyInfo(tastyVersion, attributes)),
)

def description(using Context): String = "TASTy file " + tastyFile.toString
Expand Down
11 changes: 3 additions & 8 deletions compiler/src/dotty/tools/dotc/core/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -281,16 +281,11 @@ object Symbols extends SymUtils {
def compilationUnitInfo(using Context): CompilationUnitInfo | Null =
lastDenot.topLevelClass.compilationUnitInfo

/** The version of TASTy from which the symbol was loaded, None if not applicable. */
def tastyVersion(using Context): Option[TastyVersion] =
/** The info of the TASTy from which this symbol was loaded, None if not applicable. */
def tastyInfo(using Context): Option[TastyInfo] =
val compUnitInfo = compilationUnitInfo
if compUnitInfo == null then None
else compUnitInfo.tastyVersion

/** If this class has explicit nulls enabled */
def explicitNulls(using Context): Boolean =
val compUnitInfo = compilationUnitInfo
compUnitInfo != null && compUnitInfo.explicitNulls
else compUnitInfo.tastyInfo

/** The class file from which this class was generated, null if not applicable. */
final def binaryFile(using Context): AbstractFile | Null = {
Expand Down
11 changes: 11 additions & 0 deletions compiler/src/dotty/tools/dotc/core/TastyInfo.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dotty.tools.dotc.core

import dotty.tools.io.AbstractFile
import dotty.tools.tasty.TastyVersion

/** Information about the TASTy of a class symbol.
*
* @param version The TASTy version (major, minor, experimental)
* @param attributes Attributes of in the TASTy attributes section
*/
case class TastyInfo(version: TastyVersion, attributes: tasty.Attributes)
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1078,8 +1078,8 @@ trait Checking {
tree.op match {
case id @ Ident(name: Name) =>
def methCompiledBeforeDeprecation =
meth.tastyVersion match
case Some(version) => version.major == 28 && version.minor < 4 // compiled before 3.4
meth.tastyInfo match
case Some(info) => info.version.major == 28 && info.version.minor < 4 // compiled before 3.4
case _ => false // compiled with the current compiler
name.toTermName match {
case name: SimpleName
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class Namer { typer: Typer =>
val cls =
createOrRefine[ClassSymbol](tree, name, flags, ctx.owner,
cls => adjustIfModule(new ClassCompleter(cls, tree)(ctx), tree),
newClassSymbol(ctx.owner, name, _, _, _, tree.nameSpan, CompilationUnitInfo(ctx.source.file, explicitNulls = ctx.explicitNulls)))
newClassSymbol(ctx.owner, name, _, _, _, tree.nameSpan, CompilationUnitInfo(ctx.source.file)))
cls.completer.asInstanceOf[ClassCompleter].init()
cls
case tree: MemberDef =>
Expand Down

0 comments on commit b730be1

Please sign in to comment.