Skip to content

Commit c4cdbc4

Browse files
committed
Add scala2-library-cc-tasty project
We can override the sources of the standard library with cc annotation in this project and generate a TASTy version of the standard library.
1 parent 06c925b commit c4cdbc4

File tree

4 files changed

+62
-11
lines changed

4 files changed

+62
-11
lines changed

.github/workflows/ci.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ jobs:
145145
- name: Test with Scala 2 library TASTy
146146
run: ./project/scripts/sbt ";set ThisBuild/Build.useScala2LibraryTasty := true ;scala3-bootstrapped/testCompilation i5; scala3-bootstrapped/testCompilation tests/run/typelevel-peano.scala" # only test a subset of test to avoid doubling the CI execution time
147147

148+
- name: Test with Scala 2 library TASTy with CC
149+
run: ./project/scripts/sbt ";set ThisBuild/Build.useScala2LibraryCCTasty := true ;scala3-bootstrapped/testCompilation i5; scala3-bootstrapped/testCompilation tests/run/typelevel-peano.scala" # only test a subset of test to avoid doubling the CI execution time
150+
148151
test_windows_fast:
149152
runs-on: [self-hosted, Windows]
150153
if: "(
@@ -256,7 +259,7 @@ jobs:
256259

257260
- name: MiMa
258261
run: |
259-
./project/scripts/sbt ";scala3-interfaces/mimaReportBinaryIssues ;scala3-library-bootstrapped/mimaReportBinaryIssues ;scala3-library-bootstrappedJS/mimaReportBinaryIssues; tasty-core-bootstrapped/mimaReportBinaryIssues; scala2-library-bootstrapped/mimaReportBinaryIssues"
262+
./project/scripts/sbt ";scala3-interfaces/mimaReportBinaryIssues ;scala3-library-bootstrapped/mimaReportBinaryIssues ;scala3-library-bootstrappedJS/mimaReportBinaryIssues; tasty-core-bootstrapped/mimaReportBinaryIssues; scala2-library-bootstrapped/mimaReportBinaryIssues; scala2-library-cc/mimaReportBinaryIssues"
260263
261264
- name: TASTy MiMa
262265
run: |

build.sbt

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ val `scala3-bench-micro` = Build.`scala3-bench-micro`
1717
val `scala2-library-bootstrapped` = Build.`scala2-library-bootstrapped`
1818
val `scala2-library-tasty` = Build.`scala2-library-tasty`
1919
val `scala2-library-tasty-tests` = Build.`scala2-library-tasty-tests`
20+
val `scala2-library-cc` = Build.`scala2-library-cc`
21+
val `scala2-library-cc-tasty` = Build.`scala2-library-cc-tasty`
2022
val `tasty-core` = Build.`tasty-core`
2123
val `tasty-core-bootstrapped` = Build.`tasty-core-bootstrapped`
2224
val `tasty-core-scala2` = Build.`tasty-core-scala2`

project/Build.scala

