Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/test/dotc/scoverage-ignore.excludelist
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ i24039.scala
i24553.scala
i25000.scala
i25000b.scala
i25460.scala
i3598.scala
i5039.scala
i7034.scala
Expand All @@ -75,6 +76,8 @@ infersingle.scala
interop-unsound-src
java-collectors.scala
large2.scala
lazyVals_c3.0.0.scala
lazyVals_c3.1.0.scala
match-single-sub-case.scala
match-sub-cases.scala
match-sub-sub-cases.scala
Expand All @@ -92,4 +95,3 @@ sub-cases-exhaustivity.scala
t10594.scala
tailrec.scala
traitParams.scala
i25460.scala
65 changes: 49 additions & 16 deletions compiler/test/dotty/tools/vulpix/ParallelTesting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import java.text.SimpleDateFormat
import java.util.{HashMap, Timer, TimerTask}
import java.util.concurrent.{TimeUnit, TimeoutException, Executors => JExecutors}

import scala.collection.mutable
import scala.collection.mutable, mutable.ListBuffer
import scala.io.{Codec, Source}
import scala.jdk.CollectionConverters.*
import scala.util.{Random, Try, Failure => TryFailure, Success => TrySuccess, Using}
import scala.util.control.NonFatal
import scala.util.matching.Regex
import scala.collection.mutable.ListBuffer
import scala.util.Properties.{isJavaAtLeast, javaSpecVersion}

import dotc.{Compiler, Driver}
import dotty.tools.dotc.CoverageSupport
Expand All @@ -34,7 +34,7 @@ import dotc.reporting.Diagnostic
import dotc.config.Config
import dotc.util.{DiffUtil, SourceFile, SourcePosition, Spans, NoSourcePosition}
import io.AbstractFile
import dotty.tools.vulpix.TestConfiguration.defaultOptions
import util.chaining.*

/** A parallel testing suite whose goal is to integrate nicely with JUnit
*
Expand Down Expand Up @@ -206,16 +206,15 @@ trait ParallelTesting extends RunnerOrchestration with CoverageSupport:
flags: TestFlags,
outDir: JFile
) extends TestSource {
import SeparateCompilationSource.*
case class Group(ordinal: Int, compiler: String)

lazy val compilationGroups: List[(Group, Array[JFile])] =
val Compiler = """c([\d\.]+)""".r
val Ordinal = """(\d+)""".r
lazy val compilationGroups: List[(Group, Array[JFile])] = {
def groupFor(file: JFile): Group =
val groupSuffix = file.getName.dropWhile(_ != '_').stripSuffix(".scala").stripSuffix(".java")
val groupSuffixParts = groupSuffix.split("_")
val ordinal = groupSuffixParts.collectFirst { case Ordinal(n) => n.toInt }.getOrElse(Int.MinValue)
val compiler = groupSuffixParts.collectFirst { case Compiler(c) => c }.getOrElse("")
val ordinal = groupSuffixParts.collectFirst { case GroupOrdinal(n) => n.toInt }.getOrElse(Int.MinValue)
val compiler = groupSuffixParts.collectFirst { case CompilerVersion(c) => c }.getOrElse("")
Group(ordinal, compiler)

dir.listFiles
Expand All @@ -224,15 +223,32 @@ trait ParallelTesting extends RunnerOrchestration with CoverageSupport:
.toList
.sortBy { (g, _) => (g.ordinal, g.compiler) }
.map { (g, f) => (g, f.sorted) }
}

def sourceFiles = compilationGroups.map(_._2).flatten.toArray

def checkFileBasePathCandidates: Array[String] =
Array(dir.getPath)
}
object SeparateCompilationSource:
val CompilerVersion = """c([\d\.]+)""".r
val HasCompilerVersion = """_c([\d\.]+)""".r.unanchored
val GroupOrdinal = """(\d+)""".r

/** Skip if there are no sources, such as in a spurious directory,
* or when compiling with a legacy compiler which may not run under this jdk.
*/
protected def shouldSkipTestSource(testSource: TestSource): Boolean =
testSource.sourceFiles.length == 0
val files = testSource.sourceFiles
files.length == 0
||
!TestConfiguration.usingBaselineJava
&&
testSource.match
case separate: SeparateCompilationSource =>
separate.compilationGroups.exists((group, _) => group.compiler.nonEmpty)
case _ =>
files.exists(f => SeparateCompilationSource.HasCompilerVersion.matches(f.getName))

