Skip to content

Commit 752834a

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. Usage: ``` sbt> set ThisBuild/Build.scala2Library := Build.Scala2LibraryCCTasty sbt> scala3-bootstrapped/testCompilation sbt> scala3-bootstrapped/test sbt> scala3-bootstrapped/run ... ```
1 parent 07ff4fb commit 752834a

File tree

3 files changed

+91
-26
lines changed

3 files changed

+91
-26
lines changed

.github/workflows/ci.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,10 @@ jobs:
145145
./project/scripts/sbt ";sjsSandbox/run ;sjsSandbox/test ;sjsJUnitTests/test ;set sjsJUnitTests/scalaJSLinkerConfig ~= switchToESModules ;sjsJUnitTests/test ;sjsCompilerTests/test"
146146
147147
- name: Test with Scala 2 library TASTy (fast)
148-
run: ./project/scripts/sbt ";set ThisBuild/Build.useScala2LibraryTasty := true ;scala3-bootstrapped/testCompilation i5; scala3-bootstrapped/testCompilation tests/run/typelevel-peano.scala; scala3-bootstrapped/testOnly dotty.tools.backend.jvm.DottyBytecodeTests" # only test a subset of test to avoid doubling the CI execution time
148+
run: ./project/scripts/sbt ";set ThisBuild/Build.scala2Library := Build.Scala2LibraryTasty ;scala3-bootstrapped/testCompilation i5; scala3-bootstrapped/testCompilation tests/run/typelevel-peano.scala; scala3-bootstrapped/testOnly dotty.tools.backend.jvm.DottyBytecodeTests" # only test a subset of test to avoid doubling the CI execution time
149+
150+
- name: Test with Scala 2 library with CC TASTy (fast)
151+
run: ./project/scripts/sbt ";set ThisBuild/Build.scala2Library := Build.Scala2LibraryCCTasty ;scala2-library-tasty/compile" # TODO test all the test configurations in non-CC library (currently disabled due to bug while loading the library)
149152

150153
test_scala2_library_tasty:
151154
runs-on: [self-hosted, Linux]
@@ -186,7 +189,11 @@ jobs:
186189
run: cp -vf .github/workflows/repositories /root/.sbt/ ; true
187190

188191
- name: Test with Scala 2 library TASTy
189-
run: ./project/scripts/sbt ";set ThisBuild/Build.useScala2LibraryTasty := true ;scala3-bootstrapped/testCompilation"
192+
run: ./project/scripts/sbt ";set ThisBuild/Build.scala2Library := Build.Scala2LibraryTasty ;scala3-bootstrapped/testCompilation"
193+
194+
# TODO test all the test configurations in non-CC library (currently disabled due to bug while loading the library)
195+
# - name: Test with Scala 2 library with CC TASTy
196+
# run: ./project/scripts/sbt ";set ThisBuild/Build.scala2Library := Build.Scala2LibraryCCTasty ;scala3-bootstrapped/testCompilation"
190197

191198

192199
test_windows_fast:

build.sbt

Lines changed: 2 additions & 0 deletions
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

