From fe7c711f11455cfeedc28cfb7ef87967732b2dbc Mon Sep 17 00:00:00 2001 From: Hamza Remmal Date: Tue, 7 Oct 2025 13:44:28 +0200 Subject: [PATCH 1/2] fix: also do specialisation during Scala.js --- .../dotty/tools/dotc/transform/SpecializeApplyMethods.scala | 3 --- .../src/dotty/tools/dotc/transform/SpecializeFunctions.scala | 3 --- compiler/src/dotty/tools/dotc/transform/SpecializeTuples.scala | 1 - 3 files changed, 7 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/transform/SpecializeApplyMethods.scala b/compiler/src/dotty/tools/dotc/transform/SpecializeApplyMethods.scala index c85f06e6075f..a7c9b679d65e 100644 --- a/compiler/src/dotty/tools/dotc/transform/SpecializeApplyMethods.scala +++ b/compiler/src/dotty/tools/dotc/transform/SpecializeApplyMethods.scala @@ -25,9 +25,6 @@ class SpecializeApplyMethods extends MiniPhase with InfoTransformer { override def description: String = SpecializeApplyMethods.description - override def isEnabled(using Context): Boolean = - !ctx.settings.scalajs.value && !Feature.shouldBehaveAsScala2 - private def specApplySymbol(sym: Symbol, args: List[Type], ret: Type)(using Context): Symbol = { val name = nme.apply.specializedFunction(ret, args) // Create the symbol at the next phase, so that it is a valid member of the diff --git a/compiler/src/dotty/tools/dotc/transform/SpecializeFunctions.scala b/compiler/src/dotty/tools/dotc/transform/SpecializeFunctions.scala index 43aef6279cec..007ea3112c09 100644 --- a/compiler/src/dotty/tools/dotc/transform/SpecializeFunctions.scala +++ b/compiler/src/dotty/tools/dotc/transform/SpecializeFunctions.scala @@ -19,9 +19,6 @@ class SpecializeFunctions extends MiniPhase { override def runsAfter = Set(ElimByName.name) - override def isEnabled(using Context): Boolean = - !ctx.settings.scalajs.value - /** Create forwarders from the generic applys to the specialized ones. */ override def transformDefDef(ddef: DefDef)(using Context) = { diff --git a/compiler/src/dotty/tools/dotc/transform/SpecializeTuples.scala b/compiler/src/dotty/tools/dotc/transform/SpecializeTuples.scala index 264659930505..6e732ddf9c55 100644 --- a/compiler/src/dotty/tools/dotc/transform/SpecializeTuples.scala +++ b/compiler/src/dotty/tools/dotc/transform/SpecializeTuples.scala @@ -20,7 +20,6 @@ class SpecializeTuples extends MiniPhase: override def phaseName: String = SpecializeTuples.name override def description: String = SpecializeTuples.description - override def isEnabled(using Context): Boolean = !ctx.settings.scalajs.value override def transformApply(tree: Apply)(using Context): Tree = tree match case Apply(TypeApply(fun: NameTree, targs), args) From 7fc7925008e5924ef8d561141de84ea69e826f2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Doeraene?= Date: Tue, 7 Oct 2025 13:09:51 +0200 Subject: [PATCH 2/2] Wire sjsSandbox and sjsJUnitTests for the new stdlib. Co-authored-by: Hamza Remmal --- .github/workflows/ci.yaml | 8 ------ .github/workflows/stdlib.yaml | 9 +++++-- project/Build.scala | 50 ++++++++++++++++++++++++++++++++--- 3 files changed, 53 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 7ab5e48113a7..7a617328809e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -101,10 +101,6 @@ jobs: ./project/scripts/cmdTests ./project/scripts/bootstrappedOnlyCmdTests - - name: Scala.js Test - run: | - ./project/scripts/sbt ";sjsSandbox/run ;sjsSandbox/test ;sjsJUnitTests/test ;set sjsJUnitTests/scalaJSLinkerConfig ~= switchToESModules ;sjsJUnitTests/test" - test_windows_fast: runs-on: [self-hosted, Windows] if: "( @@ -148,10 +144,6 @@ jobs: run: './project/scripts/winCmdTests.bat' shell: cmd - - name: Scala.js Test - run: sbt ";sjsJUnitTests/test ;set sjsJUnitTests/scalaJSLinkerConfig ~= switchToESModules ;sjsJUnitTests/test" - shell: cmd - test_windows_full: runs-on: [self-hosted, Windows] if: "github.event_name == 'schedule' && github.repository == 'scala/scala3' diff --git a/.github/workflows/stdlib.yaml b/.github/workflows/stdlib.yaml index f4aba9095def..cce7bab92f3c 100644 --- a/.github/workflows/stdlib.yaml +++ b/.github/workflows/stdlib.yaml @@ -532,5 +532,10 @@ jobs: java-version: 17 cache: 'sbt' - uses: sbt/setup-sbt@v1 - - name: Test Scala.js - run: ./project/scripts/sbt sjsCompilerTests/test \ No newline at end of file + - name: Scala.js compiler tests + run: ./project/scripts/sbt "sjsCompilerTests/test" + - name: Scala.js sandbox + run: ./project/scripts/sbt ";sjsSandbox/run ;sjsSandbox/test" + - name: Scala.js JUnit tests + run: ./project/scripts/sbt ";sjsJUnitTests/test ;set sjsJUnitTests/scalaJSLinkerConfig ~= switchToESModules ;sjsJUnitTests/test" + # TODO Scala.js on Windows diff --git a/project/Build.scala b/project/Build.scala index 431f6d11e353..7064adf4f8fe 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -2936,6 +2936,48 @@ object Build { BuildInfoPlugin.buildInfoDefaultSettings ) + /** Common settings for sjsSandbox and sjsJUnitTests */ + lazy val regularScalaJSProjectSettings: Seq[Setting[_]] = Def.settings( + version := dottyVersion, + scalaVersion := referenceVersion, + crossPaths := true, + autoScalaLibrary := false, // do not add a dependency to stdlib, we depend on it with dependsOn + // Add the source directories + Compile / unmanagedSourceDirectories := Seq(baseDirectory.value / "src"), + Test / unmanagedSourceDirectories := Seq(baseDirectory.value / "test"), + // NOTE: The only difference here is that we drop `-Werror` and semanticDB for now + Compile / scalacOptions := Seq("-deprecation", "-feature", "-unchecked", "-encoding", "UTF8", "-language:implicitConversions"), + Compile / scalacOptions += "-scalajs", // we really need this one for Scala.js projects + // Don't publish + publish / skip := false, + // Configure to use the non-bootstrapped compiler + scalaInstance := { + val externalCompilerDeps = (`scala3-compiler-nonbootstrapped` / Compile / externalDependencyClasspath).value.map(_.data).toSet + + // IMPORTANT: We need to use actual jars to form the ScalaInstance and not + // just directories containing classfiles because sbt maintains a cache of + // compiler instances. This cache is invalidated based on timestamps + // however this is only implemented on jars, directories are never + // invalidated. + val tastyCore = (`tasty-core-nonbootstrapped` / Compile / packageBin).value + val scalaLibrary = (`scala-library-nonbootstrapped` / Compile / packageBin).value + val scala3Interfaces = (`scala3-interfaces` / Compile / packageBin).value + val scala3Compiler = (`scala3-compiler-nonbootstrapped` / Compile / packageBin).value + + Defaults.makeScalaInstance( + dottyNonBootstrappedVersion, + libraryJars = Array(scalaLibrary), + allCompilerJars = Seq(tastyCore, scala3Interfaces, scala3Compiler) ++ externalCompilerDeps, + allDocJars = Seq.empty, + state.value, + scalaInstanceTopLoader.value + ) + }, + scalaCompilerBridgeBinaryJar := { + Some((`scala3-sbt-bridge-nonbootstrapped` / Compile / packageBin).value) + }, + ) + /** A sandbox to play with the Scala.js back-end of dotty. * * This sandbox is compiled with dotty with support for Scala.js. It can be @@ -2947,9 +2989,9 @@ object Build { */ lazy val sjsSandbox = project.in(file("sandbox/scalajs")). enablePlugins(DottyJSPlugin). - dependsOn(`scala3-library-bootstrappedJS`). + dependsOn(`scala-library-sjs`). settings( - commonBootstrappedSettings, + regularScalaJSProjectSettings, // Required to run Scala.js tests. Test / fork := false, @@ -2965,9 +3007,9 @@ object Build { */ lazy val sjsJUnitTests = project.in(file("tests/sjs-junit")). enablePlugins(DottyJSPlugin). - dependsOn(`scala3-library-bootstrappedJS`). + dependsOn(`scala-library-sjs`). settings( - commonBootstrappedSettings, + regularScalaJSProjectSettings, bspEnabled := false, scalacOptions --= Seq("-Werror", "-deprecation"),