Skip to content

Commit b730be1

Browse files
authored
Add TASTyInfo abstraction (#19089)
2 parents 55c2002 + eeb994c commit b730be1

File tree

6 files changed

+26
-30
lines changed

6 files changed

+26
-30
lines changed

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

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,15 @@ import dotty.tools.tasty.TastyVersion
88
* @param associatedFile The source or class file from which this class or
99
* the class containing this symbol was generated,
1010
* null if not applicable.
11-
* @param tastyVersion The TASTy version (major, minor, experimental)
12-
* @param explicitNulls This compilation unit has explicit nulls enabled?
11+
* @param tastyInfo Information about the TASTy from which this class was loaded.
12+
* None if not loaded from TASTy,
1313
*/
14-
class CompilationUnitInfo(
15-
val associatedFile: AbstractFile,
16-
val tastyVersion: Option[TastyVersion],
17-
val explicitNulls: Boolean
18-
) {
19-
20-
override def toString(): String =
21-
s"CompilationUnitInfo($associatedFile, $tastyVersion)"
22-
}
14+
case class CompilationUnitInfo(
15+
associatedFile: AbstractFile,
16+
tastyInfo: Option[TastyInfo],
17+
)
2318

2419
object CompilationUnitInfo:
25-
def apply(assocFile: AbstractFile | Null, explicitNulls: Boolean = false): CompilationUnitInfo | Null =
20+
def apply(assocFile: AbstractFile | Null): CompilationUnitInfo | Null =
2621
if assocFile == null then null
27-
else new CompilationUnitInfo(
28-
assocFile,
29-
tastyVersion = None,
30-
explicitNulls = explicitNulls,
31-
)
22+
else new CompilationUnitInfo(assocFile, tastyInfo = None)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,7 @@ class TastyLoader(val tastyFile: AbstractFile) extends SymbolLoader {
432432
val attributes = unpickler.tastyAttributes
433433
new CompilationUnitInfo(
434434
tastyFile,
435-
tastyVersion = Some(tastyVersion),
436-
explicitNulls = attributes.explicitNulls,
435+
tastyInfo = Some(TastyInfo(tastyVersion, attributes)),
437436
)
438437

439438
def description(using Context): String = "TASTy file " + tastyFile.toString

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,16 +281,11 @@ object Symbols extends SymUtils {
281281
def compilationUnitInfo(using Context): CompilationUnitInfo | Null =
282282
lastDenot.topLevelClass.compilationUnitInfo
283283

284-
/** The version of TASTy from which the symbol was loaded, None if not applicable. */
285-
def tastyVersion(using Context): Option[TastyVersion] =
284+
/** The info of the TASTy from which this symbol was loaded, None if not applicable. */
285+
def tastyInfo(using Context): Option[TastyInfo] =
286286
val compUnitInfo = compilationUnitInfo
287287
if compUnitInfo == null then None
288-
else compUnitInfo.tastyVersion
289-
290-
/** If this class has explicit nulls enabled */
291-
def explicitNulls(using Context): Boolean =
292-
val compUnitInfo = compilationUnitInfo
293-
compUnitInfo != null && compUnitInfo.explicitNulls
288+
else compUnitInfo.tastyInfo
294289

295290
/** The class file from which this class was generated, null if not applicable. */
296291
final def binaryFile(using Context): AbstractFile | Null = {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package dotty.tools.dotc.core
2+
3+
import dotty.tools.io.AbstractFile
4+
import dotty.tools.tasty.TastyVersion
5+
6+
/** Information about the TASTy of a class symbol.
7+
*
8+
* @param version The TASTy version (major, minor, experimental)
9+
* @param attributes Attributes of in the TASTy attributes section
10+
*/
11+
case class TastyInfo(version: TastyVersion, attributes: tasty.Attributes)

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,8 +1078,8 @@ trait Checking {
10781078
tree.op match {
10791079
case id @ Ident(name: Name) =>
10801080
def methCompiledBeforeDeprecation =
1081-
meth.tastyVersion match
1082-
case Some(version) => version.major == 28 && version.minor < 4 // compiled before 3.4
1081+
meth.tastyInfo match
1082+
case Some(info) => info.version.major == 28 && info.version.minor < 4 // compiled before 3.4
10831083
case _ => false // compiled with the current compiler
10841084
name.toTermName match {
10851085
case name: SimpleName

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class Namer { typer: Typer =>
248248
val cls =
249249
createOrRefine[ClassSymbol](tree, name, flags, ctx.owner,
250250
cls => adjustIfModule(new ClassCompleter(cls, tree)(ctx), tree),
251-
newClassSymbol(ctx.owner, name, _, _, _, tree.nameSpan, CompilationUnitInfo(ctx.source.file, explicitNulls = ctx.explicitNulls)))
251+
newClassSymbol(ctx.owner, name, _, _, _, tree.nameSpan, CompilationUnitInfo(ctx.source.file)))
252252
cls.completer.asInstanceOf[ClassCompleter].init()
253253
cls
254254
case tree: MemberDef =>

0 commit comments

Comments
 (0)