Skip to content

Commit f47d276

Browse files
committed
add CompilationUnitInfo to the CompilationUnit
1 parent 639d8e5 commit f47d276

File tree

7 files changed

+17
-13
lines changed

7 files changed

+17
-13
lines changed

compiler/src/dotty/tools/dotc/CompilationUnit.scala

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import scala.annotation.internal.sharable
1919
import scala.util.control.NoStackTrace
2020
import transform.MacroAnnotations
2121

22-
class CompilationUnit protected (val source: SourceFile) {
22+
class CompilationUnit protected (val source: SourceFile, val info: CompilationUnitInfo | Null) {
2323

2424
override def toString: String = source.toString
2525

@@ -106,7 +106,7 @@ class CompilationUnit protected (val source: SourceFile) {
106106
myAssignmentSpans.nn
107107
}
108108

109-
@sharable object NoCompilationUnit extends CompilationUnit(NoSource) {
109+
@sharable object NoCompilationUnit extends CompilationUnit(NoSource, info = null) {
110110

111111
override def isJava: Boolean = false
112112

@@ -122,13 +122,14 @@ object CompilationUnit {
122122

123123
/** Make a compilation unit for top class `clsd` with the contents of the `unpickled` tree */
124124
def apply(clsd: ClassDenotation, unpickled: Tree, forceTrees: Boolean)(using Context): CompilationUnit =
125-
val file = clsd.symbol.associatedFile.nn
126-
apply(SourceFile(file, Array.empty[Char]), unpickled, forceTrees)
125+
val compilationUnitInfo = clsd.symbol.compilationUnitInfo.nn
126+
val file = compilationUnitInfo.associatedFile
127+
apply(SourceFile(file, Array.empty[Char]), unpickled, forceTrees, compilationUnitInfo)
127128

128129
/** Make a compilation unit, given picked bytes and unpickled tree */
129-
def apply(source: SourceFile, unpickled: Tree, forceTrees: Boolean)(using Context): CompilationUnit = {
130+
def apply(source: SourceFile, unpickled: Tree, forceTrees: Boolean, info: CompilationUnitInfo)(using Context): CompilationUnit = {
130131
assert(!unpickled.isEmpty, unpickled)
131-
val unit1 = new CompilationUnit(source)
132+
val unit1 = new CompilationUnit(source, info)
132133
unit1.tpdTree = unpickled
133134
if (forceTrees) {
134135
val force = new Force
@@ -156,7 +157,8 @@ object CompilationUnit {
156157
NoSource
157158
}
158159
else source
159-
new CompilationUnit(src)
160+
val info = if src.exists then CompilationUnitInfo(src.file) else null
161+
new CompilationUnit(src, info)
160162
}
161163

162164
/** Force the tree to be loaded */

compiler/src/dotty/tools/dotc/fromtasty/AlreadyLoadedCompilationUnit.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ import dotty.tools.dotc.util.NoSource
77
* encountered, and attempted to inspect, something that has already been loaded, for example a Scala primitive or a
88
* library class like Option.
99
*/
10-
class AlreadyLoadedCompilationUnit(val className: String) extends CompilationUnit(NoSource)
10+
class AlreadyLoadedCompilationUnit(val className: String) extends CompilationUnit(NoSource, null)

compiler/src/dotty/tools/dotc/fromtasty/TASTYCompilationUnit.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ package dotty.tools.dotc.fromtasty
33
import dotty.tools.dotc.CompilationUnit
44
import dotty.tools.dotc.util.NoSource
55

6-
class TASTYCompilationUnit(val className: String) extends CompilationUnit(NoSource) {
6+
class TASTYCompilationUnit(val className: String) extends CompilationUnit(NoSource, null) {
77
override def toString: String = s"class file $className"
88
}

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)))
251+
newClassSymbol(ctx.owner, name, _, _, _, tree.nameSpan, ctx.compilationUnit.info))
252252
cls.completer.asInstanceOf[ClassCompleter].init()
253253
cls
254254
case tree: MemberDef =>

compiler/src/dotty/tools/repl/ReplCompiler.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import dotty.tools.dotc.ast.Trees.*
44
import dotty.tools.dotc.ast.{tpd, untpd}
55
import dotty.tools.dotc.ast.tpd.TreeOps
66
import dotty.tools.dotc.core.Contexts.*
7+
import dotty.tools.dotc.core.CompilationUnitInfo
78
import dotty.tools.dotc.core.Decorators.*
89
import dotty.tools.dotc.core.Flags.*
910
import dotty.tools.dotc.core.Names.*
@@ -233,7 +234,7 @@ object ReplCompiler:
233234
val objectNames = mutable.Map.empty[Int, TermName]
234235
end ReplCompiler
235236

236-
class ReplCompilationUnit(source: SourceFile) extends CompilationUnit(source):
237+
class ReplCompilationUnit(source: SourceFile) extends CompilationUnit(source, CompilationUnitInfo(source.file)):
237238
override def isSuspendable: Boolean = false
238239

239240
/** A placeholder phase that receives parse trees..

staging/src/scala/quoted/staging/ExprCompilationUnit.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ import dotty.tools.dotc.CompilationUnit
55
import dotty.tools.dotc.util.NoSource
66

77
/** Compilation unit containing the contents of a quoted expression */
8-
private class ExprCompilationUnit(val exprBuilder: Quotes => Expr[?]) extends CompilationUnit(NoSource)
8+
private class ExprCompilationUnit(val exprBuilder: Quotes => Expr[?]) extends CompilationUnit(NoSource, null)

staging/src/scala/quoted/staging/QuoteCompiler.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@ private class QuoteCompiler extends Compiler:
9595
val classTree = ClassDef(cls, DefDef(cls.primaryConstructor.asTerm), run :: Nil)
9696
val tree = PackageDef(ref(defn.RootPackage).asInstanceOf[Ident], classTree :: Nil).withSpan(pos)
9797
val source = SourceFile.virtual("<quoted.Expr>", "")
98+
val unitInfo = CompilationUnitInfo(source.file, tastyInfo = None)
9899
result = Left(outputClassName.toString)
99-
Some(CompilationUnit(source, tree, forceTrees = true))
100+
Some(CompilationUnit(source, tree, forceTrees = true, unitInfo))
100101
}
101102

102103
/** Get the literal value if this tree only contains a literal tree */

0 commit comments

Comments
 (0)