Skip to content

Commit a5127a8

Browse files
committed
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.
1 parent 3dba993 commit a5127a8

31 files changed

+284
-148
lines changed

src/compiler/scala/reflect/macros/compiler/Errors.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ trait Errors extends Traces {
1212
import definitions._
1313
import typer.TyperErrorGen._
1414
import typer.infer.InferErrorGen._
15+
private val runDefinitions = currentRun.runDefinitions
16+
import runDefinitions._
1517
def globalSettings = global.settings
1618

1719
// sanity check errors

src/compiler/scala/reflect/macros/compiler/Resolvers.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ trait Resolvers {
1212
import definitions.{EmptyPackageClass => _, _}
1313
import treeInfo._
1414
import gen._
15+
private val runDefinitions = currentRun.runDefinitions
16+
import runDefinitions.{Predef_???, _}
1517

1618
/** Determines the type of context implied by the macro def.
1719
*/

src/compiler/scala/reflect/macros/compiler/Validators.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ trait Validators {
1111
import global._
1212
import analyzer._
1313
import definitions._
14+
private val runDefinitions = currentRun.runDefinitions
15+
import runDefinitions.{Predef_???, _}
1416

1517
def validateMacroImplRef() = {
1618
sanityCheck()

src/compiler/scala/reflect/macros/util/Helpers.scala

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ trait Helpers {
2323
* or to streamline creation of the list of macro arguments.
2424
*/
2525
def transformTypeTagEvidenceParams(macroImplRef: Tree, transform: (Symbol, Symbol) => Symbol): List[List[Symbol]] = {
26+
val runDefinitions = currentRun.runDefinitions
27+
import runDefinitions._
28+
2629
val MacroContextUniverse = definitions.MacroContextUniverse
2730
val treeInfo.MacroImplReference(isBundle, _, macroImpl, _) = macroImplRef
2831
val paramss = macroImpl.paramss
@@ -51,15 +54,25 @@ trait Helpers {
5154
*
5255
* @see Metalevels.scala for more information and examples about metalevels
5356
*/
54-
def increaseMetalevel(pre: Type, tp: Type): Type = transparentShallowTransform(RepeatedParamClass, tp) {
55-
case tp => typeRef(pre, MacroContextExprClass, List(tp))
57+
def increaseMetalevel(pre: Type, tp: Type): Type = {
58+
val runDefinitions = currentRun.runDefinitions
59+
import runDefinitions._
60+
61+
transparentShallowTransform(RepeatedParamClass, tp) {
62+
case tp => typeRef(pre, MacroContextExprClass, List(tp))
63+
}
5664
}
5765

5866
/** Transforms c.Expr[T] types into c.Tree and leaves the rest unchanged.
5967
*/
60-
def untypeMetalevel(tp: Type): Type = transparentShallowTransform(RepeatedParamClass, tp) {
61-
case ExprClassOf(_) => typeRef(tp.prefix, TreesTreeType, Nil)
62-
case tp => tp
68+
def untypeMetalevel(tp: Type): Type = {
69+
val runDefinitions = currentRun.runDefinitions
70+
import runDefinitions._
71+
72+
transparentShallowTransform(RepeatedParamClass, tp) {
73+
case ExprClassOf(_) => typeRef(tp.prefix, TreesTreeType, Nil)
74+
case tp => tp
75+
}
6376
}
6477

6578
/** Decreases metalevel of the type, i.e. transforms:
@@ -68,8 +81,12 @@ trait Helpers {
6881
*
6982
* @see Metalevels.scala for more information and examples about metalevels
7083
*/
71-
def decreaseMetalevel(tp: Type): Type = transparentShallowTransform(RepeatedParamClass, tp) {
72-
case ExprClassOf(runtimeType) => runtimeType
73-
case _ => AnyTpe // so that macro impls with rhs = ??? don't screw up our inference
84+
def decreaseMetalevel(tp: Type): Type = {
85+
val runDefinitions = currentRun.runDefinitions
86+
import runDefinitions._
87+
transparentShallowTransform(RepeatedParamClass, tp) {
88+
case ExprClassOf(runtimeType) => runtimeType
89+
case _ => AnyTpe // so that macro impls with rhs = ??? don't screw up our inference
90+
}
7491
}
75-
}
92+
}

src/compiler/scala/reflect/reify/Reifier.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ abstract class Reifier extends States
2020
val global: Global
2121
import global._
2222
import definitions._
23+
private val runDefinitions = currentRun.runDefinitions
24+
import runDefinitions._
2325

2426
val typer: global.analyzer.Typer
2527
val universe: Tree
@@ -110,7 +112,7 @@ abstract class Reifier extends States
110112
// maybe try `resetLocalAttrs` once the dust settles
111113
var importantSymbols = Set[Symbol](
112114
NothingClass, AnyClass, SingletonClass, PredefModule, ScalaRunTimeModule, TypeCreatorClass, TreeCreatorClass, MirrorClass,
113-
ApiUniverseClass, JavaUniverseClass, ReflectRuntimePackage, ReflectRuntimeCurrentMirror)
115+
ApiUniverseClass, JavaUniverseClass, ReflectRuntimePackage, runDefinitions.ReflectRuntimeCurrentMirror)
114116
importantSymbols ++= importantSymbols map (_.companionSymbol)
115117
importantSymbols ++= importantSymbols map (_.moduleClass)
116118
importantSymbols ++= importantSymbols map (_.linkedClassOfClass)

src/compiler/scala/reflect/reify/Taggers.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ abstract class Taggers {
88

99
import c.universe._
1010
import definitions._
11+
private val runDefinitions = currentRun.runDefinitions
12+
import runDefinitions._
1113

1214
val coreTags = Map(
1315
ByteTpe -> nme.Byte,

src/compiler/scala/reflect/reify/codegen/GenTypes.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ trait GenTypes {
66

77
import global._
88
import definitions._
9+
private val runDefinitions = currentRun.runDefinitions
10+
import runDefinitions.{ReflectRuntimeUniverse, ReflectRuntimeCurrentMirror, _}
911

1012
/**
1113
* Reify a type.

src/compiler/scala/reflect/reify/package.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ package object reify {
6363
tpe.dealiasWiden match {
6464
case TypeRef(_, ArrayClass, componentTpe :: Nil) =>
6565
val componentErasure = reifyRuntimeClass(global)(typer0, componentTpe, concrete)
66-
gen.mkMethodCall(arrayClassMethod, List(componentErasure))
66+
gen.mkMethodCall(currentRun.runDefinitions.arrayClassMethod, List(componentErasure))
6767
case _ =>
6868
var erasure = tpe.erasure
6969
if (tpe.typeSymbol.isDerivedValueClass && global.phase.id < global.currentRun.erasurePhase.id) erasure = tpe
70-
gen.mkNullaryCall(Predef_classOf, List(erasure))
70+
gen.mkNullaryCall(currentRun.runDefinitions.Predef_classOf, List(erasure))
7171
}
7272
}
7373

src/compiler/scala/reflect/reify/phases/Reshape.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ trait Reshape {
99
import global._
1010
import definitions._
1111
import treeInfo.Unapplied
12+
private val runDefinitions = currentRun.runDefinitions
13+
import runDefinitions._
1214

1315
/**
1416
* Rolls back certain changes that were introduced during typechecking of the reifee.

src/compiler/scala/tools/nsc/backend/icode/GenICode.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ abstract class GenICode extends SubComponent {
702702
}
703703
genLoadApply3
704704

705-
case Apply(fun @ _, List(expr)) if (definitions.isBox(fun.symbol)) =>
705+
case Apply(fun @ _, List(expr)) if currentRun.runDefinitions.isBox(fun.symbol) =>
706706
def genLoadApply4 = {
707707
debuglog("BOX : " + fun.symbol.fullName)
708708
val ctx1 = genLoad(expr, ctx, toTypeKind(expr.tpe))
@@ -721,7 +721,7 @@ abstract class GenICode extends SubComponent {
721721
}
722722
genLoadApply4
723723

724-
case Apply(fun @ _, List(expr)) if (definitions.isUnbox(fun.symbol)) =>
724+
case Apply(fun @ _, List(expr)) if (currentRun.runDefinitions.isUnbox(fun.symbol)) =>
725725
debuglog("UNBOX : " + fun.symbol.fullName)
726726
val ctx1 = genLoad(expr, ctx, toTypeKind(expr.tpe))
727727
val boxType = toTypeKind(fun.symbol.owner.linkedClassOfClass.tpe)

0 commit comments

Comments
 (0)