+53-10
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,15 @@ object Build {
176176
// Use the TASTy jar from `scala2-library-tasty` in the classpath
177177
// This only works with `scala3-bootstrapped/scalac` and tests in `scala3-bootstrapped`
178178
//
179-
// Enable in SBT with: set ThisBuild/Build.useScala2LibraryTasty := true
179+
// Enable in SBT with: `set ThisBuild/Build.useScala2LibraryTasty := true`
180180
val useScala2LibraryTasty = settingKey[Boolean]("Use the TASTy jar from `scala2-library-tasty` in the classpath")
181181

182+
// Use the TASTy jar from `scala2-library-cc-tasty` in the classpath
183+
// This only works with `scala3-bootstrapped/scalac` and tests in `scala3-bootstrapped`
184+
//
185+
// Enable in SBT with: `set ThisBuild/Build.useScala2LibraryCCTasty := true`
186+
val useScala2LibraryCCTasty = settingKey[Boolean]("Use the TASTy jar from `scala2-library-cc-tasty` in the classpath")
187+
182188
// Used to compile files similar to ./bin/scalac script
183189
val scalac = inputKey[Unit]("run the compiler using the correct classpath, or the user supplied classpath")
184190

@@ -226,6 +232,7 @@ object Build {
226232
outputStrategy := Some(StdoutOutput),
227233

228234
useScala2LibraryTasty := false,
235+
useScala2LibraryCCTasty := false,
229236

230237
// enable verbose exception messages for JUnit
231238
(Test / testOptions) += Tests.Argument(TestFrameworks.JUnit, "-a", "-v", "-s"),
@@ -653,7 +660,18 @@ object Build {
653660
Seq.empty
654661
}
655662

656-
scala2LibraryTasty ++ Seq(
663+
val scala2LibraryCCTasty = jars.get("scala2-library-cc-tasty") match {
664+
case Some(scala2LibraryCCTastyJar) if useScala2LibraryCCTasty.value =>
665+
if (useScala2LibraryTasty.value) {
666+
log.warn("Both useScala2LibraryTasty and useScala2LibraryCCTasty are set (ignoring useScala2LibraryCCTasty)")
667+
Seq.empty
668+
} else Seq("-Ddotty.tests.tasties.scalaLibrary=" + scala2LibraryCCTastyJar)
669+
case _ =>
670+
if (useScala2LibraryCCTasty.value) log.warn("useScala2LibraryCCTasty is ignored on non-bootstrapped compiler")
671+
Seq.empty
672+
}
673+
674+
scala2LibraryTasty ++ scala2LibraryCCTasty ++ Seq(
657675
"-Ddotty.tests.dottyCompilerManagedSources=" + managedSrcDir,
658676
"-Ddotty.tests.classes.dottyInterfaces=" + jars("scala3-interfaces"),
659677
"-Ddotty.tests.classes.dottyLibrary=" + jars("scala3-library"),
@@ -876,6 +894,7 @@ object Build {
876894
"scala3-tasty-inspector" -> (LocalProject("scala3-tasty-inspector") / Compile / packageBin).value.getAbsolutePath,
877895
"tasty-core" -> (LocalProject("tasty-core-bootstrapped") / Compile / packageBin).value.getAbsolutePath,
878896
"scala2-library-tasty" -> (LocalProject("scala2-library-tasty") / Compile / packageBin).value.getAbsolutePath,
897+
"scala2-library-cc-tasty" -> (LocalProject("scala2-library-cc-tasty") / Compile / packageBin).value.getAbsolutePath,
879898
)
880899
},
881900

@@ -1004,8 +1023,21 @@ object Build {
10041023
withCommonSettings(Bootstrapped).
10051024
dependsOn(dottyCompiler(Bootstrapped) % "provided; compile->runtime; test->test").
10061025
settings(commonBootstrappedSettings).
1007-
settings(
1008-
moduleName := "scala2-library",
1026+
settings(scala2LibraryBootstrappedSettings).
1027+
settings(moduleName := "scala2-library")
1028+
1029+
/** Scala 2 library compiled by dotty using the latest published sources of the library.
1030+
*
1031+
* This version of the library is not (yet) TASTy/binary compatible with the Scala 2 compiled library.
1032+
*/
1033+
lazy val `scala2-library-cc` = project.in(file("scala2-library-cc")).
1034+
withCommonSettings(Bootstrapped).
1035+
dependsOn(dottyCompiler(Bootstrapped) % "provided; compile->runtime; test->test").
1036+
settings(commonBootstrappedSettings).
1037+
settings(scala2LibraryBootstrappedSettings).
1038+
settings(moduleName := "scala2-library-cc")
1039+
1040+
lazy val scala2LibraryBootstrappedSettings = Seq(
10091041
javaOptions := (`scala3-compiler-bootstrapped` / javaOptions).value,
10101042
Compile / scalacOptions ++= {
10111043
Seq("-sourcepath", ((Compile/sourceManaged).value / "scala-library-src").toString)
@@ -1088,13 +1120,13 @@ object Build {
10881120
| - final val MinorVersion = $minorVersion
10891121
| - final val ExperimentalVersion = 0
10901122
| * Clean everything to generate a compiler with those new TASTy versions
1091-
| * Run scala2-library-bootstrapped/tastyMiMaReportIssues
1123+
| * Run ${name.value}/tastyMiMaReportIssues
10921124
|""".stripMargin)
10931125

10941126
}).value,
10951127
Compile / exportJars := true,
10961128
artifactName := { (sv: ScalaVersion, module: ModuleID, artifact: Artifact) =>
1097-
"scala2-library-" + dottyVersion + "." + artifact.extension
1129+
moduleName.value + "-" + dottyVersion + "." + artifact.extension
10981130
},
10991131
run := {
11001132
val log = streams.value.log
@@ -1132,18 +1164,18 @@ object Build {
11321164
println(
11331165
s"""Usage:
11341166
|> $projectName/run list
1135-
| -- lists all files that are not overriden in scala2-library-bootstrapped/src
1167+
| -- lists all files that are not overriden in ${name.value}/src
11361168
|
11371169
|> $projectName/run clone <sources>*
1138-
| -- clones the specified sources from the scala2-library-bootstrapped/src
1170+
| -- clones the specified sources from the ${name.value}/src
11391171
| -- example: $projectName/run clone scala/Option.scala
11401172
|
11411173
|> $projectName/run overwrite <sources>*
1142-
| -- (danger) overwrites the specified sources from the scala2-library-bootstrapped/src
1174+
| -- (danger) overwrites the specified sources from the ${name.value}/src
11431175
|""".stripMargin)
11441176
}
11451177
}
1146-
)
1178+
)
11471179

11481180
/** Packages the TASTy files of `scala2-library-bootstrapped` in a jar */
11491181
lazy val `scala2-library-tasty` = project.in(file("scala2-library-tasty")).
@@ -1156,6 +1188,17 @@ object Build {
11561188
},
11571189
)
11581190

1191+
/** Packages the TASTy files of `scala2-library-cc` in a jar */
1192+
lazy val `scala2-library-cc-tasty` = project.in(file("scala2-library-cc-tasty")).
1193+
withCommonSettings(Bootstrapped).
1194+
settings(
1195+
exportJars := true,
1196+
Compile / packageBin / mappings := {
1197+
(`scala2-library-cc` / Compile / packageBin / mappings).value
1198+
.filter(_._2.endsWith(".tasty"))
1199+
},
1200+
)
1201+
11591202
/** Test the tasty generated by `scala2-library-bootstrapped`
11601203
*
11611204
* The sources in src are compiled using TASTy from scala2-library-tasty but then run

project/scripts/scala2-library-tasty-mima.sh

+3
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@ setTastyVersion $MINOR_TASTY_VERSION_SUPPORTED_BY_TASTY_MIMA 0
2020
# We set -Ycheck:all to check that -Ycompile-scala2-library does not gererate inconsistent trees.
2121
"$SBT" 'clean; scala2-library-bootstrapped/clean; reload; set `scala2-library-bootstrapped`/scalacOptions += "-Ycheck:all"; scala2-library-bootstrapped/tastyMiMaReportIssues; clean; scala2-library-bootstrapped/clean'
2222

23+
# Do the same tests with scala2-library-cc
24+
"$SBT" 'clean; scala2-library-cc/clean; reload; set `scala2-library-cc`/scalacOptions += "-Ycheck:all"; scala2-library-cc/tastyMiMaReportIssues; clean; scala2-library-cc/clean'
25+
2326
setTastyVersion $MINOR_TASTY_VERSION $EXPERIMENTAL_TASTY_VERSION

0 commit comments

Comments
 (0)