-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add compilation unit info to ClassSymbol
#19010
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
bishabosha
merged 10 commits into
scala:main
from
dotty-staging:keep-compilation-unit-info-in-symbol
Nov 23, 2023
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5e714dd
Add `CompilationUnitInfo` to `ClassSymbol`
nicolasstucki 83c05b6
Keep `TastyVersion` in `CompilationUnitInfo`
nicolasstucki ff0b153
Allow `infix enum`
nicolasstucki 8b44ffa
Deprecation warnings for old syntax: alphanumeric infix operators
nicolasstucki 0291fa8
Read TASTy header eagerly to avoid var in CompilationUnitInfo
nicolasstucki 91f8e3a
Add explicit nulls tasty attribute to CompilationUnit
nicolasstucki 2f36da4
Set explicit nulls in CompilationUnitInfo symbols from source
nicolasstucki e152b56
Review feedback
nicolasstucki 97d8171
Cache stable TASTyVersion
nicolasstucki 050859e
add scala3 library to tasty-core-scala2 project
bishabosha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
compiler/src/dotty/tools/dotc/core/CompilationUnitInfo.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
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 tastyVersion The TASTy version (major, minor, experimental) | ||
*/ | ||
class CompilationUnitInfo( | ||
val associatedFile: AbstractFile, | ||
private var tastyVersionOpt: Option[TastyVersion], | ||
) { | ||
|
||
def tastyVersion: Option[TastyVersion] = tastyVersionOpt | ||
|
||
/** Sets the TASTy version. Used to initialize the TASTy version when | ||
* Loading a TASTy file in TastyLoader. | ||
*/ | ||
def initTastyVersion(version: TastyVersion): Unit = | ||
tastyVersionOpt = Some(version) | ||
|
||
override def toString(): String = | ||
s"CompilationUnitInfo($associatedFile, $tastyVersion)" | ||
} | ||
|
||
object CompilationUnitInfo: | ||
def apply(assocFile: AbstractFile | Null): CompilationUnitInfo | Null = | ||
if assocFile == null then null | ||
else new CompilationUnitInfo(assocFile, tastyVersionOpt = None) // TODO use current TASTy version |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ import config.Printers.typr | |
import dotty.tools.dotc.classpath.FileUtils.isScalaBinary | ||
|
||
import scala.compiletime.uninitialized | ||
import dotty.tools.tasty.TastyVersion | ||
|
||
object Symbols { | ||
|
||
|
@@ -265,12 +266,27 @@ object Symbols { | |
|
||
/** The source or class file from which this class or | ||
* the class containing this symbol was generated, null if not applicable. | ||
* Note that this the returned classfile might be the top-level class | ||
* Note that the returned classfile might be from the top-level class | ||
* containing this symbol instead of the directly enclosing class. | ||
* Overridden in ClassSymbol | ||
*/ | ||
def associatedFile(using Context): AbstractFile | Null = | ||
lastDenot.topLevelClass.associatedFile | ||
val compUnitInfo = compilationUnitInfo | ||
if compUnitInfo == null then (null: AbstractFile | Null) | ||
else compUnitInfo.associatedFile | ||
|
||
/** The compilation unit info (associated file, tasty versions, ...). | ||
* Note that the returned CompilationUnitInfo might be from the top-level class | ||
* containing this symbol instead of the directly enclosing class. | ||
* Overridden in ClassSymbol | ||
*/ | ||
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] = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @EugeneFlesselle here is the new version of the TASTy version. I changed a bit your original design, now we only have a TASTy version if the symbol vas loaded from TASTy. For symbols created from source we can assume they have the current TASTy version. |
||
val compUnitInfo = compilationUnitInfo | ||
if compUnitInfo == null then None | ||
else compUnitInfo.tastyVersion | ||
|
||
/** The class file from which this class was generated, null if not applicable. */ | ||
final def binaryFile(using Context): AbstractFile | Null = { | ||
|
@@ -353,7 +369,7 @@ object Symbols { | |
def paramRef(using Context): TypeRef = denot.typeRef | ||
|
||
/** Copy a symbol, overriding selective fields. | ||
* Note that `coord` and `associatedFile` will be set from the fields in `owner`, not | ||
* Note that `coord` and `compilationUnitInfo` will be set from the fields in `owner`, not | ||
* the fields in `sym`. */ | ||
def copy(using Context)( | ||
owner: Symbol = this.owner, | ||
|
@@ -362,13 +378,14 @@ object Symbols { | |
info: Type = this.info, | ||
privateWithin: Symbol = this.privateWithin, | ||
coord: Coord = NoCoord, // Can be `= owner.coord` once we bootstrap | ||
associatedFile: AbstractFile | Null = null // Can be `= owner.associatedFile` once we bootstrap | ||
compUnitInfo: CompilationUnitInfo | Null = null // Can be `= owner.associatedFile` once we bootstrap | ||
): Symbol = { | ||
val coord1 = if (coord == NoCoord) owner.coord else coord | ||
val associatedFile1 = if (associatedFile == null) owner.associatedFile else associatedFile | ||
val compilationUnitInfo1 = if (compilationUnitInfo == null) owner.compilationUnitInfo else compilationUnitInfo | ||
|
||
|
||
if isClass then | ||
newClassSymbol(owner, name.asTypeName, flags, _ => info, privateWithin, coord1, associatedFile1) | ||
newClassSymbol(owner, name.asTypeName, flags, _ => info, privateWithin, coord1, compilationUnitInfo1) | ||
else | ||
newSymbol(owner, name, flags, info, privateWithin, coord1) | ||
} | ||
|
@@ -396,7 +413,7 @@ object Symbols { | |
type TermSymbol = Symbol { type ThisName = TermName } | ||
type TypeSymbol = Symbol { type ThisName = TypeName } | ||
|
||
class ClassSymbol private[Symbols] (coord: Coord, val assocFile: AbstractFile | Null, id: Int, nestingLevel: Int) | ||
class ClassSymbol private[Symbols] (coord: Coord, val compUnitInfo: CompilationUnitInfo | Null, id: Int, nestingLevel: Int) | ||
extends Symbol(coord, id, nestingLevel) { | ||
|
||
type ThisName = TypeName | ||
|
@@ -456,9 +473,9 @@ object Symbols { | |
} | ||
|
||
/** The source or class file from which this class was generated, null if not applicable. */ | ||
override def associatedFile(using Context): AbstractFile | Null = | ||
if assocFile != null || this.is(Package) || this.owner.is(Package) then assocFile | ||
else super.associatedFile | ||
override def compilationUnitInfo(using Context): CompilationUnitInfo | Null = | ||
if compUnitInfo != null || this.is(Package) || this.owner.is(Package) then compUnitInfo | ||
else super.compilationUnitInfo | ||
|
||
private var mySource: SourceFile = NoSource | ||
|
||
|
@@ -488,7 +505,7 @@ object Symbols { | |
} | ||
|
||
@sharable object NoSymbol extends Symbol(NoCoord, 0, 0) { | ||
override def associatedFile(using Context): AbstractFile | Null = NoSource.file | ||
override def compilationUnitInfo(using Context): CompilationUnitInfo | Null = CompilationUnitInfo(NoSource.file) | ||
override def recomputeDenot(lastd: SymDenotation)(using Context): SymDenotation = NoDenotation | ||
} | ||
|
||
|
@@ -537,9 +554,9 @@ object Symbols { | |
infoFn: ClassSymbol => Type, | ||
privateWithin: Symbol = NoSymbol, | ||
coord: Coord = NoCoord, | ||
assocFile: AbstractFile | Null = null)(using Context): ClassSymbol | ||
compUnitInfo: CompilationUnitInfo | Null = null)(using Context): ClassSymbol | ||
= { | ||
val cls = new ClassSymbol(coord, assocFile, ctx.base.nextSymId, ctx.nestingLevel) | ||
val cls = new ClassSymbol(coord, compUnitInfo, ctx.base.nextSymId, ctx.nestingLevel) | ||
val denot = SymDenotation(cls, owner, name, flags, infoFn(cls), privateWithin) | ||
cls.denot = denot | ||
cls | ||
|
@@ -555,11 +572,11 @@ object Symbols { | |
selfInfo: Type = NoType, | ||
privateWithin: Symbol = NoSymbol, | ||
coord: Coord = NoCoord, | ||
assocFile: AbstractFile | Null = null)(using Context): ClassSymbol = | ||
compUnitInfo: CompilationUnitInfo | Null = null)(using Context): ClassSymbol = | ||
newClassSymbol( | ||
owner, name, flags, | ||
ClassInfo(owner.thisType, _, parents, decls, selfInfo), | ||
privateWithin, coord, assocFile) | ||
privateWithin, coord, compUnitInfo) | ||
|
||
/** Same as `newCompleteClassSymbol` except that `parents` can be a list of arbitrary | ||
* types which get normalized into type refs and parameter bindings. | ||
|
@@ -572,15 +589,15 @@ object Symbols { | |
selfInfo: Type = NoType, | ||
privateWithin: Symbol = NoSymbol, | ||
coord: Coord = NoCoord, | ||
assocFile: AbstractFile | Null = null)(using Context): ClassSymbol = { | ||
compUnitInfo: CompilationUnitInfo | Null = null)(using Context): ClassSymbol = { | ||
def completer = new LazyType { | ||
def complete(denot: SymDenotation)(using Context): Unit = { | ||
val cls = denot.asClass.classSymbol | ||
val decls = newScope | ||
denot.info = ClassInfo(owner.thisType, cls, parentTypes.map(_.dealias), decls, selfInfo) | ||
} | ||
} | ||
newClassSymbol(owner, name, flags, completer, privateWithin, coord, assocFile) | ||
newClassSymbol(owner, name, flags, completer, privateWithin, coord, compUnitInfo) | ||
} | ||
|
||
def newRefinedClassSymbol(coord: Coord = NoCoord)(using Context): ClassSymbol = | ||
|
@@ -598,15 +615,15 @@ object Symbols { | |
infoFn: (TermSymbol, ClassSymbol) => Type, // typically a ModuleClassCompleterWithDecls | ||
privateWithin: Symbol = NoSymbol, | ||
coord: Coord = NoCoord, | ||
assocFile: AbstractFile | Null = null)(using Context): TermSymbol | ||
compUnitInfo: CompilationUnitInfo | Null = null)(using Context): TermSymbol | ||
= { | ||
val base = owner.thisType | ||
val modclsFlags = clsFlags | ModuleClassCreationFlags | ||
val modclsName = name.toTypeName.adjustIfModuleClass(modclsFlags) | ||
val module = newSymbol( | ||
owner, name, modFlags | ModuleValCreationFlags, NoCompleter, privateWithin, coord) | ||
val modcls = newClassSymbol( | ||
owner, modclsName, modclsFlags, infoFn(module, _), privateWithin, coord, assocFile) | ||
owner, modclsName, modclsFlags, infoFn(module, _), privateWithin, coord, compUnitInfo) | ||
module.info = | ||
if (modcls.isCompleted) TypeRef(owner.thisType, modcls) | ||
else new ModuleCompleter(modcls) | ||
|
@@ -627,12 +644,12 @@ object Symbols { | |
decls: Scope, | ||
privateWithin: Symbol = NoSymbol, | ||
coord: Coord = NoCoord, | ||
assocFile: AbstractFile | Null = null)(using Context): TermSymbol = | ||
compUnitInfo: CompilationUnitInfo | Null = null)(using Context): TermSymbol = | ||
newModuleSymbol( | ||
owner, name, modFlags, clsFlags, | ||
(module, modcls) => ClassInfo( | ||
owner.thisType, modcls, parents, decls, TermRef(owner.thisType, module)), | ||
privateWithin, coord, assocFile) | ||
privateWithin, coord, compUnitInfo) | ||
|
||
/** Same as `newCompleteModuleSymbol` except that `parents` can be a list of arbitrary | ||
* types which get normalized into type refs and parameter bindings. | ||
|
@@ -646,7 +663,7 @@ object Symbols { | |
decls: Scope, | ||
privateWithin: Symbol = NoSymbol, | ||
coord: Coord = NoCoord, | ||
assocFile: AbstractFile | Null = null)(using Context): TermSymbol = { | ||
compUnitInfo: CompilationUnitInfo | Null = null)(using Context): TermSymbol = { | ||
def completer(module: Symbol) = new LazyType { | ||
def complete(denot: SymDenotation)(using Context): Unit = { | ||
val cls = denot.asClass.classSymbol | ||
|
@@ -657,7 +674,7 @@ object Symbols { | |
newModuleSymbol( | ||
owner, name, modFlags, clsFlags, | ||
(module, modcls) => completer(module), | ||
privateWithin, coord, assocFile) | ||
privateWithin, coord, compUnitInfo) | ||
} | ||
|
||
/** Create a package symbol with associated package class | ||
|
@@ -697,17 +714,17 @@ object Symbols { | |
/** Create a stub symbol that will issue a missing reference error | ||
* when attempted to be completed. | ||
*/ | ||
def newStubSymbol(owner: Symbol, name: Name, file: AbstractFile | Null = null)(using Context): Symbol = { | ||
def newStubSymbol(owner: Symbol, name: Name, compUnitInfo: CompilationUnitInfo | Null = null)(using Context): Symbol = { | ||
def stubCompleter = new StubInfo() | ||
val normalizedOwner = if (owner.is(ModuleVal)) owner.moduleClass else owner | ||
typr.println(s"creating stub for ${name.show}, owner = ${normalizedOwner.denot.debugString}, file = $file") | ||
typr.println(s"creating stub for ${name.show}, owner = ${normalizedOwner.denot.debugString}, compilation unit = $compUnitInfo") | ||
typr.println(s"decls = ${normalizedOwner.unforcedDecls.toList.map(_.debugString).mkString("\n ")}") // !!! DEBUG | ||
//if (base.settings.debug.value) throw new Error() | ||
val stub = name match { | ||
case name: TermName => | ||
newModuleSymbol(normalizedOwner, name, EmptyFlags, EmptyFlags, stubCompleter, assocFile = file) | ||
newModuleSymbol(normalizedOwner, name, EmptyFlags, EmptyFlags, stubCompleter, compUnitInfo = compUnitInfo) | ||
case name: TypeName => | ||
newClassSymbol(normalizedOwner, name, EmptyFlags, stubCompleter, assocFile = file) | ||
newClassSymbol(normalizedOwner, name, EmptyFlags, stubCompleter, compUnitInfo = compUnitInfo) | ||
} | ||
stub | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.