Skip to content

Commit

Permalink
Add explicit nulls tasty attribute to CompilationUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Nov 21, 2023
1 parent a4fc774 commit 2a0282f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion compiler/src/dotty/tools/dotc/core/CompilationUnitInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import dotty.tools.tasty.TastyVersion
* the class containing this symbol was generated,
* null if not applicable.
* @param tastyVersion The TASTy version (major, minor, experimental)
* @param tastyExplicitNulls Was this compilation unit compiled with explicit nulls?
*/
class CompilationUnitInfo(
val associatedFile: AbstractFile,
val tastyVersion: Option[TastyVersion],
val tastyExplicitNulls: Boolean
) {

override def toString(): String =
Expand All @@ -22,4 +24,8 @@ class CompilationUnitInfo(
object CompilationUnitInfo:
def apply(assocFile: AbstractFile | Null): CompilationUnitInfo | Null =
if assocFile == null then null
else new CompilationUnitInfo(assocFile, tastyVersion = None) // TODO use current TASTy version
else new CompilationUnitInfo(
assocFile,
tastyVersion = None,
tastyExplicitNulls = false // TODO track explicit nulls for current compilation units (not only TASTy)
)
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,11 @@ class TastyLoader(val tastyFile: AbstractFile) extends SymbolLoader {

def compilationUnitInfo: CompilationUnitInfo | Null =
val tastyHeader = unpickler.unpickler.header
val attributes = unpickler.tastyAttributes
new CompilationUnitInfo(
tastyFile,
tastyVersion = Some(tastyHeader.version),
tastyExplicitNulls = attributes.explicitNulls,
)

def description(using Context): String = "TASTy file " + tastyFile.toString
Expand Down
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/core/tasty/DottyUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class DottyUnpickler(bytes: Array[Byte], mode: UnpickleMode = UnpickleMode.TopLe
private val attributeUnpicklerOpt = unpickler.unpickle(new AttributesSectionUnpickler)
private val treeUnpickler = unpickler.unpickle(treeSectionUnpickler(posUnpicklerOpt, commentUnpicklerOpt, attributeUnpicklerOpt)).get

def tastyAttributes: Attributes =
attributeUnpicklerOpt.map(_.attributes).getOrElse(Attributes(false, false))

/** Enter all toplevel classes and objects into their scopes
* @param roots a set of SymDenotations that should be overwritten by unpickling
*/
Expand Down

0 comments on commit 2a0282f

Please sign in to comment.