Skip to content

Commit e53521e

Browse files
Merge branch 'lampepfl:main' into fix/bisect-script-releases
2 parents 85bde83 + 25eb48e commit e53521e

File tree

158 files changed

+914
-287
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

158 files changed

+914
-287
lines changed

.github/workflows/ci.yaml

+9-2
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/test"
192+
run: ./project/scripts/sbt ";set ThisBuild/Build.scala2Library := Build.Scala2LibraryTasty ;scala3-bootstrapped/test"
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/test"
190197

191198

192199
test_windows_fast:

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`

compiler/test/dotty/Properties.scala

+3
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ object Properties {
8787

8888
/** If we are using the scala-library TASTy jar */
8989
def usingScalaLibraryTasty: Boolean = scalaLibraryTasty.isDefined
90+
/** If we are using the scala-library TASTy jar */
91+
92+
def usingScalaLibraryCCTasty: Boolean = scalaLibraryTasty.exists(_.contains("scala2-library-cc-tasty"))
9093

9194
/** scala-asm jar */
9295
def scalaAsm: String = sys.props("dotty.tests.classes.scalaAsm")

compiler/test/dotty/tools/dotc/CompilationTests.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ class CompilationTests {
4545
compileFilesInDir("tests/pos", defaultOptions.and("-Ysafe-init", "-Ylegacy-lazy-vals", "-Ycheck-constraint-deps"), FileFilter.include(TestSources.posLazyValsAllowlist)),
4646
compileDir("tests/pos-special/java-param-names", defaultOptions.withJavacOnlyOptions("-parameters")),
4747
) ::: (
48-
// FIXME: This fails due to a bug involving self types and capture checking
49-
if Properties.usingScalaLibraryTasty then Nil
50-
else List(compileDir("tests/pos-special/stdlib", allowDeepSubtypes))
48+
// TODO create a folder for capture checking tests with the stdlib, or use tests/pos-custom-args/captures under this mode?
49+
if Properties.usingScalaLibraryCCTasty then List(compileDir("tests/pos-special/stdlib", allowDeepSubtypes))
50+
else Nil
5151
)
5252

5353
if scala.util.Properties.isJavaAtLeast("16") then

project/Build.scala

+77-21
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(
@@ -764,14 +782,24 @@ object Build {
764782
else if (debugFromTasty) "dotty.tools.dotc.fromtasty.Debug"
765783
else "dotty.tools.dotc.Main"
766784

767-
var extraClasspath =
768-
scalaLibTastyOpt match {
769-
case Some(scalaLibTasty) if useScala2LibraryTasty.value =>
770-
Seq(scalaLibTasty, scalaLib, dottyLib)
771-
case _ =>
772-
if (useScala2LibraryTasty.value) log.warn("useScala2LibraryTasty is ignored on non-bootstrapped compiler")
773-
Seq(scalaLib, dottyLib)
774-
}
785+
val scala2LibraryTasty = scala2Library.value match {
786+
case Scala2LibraryJar => Seq.empty
787+
case Scala2LibraryTasty =>
788+
jars.get("scala2-library-tasty") match {
789+
case Some(jar) => Seq(jar)
790+
case None =>
791+
log.warn("Scala2LibraryTasty is ignored on non-bootstrapped compiler")
792+
Seq.empty
793+
}
794+
case Scala2LibraryCCTasty =>
795+
jars.get("scala2-library-cc-tasty") match {
796+
case Some(jar) => Seq(jar)
797+
case None =>
798+
log.warn("Scala2LibraryCCTasty is ignored on non-bootstrapped compiler")
799+
Seq.empty
800+
}
801+
}
802+
var extraClasspath = scala2LibraryTasty ++ Seq(scalaLib, dottyLib)
775803

776804
if (decompile && !args.contains("-classpath"))
777805
extraClasspath ++= Seq(".")
@@ -882,6 +910,7 @@ object Build {
882910
"scala3-tasty-inspector" -> (LocalProject("scala3-tasty-inspector") / Compile / packageBin).value.getAbsolutePath,
883911
"tasty-core" -> (LocalProject("tasty-core-bootstrapped") / Compile / packageBin).value.getAbsolutePath,
884912
"scala2-library-tasty" -> (LocalProject("scala2-library-tasty") / Compile / packageBin).value.getAbsolutePath,
913+
"scala2-library-cc-tasty" -> (LocalProject("scala2-library-cc-tasty") / Compile / packageBin).value.getAbsolutePath,
885914
)
886915
},
887916

@@ -1010,8 +1039,24 @@ object Build {
10101039
withCommonSettings(Bootstrapped).
10111040
dependsOn(dottyCompiler(Bootstrapped) % "provided; compile->runtime; test->test").
10121041
settings(commonBootstrappedSettings).
1042+
settings(scala2LibraryBootstrappedSettings).
1043+
settings(moduleName := "scala2-library")
1044+
1045+
/** Scala 2 library compiled by dotty using the latest published sources of the library.
1046+
*
1047+
* This version of the library is not (yet) TASTy/binary compatible with the Scala 2 compiled library.
1048+
*/
1049+
lazy val `scala2-library-cc` = project.in(file("scala2-library-cc")).
1050+
withCommonSettings(Bootstrapped).
1051+
dependsOn(dottyCompiler(Bootstrapped) % "provided; compile->runtime; test->test").
1052+
settings(commonBootstrappedSettings).
1053+
settings(scala2LibraryBootstrappedSettings).
10131054
settings(
1014-
moduleName := "scala2-library",
1055+
moduleName := "scala2-library-cc",
1056+
scalacOptions += "-Ycheck:all",
1057+
)
1058+
1059+
lazy val scala2LibraryBootstrappedSettings = Seq(
10151060
javaOptions := (`scala3-compiler-bootstrapped` / javaOptions).value,
10161061
Compile / scalacOptions ++= {
10171062
Seq("-sourcepath", ((Compile/sourceManaged).value / "scala-library-src").toString)
@@ -1096,13 +1141,13 @@ object Build {
10961141
| - final val MinorVersion = $minorVersion
10971142
| - final val ExperimentalVersion = 0
10981143
| * Clean everything to generate a compiler with those new TASTy versions
1099-
| * Run scala2-library-bootstrapped/tastyMiMaReportIssues
1144+
| * Run ${name.value}/tastyMiMaReportIssues
11001145
|""".stripMargin)
11011146

11021147
}).value,
11031148
Compile / exportJars := true,
11041149
artifactName := { (sv: ScalaVersion, module: ModuleID, artifact: Artifact) =>
1105-
"scala2-library-" + dottyVersion + "." + artifact.extension
1150+
moduleName.value + "-" + dottyVersion + "." + artifact.extension
11061151
},
11071152
run := {
11081153
val log = streams.value.log
@@ -1174,7 +1219,7 @@ object Build {
11741219
|""".stripMargin)
11751220
}
11761221
}
1177-
)
1222+
)
11781223

11791224
/** Packages the TASTy files of `scala2-library-bootstrapped` in a jar */
11801225
lazy val `scala2-library-tasty` = project.in(file("scala2-library-tasty")).
@@ -1187,6 +1232,17 @@ object Build {
11871232
},
11881233
)
11891234

1235+
/** Packages the TASTy files of `scala2-library-cc` in a jar */
1236+
lazy val `scala2-library-cc-tasty` = project.in(file("scala2-library-cc-tasty")).
1237+
withCommonSettings(Bootstrapped).
1238+
settings(
1239+
exportJars := true,
1240+
Compile / packageBin / mappings := {
1241+
(`scala2-library-cc` / Compile / packageBin / mappings).value
1242+
.filter(_._2.endsWith(".tasty"))
1243+
},
1244+
)
1245+
11901246
/** Test the tasty generated by `scala2-library-bootstrapped`
11911247
*
11921248
* The sources in src are compiled using TASTy from scala2-library-tasty but then run
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Scala (https://www.scala-lang.org)
3+
*
4+
* Copyright EPFL and Lightbend, Inc.
5+
*
6+
* Licensed under Apache License 2.0
7+
* (http://www.apache.org/licenses/LICENSE-2.0).
8+
*
9+
* See the NOTICE file distributed with this work for
10+
* additional information regarding copyright ownership.
11+
*/
12+
13+
// GENERATED CODE: DO NOT EDIT. See scala.Function0 for timestamp.
14+
15+
package scala
16+
17+
18+
object Function1 {
19+
20+
implicit final class UnliftOps[A, B] private[Function1](private val f: A => Option[B]) extends AnyVal {
21+
/** Converts an optional function to a partial function.
22+
*
23+
* @example Unlike [[Function.unlift]], this [[UnliftOps.unlift]] method can be used in extractors.
24+
* {{{
25+
* val of: Int => Option[String] = { i =>
26+
* if (i == 2) {
27+
* Some("matched by an optional function")
28+
* } else {
29+
* None
30+
* }
31+
* }
32+
*
33+
* util.Random.nextInt(4) match {
34+
* case of.unlift(m) => // Convert an optional function to a pattern
35+
* println(m)
36+
* case _ =>
37+
* println("Not matched")
38+
* }
39+
* }}}
40+
*/
41+
def unlift: PartialFunction[A, B] = Function.unlift(f)
42+
}
43+
44+
}
45+
46+
/** A function of 1 parameter.
47+
*
48+
* In the following example, the definition of `succ` is
49+
* shorthand, conceptually, for the anonymous class definition
50+
* `anonfun1`, although the implementation details of how the
51+
* function value is constructed may differ:
52+
*
53+
* {{{
54+
* object Main extends App {
55+
* val succ = (x: Int) => x + 1
56+
* val anonfun1 = new Function1[Int, Int] {
57+
* def apply(x: Int): Int = x + 1
58+
* }
59+
* assert(succ(0) == anonfun1(0))
60+
* }
61+
* }}}
62+
*
63+
* Note that the difference between `Function1` and [[scala.PartialFunction]]
64+
* is that the latter can specify inputs which it will not handle.
65+
*/
66+
@annotation.implicitNotFound(msg = "No implicit view available from ${T1} => ${R}.")
67+
trait Function1[@specialized(Specializable.Arg) -T1, @specialized(Specializable.Return) +R] extends AnyRef { // FIXME: self =>
68+
/** Apply the body of this function to the argument.
69+
* @return the result of function application.
70+
*/
71+
def apply(v1: T1): R
72+
73+
/** Composes two instances of Function1 in a new Function1, with this function applied last.
74+
*
75+
* @tparam A the type to which function `g` can be applied
76+
* @param g a function A => T1
77+
* @return a new function `f` such that `f(x) == apply(g(x))`
78+
*/
79+
@annotation.unspecialized def compose[A](g: A => T1): A => R = { x => apply(g(x)) }
80+
81+
/** Composes two instances of Function1 in a new Function1, with this function applied first.
82+
*
83+
* @tparam A the result type of function `g`
84+
* @param g a function R => A
85+
* @return a new function `f` such that `f(x) == g(apply(x))`
86+
*/
87+
@annotation.unspecialized def andThen[A](g: R => A): T1 => A = { x => g(apply(x)) }
88+
89+
override def toString(): String = "<function1>"
90+
}

0 commit comments

Comments
 (0)