Lines changed: 80 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,23 @@ object Build {
173173
// Run tests with filter through vulpix test suite
174174
val testCompilation = inputKey[Unit]("runs integration test with the supplied filter")
175175

176+
sealed trait Scala2Library
177+
// Use Scala 2 compiled library JAR
178+
object Scala2LibraryJar extends Scala2Library
176179
// Use the TASTy jar from `scala2-library-tasty` in the classpath
177180
// This only works with `scala3-bootstrapped/scalac` and tests in `scala3-bootstrapped`
178181
//
179-
// Enable in SBT with: `set ThisBuild/Build.useScala2LibraryTasty := true`
180-
val useScala2LibraryTasty = settingKey[Boolean]("Use the TASTy jar from `scala2-library-tasty` in the classpath")
182+
object Scala2LibraryTasty extends Scala2Library
183+
// Use the TASTy jar from `scala2-library-cc-tasty` in the classpath
184+
// This only works with `scala3-bootstrapped/scalac` and tests in `scala3-bootstrapped`
185+
//
186+
object Scala2LibraryCCTasty extends Scala2Library
187+
188+
// Set in SBT with:
189+
// - `set ThisBuild/Build.scala2Library := Build.Scala2LibraryJar` (default)
190+
// - `set ThisBuild/Build.scala2Library := Build.Scala2LibraryTasty`
191+
// - `set ThisBuild/Build.scala2Library := Build.Scala2LibraryCCTasty`
192+
val scala2Library = settingKey[Scala2Library]("Choose which version of the Scala 2 library should be used")
181193

182194
// Used to compile files similar to ./bin/scalac script
183195
val scalac = inputKey[Unit]("run the compiler using the correct classpath, or the user supplied classpath")
@@ -225,7 +237,7 @@ object Build {
225237

226238
outputStrategy := Some(StdoutOutput),
227239

228-
useScala2LibraryTasty := false,
240+
scala2Library := Scala2LibraryJar,
229241

230242
// enable verbose exception messages for JUnit
231243
(Test / testOptions) += Tests.Argument(TestFrameworks.JUnit, "-a", "-v", "-s"),
@@ -645,12 +657,18 @@ object Build {
645657
val externalDeps = externalCompilerClasspathTask.value
646658
val jars = packageAll.value
647659

648-
val scala2LibraryTasty = jars.get("scala2-library-tasty") match {
649-
case Some(scala2LibraryTastyJar) if useScala2LibraryTasty.value =>
650-
Seq("-Ddotty.tests.tasties.scalaLibrary=" + scala2LibraryTastyJar)
651-
case _ =>
652-
if (useScala2LibraryTasty.value) log.warn("useScala2LibraryTasty is ignored on non-bootstrapped compiler")
653-
Seq.empty
660+
def libraryPathProperty(jarName: String): Seq[String] =
661+
jars.get(jarName) match {
662+
case Some(jar) =>
663+
Seq(s"-Ddotty.tests.tasties.scalaLibrary=$jar")
664+
case None =>
665+
log.warn("Scala 2 library TASTy is ignored on non-bootstrapped compiler")
666+
Seq.empty
667+
}
668+
val scala2LibraryTasty = scala2Library.value match {
669+
case Scala2LibraryJar => Seq.empty
670+
case Scala2LibraryTasty => libraryPathProperty("scala2-library-tasty")
671+
case Scala2LibraryCCTasty => libraryPathProperty("scala2-library-cc-tasty")
654672
}
655673

656674
scala2LibraryTasty ++ Seq(
@@ -758,14 +776,24 @@ object Build {
758776
else if (debugFromTasty) "dotty.tools.dotc.fromtasty.Debug"
759777
else "dotty.tools.dotc.Main"
760778

761-
var extraClasspath =
762-
scalaLibTastyOpt match {
763-
case Some(scalaLibTasty) if useScala2LibraryTasty.value =>
764-
Seq(scalaLibTasty, scalaLib, dottyLib)
765-
case _ =>
766-
if (useScala2LibraryTasty.value) log.warn("useScala2LibraryTasty is ignored on non-bootstrapped compiler")
767-
Seq(scalaLib, dottyLib)
768-
}
779+
val scala2LibraryTasty = scala2Library.value match {
780+
case Scala2LibraryJar => Seq.empty
781+
case Scala2LibraryTasty =>
782+
jars.get("scala2-library-tasty") match {
783+
case Some(jar) => Seq(jar)
784+
case None =>
785+
log.warn("Scala2LibraryTasty is ignored on non-bootstrapped compiler")
786+
Seq.empty
787+
}
788+
case Scala2LibraryCCTasty =>
789+
jars.get("scala2-library-cc-tasty") match {
790+
case Some(jar) => Seq(jar)
791+
case None =>
792+
log.warn("Scala2LibraryCCTasty is ignored on non-bootstrapped compiler")
793+
Seq.empty
794+
}
795+
}
796+
var extraClasspath = scala2LibraryTasty ++ Seq(scalaLib, dottyLib)
769797

770798
if (decompile && !args.contains("-classpath"))
771799
extraClasspath ++= Seq(".")
@@ -876,6 +904,7 @@ object Build {
876904
"scala3-tasty-inspector" -> (LocalProject("scala3-tasty-inspector") / Compile / packageBin).value.getAbsolutePath,
877905
"tasty-core" -> (LocalProject("tasty-core-bootstrapped") / Compile / packageBin).value.getAbsolutePath,
878906
"scala2-library-tasty" -> (LocalProject("scala2-library-tasty") / Compile / packageBin).value.getAbsolutePath,
907+
"scala2-library-cc-tasty" -> (LocalProject("scala2-library-cc-tasty") / Compile / packageBin).value.getAbsolutePath,
879908
)
880909
},
881910

@@ -1004,8 +1033,24 @@ object Build {
10041033
withCommonSettings(Bootstrapped).
10051034
dependsOn(dottyCompiler(Bootstrapped) % "provided; compile->runtime; test->test").
10061035
settings(commonBootstrappedSettings).
1036+
settings(scala2LibraryBootstrappedSettings).
1037+
settings(moduleName := "scala2-library")
1038+
1039+
/** Scala 2 library compiled by dotty using the latest published sources of the library.
1040+
*
1041+
* This version of the library is not (yet) TASTy/binary compatible with the Scala 2 compiled library.
1042+
*/
1043+
lazy val `scala2-library-cc` = project.in(file("scala2-library-cc")).
1044+
withCommonSettings(Bootstrapped).
1045+
dependsOn(dottyCompiler(Bootstrapped) % "provided; compile->runtime; test->test").
1046+
settings(commonBootstrappedSettings).
1047+
settings(scala2LibraryBootstrappedSettings).
10071048
settings(
1008-
moduleName := "scala2-library",
1049+
moduleName := "scala2-library-cc",
1050+
scalacOptions += "-Ycheck:all",
1051+
)
1052+
1053+
lazy val scala2LibraryBootstrappedSettings = Seq(
10091054
javaOptions := (`scala3-compiler-bootstrapped` / javaOptions).value,
10101055
Compile / scalacOptions ++= {
10111056
Seq("-sourcepath", ((Compile/sourceManaged).value / "scala-library-src").toString)
@@ -1089,13 +1134,13 @@ object Build {
10891134
| - final val MinorVersion = $minorVersion
10901135
| - final val ExperimentalVersion = 0
10911136
| * Clean everything to generate a compiler with those new TASTy versions
1092-
| * Run scala2-library-bootstrapped/tastyMiMaReportIssues
1137+
| * Run ${name.value}/tastyMiMaReportIssues
10931138
|""".stripMargin)
10941139

10951140
}).value,
10961141
Compile / exportJars := true,
10971142
artifactName := { (sv: ScalaVersion, module: ModuleID, artifact: Artifact) =>
1098-
"scala2-library-" + dottyVersion + "." + artifact.extension
1143+
moduleName.value + "-" + dottyVersion + "." + artifact.extension
10991144
},
11001145
run := {
11011146
val log = streams.value.log
@@ -1133,18 +1178,18 @@ object Build {
11331178
println(
11341179
s"""Usage:
11351180
|> $projectName/run list
1136-
| -- lists all files that are not overriden in scala2-library-bootstrapped/src
1181+
| -- lists all files that are not overriden in ${name.value}/src
11371182
|
11381183
|> $projectName/run clone <sources>*
1139-
| -- clones the specified sources from the scala2-library-bootstrapped/src
1184+
| -- clones the specified sources from the ${name.value}/src
11401185
| -- example: $projectName/run clone scala/Option.scala
11411186
|
11421187
|> $projectName/run overwrite <sources>*
1143-
| -- (danger) overwrites the specified sources from the scala2-library-bootstrapped/src
1188+
| -- (danger) overwrites the specified sources from the ${name.value}/src
11441189
|""".stripMargin)
11451190
}
11461191
}
1147-
)
1192+
)
11481193

11491194
/** Packages the TASTy files of `scala2-library-bootstrapped` in a jar */
11501195
lazy val `scala2-library-tasty` = project.in(file("scala2-library-tasty")).
@@ -1157,6 +1202,17 @@ object Build {
11571202
},
11581203
)
11591204

1205+
/** Packages the TASTy files of `scala2-library-cc` in a jar */
1206+
lazy val `scala2-library-cc-tasty` = project.in(file("scala2-library-cc-tasty")).
1207+
withCommonSettings(Bootstrapped).
1208+
settings(
1209+
exportJars := true,
1210+
Compile / packageBin / mappings := {
1211+
(`scala2-library-cc` / Compile / packageBin / mappings).value
1212+
.filter(_._2.endsWith(".tasty"))
1213+
},
1214+
)
1215+
11601216
/** Test the tasty generated by `scala2-library-bootstrapped`
11611217
*
11621218
* The sources in src are compiled using TASTy from scala2-library-tasty but then run

0 commit comments

Comments
 (0)