Skip to content

Commit

Permalink
Replace stdlib-bootstrapped with stdlib-2_13-bootstrapped
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed May 23, 2023
1 parent 52bf33e commit 50d4524
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 127 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ jobs:

- name: Cmd Tests
run: |
./project/scripts/sbt ";dist/pack; scala3-bootstrapped/compile; scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/* ;stdlib-bootstrapped/test:run ;stdlib-2_13-bootstrapped/test:run ;stdlib-bootstrapped-tasty-tests/test; scala3-compiler-bootstrapped/scala3CompilerCoursierTest:test"
./project/scripts/sbt ";dist/pack; scala3-bootstrapped/compile; scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/* ;stdlib-bootstrapped/test:run ;stdlib-bootstrapped-tasty-tests/test; scala3-compiler-bootstrapped/scala3CompilerCoursierTest:test"
./project/scripts/cmdTests
./project/scripts/bootstrappedOnlyCmdTests
Expand Down Expand Up @@ -253,7 +253,7 @@ jobs:

- name: MiMa
run: |
./project/scripts/sbt ";scala3-interfaces/mimaReportBinaryIssues ;scala3-library-bootstrapped/mimaReportBinaryIssues ;scala3-library-bootstrappedJS/mimaReportBinaryIssues; tasty-core-bootstrapped/mimaReportBinaryIssues; stdlib-2_13-bootstrapped/mimaReportBinaryIssues"
./project/scripts/sbt ";scala3-interfaces/mimaReportBinaryIssues ;scala3-library-bootstrapped/mimaReportBinaryIssues ;scala3-library-bootstrappedJS/mimaReportBinaryIssues; tasty-core-bootstrapped/mimaReportBinaryIssues; stdlib-bootstrapped/mimaReportBinaryIssues"
community_build_a:
runs-on: [self-hosted, Linux]
Expand Down Expand Up @@ -488,7 +488,7 @@ jobs:

- name: Test
run: |
./project/scripts/sbt ";dist/pack ;scala3-bootstrapped/compile ;scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/* ;stdlib-bootstrapped/test:run ;stdlib-2_13-bootstrapped/test:run ;stdlib-bootstrapped-tasty-tests/test"
./project/scripts/sbt ";dist/pack ;scala3-bootstrapped/compile ;scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/* ;stdlib-bootstrapped/test:run ;stdlib-bootstrapped-tasty-tests/test"
./project/scripts/cmdTests
./project/scripts/bootstrappedOnlyCmdTests
Expand Down
1 change: 0 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ val `scala3-bench` = Build.`scala3-bench`
val `scala3-bench-bootstrapped` = Build.`scala3-bench-bootstrapped`
val `scala3-bench-micro` = Build.`scala3-bench-micro`
val `stdlib-bootstrapped` = Build.`stdlib-bootstrapped`
val `stdlib-2_13-bootstrapped` = Build.`stdlib-2_13-bootstrapped`
val `stdlib-bootstrapped-tasty-tests` = Build.`stdlib-bootstrapped-tasty-tests`
val `tasty-core` = Build.`tasty-core`
val `tasty-core-bootstrapped` = Build.`tasty-core-bootstrapped`
Expand Down
104 changes: 24 additions & 80 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -922,96 +922,30 @@ object Build {
javaOptions := (`scala3-compiler-bootstrapped` / javaOptions).value
)

/** Scala library compiled by dotty using the latest published sources of the 2.13 library
* and the current Scala 3 library sources.
*
* This version of the library is not binary compatible with the Scala 2 compiled library.
* It compiles every file as Scala 3 sources.
*/
lazy val `stdlib-bootstrapped` = project.in(file("stdlib-bootstrapped")).
withCommonSettings(Bootstrapped).
dependsOn(dottyCompiler(Bootstrapped) % "provided; compile->runtime; test->test").
settings(commonStdlibBootstrappedSettings).
settings(
Compile/scalacOptions ++= {
Seq(
"-sourcepath",
Seq(
(Compile/sourceManaged).value / "scala-library-src",
(Compile/sourceManaged).value / "dotty-library-src",
).mkString(File.pathSeparator),
)
},
(Compile / sourceGenerators) += Def.task {
val s = streams.value
val cacheDir = s.cacheDirectory
val trgDir = (Compile / sourceManaged).value / "dotty-library-src"

// NOTE `sourceDirectory` is used for actual copying,
// but `sources` are used as cache keys
val dottyLibSourceDirs = (`scala3-library-bootstrapped`/Compile/unmanagedSourceDirectories).value
def dottyLibSources = dottyLibSourceDirs.foldLeft(PathFinder.empty) { (pf, dir) =>
if (!dir.exists) pf else pf +++ (dir ** "*.scala") +++ (dir ** "*.java")
}

val cachedFun = FileFunction.cached(
cacheDir / s"copyDottyLibrarySrc",
FilesInfo.lastModified,
FilesInfo.exists,
) { _ =>
if (trgDir.exists) IO.delete(trgDir)
dottyLibSourceDirs.foreach { dir =>
if (dir.exists) {
s.log.info(s"Copying scala3-library sources from $dir to $trgDir...")
IO.copyDirectory(dir, trgDir)
}
}

((trgDir ** "*.scala") +++ (trgDir ** "*.java")).get.toSet
}

cachedFun(dottyLibSources.get.toSet).toSeq
}.taskValue,
)

