Skip to content

Commit c643250

Browse files
committed
Refactor
1 parent 54c9222 commit c643250

7 files changed

+40
-31
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,11 @@ case class AggregateClassPath(aggregates: Seq[ClassPath]) extends ClassPath {
131131
mergedEntries(index) = BinaryAndSourceFilesEntry(existing, entry)
132132
case (entry: BinaryFileEntry, existing: SourceFileEntry) =>
133133
mergedEntries(index) = BinaryAndSourceFilesEntry(entry, existing)
134-
case (entry @ TastyFileEntry(_, None), _: ClassFileEntry) =>
134+
case (entry: StandaloneTastyFileEntry, _: ClassFileEntry) =>
135+
// Here we do not create a TastyFileEntry(entry.file) because the TASTy and the classfile
136+
// come from different classpaths. These may not have the same TASTy UUID.
135137
mergedEntries(index) = entry
136-
// Here we do not create a TastyFileEntry(entry.file, existing.source.get)
137-
// because the TASTy and the the classfile come from different classpaths.
138-
// These may not have the same TASTy UUID.
139-
case (entry @ TastyFileEntry(_, None), BinaryAndSourceFilesEntry(_: ClassFileEntry, sourceEntry)) =>
138+
case (entry: StandaloneTastyFileEntry, BinaryAndSourceFilesEntry(_: ClassFileEntry, sourceEntry)) =>
140139
mergedEntries(index) = BinaryAndSourceFilesEntry(entry, sourceEntry)
141140
case _ =>
142141
}

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,35 @@ sealed trait BinaryFileEntry extends ClassRepresentation {
5050

5151
/** A classfile or .sig that does not have an associated TASTy file */
5252
private[dotty] final case class ClassFileEntry(file: AbstractFile) extends BinaryFileEntry {
53-
def classfile: Option[AbstractFile] = Some(file)
54-
def tasty: Option[AbstractFile] = None
53+
def binary: Option[AbstractFile] = Some(file)
5554
}
5655

57-
/** A TASTy file that may have an associated TASTy */
58-
private[dotty] final case class TastyFileEntry(file: AbstractFile, classfile: Option[AbstractFile]) extends BinaryFileEntry {
59-
def tasty: Option[AbstractFile] = Some(file)
56+
// object TastyFileEntry:
57+
// def apply(file: AbstractFile, hasClassfile: Boolean): BinaryFileEntry =
58+
// if hasClassfile then TastyFileEntry(file)
59+
// else StandaloneTastyFileEntry(file)
60+
61+
/** A TASTy file that has an associated TASTy */
62+
private[dotty] final case class TastyFileEntry(file: AbstractFile) extends BinaryFileEntry {
63+
def binary: Option[AbstractFile] = Some(file)
64+
}
65+
66+
/** A TASTy file that does not have an associated TASTy */
67+
private[dotty] final case class StandaloneTastyFileEntry(file: AbstractFile) extends BinaryFileEntry {
68+
def binary: Option[AbstractFile] = Some(file)
6069
}
6170

6271
private[dotty] final case class SourceFileEntry(file: AbstractFile) extends ClassRepresentation {
6372
final def fileName: String = file.name
6473
def name: String = FileUtils.stripSourceExtension(file.name)
65-
def classfile: Option[AbstractFile] = None
66-
def tasty: Option[AbstractFile] = None
74+
def binary: Option[AbstractFile] = None
6775
def source: Option[AbstractFile] = Some(file)
6876
}
6977

7078
private[dotty] final case class BinaryAndSourceFilesEntry(binaryEntry: BinaryFileEntry, sourceEntry: SourceFileEntry) extends ClassRepresentation {
7179
final def fileName: String = binaryEntry.fileName
7280
def name: String = binaryEntry.name
73-
def classfile: Option[AbstractFile] = binaryEntry.classfile
74-
def tasty: Option[AbstractFile] = binaryEntry.tasty
81+
def binary: Option[AbstractFile] = binaryEntry.binary
7582
def source: Option[AbstractFile] = sourceEntry.source
7683
}
7784

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,8 @@ case class DirectoryClassPath(dir: JFile) extends JFileDirectoryLookup[BinaryFil
277277
override def findClass(className: String): Option[ClassRepresentation] =
278278
val classfile = findClassFile(className)
279279
findTastyFile(className) match
280-
case Some(file) => Some(TastyFileEntry(file, classfile))
280+
case Some(file) =>
281+
Some(if classfile.isDefined then TastyFileEntry(file) else StandaloneTastyFileEntry(file))
281282
case None => classfile.map(ClassFileEntry(_))
282283

283284
def findClassFile(className: String): Option[AbstractFile] = {
@@ -295,8 +296,9 @@ case class DirectoryClassPath(dir: JFile) extends JFileDirectoryLookup[BinaryFil
295296
}
296297

297298
protected def createFileEntry(file: AbstractFile): BinaryFileEntry =
298-
if file.isTasty then TastyFileEntry(file, Option(file.resolveSiblingWithExtension("class")))
299-
else ClassFileEntry(file)
299+
if !file.isTasty then ClassFileEntry(file)
300+
else if file.resolveSiblingWithExtension("class") != null then TastyFileEntry(file)
301+
else StandaloneTastyFileEntry(file)
300302

301303
protected def isMatchingFile(f: JFile): Boolean =
302304
f.isTasty || (f.isClass && f.classToTasty.isEmpty)

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,12 @@ case class VirtualDirectoryClassPath(dir: VirtualDirectory) extends ClassPath wi
4545
else
4646
val classfile = lookupPath(parentDir)(pathSeq.last + ".class" :: Nil, directory = false)
4747
val tasty = lookupPath(parentDir)(pathSeq.last + ".tasty" :: Nil, directory = false)
48-
if tasty != null then Some(TastyFileEntry(tasty, Option(classfile)))
49-
else if classfile != null then Some(ClassFileEntry(classfile))
50-
else None
48+
if tasty != null then
49+
if classfile != null then Some(TastyFileEntry(tasty))
50+
else Some(StandaloneTastyFileEntry(tasty))
51+
else
52+
if classfile != null then Some(ClassFileEntry(classfile))
53+
else None
5154

5255
def findClassFile(className: String): Option[AbstractFile] = {
5356
val pathSeq = FileUtils.dirPath(className).split(java.io.File.separator)
@@ -59,8 +62,9 @@ case class VirtualDirectoryClassPath(dir: VirtualDirectory) extends ClassPath wi
5962
private[dotty] def classes(inPackage: PackageName): Seq[BinaryFileEntry] = files(inPackage)
6063

6164
protected def createFileEntry(file: AbstractFile): BinaryFileEntry =
62-
if file.isTasty then TastyFileEntry(file, Option(file.resolveSiblingWithExtension("class")))
63-
else ClassFileEntry(file)
65+
if !file.isTasty then ClassFileEntry(file)
66+
else if file.resolveSiblingWithExtension("class") != null then TastyFileEntry(file)
67+
else StandaloneTastyFileEntry(file)
6468

6569
protected def isMatchingFile(f: AbstractFile): Boolean =
6670
f.isTasty || (f.isClass && f.classToTasty.isEmpty)

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,15 @@ object ZipAndJarClassPathFactory extends ZipAndJarFileLookupFactory {
5151
override def findClass(className: String): Option[BinaryFileEntry] = {
5252
val (pkg, simpleClassName) = PackageNameUtils.separatePkgAndClassNames(className)
5353
val binaries = files(PackageName(pkg), simpleClassName + ".tasty", simpleClassName + ".class")
54-
val classfile = binaries.find(_.classfile.isDefined).flatMap(_.classfile)
55-
binaries.find(_.tasty.isDefined).flatMap(_.tasty) match
56-
case Some(file) => Some(TastyFileEntry(file, classfile))
57-
case None => classfile.map(ClassFileEntry(_))
54+
binaries.find(_.binary.isDefined)
5855
}
5956

6057
override private[dotty] def classes(inPackage: PackageName): Seq[BinaryFileEntry] = files(inPackage)
6158

6259
override protected def createFileEntry(file: FileZipArchive#Entry): BinaryFileEntry =
63-
if file.isTasty then TastyFileEntry(file, Option(file.resolveSiblingWithExtension("class")))
64-
else ClassFileEntry(file)
60+
if !file.isTasty then ClassFileEntry(file)
61+
else if file.resolveSiblingWithExtension("class") != null then TastyFileEntry(file)
62+
else StandaloneTastyFileEntry(file)
6563

6664
override protected def isRequiredFileType(file: AbstractFile): Boolean =
6765
file.isTasty || (file.isClass && file.classToTasty.isEmpty)

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.tasty.orElse(classRep.classfile), classRep.source): @unchecked) match {
192+
((classRep.binary, 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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,7 @@ object ClassPath {
200200
trait ClassRepresentation {
201201
def fileName: String
202202
def name: String
203-
def classfile: Option[AbstractFile]
204-
def tasty: Option[AbstractFile]
203+
def binary: Option[AbstractFile]
205204
def source: Option[AbstractFile]
206205

207206
/** returns the length of `name` by stripping the extension of `fileName`

0 commit comments

Comments
 (0)