Skip to content

Simplify classpath code - #26712

Open
SolalPirelli wants to merge 4 commits into
scala:mainfrom
dotty-staging:solal/classpath-simplify
Open

Simplify classpath code#26712
SolalPirelli wants to merge 4 commits into
scala:mainfrom
dotty-staging:solal/classpath-simplify

Conversation

@SolalPirelli

@SolalPirelli SolalPirelli commented Aug 5, 2026

Copy link
Copy Markdown
Contributor
  • Move ClassPath to the classpath package where it should be (it was in io)
  • Delete dead code and types
  • Delete wrapper type PackageEntry (makes it harder to cache packages, since you need to create a PackageEntry just to test whether a string is in a collection)
  • Simplify code
    • Stop using arrays / vectors / ... when all we need is iterables
  • Use caches more in JrtClassPath (turns out Files.exists in jrt:// internally throws an exception and catches it...)

Makes some benchmarks 1% faster, others are noise.

Have you relied on LLM-based tools in this contribution?

No

How was the solution tested?

Covered by existing tests (this is a refactoring)

* the Scala 2 library as it has one JAR containing the class files and one JAR containing the TASTy files.
* As classpath orders are not guaranteed to be deterministic we might end up having the TASTy in a later classpath entry.
*/
private def mergeClassesAndSources(entries: scala.collection.Seq[ClassRepresentation]): Seq[ClassRepresentation] = {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dead

}
entriesBuffer.toIndexedSeq
}
aggregates.flatMap(getEntries).filter(e => seenNames.add(e.name))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was overly convoluted

*/
package dotty.tools.dotc.classpath

import dotty.tools.io.{AbstractFile, ClassRepresentation, FileExtension}

@SolalPirelli SolalPirelli Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes in this file:

  • add ClassPath, unmodified, from io (yes this file is already named ClassPath but it didn't contain ClassPath...)
  • remove subclasses of ClassRepresentation that were unused
    • including making BinaryFileEntry concrete and delete its subclasses since they all did the same thing and were never pattern-matched outside of now-dead code

protected def toAbstractFile(f: JFile): AbstractFile = f.toPath.toPlainFile
protected def isPackage(f: JFile): Boolean = f.isPackage

assert(dir.asInstanceOf[JFile | Null] != null, "Directory file in DirectoryFileLookup cannot be null")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was testing the type system....

// Right now the compiler always asks for those at the root package anyway (inPackage == ""),
// and we have no way to query the file system for "entries without a dot in their name",
// so might as well cache them
private val allPackages = listFiles(dir).map(f => f.getFileName.toString)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved up since it's now used by multiple methods

@dottybot

dottybot commented Aug 8, 2026

Copy link
Copy Markdown
Member

Benchmarks started. Workflow run.

@dottybot

dottybot commented Aug 9, 2026

Copy link
Copy Markdown
Member

Benchmarks completed. Overview.

@SolalPirelli
SolalPirelli marked this pull request as ready for review August 10, 2026 06:54
@SolalPirelli
SolalPirelli requested a review from mbovel August 10, 2026 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants