Skip to content

[do not merge] Demonstrate that signature caching is broken #8798

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
28 changes: 28 additions & 0 deletions compiler/test/dotty/tools/SignaturesTests.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dotty.tools

import vulpix.TestConfiguration

import org.junit.Test

import dotc.ast.Trees._
import dotc.core.Decorators._
import dotc.core.Contexts._
import dotc.core.Types._

import java.io.File
import java.nio.file._

class SignaturesTest:
@Test def signatureCaching: Unit =
inCompilerContext(TestConfiguration.basicClasspath, "case class Foo(value: Unit)") {
val defn = ctx.definitions
val leftCls = ctx.requiredClass("Foo")
val ref = leftCls.requiredMethod("value").termRef

def checkSig()(using Context): Unit =
val denot = ref.denot
assert(ref.signature == denot.signature, i"Wrong cached signature at phase ${ctx.phase} for $ref.\nActual denotation signature: ${denot.signature}\nCached ref signature: ${ref.signature}")

checkSig()
checkSig()(using ctx.withPhase(ctx.erasurePhase.next))
}
18 changes: 15 additions & 3 deletions compiler/test/dotty/tools/compilerSupport.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dotty.tools

import javax.tools._
import java.io.File
import java.io._
import java.nio.file._
import java.net.URI
import scala.jdk.CollectionConverters._
Expand All @@ -10,13 +10,25 @@ import core._
import core.Contexts._
import dotc.core.Comments.{ContextDoc, ContextDocstrings}

// TODO: refactor, copy-pasted from Run#compileFromStrings
private def sourceFile(source: String, isJava: Boolean): util.SourceFile = {
val uuid = java.util.UUID.randomUUID().toString
val ext = if (isJava) ".java" else ".scala"
val virtualFile = new io.VirtualFile(s"compileFromString-$uuid.$ext")
val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, "UTF-8")) // buffering is still advised by javadoc
writer.write(source)
writer.close()
new util.SourceFile(virtualFile, scala.io.Codec.UTF8)
}

/** Initialize a compiler context with the given classpath and
* pass it to `op`.
*/
def inCompilerContext[T](classpath: String)(op: Context ?=> T): T =
def inCompilerContext[T](classpath: String, scalaSources: String*)(op: Context ?=> T): T =
val compiler = Compiler()
val run = compiler.newRun(initCtx(classpath))
run.compileUnits(Nil) // Initialize phases
run.compileUnits(scalaSources.toList.map(s =>
CompilationUnit(sourceFile(s, isJava = false))(using run.runContext)))
op(using run.runContext)

private def initCtx(classpath: String): Context =
Expand Down