Skip to content

Commit

Permalink
Merge branch 'develop' into bump-scala3-334
Browse files Browse the repository at this point in the history
  • Loading branch information
eed3si9n authored Oct 20, 2024
2 parents e429da3 + e2e2e8d commit 20dba76
Show file tree
Hide file tree
Showing 122 changed files with 494 additions and 261 deletions.
26 changes: 17 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jobs:
- os: ubuntu-latest
java: 21
jobtype: 5
- os: ubuntu-latest
java: 21
jobtype: 6
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
Expand Down Expand Up @@ -67,23 +70,28 @@ jobs:
shell: bash
run: |
sbt -v -Dfile.encoding=UTF-8 "-Dbenchmark.pattern=.*Shapeless.*" "runBenchmarks"
- name: Checkout Target Branch (4, 5)
if: ${{ github.event_name == 'pull_request' && (matrix.jobtype == 4 || matrix.jobtype == 5) }}
- name: Benchmark (AnalysisFormatBenchmark) (6)
if: ${{ matrix.jobtype == 6 }}
shell: bash
run: |
sbt -v -Dfile.encoding=UTF-8 "-Dbenchmark.pattern=.*AnalysisFormatBenchmark.*" "runBenchmarks"
- name: Checkout Target Branch (4-6)
if: ${{ github.event_name == 'pull_request' && (matrix.jobtype >= 4 && matrix.jobtype <= 6) }}
uses: actions/checkout@v4
with:
clean: false
ref: ${{ github.event.pull_request.base.ref }}
- name: Setup SBT
uses: sbt/setup-sbt@v1
if: ${{ github.event_name == 'pull_request' && (matrix.jobtype >= 4 && matrix.jobtype <= 6) }}
- name: Benchmark (Scalac) against Target Branch (4)
if: ${{ github.event_name == 'pull_request' && matrix.jobtype == 4 }}
shell: bash
run: |
sbt -v -Dfile.encoding=UTF-8 "-Dbenchmark.pattern=.*Scalac.*" "zincBenchmarks3/Jmh/clean" "runBenchmarks"
sbt -v -Dfile.encoding=UTF-8 "-Dbenchmark.pattern=.*Scalac.*" "runBenchmarks"
- name: Benchmark (Shapeless) against Target Branch (5)
if: ${{ github.event_name == 'pull_request' && matrix.jobtype == 5 }}
shell: bash
run: |
sbt -v -Dfile.encoding=UTF-8 "-Dbenchmark.pattern=.*Shapeless.*" "zincBenchmarks3/Jmh/clean" "runBenchmarks"
sbt -v -Dfile.encoding=UTF-8 "-Dbenchmark.pattern=.*Shapeless.*" "runBenchmarks"
- name: Benchmark (AnalysisFormatBenchmark) against Target Branch (6)
if: ${{ github.event_name == 'pull_request' && matrix.jobtype == 6 }}
shell: bash
run: |
sbt -v -Dfile.encoding=UTF-8 "-Dbenchmark.pattern=.*AnalysisFormatBenchmark.*" "runBenchmarks"
3 changes: 2 additions & 1 deletion .scala-steward.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ pullRequests.frequency = "14 days"
updates.ignore = [
# as per discussion on sbt/zinc#1236, this is
# "if it ain't broke don't fix it" territory
{ groupId = "com.google.protobuf" }
{ groupId = "com.google.protobuf" },
{ groupId = "org.eclipse.jgit" }
]
69 changes: 14 additions & 55 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ def mimaSettings: Seq[Setting[?]] = Seq(
"1.5.0",
"1.6.0",
"1.7.0",
"1.8.0",
"1.9.0",
"1.10.0",
)
val versions =
if (scalaVersion.value.startsWith("2.12.")) pre140 ++ post140
Expand Down Expand Up @@ -87,7 +90,6 @@ def baseSettings: Seq[Setting[?]] = Seq(
testFrameworks += new TestFramework("verify.runner.Framework"),
compile / javacOptions ++= Seq("-Xlint", "-Xlint:-serial"),
Test / publishArtifact := false,
scalacOptions ++= Seq("-YdisableFlatCpCaching"),
scalacOptions += {
scalaBinaryVersion.value match {
case "2.10" | "2.11" =>
Expand All @@ -103,27 +105,6 @@ def baseSettings: Seq[Setting[?]] = Seq(
ideSkipProject := scalaVersion.value != defaultScalaVersion,
)

def compilerVersionDependentScalacOptions: Seq[Setting[?]] = Seq(
scalacOptions := {
scalaBinaryVersion.value match {
case "2.12" | "2.13" =>
scalacOptions.value ++ List(
"-opt-inline-from:<sources>",
"-opt:l:inline",
"-Yopt-inline-heuristics:at-inline-annotated"
)
case _ =>
scalacOptions.value.filterNot(
Set(
"-Xfatal-warnings",
"-deprecation",
"-YdisableFlatCpCaching",
)
)
}
}
)

def addBaseSettingsAndTestDeps(p: Project): Project =
p.settings(baseSettings).configure(addTestDependencies)

Expand Down Expand Up @@ -261,21 +242,11 @@ lazy val zincPersist = (projectMatrix in internalPath / "zinc-persist")
.dependsOn(zincCore, zincCompileCore, zincCore % "test->test")
.settings(
name := "zinc Persist",
libraryDependencies += sbinary,
libraryDependencies ++= {
scalaPartialVersion.value match {
case Some((major, minor)) if major == 3 || minor >= 13 =>
List("org.scala-lang.modules" %% "scala-parallel-collections" % "1.0.4")
case _ =>
List()
}
},
libraryDependencies ++= List(
sbinary,
"org.scala-lang.modules" %% "scala-parallel-collections" % "1.0.4",
),
compileOrder := sbt.CompileOrder.Mixed,
Compile / scalacOptions ++= (scalaVersion.value match {
case VersionNumber(Seq(2, 12, _*), _, _) =>
List("-Ywarn-unused:-imports,-locals,-implicits,-explicits,-privates")
case _ => Nil
}),
Test / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.Flat,
mimaSettings,
mimaBinaryIssueFilters ++= ZincBuildUtil.excludeInternalProblems,
Expand Down Expand Up @@ -319,17 +290,10 @@ lazy val zincCore = (projectMatrix in internalPath / "zinc-core")
exclude[ReversedMissingMethodProblem]("xsbti.*"),
exclude[MissingClassProblem]("xsbti.*"),
),
libraryDependencies ++= {
scalaPartialVersion.value match {
case Some((major, minor)) if major == 3 || minor >= 13 =>
List(
"org.scala-lang" % "scala-reflect" % scala213,
"org.scala-lang.modules" %% "scala-parallel-collections" % "1.0.4"
)
case _ =>
List()
}
},
libraryDependencies ++= List(
"org.scala-lang" % "scala-reflect" % scala213,
"org.scala-lang.modules" %% "scala-parallel-collections" % "1.0.4"
),
)
.jvmPlatform(scalaVersions = scala3_only)
.configure(addBaseSettingsAndTestDeps, addSbtIO, addSbtUtilLogging, addSbtUtilRelation)
Expand Down Expand Up @@ -397,8 +361,6 @@ lazy val compilerInterface = (projectMatrix in internalPath / "compiler-interfac
baseSettings,
name := "Compiler Interface",
scalaVersion := scala3,
crossScalaVersions := Seq(scala3),
compilerVersionDependentScalacOptions,
libraryDependencies ++= Seq(scalatest % Test),
exportJars := true,
Compile / resourceGenerators += Def.task {
Expand Down Expand Up @@ -466,7 +428,6 @@ lazy val compilerBridge = (projectMatrix in internalPath / "compiler-bridge")
semanticdbEnabled.value && !scalaVersion.value.startsWith("2.10")
},
baseSettings,
compilerVersionDependentScalacOptions,
// We need this for import Compat._
Compile / scalacOptions --= Seq("-Ywarn-unused-import", "-Xfatal-warnings"),
Compile / scalacOptions ++= (scalaVersion.value match {
Expand Down Expand Up @@ -520,7 +481,6 @@ lazy val compilerBridgeTest = (projectMatrix in internalPath / "compiler-bridge-
name := "Compiler Bridge Test",
baseSettings,
scalaVersion := scala3,
compilerVersionDependentScalacOptions,
// we need to fork because in unit tests we set usejavacp = true which means
// we are expecting all of our dependencies to be on classpath so Scala compiler
// can use them while constructing its own classpath for compilation
Expand All @@ -547,7 +507,6 @@ lazy val zincApiInfo = (projectMatrix in internalPath / "zinc-apiinfo")
)
.settings(
name := "zinc ApiInfo",
compilerVersionDependentScalacOptions,
mimaSettings,
mimaBinaryIssueFilters ++= Seq(
exclude[IncompatibleMethTypeProblem]("xsbt.api.HashAPI.hashTypeParameters"),
Expand Down Expand Up @@ -581,7 +540,6 @@ lazy val zincClasspath = (projectMatrix in internalPath / "zinc-classpath")
.dependsOn(compilerInterface)
.settings(
name := "zinc Classpath",
compilerVersionDependentScalacOptions,
libraryDependencies ++= Seq(
// scalaCompiler.value,
launcherInterface
Expand All @@ -600,6 +558,9 @@ lazy val zincClasspath = (projectMatrix in internalPath / "zinc-classpath")
exclude[IncompatibleResultTypeProblem](
"sbt.internal.inc.classpath.NativeCopyConfig.*"
),
exclude[IncompatibleResultTypeProblem](
"sbt.internal.inc.ReflectUtilities.fields"
),
exclude[IncompatibleSignatureProblem](
"sbt.internal.inc.classpath.NativeCopyConfig.*"
),
Expand All @@ -614,7 +575,6 @@ lazy val zincClassfile = (projectMatrix in internalPath / "zinc-classfile")
.dependsOn(compilerInterface, zincTesting % Test)
.settings(
name := "zinc Classfile",
compilerVersionDependentScalacOptions,
Compile / headerSources ~= { xs =>
val excluded = Set("ZipCentralDir.java", "ZipConstants.java", "ZipUtils.java")
xs filter { x =>
Expand Down Expand Up @@ -643,7 +603,6 @@ lazy val zincScripted = (projectMatrix in internalPath / "zinc-scripted")
.enablePlugins(BuildInfoPlugin)
.settings(
baseSettings,
ideSkipProject := true, // otherwise IntelliJ complains
publish / skip := true,
name := "zinc Scripted",
Compile / buildInfo := Nil, // Only generate build info for tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import java.util.Optional

import sbt.internal.inc.classpath.ClassLoaderCache
import sbt.io.IO
import sbt.io.syntax._
import xsbti.compile._
import sbt.util.Logger
import xsbti.TestCallback.ExtractedClassDependencies
Expand All @@ -35,7 +34,7 @@ trait CompilingSpecification extends AbstractBridgeProviderTestkit {
.get("zinc.build.compilerbridge.scalaVersion")
.getOrElse(sys.error("zinc.build.compilerbridge.scalaVersion property not found"))
def maxErrors = 100
def scala213 = "2.13.14"
def scala213 = "2.13.15"

def scalaCompiler(instance: xsbti.compile.ScalaInstance, bridgeJar: Path): AnalyzingCompiler = {
val bridgeProvider = ZincUtil.constantBridgeProvider(instance, bridgeJar)
Expand Down Expand Up @@ -281,8 +280,8 @@ trait CompilingSpecification extends AbstractBridgeProviderTestkit {
val cp = (si.allJars).map(_.toPath) ++ Array(targetDir)
val classpath = cp.map(converter.toVirtualFile)
sc.doc(
sources = sources.toArray[VirtualFile],
classpath = classpath,
sources = sources.toIndexedSeq,
classpath = classpath.toIndexedSeq,
converter = converter,
outputDirectory = targetDir,
options = Nil,
Expand All @@ -305,7 +304,7 @@ trait CompilingSpecification extends AbstractBridgeProviderTestkit {
val cp = (si.allJars).map(_.toPath) ++ Array(targetDir)
val classpath = cp.map(converter.toVirtualFile)
sc.console(
classpath = classpath,
classpath = classpath.toIndexedSeq,
converter = converter,
options = Nil,
initialCommands = initial,
Expand All @@ -327,7 +326,7 @@ trait CompilingSpecification extends AbstractBridgeProviderTestkit {
val cp = (si.allJars).map(_.toPath) ++ Array(targetDir)
val classpath = cp.map(converter.toVirtualFile)
sc.interactiveConsole(
classpath = classpath,
classpath = classpath.toIndexedSeq,
converter = converter,
options = args.toSeq,
initialCommands = "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
package xsbt

import xsbti.{ PathBasedFile, VirtualFile }
import scala.reflect.io.Streamable

private trait AbstractZincFile extends scala.reflect.io.AbstractFile {
def underlying: VirtualFile
Expand All @@ -25,7 +24,22 @@ private final class ZincPlainFile private[xsbt] (val underlying: PathBasedFile)
private final class ZincVirtualFile private[xsbt] (val underlying: VirtualFile)
extends scala.reflect.io.VirtualFile(underlying.name, underlying.id)
with AbstractZincFile {
Streamable.closing(output)(_.write(Streamable.bytes(underlying.input))) // fill in the content
val buffer = new Array[Byte](4096)

val in = underlying.input()
val output0 = output

try {
var readBytes = in.read(buffer)

while (readBytes != -1) {
output0.write(buffer, 0, readBytes)
readBytes = in.read(buffer)
}
} finally {
in.close()
output0.close()
}
}

private object AbstractZincFile {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

package xsbt

import xsbti.{ AnalysisCallback, Severity }
import xsbti.{ AnalysisCallback, AnalysisCallback3, Severity }
import xsbti.compile._

import scala.tools.nsc._
Expand All @@ -20,6 +20,7 @@ import java.nio.file.{ Files, Path }

import scala.reflect.io.PlainFile
import scala.reflect.ReflectAccess._
import scala.reflect.internal.util.BatchSourceFile

/** Defines the interface of the incremental compiler hiding implementation details. */
sealed abstract class CallbackGlobal(
Expand Down Expand Up @@ -78,6 +79,15 @@ sealed class ZincCompiler(settings: Settings, dreporter: DelegatingReporter, out
extends CallbackGlobal(settings, dreporter, output)
with ZincGlobalCompat {

override def getSourceFile(f: AbstractFile): BatchSourceFile = {
val file = (f, callback) match {
case (plainFile: PlainFile, callback3: AnalysisCallback3) =>
AbstractZincFile(callback3.toVirtualFile(plainFile.file.toPath))
case _ => f
}
super.getSourceFile(file)
}

final class ZincRun(compileProgress: CompileProgress) extends Run {
override def informUnitStarting(phase: Phase, unit: CompilationUnit): Unit = {
compileProgress.startUnit(phase.name, unit.source.path)
Expand Down
29 changes: 24 additions & 5 deletions internal/compiler-bridge/src/main/scala/xsbt/CompilerBridge.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import scala.collection.mutable
import scala.reflect.io.AbstractFile
import scala.tools.nsc.CompilerCommand
import Log.debug
import xsbti.compile.analysis.ReadSourceInfos

import java.io.File

/**
Expand Down Expand Up @@ -49,6 +51,16 @@ class InterfaceCompileFailed(
override val toString: String
) extends xsbti.CompileFailed

class InterfaceCompileFailed2(
val arguments: Array[String],
val sourceInfos: ReadSourceInfos,
override val toString: String
) extends xsbti.CompileFailed2 {
import scala.collection.JavaConverters._
val problems: Array[Problem] =
sourceInfos.getAllSourceInfos.values().asScala.flatMap(_.getReportedProblems).toArray
}

class InterfaceCompileCancelled(val arguments: Array[String], override val toString: String)
extends xsbti.CompileCancelled

Expand Down Expand Up @@ -149,8 +161,8 @@ private final class CachedCompiler0(
underlyingReporter: DelegatingReporter,
compileProgress: CompileProgress
): Unit = {
// cast down to AnalysisCallback2
val callback2 = callback.asInstanceOf[xsbti.AnalysisCallback2]
// cast down to AnalysisCallback3
val callback3 = callback.asInstanceOf[xsbti.AnalysisCallback3]

compiler.set(callback, underlyingReporter)
if (command.shouldStopWithInfo) {
Expand All @@ -165,7 +177,7 @@ private final class CachedCompiler0(
run.compileFiles(sources)
processUnreportedWarnings(run)
underlyingReporter.problems.foreach(p =>
callback2.problem2(
callback3.problem2(
p.category,
p.position,
p.message,
Expand All @@ -180,8 +192,10 @@ private final class CachedCompiler0(
}

underlyingReporter.printSummary()
if (!noErrors(underlyingReporter))
handleErrors(underlyingReporter, log)
if (!noErrors(underlyingReporter)) {
val infos = callback3.getSourceInfos
handleErrors(infos, log)
}

// the case where we cancelled compilation _after_ some compilation errors got reported
// will be handled by line above so errors still will be reported properly just potentially not
Expand All @@ -195,6 +209,11 @@ private final class CachedCompiler0(
throw new InterfaceCompileFailed(args, dreporter.problems, "Compilation failed")
}

def handleErrors(sourceInfos: ReadSourceInfos, log: Logger): Nothing = {
debug(log, "Compilation failed (CompilerInterface)")
throw new InterfaceCompileFailed2(args, sourceInfos, "Compilation failed")
}

def handleCompilationCancellation(dreporter: DelegatingReporter, log: Logger): Nothing = {
assert(dreporter.cancelled, "We should get here only if when compilation got cancelled")
debug(log, "Compilation cancelled (CompilerInterface)")
Expand Down
Loading

0 comments on commit 20dba76

Please sign in to comment.