Permalink
Browse files

ClassTag.erasure => ClassTag.runtimeClass

This change is made to be consistent with JavaMirrors.
And, in my opinion, a technology-neutral term is better here.
  • Loading branch information...
xeno-by committed Jun 6, 2012
1 parent 6bb5975 commit 252a44864786b6832b9da4c29d1ac9aad48c4291
Showing with 85 additions and 84 deletions.
  1. +2 −2 src/compiler/scala/reflect/api/TagInterop.scala
  2. +1 −1 src/compiler/scala/reflect/internal/Mirrors.scala
  3. +1 −1 src/compiler/scala/reflect/internal/StdNames.scala
  4. +2 −2 src/compiler/scala/reflect/makro/runtime/Reifiers.scala
  5. +2 −2 src/compiler/scala/reflect/reify/Reifier.scala
  6. +2 −2 src/compiler/scala/reflect/reify/Taggers.scala
  7. +4 −4 src/compiler/scala/reflect/reify/package.scala
  8. +3 −3 src/compiler/scala/tools/nsc/interpreter/IMain.scala
  9. +4 −4 src/compiler/scala/tools/nsc/interpreter/Power.scala
  10. +2 −2 src/compiler/scala/tools/nsc/interpreter/TypeStrings.scala
  11. +1 −1 src/compiler/scala/tools/nsc/settings/MutableSettings.scala
  12. +1 −1 src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala
  13. +2 −2 src/compiler/scala/tools/nsc/util/ScalaClassLoader.scala
  14. +1 −1 src/compiler/scala/tools/reflect/StdTags.scala
  15. +2 −2 src/library/scala/collection/mutable/ArrayBuilder.scala
  16. +2 −2 src/library/scala/collection/mutable/WrappedArrayBuilder.scala
  17. +1 −1 src/library/scala/collection/parallel/ParIterableLike.scala
  18. +1 −1 src/library/scala/concurrent/Future.scala
  19. +2 −2 src/library/scala/reflect/ArrayTag.scala
  20. +1 −0 src/library/scala/reflect/ClassManifest.scala
  21. +30 −30 src/library/scala/reflect/ClassTag.scala
  22. +2 −2 src/library/scala/reflect/base/Attachments.scala
  23. +4 −4 src/library/scala/reflect/base/TagInterop.scala
  24. +2 −2 src/library/scala/reflect/base/TypeTags.scala
  25. +3 −3 src/library/scala/reflect/makro/Reifiers.scala
  26. +2 −2 src/library/scala/runtime/ScalaRunTime.scala
  27. +1 −1 src/library/scala/util/Marshal.scala
  28. +1 −1 src/library/scala/util/control/Exception.scala
  29. +3 −3 src/partest/scala/tools/partest/SigTest.scala
