From 0f0144c74088e396fc1440166bed5a7c6d5f44f4 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Mon, 23 Apr 2012 16:04:56 +0200 Subject: migrates stdlib and compiler to tags * all usages of ClassManifest and Manifest are replaced with tags * all manifest tests are replaced with tag tests --- .../scala/reflect/internal/AnnotationInfos.scala | 3 +- .../scala/reflect/internal/Definitions.scala | 4 +- .../reflect/internal/pickling/UnPickler.scala | 4 +- .../scala/reflect/internal/util/Origins.scala | 2 +- src/compiler/scala/reflect/runtime/Mirror.scala | 2 +- src/compiler/scala/tools/cmd/FromString.scala | 6 +-- src/compiler/scala/tools/nsc/Phases.scala | 2 +- src/compiler/scala/tools/nsc/doc/Settings.scala | 15 +++++--- .../scala/tools/nsc/doc/html/SyntaxHigh.scala | 8 ++-- .../doc/model/ModelFactoryImplicitSupport.scala | 14 +++---- .../scala/tools/nsc/interpreter/ILoop.scala | 4 +- .../scala/tools/nsc/interpreter/ILoopInit.scala | 2 +- .../scala/tools/nsc/interpreter/IMain.scala | 23 ++++++------ .../scala/tools/nsc/interpreter/NamedParam.scala | 12 +++--- .../scala/tools/nsc/interpreter/Power.scala | 43 ++++++++++++---------- .../scala/tools/nsc/interpreter/ReplVals.scala | 25 +++++++------ .../scala/tools/nsc/interpreter/RichClass.scala | 10 ++--- .../scala/tools/nsc/interpreter/TypeStrings.scala | 20 +++++----- .../scala/tools/nsc/io/ClassAndJarInfo.scala | 6 +-- src/compiler/scala/tools/nsc/io/Pickler.scala | 2 +- .../scala/tools/nsc/settings/MutableSettings.scala | 4 +- .../scala/tools/nsc/transform/CleanUp.scala | 2 +- .../scala/tools/nsc/transform/Erasure.scala | 1 + .../tools/nsc/typechecker/ContextErrors.scala | 2 +- .../tools/nsc/typechecker/MethodSynthesis.scala | 30 ++++++++------- .../tools/nsc/typechecker/NamesDefaults.scala | 4 +- .../tools/nsc/typechecker/SyntheticMethods.scala | 2 +- src/compiler/scala/tools/nsc/util/ClassPath.scala | 12 +++--- .../scala/tools/nsc/util/ScalaClassLoader.scala | 10 ++--- src/compiler/scala/tools/reflect/Invoked.scala | 2 +- src/compiler/scala/tools/reflect/UniversalFn.scala | 4 +- src/compiler/scala/tools/reflect/package.scala | 23 ++++++------ 32 files changed, 155 insertions(+), 148 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/scala/reflect/internal/AnnotationInfos.scala b/src/compiler/scala/reflect/internal/AnnotationInfos.scala index b86c62661a..fe0175fe72 100644 --- a/src/compiler/scala/reflect/internal/AnnotationInfos.scala +++ b/src/compiler/scala/reflect/internal/AnnotationInfos.scala @@ -260,8 +260,7 @@ trait AnnotationInfos extends api.AnnotationInfos { self: SymbolTable => } } - lazy val classfileAnnotArgManifest: ClassManifest[ClassfileAnnotArg] = - reflect.ClassManifest[ClassfileAnnotArg](classOf[ClassfileAnnotArg]) + lazy val classfileAnnotArgTag: ArrayTag[ClassfileAnnotArg] = arrayTag[ClassfileAnnotArg] object UnmappableAnnotation extends CompleteAnnotationInfo(NoType, Nil, Nil) } diff --git a/src/compiler/scala/reflect/internal/Definitions.scala b/src/compiler/scala/reflect/internal/Definitions.scala index 28905dd240..29eb573b64 100644 --- a/src/compiler/scala/reflect/internal/Definitions.scala +++ b/src/compiler/scala/reflect/internal/Definitions.scala @@ -534,9 +534,9 @@ trait Definitions extends reflect.api.StandardDefinitions { // private lazy val importerFromRm = self.mkImporter(rm) private lazy val importerFromRm = self.mkImporter(rm).asInstanceOf[self.Importer { val from: rm.type }] - def manifestToType(m: Manifest[_]): Type = importerFromRm.importType(m.tpe) + def compilerTypeFromTag(t: rm.TypeTag[_]): Type = importerFromRm.importType(t.tpe) - def manifestToSymbol(m: Manifest[_]): Symbol = importerFromRm.importSymbol(m.tpe.typeSymbol) + def compilerSymbolFromTag(t: rm.TypeTag[_]): Symbol = importerFromRm.importSymbol(t.sym) // The given symbol represents either String.+ or StringAdd.+ def isStringAddition(sym: Symbol) = sym == String_+ || sym == StringAdd_+ diff --git a/src/compiler/scala/reflect/internal/pickling/UnPickler.scala b/src/compiler/scala/reflect/internal/pickling/UnPickler.scala index eb4bae78d0..fd3fac1b37 100644 --- a/src/compiler/scala/reflect/internal/pickling/UnPickler.scala +++ b/src/compiler/scala/reflect/internal/pickling/UnPickler.scala @@ -447,7 +447,7 @@ abstract class UnPickler /*extends reflect.generic.UnPickler*/ { private def readArrayAnnot() = { readByte() // skip the `annotargarray` tag val end = readNat() + readIndex - until(end, () => readClassfileAnnotArg(readNat())).toArray(classfileAnnotArgManifest) + until(end, () => readClassfileAnnotArg(readNat())).toArray(classfileAnnotArgTag) } protected def readClassfileAnnotArg(i: Int): ClassfileAnnotArg = bytes(index(i)) match { case ANNOTINFO => NestedAnnotArg(at(i, readAnnotation)) @@ -843,7 +843,7 @@ abstract class UnPickler /*extends reflect.generic.UnPickler*/ { atPhase(p) (sym setInfo tp) if (currentRunId != definedAtRunId) sym.setInfo(adaptToNewRunMap(tp)) - } + } catch { case e: MissingRequirementError => throw toTypeError(e) } diff --git a/src/compiler/scala/reflect/internal/util/Origins.scala b/src/compiler/scala/reflect/internal/util/Origins.scala index b9985c8f50..19b3adda9d 100644 --- a/src/compiler/scala/reflect/internal/util/Origins.scala +++ b/src/compiler/scala/reflect/internal/util/Origins.scala @@ -88,7 +88,7 @@ object Origins { sys.addShutdownHook(counters foreach (_.purge())) } - def apply[T: Manifest](tag: String): Origins = apply(tag, manifest[T].erasure) + def apply[T: ClassTag](tag: String): Origins = apply(tag, classTag[T].erasure) def apply(tag: String, clazz: Class[_]): Origins = apply(tag, new OneLine(clazz)) def apply(tag: String, orElse: => Origins): Origins = { counters find (_.tag == tag) getOrElse { diff --git a/src/compiler/scala/reflect/runtime/Mirror.scala b/src/compiler/scala/reflect/runtime/Mirror.scala index 20024ed058..bf4bc83bea 100644 --- a/src/compiler/scala/reflect/runtime/Mirror.scala +++ b/src/compiler/scala/reflect/runtime/Mirror.scala @@ -25,7 +25,7 @@ class Mirror(var classLoader: ClassLoader) extends Universe with api.Mirror { def symbolOfInstance(obj: Any): Symbol = classToScala(obj.getClass) def typeOfInstance(obj: Any): Type = typeToScala(obj.getClass) // to do add getClass/getType for instances of primitive types, probably like this: - // def getClass[T <: AnyVal : Manifest](x: T): Symbol = manifest[T].getClass + // def getClass[T <: AnyVal : ClassTag](x: T): Symbol = classTag[T].sym def getValueOfField(receiver: AnyRef, field: Symbol): Any = { fieldToJava(field).get(receiver) diff --git a/src/compiler/scala/tools/cmd/FromString.scala b/src/compiler/scala/tools/cmd/FromString.scala index 9592e7a716..91356b3c19 100644 --- a/src/compiler/scala/tools/cmd/FromString.scala +++ b/src/compiler/scala/tools/cmd/FromString.scala @@ -7,19 +7,19 @@ package scala.tools package cmd import nsc.io.{ Path, File, Directory } -import scala.reflect.Manifest +import scala.reflect.TypeTag /** A general mechanism for defining how a command line argument * (always a String) is transformed into an arbitrary type. A few * example instances are in the companion object, but in general * either IntFromString will suffice or you'll want custom transformers. */ -abstract class FromString[+T](implicit m: Manifest[T]) extends PartialFunction[String, T] { +abstract class FromString[+T](implicit t: TypeTag[T]) extends PartialFunction[String, T] { def apply(s: String): T def isDefinedAt(s: String): Boolean = true def zero: T = apply("") - def targetString: String = m.toString + def targetString: String = t.toString } object FromString { diff --git a/src/compiler/scala/tools/nsc/Phases.scala b/src/compiler/scala/tools/nsc/Phases.scala index 1fa576afb6..aa0ea1bdd8 100644 --- a/src/compiler/scala/tools/nsc/Phases.scala +++ b/src/compiler/scala/tools/nsc/Phases.scala @@ -14,7 +14,7 @@ object Phases { /** A class for tracking something about each phase. */ - class Model[T: Manifest] { + class Model[T] { case class Cell(ph: Phase, value: T) { def name = ph.name def id = ph.id diff --git a/src/compiler/scala/tools/nsc/doc/Settings.scala b/src/compiler/scala/tools/nsc/doc/Settings.scala index 17bfb7d21d..d3a1d47de8 100644 --- a/src/compiler/scala/tools/nsc/doc/Settings.scala +++ b/src/compiler/scala/tools/nsc/doc/Settings.scala @@ -150,12 +150,15 @@ class Settings(error: String => Unit) extends scala.tools.nsc.Settings(error) { * the function result should be a humanly-understandable description of the type class */ val knownTypeClasses: Map[String, String => String] = Map() + - (".scala.package.Numeric" -> ((tparam: String) => tparam + " is a numeric class, such as Int, Long, Float or Double")) + - (".scala.package.Integral" -> ((tparam: String) => tparam + " is an integral numeric class, such as Int or Long")) + - (".scala.package.Fractional" -> ((tparam: String) => tparam + " is a fractional numeric class, such as Float or Double")) + - (".scala.reflect.Manifest" -> ((tparam: String) => tparam + " is accompanied by a Manifest, which is a runtime representation of its type that survives erasure")) + - (".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.package.Numeric" -> ((tparam: String) => tparam + " is a numeric class, such as Int, Long, Float or Double")) + + (".scala.package.Integral" -> ((tparam: String) => tparam + " is an integral numeric class, such as Int or Long")) + + (".scala.package.Fractional" -> ((tparam: String) => tparam + " is a fractional numeric class, such as Float or Double")) + + (".scala.reflect.Manifest" -> ((tparam: String) => tparam + " is accompanied by a Manifest, which is a runtime representation of its type that survives erasure")) + + (".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.TypeTag" -> ((tparam: String) => tparam + " is accompanied by a TypeTag, which is a runtime representation of its type that survives erasure")) + + (".scala.reflect.ConcreteTypeTag" -> ((tparam: String) => tparam + " is accompanied by an ConcreteTypeTag, which is a runtime representation of a concrete type that survives erasure")) /** * Set of classes to exclude from index and diagrams diff --git a/src/compiler/scala/tools/nsc/doc/html/SyntaxHigh.scala b/src/compiler/scala/tools/nsc/doc/html/SyntaxHigh.scala index f67abc58da..3ff973ec66 100644 --- a/src/compiler/scala/tools/nsc/doc/html/SyntaxHigh.scala +++ b/src/compiler/scala/tools/nsc/doc/html/SyntaxHigh.scala @@ -41,13 +41,13 @@ private[html] object SyntaxHigh { /** Standard library classes/objects, sorted alphabetically */ val standards = Array ( "Any", "AnyRef", "AnyVal", "App", "Application", "Array", - "Boolean", "Byte", "Char", "Class", "Console", "Double", - "Enumeration", "Float", "Function", "Int", + "Boolean", "Byte", "Char", "Class", "ClassTag", "ClassManifest", "ConcreteTypeTag", + "Console", "Double", "Enumeration", "Float", "Function", "Int", "List", "Long", "Manifest", "Map", - "None", "Nothing", "Null", "Object", "Option", + "NoManifest", "None", "Nothing", "Null", "Object", "Option", "OptManifest", "Pair", "Predef", "Seq", "Set", "Short", "Some", "String", "Symbol", - "Triple", "Unit") + "Triple", "TypeTag", "Unit") def apply(data: String): NodeSeq = { val buf = data.getBytes diff --git a/src/compiler/scala/tools/nsc/doc/model/ModelFactoryImplicitSupport.scala b/src/compiler/scala/tools/nsc/doc/model/ModelFactoryImplicitSupport.scala index 4e03dc8788..61f3670f5f 100644 --- a/src/compiler/scala/tools/nsc/doc/model/ModelFactoryImplicitSupport.scala +++ b/src/compiler/scala/tools/nsc/doc/model/ModelFactoryImplicitSupport.scala @@ -137,7 +137,7 @@ trait ModelFactoryImplicitSupport { // Members inherited by implicit conversions cannot override actual members memberSyms = memberSyms.filterNot((sym1: Symbol) => - existingMembers.exists(sym2 => sym1.name == sym2.name && + existingMembers.exists(sym2 => sym1.name == sym2.name && !isDistinguishableFrom(toType.memberInfo(sym1), sym.info.memberInfo(sym2)))) debug(" -> full type: " + toType) @@ -199,12 +199,12 @@ trait ModelFactoryImplicitSupport { * What? in details: * - say we start from a class A[T1, T2, T3, T4] * - we have an implicit function (view) in scope: - * def pimpA[T3 <: Long, T4](a: A[Int, Foo[Bar[X]], T3, T4])(implicit ev1: Manifest[T4], ev2: Numeric[T4]): PimpedA + * def pimpA[T3 <: Long, T4](a: A[Int, Foo[Bar[X]], T3, T4])(implicit ev1: TypeTag[T4], ev2: Numeric[T4]): PimpedA * - A is converted to PimpedA ONLY if a couple of constraints are satisfied: * * T1 must be equal to Int * * T2 must be equal to Foo[Bar[X]] * * T3 must be upper bounded by Long - * * there must be evidence of Numeric[T4] and a Mainfest[T4] within scope + * * there must be evidence of Numeric[T4] and a TypeTag[T4] within scope * - the final type is PimpedA and A therefore inherits a couple of members from pimpedA * * How? @@ -504,14 +504,14 @@ trait ModelFactoryImplicitSupport { * class. We suppose the name of the two members coincides * * The trick here is that the resultType does not matter - the condition for removal it that paramss have the same - * structure (A => B => C may not override (A, B) => C) and that all the types involved are + * structure (A => B => C may not override (A, B) => C) and that all the types involved are * of the implcit conversion's member are subtypes of the parent members' parameters */ - def isDistinguishableFrom(t1: Type, t2: Type): Boolean = + def isDistinguishableFrom(t1: Type, t2: Type): Boolean = if (t1.paramss.map(_.length) == t2.paramss.map(_.length)) { for ((t1p, t2p) <- t1.paramss.flatten zip t2.paramss.flatten) if (!isSubType(t1 memberInfo t1p, t2 memberInfo t2p)) - return true // if on the corresponding parameter you give a type that is in t1 but not in t2 - // example: + return true // if on the corresponding parameter you give a type that is in t1 but not in t2 + // example: // def foo(a: Either[Int, Double]): Int = 3 // def foo(b: Left[T1]): Int = 6 // a.foo(Right(4.5d)) prints out 3 :) diff --git a/src/compiler/scala/tools/nsc/interpreter/ILoop.scala b/src/compiler/scala/tools/nsc/interpreter/ILoop.scala index 9279d37464..297d6ad1b9 100644 --- a/src/compiler/scala/tools/nsc/interpreter/ILoop.scala +++ b/src/compiler/scala/tools/nsc/interpreter/ILoop.scala @@ -1053,11 +1053,11 @@ object ILoop { // provide the enclosing type T // in order to set up the interpreter's classpath and parent class loader properly - def breakIf[T: Manifest](assertion: => Boolean, args: NamedParam*): Unit = + def breakIf[T: ClassTag](assertion: => Boolean, args: NamedParam*): Unit = if (assertion) break[T](args.toList) // start a repl, binding supplied args - def break[T: Manifest](args: List[NamedParam]): Unit = savingContextLoader { + def break[T: ClassTag](args: List[NamedParam]): Unit = savingContextLoader { val msg = if (args.isEmpty) "" else " Binding " + args.size + " value%s.".format( if (args.size == 1) "" else "s" ) diff --git a/src/compiler/scala/tools/nsc/interpreter/ILoopInit.scala b/src/compiler/scala/tools/nsc/interpreter/ILoopInit.scala index 2f02748e8f..6a9654732b 100644 --- a/src/compiler/scala/tools/nsc/interpreter/ILoopInit.scala +++ b/src/compiler/scala/tools/nsc/interpreter/ILoopInit.scala @@ -100,7 +100,7 @@ trait ILoopInit { withLock { while (!initIsComplete) initLoopCondition.await() } } // private def warningsThunks = List( - // () => intp.bind("lastWarnings", "" + manifest[List[(Position, String)]], intp.lastWarnings _), + // () => intp.bind("lastWarnings", "" + typeTag[List[(Position, String)]], intp.lastWarnings _), // ) protected def postInitThunks = List[Option[() => Unit]]( diff --git a/src/compiler/scala/tools/nsc/interpreter/IMain.scala b/src/compiler/scala/tools/nsc/interpreter/IMain.scala index 923fc867a9..3d77344091 100644 --- a/src/compiler/scala/tools/nsc/interpreter/IMain.scala +++ b/src/compiler/scala/tools/nsc/interpreter/IMain.scala @@ -351,7 +351,7 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends classLoader.setAsContext() // this is risky, but it's our only possibility to make default reflexive mirror to work with REPL - // so far we have only used the default mirror to create a few manifests for the compiler + // so far we have only used the default mirror to create a few tags for the compiler // so it shouldn't be in conflict with our classloader, especially since it respects its parent scala.reflect.mirror.classLoader = classLoader } @@ -667,7 +667,7 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends result } def directBind(p: NamedParam): IR.Result = directBind(p.name, p.tpe, p.value) - def directBind[T: Manifest](name: String, value: T): IR.Result = directBind((name, value)) + def directBind[T: ClassTag](name: String, value: T): IR.Result = directBind((name, value)) def rebind(p: NamedParam): IR.Result = { val name = p.name @@ -683,12 +683,12 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends if (ids.isEmpty) IR.Success else interpret("import " + ids.mkString(", ")) - def quietBind(p: NamedParam): IR.Result = beQuietDuring(bind(p)) - def bind(p: NamedParam): IR.Result = bind(p.name, p.tpe, p.value) - def bind[T: Manifest](name: String, value: T): IR.Result = bind((name, value)) - def bindSyntheticValue(x: Any): IR.Result = bindValue(freshInternalVarName(), x) - def bindValue(x: Any): IR.Result = bindValue(freshUserVarName(), x) - def bindValue(name: String, x: Any): IR.Result = bind(name, TypeStrings.fromValue(x), x) + def quietBind(p: NamedParam): IR.Result = beQuietDuring(bind(p)) + def bind(p: NamedParam): IR.Result = bind(p.name, p.tpe, p.value) + def bind[T: TypeTag](name: String, value: T): IR.Result = bind((name, value)) + def bindSyntheticValue(x: Any): IR.Result = bindValue(freshInternalVarName(), x) + def bindValue(x: Any): IR.Result = bindValue(freshUserVarName(), x) + def bindValue(name: String, x: Any): IR.Result = bind(name, TypeStrings.fromValue(x), x) /** Reset this interpreter, forgetting all user-specified requests. */ def reset() { @@ -1185,9 +1185,10 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends val termname = newTypeName(name) findName(termname) orElse getModuleIfDefined(termname) } - def types[T: ClassManifest] : Symbol = types(classManifest[T].erasure.getName) - def terms[T: ClassManifest] : Symbol = terms(classManifest[T].erasure.getName) - def apply[T: ClassManifest] : Symbol = apply(classManifest[T].erasure.getName) + // [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 classSymbols = allDefSymbols collect { case x: ClassSymbol => x } def methodSymbols = allDefSymbols collect { case x: MethodSymbol => x } diff --git a/src/compiler/scala/tools/nsc/interpreter/NamedParam.scala b/src/compiler/scala/tools/nsc/interpreter/NamedParam.scala index e2b1bf34d6..a3cbfffc3b 100644 --- a/src/compiler/scala/tools/nsc/interpreter/NamedParam.scala +++ b/src/compiler/scala/tools/nsc/interpreter/NamedParam.scala @@ -13,19 +13,19 @@ trait NamedParamCreator { protected def freshName: () => String def apply(name: String, tpe: String, value: Any): NamedParam = NamedParamClass(name, tpe, value) - def apply[T: Manifest](name: String, x: T): NamedParam = new Typed[T](name, x) - def apply[T: Manifest](x: T): NamedParam = apply(freshName(), x) + def apply[T: TypeTag](name: String, x: T): NamedParam = new Typed[T](name, x) + def apply[T: TypeTag](x: T): NamedParam = apply(freshName(), x) def clazz(name: String, x: Any): NamedParam = new Untyped(name, x) def clazz(x: Any): NamedParam = clazz(freshName(), x) - implicit def namedValue[T: Manifest](name: String, x: T): NamedParam = apply(name, x) - implicit def tuple[T: Manifest](pair: (String, T)): NamedParam = apply(pair._1, pair._2) + implicit def namedValue[T: TypeTag](name: String, x: T): NamedParam = apply(name, x) + implicit def tuple[T: TypeTag](pair: (String, T)): NamedParam = apply(pair._1, pair._2) } object NamedParam extends NamedParamCreator { - class Typed[T: Manifest](val name: String, val value: T) extends NamedParam { - val tpe = TypeStrings.fromManifest[T] + class Typed[T: TypeTag](val name: String, val value: T) extends NamedParam { + val tpe = TypeStrings.fromTag[T] } class Untyped(val name: String, val value: Any) extends NamedParam { val tpe = TypeStrings.fromValue(value) diff --git a/src/compiler/scala/tools/nsc/interpreter/Power.scala b/src/compiler/scala/tools/nsc/interpreter/Power.scala index 2cb034f7ab..01ace0e984 100644 --- a/src/compiler/scala/tools/nsc/interpreter/Power.scala +++ b/src/compiler/scala/tools/nsc/interpreter/Power.scala @@ -42,10 +42,10 @@ Lost after 18/flatten { /** A class for methods to be injected into the intp in power mode. */ -class Power[ReplValsImpl <: ReplVals : Manifest](val intp: IMain, replVals: ReplValsImpl) { +class Power[ReplValsImpl <: ReplVals : TypeTag](val intp: IMain, replVals: ReplValsImpl) { import intp.{ beQuietDuring, typeOfExpression, interpret, parse } import intp.global._ - import definitions.{ manifestToType, manifestToSymbol, getClassIfDefined, getModuleIfDefined } + import definitions.{ compilerTypeFromTag, compilerSymbolFromTag, getClassIfDefined, getModuleIfDefined } abstract class SymSlurper { def isKeep(sym: Symbol): Boolean @@ -162,7 +162,7 @@ class Power[ReplValsImpl <: ReplVals : Manifest](val intp: IMain, replVals: Repl } trait LowPriorityInternalInfo { - implicit def apply[T: Manifest] : InternalInfo[T] = new InternalInfo[T](None) + implicit def apply[T: TypeTag] : InternalInfo[T] = new InternalInfo[T](None) } object InternalInfo extends LowPriorityInternalInfo { } @@ -173,21 +173,21 @@ class Power[ReplValsImpl <: ReplVals : Manifest](val intp: IMain, replVals: Repl * of the conveniences exist on that wrapper. */ trait LowPriorityInternalInfoWrapper { - implicit def apply[T: Manifest] : InternalInfoWrapper[T] = new InternalInfoWrapper[T](None) + implicit def apply[T: TypeTag] : InternalInfoWrapper[T] = new InternalInfoWrapper[T](None) } object InternalInfoWrapper extends LowPriorityInternalInfoWrapper { } - class InternalInfoWrapper[T: Manifest](value: Option[T] = None) { + class InternalInfoWrapper[T: TypeTag](value: Option[T] = None) { def ? : InternalInfo[T] = new InternalInfo[T](value) } /** Todos... - * translate manifest type arguments into applied types + * translate tag type arguments into applied types * customizable symbol filter (had to hardcode no-spec to reduce noise) */ - class InternalInfo[T: Manifest](value: Option[T] = None) { - private def newInfo[U: Manifest](value: U): InternalInfo[U] = new InternalInfo[U](Some(value)) + class InternalInfo[T: TypeTag](value: Option[T] = None) { + private def newInfo[U: TypeTag](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" @@ -198,8 +198,8 @@ class Power[ReplValsImpl <: ReplVals : Manifest](val intp: IMain, replVals: Repl || s.isAnonOrRefinementClass || s.isAnonymousFunction ) - def symbol = manifestToSymbol(fullManifest) - def tpe = manifestToType(fullManifest) + def symbol = compilerSymbolFromTag(tag) + def tpe = compilerTypeFromTag(tag) def name = symbol.name def companion = symbol.companionSymbol def info = symbol.info @@ -226,8 +226,8 @@ class Power[ReplValsImpl <: ReplVals : Manifest](val intp: IMain, replVals: Repl def pkgClasses = pkgMembers filter (s => s.isClass && s.isDefinedInPackage) def pkgSymbols = new PackageSlurper(pkgClass).slurp() filterNot excludeMember - def fullManifest = manifest[T] - def erasure = fullManifest.erasure + def tag = typeTag[T] + def erasure = tag.erasure def shortClass = erasure.getName split "[$.]" last def baseClasses = tpe.baseClasses @@ -236,9 +236,9 @@ class Power[ReplValsImpl <: ReplVals : Manifest](val intp: IMain, replVals: Repl def ancestorDeclares(name: String) = ancestors filter (_.info member newTermName(name) ne NoSymbol) def baseTypes = tpe.baseTypeSeq.toList - def <:<[U: Manifest](other: U) = tpe <:< newInfo(other).tpe - def lub[U: Manifest](other: U) = intp.global.lub(List(tpe, newInfo(other).tpe)) - def glb[U: Manifest](other: U) = intp.global.glb(List(tpe, newInfo(other).tpe)) + def <:<[U: TypeTag](other: U) = tpe <:< newInfo(other).tpe + def lub[U: TypeTag](other: U) = intp.global.lub(List(tpe, newInfo(other).tpe)) + def glb[U: TypeTag](other: U) = intp.global.glb(List(tpe, newInfo(other).tpe)) override def toString = value match { case Some(x) => "%s (%s)".format(x, shortClass) @@ -366,7 +366,7 @@ class Power[ReplValsImpl <: ReplVals : Manifest](val intp: IMain, replVals: Repl implicit lazy val powerSymbolOrdering: Ordering[Symbol] = Ordering[Name] on (_.name) implicit lazy val powerTypeOrdering: Ordering[Type] = Ordering[Symbol] on (_.typeSymbol) - implicit def replInternalInfo[T: Manifest](x: T): InternalInfoWrapper[T] = new InternalInfoWrapper[T](Some(x)) + implicit def replInternalInfo[T: TypeTag](x: T): InternalInfoWrapper[T] = new InternalInfoWrapper[T](Some(x)) implicit def replEnhancedStrings(s: String): RichReplString = new RichReplString(s) implicit def replMultiPrinting[T: Prettifier](xs: TraversableOnce[T]): MultiPrettifierClass[T] = new MultiPrettifierClass[T](xs.toSeq) @@ -381,10 +381,13 @@ class Power[ReplValsImpl <: ReplVals : Manifest](val intp: IMain, replVals: Repl } trait ReplUtilities { - def module[T: Manifest] = getModuleIfDefined(manifest[T].erasure.getName stripSuffix nme.MODULE_SUFFIX_STRING) - def clazz[T: Manifest] = getClassIfDefined(manifest[T].erasure.getName) - def info[T: Manifest] = InternalInfo[T] - def ?[T: Manifest] = InternalInfo[T] + // [Eugene to Paul] needs review! + // def module[T: TypeTag] = getModuleIfDefined(typeTag[T].erasure.getName stripSuffix nme.MODULE_SUFFIX_STRING) + // def clazz[T: TypeTag] = getClassIfDefined(typeTag[T].erasure.getName) + def module[T: TypeTag] = typeTag[T].sym.suchThat(_.isPackage) + def clazz[T: TypeTag] = typeTag[T].sym.suchThat(_.isClass) + def info[T: TypeTag] = InternalInfo[T] + def ?[T: TypeTag] = InternalInfo[T] def url(s: String) = { try new URL(s) catch { case _: MalformedURLException => diff --git a/src/compiler/scala/tools/nsc/interpreter/ReplVals.scala b/src/compiler/scala/tools/nsc/interpreter/ReplVals.scala index 4efab7e260..280247f20c 100644 --- a/src/compiler/scala/tools/nsc/interpreter/ReplVals.scala +++ b/src/compiler/scala/tools/nsc/interpreter/ReplVals.scala @@ -6,6 +6,7 @@ package scala.tools.nsc package interpreter +import scala.reflect.{mirror => rm} import language.implicitConversions /** A class which the repl utilizes to expose predefined objects. @@ -39,8 +40,8 @@ class StdReplVals(final val r: ILoop) extends ReplVals { class ReplImplicits extends power.Implicits2 { import intp.global._ - private val manifestFn = ReplVals.mkManifestToType[intp.global.type](global) - implicit def mkManifestToType(sym: Symbol) = manifestFn(sym) + private val tagFn = ReplVals.mkCompilerTypeFromTag[intp.global.type](global) + implicit def mkCompilerTypeFromTag(sym: Symbol) = tagFn(sym) } final lazy val replImplicits = new ReplImplicits @@ -53,29 +54,29 @@ object ReplVals { * not being seen as the same type as bar.global.Type even though * the globals are the same. Dependent method types to the rescue. */ - def mkManifestToType[T <: Global](global: T) = { + def mkCompilerTypeFromTag[T <: Global](global: T) = { import global._ import definitions._ - /** We can't use definitions.manifestToType directly because we're passing + /** We can't use definitions.compilerTypeFromTag directly because we're passing * it to map and the compiler refuses to perform eta expansion on a method * with a dependent return type. (Can this be relaxed?) To get around this * I have this forwarder which widens the type and then cast the result back * to the dependent type. */ - def manifestToType(m: Manifest[_]): Global#Type = - definitions.manifestToType(m) + def compilerTypeFromTag(t: rm.TypeTag[_]): Global#Type = + definitions.compilerTypeFromTag(t) - class AppliedTypeFromManifests(sym: Symbol) { - def apply[M](implicit m1: Manifest[M]): Type = + class AppliedTypeFromTags(sym: Symbol) { + def apply[M](implicit m1: rm.TypeTag[M]): Type = if (sym eq NoSymbol) NoType - else appliedType(sym, manifestToType(m1).asInstanceOf[Type]) + else appliedType(sym, compilerTypeFromTag(m1).asInstanceOf[Type]) - def apply[M1, M2](implicit m1: Manifest[M1], m2: Manifest[M2]): Type = + def apply[M1, M2](implicit m1: rm.TypeTag[M1], m2: rm.TypeTag[M2]): Type = if (sym eq NoSymbol) NoType - else appliedType(sym, manifestToType(m1).asInstanceOf[Type], manifestToType(m2).asInstanceOf[Type]) + else appliedType(sym, compilerTypeFromTag(m1).asInstanceOf[Type], compilerTypeFromTag(m2).asInstanceOf[Type]) } - (sym: Symbol) => new AppliedTypeFromManifests(sym) + (sym: Symbol) => new AppliedTypeFromTags(sym) } } diff --git a/src/compiler/scala/tools/nsc/interpreter/RichClass.scala b/src/compiler/scala/tools/nsc/interpreter/RichClass.scala index 3d4d22063e..2e735e3b9b 100644 --- a/src/compiler/scala/tools/nsc/interpreter/RichClass.scala +++ b/src/compiler/scala/tools/nsc/interpreter/RichClass.scala @@ -6,10 +6,8 @@ package scala.tools.nsc package interpreter -import scala.reflect.{mirror => rm} - class RichClass[T](val clazz: Class[T]) { - def toManifest: Manifest[T] = Manifest[T](rm.classToType(clazz)) + def toTag: ClassTag[T] = ClassTag[T](clazz) def toTypeString: String = TypeStrings.fromClazz(clazz) // Sadly isAnonymousClass does not return true for scala anonymous @@ -21,9 +19,9 @@ class RichClass[T](val clazz: Class[T]) { ) /** It's not easy... to be... me... */ - def supermans: List[Manifest[_]] = supers map (_.toManifest) - def superNames: List[String] = supers map (_.getName) - def interfaces: List[JClass] = supers filter (_.isInterface) + def supermans: List[ClassTag[_]] = supers map (_.toTag) + def superNames: List[String] = supers map (_.getName) + def interfaces: List[JClass] = supers filter (_.isInterface) def hasAncestorName(f: String => Boolean) = superNames exists f def hasAncestor(f: JClass => Boolean) = supers exists f diff --git a/src/compiler/scala/tools/nsc/interpreter/TypeStrings.scala b/src/compiler/scala/tools/nsc/interpreter/TypeStrings.scala index 9ba75d9166..5d5123811e 100644 --- a/src/compiler/scala/tools/nsc/interpreter/TypeStrings.scala +++ b/src/compiler/scala/tools/nsc/interpreter/TypeStrings.scala @@ -192,8 +192,8 @@ trait TypeStrings { else enclClass.getName + "." + (name stripPrefix enclPre) ) } - def scalaName(m: ClassManifest[_]): String = scalaName(m.erasure) - def anyClass(x: Any): JClass = if (x == null) null else x.getClass + def scalaName(m: ClassTag[_]): String = scalaName(m.erasure) + def anyClass(x: Any): JClass = if (x == null) null else x.getClass private def brackets(tps: String*): String = if (tps.isEmpty) "" @@ -209,25 +209,25 @@ trait TypeStrings { brackets(clazz.getTypeParameters map tvarString: _*) } - private def tparamString[T: Manifest] : String = { + private def tparamString[T: TypeTag] : String = { // [Eugene to Paul] needs review!! - def typeArguments: List[rm.Type] = manifest[T].tpe.typeArguments + def typeArguments: List[rm.Type] = typeTag[T].tpe.typeArguments def typeVariables: List[java.lang.Class[_]] = typeArguments map (targ => rm.typeToClass(targ)) brackets(typeArguments map (jc => tvarString(List(jc))): _*) } /** Going for an overabundance of caution right now. Later these types - * can be a lot more precise, but right now the manifests have a habit of + * can be a lot more precise, but right now the tags have a habit of * introducing material which is not syntactically valid as scala source. * When this happens it breaks the repl. It would be nice if we mandated - * that manifest toString methods (or some other method, since it's bad + * that tag toString methods (or some other method, since it's bad * practice to rely on toString for correctness) generated the VALID string * representation of the type. */ - def fromTypedValue[T: Manifest](x: T): String = fromManifest[T] - def fromValue(value: Any): String = if (value == null) "Null" else fromClazz(anyClass(value)) - def fromClazz(clazz: JClass): String = scalaName(clazz) + tparamString(clazz) - def fromManifest[T: Manifest] : String = scalaName(manifest[T].erasure) + tparamString[T] + def fromTypedValue[T: TypeTag](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: TypeTag] : String = scalaName(typeTag[T].erasure) + tparamString[T] /** Reducing fully qualified noise for some common packages. */ diff --git a/src/compiler/scala/tools/nsc/io/ClassAndJarInfo.scala b/src/compiler/scala/tools/nsc/io/ClassAndJarInfo.scala index d0a0b17494..c9ed535841 100644 --- a/src/compiler/scala/tools/nsc/io/ClassAndJarInfo.scala +++ b/src/compiler/scala/tools/nsc/io/ClassAndJarInfo.scala @@ -13,9 +13,9 @@ import collection.JavaConverters._ /** A convenience class for finding the jar with the bytecode for * a given Class object and similar common tasks. */ -class ClassAndJarInfo[T: ClassManifest] { - val man = classManifest[T] - def clazz = man.erasure +class ClassAndJarInfo[T: ClassTag] { + val tag = classTag[T] + def clazz = tag.erasure def internalName = clazz.getName.replace('.', '/') def resourceURL = new URLClassLoader(Array[URL]()) getResource internalName + ".class" diff --git a/src/compiler/scala/tools/nsc/io/Pickler.scala b/src/compiler/scala/tools/nsc/io/Pickler.scala index 86c7ca7b9a..416b84eec6 100644 --- a/src/compiler/scala/tools/nsc/io/Pickler.scala +++ b/src/compiler/scala/tools/nsc/io/Pickler.scala @@ -416,7 +416,7 @@ object Pickler { iterPickler[T] .wrapped { Vector() ++ _ } { _.iterator } .labelled ("scala.Vector") /** A pickler for array values */ - implicit def array[T : ClassManifest : Pickler]: Pickler[Array[T]] = + implicit def array[T : ClassTag : Pickler]: Pickler[Array[T]] = iterPickler[T] .wrapped { _.toArray} { _.iterator } .labelled ("scala.Array") } diff --git a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala index a52e3b8bbe..c4dd9a2a36 100644 --- a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala +++ b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala @@ -183,8 +183,8 @@ class MutableSettings(val errorFn: String => Unit) * The class loader defining `T` should provide resources `app.class.path` * 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: Manifest]: Unit = - embeddedDefaults(implicitly[Manifest[T]].erasure.getClassLoader) + def embeddedDefaults[T: ClassTag]: Unit = + embeddedDefaults(classTag[T].erasure.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` diff --git a/src/compiler/scala/tools/nsc/transform/CleanUp.scala b/src/compiler/scala/tools/nsc/transform/CleanUp.scala index fd15d92e37..bf01e142c9 100644 --- a/src/compiler/scala/tools/nsc/transform/CleanUp.scala +++ b/src/compiler/scala/tools/nsc/transform/CleanUp.scala @@ -611,7 +611,7 @@ abstract class CleanUp extends Transform with ast.TreeDSL { val ntree = typedWithPos(tree.pos)(safeREF(staticFieldSym)) super.transform(ntree) - // This transform replaces Array(Predef.wrapArray(Array(...)), ) + // This transform replaces Array(Predef.wrapArray(Array(...)), ) // with just Array(...) case Apply(appMeth, List(Apply(wrapRefArrayMeth, List(array)), _)) if (wrapRefArrayMeth.symbol == Predef_wrapRefArray && diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala index c766b52159..338c39dc5f 100644 --- a/src/compiler/scala/tools/nsc/transform/Erasure.scala +++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala @@ -668,6 +668,7 @@ abstract class Erasure extends AddInterfaces */ private def adaptMember(tree: Tree): Tree = { //Console.println("adaptMember: " + tree); + val x = 2 + 2 tree match { case Apply(TypeApply(sel @ Select(qual, name), List(targ)), List()) if tree.symbol == Any_asInstanceOf => diff --git a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala index 8d26f66370..c13be0e39d 100644 --- a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala @@ -861,7 +861,7 @@ trait ContextErrors { // (note that this is not a compilation error, it's an artifact of implicit search algorithm) // normally, such "errors" are discarded by `isCyclicOrErroneous` in Implicits.scala // but in our case this won't work, because isCyclicOrErroneous catches CyclicReference exceptions - // while our error will manifest itself as a "recursive method needs a return type" + // while our error will present itself as a "recursive method needs a return type" // // hence we (together with reportTypeError in TypeDiagnostics) make sure that this CyclicReference // evades all the handlers on its way and successfully reaches `isCyclicOrErroneous` in Implicits diff --git a/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala b/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala index 9e06cbe0d3..4c71772929 100644 --- a/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala +++ b/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala @@ -8,6 +8,7 @@ package typechecker import symtab.Flags._ import scala.collection.{ mutable, immutable } import scala.tools.util.StringOps.{ ojoin } +import scala.reflect.{ mirror => rm } import language.higherKinds /** Logic related to method synthesis which involves cooperation between @@ -21,50 +22,51 @@ trait MethodSynthesis { import CODE._ object synthesisUtil { - type M[T] = Manifest[T] - type CM[T] = ClassManifest[T] + type CTT[T] = rm.ConcreteTypeTag[T] + type CT[T] = ClassTag[T] def ValOrDefDef(sym: Symbol, body: Tree) = if (sym.isLazy) ValDef(sym, body) else DefDef(sym, body) - def applyTypeInternal(manifests: List[M[_]]): Type = { + def applyTypeInternal(tags: List[CTT[_]]): Type = { // [Eugene to Paul] needs review!! - val symbols = manifests map manifestToSymbol + val symbols = tags map compilerSymbolFromTag val container :: args = symbols val tparams = container.typeConstructor.typeParams // Conservative at present - if manifests were more usable this could do a lot more. - require(symbols forall (_ ne NoSymbol), "Must find all manifests: " + symbols) + // [Eugene to Paul] all right, they are now. what do you have in mind? + require(symbols forall (_ ne NoSymbol), "Must find all tags: " + symbols) require(container.owner.isPackageClass, "Container must be a top-level class in a package: " + container) require(tparams.size == args.size, "Arguments must match type constructor arity: " + tparams + ", " + args) appliedType(container, args map (_.tpe): _*) } - def companionType[T](implicit m: M[T]) = + def companionType[T](implicit m: CTT[T]) = getRequiredModule(m.erasure.getName).tpe // Use these like `applyType[List, Int]` or `applyType[Map, Int, String]` - def applyType[CC](implicit m1: M[CC]): Type = + def applyType[CC](implicit m1: CTT[CC]): Type = applyTypeInternal(List(m1)) - def applyType[CC[X1], X1](implicit m1: M[CC[_]], m2: M[X1]): Type = + def applyType[CC[X1], X1](implicit m1: CTT[CC[_]], m2: CTT[X1]): Type = applyTypeInternal(List(m1, m2)) - def applyType[CC[X1, X2], X1, X2](implicit m1: M[CC[_,_]], m2: M[X1], m3: M[X2]): Type = + def applyType[CC[X1, X2], X1, X2](implicit m1: CTT[CC[_,_]], m2: CTT[X1], m3: CTT[X2]): Type = applyTypeInternal(List(m1, m2, m3)) - def applyType[CC[X1, X2, X3], X1, X2, X3](implicit m1: M[CC[_,_,_]], m2: M[X1], m3: M[X2], m4: M[X3]): Type = + def applyType[CC[X1, X2, X3], X1, X2, X3](implicit m1: CTT[CC[_,_,_]], m2: CTT[X1], m3: CTT[X2], m4: CTT[X3]): Type = applyTypeInternal(List(m1, m2, m3, m4)) - def newMethodType[F](owner: Symbol)(implicit m: Manifest[F]): Type = { - val fnSymbol = manifestToSymbol(m) - assert(fnSymbol isSubClass FunctionClass(m.tpe.typeArguments.size - 1), (owner, m)) + def newMethodType[F](owner: Symbol)(implicit t: CTT[F]): Type = { + val fnSymbol = compilerSymbolFromTag(t) + assert(fnSymbol isSubClass FunctionClass(t.tpe.typeArguments.size - 1), (owner, t)) // [Eugene to Paul] needs review!! // val symbols = m.typeArguments map (m => manifestToSymbol(m)) // val formals = symbols.init map (_.typeConstructor) - val formals = manifestToType(m).typeArguments + val formals = compilerTypeFromTag(t).typeArguments val params = owner newSyntheticValueParams formals MethodType(params, formals.last) } diff --git a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala index be269cf4b2..3d9fc67389 100644 --- a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala +++ b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala @@ -39,14 +39,14 @@ trait NamesDefaults { self: Analyzer => def isNamed(arg: Tree) = nameOf(arg).isDefined /** @param pos maps indices from old to new */ - def reorderArgs[T: ClassManifest](args: List[T], pos: Int => Int): List[T] = { + def reorderArgs[T: ArrayTag](args: List[T], pos: Int => Int): List[T] = { val res = new Array[T](args.length) foreachWithIndex(args)((arg, index) => res(pos(index)) = arg) res.toList } /** @param pos maps indices from new to old (!) */ - def reorderArgsInv[T: ClassManifest](args: List[T], pos: Int => Int): List[T] = { + def reorderArgsInv[T: ArrayTag](args: List[T], pos: Int => Int): List[T] = { val argsArray = args.toArray (argsArray.indices map (i => argsArray(pos(i)))).toList } diff --git a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala index 868c236ee9..31d064c824 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala @@ -74,7 +74,7 @@ trait SyntheticMethods extends ast.TreeDSL { // Option[Int] { def productIterator: Iterator[String] } // // appearing legitimately, but this breaks invariant places - // like Manifests and Arrays which are not robust and infer things + // like Tags and Arrays which are not robust and infer things // which they shouldn't. val accessorLub = ( if (opt.experimental) { diff --git a/src/compiler/scala/tools/nsc/util/ClassPath.scala b/src/compiler/scala/tools/nsc/util/ClassPath.scala index 5dd9ce0e02..48ec941b50 100644 --- a/src/compiler/scala/tools/nsc/util/ClassPath.scala +++ b/src/compiler/scala/tools/nsc/util/ClassPath.scala @@ -26,12 +26,12 @@ object ClassPath { def scalaLibrary = locate[Option[_]] def scalaCompiler = locate[Global] - def infoFor[T](value: T) = info(value.getClass) - def info[T](clazz: Class[T]) = new ClassAndJarInfo()(ClassManifest[T](clazz)) - def info[T: ClassManifest] = new ClassAndJarInfo[T] - def locate[T: ClassManifest] = info[T].rootClasspath - def locateJar[T: ClassManifest] = info[T].rootPossibles find (x => isJarOrZip(x)) map (x => File(x)) - def locateDir[T: ClassManifest] = info[T].rootPossibles find (_.isDirectory) map (_.toDirectory) + def infoFor[T](value: T) = info(value.getClass) + def info[T](clazz: Class[T]) = new ClassAndJarInfo()(ClassTag[T](clazz)) + def info[T: ClassTag] = new ClassAndJarInfo[T] + def locate[T: ClassTag] = info[T].rootClasspath + def locateJar[T: ClassTag] = info[T].rootPossibles find (x => isJarOrZip(x)) map (x => File(x)) + def locateDir[T: ClassTag] = info[T].rootPossibles find (_.isDirectory) map (_.toDirectory) /** Expand single path entry */ private def expandS(pattern: String): List[String] = { diff --git a/src/compiler/scala/tools/nsc/util/ScalaClassLoader.scala b/src/compiler/scala/tools/nsc/util/ScalaClassLoader.scala index 700fe0c1a6..120cceb238 100644 --- a/src/compiler/scala/tools/nsc/util/ScalaClassLoader.scala +++ b/src/compiler/scala/tools/nsc/util/ScalaClassLoader.scala @@ -67,8 +67,8 @@ trait ScalaClassLoader extends JClassLoader { result } - def constructorsOf[T <: AnyRef : Manifest]: List[Constructor[T]] = - manifest[T].erasure.getConstructors.toList map (_.asInstanceOf[Constructor[T]]) + def constructorsOf[T <: AnyRef : ClassTag]: List[Constructor[T]] = + classTag[T].erasure.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 { @@ -125,9 +125,9 @@ object ScalaClassLoader { def bootLoader = apply(null) def contextChain = loaderChain(contextLoader) - def pathToErasure[T: ClassManifest] = pathToClass(classManifest[T].erasure) - def pathToClass(clazz: Class[_]) = clazz.getName.replace('.', JFile.separatorChar) + ".class" - def locate[T: ClassManifest] = contextLoader getResource pathToErasure[T] + def pathToErasure[T: ClassTag] = pathToClass(classTag[T].erasure) + def pathToClass(clazz: Class[_]) = clazz.getName.replace('.', JFile.separatorChar) + ".class" + def locate[T: ClassTag] = contextLoader getResource pathToErasure[T] /** Tries to guess the classpath by type matching the context classloader * and its parents, looking for any classloaders which will reveal their diff --git a/src/compiler/scala/tools/reflect/Invoked.scala b/src/compiler/scala/tools/reflect/Invoked.scala index 30c6201a0d..516c6b9bf6 100644 --- a/src/compiler/scala/tools/reflect/Invoked.scala +++ b/src/compiler/scala/tools/reflect/Invoked.scala @@ -16,7 +16,7 @@ class Invoked private (val proxy: AnyRef, val m: Method, val args: List[AnyRef]) def name = m.getName def arity = m.getParameterTypes.size def returnType = m.getReturnType - def returns[T: Manifest] = returnType == manifest[T].erasure + def returns[T: ClassTag] = returnType == classTag[T].erasure def invokeOn(target: AnyRef) = m.invoke(target, args: _*) def isObjectMethod = Set("toString", "equals", "hashCode") contains name diff --git a/src/compiler/scala/tools/reflect/UniversalFn.scala b/src/compiler/scala/tools/reflect/UniversalFn.scala index 9ccd580560..b0c2a19021 100644 --- a/src/compiler/scala/tools/reflect/UniversalFn.scala +++ b/src/compiler/scala/tools/reflect/UniversalFn.scala @@ -26,8 +26,8 @@ class UniversalFn private (val closure: AnyRef, val method: Method) extends (Seq * them to this universal function. Will throw an exception in the * face of any bad data. */ - def as[T: Manifest] : T = { - val clazz = manifest[T].erasure + def as[T: ClassTag] : T = { + val clazz = classTag[T].erasure require(clazz.isInterface, "Type argument must be an interface.") val interfaceMethods = clazz.getDeclaredMethods.toSet diff --git a/src/compiler/scala/tools/reflect/package.scala b/src/compiler/scala/tools/reflect/package.scala index 744bf9b226..0b0c0905cb 100644 --- a/src/compiler/scala/tools/reflect/package.scala +++ b/src/compiler/scala/tools/reflect/package.scala @@ -7,7 +7,6 @@ package scala.tools import java.lang.reflect.Method import java.{ lang => jl } -import scala.reflect.{mirror => rm} package object reflect { def nameAndArity(m: Method) = (m.getName, m.getParameterTypes.size) @@ -28,17 +27,17 @@ package object reflect { } } - def zeroOfClass(clazz: Class[_]) = zeroOf(Manifest(rm.classToType(clazz))) - def zeroOf[T](implicit m: Manifest[T]): AnyRef = { - if (m == manifest[Boolean] || m == manifest[jl.Boolean]) false: jl.Boolean - else if (m == manifest[Unit] || m == manifest[jl.Void] || m == manifest[scala.runtime.BoxedUnit]) scala.runtime.BoxedUnit.UNIT - else if (m == manifest[Char] || m == manifest[jl.Character]) 0.toChar: jl.Character - else if (m == manifest[Byte] || m == manifest[jl.Byte]) 0.toByte: jl.Byte - else if (m == manifest[Short] || m == manifest[jl.Short]) 0.toShort: jl.Short - else if (m == manifest[Int] || m == manifest[jl.Integer]) 0: jl.Integer - else if (m == manifest[Long] || m == manifest[jl.Long]) 0l: jl.Long - else if (m == manifest[Float] || m == manifest[jl.Float]) 0f: jl.Float - else if (m == manifest[Double] || m == manifest[jl.Double]) 0d: jl.Double + def zeroOfClass(clazz: Class[_]) = zeroOf(ClassTag(clazz)) + def zeroOf[T](implicit t: ClassTag[T]): AnyRef = { + if (t == classTag[Boolean] || t == classTag[jl.Boolean]) false: jl.Boolean + else if (t == classTag[Unit] || t == classTag[jl.Void] || t == classTag[scala.runtime.BoxedUnit]) scala.runtime.BoxedUnit.UNIT + else if (t == classTag[Char] || t == classTag[jl.Character]) 0.toChar: jl.Character + else if (t == classTag[Byte] || t == classTag[jl.Byte]) 0.toByte: jl.Byte + else if (t == classTag[Short] || t == classTag[jl.Short]) 0.toShort: jl.Short + else if (t == classTag[Int] || t == classTag[jl.Integer]) 0: jl.Integer + else if (t == classTag[Long] || t == classTag[jl.Long]) 0l: jl.Long + else if (t == classTag[Float] || t == classTag[jl.Float]) 0f: jl.Float + else if (t == classTag[Double] || t == classTag[jl.Double]) 0d: jl.Double else null } } -- cgit v1.2.3