Skip to content

Commit 422342d

Browse files
authored
Merge pull request #3138 from dotty-staging/java9
Java 9 support
2 parents 675b2ac + 5061c29 commit 422342d

31 files changed

+186
-259
lines changed

.gitmodules

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[submodule "scala-backend"]
22
path = scala-backend
33
url = https://github.com/lampepfl/scala.git
4-
branch = sharing-backend
4+
branch = fix-java9-itf
55
[submodule "scala2-library"]
66
path = scala2-library
77
url = https://github.com/lampepfl/scala.git

bench/src/main/scala/Benchmarks.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ object Bench {
3737
val libs = System.getProperty("BENCH_CLASS_PATH")
3838

3939
val opts = new OptionsBuilder()
40-
.jvmArgsPrepend("-Xbootclasspath/a:" + libs + ":", "-Xms2G", "-Xmx2G")
40+
.jvmArgsPrepend(s"-classpath $libs", "-Xms2G", "-Xmx2G")
4141
.mode(Mode.AverageTime)
4242
.timeUnit(TimeUnit.MILLISECONDS)
4343
.warmupIterations(warmup)

compiler/src/dotty/tools/dotc/ast/tpd.scala

+3-31
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
980980
}
981981
}
982982

983-
def applyOverloaded(receiver: Tree, method: TermName, args: List[Tree], targs: List[Type], expectedType: Type, isAnnotConstructor: Boolean = false)(implicit ctx: Context): Tree = {
983+
def applyOverloaded(receiver: Tree, method: TermName, args: List[Tree], targs: List[Type], expectedType: Type)(implicit ctx: Context): Tree = {
984984
val typer = ctx.typer
985985
val proto = new FunProtoTyped(args, expectedType)(typer)
986986
val denot = receiver.tpe.member(method)
@@ -998,7 +998,6 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
998998
assert(alternatives.size == 1,
999999
i"${if (alternatives.isEmpty) "no" else "multiple"} overloads available for " +
10001000
i"$method on ${receiver.tpe.widenDealiasKeepAnnots} with targs: $targs%, %; args: $args%, % of types ${args.tpes}%, %; expectedType: $expectedType." +
1001-
i" isAnnotConstructor = $isAnnotConstructor.\n" +
10021001
i"all alternatives: ${allAlts.map(_.symbol.showDcl).mkString(", ")}\n" +
10031002
i"matching alternatives: ${alternatives.map(_.symbol.showDcl).mkString(", ")}.") // this is parsed from bytecode tree. there's nothing user can do about it
10041003
alternatives.head
@@ -1008,35 +1007,8 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
10081007
.select(TermRef(receiver.tpe, selected.termSymbol.asTerm))
10091008
.appliedToTypes(targs)
10101009

1011-
def adaptLastArg(lastParam: Tree, expectedType: Type) = {
1012-
if (isAnnotConstructor && !(lastParam.tpe <:< expectedType)) {
1013-
val defn = ctx.definitions
1014-
val prefix = args.take(selected.widen.paramInfoss.head.size - 1)
1015-
expectedType match {
1016-
case defn.ArrayOf(el) =>
1017-
lastParam.tpe match {
1018-
case defn.ArrayOf(el2) if el2 <:< el =>
1019-
// we have a JavaSeqLiteral with a more precise type
1020-
// we cannot construct a tree as JavaSeqLiteral inferred to precise type
1021-
// if we add typed than it would be both type-correct and
1022-
// will pass Ycheck
1023-
prefix ::: List(tpd.Typed(lastParam, TypeTree(defn.ArrayOf(el))))
1024-
case _ =>
1025-
???
1026-
}
1027-
case _ => args
1028-
}
1029-
} else args
1030-
}
1031-
1032-
val callArgs: List[Tree] = if (args.isEmpty) Nil else {
1033-
val expectedType = selected.widen.paramInfoss.head.last
1034-
val lastParam = args.last
1035-
adaptLastArg(lastParam, expectedType)
1036-
}
1037-
1038-
val apply = untpd.Apply(fun, callArgs)
1039-
new typer.ApplyToTyped(apply, fun, selected, callArgs, expectedType).result.asInstanceOf[Tree] // needed to handle varargs
1010+
val apply = untpd.Apply(fun, args)
1011+
new typer.ApplyToTyped(apply, fun, selected, args, expectedType).result.asInstanceOf[Tree] // needed to handle varargs
10401012
}
10411013

10421014
@tailrec

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

-3
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,6 @@ object CompilerCommand {
137137
else if (settings.version.value) {
138138
ctx.echo(versionMsg)
139139
Nil
140-
} else if (!Properties.isJavaAtLeast("1.8")) {
141-
ctx.error("Dotty requires Java 8 to run")
142-
Nil
143140
}
144141
else if (shouldStopWithInfo) {
145142
ctx.echo(infoMessage)

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

+9-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package config
55
import java.net.{ URL, MalformedURLException }
66
import WrappedProperties.AccessControl
77
import io.{ ClassPath, File, Directory, Path, AbstractFile }
8-
import classpath.{AggregateClassPath, ClassPathFactory }
8+
import classpath.{AggregateClassPath, ClassPathFactory, JrtClassPath }
99
import ClassPath.{ JavaContext, join, split }
1010
import PartialFunction.condOpt
1111
import scala.language.postfixOps
@@ -225,13 +225,14 @@ class PathResolver(implicit ctx: Context) {
225225
// priority class path takes precedence
226226
def basis = List[Traversable[ClassPath]](
227227
classesInExpandedPath(priorityClassPath), // 0. The priority class path (for testing).
228-
classesInPath(javaBootClassPath), // 1. The Java bootstrap class path.
229-
contentsOfDirsInPath(javaExtDirs), // 2. The Java extension class path.
230-
classesInExpandedPath(javaUserClassPath), // 3. The Java application class path.
231-
classesInPath(scalaBootClassPath), // 4. The Scala boot class path.
232-
contentsOfDirsInPath(scalaExtDirs), // 5. The Scala extension class path.
233-
classesInExpandedPath(userClassPath), // 6. The Scala application class path.
234-
sourcesInPath(sourcePath) // 7. The Scala source path.
228+
JrtClassPath.apply(), // 1. The Java 9 classpath (backed by the jrt:/ virtual system, if available)
229+
classesInPath(javaBootClassPath), // 2. The Java bootstrap class path.
230+
contentsOfDirsInPath(javaExtDirs), // 3. The Java extension class path.
231+
classesInExpandedPath(javaUserClassPath), // 4. The Java application class path.
232+
classesInPath(scalaBootClassPath), // 5. The Scala boot class path.
233+
contentsOfDirsInPath(scalaExtDirs), // 6. The Scala extension class path.
234+
classesInExpandedPath(userClassPath), // 7. The Scala application class path.
235+
sourcesInPath(sourcePath) // 8. The Scala source path.
235236
)
236237

237238
lazy val containers = basis.flatten.distinct

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

-15
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,4 @@ trait PropertiesTrait {
131131
def versionMsg = "Scala %s %s -- %s".format(propCategory, versionString, copyrightString)
132132
def scalaCmd = if (isWin) "dotr.bat" else "dotr"
133133
def scalacCmd = if (isWin) "dotc.bat" else "dotc"
134-
135-
/** Can the java version be determined to be at least as high as the argument?
136-
* Hard to properly future proof this but at the rate 1.7 is going we can leave
137-
* the issue for our cyborg grandchildren to solve.
138-
*/
139-
def isJavaAtLeast(version: String) = {
140-
val okVersions = version match {
141-
case "1.5" => List("1.5", "1.6", "1.7", "1.8")
142-
case "1.6" => List("1.6", "1.7", "1.8")
143-
case "1.7" => List("1.7", "1.8")
144-
case "1.8" => List("1.8")
145-
case _ => Nil
146-
}
147-
okVersions exists (javaVersion startsWith _)
148-
}
149134
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ object Settings {
132132
case (BooleanTag, _) =>
133133
update(true, args)
134134
case (OptionTag, _) =>
135-
update(Some(propertyClass.get.newInstance), args)
135+
update(Some(propertyClass.get.getConstructor().newInstance()), args)
136136
case (ListTag, _) =>
137137
if (argRest.isEmpty) missingArg
138138
else update((argRest split ",").toList, args)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ object Annotations {
114114

115115
private def resolveConstructor(atp: Type, args:List[Tree])(implicit ctx: Context): Tree = {
116116
val targs = atp.argTypes
117-
tpd.applyOverloaded(New(atp.typeConstructor), nme.CONSTRUCTOR, args, targs, atp, isAnnotConstructor = true)
117+
tpd.applyOverloaded(New(atp.typeConstructor), nme.CONSTRUCTOR, args, targs, atp)
118118
}
119119

120120
def applyResolve(atp: Type, args: List[Tree])(implicit ctx: Context): Annotation = {

compiler/src/dotty/tools/dotc/plugins/Plugin.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ object Plugin {
177177
/** Instantiate a plugin class, given the class and
178178
* the compiler it is to be used in.
179179
*/
180-
def instantiate(clazz: AnyClass): Plugin = clazz.newInstance.asInstanceOf[Plugin]
180+
def instantiate(clazz: AnyClass): Plugin = clazz.getConstructor().newInstance().asInstanceOf[Plugin]
181181
}
182182

183183
class PluginLoadException(val path: String, message: String, cause: Exception) extends Exception(message, cause) {

compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class QuoteDriver extends Driver {
3636

3737
val clazz = classLoader.loadClass(driver.outputClassName.toString)
3838
val method = clazz.getMethod("apply")
39-
val instance = clazz.newInstance()
39+
val instance = clazz.getConstructor().newInstance()
4040

4141
method.invoke(instance).asInstanceOf[T]
4242
}

compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala

+8-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,14 @@ class ExtractDependencies extends Phase {
127127
// We can recover the fully qualified name of a classfile from
128128
// its path
129129
val classSegments = pf.givenPath.segments.takeRight(packages + 1)
130-
binaryDependency(pf.file, binaryClassName(classSegments))
130+
// FIXME: pf.file is null for classfiles coming from the modulepath
131+
// (handled by JrtClassPath) because they cannot be represented as
132+
// java.io.File, since the `binaryDependency` callback must take a
133+
// java.io.File, this means that we cannot record dependencies coming
134+
// from the modulepath. For now this isn't a big deal since we only
135+
// support having the standard Java library on the modulepath.
136+
if (pf.file != null)
137+
binaryDependency(pf.file, binaryClassName(classSegments))
131138

132139
case _ =>
133140
ctx.warning(s"sbt-deps: Ignoring dependency $depFile of class ${depFile.getClass}}")

compiler/src/dotty/tools/dotc/transform/Splicer.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ object Splicer {
125125
} else {
126126
// nested object in an object
127127
val clazz = loadClass(sym.fullNameSeparated(FlatName))
128-
(clazz, clazz.newInstance().asInstanceOf[Object])
128+
(clazz, clazz.getConstructor().newInstance().asInstanceOf[Object])
129129
}
130130
}
131131

compiler/test/dotty/Jars.scala

-61
This file was deleted.

compiler/test/dotty/Properties.scala

+23-11
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,30 @@ object Properties {
3232
*/
3333
val testsSafeMode: Boolean = sys.props.isDefinedAt("dotty.tests.safemode")
3434

35-
/** Dotty compiler path provided through define */
36-
def dottyCompiler: String = sys.props("dotty.tests.classes.compiler")
35+
/** dotty-interfaces jar */
36+
def dottyInterfaces: String = sys.props("dotty.tests.classes.dottyInterfaces")
3737

38-
/** Dotty classpath extras provided through define */
39-
def dottyExtras: List[String] =
40-
Option(sys.props("dotty.tests.extraclasspath"))
41-
.map(_.split(":").toList)
42-
.getOrElse(Nil)
38+
/** dotty-library jar */
39+
def dottyLibrary: String = sys.props("dotty.tests.classes.dottyLibrary")
4340

44-
/** Dotty interfaces path provided through define */
45-
def dottyInterfaces: String = sys.props("dotty.tests.classes.interfaces")
41+
/** dotty-compiler jar */
42+
def dottyCompiler: String = sys.props("dotty.tests.classes.dottyCompiler")
4643

47-
/** Dotty library path provided through define */
48-
def dottyLib: String = sys.props("dotty.tests.classes.library")
44+
/** compiler-interface jar */
45+
def compilerInterface: String = sys.props("dotty.tests.classes.compilerInterface")
46+
47+
/** scala-library jar */
48+
def scalaLibrary: String = sys.props("dotty.tests.classes.scalaLibrary")
49+
50+
/** scala-asm jar */
51+
def scalaAsm: String = sys.props("dotty.tests.classes.scalaAsm")
52+
53+
/** scala-xml jar */
54+
def scalaXml: String = sys.props("dotty.tests.classes.scalaXml")
55+
56+
/** jline-terminal jar */
57+
def jlineTerminal: String = sys.props("dotty.tests.classes.jlineTerminal")
58+
59+
/** jline-reader jar */
60+
def jlineReader: String = sys.props("dotty.tests.classes.jlineReader")
4961
}

compiler/test/dotty/tools/DottyTest.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package dotty
22
package tools
33

4+
import vulpix.TestConfiguration
5+
46
import dotc.core._
57
import dotc.core.Comments.{ContextDoc, ContextDocstrings}
68
import dotc.core.Contexts._
@@ -39,7 +41,7 @@ trait DottyTest extends ContextEscapeDetection {
3941

4042
protected def initializeCtx(fc: FreshContext): Unit = {
4143
fc.setSetting(fc.settings.encoding, "UTF8")
42-
fc.setSetting(fc.settings.classpath, Jars.dottyLib)
44+
fc.setSetting(fc.settings.classpath, TestConfiguration.basicClasspath)
4345
fc.setProperty(ContextDoc, new ContextDocstrings)
4446
}
4547

compiler/test/dotty/tools/backend/jvm/DottyBytecodeTest.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package dotty
22
package tools
33
package backend.jvm
44

5+
import vulpix.TestConfiguration
6+
57
import dotc.core.Contexts.{Context, ContextBase}
68
import dotc.core.Comments.{ContextDoc, ContextDocstrings}
79
import dotc.core.Phases.Phase
@@ -44,7 +46,7 @@ trait DottyBytecodeTest {
4446
def initCtx = {
4547
val ctx0 = (new ContextBase).initialCtx.fresh
4648
val outputDir = new VirtualDirectory("<DottyBytecodeTest output>")
47-
ctx0.setSetting(ctx0.settings.classpath, Jars.dottyLib)
49+
ctx0.setSetting(ctx0.settings.classpath, TestConfiguration.basicClasspath)
4850
ctx0.setProperty(ContextDoc, new ContextDocstrings)
4951
ctx0.setSetting(ctx0.settings.outputDir, outputDir)
5052
}

0 commit comments

Comments
 (0)