Skip to content

Commit

Permalink
Enable Scala 2.13.0 in the linker and all the other artifacts.
Browse files Browse the repository at this point in the history
Partest is not yet unabled in this commit, because a dependency of
`partest` 2.13.0, namely `testkit`, was not published. See
scala/bug#11529 upstream.
  • Loading branch information
sjrd committed Jun 18, 2019
1 parent 21729f3 commit e8d8109
Show file tree
Hide file tree
Showing 21 changed files with 170 additions and 110 deletions.
8 changes: 1 addition & 7 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ def allJavaVersions = otherJavaVersions.clone()
allJavaVersions << mainJavaVersion

def mainScalaVersion = "2.12.8"
def mainScalaVersions = ["2.11.12", "2.12.8"]
def mainScalaVersions = ["2.11.12", "2.12.8", "2.13.0"]
def otherScalaVersions = [
"2.11.0",
"2.11.1",
Expand All @@ -440,7 +440,6 @@ def otherScalaVersions = [
"2.12.6",
"2.12.7"
]
def noToolsScalaVersions = ["2.13.0"]

// The 'quick' matrix
def quickMatrix = []
Expand All @@ -456,11 +455,6 @@ mainScalaVersions.each { scalaVersion ->
quickMatrix.add([task: "partest-fastopt", scala: scalaVersion, java: mainJavaVersion])
}
quickMatrix.add([task: "test-suite-ecma-script5-force-polyfills", scala: mainScalaVersion, java: mainJavaVersion, testSuite: "testSuite"])
noToolsScalaVersions.each { scalaVersion ->
quickMatrix.add([task: "main", scala: scalaVersion, java: mainJavaVersion])
quickMatrix.add([task: "test-suite-ecma-script2015", scala: scalaVersion, java: mainJavaVersion, testSuite: "testSuite"])
quickMatrix.add([task: "test-suite-ecma-script5", scala: scalaVersion, java: mainJavaVersion, testSuite: "testSuite"])
}
allJavaVersions.each { javaVersion ->
quickMatrix.add([task: "tools-sbtplugin", scala: "2.12.8", sbt_version_override: "", java: javaVersion])
quickMatrix.add([task: "tools", scala: "2.10.7", java: javaVersion])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ package org.scalajs.jsenv.test

import org.scalajs.jsenv.JSEnv

import scala.collection.JavaConverters._
import scala.reflect.ClassTag

import org.junit.runner.Runner
Expand All @@ -40,7 +39,7 @@ abstract class JSEnvSuite(private[test] val config: JSEnvSuiteConfig)

/** Runner for a [[JSEnvSuite]]. May only be used on subclasses of [[JSEnvSuite]]. */
final class JSEnvSuiteRunner(root: Class[_], config: JSEnvSuiteConfig)
extends Suite(root, JSEnvSuiteRunner.getRunners(config).asJava) {
extends Suite(root, JSEnvSuiteRunner.getRunners(config)) {

/** Constructor for reflective instantiation via `@RunWith`. */
def this(suite: Class[_ <: JSEnvSuite]) =
Expand All @@ -56,16 +55,19 @@ private object JSEnvSuiteRunner {
.map { case (name, value) => s"$name = $value" }
.mkString("[", ", ", "]")

val paramValues = config +: params.map(_._2)
val paramValues = new java.util.LinkedList[AnyRef]
paramValues.add(config)
for (param <- params)
paramValues.add(param._2)

new BlockJUnit4ClassRunnerWithParameters(
new TestWithParameters(name, new TestClass(t.runtimeClass), paramValues.asJava))
new TestWithParameters(name, new TestClass(t.runtimeClass), paramValues))
}

private def getRunners(config: JSEnvSuiteConfig): List[Runner] = {
private def getRunners(config: JSEnvSuiteConfig): java.util.List[Runner] = {
import java.lang.Boolean.{TRUE, FALSE}

List(
java.util.Arrays.asList(
r[RunTests](config, "withCom" -> FALSE),
r[RunTests](config, "withCom" -> TRUE),
r[TimeoutRunTests](config, "withCom" -> FALSE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

package org.scalajs.linker.backend.closure

import scala.collection.JavaConverters._
import scala.concurrent._

import java.io._
Expand Down Expand Up @@ -92,7 +91,7 @@ final class ClosureLinkerBackend(config: LinkerBackendImpl.Config)
}

// Compile the module
val closureExterns = List(
val closureExterns = java.util.Arrays.asList(
ClosureSource.fromCode("ScalaJSExterns.js", ClosureLinkerBackend.ScalaJSExterns),
ClosureSource.fromCode("ScalaJSGlobalRefs.js", makeExternsForGlobalRefs(globalRefs)),
ClosureSource.fromCode("ScalaJSExportExterns.js", makeExternsForExports(topLevelVarDeclarations, unit)))
Expand All @@ -101,7 +100,7 @@ final class ClosureLinkerBackend(config: LinkerBackendImpl.Config)

val result = logger.time("Closure: Compiler pass") {
compiler.compileModules(
closureExterns.asJava, List(module).asJava, options)
closureExterns, java.util.Arrays.asList(module), options)
}

if (!result.success) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private[closure] class ClosureModuleBuilder(
relativizeBaseURI: Option[URI] = None) extends JSBuilder {

private val transformer = new ClosureAstTransformer(relativizeBaseURI)
private val treeBuf = mutable.ListBuffer.empty[Node]
private val treeBuf = List.newBuilder[Node]

def addJSTree(tree: Tree): Unit = {
/* Top-level `js.Block`s must be explicitly flattened here.
Expand All @@ -54,8 +54,9 @@ private[closure] class ClosureModuleBuilder(
def result(): JSModule = {
val module = new JSModule("Scala.js")

if (treeBuf.nonEmpty) {
val root = transformer.setNodePosition(IR.script(treeBuf: _*), NoPosition)
val trees = treeBuf.result()
if (trees.nonEmpty) {
val root = transformer.setNodePosition(IR.script(trees: _*), NoPosition)
val ast = new ClosureModuleBuilder.ScalaJSSourceAst(root)
module.add(new CompilerInput(ast, ast.getInputId(), false))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ final class ParIncOptimizer(config: CommonPhaseConfig)
def emptyParIterable[V]: ParIterable[V] = ParArray.empty

// Operations on ParMap
def parMapIsEmpty[K, V](map: ParMap[K, V]): Boolean = map.isEmpty
def forceGet[K, V](map: ParMap[K, V], k: K): V = map(k)
def get[K, V](map: ParMap[K, V], k: K): Option[V] = map.get(k)
def put[K, V](map: ParMap[K, V], k: K, v: V): Unit = map.put(k, v)
def remove[K, V](map: ParMap[K, V], k: K): Option[V] = map.remove(k)

Expand All @@ -51,16 +54,19 @@ final class ParIncOptimizer(config: CommonPhaseConfig)
}
}

def valuesForeach[K, V, U](map: ParMap[K, V])(f: V => U): Unit =
map.values.foreach(f)

// Operations on AccMap
def acc[K, V](map: AccMap[K, V], k: K, v: V): Unit =
map.getOrPut(k, AtomicAcc.empty) += v

def getAcc[K, V](map: AccMap[K, V], k: K): GenIterable[V] =
def getAcc[K, V](map: AccMap[K, V], k: K): ParIterable[V] =
map.get(k).fold[Iterable[V]](Nil)(_.removeAll()).toParArray

def parFlatMapKeys[A, B](map: AccMap[A, _])(
f: A => GenTraversableOnce[B]): GenIterable[B] =
map.keys.flatMap(f).toParArray
f: A => Option[B]): ParIterable[B] =
map.keys.flatMap(f(_)).toParArray

// Operations on ParIterable
def prepAdd[V](it: ParIterable[V]): Addable[V] =
Expand All @@ -71,6 +77,12 @@ final class ParIncOptimizer(config: CommonPhaseConfig)

def finishAdd[V](addable: Addable[V]): ParIterable[V] =
addable.removeAll().toParArray

def foreach[V, U](it: ParIterable[V])(f: V => U): Unit =
it.foreach(f)

def filter[V](it: ParIterable[V])(f: V => Boolean): ParIterable[V] =
it.filter(f)
}

private val _interfaces = TrieMap.empty[String, InterfaceType]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Scala.js (https://www.scala-js.org/)
*
* Copyright EPFL.
*
* Licensed under Apache License 2.0
* (https://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/

package org.scalajs.linker

import scala.collection.mutable

private[linker] object CollectionsCompat {
implicit class MutableMapCompatOps[K, V](val __self: mutable.Map[K, V])
extends AnyVal {

// filterInPlace replaces retain
def filterInPlace(p: (K, V) => Boolean): Unit = {
// Believe it or not, this is the implementation of `retain` in 2.12.x:

// scala/bug#7269 toList avoids ConcurrentModificationException
for ((k, v) <- __self.toList) {
if (!p(k, v))
__self -= k
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ trait Analysis {
import Analysis._

def classInfos: scala.collection.Map[String, ClassInfo]
def errors: Seq[Error]
def errors: scala.collection.Seq[Error]
}

object Analysis {
Expand Down Expand Up @@ -62,8 +62,8 @@ object Analysis {
def encodedName: String
def kind: ClassKind
def superClass: Option[ClassInfo]
def interfaces: Seq[ClassInfo]
def ancestors: Seq[ClassInfo]
def interfaces: scala.collection.Seq[ClassInfo]
def ancestors: scala.collection.Seq[ClassInfo]
def nonExistent: Boolean
/** For a Scala class, it is instantiated with a `New`; for a JS class,
* its constructor is accessed with a `JSLoadConstructor` or because it
Expand All @@ -74,8 +74,8 @@ object Analysis {
def isModuleAccessed: Boolean
def areInstanceTestsUsed: Boolean
def isDataAccessed: Boolean
def linkedFrom: Seq[From]
def instantiatedFrom: Seq[From]
def linkedFrom: scala.collection.Seq[From]
def instantiatedFrom: scala.collection.Seq[From]
def methodInfos(
namespace: MemberNamespace): scala.collection.Map[String, MethodInfo]

Expand All @@ -97,8 +97,8 @@ object Analysis {
def isExported: Boolean
def isReflProxy: Boolean
def isReachable: Boolean
def calledFrom: Seq[From]
def instantiatedSubclasses: Seq[ClassInfo]
def calledFrom: scala.collection.Seq[From]
def instantiatedSubclasses: scala.collection.Seq[ClassInfo]
def nonExistent: Boolean
def syntheticKind: MethodSyntheticKind

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private final class Analyzer(config: CommonPhaseConfig,

def classInfos: scala.collection.Map[String, Analysis.ClassInfo] = _loadedClassInfos

def errors: Seq[Error] = _errors
def errors: scala.collection.Seq[Error] = _errors

def computeReachability(): Future[Unit] = {
require(_classInfos.isEmpty, "Cannot run the same Analyzer multiple times")
Expand Down Expand Up @@ -1150,7 +1150,7 @@ object Analyzer {
}

trait InputProvider {
def classesWithEntryPoints(): TraversableOnce[String]
def classesWithEntryPoints(): Iterable[String]

def loadInfo(encodedName: String)(implicit ec: ExecutionContext): Option[Future[Infos.ClassInfo]]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ object Infos {
this
}

def addInterfaces(interfaces: TraversableOnce[String]): this.type = {
def addInterfaces(interfaces: List[String]): this.type = {
this.interfaces ++= interfaces
this
}
Expand Down Expand Up @@ -319,7 +319,7 @@ object Infos {
def result(): MethodInfo = {
def toMapOfLists[A](
m: mutable.Map[String, mutable.Set[A]]): Map[String, List[A]] = {
m.mapValues(_.toList).toMap
m.map(kv => kv._1 -> kv._2.toList).toMap
}

MethodInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.scalajs.logging._
import org.scalajs.linker._
import org.scalajs.linker.standard._
import org.scalajs.linker.backend.javascript.{Trees => js, _}
import org.scalajs.linker.CollectionsCompat.MutableMapCompatOps

import GlobalRefUtils._

Expand Down Expand Up @@ -402,7 +403,7 @@ final class Emitter private (config: CommonPhaseConfig,
logger.debug(
s"Emitter: Method tree cache stats: resued: $statsMethodsReused -- "+
s"invalidated: $statsMethodsInvalidated")
classCaches.retain((_, c) => c.cleanAfterRun())
classCaches.filterInPlace((_, c) => c.cleanAfterRun())
}

/** Generates all the desugared classes.
Expand Down Expand Up @@ -658,7 +659,7 @@ final class Emitter private (config: CommonPhaseConfig,

private def mergeVersions(v1: Option[String],
v2: Option[String]): Option[String] = {
v1.flatMap(s1 => v2.map(s2 => s1.length + "-" + s1 + s2))
v1.flatMap(s1 => v2.map(s2 => "" + s1.length + "-" + s1 + s2))
}

private def getClassTreeCache(linkedClass: LinkedClass): DesugaredClassCache =
Expand Down Expand Up @@ -722,7 +723,7 @@ final class Emitter private (config: CommonPhaseConfig,
}

def cleanAfterRun(): Boolean = {
_methodCaches.foreach(_.retain((_, c) => c.cleanAfterRun()))
_methodCaches.foreach(_.filterInPlace((_, c) => c.cleanAfterRun()))

if (_constructorCache.exists(!_.cleanAfterRun()))
_constructorCache = None
Expand Down Expand Up @@ -837,9 +838,9 @@ private object Emitter {
cond(!coreSpec.esFeatures.allowBigIntsForLongs) {
multiple(
instanceTests(LongImpl.RuntimeLongClass),
instantiateClass(LongImpl.RuntimeLongClass, LongImpl.AllConstructors),
callMethods(LongImpl.RuntimeLongClass, LongImpl.AllMethods),
callOnModule(LongImpl.RuntimeLongModuleClass, LongImpl.AllModuleMethods)
instantiateClass(LongImpl.RuntimeLongClass, LongImpl.AllConstructors.toList),
callMethods(LongImpl.RuntimeLongClass, LongImpl.AllMethods.toList),
callOnModule(LongImpl.RuntimeLongModuleClass, LongImpl.AllModuleMethods.toList)
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.scalajs.ir.Types.Type

import org.scalajs.linker._
import org.scalajs.linker.standard._
import org.scalajs.linker.CollectionsCompat.MutableMapCompatOps

private[emitter] final class KnowledgeGuardian(config: CommonPhaseConfig) {
import KnowledgeGuardian._
Expand Down Expand Up @@ -73,7 +74,7 @@ private[emitter] final class KnowledgeGuardian(config: CommonPhaseConfig) {
}

// Garbage collection
classes.retain((_, cls) => cls.testAndResetIsAlive())
classes.filterInPlace((_, cls) => cls.testAndResetIsAlive())

val invalidateAll = !firstRun && {
newIsParentDataAccessed != isParentDataAccessed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ private final class IRChecker(unit: LinkingUnit, logger: Logger) {
val initialEnv = Env.fromSignature(NoType, classDef.jsClassCaptures,
params, NoType, isConstructor = true)

val preparedEnv = (initialEnv /: prepStats) { (prevEnv, stat) =>
val preparedEnv = prepStats.foldLeft(initialEnv) { (prevEnv, stat) =>
typecheckStat(stat, prevEnv)
}

Expand Down Expand Up @@ -601,7 +601,7 @@ private final class IRChecker(unit: LinkingUnit, logger: Logger) {
env

case Block(stats) =>
(env /: stats) { (prevEnv, stat) =>
stats.foldLeft(env) { (prevEnv, stat) =>
typecheckStat(stat, prevEnv)
}
env
Expand Down Expand Up @@ -718,7 +718,7 @@ private final class IRChecker(unit: LinkingUnit, logger: Logger) {

case Block(statsAndExpr) =>
val stats :+ expr = statsAndExpr
val envAfterStats = (env /: stats) { (prevEnv, stat) =>
val envAfterStats = stats.foldLeft(env) { (prevEnv, stat) =>
typecheckStat(stat, prevEnv)
}
typecheckExpr(expr, envAfterStats)
Expand Down Expand Up @@ -1321,7 +1321,7 @@ private final class IRChecker(unit: LinkingUnit, logger: Logger) {
val ancestors: Set[String],
val hasInstances: Boolean,
val jsNativeLoadSpec: Option[JSNativeLoadSpec],
_fields: TraversableOnce[CheckedField])(
_fields: List[CheckedField])(
implicit ctx: ErrorContext) {

val fields = _fields.filter(!_.flags.namespace.isStatic).map(f => f.name -> f).toMap
Expand Down
Loading

0 comments on commit e8d8109

Please sign in to comment.