Skip to content

Commit

Permalink
Prefer override protected, partest tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed Feb 10, 2023
1 parent 9f97fd1 commit 4d5849a
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
override def enterSyntheticSym(tree: Tree): Symbol = tree.symbol
}

protected override def newBodyDuplicator(context: Context): SpecializeBodyDuplicator =
override protected def newBodyDuplicator(context: Context): SpecializeBodyDuplicator =
new SpecializeBodyDuplicator(context)

override def newNamer(context: Context): Namer =
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/typechecker/Duplicators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ abstract class Duplicators extends Analyzer {
private var envSubstitution: SubstTypeMap = _

private class SubstSkolemsTypeMap(from: List[Symbol], to: List[Type]) extends SubstTypeMap(from, to) {
protected override def matches(sym1: Symbol, sym2: Symbol) =
override protected def matches(sym1: Symbol, sym2: Symbol) =
if (sym2.isTypeSkolem) sym2.deSkolemize eq sym1
else sym1 eq sym2
}
Expand Down
2 changes: 1 addition & 1 deletion src/library/scala/collection/mutable/ArrayDeque.scala
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ class ArrayDeque[A] protected (

override def isEmpty = start == end

protected override def klone(): ArrayDeque[A] = new ArrayDeque(array.clone(), start = start, end = end)
override protected def klone(): ArrayDeque[A] = new ArrayDeque(array.clone(), start = start, end = end)

override def iterableFactory: SeqFactory[ArrayDeque] = ArrayDeque

Expand Down
2 changes: 1 addition & 1 deletion src/library/scala/collection/mutable/Queue.scala
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class Queue[A] protected (array: Array[AnyRef], start: Int, end: Int)
*/
@`inline` final def front: A = head

protected override def klone(): Queue[A] = {
override protected def klone(): Queue[A] = {
val bf = newSpecificBuilder
bf ++= this
bf.result()
Expand Down
2 changes: 1 addition & 1 deletion src/library/scala/collection/mutable/Stack.scala
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class Stack[A] protected (array: Array[AnyRef], start: Int, end: Int)
*/
@`inline` final def top: A = head

protected override def klone(): Stack[A] = {
override protected def klone(): Stack[A] = {
val bf = newSpecificBuilder
bf ++= this
bf.result()
Expand Down
2 changes: 1 addition & 1 deletion src/library/scala/collection/mutable/UnrolledBuffer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -438,5 +438,5 @@ object UnrolledBuffer extends StrictOptimizedClassTagSeqFactory[UnrolledBuffer]
// Todo -- revisit whether inheritance is the best way to achieve this functionality
private[collection] class DoublingUnrolledBuffer[T](implicit t: ClassTag[T]) extends UnrolledBuffer[T]()(t) {
override def calcNextLength(sz: Int) = if (sz < 10000) sz * 2 else sz
protected override def newUnrolled = new UnrolledBuffer.Unrolled[T](0, new Array[T](4), null, this)
override protected def newUnrolled = new UnrolledBuffer.Unrolled[T](0, new Array[T](4), null, this)
}
47 changes: 22 additions & 25 deletions src/partest/scala/tools/partest/nest/Runner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -418,18 +418,15 @@ class Runner(val testInfo: TestInfo, val suiteRunner: AbstractRunner) {
* 2. Runs script function, providing log file and output directory as arguments.
* 2b. or, just run the script without context and return a new context
*/
def runInContext(body: => TestState): TestState = {
body
}
def runInContext(body: => TestState): TestState = body

/** Grouped files in group order, and lex order within each group. */
def groupedFiles(sources: List[File]): List[List[File]] = (
def groupedFiles(sources: List[File]): List[List[File]] =
if (sources.sizeIs > 1) {
val grouped = sources groupBy (_.group)
grouped.keys.toList.sorted map (k => grouped(k) sortBy (_.getName))
val grouped = sources.groupBy(_.group)
grouped.keys.toList.sorted.map(grouped(_).sortBy(_.getName))
}
else List(sources)
)

/** Source files for the given test file. */
def sources(file: File): List[File] = if (file.isDirectory) file.listFiles.toList.filter(_.isJavaOrScala) else List(file)
Expand Down Expand Up @@ -483,31 +480,31 @@ class Runner(val testInfo: TestInfo, val suiteRunner: AbstractRunner) {
files.flatMap(argsFor)
}

abstract class CompileRound {
def fs: List[File]
def result: TestState
sealed abstract class CompileRound {
def files: List[File]
def description: String
protected def computeResult: TestState

final lazy val result: TestState = { pushTranscript(description); computeResult }

def fsString = fs map (_.toString stripPrefix parentFile.toString + "/") mkString " "
def isOk = result.isOk
def mkScalacString(): String = s"""scalac $fsString"""
override def toString = description + ( if (result.isOk) "" else "\n" + result.status )
final protected def fsString = files.map(_.toString.stripPrefix(s"$parentFile/")).mkString(" ")
final override def toString = description + ( if (result.isOk) "" else "\n" + result.status )
}
case class OnlyJava(fs: List[File]) extends CompileRound {
final case class OnlyJava(files: List[File]) extends CompileRound {
def description = s"""javac $fsString"""
lazy val result = { pushTranscript(description) ; javac(fs) }
override protected def computeResult = javac(files)
}
case class OnlyScala(fs: List[File]) extends CompileRound {
def description = mkScalacString()
lazy val result = { pushTranscript(description) ; attemptCompile(fs) }
final case class OnlyScala(files: List[File]) extends CompileRound {
def description = s"""scalac $fsString"""
override protected def computeResult = attemptCompile(files)
}
case class ScalaAndJava(fs: List[File]) extends CompileRound {
def description = mkScalacString()
lazy val result = { pushTranscript(description) ; attemptCompile(fs) }
final case class ScalaAndJava(files: List[File]) extends CompileRound {
def description = s"""scalac $fsString"""
override protected def computeResult = attemptCompile(files)
}
case class SkipRound(fs: List[File], state: TestState) extends CompileRound {
final case class SkipRound(files: List[File], state: TestState) extends CompileRound {
def description: String = state.status
lazy val result = { pushTranscript(description); state }
override protected def computeResult = state
}

def compilationRounds(file: File): List[CompileRound] = {
Expand Down Expand Up @@ -535,7 +532,7 @@ class Runner(val testInfo: TestInfo, val suiteRunner: AbstractRunner) {
}

def mixedCompileGroup(allFiles: List[File]): List[CompileRound] = {
val (scalaFiles, javaFiles) = allFiles partition (_.isScala)
val (scalaFiles, javaFiles) = allFiles.partition(_.isScala)
val round1 = if (scalaFiles.isEmpty) None else Some(ScalaAndJava(allFiles))
val round2 = if (javaFiles.isEmpty) None else Some(OnlyJava(javaFiles))

Expand Down
12 changes: 9 additions & 3 deletions src/partest/scala/tools/partest/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ package object partest {

/** Sources have a numerical group, specified by name_7 and so on. */
private val GroupPattern = """.*_(\d+)""".r
private object IntOf {
def unapply(ds: String): Some[Int] = Some {
try ds.toInt
catch { case _: NumberFormatException => -1 }
}
}

implicit class `special string ops`(private val s: String) extends AnyVal {
def linesIfNonEmpty: Iterator[String] = if (!s.isEmpty) s.linesIterator else Iterator.empty
Expand Down Expand Up @@ -85,11 +91,11 @@ package object partest {
def hasExtension(ext: String) = sf hasExtension ext
def changeExtension(ext: String): File = (sf changeExtension ext).jfile

/** The group number for this source file, or -1 for no group. */
/** The group number for this source file, or -1 for no group or out of range. */
def group: Int =
sf.stripExtension match {
case GroupPattern(g) if g.toInt >= 0 => g.toInt
case _ => -1
case GroupPattern(IntOf(g)) => g
case _ => -1
}

// Files.readString on jdk 11
Expand Down

0 comments on commit 4d5849a

Please sign in to comment.