diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2012-09-14 08:12:32 -0700 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2012-09-14 08:12:32 -0700 |
commit | 65358306ba2538a6954767952058d6281ef139e2 (patch) | |
tree | 51a8bc0a388c578e96b97a24c8ef272dafe5c0d4 /src | |
parent | 52abc96229e624f6b31ee30ffced945ff652c994 (diff) | |
parent | 511578d7938a57b0756501cd565435083739fb39 (diff) | |
download | scala-65358306ba2538a6954767952058d6281ef139e2.tar.gz scala-65358306ba2538a6954767952058d6281ef139e2.tar.bz2 scala-65358306ba2538a6954767952058d6281ef139e2.zip |
Merge pull request #1295 from scalamacros/ticket/6323
improvements for type tags
Diffstat (limited to 'src')
39 files changed, 260 insertions, 271 deletions
diff --git a/src/compiler/scala/reflect/macros/runtime/Aliases.scala b/src/compiler/scala/reflect/macros/runtime/Aliases.scala index 5e15b61dbd..30e72997f7 100644 --- a/src/compiler/scala/reflect/macros/runtime/Aliases.scala +++ b/src/compiler/scala/reflect/macros/runtime/Aliases.scala @@ -17,12 +17,12 @@ trait Aliases { override type Expr[+T] = universe.Expr[T] override val Expr = universe.Expr - override type AbsTypeTag[T] = universe.AbsTypeTag[T] + override type WeakTypeTag[T] = universe.WeakTypeTag[T] override type TypeTag[T] = universe.TypeTag[T] - override val AbsTypeTag = universe.AbsTypeTag + override val WeakTypeTag = universe.WeakTypeTag override val TypeTag = universe.TypeTag - override def absTypeTag[T](implicit attag: AbsTypeTag[T]) = attag + override def weakTypeTag[T](implicit attag: WeakTypeTag[T]) = attag override def typeTag[T](implicit ttag: TypeTag[T]) = ttag - override def absTypeOf[T](implicit attag: AbsTypeTag[T]): Type = attag.tpe + override def weakTypeOf[T](implicit attag: WeakTypeTag[T]): Type = attag.tpe override def typeOf[T](implicit ttag: TypeTag[T]): Type = ttag.tpe }
\ No newline at end of file diff --git a/src/compiler/scala/reflect/macros/runtime/Exprs.scala b/src/compiler/scala/reflect/macros/runtime/Exprs.scala index 4217a6a404..ebf8fa2b96 100644 --- a/src/compiler/scala/reflect/macros/runtime/Exprs.scala +++ b/src/compiler/scala/reflect/macros/runtime/Exprs.scala @@ -4,5 +4,5 @@ package runtime trait Exprs { self: Context => - def Expr[T: AbsTypeTag](tree: Tree): Expr[T] = universe.Expr[T](mirror, universe.FixedMirrorTreeCreator(mirror, tree)) + def Expr[T: WeakTypeTag](tree: Tree): Expr[T] = universe.Expr[T](mirror, universe.FixedMirrorTreeCreator(mirror, tree)) } diff --git a/src/compiler/scala/reflect/macros/runtime/TypeTags.scala b/src/compiler/scala/reflect/macros/runtime/TypeTags.scala index 2bc2fe6384..19b60159de 100644 --- a/src/compiler/scala/reflect/macros/runtime/TypeTags.scala +++ b/src/compiler/scala/reflect/macros/runtime/TypeTags.scala @@ -4,6 +4,6 @@ package runtime trait TypeTags { self: Context => - def AbsTypeTag[T](tpe: Type): AbsTypeTag[T] = universe.AbsTypeTag[T](mirror, universe.FixedMirrorTypeCreator(mirror, tpe)) + def WeakTypeTag[T](tpe: Type): WeakTypeTag[T] = universe.WeakTypeTag[T](mirror, universe.FixedMirrorTypeCreator(mirror, tpe)) def TypeTag[T](tpe: Type): TypeTag[T] = universe.TypeTag[T](mirror, universe.FixedMirrorTypeCreator(mirror, tpe)) } diff --git a/src/compiler/scala/reflect/reify/Errors.scala b/src/compiler/scala/reflect/reify/Errors.scala index 5e15c5ad3a..73c13901b6 100644 --- a/src/compiler/scala/reflect/reify/Errors.scala +++ b/src/compiler/scala/reflect/reify/Errors.scala @@ -27,8 +27,8 @@ trait Errors { throw new ReificationError(defaultErrorPosition, msg) } - def CannotReifyTypeTagHavingUnresolvedTypeParameters(tpe: Type) = { - val msg = "cannot reify TypeTag having unresolved type parameter %s".format(tpe) + def CannotReifyWeakType(details: Any) = { + val msg = "cannot create a TypeTag" + details throw new ReificationError(defaultErrorPosition, msg) } diff --git a/src/compiler/scala/reflect/reify/States.scala b/src/compiler/scala/reflect/reify/States.scala index a01cfe5d74..58455c9f3c 100644 --- a/src/compiler/scala/reflect/reify/States.scala +++ b/src/compiler/scala/reflect/reify/States.scala @@ -34,9 +34,11 @@ trait States { def reificationIsConcrete_=(value: Boolean): Unit = { _reificationIsConcrete = value if (!value && concrete) { - assert(current.isInstanceOf[Type], current) - val offender = current.asInstanceOf[Type] - CannotReifyTypeTagHavingUnresolvedTypeParameters(offender) + current match { + case tpe: Type => CannotReifyWeakType(s" having unresolved type parameter $tpe") + case sym: Symbol => CannotReifyWeakType(s" referring to local ${sym.kindString} ${sym.fullName}") + case _ => CannotReifyWeakType("") + } } } var reifyStack = reifee :: Nil diff --git a/src/compiler/scala/reflect/reify/Taggers.scala b/src/compiler/scala/reflect/reify/Taggers.scala index a8523fe686..bc12d383a4 100644 --- a/src/compiler/scala/reflect/reify/Taggers.scala +++ b/src/compiler/scala/reflect/reify/Taggers.scala @@ -37,7 +37,7 @@ abstract class Taggers { } def materializeTypeTag(universe: Tree, mirror: Tree, tpe: Type, concrete: Boolean): Tree = { - val tagType = if (concrete) TypeTagClass else AbsTypeTagClass + val tagType = if (concrete) TypeTagClass else WeakTypeTagClass // what we need here is to compose a type BaseUniverse # TypeTag[$tpe] // to look for an implicit that conforms to this type // that's why neither appliedType(tagType, List(tpe)) aka TypeRef(TypeTagsClass.thisType, tagType, List(tpe)) @@ -50,7 +50,7 @@ abstract class Taggers { case success if !success.isEmpty => Apply(Select(success, nme.in), List(mirror orElse mkDefaultMirrorRef(c.universe)(universe, c.callsiteTyper))) case _ => - val tagModule = if (concrete) TypeTagModule else AbsTypeTagModule + val tagModule = if (concrete) TypeTagModule else WeakTypeTagModule materializeTag(universe, tpe, tagModule, c.reifyType(universe, mirror, tpe, concrete = concrete)) } } diff --git a/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala b/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala index ca6e14cfd3..c4b674955a 100644 --- a/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala +++ b/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala @@ -90,49 +90,61 @@ trait GenSymbols { } } else { // todo. make sure that free methods and free local defs work correctly - if (sym.isTerm) reifyFreeTerm(sym, Ident(sym)) - else reifyFreeType(sym, Ident(sym)) + if (sym.isExistential) reifySymDef(sym) + else if (sym.isTerm) reifyFreeTerm(Ident(sym)) + else reifyFreeType(Ident(sym)) } } - def reifyFreeTerm(sym: Symbol, value: Tree): Tree = - reifyIntoSymtab(sym) { + def reifyFreeTerm(binding: Tree): Tree = + reifyIntoSymtab(binding.symbol) { sym => if (reifyDebug) println("Free term" + (if (sym.isCapturedVariable) " (captured)" else "") + ": " + sym + "(" + sym.accurateKindString + ")") - var name = newTermName(nme.REIFY_FREE_PREFIX + sym.name) - if (sym.isType) name = name.append(nme.REIFY_FREE_THIS_SUFFIX) + val name = newTermName(nme.REIFY_FREE_PREFIX + sym.name + (if (sym.isType) nme.REIFY_FREE_THIS_SUFFIX else "")) if (sym.isCapturedVariable) { - assert(value.isInstanceOf[Ident], showRaw(value)) - val capturedTpe = capturedVariableType(sym) - val capturedValue = referenceCapturedVariable(sym) - (name, mirrorBuildCall(nme.newFreeTerm, reify(sym.name.toString), reify(capturedTpe), capturedValue, mirrorBuildCall(nme.flagsFromBits, reify(sym.flags)), reify(origin(sym)))) + assert(binding.isInstanceOf[Ident], showRaw(binding)) + val capturedBinding = referenceCapturedVariable(sym) + Reification(name, capturedBinding, mirrorBuildCall(nme.newFreeTerm, reify(sym.name.toString), capturedBinding, mirrorBuildCall(nme.flagsFromBits, reify(sym.flags)), reify(origin(sym)))) } else { - (name, mirrorBuildCall(nme.newFreeTerm, reify(sym.name.toString), reify(sym.tpe), value, mirrorBuildCall(nme.flagsFromBits, reify(sym.flags)), reify(origin(sym)))) + Reification(name, binding, mirrorBuildCall(nme.newFreeTerm, reify(sym.name.toString), binding, mirrorBuildCall(nme.flagsFromBits, reify(sym.flags)), reify(origin(sym)))) } } - def reifyFreeType(sym: Symbol, value: Tree): Tree = - reifyIntoSymtab(sym) { + def reifyFreeType(binding: Tree): Tree = + reifyIntoSymtab(binding.symbol) { sym => if (reifyDebug) println("Free type: %s (%s)".format(sym, sym.accurateKindString)) - var name = newTermName(nme.REIFY_FREE_PREFIX + sym.name) - val phantomTypeTag = Apply(TypeApply(Select(Ident(nme.UNIVERSE_SHORT), nme.TypeTag), List(value)), List(Literal(Constant(null)), Literal(Constant(null)))) - val flavor = if (sym.isExistential) nme.newFreeExistential else nme.newFreeType - (name, mirrorBuildCall(flavor, reify(sym.name.toString), reify(sym.info), phantomTypeTag, mirrorBuildCall(nme.flagsFromBits, reify(sym.flags)), reify(origin(sym)))) + state.reificationIsConcrete = false + val name = newTermName(nme.REIFY_FREE_PREFIX + sym.name) + Reification(name, binding, mirrorBuildCall(nme.newFreeType, reify(sym.name.toString), mirrorBuildCall(nme.flagsFromBits, reify(sym.flags)), reify(origin(sym)))) } def reifySymDef(sym: Symbol): Tree = - reifyIntoSymtab(sym) { + reifyIntoSymtab(sym) { sym => if (reifyDebug) println("Sym def: %s (%s)".format(sym, sym.accurateKindString)) - assert(!sym.isLocatable, sym) // if this assertion fires, then tough type reification needs to be rethought - sym.owner.ownersIterator find (!_.isLocatable) foreach reifySymDef - var name = newTermName(nme.REIFY_SYMDEF_PREFIX + sym.name) - (name, mirrorBuildCall(nme.newNestedSymbol, reify(sym.owner), reify(sym.name), reify(sym.pos), mirrorBuildCall(nme.flagsFromBits, reify(sym.flags)), reify(sym.isClass))) + val name = newTermName(nme.REIFY_SYMDEF_PREFIX + sym.name) + def reifiedOwner = if (sym.owner.isLocatable) reify(sym.owner) else reifySymDef(sym.owner) + Reification(name, Ident(sym), mirrorBuildCall(nme.newNestedSymbol, reifiedOwner, reify(sym.name), reify(sym.pos), mirrorBuildCall(nme.flagsFromBits, reify(sym.flags)), reify(sym.isClass))) } - private def reifyIntoSymtab(sym: Symbol)(reificode: => (TermName, Tree)): Tree ={ + case class Reification(name: Name, binding: Tree, tree: Tree) + + private def reifyIntoSymtab(sym: Symbol)(reificode: Symbol => Reification): Tree = { def fromSymtab = symtab symRef sym if (fromSymtab == EmptyTree) { - val reification = reificode - state.symtab += (sym, reification._1, reification._2) + // reification is lazy, so that we can carefully choose where to evaluate it + // and we choose this place to be exactly here: + // + // reasons: + // 1) reification happens at maximum once per symbol to prevent repeated reifications + // 2) reification happens before putting the symbol itself into the symbol table to ensure correct initialization order: + // for example, if reification of symbol A refers to reification of symbol B + // (this might happen when we're doing `reifySymDef`, which expands into `newNestedSymbol`, which needs `sym.owner`) + // then we have to put reification-B into the symbol table before reification-A + // so that subsequent code generation that traverses the symbol table in the first-added first-codegenned order + // produces valid Scala code (with vals in a block depending only on lexically preceding vals) + val reification = reificode(sym) + import reification.{name, binding} + val tree = reification.tree addAttachment ReifyBindingAttachment(binding) + state.symtab += (sym, name, tree) } fromSymtab } diff --git a/src/compiler/scala/reflect/reify/codegen/GenTrees.scala b/src/compiler/scala/reflect/reify/codegen/GenTrees.scala index f48df8df65..bdcc7383b0 100644 --- a/src/compiler/scala/reflect/reify/codegen/GenTrees.scala +++ b/src/compiler/scala/reflect/reify/codegen/GenTrees.scala @@ -124,7 +124,7 @@ trait GenTrees { val sym = tree.symbol if (reifyDebug) println("This for %s, reified as freeVar".format(sym)) if (reifyDebug) println("Free: " + sym) - mirrorBuildCall(nme.Ident, reifyFreeTerm(sym, This(sym))) + mirrorBuildCall(nme.Ident, reifyFreeTerm(This(sym))) case tree @ This(_) if !tree.symbol.isLocalToReifee => if (reifyDebug) println("This for %s, reified as This".format(tree.symbol)) mirrorBuildCall(nme.This, reify(tree.symbol)) diff --git a/src/compiler/scala/reflect/reify/codegen/GenTypes.scala b/src/compiler/scala/reflect/reify/codegen/GenTypes.scala index 1d2e177688..7aa87dc2f8 100644 --- a/src/compiler/scala/reflect/reify/codegen/GenTypes.scala +++ b/src/compiler/scala/reflect/reify/codegen/GenTypes.scala @@ -73,7 +73,7 @@ trait GenTypes { if (tpe.isSpliceable && !(quantified contains tpe.typeSymbol)) { if (reifyDebug) println("splicing " + tpe) - val tagFlavor = if (concrete) tpnme.TypeTag.toString else tpnme.AbsTypeTag.toString + val tagFlavor = if (concrete) tpnme.TypeTag.toString else tpnme.WeakTypeTag.toString val key = (tagFlavor, tpe.typeSymbol) // if this fails, it might produce the dreaded "erroneous or inaccessible type" error // to find out the whereabouts of the error run scalac with -Ydebug diff --git a/src/compiler/scala/reflect/reify/codegen/GenUtils.scala b/src/compiler/scala/reflect/reify/codegen/GenUtils.scala index 2b7733fb6c..8aef8d772f 100644 --- a/src/compiler/scala/reflect/reify/codegen/GenUtils.scala +++ b/src/compiler/scala/reflect/reify/codegen/GenUtils.scala @@ -131,7 +131,7 @@ trait GenUtils { def isCrossStageTypeBearer(tree: Tree): Boolean = tree match { case TypeApply(hk, _) => isCrossStageTypeBearer(hk) - case Select(sym @ Select(_, ctor), nme.apply) if ctor == nme.AbsTypeTag || ctor == nme.TypeTag || ctor == nme.Expr => true + case Select(sym @ Select(_, ctor), nme.apply) if ctor == nme.WeakTypeTag || ctor == nme.TypeTag || ctor == nme.Expr => true case _ => false } diff --git a/src/compiler/scala/reflect/reify/phases/Reshape.scala b/src/compiler/scala/reflect/reify/phases/Reshape.scala index fcf3c0e65c..0b07c47c0f 100644 --- a/src/compiler/scala/reflect/reify/phases/Reshape.scala +++ b/src/compiler/scala/reflect/reify/phases/Reshape.scala @@ -103,8 +103,8 @@ trait Reshape { // of, say, ClassTag or TypeTag case Apply(TypeApply(_, List(tt)), _) if original.symbol == MacroInternal_materializeClassTag => gen.mkNullaryCall(Predef_implicitly, List(appliedType(ClassTagClass, tt.tpe))) - case Apply(TypeApply(_, List(tt)), List(pre)) if original.symbol == MacroInternal_materializeAbsTypeTag => - gen.mkNullaryCall(Predef_implicitly, List(typeRef(pre.tpe, AbsTypeTagClass, List(tt.tpe)))) + case Apply(TypeApply(_, List(tt)), List(pre)) if original.symbol == MacroInternal_materializeWeakTypeTag => + gen.mkNullaryCall(Predef_implicitly, List(typeRef(pre.tpe, WeakTypeTagClass, List(tt.tpe)))) case Apply(TypeApply(_, List(tt)), List(pre)) if original.symbol == MacroInternal_materializeTypeTag => gen.mkNullaryCall(Predef_implicitly, List(typeRef(pre.tpe, TypeTagClass, List(tt.tpe)))) case _ => diff --git a/src/compiler/scala/reflect/reify/utils/Extractors.scala b/src/compiler/scala/reflect/reify/utils/Extractors.scala index ebe3957e69..1df9efbb82 100644 --- a/src/compiler/scala/reflect/reify/utils/Extractors.scala +++ b/src/compiler/scala/reflect/reify/utils/Extractors.scala @@ -94,7 +94,7 @@ trait Extractors { object ReifiedTree { def apply(universe: Tree, mirror: Tree, symtab: SymbolTable, rtree: Tree, tpe: Type, rtpe: Tree, concrete: Boolean): Tree = { - val tagFactory = if (concrete) nme.TypeTag else nme.AbsTypeTag + val tagFactory = if (concrete) nme.TypeTag else nme.WeakTypeTag val tagCtor = TypeApply(Select(Select(Ident(nme.UNIVERSE_SHORT), tagFactory), nme.apply), List(TypeTree(tpe))) val exprCtor = TypeApply(Select(Select(Ident(nme.UNIVERSE_SHORT), nme.Expr), nme.apply), List(TypeTree(tpe))) val tagArgs = List(Ident(nme.MIRROR_SHORT), mkCreator(tpnme.REIFY_TYPECREATOR_PREFIX, symtab, rtpe)) @@ -122,7 +122,7 @@ trait Extractors { object ReifiedType { def apply(universe: Tree, mirror: Tree, symtab: SymbolTable, tpe: Type, rtpe: Tree, concrete: Boolean) = { - val tagFactory = if (concrete) nme.TypeTag else nme.AbsTypeTag + val tagFactory = if (concrete) nme.TypeTag else nme.WeakTypeTag val ctor = TypeApply(Select(Select(Ident(nme.UNIVERSE_SHORT), tagFactory), nme.apply), List(TypeTree(tpe))) val args = List(Ident(nme.MIRROR_SHORT), mkCreator(tpnme.REIFY_TYPECREATOR_PREFIX, symtab, rtpe)) val unwrapped = Apply(ctor, args) @@ -176,12 +176,11 @@ trait Extractors { List( _, _, - binding, Apply(Select(Select(uref2 @ Ident(_), build2), flagsFromBits), List(Literal(Constant(flags: Long)))), Literal(Constant(origin: String))))) if uref1.name == nme.UNIVERSE_SHORT && build1 == nme.build && newFreeTerm == nme.newFreeTerm && uref2.name == nme.UNIVERSE_SHORT && build2 == nme.build && flagsFromBits == nme.flagsFromBits => - Some(uref1, name, binding, flags, origin) + Some(uref1, name, reifyBinding(tree), flags, origin) case _ => None } @@ -194,22 +193,11 @@ trait Extractors { Select(Select(uref1 @ Ident(_), build1), newFreeType), List( _, - _, - value, Apply(Select(Select(uref2 @ Ident(_), build2), flagsFromBits), List(Literal(Constant(flags: Long)))), Literal(Constant(origin: String))))) - if uref1.name == nme.UNIVERSE_SHORT && build1 == nme.build && (newFreeType == nme.newFreeType || newFreeType == nme.newFreeExistential) && + if uref1.name == nme.UNIVERSE_SHORT && build1 == nme.build && newFreeType == nme.newFreeType && uref2.name == nme.UNIVERSE_SHORT && build2 == nme.build && flagsFromBits == nme.flagsFromBits => - value match { - case Apply(TypeApply(Select(Select(uref3 @ Ident(_), typeTag), apply), List(binding)), List(Literal(Constant(null)), _)) - if uref3.name == nme.UNIVERSE_SHORT && typeTag == nme.TypeTag && apply == nme.apply => - Some(uref1, name, binding, flags, origin) - case Apply(TypeApply(Select(uref3 @ Ident(_), typeTag), List(binding)), List(Literal(Constant(null)), _)) - if uref3.name == nme.UNIVERSE_SHORT && typeTag == nme.TypeTag => - Some(uref1, name, binding, flags, origin) - case _ => - throw new Error("unsupported free type def: %s%n%s".format(value, showRaw(value))) - } + Some(uref1, name, reifyBinding(tree), flags, origin) case _ => None } diff --git a/src/compiler/scala/reflect/reify/utils/StdAttachments.scala b/src/compiler/scala/reflect/reify/utils/StdAttachments.scala index abbed814e0..0b9cf58c89 100644 --- a/src/compiler/scala/reflect/reify/utils/StdAttachments.scala +++ b/src/compiler/scala/reflect/reify/utils/StdAttachments.scala @@ -6,7 +6,13 @@ trait StdAttachments { import global._ - case class ReifyBindingAttachment(binding: Symbol) + case class ReifyBindingAttachment(binding: Tree) - case class ReifyAliasAttachment(binding: Symbol, alias: TermName) + def reifyBinding(tree: Tree): Tree = + tree.attachments.get[ReifyBindingAttachment] match { + case Some(ReifyBindingAttachment(binding)) => binding + case other => Ident(NoSymbol) + } + + case class ReifyAliasAttachment(sym: Symbol, alias: TermName) }
\ No newline at end of file diff --git a/src/compiler/scala/reflect/reify/utils/SymbolTables.scala b/src/compiler/scala/reflect/reify/utils/SymbolTables.scala index 3892c86dd3..2e17558f54 100644 --- a/src/compiler/scala/reflect/reify/utils/SymbolTables.scala +++ b/src/compiler/scala/reflect/reify/utils/SymbolTables.scala @@ -17,6 +17,7 @@ trait SymbolTables { private[SymbolTable] val original: Option[List[Tree]] = None) { def syms: List[Symbol] = symtab.keys.toList + def isConcrete: Boolean = symtab.values forall (sym => !FreeTypeDef.unapply(sym).isDefined) // def aliases: Map[Symbol, List[TermName]] = aliases.distinct groupBy (_._1) mapValues (_ map (_._2)) @@ -45,28 +46,27 @@ trait SymbolTables { def symRef(sym: Symbol): Tree = symtab.get(sym) match { - case Some(FreeDef(_, name, _, _, _)) => Ident(name) addAttachment ReifyBindingAttachment(sym) - case Some(SymDef(_, name, _, _)) => Ident(name) addAttachment ReifyBindingAttachment(sym) + case Some(FreeDef(_, name, binding, _, _)) => Ident(name) addAttachment binding + case Some(SymDef(_, name, _, _)) => Ident(name) addAttachment ReifyBindingAttachment(Ident(sym)) case None => EmptyTree } def +(sym: Symbol, name: TermName, reification: Tree): SymbolTable = add(sym, name, reification) - def +(sym: Symbol, name: TermName): SymbolTable = add(sym, name) def +(symDef: Tree): SymbolTable = add(symDef) def ++(symDefs: TraversableOnce[Tree]): SymbolTable = (this /: symDefs)((symtab, symDef) => symtab.add(symDef)) def ++(symtab: SymbolTable): SymbolTable = { val updated = this ++ symtab.symtab.values; new SymbolTable(updated.symtab, updated.aliases ++ symtab.aliases) } def -(sym: Symbol): SymbolTable = remove(sym) def -(name: TermName): SymbolTable = remove(name) - def -(symDef: Tree): SymbolTable = remove(binding(symDef)) + def -(symDef: Tree): SymbolTable = remove(reifyBinding(symDef).symbol) def --(syms: GenTraversableOnce[Symbol]): SymbolTable = (this /: syms)((symtab, sym) => symtab.remove(sym)) def --(names: Iterable[TermName]): SymbolTable = (this /: names)((symtab, name) => symtab.remove(name)) - def --(symDefs: TraversableOnce[Tree]): SymbolTable = this -- (symDefs map (binding(_))) + def --(symDefs: TraversableOnce[Tree]): SymbolTable = this -- (symDefs map (reifyBinding(_))) def --(symtab: SymbolTable): SymbolTable = { val updated = this -- symtab.symtab.values; new SymbolTable(updated.symtab, updated.aliases diff symtab.aliases) } def filterSyms(p: Symbol => Boolean): SymbolTable = this -- (syms filterNot p) def filterAliases(p: (Symbol, TermName) => Boolean): SymbolTable = this -- (aliases filterNot (tuple => p(tuple._1, tuple._2)) map (_._2)) private def add(symDef: Tree): SymbolTable = { - val sym = binding(symDef) + val sym = reifyBinding(symDef).symbol assert(sym != NoSymbol, showRaw(symDef)) val name = symDef match { case FreeDef(_, name, _, _, _) => name @@ -85,7 +85,8 @@ trait SymbolTables { val fresh = typer.context.unit.fresh newTermName(fresh.newName(name)) } - add(ValDef(NoMods, freshName(name0), TypeTree(), reification) addAttachment ReifyBindingAttachment(sym)) + val bindingAttachment = reification.attachments.get[ReifyBindingAttachment].get + add(ValDef(NoMods, freshName(name0), TypeTree(), reification) addAttachment bindingAttachment) } private def add(sym: Symbol, name: TermName): SymbolTable = { @@ -115,12 +116,6 @@ trait SymbolTables { new SymbolTable(newSymtab, newAliases) } - private def binding(tree: Tree): Symbol = - tree.attachments.get[ReifyBindingAttachment] match { - case Some(ReifyBindingAttachment(binding)) => binding - case other => NoSymbol - } - private val cache = mutable.Map[SymbolTable, List[Tree]]() def encode: List[Tree] = cache.getOrElseUpdate(this, SymbolTable.encode(this)) map (_.duplicate) @@ -147,7 +142,7 @@ trait SymbolTables { def apply(encoded: List[Tree]): SymbolTable = { var result = new SymbolTable(original = Some(encoded)) encoded foreach (entry => (entry.attachments.get[ReifyBindingAttachment], entry.attachments.get[ReifyAliasAttachment]) match { - case (Some(ReifyBindingAttachment(sym)), _) => result += entry + case (Some(ReifyBindingAttachment(_)), _) => result += entry case (_, Some(ReifyAliasAttachment(sym, alias))) => result = new SymbolTable(result.symtab, result.aliases :+ (sym, alias)) case _ => // do nothing, this is boilerplate that can easily be recreated by subsequent `result.encode` }) @@ -169,30 +164,26 @@ trait SymbolTables { def fillInSymbol(sym: Symbol): Tree = { if (reifyDebug) println("Filling in: %s (%s)".format(sym, sym.accurateKindString)) - val isFree = currtab.symName(sym) startsWith nme.REIFY_FREE_PREFIX - if (isFree) { - if (sym.annotations.isEmpty) EmptyTree - else Apply(Select(currtab.symRef(sym), nme.setAnnotations), List(reifier.reify(sym.annotations))) - } else { - // SI-6204 don't reify signatures for incomplete symbols, because this might lead to cyclic reference errors - val signature = - if (sym.isInitialized) { - if (sym.isCapturedVariable) capturedVariableType(sym) - else sym.info - } else NoType - val rset = reifier.mirrorBuildCall(nme.setTypeSignature, currtab.symRef(sym), reifier.reify(signature)) - // `Symbol.annotations` doesn't initialize the symbol, so we don't need to do anything special here - // also since we call `sym.info` a few lines above, by now the symbol will be initialized (if possible) - // so the annotations will be filled in and will be waiting to be reified (unless symbol initialization is prohibited as described above) - if (sym.annotations.isEmpty) rset - else reifier.mirrorBuildCall(nme.setAnnotations, rset, reifier.mkList(sym.annotations map reifier.reifyAnnotationInfo)) - } + val isFreeTerm = FreeTermDef.unapply(currtab.symDef(sym)).isDefined + // SI-6204 don't reify signatures for incomplete symbols, because this might lead to cyclic reference errors + val signature = + if (sym.isInitialized) { + if (sym.isCapturedVariable) capturedVariableType(sym) + else if (isFreeTerm) sym.tpe + else sym.info + } else NoType + val rset = reifier.mirrorBuildCall(nme.setTypeSignature, currtab.symRef(sym), reifier.reify(signature)) + // `Symbol.annotations` doesn't initialize the symbol, so we don't need to do anything special here + // also since we call `sym.info` a few lines above, by now the symbol will be initialized (if possible) + // so the annotations will be filled in and will be waiting to be reified (unless symbol initialization is prohibited as described above) + if (sym.annotations.isEmpty) rset + else reifier.mirrorBuildCall(nme.setAnnotations, rset, reifier.mkList(sym.annotations map reifier.reifyAnnotationInfo)) } // `fillInSymbol` might add symbols to `symtab`, that's why this is done iteratively var progress = 0 while (progress < cumulativeSymtab.length) { - val sym = currtab.binding(cumulativeSymtab(progress)) + val sym = reifyBinding(cumulativeSymtab(progress)).symbol if (sym != NoSymbol) { val symtabProgress = currtab.symtab.size val aliasesProgress = currtab.aliases.length @@ -207,7 +198,7 @@ trait SymbolTables { val withAliases = cumulativeSymtab flatMap (entry => { val result = mutable.ListBuffer[Tree]() result += entry - val sym = currtab.binding(entry) + val sym = reifyBinding(entry).symbol if (sym != NoSymbol) result ++= cumulativeAliases.distinct filter (alias => alias._1 == sym && alias._2 != currtab.symName(sym)) map (alias => { val canonicalName = currtab.symName(sym) diff --git a/src/compiler/scala/tools/nsc/doc/Settings.scala b/src/compiler/scala/tools/nsc/doc/Settings.scala index dbc34bd7b3..60cd375175 100644 --- a/src/compiler/scala/tools/nsc/doc/Settings.scala +++ b/src/compiler/scala/tools/nsc/doc/Settings.scala @@ -257,7 +257,7 @@ class Settings(error: String => Unit, val printMsg: String => Unit = println(_)) ("scala.reflect.ClassManifest" -> ((tparam: String) => tparam + " is accompanied by a ClassManifest, which is a runtime representation of its type that survives erasure")) + ("scala.reflect.OptManifest" -> ((tparam: String) => tparam + " is accompanied by an OptManifest, which can be either a runtime representation of its type or the NoManifest, which means the runtime type is not available")) + ("scala.reflect.ClassTag" -> ((tparam: String) => tparam + " is accompanied by a ClassTag, which is a runtime representation of its type that survives erasure")) + - ("scala.reflect.AbsTypeTag" -> ((tparam: String) => tparam + " is accompanied by an AbsTypeTag, which is a runtime representation of its type that survives erasure")) + + ("scala.reflect.WeakTypeTag" -> ((tparam: String) => tparam + " is accompanied by an WeakTypeTag, which is a runtime representation of its type that survives erasure")) + ("scala.reflect.base.TypeTags.TypeTag" -> ((tparam: String) => tparam + " is accompanied by a TypeTag, which is a runtime representation of its type that survives erasure")) /** diff --git a/src/compiler/scala/tools/nsc/doc/html/SyntaxHigh.scala b/src/compiler/scala/tools/nsc/doc/html/SyntaxHigh.scala index f1eab841f9..9b0765e394 100644 --- a/src/compiler/scala/tools/nsc/doc/html/SyntaxHigh.scala +++ b/src/compiler/scala/tools/nsc/doc/html/SyntaxHigh.scala @@ -40,7 +40,7 @@ private[html] object SyntaxHigh { /** Standard library classes/objects, sorted alphabetically */ val standards = Array ( - "AbsTypeTag", "Any", "AnyRef", "AnyVal", "App", "Application", "Array", + "WeakTypeTag", "Any", "AnyRef", "AnyVal", "App", "Application", "Array", "Boolean", "Byte", "Char", "Class", "ClassTag", "ClassManifest", "Console", "Double", "Enumeration", "Float", "Function", "Int", "List", "Long", "Manifest", "Map", diff --git a/src/compiler/scala/tools/nsc/interpreter/ReplVals.scala b/src/compiler/scala/tools/nsc/interpreter/ReplVals.scala index 5b8e4c3d92..cb10de7dca 100644 --- a/src/compiler/scala/tools/nsc/interpreter/ReplVals.scala +++ b/src/compiler/scala/tools/nsc/interpreter/ReplVals.scala @@ -65,7 +65,7 @@ object ReplVals { * I have this forwarder which widens the type and then cast the result back * to the dependent type. */ - def compilerTypeFromTag(t: BaseUniverse # AbsTypeTag[_]): Global#Type = + def compilerTypeFromTag(t: BaseUniverse # WeakTypeTag[_]): Global#Type = definitions.compilerTypeFromTag(t) class AppliedTypeFromTags(sym: Symbol) { diff --git a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala index 49ace019b9..bbeb549289 100644 --- a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala @@ -738,7 +738,7 @@ trait ContextErrors { ) val forgotten = ( if (sym.isTerm) "splice when splicing this variable into a reifee" - else "c.AbsTypeTag annotation for this type parameter" + else "c.WeakTypeTag annotation for this type parameter" ) macroExpansionError(expandee, template(sym.name.nameKind).format(sym.name + " " + sym.origin, forgotten)) } @@ -1234,7 +1234,7 @@ trait ContextErrors { message + suffix } - private def abbreviateCoreAliases(s: String): String = List("AbsTypeTag", "Expr").foldLeft(s)((res, x) => res.replace("c.universe." + x, "c." + x)) + private def abbreviateCoreAliases(s: String): String = List("WeakTypeTag", "Expr").foldLeft(s)((res, x) => res.replace("c.universe." + x, "c." + x)) private def showMeth(pss: List[List[Symbol]], restpe: Type, abbreviate: Boolean) = { var argsPart = (pss map (ps => ps map (_.defString) mkString ("(", ", ", ")"))).mkString @@ -1313,7 +1313,7 @@ trait ContextErrors { // aXXX (e.g. aparams) => characteristics of the macro impl ("a" stands for "actual") // rXXX (e.g. rparams) => characteristics of a reference macro impl signature synthesized from the macro def ("r" stands for "reference") - def MacroImplNonTagImplicitParameters(params: List[Symbol]) = compatibilityError("macro implementations cannot have implicit parameters other than AbsTypeTag evidences") + def MacroImplNonTagImplicitParameters(params: List[Symbol]) = compatibilityError("macro implementations cannot have implicit parameters other than WeakTypeTag evidences") def MacroImplParamssMismatchError() = compatibilityError("number of parameter sections differ") diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala index 6a91922b4c..08978ef4b5 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -1151,7 +1151,7 @@ trait Implicits { private def TagSymbols = TagMaterializers.keySet private val TagMaterializers = Map[Symbol, Symbol]( ClassTagClass -> MacroInternal_materializeClassTag, - AbsTypeTagClass -> MacroInternal_materializeAbsTypeTag, + WeakTypeTagClass -> MacroInternal_materializeWeakTypeTag, TypeTagClass -> MacroInternal_materializeTypeTag ) diff --git a/src/compiler/scala/tools/nsc/typechecker/Macros.scala b/src/compiler/scala/tools/nsc/typechecker/Macros.scala index 59935677a8..27a88a3683 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Macros.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Macros.scala @@ -26,7 +26,7 @@ import scala.reflect.macros.runtime.AbortMacroException * * Then fooBar needs to point to a static method of the following form: * - * def fooBar[T: c.AbsTypeTag] // type tag annotation is optional + * def fooBar[T: c.WeakTypeTag] // type tag annotation is optional * (c: scala.reflect.macros.Context) * (xs: c.Expr[List[T]]) * : c.Expr[T] = { @@ -84,7 +84,7 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces { val methName: String, // flattens the macro impl's parameter lists having symbols replaced with metadata // currently metadata is an index of the type parameter corresponding to that type tag (if applicable) - // f.ex. for: def impl[T: AbsTypeTag, U: AbsTypeTag, V](c: Context)(x: c.Expr[T]): (U, V) = ??? + // f.ex. for: def impl[T: WeakTypeTag, U: WeakTypeTag, V](c: Context)(x: c.Expr[T]): (U, V) = ??? // `signature` will be equal to List(-1, -1, 0, 1) val signature: List[Int], // type arguments part of a macro impl ref (the right-hand side of a macro definition) @@ -216,7 +216,7 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces { } /** Transforms parameters lists of a macro impl. - * The `transform` function is invoked only for AbsTypeTag evidence parameters. + * The `transform` function is invoked only for WeakTypeTag evidence parameters. * * The transformer takes two arguments: a value parameter from the parameter list * and a type parameter that is witnesses by the value parameter. @@ -232,7 +232,7 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces { if (paramss.isEmpty || paramss.last.isEmpty) return paramss // no implicit parameters in the signature => nothing to do if (paramss.head.isEmpty || !(paramss.head.head.tpe <:< MacroContextClass.tpe)) return paramss // no context parameter in the signature => nothing to do def transformTag(param: Symbol): Symbol = param.tpe.dealias match { - case TypeRef(SingleType(SingleType(NoPrefix, c), universe), AbsTypeTagClass, targ :: Nil) + case TypeRef(SingleType(SingleType(NoPrefix, c), universe), WeakTypeTagClass, targ :: Nil) if c == paramss.head.head && universe == MacroContextUniverse => transform(param, targ.typeSymbol) case _ => @@ -336,7 +336,7 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces { RepeatedParamClass.typeConstructor, List(implType(isType, sigma(origTpe.typeArgs.head)))) else { - val tsym = getMember(MacroContextClass, if (isType) tpnme.AbsTypeTag else tpnme.Expr) + val tsym = getMember(MacroContextClass, if (isType) tpnme.WeakTypeTag else tpnme.Expr) typeRef(singleType(NoPrefix, ctxParam), tsym, List(sigma(origTpe))) } val paramCache = collection.mutable.Map[Symbol, Symbol]() @@ -630,7 +630,7 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces { macroDef.owner) } else targ.tpe - context.AbsTypeTag(tpe) + context.WeakTypeTag(tpe) }) macroTraceVerbose("tags: ")(tags) @@ -872,13 +872,13 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces { new Transformer { override def transform(tree: Tree) = super.transform(tree match { // todo. expansion should work from the inside out - case wannabe if (delayed contains wannabe) && calculateUndetparams(wannabe).isEmpty => - val context = wannabe.attachments.get[MacroRuntimeAttachment].get.typerContext - delayed -= wannabe + case tree if (delayed contains tree) && calculateUndetparams(tree).isEmpty => + val context = tree.attachments.get[MacroRuntimeAttachment].get.typerContext + delayed -= tree context.implicitsEnabled = typer.context.implicitsEnabled context.enrichmentEnabled = typer.context.enrichmentEnabled context.macrosEnabled = typer.context.macrosEnabled - macroExpand(newTyper(context), wannabe, EXPRmode, WildcardType) + macroExpand(newTyper(context), tree, EXPRmode, WildcardType) case _ => tree }) diff --git a/src/compiler/scala/tools/nsc/typechecker/Tags.scala b/src/compiler/scala/tools/nsc/typechecker/Tags.scala index f82e009be8..167bf5c857 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Tags.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Tags.scala @@ -26,7 +26,7 @@ trait Tags { /** Finds in scope or materializes a ClassTag. * Should be used instead of ClassManifest every time compiler needs to persist an erasure. * - * Once upon a time, we had an `ErasureTag` which was to `ClassTag` the same that `AbsTypeTag` is for `TypeTag`. + * Once upon a time, we had an `ErasureTag` which was to `ClassTag` the same that `WeakTypeTag` is for `TypeTag`. * However we found out that we don't really need this concept, so it got removed. * * @param pos Position for error reporting. Please, provide meaningful value. @@ -43,7 +43,7 @@ trait Tags { resolveTag(pos, taggedTp, allowMaterialization) } - /** Finds in scope or materializes an AbsTypeTag (if `concrete` is false) or a TypeTag (if `concrete` is true). + /** Finds in scope or materializes an WeakTypeTag (if `concrete` is false) or a TypeTag (if `concrete` is true). * * @param pos Position for error reporting. Please, provide meaningful value. * @param pre Prefix that represents a universe this type tag will be bound to. @@ -60,7 +60,7 @@ trait Tags { * EmptyTree if `allowMaterialization` is false, and there is no array tag in scope. */ def resolveTypeTag(pos: Position, pre: Type, tp: Type, concrete: Boolean, allowMaterialization: Boolean = true): Tree = { - val tagSym = if (concrete) TypeTagClass else AbsTypeTagClass + val tagSym = if (concrete) TypeTagClass else WeakTypeTagClass val tagTp = if (pre == NoType) TypeRef(BaseUniverseClass.toTypeConstructor, tagSym, List(tp)) else singleType(pre, pre member tagSym.name) val taggedTp = appliedType(tagTp, List(tp)) resolveTag(pos, taggedTp, allowMaterialization) diff --git a/src/compiler/scala/tools/reflect/FastTrack.scala b/src/compiler/scala/tools/reflect/FastTrack.scala index 07c972899e..d6bed0c6d1 100644 --- a/src/compiler/scala/tools/reflect/FastTrack.scala +++ b/src/compiler/scala/tools/reflect/FastTrack.scala @@ -23,7 +23,7 @@ trait FastTrack { def validate(c: MacroContext): Boolean = expander.isDefinedAt((c, c.expandee)) def run(c: MacroContext): Any = { val result = expander((c, c.expandee)) - c.Expr[Nothing](result)(c.AbsTypeTag.Nothing) + c.Expr[Nothing](result)(c.WeakTypeTag.Nothing) } } @@ -31,7 +31,7 @@ trait FastTrack { var registry = Map[Symbol, FastTrackEntry]() implicit class BindTo(sym: Symbol) { def bindTo(expander: FastTrackExpander): Unit = if (sym != NoSymbol) registry += sym -> FastTrackEntry(sym, expander) } MacroInternal_materializeClassTag bindTo { case (c, Apply(TypeApply(_, List(tt)), List(u))) => c.materializeClassTag(u, tt.tpe) } - MacroInternal_materializeAbsTypeTag bindTo { case (c, Apply(TypeApply(_, List(tt)), List(u))) => c.materializeTypeTag(u, EmptyTree, tt.tpe, concrete = false) } + MacroInternal_materializeWeakTypeTag bindTo { case (c, Apply(TypeApply(_, List(tt)), List(u))) => c.materializeTypeTag(u, EmptyTree, tt.tpe, concrete = false) } MacroInternal_materializeTypeTag bindTo { case (c, Apply(TypeApply(_, List(tt)), List(u))) => c.materializeTypeTag(u, EmptyTree, tt.tpe, concrete = true) } BaseUniverseReify bindTo { case (c, Apply(TypeApply(_, List(tt)), List(expr))) => c.materializeExpr(c.prefix.tree, EmptyTree, expr) } ReflectRuntimeCurrentMirror bindTo { case (c, _) => scala.reflect.runtime.Macros.currentMirror(c).tree } diff --git a/src/library/scala/reflect/base/Base.scala b/src/library/scala/reflect/base/Base.scala index 28ebdf4377..6f90d598f9 100644 --- a/src/library/scala/reflect/base/Base.scala +++ b/src/library/scala/reflect/base/Base.scala @@ -36,10 +36,10 @@ class Base extends Universe { self => def newClassSymbol(name: TypeName, pos: Position = NoPosition, flags: FlagSet = NoFlags): ClassSymbol = new ClassSymbol(this, name, flags) - def newFreeTermSymbol(name: TermName, info: Type, value: => Any, flags: FlagSet = NoFlags, origin: String = null) = + def newFreeTermSymbol(name: TermName, value: => Any, flags: FlagSet = NoFlags, origin: String = null) = new FreeTermSymbol(this, name, flags) - def newFreeTypeSymbol(name: TypeName, info: Type, value: => Any, flags: FlagSet = NoFlags, origin: String = null) = + def newFreeTypeSymbol(name: TypeName, flags: FlagSet = NoFlags, origin: String = null) = new FreeTypeSymbol(this, name, flags) private def kindString: String = @@ -311,13 +311,10 @@ class Base extends Universe { self => else new TypeSymbol(owner, name.toTypeName, flags) else new TermSymbol(owner, name.toTermName, flags) - def newFreeTerm(name: String, info: Type, value: => Any, flags: Long = 0L, origin: String = null): FreeTermSymbol = + def newFreeTerm(name: String, value: => Any, flags: Long = 0L, origin: String = null): FreeTermSymbol = new FreeTermSymbol(rootMirror.RootClass, newTermName(name), flags) - def newFreeType(name: String, info: Type, value: => Any, flags: Long = 0L, origin: String = null): FreeTypeSymbol = - new FreeTypeSymbol(rootMirror.RootClass, newTypeName(name), flags) - - def newFreeExistential(name: String, info: Type, value: => Any, flags: Long = 0L, origin: String = null): FreeTypeSymbol = + def newFreeType(name: String, flags: Long = 0L, origin: String = null): FreeTypeSymbol = new FreeTypeSymbol(rootMirror.RootClass, newTypeName(name), flags) def setTypeSignature[S <: Symbol](sym: S, tpe: Type): S = sym diff --git a/src/library/scala/reflect/base/BuildUtils.scala b/src/library/scala/reflect/base/BuildUtils.scala index 98f32231ad..c4231dd515 100644 --- a/src/library/scala/reflect/base/BuildUtils.scala +++ b/src/library/scala/reflect/base/BuildUtils.scala @@ -29,36 +29,18 @@ trait BuildUtils { self: Universe => /** Create a fresh free term symbol. * @param name the name of the free variable - * @param info the type signature of the free variable * @param value the value of the free variable at runtime * @param flags (optional) flags of the free variable * @param origin debug information that tells where this symbol comes from */ - def newFreeTerm(name: String, info: Type, value: => Any, flags: FlagSet = NoFlags, origin: String = null): FreeTermSymbol + def newFreeTerm(name: String, value: => Any, flags: FlagSet = NoFlags, origin: String = null): FreeTermSymbol - /** Create a fresh free non-existential type symbol. + /** Create a fresh free type symbol. * @param name the name of the free variable - * @param info the type signature of the free variable - * @param value a type tag that captures the value of the free variable - * is completely phantom, since the captured type cannot be propagated to the runtime - * if it could be, we wouldn't be creating a free type to begin with - * the only usage for it is preserving the captured symbol for compile-time analysis * @param flags (optional) flags of the free variable * @param origin debug information that tells where this symbol comes from */ - def newFreeType(name: String, info: Type, value: => Any, flags: FlagSet = NoFlags, origin: String = null): FreeTypeSymbol - - /** Create a fresh free existential type symbol. - * @param name the name of the free variable - * @param info the type signature of the free variable - * @param value a type tag that captures the value of the free variable - * is completely phantom, since the captured type cannot be propagated to the runtime - * if it could be, we wouldn't be creating a free type to begin with - * the only usage for it is preserving the captured symbol for compile-time analysis - * @param flags (optional) flags of the free variable - * @param origin (optional) debug information that tells where this symbol comes from - */ - def newFreeExistential(name: String, info: Type, value: => Any, flags: FlagSet = NoFlags, origin: String = null): FreeTypeSymbol + def newFreeType(name: String, flags: FlagSet = NoFlags, origin: String = null): FreeTypeSymbol /** Set symbol's type signature to given type. * @return the symbol itself diff --git a/src/library/scala/reflect/base/Exprs.scala b/src/library/scala/reflect/base/Exprs.scala index 10c222722a..45598c03e2 100644 --- a/src/library/scala/reflect/base/Exprs.scala +++ b/src/library/scala/reflect/base/Exprs.scala @@ -28,19 +28,19 @@ trait Exprs { self: Universe => } object Expr { - def apply[T: AbsTypeTag](mirror: MirrorOf[self.type], treec: TreeCreator): Expr[T] = new ExprImpl[T](mirror.asInstanceOf[Mirror], treec) + def apply[T: WeakTypeTag](mirror: MirrorOf[self.type], treec: TreeCreator): Expr[T] = new ExprImpl[T](mirror.asInstanceOf[Mirror], treec) def unapply[T](expr: Expr[T]): Option[Tree] = Some(expr.tree) } - private class ExprImpl[+T: AbsTypeTag](val mirror: Mirror, val treec: TreeCreator) extends Expr[T] { + private class ExprImpl[+T: WeakTypeTag](val mirror: Mirror, val treec: TreeCreator) extends Expr[T] { def in[U <: Universe with Singleton](otherMirror: MirrorOf[U]): U # Expr[T] = { val otherMirror1 = otherMirror.asInstanceOf[MirrorOf[otherMirror.universe.type]] - val tag1 = (implicitly[AbsTypeTag[T]] in otherMirror).asInstanceOf[otherMirror.universe.AbsTypeTag[T]] + val tag1 = (implicitly[WeakTypeTag[T]] in otherMirror).asInstanceOf[otherMirror.universe.WeakTypeTag[T]] otherMirror.universe.Expr[T](otherMirror1, treec)(tag1) } lazy val tree: Tree = treec(mirror) - lazy val staticType: Type = implicitly[AbsTypeTag[T]].tpe + lazy val staticType: Type = implicitly[WeakTypeTag[T]].tpe def actualType: Type = treeType(tree) def splice: T = throw new UnsupportedOperationException(""" @@ -54,11 +54,11 @@ trait Exprs { self: Universe => |if you want to get a value of the underlying expression, add scala-compiler.jar to the classpath, |import `scala.tools.reflect.Eval` and call `<your expr>.eval` instead.""".trim.stripMargin) - private def writeReplace(): AnyRef = new SerializedExpr(treec, implicitly[AbsTypeTag[T]].in(scala.reflect.basis.rootMirror)) + private def writeReplace(): AnyRef = new SerializedExpr(treec, implicitly[WeakTypeTag[T]].in(scala.reflect.basis.rootMirror)) } } -private[scala] class SerializedExpr(var treec: TreeCreator, var tag: scala.reflect.basis.AbsTypeTag[_]) extends Serializable { +private[scala] class SerializedExpr(var treec: TreeCreator, var tag: scala.reflect.basis.WeakTypeTag[_]) extends Serializable { private def writeObject(out: java.io.ObjectOutputStream): Unit = { out.writeObject(treec) out.writeObject(tag) @@ -66,7 +66,7 @@ private[scala] class SerializedExpr(var treec: TreeCreator, var tag: scala.refle private def readObject(in: java.io.ObjectInputStream): Unit = { treec = in.readObject().asInstanceOf[TreeCreator] - tag = in.readObject().asInstanceOf[scala.reflect.basis.AbsTypeTag[_]] + tag = in.readObject().asInstanceOf[scala.reflect.basis.WeakTypeTag[_]] } private def readResolve(): AnyRef = { diff --git a/src/library/scala/reflect/base/TypeTags.scala b/src/library/scala/reflect/base/TypeTags.scala index b7e0c37a4b..37e0c4f02f 100644 --- a/src/library/scala/reflect/base/TypeTags.scala +++ b/src/library/scala/reflect/base/TypeTags.scala @@ -17,15 +17,15 @@ import language.implicitConversions * === Overview === * * Type tags are organized in a hierarchy of three classes: - * [[scala.reflect.ClassTag]], [[scala.reflect.base.Universe#TypeTag]] and [[scala.reflect.base.Universe#AbsTypeTag]]. + * [[scala.reflect.ClassTag]], [[scala.reflect.base.Universe#TypeTag]] and [[scala.reflect.base.Universe#WeakTypeTag]]. * * A [[scala.reflect.ClassTag]] carries a runtime class that corresponds to the source type T. * As of such, it possesses the knowledge about how to build single- and multi-dimensional arrays of elements of that type. * It guarantees that the source type T did not to contain any references to type parameters or abstract types. * [[scala.reflect.ClassTag]] corresponds to a previous notion of [[scala.reflect.ClassManifest]]. * - * A [[scala.reflect.base.Universe#AbsTypeTag]] value wraps a full Scala type in its tpe field. - * A [[scala.reflect.base.Universe#TypeTag]] value is an [[scala.reflect.base.Universe#AbsTypeTag]] + * A [[scala.reflect.base.Universe#WeakTypeTag]] value wraps a full Scala type in its tpe field. + * A [[scala.reflect.base.Universe#TypeTag]] value is an [[scala.reflect.base.Universe#WeakTypeTag]] * that is guaranteed not to contain any references to type parameters or abstract types. * * [Eugene++] also mention sensitivity to prefixes, i.e. that rb.TypeTag is different from ru.TypeTag @@ -40,36 +40,36 @@ import language.implicitConversions * import reflect.mirror._ * def f[T: TypeTag, U] = { * type L = T => U - * implicitly[AbsTypeTag[L]] + * implicitly[WeakTypeTag[L]] * } * * Then a call of f[String, Int] will yield a result of the form * - * AbsTypeTag(<[ String => U ]>). + * WeakTypeTag(<[ String => U ]>). * * Note that T has been replaced by String, because it comes with a TypeTag in f, whereas U was left as a type parameter. * - * === AbsTypeTag vs TypeTag === + * === WeakTypeTag vs TypeTag === * - * Be careful with AbsTypeTag, because it will reify types even if these types are abstract. + * Be careful with WeakTypeTag, because it will reify types even if these types are abstract. * This makes it easy to forget to tag one of the methods in the call chain and discover it much later in the runtime * by getting cryptic errors far away from their source. For example, consider the following snippet: * - * def bind[T: AbsTypeTag](name: String, value: T): IR.Result = bind((name, value)) - * def bind(p: NamedParam): IR.Result = bind(p.name, p.tpe, p.value) + * def bind[T: WeakTypeTag](name: String, value: T): IR.Result = bind((name, value)) + * def bind(p: NamedParam): IR.Result = bind(p.name, p.tpe, p.value) * object NamedParam { - * implicit def namedValue[T: AbsTypeTag](name: String, x: T): NamedParam = apply(name, x) - * def apply[T: AbsTypeTag](name: String, x: T): NamedParam = new Typed[T](name, x) + * implicit def namedValue[T: WeakTypeTag](name: String, x: T): NamedParam = apply(name, x) + * def apply[T: WeakTypeTag](name: String, x: T): NamedParam = new Typed[T](name, x) * } * * This fragment of Scala REPL implementation defines a `bind` function that carries a named value along with its type - * into the heart of the REPL. Using a [[scala.reflect.base.Universe#AbsTypeTag]] here is reasonable, because it is desirable + * into the heart of the REPL. Using a [[scala.reflect.base.Universe#WeakTypeTag]] here is reasonable, because it is desirable * to work with all types, even if they are type parameters or abstract type members. * - * However if any of the three `AbsTypeTag` context bounds is omitted, the resulting code will be incorrect, - * because the missing `AbsTypeTag` will be transparently generated by the compiler, carrying meaningless information. + * However if any of the three `WeakTypeTag` context bounds is omitted, the resulting code will be incorrect, + * because the missing `WeakTypeTag` will be transparently generated by the compiler, carrying meaningless information. * Most likely, this problem will manifest itself elsewhere, making debugging complicated. - * If `AbsTypeTag` context bounds were replaced with `TypeTag`, then such errors would be reported statically. + * If `WeakTypeTag` context bounds were replaced with `TypeTag`, then such errors would be reported statically. * But in that case we wouldn't be able to use `bind` in arbitrary contexts. * * === Backward compatibility === @@ -104,71 +104,71 @@ trait TypeTags { self: Universe => import definitions._ /** - * If an implicit value of type u.AbsTypeTag[T] is required, the compiler will make one up on demand. + * If an implicit value of type u.WeakTypeTag[T] is required, the compiler will make one up on demand. * The implicitly created value contains in its tpe field a value of type u.Type that is a reflective representation of T. * In that value, any occurrences of type parameters or abstract types U * which come themselves with a TypeTag are represented by the type referenced by that TypeTag. * * @see [[scala.reflect.base.TypeTags]] */ - @annotation.implicitNotFound(msg = "No AbsTypeTag available for ${T}") - trait AbsTypeTag[T] extends Equals with Serializable { + @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: MirrorOf[U]): U # AbsTypeTag[T] + def in[U <: Universe with Singleton](otherMirror: MirrorOf[U]): U # WeakTypeTag[T] def tpe: Type /** case class accessories */ - override def canEqual(x: Any) = x.isInstanceOf[AbsTypeTag[_]] - override def equals(x: Any) = x.isInstanceOf[AbsTypeTag[_]] && this.mirror == x.asInstanceOf[AbsTypeTag[_]].mirror && this.tpe == x.asInstanceOf[AbsTypeTag[_]].tpe + override def canEqual(x: Any) = x.isInstanceOf[WeakTypeTag[_]] + override def equals(x: Any) = x.isInstanceOf[WeakTypeTag[_]] && this.mirror == x.asInstanceOf[WeakTypeTag[_]].mirror && this.tpe == x.asInstanceOf[WeakTypeTag[_]].tpe override def hashCode = mirror.hashCode * 31 + tpe.hashCode - override def toString = "AbsTypeTag[" + tpe + "]" + override def toString = "WeakTypeTag[" + tpe + "]" } - object AbsTypeTag { - val Byte : AbsTypeTag[scala.Byte] = TypeTag.Byte - val Short : AbsTypeTag[scala.Short] = TypeTag.Short - val Char : AbsTypeTag[scala.Char] = TypeTag.Char - val Int : AbsTypeTag[scala.Int] = TypeTag.Int - val Long : AbsTypeTag[scala.Long] = TypeTag.Long - val Float : AbsTypeTag[scala.Float] = TypeTag.Float - val Double : AbsTypeTag[scala.Double] = TypeTag.Double - val Boolean : AbsTypeTag[scala.Boolean] = TypeTag.Boolean - val Unit : AbsTypeTag[scala.Unit] = TypeTag.Unit - val Any : AbsTypeTag[scala.Any] = TypeTag.Any - val AnyVal : AbsTypeTag[scala.AnyVal] = TypeTag.AnyVal - val AnyRef : AbsTypeTag[scala.AnyRef] = TypeTag.AnyRef - val Object : AbsTypeTag[java.lang.Object] = TypeTag.Object - val Nothing : AbsTypeTag[scala.Nothing] = TypeTag.Nothing - val Null : AbsTypeTag[scala.Null] = TypeTag.Null + object WeakTypeTag { + val Byte : WeakTypeTag[scala.Byte] = TypeTag.Byte + val Short : WeakTypeTag[scala.Short] = TypeTag.Short + val Char : WeakTypeTag[scala.Char] = TypeTag.Char + val Int : WeakTypeTag[scala.Int] = TypeTag.Int + val Long : WeakTypeTag[scala.Long] = TypeTag.Long + val Float : WeakTypeTag[scala.Float] = TypeTag.Float + val Double : WeakTypeTag[scala.Double] = TypeTag.Double + val Boolean : WeakTypeTag[scala.Boolean] = TypeTag.Boolean + val Unit : WeakTypeTag[scala.Unit] = TypeTag.Unit + val Any : WeakTypeTag[scala.Any] = TypeTag.Any + val AnyVal : WeakTypeTag[scala.AnyVal] = TypeTag.AnyVal + val AnyRef : WeakTypeTag[scala.AnyRef] = TypeTag.AnyRef + val Object : WeakTypeTag[java.lang.Object] = TypeTag.Object + val Nothing : WeakTypeTag[scala.Nothing] = TypeTag.Nothing + val Null : WeakTypeTag[scala.Null] = TypeTag.Null - def apply[T](mirror1: MirrorOf[self.type], tpec1: TypeCreator): AbsTypeTag[T] = + def apply[T](mirror1: MirrorOf[self.type], tpec1: TypeCreator): WeakTypeTag[T] = tpec1(mirror1) match { - case ByteTpe => AbsTypeTag.Byte.asInstanceOf[AbsTypeTag[T]] - case ShortTpe => AbsTypeTag.Short.asInstanceOf[AbsTypeTag[T]] - case CharTpe => AbsTypeTag.Char.asInstanceOf[AbsTypeTag[T]] - case IntTpe => AbsTypeTag.Int.asInstanceOf[AbsTypeTag[T]] - case LongTpe => AbsTypeTag.Long.asInstanceOf[AbsTypeTag[T]] - case FloatTpe => AbsTypeTag.Float.asInstanceOf[AbsTypeTag[T]] - case DoubleTpe => AbsTypeTag.Double.asInstanceOf[AbsTypeTag[T]] - case BooleanTpe => AbsTypeTag.Boolean.asInstanceOf[AbsTypeTag[T]] - case UnitTpe => AbsTypeTag.Unit.asInstanceOf[AbsTypeTag[T]] - case AnyTpe => AbsTypeTag.Any.asInstanceOf[AbsTypeTag[T]] - case AnyValTpe => AbsTypeTag.AnyVal.asInstanceOf[AbsTypeTag[T]] - case AnyRefTpe => AbsTypeTag.AnyRef.asInstanceOf[AbsTypeTag[T]] - case ObjectTpe => AbsTypeTag.Object.asInstanceOf[AbsTypeTag[T]] - case NothingTpe => AbsTypeTag.Nothing.asInstanceOf[AbsTypeTag[T]] - case NullTpe => AbsTypeTag.Null.asInstanceOf[AbsTypeTag[T]] - case _ => new AbsTypeTagImpl[T](mirror1.asInstanceOf[Mirror], tpec1) + case ByteTpe => WeakTypeTag.Byte.asInstanceOf[WeakTypeTag[T]] + case ShortTpe => WeakTypeTag.Short.asInstanceOf[WeakTypeTag[T]] + case CharTpe => WeakTypeTag.Char.asInstanceOf[WeakTypeTag[T]] + case IntTpe => WeakTypeTag.Int.asInstanceOf[WeakTypeTag[T]] + case LongTpe => WeakTypeTag.Long.asInstanceOf[WeakTypeTag[T]] + case FloatTpe => WeakTypeTag.Float.asInstanceOf[WeakTypeTag[T]] + case DoubleTpe => WeakTypeTag.Double.asInstanceOf[WeakTypeTag[T]] + case BooleanTpe => WeakTypeTag.Boolean.asInstanceOf[WeakTypeTag[T]] + case UnitTpe => WeakTypeTag.Unit.asInstanceOf[WeakTypeTag[T]] + case AnyTpe => WeakTypeTag.Any.asInstanceOf[WeakTypeTag[T]] + case AnyValTpe => WeakTypeTag.AnyVal.asInstanceOf[WeakTypeTag[T]] + case AnyRefTpe => WeakTypeTag.AnyRef.asInstanceOf[WeakTypeTag[T]] + case ObjectTpe => WeakTypeTag.Object.asInstanceOf[WeakTypeTag[T]] + case NothingTpe => WeakTypeTag.Nothing.asInstanceOf[WeakTypeTag[T]] + case NullTpe => WeakTypeTag.Null.asInstanceOf[WeakTypeTag[T]] + case _ => new WeakTypeTagImpl[T](mirror1.asInstanceOf[Mirror], tpec1) } - def unapply[T](ttag: AbsTypeTag[T]): Option[Type] = Some(ttag.tpe) + def unapply[T](ttag: WeakTypeTag[T]): Option[Type] = Some(ttag.tpe) } - private class AbsTypeTagImpl[T](val mirror: Mirror, val tpec: TypeCreator) extends AbsTypeTag[T] { + private class WeakTypeTagImpl[T](val mirror: Mirror, val tpec: TypeCreator) extends WeakTypeTag[T] { lazy val tpe: Type = tpec(mirror) - def in[U <: Universe with Singleton](otherMirror: MirrorOf[U]): U # AbsTypeTag[T] = { + def in[U <: Universe with Singleton](otherMirror: MirrorOf[U]): U # WeakTypeTag[T] = { val otherMirror1 = otherMirror.asInstanceOf[MirrorOf[otherMirror.universe.type]] - otherMirror.universe.AbsTypeTag[T](otherMirror1, tpec) + otherMirror.universe.WeakTypeTag[T](otherMirror1, tpec) } private def writeReplace(): AnyRef = new SerializedTypeTag(tpec, concrete = false) } @@ -180,7 +180,7 @@ trait TypeTags { self: Universe => * @see [[scala.reflect.base.TypeTags]] */ @annotation.implicitNotFound(msg = "No TypeTag available for ${T}") - trait TypeTag[T] extends AbsTypeTag[T] with Equals with Serializable { + trait TypeTag[T] extends WeakTypeTag[T] with Equals with Serializable { override def in[U <: Universe with Singleton](otherMirror: MirrorOf[U]): U # TypeTag[T] /** case class accessories */ @@ -230,7 +230,7 @@ trait TypeTags { self: Universe => def unapply[T](ttag: TypeTag[T]): Option[Type] = Some(ttag.tpe) } - private class TypeTagImpl[T](mirror: Mirror, tpec: TypeCreator) extends AbsTypeTagImpl[T](mirror, tpec) with TypeTag[T] { + private class TypeTagImpl[T](mirror: Mirror, tpec: TypeCreator) extends WeakTypeTagImpl[T](mirror, tpec) with TypeTag[T] { override def in[U <: Universe with Singleton](otherMirror: MirrorOf[U]): U # TypeTag[T] = { val otherMirror1 = otherMirror.asInstanceOf[MirrorOf[otherMirror.universe.type]] otherMirror.universe.TypeTag[T](otherMirror1, tpec) @@ -250,11 +250,11 @@ trait TypeTags { self: Universe => } // incantations - def absTypeTag[T](implicit attag: AbsTypeTag[T]) = attag + def weakTypeTag[T](implicit attag: WeakTypeTag[T]) = attag def typeTag[T](implicit ttag: TypeTag[T]) = ttag // big thanks to Viktor Klang for this brilliant idea! - def absTypeOf[T](implicit attag: AbsTypeTag[T]): Type = attag.tpe + def weakTypeOf[T](implicit attag: WeakTypeTag[T]): Type = attag.tpe def typeOf[T](implicit ttag: TypeTag[T]): Type = ttag.tpe } @@ -272,6 +272,6 @@ private[scala] class SerializedTypeTag(var tpec: TypeCreator, var concrete: Bool private def readResolve(): AnyRef = { import scala.reflect.basis._ if (concrete) TypeTag(rootMirror, tpec) - else AbsTypeTag(rootMirror, tpec) + else WeakTypeTag(rootMirror, tpec) } }
\ No newline at end of file diff --git a/src/library/scala/reflect/base/Universe.scala b/src/library/scala/reflect/base/Universe.scala index f098876c18..18599ad092 100644 --- a/src/library/scala/reflect/base/Universe.scala +++ b/src/library/scala/reflect/base/Universe.scala @@ -46,7 +46,7 @@ abstract class Universe extends Symbols * def macroImpl[T](c: Context) = { * ... * // T here is just a type parameter, so the tree produced by reify won't be of much use in a macro expansion - * // however, if T were annotated with c.AbsTypeTag (which would declare an implicit parameter for macroImpl) + * // however, if T were annotated with c.WeakTypeTag (which would declare an implicit parameter for macroImpl) * // then reification would substitute T with the TypeTree that was used in a TypeApply of this particular macro invocation * val factory = c.reify{ new Queryable[T] } * ... diff --git a/src/library/scala/reflect/macros/internal/package.scala b/src/library/scala/reflect/macros/internal/package.scala index 0a0e6c5b51..aca2b765f1 100644 --- a/src/library/scala/reflect/macros/internal/package.scala +++ b/src/library/scala/reflect/macros/internal/package.scala @@ -8,6 +8,6 @@ import scala.reflect.ClassTag // todo. once we have implicit macros for tag generation, we can remove these anchors package object internal { private[scala] def materializeClassTag[T](u: BaseUniverse): ClassTag[T] = ??? // macro - private[scala] def materializeAbsTypeTag[T](u: BaseUniverse): u.AbsTypeTag[T] = ??? // macro + private[scala] def materializeWeakTypeTag[T](u: BaseUniverse): u.WeakTypeTag[T] = ??? // macro private[scala] def materializeTypeTag[T](u: BaseUniverse): u.TypeTag[T] = ??? // macro } diff --git a/src/reflect/scala/reflect/internal/BuildUtils.scala b/src/reflect/scala/reflect/internal/BuildUtils.scala index 74b9442076..f7371f4180 100644 --- a/src/reflect/scala/reflect/internal/BuildUtils.scala +++ b/src/reflect/scala/reflect/internal/BuildUtils.scala @@ -30,14 +30,11 @@ trait BuildUtils extends base.BuildUtils { self: SymbolTable => else MissingRequirementError.notFound("overloaded method %s #%d in %s".format(name, index, owner.fullName)) } - def newFreeTerm(name: String, info: Type, value: => Any, flags: Long = 0L, origin: String = null): FreeTermSymbol = - newFreeTermSymbol(newTermName(name), info, value, flags, origin) + def newFreeTerm(name: String, value: => Any, flags: Long = 0L, origin: String = null): FreeTermSymbol = + newFreeTermSymbol(newTermName(name), value, flags, origin) - def newFreeType(name: String, info: Type, value: => Any, flags: Long = 0L, origin: String = null): FreeTypeSymbol = - newFreeTypeSymbol(newTypeName(name), info, value, (if (flags == 0L) PARAM else flags) | DEFERRED, origin) - - def newFreeExistential(name: String, info: Type, value: => Any, flags: Long = 0L, origin: String = null): FreeTypeSymbol = - newFreeTypeSymbol(newTypeName(name), info, value, (if (flags == 0L) EXISTENTIAL else flags) | DEFERRED, origin) + def newFreeType(name: String, flags: Long = 0L, origin: String = null): FreeTypeSymbol = + newFreeTypeSymbol(newTypeName(name), flags, origin) def newNestedSymbol(owner: Symbol, name: Name, pos: Position, flags: Long, isClass: Boolean): Symbol = owner.newNestedSymbol(name, pos, flags, isClass) diff --git a/src/reflect/scala/reflect/internal/Definitions.scala b/src/reflect/scala/reflect/internal/Definitions.scala index 15b74058b7..6d9f68a8a5 100644 --- a/src/reflect/scala/reflect/internal/Definitions.scala +++ b/src/reflect/scala/reflect/internal/Definitions.scala @@ -505,8 +505,8 @@ trait Definitions extends api.StandardDefinitions { lazy val ClassTagModule = requiredModule[scala.reflect.ClassTag[_]] lazy val ClassTagClass = requiredClass[scala.reflect.ClassTag[_]] lazy val TypeTagsClass = requiredClass[scala.reflect.base.TypeTags] - lazy val AbsTypeTagClass = getMemberClass(TypeTagsClass, tpnme.AbsTypeTag) - lazy val AbsTypeTagModule = getMemberModule(TypeTagsClass, nme.AbsTypeTag) + lazy val WeakTypeTagClass = getMemberClass(TypeTagsClass, tpnme.WeakTypeTag) + lazy val WeakTypeTagModule = getMemberModule(TypeTagsClass, nme.WeakTypeTag) lazy val TypeTagClass = getMemberClass(TypeTagsClass, tpnme.TypeTag) lazy val TypeTagModule = getMemberModule(TypeTagsClass, nme.TypeTag) @@ -527,7 +527,7 @@ trait Definitions extends api.StandardDefinitions { lazy val MacroImplAnnotation = requiredClass[scala.reflect.macros.internal.macroImpl] lazy val MacroInternalPackage = getPackageObject("scala.reflect.macros.internal") def MacroInternal_materializeClassTag = getMemberMethod(MacroInternalPackage, nme.materializeClassTag) - def MacroInternal_materializeAbsTypeTag = getMemberMethod(MacroInternalPackage, nme.materializeAbsTypeTag) + def MacroInternal_materializeWeakTypeTag = getMemberMethod(MacroInternalPackage, nme.materializeWeakTypeTag) def MacroInternal_materializeTypeTag = getMemberMethod(MacroInternalPackage, nme.materializeTypeTag) lazy val StringContextClass = requiredClass[scala.StringContext] @@ -542,8 +542,8 @@ trait Definitions extends api.StandardDefinitions { lazy val NoneModule: ModuleSymbol = requiredModule[scala.None.type] lazy val SomeModule: ModuleSymbol = requiredModule[scala.Some.type] - def compilerTypeFromTag(tt: BaseUniverse # AbsTypeTag[_]): Type = tt.in(rootMirror).tpe - def compilerSymbolFromTag(tt: BaseUniverse # AbsTypeTag[_]): Symbol = tt.in(rootMirror).tpe.typeSymbol + def compilerTypeFromTag(tt: BaseUniverse # WeakTypeTag[_]): Type = tt.in(rootMirror).tpe + def compilerSymbolFromTag(tt: BaseUniverse # WeakTypeTag[_]): Symbol = tt.in(rootMirror).tpe.typeSymbol // The given symbol represents either String.+ or StringAdd.+ def isStringAddition(sym: Symbol) = sym == String_+ || sym == StringAdd_+ diff --git a/src/reflect/scala/reflect/internal/Importers.scala b/src/reflect/scala/reflect/internal/Importers.scala index 4b3eb0cdc4..87058df732 100644 --- a/src/reflect/scala/reflect/internal/Importers.scala +++ b/src/reflect/scala/reflect/internal/Importers.scala @@ -72,9 +72,9 @@ trait Importers extends api.Importers { self: SymbolTable => case x: from.ModuleSymbol => linkReferenced(myowner.newModuleSymbol(myname, mypos, myflags), x, importSymbol) case x: from.FreeTermSymbol => - newFreeTermSymbol(importName(x.name).toTermName, importType(x.info), x.value, x.flags, x.origin) + newFreeTermSymbol(importName(x.name).toTermName, x.value, x.flags, x.origin) setInfo importType(x.info) case x: from.FreeTypeSymbol => - newFreeTypeSymbol(importName(x.name).toTypeName, importType(x.info), x.value, x.flags, x.origin) + newFreeTypeSymbol(importName(x.name).toTypeName, x.flags, x.origin) case x: from.TermSymbol => linkReferenced(myowner.newValue(myname, mypos, myflags), x, importSymbol) case x: from.TypeSkolem => diff --git a/src/reflect/scala/reflect/internal/StdNames.scala b/src/reflect/scala/reflect/internal/StdNames.scala index f63e2602b1..92adc85e25 100644 --- a/src/reflect/scala/reflect/internal/StdNames.scala +++ b/src/reflect/scala/reflect/internal/StdNames.scala @@ -131,7 +131,7 @@ trait StdNames { final val Seq: NameType = "Seq" final val Symbol: NameType = "Symbol" final val ClassTag: NameType = "ClassTag" - final val AbsTypeTag: NameType = "AbsTypeTag" + final val WeakTypeTag: NameType = "WeakTypeTag" final val TypeTag : NameType = "TypeTag" final val Expr: NameType = "Expr" final val String: NameType = "String" @@ -704,14 +704,13 @@ trait StdNames { val manifestToTypeTag: NameType = "manifestToTypeTag" val map: NameType = "map" val materializeClassTag: NameType = "materializeClassTag" - val materializeAbsTypeTag: NameType = "materializeAbsTypeTag" + val materializeWeakTypeTag: NameType = "materializeWeakTypeTag" val materializeTypeTag: NameType = "materializeTypeTag" val mirror : NameType = "mirror" val moduleClass : NameType = "moduleClass" val name: NameType = "name" val ne: NameType = "ne" val newArray: NameType = "newArray" - val newFreeExistential: NameType = "newFreeExistential" val newFreeTerm: NameType = "newFreeTerm" val newFreeType: NameType = "newFreeType" val newNestedSymbol: NameType = "newNestedSymbol" diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala index b1e81de037..430cf58a54 100644 --- a/src/reflect/scala/reflect/internal/Symbols.scala +++ b/src/reflect/scala/reflect/internal/Symbols.scala @@ -48,13 +48,13 @@ trait Symbols extends api.Symbols { self: SymbolTable => /** Create a new free term. Its owner is NoSymbol. */ - def newFreeTermSymbol(name: TermName, info: Type, value: => Any, flags: Long = 0L, origin: String): FreeTermSymbol = - new FreeTermSymbol(name, value, origin) initFlags flags setInfo info + def newFreeTermSymbol(name: TermName, value: => Any, flags: Long = 0L, origin: String): FreeTermSymbol = + new FreeTermSymbol(name, value, origin) initFlags flags /** Create a new free type. Its owner is NoSymbol. */ - def newFreeTypeSymbol(name: TypeName, info: Type, value: => Any, flags: Long = 0L, origin: String): FreeTypeSymbol = - new FreeTypeSymbol(name, value, origin) initFlags flags setInfo info + def newFreeTypeSymbol(name: TypeName, flags: Long = 0L, origin: String): FreeTypeSymbol = + new FreeTypeSymbol(name, origin) initFlags flags /** The original owner of a class. Used by the backend to generate * EnclosingMethod attributes. @@ -3080,9 +3080,7 @@ trait Symbols extends api.Symbols { self: SymbolTable => } implicit val FreeTermSymbolTag = ClassTag[FreeTermSymbol](classOf[FreeTermSymbol]) - class FreeTypeSymbol(name0: TypeName, value0: => Any, val origin: String) extends TypeSkolem(NoSymbol, NoPosition, name0, NoSymbol) with FreeSymbol with FreeTypeSymbolApi { - def value = value0 - } + class FreeTypeSymbol(name0: TypeName, val origin: String) extends TypeSkolem(NoSymbol, NoPosition, name0, NoSymbol) with FreeSymbol with FreeTypeSymbolApi implicit val FreeTypeSymbolTag = ClassTag[FreeTypeSymbol](classOf[FreeTypeSymbol]) /** An object representing a missing symbol */ diff --git a/src/reflect/scala/reflect/macros/Aliases.scala b/src/reflect/scala/reflect/macros/Aliases.scala index ad100d7e89..eff7f34b02 100644 --- a/src/reflect/scala/reflect/macros/Aliases.scala +++ b/src/reflect/scala/reflect/macros/Aliases.scala @@ -17,12 +17,12 @@ trait Aliases { type Expr[+T] = universe.Expr[T] val Expr = universe.Expr - type AbsTypeTag[T] = universe.AbsTypeTag[T] + type WeakTypeTag[T] = universe.WeakTypeTag[T] type TypeTag[T] = universe.TypeTag[T] - val AbsTypeTag = universe.AbsTypeTag + val WeakTypeTag = universe.WeakTypeTag val TypeTag = universe.TypeTag - def absTypeTag[T](implicit attag: AbsTypeTag[T]) = attag + def weakTypeTag[T](implicit attag: WeakTypeTag[T]) = attag def typeTag[T](implicit ttag: TypeTag[T]) = ttag - def absTypeOf[T](implicit attag: AbsTypeTag[T]): Type = attag.tpe + def weakTypeOf[T](implicit attag: WeakTypeTag[T]): Type = attag.tpe def typeOf[T](implicit ttag: TypeTag[T]): Type = ttag.tpe } diff --git a/src/reflect/scala/reflect/macros/Exprs.scala b/src/reflect/scala/reflect/macros/Exprs.scala index ceaab06d12..280d5508c8 100644 --- a/src/reflect/scala/reflect/macros/Exprs.scala +++ b/src/reflect/scala/reflect/macros/Exprs.scala @@ -4,5 +4,5 @@ package macros trait Exprs { self: Context => - def Expr[T: AbsTypeTag](tree: Tree): Expr[T] + def Expr[T: WeakTypeTag](tree: Tree): Expr[T] } diff --git a/src/reflect/scala/reflect/macros/TypeTags.scala b/src/reflect/scala/reflect/macros/TypeTags.scala index 8f590d1de4..2f15e37f6a 100644 --- a/src/reflect/scala/reflect/macros/TypeTags.scala +++ b/src/reflect/scala/reflect/macros/TypeTags.scala @@ -4,6 +4,6 @@ package macros trait TypeTags { self: Context => - def AbsTypeTag[T](tpe: Type): AbsTypeTag[T] + def WeakTypeTag[T](tpe: Type): WeakTypeTag[T] def TypeTag[T](tpe: Type): TypeTag[T] } diff --git a/src/reflect/scala/reflect/runtime/JavaMirrors.scala b/src/reflect/scala/reflect/runtime/JavaMirrors.scala index 9f2c3fc79c..f4b68640ae 100644 --- a/src/reflect/scala/reflect/runtime/JavaMirrors.scala +++ b/src/reflect/scala/reflect/runtime/JavaMirrors.scala @@ -120,19 +120,20 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym // ----------- Implementations of mirror operations and classes ------------------- - private def ErrorInnerClass(wannabe: Symbol) = throw new ScalaReflectionException(s"$wannabe is an inner class, use reflectClass on an InstanceMirror to obtain its ClassMirror") - private def ErrorInnerModule(wannabe: Symbol) = throw new ScalaReflectionException(s"$wannabe is an inner module, use reflectModule on an InstanceMirror to obtain its ModuleMirror") - private def ErrorStaticClass(wannabe: Symbol) = throw new ScalaReflectionException(s"$wannabe is a static class, use reflectClass on a RuntimeMirror to obtain its ClassMirror") - private def ErrorStaticModule(wannabe: Symbol) = throw new ScalaReflectionException(s"$wannabe is a static module, use reflectModule on a RuntimeMirror to obtain its ModuleMirror") - private def ErrorNotMember(wannabe: Symbol, owner: Symbol) = throw new ScalaReflectionException(s"expected a member of $owner, you provided ${wannabe.kindString} ${wannabe.fullName}") - private def ErrorNotField(wannabe: Symbol) = throw new ScalaReflectionException(s"expected a field or an accessor method symbol, you provided $wannabe") - private def ErrorNonExistentField(wannabe: Symbol) = throw new ScalaReflectionException(s""" - |Scala field ${wannabe.name} isn't represented as a Java field, neither it has a Java accessor method + private def ErrorInnerClass(sym: Symbol) = throw new ScalaReflectionException(s"$sym is an inner class, use reflectClass on an InstanceMirror to obtain its ClassMirror") + private def ErrorInnerModule(sym: Symbol) = throw new ScalaReflectionException(s"$sym is an inner module, use reflectModule on an InstanceMirror to obtain its ModuleMirror") + private def ErrorStaticClass(sym: Symbol) = throw new ScalaReflectionException(s"$sym is a static class, use reflectClass on a RuntimeMirror to obtain its ClassMirror") + private def ErrorStaticModule(sym: Symbol) = throw new ScalaReflectionException(s"$sym is a static module, use reflectModule on a RuntimeMirror to obtain its ModuleMirror") + private def ErrorNotMember(sym: Symbol, owner: Symbol) = throw new ScalaReflectionException(s"expected a member of $owner, you provided ${sym.kindString} ${sym.fullName}") + private def ErrorNotField(sym: Symbol) = throw new ScalaReflectionException(s"expected a field or an accessor method symbol, you provided $sym") + private def ErrorNonExistentField(sym: Symbol) = throw new ScalaReflectionException(s""" + |Scala field ${sym.name} isn't represented as a Java field, neither it has a Java accessor method |note that private parameters of class constructors don't get mapped onto fields and/or accessors, |unless they are used outside of their declaring constructors. """.trim.stripMargin) - private def ErrorSetImmutableField(wannabe: Symbol) = throw new ScalaReflectionException(s"cannot set an immutable field ${wannabe.name}") - private def ErrorNotConstructor(wannabe: Symbol, owner: Symbol) = throw new ScalaReflectionException(s"expected a constructor of $owner, you provided $wannabe") + private def ErrorSetImmutableField(sym: Symbol) = throw new ScalaReflectionException(s"cannot set an immutable field ${sym.name}") + private def ErrorNotConstructor(sym: Symbol, owner: Symbol) = throw new ScalaReflectionException(s"expected a constructor of $owner, you provided $sym") + private def ErrorFree(member: Symbol, freeType: Symbol) = throw new ScalaReflectionException(s"cannot reflect ${member.kindString} ${member.name}, because it's a member of a weak type ${freeType.name}") def reflect[T: ClassTag](obj: T): InstanceMirror = new JavaInstanceMirror(obj) @@ -154,13 +155,30 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym def moduleSymbol(rtcls: RuntimeClass): ModuleSymbol = classToScala(rtcls).companionModule.asModule - private def checkMemberOf(wannabe: Symbol, owner: ClassSymbol) { - if (wannabe.owner == AnyClass || wannabe.owner == AnyRefClass || wannabe.owner == ObjectClass) { + private def ensuringNotFree(sym: Symbol)(body: => Any) { + val freeType = sym.ownerChain find (_.isFreeType) + freeType match { + case Some(freeType) => ErrorFree(sym, freeType) + case _ => body + } + } + + private def checkMemberOf(sym: Symbol, owner: ClassSymbol) { + if (sym.owner == AnyClass || sym.owner == AnyRefClass || sym.owner == ObjectClass) { // do nothing - } else if (wannabe.owner == AnyValClass) { - if (!owner.isPrimitiveValueClass && !owner.isDerivedValueClass) ErrorNotMember(wannabe, owner) + } else if (sym.owner == AnyValClass) { + if (!owner.isPrimitiveValueClass && !owner.isDerivedValueClass) ErrorNotMember(sym, owner) } else { - if (!(owner.info.baseClasses contains wannabe.owner)) ErrorNotMember(wannabe, owner) + ensuringNotFree(sym) { + if (!(owner.info.baseClasses contains sym.owner)) ErrorNotMember(sym, owner) + } + } + } + + private def checkConstructorOf(sym: Symbol, owner: ClassSymbol) { + if (!sym.isClassConstructor) ErrorNotConstructor(sym, owner) + ensuringNotFree(sym) { + if (!owner.info.decls.toList.contains(sym)) ErrorNotConstructor(sym, owner) } } @@ -386,8 +404,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym def erasure = symbol def isStatic = false def reflectConstructor(constructor: MethodSymbol) = { - if (!constructor.isClassConstructor) ErrorNotConstructor(constructor, symbol) - if (!symbol.info.decls.toList.contains(constructor)) ErrorNotConstructor(constructor, symbol) + checkConstructorOf(constructor, symbol) new JavaConstructorMirror(outer, constructor) } def companion: Option[ModuleMirror] = symbol.companionModule match { diff --git a/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala b/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala index 40346cad79..7705610efb 100644 --- a/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala +++ b/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala @@ -14,11 +14,11 @@ trait SynchronizedSymbols extends internal.Symbols { self: SymbolTable => override def connectModuleToClass(m: ModuleSymbol, moduleClass: ClassSymbol): ModuleSymbol = synchronized { super.connectModuleToClass(m, moduleClass) } - override def newFreeTermSymbol(name: TermName, info: Type, value: => Any, flags: Long = 0L, origin: String = null): FreeTermSymbol = - new FreeTermSymbol(name, value, origin) with SynchronizedTermSymbol initFlags flags setInfo info + override def newFreeTermSymbol(name: TermName, value: => Any, flags: Long = 0L, origin: String = null): FreeTermSymbol = + new FreeTermSymbol(name, value, origin) with SynchronizedTermSymbol initFlags flags - override def newFreeTypeSymbol(name: TypeName, info: Type, value: => Any, flags: Long = 0L, origin: String = null): FreeTypeSymbol = - new FreeTypeSymbol(name, value, origin) with SynchronizedTypeSymbol initFlags flags setInfo info + override def newFreeTypeSymbol(name: TypeName, flags: Long = 0L, origin: String = null): FreeTypeSymbol = + new FreeTypeSymbol(name, origin) with SynchronizedTypeSymbol initFlags flags override protected def makeNoSymbol: NoSymbol = new NoSymbol with SynchronizedSymbol diff --git a/src/reflect/scala/reflect/runtime/package.scala b/src/reflect/scala/reflect/runtime/package.scala index ccdea3e82d..d325cf6a16 100644 --- a/src/reflect/scala/reflect/runtime/package.scala +++ b/src/reflect/scala/reflect/runtime/package.scala @@ -17,7 +17,7 @@ package runtime { if (runtimeClass.isEmpty) c.abort(c.enclosingPosition, "call site does not have an enclosing class") val runtimeUniverse = Select(Select(Select(Ident(newTermName("scala")), newTermName("reflect")), newTermName("runtime")), newTermName("universe")) val currentMirror = Apply(Select(runtimeUniverse, newTermName("runtimeMirror")), List(Select(runtimeClass, newTermName("getClassLoader")))) - c.Expr[Nothing](currentMirror)(c.AbsTypeTag.Nothing) + c.Expr[Nothing](currentMirror)(c.WeakTypeTag.Nothing) } } } |