Skip to content

Commit 2d8a572

Browse files
committed
chore: first draft of the stdlib
1 parent f7e5df5 commit 2d8a572

File tree

9 files changed

+3409
-44
lines changed

9 files changed

+3409
-44
lines changed

project/Build.scala

+85
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import sbtbuildinfo.BuildInfoPlugin.autoImport._
3232
import sbttastymima.TastyMiMaPlugin
3333
import sbttastymima.TastyMiMaPlugin.autoImport._
3434

35+
import scala.jdk.CollectionConverters._
36+
3537
import scala.util.Properties.isJavaAtLeast
3638

3739
import org.portablescala.sbtplatformdeps.PlatformDepsPlugin.autoImport._
@@ -1278,13 +1280,96 @@ object Build {
12781280
sources
12791281
} (Set(scalaLibrarySourcesJar)).toSeq
12801282
}.taskValue,
1283+
(Compile / resourceGenerators) += Def.task {
1284+
val s = streams.value
1285+
val cacheDir = s.cacheDirectory
1286+
val trgDir = (Compile / resourceManaged).value / "scala-library-classes"
1287+
val report = update.value
1288+
1289+
val scalaLibraryBinaryJar = report.select(
1290+
configuration = configurationFilter(),
1291+
module = (_: ModuleID).name == "scala-library",
1292+
artifact = artifactFilter(`type` = "jar")).headOption.getOrElse {
1293+
sys.error(s"Could not fetch scala-library binary JAR")
1294+
}
1295+
1296+
FileFunction.cached(cacheDir / s"fetchScalaLibraryClasses",
1297+
FilesInfo.lastModified, FilesInfo.exists) { dependencies =>
1298+
s.log.info(s"Unpacking scala-library binaries to $trgDir...")
1299+
if (trgDir.exists)
1300+
IO.delete(trgDir)
1301+
IO.createDirectory(trgDir)
1302+
IO.unzip(scalaLibraryBinaryJar, trgDir)
1303+
1304+
(trgDir ** "*.class").get.toSet
1305+
} (Set(scalaLibraryBinaryJar)).toSeq
1306+
}.taskValue,
12811307
(Compile / sources) := {
12821308
val files = (Compile / sources).value
12831309
val overwrittenSourcesDir = (Compile / scalaSource).value
12841310
val overwrittenSources = files.flatMap(_.relativeTo(overwrittenSourcesDir)).toSet
12851311
val reference = (Compile/sourceManaged).value / "scala-library-src"
12861312
files.filterNot(_.relativeTo(reference).exists(overwrittenSources))
12871313
},
1314+
(Compile / compile) := {
1315+
val result = (Compile / compile).value
1316+
println("Generating the diff...")
1317+
val files = (Compile / resources).value
1318+
val overwrittenSources = Files.walk((Compile / classDirectory).value.toPath())
1319+
.iterator()
1320+
.asScala
1321+
.map(_.toFile)
1322+
.map(_.relativeTo((Compile / classDirectory).value).get)
1323+
.toSet
1324+
val reference = (Compile / resourceManaged).value / "scala-library-classes"
1325+
val diff = files.filterNot(_.relativeTo(reference).exists(overwrittenSources))
1326+
1327+
IO.copy(diff.map { file =>
1328+
file -> (Compile / classDirectory).value / file.relativeTo(reference).get.getPath
1329+
})
1330+
1331+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "Tuple1.class"), (Compile / classDirectory).value / "scala" / "Tuple1.class" )
1332+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "Tuple2.class"), (Compile / classDirectory).value / "scala" / "Tuple2.class" )
1333+
1334+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "collection" / "DoubleStepper.class"), (Compile / classDirectory).value / "scala" / "collection" / "DoubleStepper.class" )
1335+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "collection" / "IntStepper.class"), (Compile / classDirectory).value / "scala" / "collection" / "IntStepper.class" )
1336+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "collection" / "LongStepper.class"), (Compile / classDirectory).value / "scala" / "collection" / "LongStepper.class" )
1337+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "collection" / "immutable" / "DoubleVectorStepper.class"), (Compile / classDirectory).value / "scala" / "collection" / "immutable" / "DoubleVectorStepper.class" )
1338+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "collection" / "immutable" / "IntVectorStepper.class"), (Compile / classDirectory).value / "scala" / "collection" / "immutable" / "IntVectorStepper.class" )
1339+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "collection" / "immutable" / "LongVectorStepper.class"), (Compile / classDirectory).value / "scala" / "collection" / "immutable" / "LongVectorStepper.class" )
1340+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "jdk" / "DoubleAccumulator.class"), (Compile / classDirectory).value / "scala" / "jdk" / "DoubleAccumulator.class" )
1341+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "jdk" / "IntAccumulator.class"), (Compile / classDirectory).value / "scala" / "jdk" / "IntAccumulator.class" )
1342+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "jdk" / "LongAccumulator.class"), (Compile / classDirectory).value / "scala" / "jdk" / "LongAccumulator.class" )
1343+
1344+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "jdk" / "FunctionWrappers$FromJavaBooleanSupplier.class"), (Compile / classDirectory).value / "scala" / "jdk" / "FunctionWrappers$FromJavaBooleanSupplier.class" )
1345+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "jdk" / "FunctionWrappers$FromJavaDoubleBinaryOperator.class"), (Compile / classDirectory).value / "scala" / "jdk" / "FunctionWrappers$FromJavaDoubleBinaryOperator.class" )
1346+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "jdk" / "FunctionWrappers$FromJavaDoubleConsumer.class"), (Compile / classDirectory).value / "scala" / "jdk" / "FunctionWrappers$FromJavaDoubleConsumer.class" )
1347+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "jdk" / "FunctionWrappers$FromJavaDoublePredicate.class"), (Compile / classDirectory).value / "scala" / "jdk" / "FunctionWrappers$FromJavaDoublePredicate.class" )
1348+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "jdk" / "FunctionWrappers$FromJavaDoubleSupplier.class"), (Compile / classDirectory).value / "scala" / "jdk" / "FunctionWrappers$FromJavaDoubleSupplier.class" )
1349+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "jdk" / "FunctionWrappers$FromJavaDoubleToIntFunction.class"), (Compile / classDirectory).value / "scala" / "jdk" / "FunctionWrappers$FromJavaDoubleToIntFunction.class" )
1350+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "jdk" / "FunctionWrappers$FromJavaDoubleToLongFunction.class"), (Compile / classDirectory).value / "scala" / "jdk" / "FunctionWrappers$FromJavaDoubleToLongFunction.class" )
1351+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "jdk" / "FunctionWrappers$FromJavaDoubleUnaryOperator.class"), (Compile / classDirectory).value / "scala" / "jdk" / "FunctionWrappers$FromJavaDoubleUnaryOperator.class" )
1352+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "jdk" / "FunctionWrappers$FromJavaIntBinaryOperator.class"), (Compile / classDirectory).value / "scala" / "jdk" / "FunctionWrappers$FromJavaIntBinaryOperator.class" )
1353+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "jdk" / "FunctionWrappers$FromJavaIntConsumer.class"), (Compile / classDirectory).value / "scala" / "jdk" / "FunctionWrappers$FromJavaIntConsumer.class" )
1354+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "jdk" / "FunctionWrappers$FromJavaIntPredicate.class"), (Compile / classDirectory).value / "scala" / "jdk" / "FunctionWrappers$FromJavaIntPredicate.class" )
1355+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "jdk" / "FunctionWrappers$FromJavaIntSupplier.class"), (Compile / classDirectory).value / "scala" / "jdk" / "FunctionWrappers$FromJavaIntSupplier.class" )
1356+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "jdk" / "FunctionWrappers$FromJavaIntToDoubleFunction.class"), (Compile / classDirectory).value / "scala" / "jdk" / "FunctionWrappers$FromJavaIntToDoubleFunction.class" )
1357+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "jdk" / "FunctionWrappers$FromJavaIntToLongFunction.class"), (Compile / classDirectory).value / "scala" / "jdk" / "FunctionWrappers$FromJavaIntToLongFunction.class" )
1358+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "jdk" / "FunctionWrappers$FromJavaIntUnaryOperator.class"), (Compile / classDirectory).value / "scala" / "jdk" / "FunctionWrappers$FromJavaIntUnaryOperator.class" )
1359+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "jdk" / "FunctionWrappers$FromJavaLongBinaryOperator.class"), (Compile / classDirectory).value / "scala" / "jdk" / "FunctionWrappers$FromJavaLongBinaryOperator.class" )
1360+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "jdk" / "FunctionWrappers$FromJavaLongConsumer.class"), (Compile / classDirectory).value / "scala" / "jdk" / "FunctionWrappers$FromJavaLongConsumer.class" )
1361+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "jdk" / "FunctionWrappers$FromJavaLongPredicate.class"), (Compile / classDirectory).value / "scala" / "jdk" / "FunctionWrappers$FromJavaLongPredicate.class" )
1362+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "jdk" / "FunctionWrappers$FromJavaLongSupplier.class"), (Compile / classDirectory).value / "scala" / "jdk" / "FunctionWrappers$FromJavaLongSupplier.class" )
1363+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "jdk" / "FunctionWrappers$FromJavaLongToDoubleFunction.class"), (Compile / classDirectory).value / "scala" / "jdk" / "FunctionWrappers$FromJavaLongToDoubleFunction.class" )
1364+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "jdk" / "FunctionWrappers$FromJavaLongToIntFunction.class"), (Compile / classDirectory).value / "scala" / "jdk" / "FunctionWrappers$FromJavaLongToIntFunction.class" )
1365+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "jdk" / "FunctionWrappers$FromJavaLongUnaryOperator.class"), (Compile / classDirectory).value / "scala" / "jdk" / "FunctionWrappers$FromJavaLongUnaryOperator.class" )
1366+
1367+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "collection" / "ArrayOps$ReverseIterator.class"), (Compile / classDirectory).value / "scala" / "collection" / "ArrayOps$ReverseIterator.class" )
1368+
1369+
IO.copyFile(((Compile / resourceManaged).value / "scala-library-classes" / "scala" / "runtime" / "NonLocalReturnControl.class"), (Compile / classDirectory).value / "scala" / "runtime" / "NonLocalReturnControl.class" )
1370+
1371+
result
1372+
},
12881373
(Test / managedClasspath) ~= {
12891374
_.filterNot(file => file.data.getName == s"scala-library-$stdlibBootstrappedVersion.jar")
12901375
},

