Skip to content

Commit 91351e3

Browse files
authored
remove deadcode in the compiler (#24505)
- Move the `ScalaClassLoader` file to the repl - Remove deadcode and the `dotty.tools.runner` package - Remove deadcode `WorklistAlgorithm` - Remove reflective calls for JDK9+ classes.
2 parents add10eb + 01330c9 commit 91351e3

File tree

12 files changed

+59
-335
lines changed

12 files changed

+59
-335
lines changed

compiler/src/dotty/tools/MainGenericCompiler.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ import java.io.File
77
import java.lang.Thread
88
import scala.annotation.internal.sharable
99
import dotty.tools.dotc.util.ClasspathFromClassloader
10-
import dotty.tools.runner.ObjectRunner
1110
import dotty.tools.dotc.config.Properties.envOrNone
1211
import dotty.tools.io.Jar
13-
import dotty.tools.runner.ScalaClassLoader
1412
import java.nio.file.Paths
1513
import dotty.tools.dotc.config.CommandLineParser
1614
import dotty.tools.scripting.StringDriver

compiler/src/dotty/tools/backend/WorklistAlgorithm.scala

Lines changed: 0 additions & 57 deletions
This file was deleted.

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

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import java.net.{URI, URL}
88
import java.nio.file.{FileSystems, Files}
99

1010
import dotty.tools.dotc.classpath.PackageNameUtils.{packageContains, separatePkgAndClassNames}
11-
import dotty.tools.io.{AbstractFile, PlainFile, ClassPath, ClassRepresentation, EfficientClassPath, JDK9Reflectors}
11+
import dotty.tools.io.{AbstractFile, PlainFile, ClassPath, ClassRepresentation, EfficientClassPath}
1212
import FileUtils.*
1313
import PlainFile.toPlainFile
1414

@@ -124,34 +124,21 @@ trait JFileDirectoryLookup[FileEntryType <: ClassRepresentation] extends Directo
124124
}
125125

126126
object JrtClassPath {
127-
import java.nio.file.*, java.net.URI
128-
def apply(release: Option[String]): Option[ClassPath] = {
129-
import scala.util.Properties.*
130-
if (!isJavaAtLeast("9")) None
131-
else {
132-
// Longer term we'd like an official API for this in the JDK
133-
// Discussion: http://mail.openjdk.java.net/pipermail/compiler-dev/2018-March/thread.html#11738
134-
135-
val currentMajorVersion: Int = JDK9Reflectors.runtimeVersionMajor(JDK9Reflectors.runtimeVersion()).intValue()
136-
release match {
137-
case Some(v) if v.toInt < currentMajorVersion =>
138-
try {
139-
val ctSym = Paths.get(javaHome).resolve("lib").resolve("ct.sym")
140-
if (Files.notExists(ctSym)) None
141-
else Some(new CtSymClassPath(ctSym, v.toInt))
142-
} catch {
143-
case NonFatal(_) => None
144-
}
145-
case _ =>
146-
try {
147-
val fs = FileSystems.getFileSystem(URI.create("jrt:/"))
148-
Some(new JrtClassPath(fs))
149-
} catch {
150-
case _: ProviderNotFoundException | _: FileSystemNotFoundException => None
151-
}
152-
}
153-
}
154-
}
127+
import java.nio.file.*, java.net.URI, scala.util.Properties
128+
def apply(release: Option[String]): Option[ClassPath] =
129+
// Longer term we'd like an official API for this in the JDK
130+
// Discussion: http://mail.openjdk.java.net/pipermail/compiler-dev/2018-March/thread.html#11738
131+
release match
132+
case Some(v) if v.toInt < Runtime.version().feature() =>
133+
try
134+
val ctSym = Paths.get(Properties.javaHome).resolve("lib").resolve("ct.sym")
135+
if (Files.notExists(ctSym)) None
136+
else Some(new CtSymClassPath(ctSym, v.toInt))
137+
catch case NonFatal(_) => None
138+
case _ =>
139+
try Some(new JrtClassPath(FileSystems.getFileSystem(URI.create("jrt:/"))))
140+
catch case _: ProviderNotFoundException | _: FileSystemNotFoundException => None
141+
end apply
155142
}
156143

