summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala10
-rw-r--r--src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala4
-rw-r--r--src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala2
-rw-r--r--src/compiler/scala/tools/nsc/transform/AddInterfaces.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Namers.scala2
-rw-r--r--src/reflect/scala/reflect/api/Symbols.scala17
-rw-r--r--src/reflect/scala/reflect/internal/Flags.scala6
-rw-r--r--src/reflect/scala/reflect/internal/HasFlags.scala2
-rw-r--r--src/reflect/scala/reflect/internal/Importers.scala2
-rw-r--r--src/reflect/scala/reflect/internal/Symbols.scala93
-rw-r--r--src/reflect/scala/reflect/internal/Types.scala10
-rw-r--r--src/reflect/scala/reflect/internal/pickling/UnPickler.scala2
-rw-r--r--src/reflect/scala/reflect/runtime/JavaMirrors.scala10
-rw-r--r--src/reflect/scala/reflect/runtime/SymbolLoaders.scala4
-rw-r--r--src/reflect/scala/reflect/runtime/SymbolTable.scala28
-rw-r--r--test/files/run/existentials3-new.check8
-rw-r--r--test/files/run/reflection-java-annotations.scala4
-rw-r--r--test/files/run/reflection-magicsymbols-invoke.check4
-rw-r--r--test/files/run/reify_ann1a.scala1
-rw-r--r--test/files/run/reify_ann1b.scala1
-rw-r--r--test/files/run/reify_ann2a.scala1
-rw-r--r--test/files/run/reify_ann3.scala1
-rw-r--r--test/files/run/reify_ann4.scala1
-rw-r--r--test/files/run/reify_ann5.scala1
-rw-r--r--test/files/run/t5423.scala2
-rw-r--r--test/files/run/t6277.check1
-rw-r--r--test/files/run/t6277.scala9
27 files changed, 164 insertions, 64 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala b/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
index f7c3a55954..369b6aa77d 100644
--- a/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
+++ b/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
@@ -219,7 +219,7 @@ abstract class SymbolLoaders {
/**
* Load contents of a package
*/
- class PackageLoader(classpath: ClassPath[platform.BinaryRepr]) extends SymbolLoader {
+ class PackageLoader(classpath: ClassPath[platform.BinaryRepr]) extends SymbolLoader with FlagAgnosticCompleter {
protected def description = "package loader "+ classpath.name
protected def doComplete(root: Symbol) {
@@ -242,7 +242,7 @@ abstract class SymbolLoaders {
}
}
- class ClassfileLoader(val classfile: AbstractFile) extends SymbolLoader {
+ class ClassfileLoader(val classfile: AbstractFile) extends SymbolLoader with FlagAssigningCompleter {
private object classfileParser extends ClassfileParser {
val global: SymbolLoaders.this.global.type = SymbolLoaders.this.global
}
@@ -267,7 +267,7 @@ abstract class SymbolLoaders {
override def sourcefile: Option[AbstractFile] = classfileParser.srcfile
}
- class MsilFileLoader(msilFile: MsilFile) extends SymbolLoader {
+ class MsilFileLoader(msilFile: MsilFile) extends SymbolLoader with FlagAssigningCompleter {
private def typ = msilFile.msilType
private object typeParser extends clr.TypeParser {
val global: SymbolLoaders.this.global.type = SymbolLoaders.this.global
@@ -277,14 +277,14 @@ abstract class SymbolLoaders {
protected def doComplete(root: Symbol) { typeParser.parse(typ, root) }
}
- class SourcefileLoader(val srcfile: AbstractFile) extends SymbolLoader {
+ class SourcefileLoader(val srcfile: AbstractFile) extends SymbolLoader with FlagAssigningCompleter {
protected def description = "source file "+ srcfile.toString
override def fromSource = true
override def sourcefile = Some(srcfile)
protected def doComplete(root: Symbol): Unit = global.currentRun.compileLate(srcfile)
}
- object moduleClassLoader extends SymbolLoader {
+ object moduleClassLoader extends SymbolLoader with FlagAssigningCompleter {
protected def description = "module class loader"
protected def doComplete(root: Symbol) { root.sourceModule.initialize }
}
diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
index a356b70e62..8fd8dfaf83 100644
--- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
+++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
@@ -844,7 +844,7 @@ abstract class ClassfileParser {
GenPolyType(ownTypeParams, tpe)
} // sigToType
- class TypeParamsType(override val typeParams: List[Symbol]) extends LazyType {
+ class TypeParamsType(override val typeParams: List[Symbol]) extends LazyType with FlagAgnosticCompleter {
override def complete(sym: Symbol) { throw new AssertionError("cyclic type dereferencing") }
}
@@ -1228,7 +1228,7 @@ abstract class ClassfileParser {
}
}
- class LazyAliasType(alias: Symbol) extends LazyType {
+ class LazyAliasType(alias: Symbol) extends LazyType with FlagAgnosticCompleter {
override def complete(sym: Symbol) {
sym setInfo createFromClonedSymbols(alias.initialize.typeParams, alias.tpe)(typeFun)
}
diff --git a/src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala b/src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala
index 18b95ba191..1d2ffd2a73 100644
--- a/src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala
+++ b/src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala
@@ -64,7 +64,7 @@ abstract class TypeParser {
busy = false
}
- class TypeParamsType(override val typeParams: List[Symbol]) extends LazyType {
+ class TypeParamsType(override val typeParams: List[Symbol]) extends LazyType with FlagAgnosticCompleter {
override def complete(sym: Symbol) { throw new AssertionError("cyclic type dereferencing") }
}
diff --git a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala
index ab0a8756a4..18db1e6ab4 100644
--- a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala
+++ b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala
@@ -132,7 +132,7 @@ abstract class AddInterfaces extends InfoTransform { self: Erasure =>
* - for every interface member of iface: its implementation method, if one is needed
* - every former member of iface that is implementation only
*/
- private class LazyImplClassType(iface: Symbol) extends LazyType {
+ private class LazyImplClassType(iface: Symbol) extends LazyType with FlagAgnosticCompleter {
/** Compute the decls of implementation class implClass,
* given the decls ifaceDecls of its interface.
*/
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
index 9e66d696cb..1b2225f5f2 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
@@ -1506,7 +1506,7 @@ trait Namers extends MethodSynthesis {
/** A class representing a lazy type with known type parameters.
*/
- class PolyTypeCompleter(tparams: List[TypeDef], restp: TypeCompleter, owner: Tree, ctx: Context) extends LockingTypeCompleter {
+ class PolyTypeCompleter(tparams: List[TypeDef], restp: TypeCompleter, owner: Tree, ctx: Context) extends LockingTypeCompleter with FlagAgnosticCompleter {
private val ownerSym = owner.symbol
override val typeParams = tparams map (_.symbol) //@M
override val tree = restp.tree
diff --git a/src/reflect/scala/reflect/api/Symbols.scala b/src/reflect/scala/reflect/api/Symbols.scala
index 78345e27f2..d8f955ddf3 100644
--- a/src/reflect/scala/reflect/api/Symbols.scala
+++ b/src/reflect/scala/reflect/api/Symbols.scala
@@ -214,22 +214,7 @@ trait Symbols { self: Universe =>
/** A list of annotations attached to this Symbol.
*/
- // we cannot expose the `annotations` method because it doesn't auto-initialize a symbol (see SI-5423)
- // there was an idea to use the `isCompilerUniverse` flag and auto-initialize symbols in `annotations` whenever this flag is false
- // but it doesn't work, because the unpickler (that is shared between reflective universes and global universes) is very picky about initialization
- // scala.reflect.internal.Types$TypeError: bad reference while unpickling scala.collection.immutable.Nil: type Nothing not found in scala.type not found.
- // at scala.reflect.internal.pickling.UnPickler$Scan.toTypeError(UnPickler.scala:836)
- // at scala.reflect.internal.pickling.UnPickler$Scan$LazyTypeRef.complete(UnPickler.scala:849) // auto-initialize goes boom
- // at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1140)
- // at scala.reflect.internal.Symbols$Symbol.initialize(Symbols.scala:1272) // this triggers auto-initialize
- // at scala.reflect.internal.Symbols$Symbol.annotations(Symbols.scala:1438) // unpickler first tries to get pre-existing annotations
- // at scala.reflect.internal.Symbols$Symbol.addAnnotation(Symbols.scala:1458) // unpickler tries to add the annotation being read
- // at scala.reflect.internal.pickling.UnPickler$Scan.readSymbolAnnotation(UnPickler.scala:489) // unpickler detects an annotation
- // at scala.reflect.internal.pickling.UnPickler$Scan.run(UnPickler.scala:88)
- // at scala.reflect.internal.pickling.UnPickler.unpickle(UnPickler.scala:37)
- // at scala.reflect.runtime.JavaMirrors$JavaMirror.unpickleClass(JavaMirrors.scala:253) // unpickle from within a reflexive mirror
- // def annotations: List[Annotation]
- def getAnnotations: List[Annotation]
+ def annotations: List[Annotation]
/** For a class: the module or case class factory with the same name in the same package.
* For a module: the class with the same name in the same package.
diff --git a/src/reflect/scala/reflect/internal/Flags.scala b/src/reflect/scala/reflect/internal/Flags.scala
index 0eb839479a..bb454b1df7 100644
--- a/src/reflect/scala/reflect/internal/Flags.scala
+++ b/src/reflect/scala/reflect/internal/Flags.scala
@@ -296,6 +296,12 @@ class Flags extends ModifierFlags {
/** These flags are pickled */
final val PickledFlags = InitialFlags & ~FlagsNotPickled
+ /** If we have a top-level class or module
+ * and someone asks us for a flag not in TopLevelPickledFlags,
+ * then we don't need unpickling to give a definite answer.
+ */
+ final val TopLevelPickledFlags = PickledFlags & ~(MODULE | METHOD | PACKAGE | PARAM | EXISTENTIAL)
+
def getterFlags(fieldFlags: Long): Long = ACCESSOR + (
if ((fieldFlags & MUTABLE) != 0) fieldFlags & ~MUTABLE & ~PRESUPER
else fieldFlags & ~PRESUPER | STABLE
diff --git a/src/reflect/scala/reflect/internal/HasFlags.scala b/src/reflect/scala/reflect/internal/HasFlags.scala
index 62c8ed702b..4a3663b8ea 100644
--- a/src/reflect/scala/reflect/internal/HasFlags.scala
+++ b/src/reflect/scala/reflect/internal/HasFlags.scala
@@ -99,6 +99,7 @@ trait HasFlags {
def isLabel = hasAllFlags(LABEL | METHOD) && !hasAccessorFlag
def isLazy = hasFlag(LAZY)
def isLifted = hasFlag(LIFTED)
+ def isMacro = hasFlag(MACRO)
def isMutable = hasFlag(MUTABLE)
def isOverride = hasFlag(OVERRIDE)
def isParamAccessor = hasFlag(PARAMACCESSOR)
@@ -109,6 +110,7 @@ trait HasFlags {
def isProtectedLocal = hasAllFlags(ProtectedLocal)
def isPublic = hasNoFlags(PRIVATE | PROTECTED) && !hasAccessBoundary
def isSealed = hasFlag(SEALED)
+ def isSpecialized = hasFlag(SPECIALIZED)
def isSuperAccessor = hasFlag(SUPERACCESSOR)
def isSynthetic = hasFlag(SYNTHETIC)
def isTrait = hasFlag(TRAIT) && !hasFlag(PARAM)
diff --git a/src/reflect/scala/reflect/internal/Importers.scala b/src/reflect/scala/reflect/internal/Importers.scala
index c116928d37..893d039c3e 100644
--- a/src/reflect/scala/reflect/internal/Importers.scala
+++ b/src/reflect/scala/reflect/internal/Importers.scala
@@ -104,7 +104,7 @@ trait Importers extends api.Importers { self: SymbolTable =>
mysym setFlag Flags.LOCKED
mysym setInfo {
val mytypeParams = sym.typeParams map importSymbol
- new LazyPolyType(mytypeParams) {
+ new LazyPolyType(mytypeParams) with FlagAgnosticCompleter {
override def complete(s: Symbol) {
val result = sym.info match {
case from.PolyType(_, res) => res
diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala
index a0e28bf735..647a3c631b 100644
--- a/src/reflect/scala/reflect/internal/Symbols.scala
+++ b/src/reflect/scala/reflect/internal/Symbols.scala
@@ -55,6 +55,16 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
def newFreeTypeSymbol(name: TypeName, flags: Long = 0L, origin: String): FreeTypeSymbol =
new FreeTypeSymbol(name, origin) initFlags flags
+ /** Determines whether the given information request should trigger the given symbol's completer.
+ * See comments to `Symbol.needsInitialize` for details.
+ */
+ protected def shouldTriggerCompleter(symbol: Symbol, completer: Type, isFlagRelated: Boolean, mask: Long) =
+ completer match {
+ case null => false
+ case _: FlagAgnosticCompleter => !isFlagRelated
+ case _ => abort(s"unsupported completer: $completer of class ${if (completer != null) completer.getClass else null} for symbol ${symbol.fullName}")
+ }
+
/** The original owner of a class. Used by the backend to generate
* EnclosingMethod attributes.
*/
@@ -67,7 +77,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
def isParamWithDefault: Boolean = this.hasDefault
def isByNameParam: Boolean = this.isValueParameter && (this hasFlag BYNAMEPARAM)
def isImplementationArtifact: Boolean = (this hasFlag BRIDGE) || (this hasFlag VBRIDGE) || (this hasFlag ARTIFACT)
- def isJava: Boolean = this hasFlag JAVA
+ def isJava: Boolean = isJavaDefined
def isVal: Boolean = isTerm && !isModule && !isMethod && !isMutable
def isVar: Boolean = isTerm && !isModule && !isMethod && isMutable
@@ -88,7 +98,6 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
def toTypeIn(site: Type): Type = site.memberType(this)
def toTypeConstructor: Type = typeConstructor
def setTypeSignature(tpe: Type): this.type = { setInfo(tpe); this }
- def getAnnotations: List[AnnotationInfo] = { initialize; annotations }
def setAnnotations(annots: AnnotationInfo*): this.type = { setAnnotations(annots.toList); this }
def getter: Symbol = getter(owner)
@@ -218,9 +227,10 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
val m = newModuleSymbol(clazz.name.toTermName, clazz.pos, MODULE | newFlags)
connectModuleToClass(m, clazz.asInstanceOf[ClassSymbol])
}
- final def newModule(name: TermName, pos: Position = NoPosition, newFlags: Long = 0L): ModuleSymbol = {
- val m = newModuleSymbol(name, pos, newFlags | MODULE)
- val clazz = newModuleClass(name.toTypeName, pos, m getFlag ModuleToClassFlags)
+ final def newModule(name: TermName, pos: Position = NoPosition, newFlags0: Long = 0L): ModuleSymbol = {
+ val newFlags = newFlags0 | MODULE
+ val m = newModuleSymbol(name, pos, newFlags)
+ val clazz = newModuleClass(name.toTypeName, pos, newFlags & ModuleToClassFlags)
connectModuleToClass(m, clazz)
}
@@ -238,9 +248,10 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
final def newModuleSymbol(name: TermName, pos: Position = NoPosition, newFlags: Long = 0L): ModuleSymbol =
newTermSymbol(name, pos, newFlags).asInstanceOf[ModuleSymbol]
- final def newModuleAndClassSymbol(name: Name, pos: Position, flags: FlagSet): (ModuleSymbol, ClassSymbol) = {
- val m = newModuleSymbol(name, pos, flags | MODULE)
- val c = newModuleClass(name.toTypeName, pos, m getFlag ModuleToClassFlags)
+ final def newModuleAndClassSymbol(name: Name, pos: Position, flags0: FlagSet): (ModuleSymbol, ClassSymbol) = {
+ val flags = flags0 | MODULE
+ val m = newModuleSymbol(name, pos, flags)
+ val c = newModuleClass(name.toTypeName, pos, flags & ModuleToClassFlags)
connectModuleToClass(m, c)
(m, c)
}
@@ -489,14 +500,12 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
def isAliasType = false
def isAbstractType = false
def isSkolem = false
- def isMacro = this hasFlag MACRO
/** A Type, but not a Class. */
def isNonClassType = false
/** The bottom classes are Nothing and Null, found in Definitions. */
def isBottomClass = false
- def isSpecialized = this hasFlag SPECIALIZED
/** These are all tests for varieties of ClassSymbol, which has these subclasses:
* - ModuleClassSymbol
@@ -585,11 +594,20 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
&& owner.isPackageClass
&& nme.isReplWrapperName(name)
)
- final def getFlag(mask: Long): Long = flags & mask
+ final def getFlag(mask: Long): Long = {
+ if (!isCompilerUniverse && needsInitialize(isFlagRelated = true, mask = mask)) initialize
+ flags & mask
+ }
/** Does symbol have ANY flag in `mask` set? */
- final def hasFlag(mask: Long): Boolean = (flags & mask) != 0
+ final def hasFlag(mask: Long): Boolean = {
+ if (!isCompilerUniverse && needsInitialize(isFlagRelated = true, mask = mask)) initialize
+ (flags & mask) != 0
+ }
/** Does symbol have ALL the flags in `mask` set? */
- final def hasAllFlags(mask: Long): Boolean = (flags & mask) == mask
+ final def hasAllFlags(mask: Long): Boolean = {
+ if (!isCompilerUniverse && needsInitialize(isFlagRelated = true, mask = mask)) initialize
+ (flags & mask) == mask
+ }
def setFlag(mask: Long): this.type = { _rawflags |= mask ; this }
def resetFlag(mask: Long): this.type = { _rawflags &= ~mask ; this }
@@ -1138,7 +1156,10 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
/** See comment in HasFlags for how privateWithin combines with flags.
*/
private[this] var _privateWithin: Symbol = _
- def privateWithin = _privateWithin
+ def privateWithin = {
+ if (!isCompilerUniverse && needsInitialize(isFlagRelated = false, mask = 0)) initialize
+ _privateWithin
+ }
def privateWithin_=(sym: Symbol) { _privateWithin = sym }
def setPrivateWithin(sym: Symbol): this.type = { privateWithin_=(sym) ; this }
@@ -1329,6 +1350,46 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
this
}
+ /** Called when the programmer requests information that might require initialization of the underlying symbol.
+ *
+ * `isFlagRelated` and `mask` describe the nature of this information.
+ * isFlagRelated = true means that the programmer needs particular bits in flags.
+ * isFlagRelated = false means that the request is unrelated to flags (annotations or privateWithin).
+ *
+ * In our current architecture, symbols for top-level classes and modules
+ * are created as dummies. Package symbols just call newClass(name) or newModule(name) and
+ * consider their job done.
+ *
+ * In order for such a dummy to provide meaningful info (e.g. a list of its members),
+ * it needs to go through unpickling. Unpickling is a process of reading Scala metadata
+ * from ScalaSignature annotations and assigning it to symbols and types.
+ *
+ * A single unpickling session takes a top-level class or module, parses the ScalaSignature annotation
+ * and then reads metadata for the unpicklee, its companion (if any) and all their members recursively
+ * (i.e. the pickle not only contains info about directly nested classes/modules, but also about
+ * classes/modules nested into those and so on).
+ *
+ * Unpickling is triggered automatically whenever typeSignature (info in compiler parlance) is called.
+ * This happens because package symbols assign completer thunks to the dummies they create.
+ * Therefore metadata loading happens lazily and transparently.
+ *
+ * Almost transparently. Unfortunately metadata isn't limited to just signatures (i.e. lists of members).
+ * It also includes flags (which determine e.g. whether a class is sealed or not), annotations and privateWithin.
+ * This gives rise to unpleasant effects like in SI-6277, when a flag test called on an uninitialize symbol
+ * produces incorrect results.
+ *
+ * One might think that the solution is simple: automatically call the completer whenever one needs
+ * flags, annotations and privateWithin - just like it's done for typeSignature. Unfortunately, this
+ * leads to weird crashes in scalac, and currently we can't attempt to fix the core of the compiler
+ * risk stability a few weeks before the final release.
+ *
+ * However we do need to fix this for runtime reflection, since it's not something we'd like to
+ * expose to reflection users. Therefore a proposed solution is to check whether we're in a
+ * runtime reflection universe and if yes then to commence initialization.
+ */
+ protected def needsInitialize(isFlagRelated: Boolean, mask: Long) =
+ !isInitialized && (flags & LOCKED) == 0 && shouldTriggerCompleter(this, if (infos ne null) infos.info else null, isFlagRelated, mask)
+
/** Was symbol's type updated during given phase? */
final def isUpdatedAt(pid: Phase#Id): Boolean = {
assert(isCompilerUniverse)
@@ -1491,8 +1552,10 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
/** After the typer phase (before, look at the definition's Modifiers), contains
* the annotations attached to member a definition (class, method, type, field).
*/
- def annotations: List[AnnotationInfo] =
+ def annotations: List[AnnotationInfo] = {
+ if (!isCompilerUniverse && needsInitialize(isFlagRelated = false, mask = 0)) initialize
_annotations
+ }
def setAnnotations(annots: List[AnnotationInfo]): this.type = {
_annotations = annots
diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala
index 4311f1dd4f..fd5694b599 100644
--- a/src/reflect/scala/reflect/internal/Types.scala
+++ b/src/reflect/scala/reflect/internal/Types.scala
@@ -3445,6 +3445,16 @@ trait Types extends api.Types { self: SymbolTable =>
override def kind = "LazyType"
}
+ /** A marker trait representing an as-yet unevaluated type
+ * which doesn't assign flags to the underlying symbol.
+ */
+ trait FlagAgnosticCompleter extends LazyType
+
+ /** A marker trait representing an as-yet unevaluated type
+ * which assigns flags to the underlying symbol.
+ */
+ trait FlagAssigningCompleter extends LazyType
+
abstract class LazyPolyType(override val typeParams: List[Symbol]) extends LazyType {
override def safeToString =
(if (typeParams.isEmpty) "" else typeParamsString(this)) + super.safeToString
diff --git a/src/reflect/scala/reflect/internal/pickling/UnPickler.scala b/src/reflect/scala/reflect/internal/pickling/UnPickler.scala
index a9994a037f..b158a1ac26 100644
--- a/src/reflect/scala/reflect/internal/pickling/UnPickler.scala
+++ b/src/reflect/scala/reflect/internal/pickling/UnPickler.scala
@@ -848,7 +848,7 @@ abstract class UnPickler /*extends scala.reflect.generic.UnPickler*/ {
}
/** A lazy type which when completed returns type at index `i`. */
- private class LazyTypeRef(i: Int) extends LazyType {
+ private class LazyTypeRef(i: Int) extends LazyType with FlagAgnosticCompleter {
private val definedAtRunId = currentRunId
private val p = phase
override def complete(sym: Symbol) : Unit = try {
diff --git a/src/reflect/scala/reflect/runtime/JavaMirrors.scala b/src/reflect/scala/reflect/runtime/JavaMirrors.scala
index 2f12ba59a2..9cb3cf2382 100644
--- a/src/reflect/scala/reflect/runtime/JavaMirrors.scala
+++ b/src/reflect/scala/reflect/runtime/JavaMirrors.scala
@@ -44,6 +44,8 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { thisUnive
// overriden by ReflectGlobal
def rootClassLoader: ClassLoader = this.getClass.getClassLoader
+ trait JavaClassCompleter extends FlagAssigningCompleter
+
def init() = {
definitions.AnyValClass // force it.
@@ -71,7 +73,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { thisUnive
/** The lazy type for root.
*/
- override lazy val rootLoader = new LazyType {
+ override lazy val rootLoader = new LazyType with FlagAgnosticCompleter {
override def complete(sym: Symbol) = sym setInfo new LazyPackageType
}
@@ -609,7 +611,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { thisUnive
* A completer that fills in the type of a Scala type parameter from the bounds of a Java type variable.
* @param jtvar The Java type variable
*/
- private class TypeParamCompleter(jtvar: jTypeVariable[_ <: GenericDeclaration]) extends LazyType {
+ private class TypeParamCompleter(jtvar: jTypeVariable[_ <: GenericDeclaration]) extends LazyType with FlagAgnosticCompleter {
override def load(sym: Symbol) = complete(sym)
override def complete(sym: Symbol) = {
sym setInfo TypeBounds.upper(glb(jtvar.getBounds.toList map typeToScala map objToAny))
@@ -634,7 +636,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { thisUnive
* @param module The Scala companion object for which info is copied
* @param jclazz The Java class
*/
- private class FromJavaClassCompleter(clazz: Symbol, module: Symbol, jclazz: jClass[_]) extends LazyType {
+ private class FromJavaClassCompleter(clazz: Symbol, module: Symbol, jclazz: jClass[_]) extends LazyType with JavaClassCompleter with FlagAssigningCompleter {
/** used to avoid cycles while initializing classes */
private var parentsLevel = 0
@@ -710,7 +712,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { thisUnive
}
}
- class LazyPolyType(override val typeParams: List[Symbol]) extends LazyType {
+ class LazyPolyType(override val typeParams: List[Symbol]) extends LazyType with FlagAgnosticCompleter {
override def complete(sym: Symbol) {
completeRest()
}
diff --git a/src/reflect/scala/reflect/runtime/SymbolLoaders.scala b/src/reflect/scala/reflect/runtime/SymbolLoaders.scala
index f3473d46a7..d1be73bed3 100644
--- a/src/reflect/scala/reflect/runtime/SymbolLoaders.scala
+++ b/src/reflect/scala/reflect/runtime/SymbolLoaders.scala
@@ -14,7 +14,7 @@ trait SymbolLoaders { self: SymbolTable =>
* by unpickling information from the corresponding Java class. If no Java class
* is found, a package is created instead.
*/
- class TopClassCompleter(clazz: Symbol, module: Symbol) extends SymLoader {
+ class TopClassCompleter(clazz: Symbol, module: Symbol) extends SymLoader with FlagAssigningCompleter {
// def makePackage() {
// println("wrong guess; making package "+clazz)
// val ptpe = newPackageType(module.moduleClass)
@@ -80,7 +80,7 @@ trait SymbolLoaders { self: SymbolTable =>
/** The type completer for packages.
*/
- class LazyPackageType extends LazyType {
+ class LazyPackageType extends LazyType with FlagAgnosticCompleter {
override def complete(sym: Symbol) {
assert(sym.isPackageClass)
sym setInfo new ClassInfoType(List(), new PackageScope(sym), sym)
diff --git a/src/reflect/scala/reflect/runtime/SymbolTable.scala b/src/reflect/scala/reflect/runtime/SymbolTable.scala
index 5b9090dae5..73632be965 100644
--- a/src/reflect/scala/reflect/runtime/SymbolTable.scala
+++ b/src/reflect/scala/reflect/runtime/SymbolTable.scala
@@ -1,6 +1,8 @@
package scala.reflect
package runtime
+import scala.reflect.internal.Flags._
+
/**
* This symbol table trait fills in the definitions so that class information is obtained by refection.
* It can be used either from a reflexive universe (class scala.reflect.runtime.JavaUniverse), or else from
@@ -14,4 +16,30 @@ trait SymbolTable extends internal.SymbolTable with JavaMirrors with SymbolLoade
def debugInfo(msg: => String) =
if (settings.debug.value) info(msg)
+ /** Declares that this is a runtime reflection universe.
+ *
+ * This means that we can make certain assumptions to optimize the universe.
+ * For example, we may auto-initialize symbols on flag and annotation requests
+ * (see `shouldTriggerCompleter` below for more details).
+ *
+ * On the other hand, this also means that usage scenarios of the universe
+ * will differ from the conventional ones. For example, we have to do additional cleanup
+ * in order to prevent memory leaks: http://groups.google.com/group/scala-internals/browse_thread/thread/eabcf3d406dab8b2.
+ */
+ override def isCompilerUniverse = false
+
+ /** Unlike compiler universes, reflective universes can auto-initialize symbols on flag requests.
+ *
+ * scalac wasn't designed with such auto-initialization in mind, and quite often it makes assumptions
+ * that flag requests won't cause initialization. Therefore enabling auto-init leads to cyclic errors.
+ * We could probably fix those, but at the moment it's too risky.
+ *
+ * Reflective universes share codebase with scalac, but their surface is much smaller, which means less assumptions.
+ * These assumptions are taken care of in this overriden `shouldTriggerCompleter` method.
+ */
+ override protected def shouldTriggerCompleter(symbol: Symbol, completer: Type, isFlagRelated: Boolean, mask: Long) =
+ completer match {
+ case _: TopClassCompleter | _: JavaClassCompleter => !isFlagRelated || (mask & TopLevelPickledFlags) != 0
+ case _ => super.shouldTriggerCompleter(symbol, completer, isFlagRelated, mask)
+ }
}
diff --git a/test/files/run/existentials3-new.check b/test/files/run/existentials3-new.check
index bb6fe1a5e3..00614b19db 100644
--- a/test/files/run/existentials3-new.check
+++ b/test/files/run/existentials3-new.check
@@ -3,8 +3,8 @@ Bar, t=TypeRef, s=type Bar
Test.ToS, t=RefinedType, s=f3
Test.ToS, t=RefinedType, s=f4
Test.ToS, t=RefinedType, s=f5
-() => Test.ToS, t=TypeRef, s=class Function0
-() => Test.ToS, t=TypeRef, s=class Function0
+() => Test.ToS, t=TypeRef, s=trait Function0
+() => Test.ToS, t=TypeRef, s=trait Function0
$anon, t=TypeRef, s=type $anon
$anon, t=TypeRef, s=type $anon
List[java.lang.Object{type T1}#T1], t=TypeRef, s=class List
@@ -15,8 +15,8 @@ Bar, t=TypeRef, s=type Bar
Test.ToS, t=RefinedType, s=g3
Test.ToS, t=RefinedType, s=g4
Test.ToS, t=RefinedType, s=g5
-() => Test.ToS, t=TypeRef, s=class Function0
-() => Test.ToS, t=TypeRef, s=class Function0
+() => Test.ToS, t=TypeRef, s=trait Function0
+() => Test.ToS, t=TypeRef, s=trait Function0
$anon, t=TypeRef, s=type $anon
$anon, t=TypeRef, s=type $anon
List[java.lang.Object{type T1}#T1], t=TypeRef, s=class List
diff --git a/test/files/run/reflection-java-annotations.scala b/test/files/run/reflection-java-annotations.scala
index 0b16c0d103..2e3fed48ce 100644
--- a/test/files/run/reflection-java-annotations.scala
+++ b/test/files/run/reflection-java-annotations.scala
@@ -2,6 +2,6 @@ object Test extends App {
import scala.reflect.runtime.universe._
val sym = typeOf[JavaAnnottee].typeSymbol
sym.typeSignature
- sym.getAnnotations foreach (_.javaArgs)
- println(sym.getAnnotations)
+ sym.annotations foreach (_.javaArgs)
+ println(sym.annotations)
} \ No newline at end of file
diff --git a/test/files/run/reflection-magicsymbols-invoke.check b/test/files/run/reflection-magicsymbols-invoke.check
index 520dc2bfbe..f5258efeb7 100644
--- a/test/files/run/reflection-magicsymbols-invoke.check
+++ b/test/files/run/reflection-magicsymbols-invoke.check
@@ -90,7 +90,7 @@ method $asInstanceOf: [T0]()T0
method $isInstanceOf: [T0]()Boolean
method ==: (x$1: Any)Boolean
method ==: (x$1: AnyRef)Boolean
-method apply: (i: <?>)T
+method apply: (i: Int)T
method asInstanceOf: [T0]=> T0
method clone: ()Array[T]
method eq: (x$1: AnyRef)Boolean
@@ -105,7 +105,7 @@ method notify: ()Unit
method notifyAll: ()Unit
method synchronized: [T0](x$1: T0)T0
method toString: ()java.lang.String
-method update: (i: <?>, x: <?>)Unit
+method update: (i: Int, x: T)Unit
method wait: ()Unit
method wait: (x$1: Long)Unit
method wait: (x$1: Long, x$2: Int)Unit
diff --git a/test/files/run/reify_ann1a.scala b/test/files/run/reify_ann1a.scala
index 88b4191195..c23048e463 100644
--- a/test/files/run/reify_ann1a.scala
+++ b/test/files/run/reify_ann1a.scala
@@ -21,7 +21,6 @@ object Test extends App {
// test 2: import and typecheck
val toolbox = cm.mkToolBox()
val ttree = toolbox.typeCheck(tree)
- ttree.foreach(sub => if (sub.hasSymbol) sub.symbol.typeSignature)
println(ttree.toString)
// test 3: import and compile
diff --git a/test/files/run/reify_ann1b.scala b/test/files/run/reify_ann1b.scala
index a8fb876023..29ce6021a2 100644
--- a/test/files/run/reify_ann1b.scala
+++ b/test/files/run/reify_ann1b.scala
@@ -21,7 +21,6 @@ object Test extends App {
// test 2: import and typecheck
val toolbox = cm.mkToolBox()
val ttree = toolbox.typeCheck(tree)
- ttree.foreach(sub => if (sub.hasSymbol) sub.symbol.typeSignature)
println(ttree.toString)
// test 3: import and compile
diff --git a/test/files/run/reify_ann2a.scala b/test/files/run/reify_ann2a.scala
index b7e5833584..53423e12c3 100644
--- a/test/files/run/reify_ann2a.scala
+++ b/test/files/run/reify_ann2a.scala
@@ -21,7 +21,6 @@ object Test extends App {
// test 2: import and typecheck
val toolbox = cm.mkToolBox()
val ttree = toolbox.typeCheck(tree)
- ttree.foreach(sub => if (sub.hasSymbol) sub.symbol.typeSignature)
println(ttree.toString)
// test 3: import and compile
diff --git a/test/files/run/reify_ann3.scala b/test/files/run/reify_ann3.scala
index 662d58aaf3..4162fa532f 100644
--- a/test/files/run/reify_ann3.scala
+++ b/test/files/run/reify_ann3.scala
@@ -15,7 +15,6 @@ object Test extends App {
// test 2: import and typecheck
val toolbox = cm.mkToolBox()
val ttree = toolbox.typeCheck(tree)
- ttree.foreach(sub => if (sub.hasSymbol) sub.symbol.typeSignature)
println(ttree.toString)
// test 3: import and compile
diff --git a/test/files/run/reify_ann4.scala b/test/files/run/reify_ann4.scala
index a85e5e3625..0aedb77b5e 100644
--- a/test/files/run/reify_ann4.scala
+++ b/test/files/run/reify_ann4.scala
@@ -19,7 +19,6 @@ object Test extends App {
// test 2: import and typecheck
val toolbox = cm.mkToolBox()
val ttree = toolbox.typeCheck(tree)
- ttree.foreach(sub => if (sub.hasSymbol) sub.symbol.typeSignature)
println(ttree.toString)
// test 3: import and compile
diff --git a/test/files/run/reify_ann5.scala b/test/files/run/reify_ann5.scala
index 877360180c..d27be3b6d5 100644
--- a/test/files/run/reify_ann5.scala
+++ b/test/files/run/reify_ann5.scala
@@ -16,7 +16,6 @@ object Test extends App {
// test 2: import and typecheck
val toolbox = cm.mkToolBox()
val ttree = toolbox.typeCheck(tree)
- ttree.foreach(sub => if (sub.hasSymbol) sub.symbol.typeSignature)
println(ttree.toString)
// test 3: import and compile
diff --git a/test/files/run/t5423.scala b/test/files/run/t5423.scala
index 9b8ba090fa..c1632126b2 100644
--- a/test/files/run/t5423.scala
+++ b/test/files/run/t5423.scala
@@ -7,5 +7,5 @@ final class table extends annotation.StaticAnnotation
object Test extends App {
val s = cm.classSymbol(classOf[A])
- println(s.getAnnotations)
+ println(s.annotations)
} \ No newline at end of file
diff --git a/test/files/run/t6277.check b/test/files/run/t6277.check
new file mode 100644
index 0000000000..f32a5804e2
--- /dev/null
+++ b/test/files/run/t6277.check
@@ -0,0 +1 @@
+true \ No newline at end of file
diff --git a/test/files/run/t6277.scala b/test/files/run/t6277.scala
new file mode 100644
index 0000000000..41feee8a8a
--- /dev/null
+++ b/test/files/run/t6277.scala
@@ -0,0 +1,9 @@
+import scala.reflect.runtime.universe._
+
+object Test extends App {
+ locally {
+ val sym = typeOf[List[_]].typeSymbol.asClass
+ val q = sym.isSealed
+ println(q)
+ }
+} \ No newline at end of file