Skip to content

Commit e3f1aa1

Browse files
authored
port scala-stdlib for Scala.js (#24115)
2 parents f4e6239 + 52495cf commit e3f1aa1

31 files changed

+286
-211
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ jobs:
103103
104104
- name: Scala.js Test
105105
run: |
106-
./project/scripts/sbt ";sjsSandbox/run ;sjsSandbox/test ;sjsJUnitTests/test ;set sjsJUnitTests/scalaJSLinkerConfig ~= switchToESModules ;sjsJUnitTests/test ;sjsCompilerTests/test"
106+
./project/scripts/sbt ";sjsSandbox/run ;sjsSandbox/test ;sjsJUnitTests/test ;set sjsJUnitTests/scalaJSLinkerConfig ~= switchToESModules ;sjsJUnitTests/test"
107107
108108
test_windows_fast:
109109
runs-on: [self-hosted, Windows]
@@ -149,7 +149,7 @@ jobs:
149149
shell: cmd
150150

151151
- name: Scala.js Test
152-
run: sbt ";sjsJUnitTests/test ;set sjsJUnitTests/scalaJSLinkerConfig ~= switchToESModules ;sjsJUnitTests/test ;sjsCompilerTests/test"
152+
run: sbt ";sjsJUnitTests/test ;set sjsJUnitTests/scalaJSLinkerConfig ~= switchToESModules ;sjsJUnitTests/test"
153153
shell: cmd
154154

155155
test_windows_full:

.github/workflows/stdlib.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,13 +392,33 @@ jobs:
392392
- name: Report MiMa issues in `tasty-core-bootstrapped`
393393
run: ./project/scripts/sbt tasty-core-bootstrapped-new/mimaReportBinaryIssues
394394

395+
mima-scala-library-sjs:
396+
runs-on: ubuntu-latest
397+
needs: scala-library-sjs
398+
steps:
399+
- name: Git Checkout
400+
uses: actions/checkout@v5
401+
402+
- name: Set up JDK 17
403+
uses: actions/setup-java@v5
404+
with:
405+
distribution: 'temurin'
406+
java-version: 17
407+
cache: 'sbt'
408+
409+
- uses: sbt/setup-sbt@v1
410+
- name: Report MiMa issues in `scala-library-sjs`
411+
run: ./project/scripts/sbt scala-library-sjs/mimaReportBinaryIssues
412+
395413
#################################################################################################
396414
########################################### TEST JOBS ###########################################
397415
#################################################################################################
398416

399417
test-scala3-compiler-nonbootstrapped:
400418
runs-on: ubuntu-latest
401419
needs: [scala3-compiler-nonbootstrapped, tasty-core-nonbootstrapped, scala-library-nonbootstrapped]
420+
# Non-bootstrapped can definetely not be enabled until we have at least 3.8.0-RC1 as a reference compiler
421+
if: false
402422
steps:
403423
- name: Git Checkout
404424
uses: actions/checkout@v5
@@ -497,3 +517,20 @@ jobs:
497517
- uses: sbt/setup-sbt@v1
498518
- name: Test `tasty-core-bootstrapped`
499519
run: ./project/scripts/sbt tasty-core-bootstrapped-new/test
520+
521+
test-scala-js:
522+
runs-on: ubuntu-latest
523+
needs: [scala3-compiler-bootstrapped, tasty-core-bootstrapped, scala3-staging, scala3-tasty-inspector, scala-library-sjs]
524+
steps:
525+
- name: Git Checkout
526+
uses: actions/checkout@v5
527+
528+
- name: Set up JDK 17
529+
uses: actions/setup-java@v5
530+
with:
531+
distribution: 'temurin'
532+
java-version: 17
533+
cache: 'sbt'
534+
- uses: sbt/setup-sbt@v1
535+
- name: Test Scala.js
536+
run: ./project/scripts/sbt sjsCompilerTests/test

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ object SourceLanguage:
3232
SourceLanguage.Java
3333
// Scala 2 methods don't have Inline set, except for the ones injected with `patchStdlibClass`
3434
// which are really Scala 3 methods.
35-
else if denot.isClass && denot.is(Scala2x) || (denot.maybeOwner.lastKnownDenotation.is(Scala2x) && !denot.is(Inline)) then
35+
else if denot.isClass && denot.is(Scala2x)
36+
|| (denot.maybeOwner.lastKnownDenotation.is(Scala2x) && !denot.is(Inline))
37+
|| denot.is(Param) && denot.maybeOwner.is(Method) && denot.maybeOwner.maybeOwner.lastKnownDenotation.is(Scala2x) then
3638
SourceLanguage.Scala2
3739
else
3840
SourceLanguage.Scala3

compiler/test/dotty/Properties.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ object Properties {
5757
/** dotty-interfaces jar */
5858
def dottyInterfaces: String = sys.props("dotty.tests.classes.dottyInterfaces")
5959

60-
/** dotty-library-js jar */
61-
def dottyLibraryJS: String = sys.props("dotty.tests.classes.dottyLibraryJS")
62-
6360
/** dotty-compiler jar */
6461
def dottyCompiler: String = sys.props("dotty.tests.classes.dottyCompiler")
6562

compiler/test/dotty/tools/vulpix/TestConfiguration.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ object TestConfiguration {
4848
Properties.scalaJSJavalib,
4949
Properties.scalaJSScalalib,
5050
Properties.scalaJSLibrary,
51-
Properties.dottyLibraryJS
5251
))
5352

5453
def mkClasspath(classpaths: List[String]): String =

library-js/src/scala/App.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
package scala
1414

15+
import scala.language.`2.13`
16+
1517
import java.lang.System.{currentTimeMillis => currentTime}
1618
import scala.collection.mutable.ListBuffer
1719

library-js/src/scala/Array.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
package scala
1414

15+
import scala.language.`2.13`
16+
1517
import language.experimental.captureChecking
1618

1719
//import scala.collection.generic._

library-js/src/scala/Console.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
package scala
1414

15+
import scala.language.`2.13`
16+
1517
import java.io.{ BufferedReader, InputStream, InputStreamReader, OutputStream, PrintStream, Reader }
1618
import scala.io.AnsiColor
1719
import scala.util.DynamicVariable

library-js/src/scala/Enumeration.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
package scala
1414

15+
import scala.language.`2.13`
16+
1517
import scala.collection.{SpecificIterableFactory, StrictOptimizedIterableOps, View, immutable, mutable}
1618
import java.lang.reflect.{Field => JField, Method => JMethod}
1719

library-js/src/scala/Symbol.scala

Lines changed: 6 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
package scala
1414

15+
import scala.language.`2.13`
16+
1517
import scala.scalajs.js
1618

1719
/** This class provides a simple way to get unique objects for equal strings.
@@ -37,15 +39,14 @@ final class Symbol private (val name: String) extends Serializable {
3739
override def equals(other: Any) = this eq other.asInstanceOf[AnyRef]
3840
}
3941

40-
// Modified to use Scala.js specific cache
41-
object Symbol extends JSUniquenessCache[Symbol] {
42+
object Symbol extends UniquenessCache[String, Symbol] {
4243
override def apply(name: String): Symbol = super.apply(name)
4344
protected def valueFromKey(name: String): Symbol = new Symbol(name)
4445
protected def keyFromValue(sym: Symbol): Option[String] = Some(sym.name)
4546
}
4647

47-
private[scala] abstract class JSUniquenessCache[V]
48-
{
48+
// Modified to use Scala.js specific cache
49+
private[scala] abstract class UniquenessCache[K, V >: Null] {
4950
private val cache = js.Dictionary.empty[V]
5051

5152
protected def valueFromKey(k: String): V
@@ -55,59 +56,4 @@ private[scala] abstract class JSUniquenessCache[V]
5556
cache.getOrElseUpdate(name, valueFromKey(name))
5657

5758
def unapply(other: V): Option[String] = keyFromValue(other)
58-
}
59-
60-
/** This is private so it won't appear in the library API, but
61-
* abstracted to offer some hope of reusability. */
62-
/* DELETED for Scala.js
63-
private[scala] abstract class UniquenessCache[K >: js.String, V >: Null]
64-
{
65-
66-
import java.lang.ref.WeakReference
67-
import java.util.WeakHashMap
68-
import java.util.concurrent.locks.ReentrantReadWriteLock
69-
70-
private[this] val rwl = new ReentrantReadWriteLock()
71-
private[this] val rlock = rwl.readLock
72-
private[this] val wlock = rwl.writeLock
73-
private[this] val map = new WeakHashMap[K, WeakReference[V]]
74-
75-
protected def valueFromKey(k: K): V
76-
protected def keyFromValue(v: V): Option[K]
77-
78-
def apply(name: K): V = {
79-
def cached(): V = {
80-
rlock.lock
81-
try {
82-
val reference = map get name
83-
if (reference == null) null
84-
else reference.get // will be null if we were gc-ed
85-
}
86-
finally rlock.unlock
87-
}
88-
def updateCache(): V = {
89-
wlock.lock
90-
try {
91-
val res = cached()
92-
if (res != null) res
93-
else {
94-
// If we don't remove the old String key from the map, we can
95-
// wind up with one String as the key and a different String as
96-
// the name field in the Symbol, which can lead to surprising GC
97-
// behavior and duplicate Symbols. See scala/bug#6706.
98-
map remove name
99-
val sym = valueFromKey(name)
100-
map.put(name, new WeakReference(sym))
101-
sym
102-
}
103-
}
104-
finally wlock.unlock
105-
}
106-
107-
val res = cached()
108-
if (res == null) updateCache()
109-
else res
110-
}
111-
def unapply(other: V): Option[K] = keyFromValue(other)
112-
}
113-
*/
59+
}

0 commit comments

Comments
 (0)