protected def shouldReRun(testSource: TestSource): Boolean =
failedTests.forall(rerun => testSource match {
Expand All @@ -253,7 +269,15 @@ trait ParallelTesting extends RunnerOrchestration with CoverageSupport:
Try(testSource match {
case testSource @ JointCompilationSource(name, files, flags, outDir, fromTasty, decompilation) =>
val reporter = fromTasty match
case NotFromTasty => compile(testSource.sourceFiles, flags, outDir)
case NotFromTasty =>
if testSource.sourceFiles.length == 1 then
testSource.sourceFiles(0).getName match
case SeparateCompilationSource.HasCompilerVersion(version) =>
val compiler = version.stripSuffix(".")
compileWithOtherCompiler(compiler, testSource.sourceFiles, flags, outDir)
case _ => compile(testSource.sourceFiles, flags, outDir)
else
compile(testSource.sourceFiles, flags, outDir)
case FromTasty => compileFromTasty(flags, outDir)
case FromBestEffortTasty => compileFromBestEffortTasty(flags, outDir)
case WithBestEffortTasty(bestEffortDir) => compileWithBestEffortTasty(testSource.sourceFiles, bestEffortDir, flags, outDir)
Expand Down Expand Up @@ -494,7 +518,6 @@ trait ParallelTesting extends RunnerOrchestration with CoverageSupport:
throw e

protected def compile(files0: Array[JFile], flags0: TestFlags, targetDir: JFile): TestReporter = {
import scala.util.Properties.*

def flattenFiles(f: JFile): Array[JFile] =
if (f.isDirectory) f.listFiles.flatMap(flattenFiles)
Expand Down Expand Up @@ -623,7 +646,7 @@ trait ParallelTesting extends RunnerOrchestration with CoverageSupport:
addToLast(barLine(start = false))
diagnostics.reverse

protected def compileWithOtherCompiler(compiler: String, files: Array[JFile], flags: TestFlags, targetDir: JFile): TestReporter =
protected def compileWithOtherCompiler(compiler: String, files: Array[JFile], flags: TestFlags, targetDir: JFile): TestReporter = {
def artifactClasspath(organizationName: String, moduleName: String) =
import coursier._
val dep = Dependency(
Expand Down Expand Up @@ -683,6 +706,8 @@ trait ParallelTesting extends RunnerOrchestration with CoverageSupport:
}

reporter
}
end compileWithOtherCompiler

protected def compileFromBestEffortTasty(flags0: TestFlags, targetDir: JFile): TestReporter = {
val classes = flattenFiles(targetDir).filter(isBestEffortTastyFile).map(_.toString)
Expand Down Expand Up @@ -1418,15 +1443,15 @@ trait ParallelTesting extends RunnerOrchestration with CoverageSupport:

/** Create out directory for directory `d` */
def createOutputDirsForDir(d: JFile, sourceDir: JFile, outDir: String): JFile = {
val targetDir = new JFile(outDir + s"${sourceDir.getName}/${d.getName}")
val targetDir = new JFile(s"${outDir}${sourceDir.getName}/${d.getName}")
targetDir.mkdirs()
targetDir
}

/** Create out directory for `file` */
private def createOutputDirsForFile(file: JFile, sourceDir: JFile, outDir: String): JFile = {
val uniqueSubdir = file.getName.substring(0, file.getName.lastIndexOf('.'))
val targetDir = new JFile(outDir + s"${sourceDir.getName}${JFile.separatorChar}$uniqueSubdir")
val targetDir = new JFile(s"${outDir}${sourceDir.getName}${JFile.separatorChar}$uniqueSubdir")
targetDir.mkdirs()
targetDir
}
Expand Down Expand Up @@ -1529,6 +1554,8 @@ trait ParallelTesting extends RunnerOrchestration with CoverageSupport:
* target all files are grouped according to the file suffix `_X` where `X`
* is a number. These groups are then ordered in ascending order based on
* the value of `X` and each group is compiled one after the other.
* A file can request compilation by a legacy compiler via a version suffix:
* `A_1_c3.2.0.scala` in group 1 is compiled by 3.2.0 under canonical JDK 17.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* `A_1_c3.2.0.scala` in group 1 is compiled by 3.2.0 under canonical JDK 17.
* `A_1_c3.2.0.scala` in group 1 is compiled by 3.2.0 under the default JDK.

the exact version doesn't really matter here and this comment will become obsolete otherwise, IMHO

*
* For this function to work as expected, we use the same convention for
* directory layout as the old partest. That is:
Expand All @@ -1552,8 +1579,14 @@ trait ParallelTesting extends RunnerOrchestration with CoverageSupport:
!isPicklerTest || source.compilationGroups.length == 1
}
val targets =
files.map(f => JointCompilationSource(testGroup.name, Array(f), flags, createOutputDirsForFile(f, sourceDir, outDir))) ++
dirs.map { dir => SeparateCompilationSource(testGroup.name, dir, flags, createOutputDirsForDir(dir, sourceDir, outDir)) }.filter(picklerDirFilter)
files.map: f =>
val out = createOutputDirsForFile(f, sourceDir, outDir)
JointCompilationSource(testGroup.name, Array(f), flags, out)
++
dirs.map: dir =>
val out = createOutputDirsForDir(dir, sourceDir, outDir)
SeparateCompilationSource(testGroup.name, dir, flags, out)
.filter(picklerDirFilter)

// Create a CompilationTest and let the user decide whether to execute a pos or a neg test
new CompilationTest(targets)
Expand Down
3 changes: 3 additions & 0 deletions compiler/test/dotty/tools/vulpix/TestConfiguration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ package tools
package vulpix

import scala.language.unsafeNulls
import scala.util.Properties.javaSpecVersion

import java.io.File

object TestConfiguration {

val usingBaselineJava = javaSpecVersion.startsWith("17")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any way we can reuse https://github.com/dotty-staging/dotty/blob/main/compiler/src/dotty/tools/dotc/config/ScalaSettingsProperties.scala#L13 to avoid introducing another place that needs changing when we bump the minimum JDK?


val pageWidth = 120

val noCheckOptions = Array(
Expand Down
15 changes: 11 additions & 4 deletions tests/run-tasty-inspector/tastyPaths.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import scala.quoted.*
import scala.tasty.inspector.*

import java.io.File.separatorChar
import java.io.File.{pathSeparator, separatorChar}

import dotty.tools.dotc.util.ClasspathFromClassloader
import dotty.tools.io.Path

opaque type PhoneNumber = String

Expand All @@ -14,8 +17,12 @@ object Test {
def main(args: Array[String]): Unit = {
// Artefact of the current test infrastructure
// TODO improve infrastructure to avoid needing this code on each test
val classpath = dotty.tools.dotc.util.ClasspathFromClassloader(this.getClass.getClassLoader).split(java.io.File.pathSeparator).find(_.contains("runWithCompiler")).get
val allTastyFiles = dotty.tools.io.Path(classpath).walkFilter(_.extension == "tasty").map(_.toString).toList
val classpath =
ClasspathFromClassloader(getClass.getClassLoader)
.split(pathSeparator)
.find(_.contains("runWithCompiler"))
.get
val allTastyFiles = Path(classpath).walkFilter(_.extension == "tasty").map(_.toString).toList
val tastyFiles = allTastyFiles.filter(_.contains("I8163"))

TastyInspector.inspectTastyFiles(tastyFiles)(new TestInspector())
Expand All @@ -30,4 +37,4 @@ class TestInspector() extends Inspector:
quotes.reflect.SourceFile.current
assert(false)
catch case ex: java.lang.UnsupportedOperationException =>
println(ex.getMessage) // ok
println(ex.getMessage) // ok
1 change: 1 addition & 0 deletions tests/run/lazyVals_c3.0.0.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// scalajs: --skip
// Compiled with 3.0.0 and run with current compiler
class Foo:
lazy val x =
Expand Down
1 change: 1 addition & 0 deletions tests/run/lazyVals_c3.1.0.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// scalajs: --skip
// Compiled with 3.1.0 and run with current compiler
class Foo:
lazy val x =
Expand Down
Loading