Skip to content

Commit

Permalink
Merge branch 'develop' into make-scripted-test-run-at-213
Browse files Browse the repository at this point in the history
  • Loading branch information
eed3si9n authored Apr 8, 2024
2 parents dec94af + cfd5081 commit f517e92
Show file tree
Hide file tree
Showing 144 changed files with 2,916 additions and 239 deletions.
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Scala Steward: Reformat with scalafmt 3.8.0
c7afd84c5921949600cd336bbc72acbb41d2342b
33 changes: 29 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ jobs:
- os: ubuntu-latest
java: 21
jobtype: 4
- os: ubuntu-latest
java: 21
jobtype: 5
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: ${{ matrix.java }}
Expand All @@ -50,9 +53,31 @@ jobs:
if: ${{ matrix.jobtype == 3 }}
shell: bash
run: |
sbt -v -Dfile.encoding=UTF-8 "runBenchmarks"
- name: Build and test (4)
sbt -v -Dfile.encoding=UTF-8 scalafmtCheckAll scalafmtSbtCheck
- name: Benchmark (Scalac) (4)
if: ${{ matrix.jobtype == 4 }}
shell: bash
run: |
sbt -v -Dfile.encoding=UTF-8 scalafmtCheckAll scalafmtSbtCheck
sbt -v -Dfile.encoding=UTF-8 "-Dbenchmark.pattern=.*Scalac.*" "runBenchmarks"
- name: Benchmark (Shapeless) (5)
if: ${{ matrix.jobtype == 5 }}
shell: bash
run: |
sbt -v -Dfile.encoding=UTF-8 "-Dbenchmark.pattern=.*Shapeless.*" "runBenchmarks"
- name: Checkout Develop Branch (4, 5)
if: ${{ github.event_name == 'pull_request' && (matrix.jobtype == 4 || matrix.jobtype == 5) }}
uses: actions/checkout@v4
with:
clean: false
ref: develop
- name: Benchmark (Scalac) against Develop Branch (4)
if: ${{ github.event_name == 'pull_request' && matrix.jobtype == 4 }}
shell: bash
run: |
sbt -v -Dfile.encoding=UTF-8 "-Dbenchmark.pattern=.*Scalac.*" "zincBenchmarks/jmh:clean" "runBenchmarks"
- name: Benchmark (Shapeless) against Develop Branch (5)
if: ${{ github.event_name == 'pull_request' && matrix.jobtype == 5 }}
shell: bash
run: |
sbt -v -Dfile.encoding=UTF-8 "-Dbenchmark.pattern=.*Shapeless.*" "zincBenchmarks/jmh:clean" "runBenchmarks"
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ zinc/src/test/resources/bin
.idea
metals.sbt
.bsp
.DS_Store
.DS_Store
.vscode
.metals
.bloop
13 changes: 12 additions & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 3.7.17
version = 3.8.0
runner.dialect = scala212

project.git = true
Expand All @@ -25,3 +25,14 @@ danglingParentheses.defnSite = true

# Minimize diffs
rewrite.trailingCommas.style = keep

rewrite.scala3.convertToNewSyntax = true
fileOverride {
"glob:**/internal/compiler-bridge/**" {
rewrite.scala3.convertToNewSyntax = false
}
}
runner.dialectOverride.allowSignificantIndentation = false
runner.dialectOverride.allowAsForImportRename = false
runner.dialectOverride.allowStarWildcardImport = false
runner.dialectOverride.allowPostfixStarVarargSplices = false
17 changes: 9 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.github.os72.protocjar.Protoc
def zincRootPath: File = file(sys.props.getOrElse("sbtzinc.path", ".")).getCanonicalFile
def internalPath = zincRootPath / "internal"

