Skip to content

Add TASTyInfo abstraction #19089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 27, 2023
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
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