157144
/**
@@ -228,11 +215,9 @@ final class CtSymClassPath(ctSym: java.nio.file.Path, release: Int) extends Clas
228215
// e.g. "java.lang" -> Seq(/876/java/lang, /87/java/lang, /8/java/lang))
229216
private val packageIndex: scala.collection.Map[String, scala.collection.Seq[Path]] = {
230217
val index = collection.mutable.HashMap[String, collection.mutable.ListBuffer[Path]]()
231-
val isJava12OrHigher = scala.util.Properties.isJavaAtLeast("12")
232218
rootsForRelease.foreach(root => Files.walk(root).iterator().asScala.filter(Files.isDirectory(_)).foreach { p =>
233-
val moduleNamePathElementCount = if (isJava12OrHigher) 1 else 0
234-
if (p.getNameCount > root.getNameCount + moduleNamePathElementCount) {
235-
val packageDotted = p.subpath(moduleNamePathElementCount + root.getNameCount, p.getNameCount).toString.replace('/', '.')
219+
if (p.getNameCount > root.getNameCount + 1) {
220+
val packageDotted = p.subpath(1 + root.getNameCount, p.getNameCount).toString.replace('/', '.')
236221
index.getOrElseUpdate(packageDotted, new collection.mutable.ListBuffer) += p
237222
}
238223
})

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import dotty.tools.dotc.config.Settings.{Setting, SettingAlias, SettingGroup, Se
66
import dotty.tools.dotc.config.SourceVersion
77
import dotty.tools.dotc.core.Contexts.*
88
import dotty.tools.dotc.rewrites.Rewrites
9-
import dotty.tools.io.{AbstractFile, Directory, JDK9Reflectors, PlainDirectory, NoAbstractFile}
9+
import dotty.tools.io.{AbstractFile, Directory, PlainDirectory, NoAbstractFile}
1010
import Setting.ChoiceWithHelp
1111
import ScalaSettingCategories.*
1212

compiler/src/dotty/tools/dotc/config/ScalaSettingsProperties.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package config
33

44
import Settings.Setting.ChoiceWithHelp
55
import dotty.tools.backend.jvm.BackendUtils.classfileVersionMap
6-
import dotty.tools.io.{AbstractFile, Directory, JDK9Reflectors, PlainDirectory, NoAbstractFile}
6+
import dotty.tools.io.{AbstractFile, Directory, PlainDirectory, NoAbstractFile}
77

88
object ScalaSettingsProperties:
99

@@ -16,7 +16,7 @@ object ScalaSettingsProperties:
1616
(minTargetVersion to maxTargetVersion).toList.map(_.toString)
1717

1818
def supportedReleaseVersions: List[String] =
19-
val jdkVersion = JDK9Reflectors.runtimeVersionMajor(JDK9Reflectors.runtimeVersion()).intValue()
19+
val jdkVersion = Runtime.version().feature()
2020
val maxVersion = Math.min(jdkVersion, maxTargetVersion)
2121
(minReleaseVersion to maxVersion).toList.map(_.toString)
2222

compiler/src/dotty/tools/io/JDK9Reflectors.java

Lines changed: 0 additions & 106 deletions
This file was deleted.

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import java.net.URL
1111
import java.io.{ IOException, InputStream, OutputStream, FilterInputStream }
1212
import java.nio.file.Files
1313
import java.util.zip.{ ZipEntry, ZipFile }
14-
import java.util.jar.Manifest
14+
import java.util.jar.{ Manifest, JarFile }
1515
import scala.collection.mutable
1616
import scala.jdk.CollectionConverters.*
1717

@@ -117,8 +117,7 @@ final class FileZipArchive(jpath: JPath, release: Option[String]) extends ZipArc
117117
private def openZipFile(): ZipFile = try {
118118
release match {
119119
case Some(r) if file.getName.endsWith(".jar") =>
120-
val releaseVersion = JDK9Reflectors.runtimeVersionParse(r)
121-
JDK9Reflectors.newJarFile(file, true, ZipFile.OPEN_READ, releaseVersion)
120+
new JarFile(file, true, ZipFile.OPEN_READ, Runtime.Version.parse(r))
122121
case _ =>
123122
new ZipFile(file)
124123
}

compiler/src/dotty/tools/runner/ObjectRunner.scala

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)