Skip to content

Commit ce9413b

Browse files
committed
refector
1 parent cf73804 commit ce9413b

File tree

4 files changed

+17
-28
lines changed

4 files changed

+17
-28
lines changed

compiler/src/dotty/tools/dotc/classpath/AggregateClassPath.scala

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ case class AggregateClassPath(aggregates: Seq[ClassPath]) extends ClassPath {
115115
* having the TASTy in a later classpath entry.
116116
*/
117117
private def mergeClassesAndSources(entries: scala.collection.Seq[ClassRepresentation]): Seq[ClassRepresentation] = {
118+
def onlyClassEntry(entry: ClassRepresentation): Boolean = !entry.tasty.isDefined && entry.classfile.isDefined
119+
def onlyTastyEntry(entry: ClassRepresentation): Boolean = !entry.classfile.isDefined && entry.tasty.isDefined
118120
// based on the implementation from MergedClassPath
119121
var count = 0
120122
val indices = util.HashMap[String, Int]()
@@ -126,19 +128,16 @@ case class AggregateClassPath(aggregates: Seq[ClassPath]) extends ClassPath {
126128
if (indices.contains(name)) {
127129
val index = indices(name)
128130
val existing = mergedEntries(index)
129-
130-
if !existing.binary.isDefined && entry.binary.isDefined then
131-
mergedEntries(index) = BinaryAndSourceFilesEntry(entry, existing)
132-
else if
133-
existing.classfile.isDefined && !existing.tasty.isDefined
134-
&& !entry.classfile.isDefined && entry.tasty.isDefined
135-
then
136-
mergedEntries(index) = existing.source match
137-
case Some(source) => BinaryAndSourceFilesEntry(entry, existing)
138-
case None => entry
139-
140-
if (existing.source.isEmpty && entry.source.isDefined)
141-
mergedEntries(index) = BinaryAndSourceFilesEntry(existing, entry)
131+
(entry, existing) match
132+
case (entry: SourceFileEntry, existing: BinaryFileEntry) =>
133+
mergedEntries(index) = BinaryAndSourceFilesEntry(existing, entry)
134+
case (entry: BinaryFileEntry, existing: SourceFileEntry) =>
135+
mergedEntries(index) = BinaryAndSourceFilesEntry(entry, existing)
136+
case (entry: BinaryFileEntry, existing: BinaryFileEntry) if onlyClassEntry(existing) && onlyTastyEntry(entry) =>
137+
mergedEntries(index) = entry
138+
case (entry: BinaryFileEntry, existing: BinaryAndSourceFilesEntry) if onlyClassEntry(existing) && onlyTastyEntry(entry) =>
139+
mergedEntries(index) = BinaryAndSourceFilesEntry(entry, existing.sourceEntry)
140+
case _ =>
142141
}
143142
else {
144143
indices(name) = count

compiler/src/dotty/tools/dotc/classpath/ClassPath.scala

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ object ClassPathEntries {
1616

1717
trait BinaryFileEntry extends ClassRepresentation {
1818
def file: AbstractFile
19-
def binary: Option[AbstractFile] = Some(file)
19+
final def fileName: String = file.name
20+
final def name: String = FileUtils.stripClassExtension(file.name) // class name
21+
final def source: Option[AbstractFile] = None
2022
}
2123

2224
case class PackageName(dottedString: String) {
@@ -46,36 +48,25 @@ trait PackageEntry {
4648
}
4749

4850
private[dotty] case class ClassFileEntry(file: AbstractFile) extends BinaryFileEntry {
49-
final def fileName: String = file.name
50-
def name: String = FileUtils.stripClassExtension(file.name) // class name
5151
def classfile: Option[AbstractFile] = Some(file)
5252
def tasty: Option[AbstractFile] = None
53-
def source: Option[AbstractFile] = None
5453
}
5554

5655
private[dotty] case class TastyFileEntry(file: AbstractFile, classfile: Option[AbstractFile]) extends BinaryFileEntry {
57-
final def fileName: String = file.name
58-
def name: String = FileUtils.stripClassExtension(file.name) // class name
5956
def tasty: Option[AbstractFile] = Some(file)
60-
def source: Option[AbstractFile] = None
6157
}
6258

6359
private[dotty] case class SourceFileEntry(file: AbstractFile) extends ClassRepresentation {
6460
final def fileName: String = file.name
6561
def name: String = FileUtils.stripSourceExtension(file.name)
66-
def binary: Option[AbstractFile] = None
6762
def classfile: Option[AbstractFile] = None
6863
def tasty: Option[AbstractFile] = None
6964
def source: Option[AbstractFile] = Some(file)
7065
}
7166

72-
private[dotty] case class BinaryAndSourceFilesEntry(binaryEntry: ClassRepresentation, sourceEntry: ClassRepresentation) extends ClassRepresentation {
73-
// TODO set these types in constructor
74-
assert(binaryEntry.isInstanceOf[BinaryFileEntry])
75-
assert(sourceEntry.isInstanceOf[SourceFileEntry])
67+
private[dotty] case class BinaryAndSourceFilesEntry(binaryEntry: BinaryFileEntry, sourceEntry: SourceFileEntry) extends ClassRepresentation {
7668
final def fileName: String = binaryEntry.fileName
7769
def name: String = binaryEntry.name
78-
def binary: Option[AbstractFile] = binaryEntry.binary
7970
def classfile: Option[AbstractFile] = binaryEntry.classfile
8071
def tasty: Option[AbstractFile] = binaryEntry.tasty
8172
def source: Option[AbstractFile] = sourceEntry.source

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ object SymbolLoaders {
189189
/** Initialize toplevel class and module symbols in `owner` from class path representation `classRep`
190190
*/
191191
def initializeFromClassPath(owner: Symbol, classRep: ClassRepresentation)(using Context): Unit =
192-
((classRep.binary, classRep.source): @unchecked) match {
192+
((classRep.tasty.orElse(classRep.classfile), classRep.source): @unchecked) match {
193193
case (Some(bin), Some(src)) if needCompile(bin, src) && !binaryOnly(owner, nameOf(classRep)) =>
194194
if (ctx.settings.verbose.value) report.inform("[symloader] picked up newer source file for " + src.path)
195195
enterToplevelsFromSource(owner, nameOf(classRep), src)

compiler/src/dotty/tools/io/ClassPath.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ object ClassPath {
200200
trait ClassRepresentation {
201201
def fileName: String
202202
def name: String
203-
def binary: Option[AbstractFile]
204203
def classfile: Option[AbstractFile]
205204
def tasty: Option[AbstractFile]
206205
def source: Option[AbstractFile]

0 commit comments

Comments
 (0)