Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Scala 2.13.x support #1916

Merged
merged 75 commits into from Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from 60 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
8a3db5d
Initial 2.13 cross compile compat:
WojciechMazur Sep 29, 2020
47733cf
Updated ScalaVersions
WojciechMazur Sep 29, 2020
b713318
Fix early initializers in NirPlugin
WojciechMazur Sep 30, 2020
aeb5bf5
Use java parallel processing instead of scala parallel collections (s…
WojciechMazur Sep 30, 2020
d4f7691
Removed posix.time import causing wrong reference in scope
WojciechMazur Oct 1, 2020
bea1f01
Make javalib 2.13 cross-compilable
WojciechMazur Oct 1, 2020
f1a49d9
Replace deprecated scala.collection.JavaConverters with scala.jdk.Col…
WojciechMazur Oct 1, 2020
c94f59f
Enable implicitConversions in scalalib
WojciechMazur Oct 2, 2020
a0db29c
Move common overrides to scalalib/overrides
WojciechMazur Oct 2, 2020
11acf24
Reimport missing java.Iterable, fix FilesSuite to work with underylin…
WojciechMazur Oct 2, 2020
46a8ee6
Test interface/compiler cross-build compat fixes
WojciechMazur Oct 3, 2020
fed20a6
Unit-tests cross-build compat fixes
WojciechMazur Oct 3, 2020
d9cfd74
Replace serializable symbol to use java.io.Serializable
WojciechMazur Oct 3, 2020
7f30443
Add scala-collections-compat sources to scalalib
WojciechMazur Oct 3, 2020
8bd9032
Add scala-collections-compat sources to scalalib
WojciechMazur Oct 3, 2020
b46c522
fix diferrent resolving of time import in TimesSuite
WojciechMazur Oct 3, 2020
07cdfcc
Add basic scalalib overrides for 2.13, remove redundant overrides in …
WojciechMazur Oct 3, 2020
f1f5330
Introduce Float/Double Ordering implicit overrides in java.util.Arrays
WojciechMazur Oct 3, 2020
927a820
Add higherKinds scalacOption to scalalib
WojciechMazur Oct 3, 2020
97f071d
Fix match in 2.13 - for non Int cases generate if-else chain instead …
WojciechMazur Oct 4, 2020
d7b276e
Add 2.13.0 - 2.13.2 compat for Symbol.toString (Changed in 2.13.3)
WojciechMazur Oct 4, 2020
8aed3f1
Remove more redundant overrides
WojciechMazur Oct 4, 2020
9299590
Update auxlib runtime.Statics to match 2.13 changes
WojciechMazur Oct 5, 2020
8231c2a
build.sbt cleanup and fixes
WojciechMazur Oct 5, 2020
b3e90b2
After rebase fixes
WojciechMazur Oct 5, 2020
15df0d1
Port Hashtable from Scala.js, due to to cyclic dependency of 2.13 Has…
WojciechMazur Oct 5, 2020
262ac36
Add 2.13.3 to travis CI matrix [ci skip]
WojciechMazur Oct 5, 2020
12488ae
Add missing changes:
WojciechMazur Oct 5, 2020
7480f62
Allow cross-testing junit jvm
WojciechMazur Oct 5, 2020
7d3dbaa
Remove ported scala-collections-compat from scalalib overides.
WojciechMazur Oct 6, 2020
379f324
javalib Streams adapted to not use collections-compat
WojciechMazur Oct 6, 2020
f06d440
cleanup
WojciechMazur Oct 6, 2020
c3e94fa
build.sbt cleanup & fixes
WojciechMazur Oct 7, 2020
970cdbb
Prevent compiling tests with wrong scala version
WojciechMazur Oct 7, 2020
234de4a
Replaced usage of deprecated usage of mutable.ListMap with immutable …
WojciechMazur Oct 13, 2020
cd4cda0
after rebase fixes
WojciechMazur Oct 13, 2020
d2ff2f7
Move logger to `util` module in order to allow cross testing testRunner
WojciechMazur Oct 14, 2020
a0d9fd1
Build fixes
WojciechMazur Oct 14, 2020
41edd88
After rebase fix: Port changes tests to JUnit
WojciechMazur Oct 22, 2020
16e39e7
After rebase fix
WojciechMazur Nov 6, 2020
395cbd6
Revert not strictly needed build.sbt changes for 2.13 support
WojciechMazur Nov 6, 2020
c14c0a5
Set default scala version 2.12 in build
WojciechMazur Nov 9, 2020
5ebdc1a
SocketImpl methods close and shutdownInput/Output have empty param ar…
WojciechMazur Nov 9, 2020
478d606
Applied styling fixes
WojciechMazur Nov 9, 2020
ccc56c0
Add comment to laziness of j.l.System.systemProperties
WojciechMazur Nov 9, 2020
2b75b52
Use mutable HashMpa in BinarySerializer to store indexes of files
WojciechMazur Nov 9, 2020
ea76b34
Revert to using genLiteralValue directly instead of genExpr
WojciechMazur Nov 9, 2020
7c5da5f
Revert removed scalalib overrides
WojciechMazur Nov 9, 2020
8a7cf75
Remove scala 2.13.x Symbol overrides
WojciechMazur Nov 9, 2020
7343b18
Removes illegal jdk.CollectionConventers in scalalib overrides
WojciechMazur Nov 9, 2020
695d424
Additional styling fixes
WojciechMazur Nov 9, 2020
4164b87
Remove illegal ussages of collectionsCompat lib in build
WojciechMazur Nov 9, 2020
3745d4a
Remove nir.Show collectionsConverter dependency
WojciechMazur Nov 9, 2020
c7ce2a9
Remove util collectionsConverter dependency
WojciechMazur Nov 9, 2020
39b2aad
Remove unitTests CollectionConverters dependency
WojciechMazur Nov 10, 2020
3404b24
Remove parallelStream from scalanative.util package
WojciechMazur Nov 11, 2020
c9ad9b8
Remove implicit conversion for UnrolledBuffer->Seq, and Seq -> immuta…
WojciechMazur Nov 11, 2020
28f8a03
Revert Scala version dependent HashCode tests after rebase
WojciechMazur Nov 11, 2020
d08010d
After rebase fixes
WojciechMazur Nov 11, 2020
c22e377
Remove duplicated CollectionConverters.scala
WojciechMazur Nov 11, 2020
86672f6
Remove no longer needed collectionsCompat and parallel-collections li…
WojciechMazur Nov 11, 2020
a96d1e4
Add Predef and `scala` package optimization used in previous versions
WojciechMazur Nov 11, 2020
7c7d875
Remove remaining usages of JavaConverters in tools
WojciechMazur Nov 11, 2020
a6c00a5
Remove laziness of Vector if `scala` package
WojciechMazur Nov 11, 2020
4ad48f5
Remove laziness of System.systemProperties, it was fixed by scalalib …
WojciechMazur Nov 11, 2020
3dcbf8e
Fix empty code dumps
WojciechMazur Nov 11, 2020
9589552
Don't use view in Show.dump. It does not contains sortBy method in 2.13
WojciechMazur Nov 12, 2020
7ab5ba4
Port 2.13 scala.reflect overrides from scala.js
WojciechMazur Nov 12, 2020
5d5afa1
Revert "Remove laziness of System.systemProperties, it was fixed by s…
WojciechMazur Nov 12, 2020
373b22d
Removed no longer need libDependency in project/build.sbt
WojciechMazur Nov 12, 2020
a8306f4
Styling fixes in javalib
WojciechMazur Nov 12, 2020
cd40d25
Fix checking for scala version in HashCodeTest
WojciechMazur Nov 12, 2020
d0c5cf2
Add missing param braces in ju.BaseStream and FileAttribute
WojciechMazur Nov 12, 2020
bbcc160
Remove laziness of ju.System.systemProperties. Set 2.13 scala package…
WojciechMazur Nov 12, 2020
70eb2ba
Explicitly use `nsc.Global with Singleton` instead of using type alias
WojciechMazur Nov 12, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -3,6 +3,7 @@ sudo: required
scala:
- "2.11.12"
- "2.12.12"
- "2.13.3"

os: linux
dist: trusty
Expand Down
16 changes: 16 additions & 0 deletions auxlib/src/main/scala/scala/runtime/Statics.scala
Expand Up @@ -73,4 +73,20 @@ object Statics {
case x: java.lang.Float => floatHash(x.floatValue)
case _ => x.hashCode
}

/** Used as a marker object to return from PartialFunctions */
def pfMarker: AnyRef = PFMarker

private object PFMarker extends AnyRef

def releaseFence(): Unit = ()

/** Just throws an exception.
*
* Used by the synthetic `productElement` and `productElementName` methods
* in case classes. Delegating the exception-throwing to this function
* reduces the bytecode size of the case class.
*/
final def ioobe[T](n: Int): T =
throw new IndexOutOfBoundsException(String.valueOf(n))
}
51 changes: 25 additions & 26 deletions build.sbt
Expand Up @@ -59,16 +59,9 @@ inThisBuild(
addCommandAlias(
"test-all",
Seq(
"sandbox/run",
"testRunner/test",
"testInterface/test",
"tools/test",
"tests/test",
"nirparser/test",
"sbtScalaNative/scripted",
"tools/mimaReportBinaryIssues",
"junitTestOutputsJVM/test",
"junitTestOutputsNative/test"
"test-tools",
"test-runtime",
"test-scripted"
).mkString(";")
)

Expand Down Expand Up @@ -103,6 +96,18 @@ addCommandAlias(
lazy val publishSnapshot =
taskKey[Unit]("Publish snapshot to sonatype on every commit to master.")

val collectionsCompatLib = {
"org.scala-lang.modules" %% "scala-collection-compat" % "2.2.0"
}

def parallelCollectionsLib(scalaVersion: String): Seq[ModuleID] = {
CrossVersion.partialVersion(scalaVersion) match {
case Some((2, n)) if n >= 13 =>
Seq("org.scala-lang.modules" %% "scala-parallel-collections" % "0.2.0")
case _ => Nil
}
}

// to publish plugin (we only need to do this once, it's already done!)
// follow: https://www.scala-sbt.org/1.x/docs/Bintray-For-Plugins.html
// then add a new package
Expand Down Expand Up @@ -220,6 +225,9 @@ lazy val util =
.in(file("util"))
.settings(toolSettings)
.settings(mavenPublishSettings)
.settings(
libraryDependencies += collectionsCompatLib
)
WojciechMazur marked this conversation as resolved.
Show resolved Hide resolved

lazy val nir =
project
Expand Down Expand Up @@ -256,8 +264,9 @@ lazy val tools =
.settings(
libraryDependencies ++= Seq(
scalacheckDep,
scalatestDep
),
scalatestDep,
collectionsCompatLib
WojciechMazur marked this conversation as resolved.
Show resolved Hide resolved
) ++ parallelCollectionsLib(scalaVersion.value),
Test / fork := true,
Test / javaOptions ++= {
val nscpluginjar = (nscplugin / Compile / Keys.`package`).value
Expand Down Expand Up @@ -422,15 +431,13 @@ lazy val scalalib =
.in(file("scalalib"))
.enablePlugins(MyScalaNativePlugin)
.settings(
// This build uses Scala 2.11 version 2.11.12 to compile
// what appears to be 2.11.0 sources. This yields 114
// deprecations. Editing those sources is not an option (long story),
// so do not spend compile time looking for the deprecations.
// Keep the log file clean so that real issues stand out.
scalacOptions -= "-deprecation",
scalacOptions += "-deprecation:false",
// The option below is needed since Scala 2.12.12.
scalacOptions += "-language:postfixOps"
scalacOptions += "-language:postfixOps",
// The option below is needed since Scala 2.13.0.
scalacOptions += "-language:implicitConversions",
scalacOptions += "-language:higherKinds"
)
.settings(mavenPublishSettings)
.settings(
Expand Down Expand Up @@ -582,10 +589,6 @@ lazy val tests =
)
.settings(noPublishSettings)
.settings(
// nativeOptimizerReporter := OptimizerReporter.toDirectory(
// crossTarget.value),
// nativeLinkerReporter := LinkerReporter.toFile(
// target.value / "out.dot"),
sjrd marked this conversation as resolved.
Show resolved Hide resolved
testFrameworks ++= Seq(
new TestFramework("tests.NativeFramework"),
new TestFramework("com.novocode.junit.JUnitFramework")
Expand Down Expand Up @@ -615,10 +618,6 @@ lazy val sandbox =
.enablePlugins(MyScalaNativePlugin)
.settings(scalacOptions -= "-Xfatal-warnings")
.settings(noPublishSettings)
.settings(
// nativeOptimizerReporter := OptimizerReporter.toDirectory(
// crossTarget.value),
)
WojciechMazur marked this conversation as resolved.
Show resolved Hide resolved
.dependsOn(nscplugin % "plugin", allCoreLibs, testInterface % Test)

lazy val testingCompilerInterface =
Expand Down
@@ -0,0 +1,21 @@
package scala.scalanative.compat

import java.util.stream.WrappedScalaStream
import scala.collection.immutable
import scala.language.implicitConversions

private[scalanative] object ScalaStream {
type Underlying[T] = immutable.Stream[T]
val Underlying = immutable.Stream

implicit class ScalaStreamImpl[T](val underyling: Underlying[T])
extends AnyVal {
def wrappedStream(closeHanlder: Option[Runnable] = None) =
new WrappedScalaStream[T](underyling, closeHanlder)
}

implicit def seqToScalaStream[T](seq: Iterable[T]): Underlying[T] = {
seq.to[Underlying]
}

}
@@ -0,0 +1,20 @@
package scala.scalanative.compat

import java.util.stream.WrappedScalaStream
import scala.collection.immutable
import scala.language.implicitConversions

private[scalanative] object ScalaStream {
type Underlying[T] = immutable.Stream[T]
val Underlying = immutable.Stream

implicit class ScalaStreamImpl[T](val underyling: Underlying[T])
extends AnyVal {
def wrappedStream(closeHanlder: Option[Runnable] = None) =
new WrappedScalaStream[T](underyling, closeHanlder)
}

implicit def seqToScalaStream[T](seq: Iterable[T]): Underlying[T] = {
seq.to[Underlying]
}
}
@@ -0,0 +1,21 @@
package scala.scalanative.compat

import java.util.stream.WrappedScalaStream
import scala.collection.immutable
import scala.language.implicitConversions

private[scalanative] object ScalaStream {
type Underlying[T] = immutable.LazyList[T]
val Underlying = immutable.LazyList

implicit class ScalaStreamImpl[T](val underyling: Underlying[T])
extends AnyVal {
def wrappedStream(closeHanlder: Option[Runnable] = None) =
new WrappedScalaStream[T](underyling, closeHanlder)
}

implicit def seqToScalaStream[T](seq: Iterable[T]): Underlying[T] = {
seq.to(Underlying)
}

}
2 changes: 1 addition & 1 deletion javalib/src/main/scala/java/io/BufferedOutputStream.scala
Expand Up @@ -73,7 +73,7 @@ class BufferedOutputStream(out: OutputStream, size: Int)
count += 1
}

private def flushInternal() {
private def flushInternal() = {
WojciechMazur marked this conversation as resolved.
Show resolved Hide resolved
if (count > 0) {
out.write(buf, 0, count)
count = 0
Expand Down
5 changes: 1 addition & 4 deletions javalib/src/main/scala/java/io/BufferedReader.scala
@@ -1,6 +1,6 @@
package java.io

import scala.collection.immutable.{Stream => SStream}
import scala.scalanative.compat.StreamsCompat._
import java.util.stream.{Stream, WrappedScalaStream}

class BufferedReader(in: Reader, sz: Int) extends Reader {
Expand Down Expand Up @@ -162,9 +162,6 @@ class BufferedReader(in: Reader, sz: Int) extends Reader {
}
}

private def toScalaStream(): SStream[String] =
toScalaStream(false)

private[this] def toScalaStream(closeAtEnd: Boolean): SStream[String] = {
Option(readLine()) match {
case None =>
Expand Down
4 changes: 1 addition & 3 deletions javalib/src/main/scala/java/io/BufferedWriter.scala
@@ -1,7 +1,5 @@
package java.io

import scala.compat.Platform.EOL

class BufferedWriter(out: Writer, sz: Int) extends Writer {

if (sz <= 0) throw new IllegalArgumentException("Buffer size <= 0")
Expand All @@ -26,7 +24,7 @@ class BufferedWriter(out: Writer, sz: Int) extends Writer {
}

def newLine(): Unit =
write(EOL, 0, EOL.length)
write(System.lineSeparator(), 0, System.lineSeparator().length)

override def write(c: Int): Unit =
write(Array(c.toChar), 0, 1)
Expand Down
43 changes: 22 additions & 21 deletions javalib/src/main/scala/java/io/File.scala
Expand Up @@ -31,7 +31,7 @@ class File(_path: String) extends Serializable with Comparable[File] {
this(Option(parent).map(_.path).orNull, child)

def this(uri: URI) = {
this(uri.getPath)
this(uri.getPath())
checkURI(uri)
}

Expand Down Expand Up @@ -122,7 +122,7 @@ class File(_path: String) extends Serializable with Comparable[File] {

def getCanonicalPath(): String =
Zone { implicit z =>
if (exists) {
if (exists()) {
fromCString(simplifyExistingPath(toCString(properPath)))
} else {
simplifyNonExistingPath(fromCString(resolve(toCString(properPath))))
Expand Down Expand Up @@ -153,7 +153,7 @@ class File(_path: String) extends Serializable with Comparable[File] {
case (acc, seg) => seg :: acc
}
.reverse
.filterNot(_.isEmpty)
.filterNot(_.isEmpty())
.mkString(separator, separator, "")

@throws(classOf[IOException])
Expand All @@ -166,11 +166,12 @@ class File(_path: String) extends Serializable with Comparable[File] {
}

def getParent(): String =
path.split(separatorChar).filterNot(_.isEmpty) match {
case Array() if !isAbsolute => null
case Array(_) if !isAbsolute => null
case parts if !isAbsolute => parts.init.mkString(separator)
case parts if isAbsolute => parts.init.mkString(separator, separator, "")
path.split(separatorChar).filterNot(_.isEmpty()) match {
case Array() if !isAbsolute() => null
case Array(_) if !isAbsolute() => null
case parts if !isAbsolute() => parts.init.mkString(separator)
case parts if isAbsolute() =>
parts.init.mkString(separator, separator, "")
}

def getParentFile(): File = {
Expand Down Expand Up @@ -310,7 +311,7 @@ class File(_path: String) extends Serializable with Comparable[File] {

override def toString(): String = path

def deleteOnExit(): Unit = DeleteOnExit.addFile(this.getAbsolutePath)
def deleteOnExit(): Unit = DeleteOnExit.addFile(this.getAbsolutePath())

@stub
def toURL(): java.net.URL = ???
Expand Down Expand Up @@ -419,7 +420,7 @@ object File {
throw new IOException(
"getcwd() error in trying to get user directory."))

if (path.isEmpty) userdir
if (path.isEmpty()) userdir
else if (userdir.endsWith(separator)) userdir + path
else userdir + separator + path
}
Expand Down Expand Up @@ -521,16 +522,16 @@ object File {
}
}

val pathSeparatorChar: Char = if (Platform.isWindows) ';' else ':'
val pathSeparatorChar: Char = if (Platform.isWindows()) ';' else ':'
val pathSeparator: String = pathSeparatorChar.toString
val separatorChar: Char = if (Platform.isWindows) '\\' else '/'
val separatorChar: Char = if (Platform.isWindows()) '\\' else '/'
val separator: String = separatorChar.toString
private var counter: Int = 0
private var counterBase: Int = 0
private val caseSensitive: Boolean = !Platform.isWindows
private val caseSensitive: Boolean = !Platform.isWindows()

def listRoots(): Array[File] =
if (Platform.isWindows) ???
if (Platform.isWindows()) ???
else {
var array = new Array[File](1)
array(0) = new File("/")
Expand All @@ -556,19 +557,19 @@ object File {
def compMsg(comp: String): String =
s"Found $comp component in URI"

if (!uri.isAbsolute) {
if (!uri.isAbsolute()) {
throwExc("URI is not absolute")
} else if (!uri.getRawSchemeSpecificPart.startsWith("/")) {
} else if (!uri.getRawSchemeSpecificPart().startsWith("/")) {
throwExc("URI is not hierarchical")
} else if (uri.getScheme == null || !(uri.getScheme == "file")) {
} else if (uri.getScheme() == null || !(uri.getScheme() == "file")) {
throwExc("Expected file scheme in URI")
} else if (uri.getRawPath == null || uri.getRawPath.length == 0) {
} else if (uri.getRawPath() == null || uri.getRawPath().length() == 0) {
throwExc("Expected non-empty path in URI")
} else if (uri.getRawAuthority != null) {
} else if (uri.getRawAuthority() != null) {
throwExc(compMsg("authority"))
} else if (uri.getRawQuery != null) {
} else if (uri.getRawQuery() != null) {
throwExc(compMsg("query"))
} else if (uri.getRawFragment != null) {
} else if (uri.getRawFragment() != null) {
throwExc(compMsg("fragment"))
}
// else URI is ok
Expand Down
4 changes: 2 additions & 2 deletions javalib/src/main/scala/java/io/FileDescriptor.scala
Expand Up @@ -34,9 +34,9 @@ object FileDescriptor {

private[io] def openReadOnly(file: File): FileDescriptor =
Zone { implicit z =>
val fd = fcntl.open(toCString(file.getPath), fcntl.O_RDONLY, 0.toUInt)
val fd = fcntl.open(toCString(file.getPath()), fcntl.O_RDONLY, 0.toUInt)
if (fd == -1) {
throw new FileNotFoundException("No such file " + file.getPath)
throw new FileNotFoundException("No such file " + file.getPath())
}
new FileDescriptor(fd, true)
}
Expand Down
2 changes: 1 addition & 1 deletion javalib/src/main/scala/java/io/FileOutputStream.scala
Expand Up @@ -67,7 +67,7 @@ object FileOutputStream {
import stat._
val flags = O_CREAT | O_WRONLY | (if (append) O_APPEND else O_TRUNC)
val mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH
val fd = open(toCString(file.getPath), flags, mode)
val fd = open(toCString(file.getPath()), flags, mode)
if (fd == -1)
throw new FileNotFoundException(
s"$file (${fromCString(string.strerror(errno.errno))})")
Expand Down