diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-10-29 16:04:17 +0100 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-11-08 08:25:18 +0100 |
commit | a5127a8392fd2a0bce9b3ced302b4ebe1a80bc65 (patch) | |
tree | 4d52b8ed7dd8fcfb10d4bef41198ffe6ecc7cfe6 /test | |
parent | 3dba9932fcc79ce0ea6f7c9282320c14c95d133f (diff) | |
download | scala-a5127a8392fd2a0bce9b3ced302b4ebe1a80bc65.tar.gz scala-a5127a8392fd2a0bce9b3ced302b4ebe1a80bc65.tar.bz2 scala-a5127a8392fd2a0bce9b3ced302b4ebe1a80bc65.zip |
SI-7678 Don't cache member symbols of TypeTags in Definitions.
It we can only safely use vals in Definitions for top-level symbols.
Otherwise, when the IDE switches to loading the symbol from source,
we can hold on to a stale symbol, which in turn impedes implicit
materialization of TypeTags.
This commit moves (most) of the accessors for member symbols
into RunDefinitions, and changes calling code accordingly.
This is a win for presentation compiler correctness, and
might even shave of a few cycles.
In a few cases, I have had to leave a `def` to a member symbol
in Definitions so we can get to it from the SymbolTable cake,
which doesn't see RunDefinitions.
The macro FastTrack facility now correctly recreates the mapping
from Symbol to macro implementation each run, using a new facility
in perRunCaches to create a run-indexed cache.
The enclosed test recreates the situation reported in the ticket,
in which TypeTags.scala is loaded from source.
Diffstat (limited to 'test')
-rw-r--r-- | test/files/presentation/t7678.check | 1 | ||||
-rw-r--r-- | test/files/presentation/t7678/Runner.scala | 62 | ||||
-rw-r--r-- | test/files/presentation/t7678/src/TypeTag.scala | 9 |
3 files changed, 72 insertions, 0 deletions
diff --git a/test/files/presentation/t7678.check b/test/files/presentation/t7678.check new file mode 100644 index 0000000000..f06434b322 --- /dev/null +++ b/test/files/presentation/t7678.check @@ -0,0 +1 @@ +reload: TypeTag.scala diff --git a/test/files/presentation/t7678/Runner.scala b/test/files/presentation/t7678/Runner.scala new file mode 100644 index 0000000000..14d6dc2a70 --- /dev/null +++ b/test/files/presentation/t7678/Runner.scala @@ -0,0 +1,62 @@ +import scala.tools.nsc.interactive.tests._ +import scala.reflect.internal.util._ + +object Test extends InteractiveTest { + + import compiler._, definitions._ + + override def runDefaultTests() { + def resolveTypeTagHyperlink() { + val sym = compiler.askForResponse(() => compiler.currentRun.runDefinitions.TypeTagClass).get.left.get + val r = new Response[Position] + compiler.askLinkPos(sym, new BatchSourceFile("", source), r) + r.get + } + + def checkTypeTagSymbolConsistent() { + compiler.askForResponse { + () => { + val runDefinitions = currentRun.runDefinitions + import runDefinitions._ + assert(TypeTagsClass.map(sym => getMemberClass(sym, tpnme.TypeTag)) == TypeTagClass) + assert(TypeTagsClass.map(sym => getMemberClass(sym, tpnme.WeakTypeTag)) == WeakTypeTagClass) + assert(TypeTagsClass.map(sym => getMemberModule(sym, nme.WeakTypeTag)) == WeakTypeTagModule) + assert(getMemberMethod(ReflectPackage, nme.materializeClassTag) == materializeClassTag) + assert(ReflectApiPackage.map(sym => getMemberMethod(sym, nme.materializeWeakTypeTag)) == materializeWeakTypeTag) + assert(ReflectApiPackage.map(sym => getMemberMethod(sym, nme.materializeTypeTag)) == materializeTypeTag) + () + } + }.get match { + case Right(t) => t.printStackTrace + case Left(_) => + } + } + resolveTypeTagHyperlink() + // The presentation compiler loads TypeTags from source; we'll get new symbols for its members. + // Need to make sure we didn't cache the old ones in Definitions. + checkTypeTagSymbolConsistent() + } + + def source = + """ + |package scala + |package reflect + |package api + | + |trait TypeTags { self: Universe => + | import definitions._ + | + | @annotation.implicitNotFound(msg = "No WeakTypeTag available for ${T}") + | trait WeakTypeTag[T] extends Equals with Serializable { + | val mirror: Mirror + | def in[U <: Universe with Singleton](otherMirror: scala.reflect.api.Mirror[U]): U # WeakTypeTag[T] + | def tpe: Type + | } + | object WeakTypeTag + | + | trait TypeTag[T] extends WeakTypeTag[T] with Equals with Serializable { + | } + | object TypeTag + | + """.stripMargin +} diff --git a/test/files/presentation/t7678/src/TypeTag.scala b/test/files/presentation/t7678/src/TypeTag.scala new file mode 100644 index 0000000000..0b222f8851 --- /dev/null +++ b/test/files/presentation/t7678/src/TypeTag.scala @@ -0,0 +1,9 @@ +package test + +object Test { + import scala.reflect.runtime.{ universe => ru } + def getTypeTag(implicit tag: ru.TypeTag[Int] ) = () + locally { + getTypeTag/*?*/ + } +} |