@@ -15,8 +15,8 @@ trait TagInterop { self: JavaUniverse =>
// [Eugene++] implement more sophisticated logic
// Martin said it'd be okay to simply copypaste `Implicits.manifestOfType`
val mirror = mirror0.asInstanceOf[Mirror]
val erasure = mirror.runtimeClass(tag.in(mirror).tpe)
Manifest.classType(erasure).asInstanceOf[Manifest[T]]
val runtimeClass = mirror.runtimeClass(tag.in(mirror).tpe)
Manifest.classType(runtimeClass).asInstanceOf[Manifest[T]]
}
override def manifestToConcreteTypeTag[T](mirror0: Any, manifest: Manifest[T]): base.Universe # ConcreteTypeTag[T] =
@@ -103,7 +103,7 @@ trait Mirrors extends api.Mirrors {
if (clazz.isArray) "Array[" + erasureString(clazz.getComponentType) + "]"
else clazz.getName
}
erasureString(classTag[T].erasure)
erasureString(classTag[T].runtimeClass)
}
def requiredClass[T: ClassTag] : ClassSymbol =
@@ -651,7 +651,6 @@ trait StdNames {
val equalsNumNum : NameType = "equalsNumNum"
val equalsNumObject : NameType = "equalsNumObject"
val equals_ : NameType = if (forMSIL) "Equals" else "equals"
val erasure: NameType = "erasure"
val error: NameType = "error"
val eval: NameType = "eval"
val ex: NameType = "ex"
@@ -727,6 +726,7 @@ trait StdNames {
val rootMirror : NameType = "rootMirror"
val runOrElse: NameType = "runOrElse"
val runtime: NameType = "runtime"
val runtimeClass: NameType = "runtimeClass"
val runtimeMirror: NameType = "runtimeMirror"
val sameElements: NameType = "sameElements"
val scala_ : NameType = "scala"
@@ -20,8 +20,8 @@ trait Reifiers {
def reifyType(prefix: Tree, tpe: Type, dontSpliceAtTopLevel: Boolean = false, concrete: Boolean = false): Tree =
scala.reflect.reify.`package`.reifyType(mirror)(callsiteTyper, prefix, tpe, dontSpliceAtTopLevel, concrete)
def reifyErasure(tpe: Type, concrete: Boolean = true): Tree =
scala.reflect.reify.`package`.reifyErasure(mirror)(callsiteTyper, tpe, concrete)
def reifyRuntimeClass(tpe: Type, concrete: Boolean = true): Tree =
scala.reflect.reify.`package`.reifyRuntimeClass(mirror)(callsiteTyper, tpe, concrete)
def unreifyTree(tree: Tree): Tree =
Select(tree, definitions.ExprSplice)
@@ -78,7 +78,7 @@ abstract class Reifier extends Phases
val tagModule = if (reificationIsConcrete) ConcreteTypeTagModule else TypeTagModule
val tagCtor = TypeApply(Select(Ident(nme.MIRROR_SHORT), tagModule.name), List(TypeTree(taggedType)))
val exprCtor = TypeApply(Select(Ident(nme.MIRROR_SHORT), ExprModule.name), List(TypeTree(taggedType)))
val tagArgs = List(reify(taggedType), reifyErasure(mirror)(typer, taggedType, concrete = false))
val tagArgs = List(reify(taggedType), reifyRuntimeClass(mirror)(typer, taggedType, concrete = false))
Apply(Apply(exprCtor, List(rtree)), List(Apply(tagCtor, tagArgs)))
case tpe: Type =>
@@ -89,7 +89,7 @@ abstract class Reifier extends Phases
val taggedType = tpe
val tagModule = if (reificationIsConcrete) ConcreteTypeTagModule else TypeTagModule
val ctor = TypeApply(Select(Ident(nme.MIRROR_SHORT), tagModule.name), List(TypeTree(taggedType)))
val args = List(rtree, reifyErasure(mirror)(typer, taggedType, concrete = false))
val args = List(rtree, reifyRuntimeClass(mirror)(typer, taggedType, concrete = false))
Apply(ctor, args)
case _ =>
@@ -32,9 +32,9 @@ abstract class Taggers {
def materializeClassTag(prefix: Tree, tpe: Type): Tree =
materializeTag(prefix, tpe, ClassTagModule, {
val erasure = c.reifyErasure(tpe, concrete = true)
val runtimeClass = c.reifyRuntimeClass(tpe, concrete = true)
val factory = TypeApply(Select(Ident(ClassTagModule), "apply"), List(TypeTree(tpe)))
Apply(factory, List(erasure))
Apply(factory, List(runtimeClass))
})
def materializeTypeTag(prefix: Tree, tpe: Type, concrete: Boolean): Tree = {
@@ -28,7 +28,7 @@ package object reify {
def reifyType(global: Global)(typer: global.analyzer.Typer, prefix: global.Tree, tpe: global.Type, dontSpliceAtTopLevel: Boolean = false, concrete: Boolean = false): global.Tree =
mkReifier(global)(typer, prefix, tpe, dontSpliceAtTopLevel, concrete).reified.asInstanceOf[global.Tree]
def reifyErasure(global: Global)(typer0: global.analyzer.Typer, tpe: global.Type, concrete: Boolean = true): global.Tree = {
def reifyRuntimeClass(global: Global)(typer0: global.analyzer.Typer, tpe: global.Type, concrete: Boolean = true): global.Tree = {
import global._
import definitions._
import analyzer.enclosingMacroPosition
@@ -39,14 +39,14 @@ package object reify {
inScope match {
case (success, _) if !success.isEmpty =>
Select(success, nme.erasure)
Select(success, nme.runtimeClass)
case (_, success) if !success.isEmpty =>
gen.mkMethodCall(arrayElementClassMethod, List(success))
case _ =>
tpe.normalize match {
case TypeRef(_, ArrayClass, componentTpe :: Nil) =>
val componentErasure = reifyErasure(global)(typer0, componentTpe, concrete)
gen.mkMethodCall(arrayClassMethod, List(componentErasure))
val componentRuntimeClass = reifyRuntimeClass(global)(typer0, componentTpe, concrete)
gen.mkMethodCall(arrayClassMethod, List(componentRuntimeClass))
case _ =>
if (tpe.isSpliceable && concrete)
throw new ReificationError(enclosingMacroPosition, "tpe %s is an unresolved spliceable type".format(tpe))
@@ -1120,9 +1120,9 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
findName(termname) orElse getModuleIfDefined(termname)
}
// [Eugene to Paul] possibly you could make use of TypeTags here
def types[T: ClassTag] : Symbol = types(classTag[T].erasure.getName)
def terms[T: ClassTag] : Symbol = terms(classTag[T].erasure.getName)
def apply[T: ClassTag] : Symbol = apply(classTag[T].erasure.getName)
def types[T: ClassTag] : Symbol = types(classTag[T].runtimeClass.getName)
def terms[T: ClassTag] : Symbol = terms(classTag[T].runtimeClass.getName)
def apply[T: ClassTag] : Symbol = apply(classTag[T].runtimeClass.getName)
def classSymbols = allDefSymbols collect { case x: ClassSymbol => x }
def methodSymbols = allDefSymbols collect { case x: MethodSymbol => x }
@@ -188,7 +188,7 @@ class Power[ReplValsImpl <: ReplVals : ru.TypeTag: ClassTag](val intp: IMain, re
* translate tag type arguments into applied types
* customizable symbol filter (had to hardcode no-spec to reduce noise)
*/
class InternalInfo[T](value: Option[T] = None)(implicit typeEvidence: ru.TypeTag[T], erasureEvidence: ClassTag[T]) {
class InternalInfo[T](value: Option[T] = None)(implicit typeEvidence: ru.TypeTag[T], runtimeClassEvidence: ClassTag[T]) {
private def newInfo[U: ru.TypeTag : ClassTag](value: U): InternalInfo[U] = new InternalInfo[U](Some(value))
private def isSpecialized(s: Symbol) = s.name.toString contains "$mc"
private def isImplClass(s: Symbol) = s.name.toString endsWith "$class"
@@ -229,8 +229,8 @@ class Power[ReplValsImpl <: ReplVals : ru.TypeTag: ClassTag](val intp: IMain, re
def pkgSymbols = new PackageSlurper(pkgClass).slurp() filterNot excludeMember
def tag = typeEvidence
def erasure = erasureEvidence.erasure
def shortClass = erasure.getName split "[$.]" last
def runtimeClass = runtimeClassEvidence.runtimeClass
def shortClass = runtimeClass.getName split "[$.]" last
def baseClasses = tpe.baseClasses
def baseClassDecls = mapFrom(baseClasses)(_.info.decls.toList.sortBy(_.name))
@@ -244,7 +244,7 @@ class Power[ReplValsImpl <: ReplVals : ru.TypeTag: ClassTag](val intp: IMain, re
override def toString = value match {
case Some(x) => "%s (%s)".format(x, shortClass)
case _ => erasure.getName
case _ => runtimeClass.getName
}
}
@@ -192,7 +192,7 @@ trait TypeStrings {
else enclClass.getName + "." + (name stripPrefix enclPre)
)
}
def scalaName(ct: ClassTag[_]): String = scalaName(ct.erasure)
def scalaName(ct: ClassTag[_]): String = scalaName(ct.runtimeClass)
def anyClass(x: Any): JClass = if (x == null) null else x.getClass
private def brackets(tps: String*): String =
@@ -229,7 +229,7 @@ trait TypeStrings {
def fromTypedValue[T: ru.TypeTag : ClassTag](x: T): String = fromTag[T]
def fromValue(value: Any): String = if (value == null) "Null" else fromClazz(anyClass(value))
def fromClazz(clazz: JClass): String = scalaName(clazz) + tparamString(clazz)
def fromTag[T: ru.TypeTag : ClassTag] : String = scalaName(classTag[T].erasure) + tparamString[T]
def fromTag[T: ru.TypeTag : ClassTag] : String = scalaName(classTag[T].runtimeClass) + tparamString[T]
/** Reducing fully qualified noise for some common packages.
*/
@@ -184,7 +184,7 @@ class MutableSettings(val errorFn: String => Unit)
* and `boot.class.path`. These resources should contain the application
* and boot classpaths in the same form as would be passed on the command line.*/
def embeddedDefaults[T: ClassTag]: Unit =
embeddedDefaults(classTag[T].erasure.getClassLoader)
embeddedDefaults(classTag[T].runtimeClass.getClassLoader)
/** Initializes these settings for embedded use by a class from the given class loader.
* The class loader for `T` should provide resources `app.class.path`
@@ -45,7 +45,7 @@ trait MethodSynthesis {
}
def companionType[T](implicit ct: CT[T]) =
rootMirror.getRequiredModule(ct.erasure.getName).tpe
rootMirror.getRequiredModule(ct.runtimeClass.getName).tpe
// Use these like `applyType[List, Int]` or `applyType[Map, Int, String]`
def applyType[CC](implicit t1: CTT[CC]): Type =
@@ -46,7 +46,7 @@ trait ScalaClassLoader extends JClassLoader {
tryToInitializeClass[AnyRef](path) map (_.newInstance()) orNull
def constructorsOf[T <: AnyRef : ClassTag]: List[Constructor[T]] =
classTag[T].erasure.getConstructors.toList map (_.asInstanceOf[Constructor[T]])
classTag[T].runtimeClass.getConstructors.toList map (_.asInstanceOf[Constructor[T]])
/** The actual bytes for a class file, or an empty array if it can't be found. */
def classBytes(className: String): Array[Byte] = classAsStream(className) match {
@@ -102,7 +102,7 @@ object ScalaClassLoader {
def bootLoader = apply(null)
def contextChain = loaderChain(contextLoader)
def pathToErasure[T: ClassTag] = pathToClass(classTag[T].erasure)
def pathToErasure[T: ClassTag] = pathToClass(classTag[T].runtimeClass)
def pathToClass(clazz: Class[_]) = clazz.getName.replace('.', JFile.separatorChar) + ".class"
def locate[T: ClassTag] = contextLoader getResource pathToErasure[T]
@@ -29,7 +29,7 @@ object StdTags {
ru.runtimeMirror(ourClassloader),
new TypeCreator {
def apply[U <: BaseUniverse with Singleton](m: MirrorOf[U]): U # Type =
m.staticClass(classTag[T].erasure.getName).asTypeConstructor.asInstanceOf[U # Type]
m.staticClass(classTag[T].runtimeClass.getName).asTypeConstructor.asInstanceOf[U # Type]
})
lazy val tagOfInt = ru.TypeTag.Int
lazy val tagOfFile = tagOfStaticClass[scala.tools.nsc.io.File]
@@ -36,8 +36,8 @@ object ArrayBuilder {
*/
def make[T: ArrayTag](): ArrayBuilder[T] = {
val tag = implicitly[ArrayTag[T]]
val erasure = ScalaRunTime.arrayElementClass(tag)
erasure match {
val runtimeClass = ScalaRunTime.arrayElementClass(tag)
runtimeClass match {
case java.lang.Byte.TYPE => new ArrayBuilder.ofByte().asInstanceOf[ArrayBuilder[T]]
case java.lang.Short.TYPE => new ArrayBuilder.ofShort().asInstanceOf[ArrayBuilder[T]]
case java.lang.Character.TYPE => new ArrayBuilder.ofChar().asInstanceOf[ArrayBuilder[T]]
@@ -32,8 +32,8 @@ class WrappedArrayBuilder[A](tag: ArrayTag[A]) extends Builder[A, WrappedArray[A
private var size: Int = 0
private def mkArray(size: Int): WrappedArray[A] = {
val erasure = arrayElementClass(tag)
val newelems = erasure match {
val runtimeClass = arrayElementClass(tag)
val newelems = runtimeClass match {
case java.lang.Byte.TYPE => new WrappedArray.ofByte(new Array[Byte](size)).asInstanceOf[WrappedArray[A]]
case java.lang.Short.TYPE => new WrappedArray.ofShort(new Array[Short](size)).asInstanceOf[WrappedArray[A]]
case java.lang.Character.TYPE => new WrappedArray.ofChar(new Array[Char](size)).asInstanceOf[WrappedArray[A]]
@@ -303,7 +303,7 @@ self: ParIterableLike[T, Repr, Sequential] =>
protected implicit def builder2ops[Elem, To](cb: Builder[Elem, To]) = new BuilderOps[Elem, To] {
def ifIs[Cmb](isbody: Cmb => Unit) = new Otherwise[Cmb] {
def otherwise(notbody: => Unit)(implicit t: ClassTag[Cmb]) {
if (cb.getClass == t.erasure) isbody(cb.asInstanceOf[Cmb]) else notbody
if (cb.getClass == t.runtimeClass) isbody(cb.asInstanceOf[Cmb]) else notbody
}
}
def isCombiner = cb.isInstanceOf[Combiner[_, _]]
@@ -489,7 +489,7 @@ trait Future[+T] extends Awaitable[T] {
case l: Left[_, _] => p complete l.asInstanceOf[Left[Throwable, S]]
case Right(t) =>
p complete (try {
Right(boxedType(tag.erasure).cast(t).asInstanceOf[S])
Right(boxedType(tag.runtimeClass).cast(t).asInstanceOf[S])
} catch {
case e: ClassCastException => Left(e)
})
@@ -7,8 +7,8 @@ package scala.reflect
* cannot contain unresolved references to type parameters or abstract types.
*
* Scala library provides a standard implementation of this trait,
* `ClassTag[T]` that explicitly carries the `java.lang.Class` erasure of type T
* and uses Java reflection to instantiate arrays.
* `ClassTag[T]` that explicitly carries the runtime class of type T
* and uses reflection to instantiate arrays.
*
* However other platforms (e.g. a Scala -> JS crosscompiler) may reimplement this trait as they see fit
* and then expose the implementation via an implicit macro.
@@ -27,6 +27,7 @@ trait ClassManifest[T] extends OptManifest[T] with ClassTag[T] with Equals with
/** A class representing the type `U` to which `T` would be erased. Note
* that there is no subtyping relationship between `T` and `U`. */
def erasure: jClass[_]
override def runtimeClass: jClass[_] = erasure
private def subtype(sub: jClass[_], sup: jClass[_]): Boolean = {
def loop(left: Set[jClass[_]], seen: Set[jClass[_]]): Boolean = {
Oops, something went wrong.

0 comments on commit 252a448

Please sign in to comment.