def mimaSettings: Seq[Setting[_]] = Seq(
def mimaSettings: Seq[Setting[?]] = Seq(
mimaPreviousArtifacts := {
val pre140 = Set(
"1.0.0",
Expand Down Expand Up @@ -83,7 +83,7 @@ Global / concurrentRestrictions += Tags.limit(Tags.Test, 4)
ThisBuild / Test / fork := true
Global / excludeLintKeys += ideSkipProject

def baseSettings: Seq[Setting[_]] = Seq(
def baseSettings: Seq[Setting[?]] = Seq(
testOptions += Tests.Argument(TestFrameworks.ScalaCheck, "-w", "1", "-verbosity", "2"),
testFrameworks += new TestFramework("verify.runner.Framework"),
compile / javacOptions ++= Seq("-Xlint", "-Xlint:-serial"),
Expand All @@ -104,7 +104,7 @@ def baseSettings: Seq[Setting[_]] = Seq(
ideSkipProject := scalaVersion.value != defaultScalaVersion,
)

def compilerVersionDependentScalacOptions: Seq[Setting[_]] = Seq(
def compilerVersionDependentScalacOptions: Seq[Setting[?]] = Seq(
scalacOptions := {
scalaBinaryVersion.value match {
case "2.12" | "2.13" =>
Expand Down Expand Up @@ -376,10 +376,10 @@ lazy val zincBenchmarks = (projectMatrix in internalPath / "zinc-benchmarks")
.enablePlugins(JmhPlugin)
.settings(
publish / skip := true,
ideSkipProject := true, // otherwise IntelliJ complains
baseSettings,
name := "Benchmarks of Zinc and the compiler bridge",
libraryDependencies ++= Seq(
"org.eclipse.jgit" % "org.eclipse.jgit" % "6.7.0.202309050840-r",
"org.eclipse.jgit" % "org.eclipse.jgit" % "6.9.0.202403050737-r",
"net.openhft" % "affinity" % "3.23.3",
),
Test / javaOptions ++= List("-Xmx600M", "-Xms600M"),
Expand Down Expand Up @@ -553,7 +553,7 @@ lazy val compilerBridgeTest = (projectMatrix in internalPath / "compiler-bridge-

val scalaPartialVersion = Def.setting(CrossVersion.partialVersion(scalaVersion.value))

def inBoth(ss: Setting[_]*): Seq[Setting[_]] = Seq(Compile, Test).flatMap(inConfig(_)(ss))
def inBoth(ss: Setting[?]*): Seq[Setting[?]] = Seq(Compile, Test).flatMap(inConfig(_)(ss))

// defines operations on the API of a source, including determining whether it has changed and converting it to a string
// and discovery of classes and annotations
Expand Down Expand Up @@ -697,11 +697,12 @@ crossTestBridges := (compilerBridgeTest.jvm(scala213) / Test / test).dependsOn(p
addCommandAlias(
"runBenchmarks", {
val dir = IO.createTemporaryDirectory.getAbsolutePath
val pattern = sys.props.getOrElse("benchmark.pattern", "")
Seq(
s"${compilerBridge213.id}/packageBin",
s"${compilerBridge212.id}/packageBin",
s"${zincBenchmarks.jvm(scala212).id}/Test/run $dir",
s"${zincBenchmarks.jvm(scala212).id}/jmh:run -p _tempDir=$dir -prof gc -foe true",
s"${zincBenchmarks.jvm(scala212).id}/Test/run $dir $pattern",
s"${zincBenchmarks.jvm(scala212).id}/jmh:run -p _tempDir=$dir -prof gc -foe true $pattern",
s"""eval IO.delete(file("$dir"))""",
).mkString(";", ";", "")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ 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.12"
def scala213 = "2.13.13"

def scalaCompiler(instance: xsbti.compile.ScalaInstance, bridgeJar: Path): AnalyzingCompiler = {
val bridgeProvider = ZincUtil.constantBridgeProvider(instance, bridgeJar)
val classpath = ClasspathOptionsUtil.boot
val classpath = ClasspathOptionsUtil.noboot(instance.version)
val cache = Some(new ClassLoaderCache(new URLClassLoader(Array())))
new AnalyzingCompiler(instance, bridgeProvider, classpath, _ => (), cache)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@ abstract class Compat {
import global._

protected def processOriginalTreeAttachment(in: Tree)(func: Tree => Unit): Unit = ()

protected def processSAMAttachment(f: Function)(addDependency: Symbol => Unit): Unit =
()
}
object Compat {
// IR is renamed to Results
val Results = scala.tools.nsc.interpreter.IR

// IMain in 2.13 accepts ReplReporter
def replReporter(settings: Settings, writer: PrintWriter) = writer

implicit final class SettingsCompat(val settings: Settings) extends AnyVal {
@inline final def optInlinerEnabled: Boolean = false
}
}

/** Defines compatibility utils for [[ZincCompiler]]. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ abstract class Compat {
protected def processOriginalTreeAttachment(in: Tree)(func: Tree => Unit): Unit = {
Compat.OriginalTreeTraverser.Instance.traverseOriginal(in)(func)
}

protected def processSAMAttachment(f: Function)(addDependency: Symbol => Unit): Unit = {
f.attachments.get[SAMFunction].foreach(sam => {
addDependency(sam.samTp.typeSymbol)
})
}
}
object Compat {
// IR is renamed to Results
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ sealed class ZincCompiler(settings: Settings, dreporter: DelegatingReporter, out
val analyzer = new Analyzer(global)
def newPhase(prev: Phase) = analyzer.newPhase(prev)
def name = phaseName

def description = "analyze the generated class files and map them to sources"
}

/** Phase that extracts dependency information */
Expand All @@ -116,6 +118,8 @@ sealed class ZincCompiler(settings: Settings, dreporter: DelegatingReporter, out
val dependency = new Dependency(global)
def newPhase(prev: Phase) = dependency.newPhase(prev)
def name = phaseName

def description = "extract dependency information"
}

/**
Expand All @@ -136,13 +140,18 @@ sealed class ZincCompiler(settings: Settings, dreporter: DelegatingReporter, out
val api = new API(global)
def newPhase(prev: Phase) = api.newPhase(prev)
def name = phaseName

def description = "construct a representation of the public API"
}

override lazy val phaseDescriptors = {
phasesSet += sbtAnalyzer
phasesDescMap(sbtAnalyzer) = sbtAnalyzer.description
if (callback.enabled()) {
phasesSet += sbtDependency
phasesDescMap(sbtDependency) = sbtDependency.description
phasesSet += apiExtractor
phasesDescMap(apiExtractor) = apiExtractor.description
}
this.computePhaseDescriptors
}
Expand Down
3 changes: 3 additions & 0 deletions internal/compiler-bridge/src/main/scala/xsbt/ClassName.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ trait ClassName extends Compat {
protected def constructorNameAsString(cls: Symbol): String =
cls.fullName(';') ++ ";init;"

protected def constructorNameAsString(cls: Symbol, index: String): String =
cls.fullName(';') ++ s";init;default;$index"

/**
* Mangle a JVM symbol name in a format better suited for internal uses by sbt.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ private final class CachedCompiler0(
// cast down to AnalysisCallback2
val callback2 = callback.asInstanceOf[xsbti.AnalysisCallback2]

compiler.set(callback, underlyingReporter)
if (command.shouldStopWithInfo) {
underlyingReporter.info(null, command.getInfoMessage(compiler), true)
throw new InterfaceCompileFailed(args, Array(), StopInfoError)
}

if (noErrors(underlyingReporter)) {
debug(log, prettyPrintCompilationArguments(args))
compiler.set(callback, underlyingReporter)
val run = new compiler.ZincRun(compileProgress)

run.compileFiles(sources)
Expand Down
46 changes: 42 additions & 4 deletions internal/compiler-bridge/src/main/scala/xsbt/Dependency.scala
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ final class Dependency(val global: CallbackGlobal) extends LocateClassFile with
val memberRef = processDependency(DependencyByMemberRef, false) _
val inheritance = processDependency(DependencyByInheritance, true) _
val localInheritance = processDependency(LocalDependencyByInheritance, true) _
val scala2MacroExpansion = processDependency(DependencyByMacroExpansion, false) _

@deprecated("Use processDependency that takes allowLocal.", "1.1.0")
def processDependency(context: DependencyContext)(dep: ClassDependency): Unit =
Expand Down Expand Up @@ -214,6 +215,7 @@ final class Dependency(val global: CallbackGlobal) extends LocateClassFile with
private val _memberRefCache = new JavaSet[ClassDependency]()
private val _inheritanceCache = new JavaSet[ClassDependency]()
private val _localInheritanceCache = new JavaSet[ClassDependency]()
private val _dependencyByMacroExpansionCache = new JavaSet[ClassDependency]()
private val _topLevelImportCache = new JavaSet[Symbol]()

private var _currentDependencySource: Symbol = _
Expand Down Expand Up @@ -363,10 +365,28 @@ final class Dependency(val global: CallbackGlobal) extends LocateClassFile with
override def addDependency(symbol: global.Symbol) = handler(symbol)
}

def addTypeDependencies(tpe: Type): Unit = {
object TypeDependencyTraverserForMacro extends TypeDependencyTraverser {
private var owner: Symbol = _
def setOwner(symbol: Symbol) = owner = symbol
override def addDependency(symbol: global.Symbol): Unit = {
addClassDependency(
_dependencyByMacroExpansionCache,
processor.scala2MacroExpansion,
owner,
symbol
)
}
}

def addTypeDependencies(tpe: Type, forMacro: Boolean = false): Unit = {
val fromClass = resolveDependencySource
TypeDependencyTraverser.setOwner(fromClass)
TypeDependencyTraverser.traverse(tpe)
if (forMacro) {
TypeDependencyTraverserForMacro.setOwner(fromClass)
TypeDependencyTraverserForMacro.traverse(tpe)
} else {
TypeDependencyTraverser.setOwner(fromClass)
TypeDependencyTraverser.traverse(tpe)
}
}

private def addInheritanceDependency(dep: Symbol): Unit = {
Expand Down Expand Up @@ -441,7 +461,7 @@ final class Dependency(val global: CallbackGlobal) extends LocateClassFile with
addDependency(symbol)
}

inheritanceTypes.foreach(addTypeDependencies)
inheritanceTypes.foreach(addTypeDependencies(_, false))
addTypeDependencies(self.tpt.tpe)

traverseTrees(body)
Expand All @@ -462,6 +482,14 @@ final class Dependency(val global: CallbackGlobal) extends LocateClassFile with
addTypeDependencies(typeTree.tpe)

case m @ MacroExpansionOf(original) if inspectedOriginalTrees.add(original) =>
// TODO: typesTouchedDuringMacroExpansion can be provided by compiler
// in the form of tree attachment
val typesTouchedDuringMacroExpansion = original match {
case Apply(TypeApply(_, args), _) => args.map(_.tpe)
case TypeApply(_, args) => args.map(_.tpe)
case _ => List.empty[Type]
}
typesTouchedDuringMacroExpansion.foreach(addTypeDependencies(_, true))
traverse(original)
super.traverse(m)

Expand All @@ -475,6 +503,16 @@ final class Dependency(val global: CallbackGlobal) extends LocateClassFile with
val sym = if (tree.symbol.isModule) tree.symbol.moduleClass else tree.symbol
localToNonLocalClass.resolveNonLocal(sym)
super.traverse(tree)

case f: Function =>
processSAMAttachment(f)(symbol => {
addDependency(symbol)
// Not using addInheritanceDependency as it would incorrectly classify dependency as non-local
// ref: https://github.com/scala/scala/pull/10617/files#r1415226169
val from = resolveDependencySource
addClassDependency(_localInheritanceCache, processor.localInheritance, from, symbol)
})
super.traverse(tree)
case other => super.traverse(other)
}
}
Expand Down
Loading

0 comments on commit f517e92

Please sign in to comment.