Skip to content

Commit

Permalink
Clean up some testing in the backend
Browse files Browse the repository at this point in the history
Build in the facility to keep certain per-run caches alive after
a run (to allow inspecting them). This was previously done by
hand, requiring every test in a file to clear those caches
before running a new test. Forgetting to do so would lead to
cross-talk.
  • Loading branch information
lrytz authored and retronym committed May 30, 2017
1 parent e7dd229 commit 7d6625c
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 87 deletions.
19 changes: 7 additions & 12 deletions test/junit/scala/tools/nsc/backend/jvm/opt/CallGraphTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,17 @@ class CallGraphTest extends BytecodeTesting {
override def compilerArgs = "-opt:inline-global -opt-warnings"
import compiler._
import global.genBCode.bTypes
val notPerRun: List[Clearable] = List(

compiler.keepPerRunCachesAfterRun(List(
bTypes.classBTypeCacheFromSymbol,
bTypes.classBTypeCacheFromClassfile,
bTypes.byteCodeRepository.compilingClasses,
bTypes.byteCodeRepository.parsedClasses,
bTypes.callGraph.callsites)
notPerRun foreach global.perRunCaches.unrecordCache
bTypes.callGraph.callsites))

import global.genBCode.bTypes._
import callGraph._

def compile(code: String, allowMessage: StoreReporter#Info => Boolean = _ => false): List[ClassNode] = {
notPerRun.foreach(_.clear())
compileClasses(code, allowMessage = allowMessage).map(c => byteCodeRepository.classNode(c.name).get)
}

def callsInMethod(methodNode: MethodNode): List[MethodInsnNode] = methodNode.instructions.iterator.asScala.collect({
case call: MethodInsnNode => call
}).toList
Expand Down Expand Up @@ -101,7 +96,7 @@ class CallGraphTest extends BytecodeTesting {
msgCount += 1
ok exists (m.msg contains _)
}
val List(cCls, cMod, dCls, testCls) = compile(code, checkMsg)
val List(cCls, cMod, dCls, testCls) = { compileClasses(code, allowMessage = checkMsg); compiledClassesFromCache }
assert(msgCount == 4, msgCount)

val List(cf1, cf2, cf3, cf4, cf5, cf6, cf7) = getAsmMethods(cCls, _.startsWith("f"))
Expand Down Expand Up @@ -142,7 +137,7 @@ class CallGraphTest extends BytecodeTesting {
| def m = java.lang.Class.forName("C")
|}
""".stripMargin
val List(c) = compile(code)
val List(c) = { compileClasses(code); compiledClassesFromCache }
val m = getAsmMethod(c, "m")
val List(fn) = callsInMethod(m)
val forNameMeth = byteCodeRepository.methodNode("java/lang/Class", "forName", "(Ljava/lang/String;)Ljava/lang/Class;").get._1
Expand All @@ -169,7 +164,7 @@ class CallGraphTest extends BytecodeTesting {
| def selfSamCallE = iAmASamE(10)
|}
|""".stripMargin
val List(c, d, e) = compile(code)
val List(c, d, e) = compileClasses(code)

def callIn(m: String) = callGraph.callsites.find(_._1.name == m).get._2.values.head
val t1h = callIn("t1")
Expand Down Expand Up @@ -204,7 +199,7 @@ class CallGraphTest extends BytecodeTesting {
|}
""".stripMargin

compile(code)
compileClasses(code)
def callIn(m: String) = callGraph.callsites.find(_._1.name == m).get._2.values.head
assertEquals(callIn("t1").argInfos.toList, List((1, FunctionLiteral)))
assertEquals(callIn("t2").argInfos.toList, List((1, ForwardedParam(2))))
Expand Down
12 changes: 3 additions & 9 deletions test/junit/scala/tools/nsc/backend/jvm/opt/InlineInfoTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,11 @@ class InlineInfoTest extends BytecodeTesting {

override def compilerArgs = "-opt:l:classpath"

def notPerRun: List[Clearable] = List(
compiler.keepPerRunCachesAfterRun(List(
bTypes.classBTypeCacheFromSymbol,
bTypes.classBTypeCacheFromClassfile,
bTypes.byteCodeRepository.compilingClasses,
bTypes.byteCodeRepository.parsedClasses)
notPerRun foreach global.perRunCaches.unrecordCache

def compile(code: String) = {
notPerRun.foreach(_.clear())
compiler.compileClasses(code)
}
bTypes.byteCodeRepository.parsedClasses))

@Test
def inlineInfosFromSymbolAndAttribute(): Unit = {
Expand All @@ -51,7 +45,7 @@ class InlineInfoTest extends BytecodeTesting {
|}
|class C extends T with U
""".stripMargin
val classes = compile(code)
val classes = compileClasses(code)

val fromSyms = classes.map(c => global.genBCode.bTypes.cachedClassBType(c.name).get.info.get.inlineInfo)

Expand Down
Loading

0 comments on commit 7d6625c

Please sign in to comment.