project/Scala2LibraryBootstrappedMiMaFilters.scala

+11-44
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,9 @@ object Scala2LibraryBootstrappedMiMaFilters {
66
val BackwardsBreakingChanges: Map[String, Seq[ProblemFilter]] = Map(
77
Build.stdlibBootstrappedVersion -> {
88
Seq(
9-
// Files that are not compiled in the bootstrapped library
10-
ProblemFilters.exclude[MissingClassProblem]("scala.AnyVal"),
11-
129
// Scala language features
1310
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.language.<clinit>"),
1411
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.language#experimental.<clinit>"),
15-
ProblemFilters.exclude[FinalClassProblem]("scala.language$experimental$"),
16-
ProblemFilters.exclude[FinalClassProblem]("scala.languageFeature$*$"),
1712

1813
// trait $init$
1914
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.*.$init$"),
@@ -23,39 +18,18 @@ object Scala2LibraryBootstrappedMiMaFilters {
2318

2419
// Companion module class
2520
ProblemFilters.exclude[FinalClassProblem]("scala.*$"),
26-
27-
// Scala 2 intrinsic macros
28-
ProblemFilters.exclude[FinalMethodProblem]("scala.StringContext.s"),
29-
30-
// Specialization?
31-
ProblemFilters.exclude[MissingFieldProblem]("scala.Tuple1._1"), // field _1 in class scala.Tuple1 does not have a correspondent in current version
32-
ProblemFilters.exclude[MissingFieldProblem]("scala.Tuple2._1"), // field _1 in class scala.Tuple2 does not have a correspondent in current version
33-
ProblemFilters.exclude[MissingFieldProblem]("scala.Tuple2._2"), // field _2 in class scala.Tuple2 does not have a correspondent in current version
34-
35-
// Scala 2 specialization
36-
ProblemFilters.exclude[MissingClassProblem]("scala.*$sp"),
37-
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.*$sp"),
38-
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.*#*#sp.$init$"),
39-
ProblemFilters.exclude[MissingTypesProblem]("scala.collection.DoubleStepper"),
40-
ProblemFilters.exclude[MissingTypesProblem]("scala.collection.immutable.DoubleVectorStepper"),
41-
ProblemFilters.exclude[MissingTypesProblem]("scala.collection.immutable.IntVectorStepper"),
42-
ProblemFilters.exclude[MissingTypesProblem]("scala.collection.immutable.LongVectorStepper"),
43-
ProblemFilters.exclude[MissingTypesProblem]("scala.collection.IntStepper"),
44-
ProblemFilters.exclude[MissingTypesProblem]("scala.collection.LongStepper"),
45-
ProblemFilters.exclude[MissingTypesProblem]("scala.jdk.DoubleAccumulator"),
46-
ProblemFilters.exclude[MissingTypesProblem]("scala.jdk.FunctionWrappers$*"),
47-
ProblemFilters.exclude[MissingTypesProblem]("scala.jdk.IntAccumulator"),
48-
ProblemFilters.exclude[MissingTypesProblem]("scala.jdk.LongAccumulator"),
49-
ProblemFilters.exclude[FinalClassProblem]("scala.collection.ArrayOps$ReverseIterator"),
50-
ProblemFilters.exclude[FinalClassProblem]("scala.Tuple1"),
51-
ProblemFilters.exclude[FinalClassProblem]("scala.Tuple2"),
52-
53-
// other
54-
ProblemFilters.exclude[FinalMethodProblem]("scala.Enumeration.ValueOrdering"),
55-
ProblemFilters.exclude[FinalMethodProblem]("scala.Enumeration.ValueSet"),
5621
ProblemFilters.exclude[FinalMethodProblem]("scala.io.Source.NoPositioner"),
5722
ProblemFilters.exclude[FinalMethodProblem]("scala.io.Source.RelaxedPosition"),
5823
ProblemFilters.exclude[FinalMethodProblem]("scala.io.Source.RelaxedPositioner"),
24+
ProblemFilters.exclude[FinalMethodProblem]("scala.Enumeration.ValueOrdering"),
25+
ProblemFilters.exclude[FinalMethodProblem]("scala.Enumeration.ValueSet"),
26+
27+
// TODO: Remove this filter when we don't use resources to unpack the binaries
28+
ProblemFilters.exclude[MissingClassProblem]("scala-library-classes.*"),
29+
30+
// Scala 2 intrinsic macros, why is it final ?
31+
ProblemFilters.exclude[FinalMethodProblem]("scala.StringContext.s"),
32+
5933
ProblemFilters.exclude[IncompatibleResultTypeProblem]("scala.collection.immutable.SortedMapOps.coll"),
6034
ProblemFilters.exclude[IncompatibleResultTypeProblem]("scala.collection.immutable.TreeMap.empty"),
6135
ProblemFilters.exclude[IncompatibleResultTypeProblem]("scala.collection.immutable.TreeMap.fromSpecific"),
@@ -64,18 +38,9 @@ object Scala2LibraryBootstrappedMiMaFilters {
6438
ProblemFilters.exclude[IncompatibleResultTypeProblem]("scala.collection.mutable.TreeMap.fromSpecific"),
6539
ProblemFilters.exclude[IncompatibleResultTypeProblem]("scala.reflect.ManifestFactory#NothingManifest.newArray"),
6640
ProblemFilters.exclude[IncompatibleResultTypeProblem]("scala.reflect.ManifestFactory#NullManifest.newArray"),
67-
ProblemFilters.exclude[MissingFieldProblem]("scala.collection.ArrayOps#ReverseIterator.xs"),
68-
ProblemFilters.exclude[MissingFieldProblem]("scala.runtime.NonLocalReturnControl.value"),
6941
ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.collection.immutable.SortedMapOps.coll"),
7042
) ++
7143
Seq( // DirectMissingMethodProblem
72-
"scala.collection.LinearSeqIterator#LazyCell.this",
73-
"scala.collection.mutable.PriorityQueue#ResizableArrayAccess.this",
74-
"scala.concurrent.BatchingExecutor#AbstractBatch.this",
75-
"scala.concurrent.Channel#LinkedList.this",
76-
"scala.Enumeration#ValueOrdering.this",
77-
"scala.io.Source#RelaxedPosition.this",
78-
"scala.collection.IterableOnceOps#Maximized.this", // New in 2.13.11: private inner class
7944
"scala.util.Properties.<clinit>",
8045
"scala.util.Sorting.scala$util$Sorting$$mergeSort$default$5",
8146
).map(ProblemFilters.exclude[DirectMissingMethodProblem])
@@ -90,6 +55,8 @@ object Scala2LibraryBootstrappedMiMaFilters {
9055
ProblemFilters.exclude[MissingFieldProblem]("scala.language.experimental"),
9156
ProblemFilters.exclude[MissingFieldProblem]("scala.languageFeature*"),
9257

58+
ProblemFilters.exclude[MissingClassProblem]("scala-library-classes.*"),
59+
9360
// https://github.com/scala/scala/blob/v2.13.10/src/library/scala/collection/immutable/Range.scala#LL155C1-L156C1
9461
// Issue #17519: we do not set final on the default methods of final copy method.
9562
ProblemFilters.exclude[FinalMethodProblem]("scala.collection.immutable.Range.copy$default$*"),

0 commit comments

Comments
 (0)