/** Scala 2 library compiled by dotty using the latest published sources of the library.
*
* This version of the library is not (yet) binary compatible with the Scala 2 compiled library.
* This version of the library is not (yet) TASTy/binary compatible with the Scala 2 compiled library.
*/
lazy val `stdlib-2_13-bootstrapped` = project.in(file("stdlib-2_13-bootstrapped")).
lazy val `stdlib-bootstrapped` = project.in(file("stdlib-bootstrapped")).
withCommonSettings(Bootstrapped).
dependsOn(dottyCompiler(Bootstrapped) % "provided; compile->runtime; test->test").
settings(commonStdlibBootstrappedSettings).
settings(commonBootstrappedSettings).
settings(
scalacOptions += "-Yscala2-stdlib",
Compile / scalacOptions ++= {
Seq("-sourcepath", ((Compile/sourceManaged).value / "scala-library-src").toString)
},
// TODO package only TASTy files.
// We first need to check that a project can depend on a JAR that only contains TASTy files.
// Compile / exportJars := true,
// Compile / packageBin / mappings ~= { _.filter(_._2.endsWith(".tasty")) },
mimaCheckDirection := "both",
mimaBackwardIssueFilters := MiMaFilters.StdlibBootstrappedBackwards,
mimaForwardIssueFilters := MiMaFilters.StdlibBootstrappedForward,
mimaPreviousArtifacts += "org.scala-lang" % "scala-library" % stdlibVersion(Bootstrapped),
mimaExcludeAnnotations ++= Seq(
"scala.annotation.experimental",
"scala.annotation.specialized",
"scala.annotation.unspecialized",
),
)

lazy val commonStdlibBootstrappedSettings =
commonBootstrappedSettings ++ Seq(
moduleName := "scala-library",
javaOptions := (`scala3-compiler-bootstrapped` / javaOptions).value,
Compile / doc / scalacOptions += "-Ydocument-synthetic-types",
scalacOptions += "-Yscala2-stdlib",
scalacOptions -= "-Xfatal-warnings",
ivyConfigurations += SourceDeps.hide,
transitiveClassifiers := Seq("sources"),
libraryDependencies +=
("org.scala-lang" % "scala-library" % stdlibVersion(Bootstrapped) % "sourcedeps"),
(Test / managedClasspath) ~= {
_.filterNot(file => file.data.getName == s"scala-library-${stdlibVersion(Bootstrapped)}.jar")
},
Compile / scalacOptions ++= {
Seq("-sourcepath", ((Compile/sourceManaged).value / "scala-library-src").toString)
},
(Compile / sourceGenerators) += Def.task {
val s = streams.value
val cacheDir = s.cacheDirectory
Expand Down Expand Up @@ -1051,10 +985,20 @@ object Build {
val reference = (Compile/sourceManaged).value / "scala-library-src"
files.filterNot(_.relativeTo(reference).exists(overwritenSources))
},
(Test / managedClasspath) ~= {
_.filterNot(file => file.data.getName == s"scala-library-${stdlibVersion(Bootstrapped)}.jar")
},
)
// TODO package only TASTy files.
// We first need to check that a project can depend on a JAR that only contains TASTy files.
// Compile / exportJars := true,
// Compile / packageBin / mappings ~= { _.filter(_._2.endsWith(".tasty")) },
mimaCheckDirection := "both",
mimaBackwardIssueFilters := MiMaFilters.StdlibBootstrappedBackwards,
mimaForwardIssueFilters := MiMaFilters.StdlibBootstrappedForward,
mimaPreviousArtifacts += "org.scala-lang" % "scala-library" % stdlibVersion(Bootstrapped),
mimaExcludeAnnotations ++= Seq(
"scala.annotation.experimental",
"scala.annotation.specialized",
"scala.annotation.unspecialized",
),
)

/** Test the tasty generated by `stdlib-bootstrapped`
*
Expand Down
42 changes: 0 additions & 42 deletions stdlib-2_13-bootstrapped/test/Main.scala

This file was deleted.

32 changes: 31 additions & 1 deletion stdlib-bootstrapped/test/Main.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,42 @@
package hello

import scala.util.*
import scala.compiletime.testing.typeChecks

enum Color:
case Red, Green, Blue

object HelloWorld:
def main(args: Array[String]): Unit = {
println("hello dotty.superbootstrapped!")
println("hello 2.13 library bootstrapped")
println(Color.Red)
println(Color.Green)
println(Color.Blue)

testScala2UnapplySignatures()
testScala2ObjectParents()
testScala2ProductMembers()
}

def testScala2UnapplySignatures() = {
val _: Option[Int] = Some.unapply(Some(1))
val _: Option[Int] = Right.unapply(Right(1))
val _: Option[(Int, List[Int])] = ::.unapply(::(1, Nil))

val _: Option[Int] = Tuple1.unapply(Tuple1(1))
val _: Option[(Int, Int)] = Tuple2.unapply((1, 2))
val _: Option[(Int, Int, Int)] = Tuple3.unapply((1, 2, 3))
}

def testScala2ObjectParents() = {
assert(!typeChecks("Either: scala.deriving.Mirror.Sum"))
assert(!typeChecks("Either: scala.deriving.Mirror"))
}
def testScala2ProductMembers() = {
Some(1)._1
Right(1)._1
(1, 2)._1
(1, 2)._2
::(1, Nil)._1
::(1, Nil)._2
}

0 comments on commit 50d4524

Please sign in to comment.