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 +- src/detach/library/scala/remoting/Channel.scala | 32 +- src/library/scala/Array.scala | 54 +- .../scala/collection/GenTraversableOnce.scala | 6 +- src/library/scala/collection/Traversable.scala | 2 +- src/library/scala/collection/TraversableOnce.scala | 2 +- .../scala/collection/TraversableProxyLike.scala | 2 +- .../generic/ArrayTagTraversableFactory.scala | 31 + .../generic/ClassManifestTraversableFactory.scala | 31 - .../generic/GenericArrayTagCompanion.scala | 32 + .../GenericArrayTagTraversableTemplate.scala | 30 + .../generic/GenericClassManifestCompanion.scala | 32 - .../GenericClassManifestTraversableTemplate.scala | 26 - .../collection/generic/TraversableForwarder.scala | 2 +- src/library/scala/collection/generic/package.scala | 9 + .../scala/collection/immutable/PagedSeq.scala | 10 +- .../scala/collection/immutable/StringLike.scala | 2 +- .../collection/interfaces/IterableMethods.scala | 1 - .../scala/collection/interfaces/SeqMethods.scala | 1 - .../scala/collection/interfaces/SetMethods.scala | 1 - .../interfaces/TraversableOnceMethods.scala | 2 +- .../scala/collection/mutable/ArrayBuilder.scala | 17 +- .../scala/collection/mutable/ArrayOps.scala | 27 +- .../scala/collection/mutable/ArrayStack.scala | 2 +- .../scala/collection/mutable/FlatArray.scala | 28 +- .../scala/collection/mutable/UnrolledBuffer.scala | 14 +- .../scala/collection/mutable/WrappedArray.scala | 43 +- .../collection/mutable/WrappedArrayBuilder.scala | 16 +- .../collection/parallel/ParIterableLike.scala | 20 +- .../collection/parallel/mutable/ParArray.scala | 4 +- .../mutable/UnrolledParArrayCombiner.scala | 2 +- src/library/scala/concurrent/Future.scala | 36 +- src/library/scala/reflect/DummyMirror.scala | 3 +- .../scala/reflect/api/AnnotationInfos.scala | 2 +- src/library/scala/util/Marshal.scala | 2 +- src/library/scala/util/Sorting.scala | 16 +- src/library/scala/util/control/Exception.scala | 6 +- src/partest/scala/tools/partest/CompilerTest.scala | 11 +- src/partest/scala/tools/partest/SigTest.scala | 24 +- src/scalacheck/org/scalacheck/Arbitrary.scala | 2 +- src/scalacheck/org/scalacheck/util/Buildable.scala | 2 +- src/swing/scala/swing/Font.scala.disabled | 32 +- .../parallel/benchmarks/arrays/Resetting.scala | 8 +- .../parallel_array/MatrixMultiplication.scala | 26 +- test/disabled/presentation/akka.check | 24 +- .../presentation/akka/src/akka/actor/Actor.scala | 4 +- .../akka/src/akka/actor/ActorRef.scala | 16 +- .../akka/src/akka/actor/ActorRegistry.scala | 30 +- .../akka/src/akka/event/EventHandler.scala | 4 +- .../src/akka/remoteinterface/RemoteInterface.scala | 4 +- .../presentation/akka/src/akka/util/Helpers.scala | 2 +- test/disabled/presentation/simple-tests.check | 2 +- test/files/jvm/manifests-new.check | 58 ++ test/files/jvm/manifests-new.scala | 109 ++++ test/files/jvm/manifests.check | 56 -- test/files/jvm/manifests.scala | 112 ---- test/files/jvm/serialization-new.check | 313 ++++++++++ test/files/jvm/serialization-new.scala | 651 +++++++++++++++++++++ test/files/jvm/serialization.check | 313 ---------- test/files/jvm/serialization.scala | 651 --------------------- test/files/neg/t2386.check | 4 - test/files/neg/t2386.scala | 3 - test/files/neg/t3692-new.check | 4 + test/files/neg/t3692-new.flags | 1 + test/files/neg/t3692-new.scala | 19 + test/files/neg/t3692.check | 11 - test/files/neg/t3692.flags | 1 - test/files/neg/t3692.scala | 19 - test/files/neg/t5452-new.check | 8 + test/files/neg/t5452-new.scala | 29 + test/files/neg/t5452.check | 8 - test/files/neg/t5452.scala | 29 - test/files/pos/contextbounds-implicits-new.scala | 8 + test/files/pos/contextbounds-implicits.scala | 8 - test/files/pos/implicits-new.scala | 89 +++ test/files/pos/implicits.scala | 89 --- test/files/pos/manifest1-new.scala | 21 + test/files/pos/manifest1.scala | 21 - test/files/pos/nothing_manifest_disambig-new.scala | 10 + test/files/pos/nothing_manifest_disambig.scala | 10 - test/files/pos/spec-constr-new.scala | 7 + test/files/pos/spec-constr.scala | 7 - test/files/pos/spec-doubledef-new.scala | 28 + test/files/pos/spec-doubledef.scala | 28 - test/files/pos/spec-fields-new.scala | 10 + test/files/pos/spec-fields.scala | 10 - test/files/pos/spec-params-new.scala | 32 + test/files/pos/spec-params.scala | 32 - test/files/pos/spec-sparsearray-new.scala | 24 + test/files/pos/spec-sparsearray.scala | 24 - test/files/pos/t1381-new.scala | 31 + test/files/pos/t1381.scala | 31 - test/files/pos/t2795-new.scala | 17 + test/files/pos/t2795.scala | 17 - test/files/pos/t3363-new.scala | 18 + test/files/pos/t3363.scala | 18 - test/files/pos/t3498-new.scala | 15 + test/files/pos/t3498.scala | 15 - test/files/presentation/ide-bug-1000531.check | 2 +- test/files/run/arrayclone-new.scala | 106 ++++ test/files/run/arrayclone.scala | 106 ---- test/files/run/ctries-new/DumbHash.scala | 14 + test/files/run/ctries-new/Wrap.scala | 9 + test/files/run/ctries-new/concmap.scala | 188 ++++++ test/files/run/ctries-new/iterator.scala | 289 +++++++++ test/files/run/ctries-new/lnode.scala | 61 ++ test/files/run/ctries-new/main.scala | 45 ++ test/files/run/ctries-new/snapshot.scala | 267 +++++++++ test/files/run/ctries/DumbHash.scala | 14 - test/files/run/ctries/Wrap.scala | 9 - test/files/run/ctries/concmap.scala | 188 ------ test/files/run/ctries/iterator.scala | 289 --------- test/files/run/ctries/lnode.scala | 61 -- test/files/run/ctries/main.scala | 45 -- test/files/run/ctries/snapshot.scala | 267 --------- test/files/run/existentials3-new.check | 24 + test/files/run/existentials3-new.scala | 78 +++ test/files/run/existentials3.check | 24 - test/files/run/existentials3.scala | 79 --- test/files/run/getClassTest-new.check | 18 + test/files/run/getClassTest-new.scala | 66 +++ test/files/run/getClassTest.check | 18 - test/files/run/getClassTest.scala | 66 --- test/files/run/manifests-new.scala | 147 +++++ test/files/run/manifests.scala | 149 ----- test/files/run/patmat_unapp_abstype-new.check | 4 + test/files/run/patmat_unapp_abstype-new.flags | 1 + test/files/run/patmat_unapp_abstype-new.scala | 83 +++ test/files/run/patmat_unapp_abstype.check | 4 - test/files/run/patmat_unapp_abstype.flags | 1 - test/files/run/patmat_unapp_abstype.scala | 83 --- test/files/run/primitive-sigs-2-new.check | 7 + test/files/run/primitive-sigs-2-new.scala | 31 + test/files/run/primitive-sigs-2.check | 7 - test/files/run/primitive-sigs-2.scala | 39 -- test/files/run/reflection-implClass-new.scala | 38 ++ test/files/run/reflection-implClass.scala | 38 -- test/files/run/reify_implicits-new.check | 1 + test/files/run/reify_implicits-new.scala | 14 + test/files/run/reify_implicits.check | 1 - test/files/run/reify_implicits.scala | 14 - test/files/run/repl-power.check | 64 +- test/files/run/repl-power.scala | 3 +- test/files/run/t0421-new.check | 3 + test/files/run/t0421-new.scala | 30 + test/files/run/t0421.check | 3 - test/files/run/t0421.scala | 30 - test/files/run/t0677-new.scala | 8 + test/files/run/t0677.scala | 8 - test/files/run/t1195-new.check | 6 + test/files/run/t1195-new.scala | 26 + test/files/run/t1195.check | 6 - test/files/run/t1195.scala | 26 - test/files/run/t2236-new.scala | 17 + test/files/run/t2236.scala | 17 - test/files/run/t2386-new.check | 2 + test/files/run/t2386-new.scala | 5 + test/files/run/t3507-new.check | 1 + test/files/run/t3507-new.scala | 15 + test/files/run/t3507.check | 1 - test/files/run/t3507.scala | 15 - test/files/run/t3758.check | 6 - test/files/run/t3758.scala | 10 - test/files/run/t4110-new.check | 2 + test/files/run/t4110-new.scala | 11 + test/files/run/t4110.check | 2 - test/files/run/t4110.scala | 11 - test/files/scalacheck/array-new.scala | 36 ++ test/files/scalacheck/array.scala | 37 -- test/files/specialized/spec-matrix-new.check | 2 + test/files/specialized/spec-matrix-new.scala | 80 +++ test/files/specialized/spec-matrix.check | 2 - test/files/specialized/spec-matrix.scala | 80 --- test/pending/pos/inference.scala | 20 +- test/pending/shootout/meteor.scala | 64 +- test/scaladoc/resources/implicits-base-res.scala | 3 +- 207 files changed, 3851 insertions(+), 3855 deletions(-) create mode 100644 src/library/scala/collection/generic/ArrayTagTraversableFactory.scala delete mode 100644 src/library/scala/collection/generic/ClassManifestTraversableFactory.scala create mode 100644 src/library/scala/collection/generic/GenericArrayTagCompanion.scala create mode 100644 src/library/scala/collection/generic/GenericArrayTagTraversableTemplate.scala delete mode 100644 src/library/scala/collection/generic/GenericClassManifestCompanion.scala delete mode 100644 src/library/scala/collection/generic/GenericClassManifestTraversableTemplate.scala create mode 100644 test/files/jvm/manifests-new.check create mode 100644 test/files/jvm/manifests-new.scala delete mode 100644 test/files/jvm/manifests.check delete mode 100644 test/files/jvm/manifests.scala create mode 100644 test/files/jvm/serialization-new.check create mode 100644 test/files/jvm/serialization-new.scala delete mode 100644 test/files/jvm/serialization.check delete mode 100644 test/files/jvm/serialization.scala delete mode 100644 test/files/neg/t2386.check delete mode 100644 test/files/neg/t2386.scala create mode 100644 test/files/neg/t3692-new.check create mode 100644 test/files/neg/t3692-new.flags create mode 100644 test/files/neg/t3692-new.scala delete mode 100644 test/files/neg/t3692.check delete mode 100644 test/files/neg/t3692.flags delete mode 100644 test/files/neg/t3692.scala create mode 100644 test/files/neg/t5452-new.check create mode 100644 test/files/neg/t5452-new.scala delete mode 100644 test/files/neg/t5452.check delete mode 100644 test/files/neg/t5452.scala create mode 100644 test/files/pos/contextbounds-implicits-new.scala delete mode 100644 test/files/pos/contextbounds-implicits.scala create mode 100644 test/files/pos/implicits-new.scala delete mode 100644 test/files/pos/implicits.scala create mode 100644 test/files/pos/manifest1-new.scala delete mode 100644 test/files/pos/manifest1.scala create mode 100644 test/files/pos/nothing_manifest_disambig-new.scala delete mode 100644 test/files/pos/nothing_manifest_disambig.scala create mode 100644 test/files/pos/spec-constr-new.scala delete mode 100644 test/files/pos/spec-constr.scala create mode 100644 test/files/pos/spec-doubledef-new.scala delete mode 100644 test/files/pos/spec-doubledef.scala create mode 100644 test/files/pos/spec-fields-new.scala delete mode 100644 test/files/pos/spec-fields.scala create mode 100644 test/files/pos/spec-params-new.scala delete mode 100644 test/files/pos/spec-params.scala create mode 100644 test/files/pos/spec-sparsearray-new.scala delete mode 100644 test/files/pos/spec-sparsearray.scala create mode 100644 test/files/pos/t1381-new.scala delete mode 100644 test/files/pos/t1381.scala create mode 100644 test/files/pos/t2795-new.scala delete mode 100644 test/files/pos/t2795.scala create mode 100644 test/files/pos/t3363-new.scala delete mode 100755 test/files/pos/t3363.scala create mode 100644 test/files/pos/t3498-new.scala delete mode 100644 test/files/pos/t3498.scala create mode 100644 test/files/run/arrayclone-new.scala delete mode 100644 test/files/run/arrayclone.scala create mode 100644 test/files/run/ctries-new/DumbHash.scala create mode 100644 test/files/run/ctries-new/Wrap.scala create mode 100644 test/files/run/ctries-new/concmap.scala create mode 100644 test/files/run/ctries-new/iterator.scala create mode 100644 test/files/run/ctries-new/lnode.scala create mode 100644 test/files/run/ctries-new/main.scala create mode 100644 test/files/run/ctries-new/snapshot.scala delete mode 100644 test/files/run/ctries/DumbHash.scala delete mode 100644 test/files/run/ctries/Wrap.scala delete mode 100644 test/files/run/ctries/concmap.scala delete mode 100644 test/files/run/ctries/iterator.scala delete mode 100644 test/files/run/ctries/lnode.scala delete mode 100644 test/files/run/ctries/main.scala delete mode 100644 test/files/run/ctries/snapshot.scala create mode 100644 test/files/run/existentials3-new.check create mode 100644 test/files/run/existentials3-new.scala delete mode 100644 test/files/run/existentials3.check delete mode 100644 test/files/run/existentials3.scala create mode 100644 test/files/run/getClassTest-new.check create mode 100644 test/files/run/getClassTest-new.scala delete mode 100644 test/files/run/getClassTest.check delete mode 100644 test/files/run/getClassTest.scala create mode 100644 test/files/run/manifests-new.scala delete mode 100644 test/files/run/manifests.scala create mode 100644 test/files/run/patmat_unapp_abstype-new.check create mode 100644 test/files/run/patmat_unapp_abstype-new.flags create mode 100644 test/files/run/patmat_unapp_abstype-new.scala delete mode 100644 test/files/run/patmat_unapp_abstype.check delete mode 100644 test/files/run/patmat_unapp_abstype.flags delete mode 100644 test/files/run/patmat_unapp_abstype.scala create mode 100644 test/files/run/primitive-sigs-2-new.check create mode 100644 test/files/run/primitive-sigs-2-new.scala delete mode 100644 test/files/run/primitive-sigs-2.check delete mode 100644 test/files/run/primitive-sigs-2.scala create mode 100644 test/files/run/reflection-implClass-new.scala delete mode 100644 test/files/run/reflection-implClass.scala create mode 100644 test/files/run/reify_implicits-new.check create mode 100644 test/files/run/reify_implicits-new.scala delete mode 100644 test/files/run/reify_implicits.check delete mode 100644 test/files/run/reify_implicits.scala create mode 100644 test/files/run/t0421-new.check create mode 100644 test/files/run/t0421-new.scala delete mode 100644 test/files/run/t0421.check delete mode 100644 test/files/run/t0421.scala create mode 100644 test/files/run/t0677-new.scala delete mode 100644 test/files/run/t0677.scala create mode 100644 test/files/run/t1195-new.check create mode 100644 test/files/run/t1195-new.scala delete mode 100644 test/files/run/t1195.check delete mode 100644 test/files/run/t1195.scala create mode 100644 test/files/run/t2236-new.scala delete mode 100755 test/files/run/t2236.scala create mode 100644 test/files/run/t2386-new.check create mode 100644 test/files/run/t2386-new.scala create mode 100644 test/files/run/t3507-new.check create mode 100644 test/files/run/t3507-new.scala delete mode 100644 test/files/run/t3507.check delete mode 100644 test/files/run/t3507.scala delete mode 100644 test/files/run/t3758.check delete mode 100644 test/files/run/t3758.scala create mode 100644 test/files/run/t4110-new.check create mode 100644 test/files/run/t4110-new.scala delete mode 100644 test/files/run/t4110.check delete mode 100644 test/files/run/t4110.scala create mode 100644 test/files/scalacheck/array-new.scala delete mode 100644 test/files/scalacheck/array.scala create mode 100644 test/files/specialized/spec-matrix-new.check create mode 100644 test/files/specialized/spec-matrix-new.scala delete mode 100644 test/files/specialized/spec-matrix.check delete mode 100644 test/files/specialized/spec-matrix.scala 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 } } diff --git a/src/detach/library/scala/remoting/Channel.scala b/src/detach/library/scala/remoting/Channel.scala index 541e45a477..54b8fb100e 100644 --- a/src/detach/library/scala/remoting/Channel.scala +++ b/src/detach/library/scala/remoting/Channel.scala @@ -116,20 +116,20 @@ class Channel protected (socket: Socket) { * the expected type. */ @throws(classOf[ChannelException]) - def receive[T](implicit expected: reflect.Manifest[T]): T = { - val found = in.readObject().asInstanceOf[reflect.Manifest[_]] + def receive[T](implicit expected: reflect.ClassTag[T]): T = { + val found = in.readObject().asInstanceOf[reflect.ClassTag[_]] info("receive: found="+found+", expected="+expected) - import scala.reflect.Manifest + import scala.reflect.ClassTag val x = found match { - case Manifest.Unit => () - case Manifest.Boolean => in.readBoolean() - case Manifest.Byte => in.readByte() - case Manifest.Char => in.readChar() - case Manifest.Short => in.readShort() - case Manifest.Int => in.readInt() - case Manifest.Long => in.readLong() - case Manifest.Float => in.readFloat() - case Manifest.Double => in.readDouble() + case ClassTag.Unit => () + case ClassTag.Boolean => in.readBoolean() + case ClassTag.Byte => in.readByte() + case ClassTag.Char => in.readChar() + case ClassTag.Short => in.readShort() + case ClassTag.Int => in.readInt() + case ClassTag.Long => in.readLong() + case ClassTag.Float => in.readFloat() + case ClassTag.Double => in.readDouble() case _ => in.readObject() } val res = if (found <:< expected) @@ -144,12 +144,12 @@ class Channel protected (socket: Socket) { /** ? method may throw either an * ClassNotFoundException or an IOException. */ - def ?[T](implicit m: reflect.Manifest[T]): T = receive[T](m) + def ?[T](implicit t: reflect.ClassTag[T]): T = receive[T](t) /** send method may throw an IOException. */ - def send[T](x: T)(implicit m: reflect.Manifest[T]) { - out writeObject m + def send[T](x: T)(implicit t: reflect.ClassTag[T]) { + out writeObject t x match { case x: Unit => // nop case x: Boolean => out writeBoolean x @@ -168,7 +168,7 @@ class Channel protected (socket: Socket) { /** ! method may throw an IOException. */ - def ![T](x: T)(implicit m: reflect.Manifest[T]) { send(x)(m) } + def ![T](x: T)(implicit m: reflect.ClassTag[T]) { send(x)(m) } def close() { try { socket.close() } diff --git a/src/library/scala/Array.scala b/src/library/scala/Array.scala index 5b8ebde308..fd61cfd0a1 100644 --- a/src/library/scala/Array.scala +++ b/src/library/scala/Array.scala @@ -12,17 +12,17 @@ import scala.collection.generic._ import scala.collection.{ mutable, immutable } import mutable.{ ArrayBuilder, ArraySeq } import compat.Platform.arraycopy -import scala.reflect.ClassManifest +import scala.reflect.ArrayTag import scala.runtime.ScalaRunTime.{ array_apply, array_update } /** Contains a fallback builder for arrays when the element type - * does not have a class manifest. In that case a generic array is built. + * does not have a class tag. In that case a generic array is built. */ class FallbackArrayBuilding { /** A builder factory that generates a generic array. * Called instead of `Array.newBuilder` if the element type of an array - * does not have a class manifest. Note that fallbackBuilder factory + * does not have a class tag. Note that fallbackBuilder factory * needs an implicit parameter (otherwise it would not be dominated in * implicit search by `Array.canBuildFrom`). We make sure that * implicit search is always successful. @@ -48,16 +48,16 @@ class FallbackArrayBuilding { * @version 1.0 */ object Array extends FallbackArrayBuilding { - implicit def canBuildFrom[T](implicit m: ClassManifest[T]): CanBuildFrom[Array[_], T, Array[T]] = + implicit def canBuildFrom[T](implicit t: ArrayTag[T]): CanBuildFrom[Array[_], T, Array[T]] = new CanBuildFrom[Array[_], T, Array[T]] { - def apply(from: Array[_]) = ArrayBuilder.make[T]()(m) - def apply() = ArrayBuilder.make[T]()(m) + def apply(from: Array[_]) = ArrayBuilder.make[T]()(t) + def apply() = ArrayBuilder.make[T]()(t) } /** * Returns a new [[scala.collection.mutable.ArrayBuilder]]. */ - def newBuilder[T](implicit m: ClassManifest[T]): ArrayBuilder[T] = ArrayBuilder.make[T]()(m) + def newBuilder[T](implicit t: ArrayTag[T]): ArrayBuilder[T] = ArrayBuilder.make[T]()(t) private def slowcopy(src : AnyRef, srcPos : Int, @@ -98,14 +98,14 @@ object Array extends FallbackArrayBuilding { } /** Returns an array of length 0 */ - def empty[T: ClassManifest]: Array[T] = new Array[T](0) + def empty[T: ArrayTag]: Array[T] = new Array[T](0) /** Creates an array with given elements. * * @param xs the elements to put in the array * @return an array containing all elements from xs. */ - def apply[T: ClassManifest](xs: T*): Array[T] = { + def apply[T: ArrayTag](xs: T*): Array[T] = { val array = new Array[T](xs.length) var i = 0 for (x <- xs.iterator) { array(i) = x; i += 1 } @@ -194,23 +194,23 @@ object Array extends FallbackArrayBuilding { } /** Creates array with given dimensions */ - def ofDim[T: ClassManifest](n1: Int): Array[T] = + def ofDim[T: ArrayTag](n1: Int): Array[T] = new Array[T](n1) /** Creates a 2-dimensional array */ - def ofDim[T: ClassManifest](n1: Int, n2: Int): Array[Array[T]] = { + def ofDim[T: ArrayTag](n1: Int, n2: Int): Array[Array[T]] = { val arr: Array[Array[T]] = (new Array[Array[T]](n1): Array[Array[T]]) for (i <- 0 until n1) arr(i) = new Array[T](n2) arr // tabulate(n1)(_ => ofDim[T](n2)) } /** Creates a 3-dimensional array */ - def ofDim[T: ClassManifest](n1: Int, n2: Int, n3: Int): Array[Array[Array[T]]] = + def ofDim[T: ArrayTag](n1: Int, n2: Int, n3: Int): Array[Array[Array[T]]] = tabulate(n1)(_ => ofDim[T](n2, n3)) /** Creates a 4-dimensional array */ - def ofDim[T: ClassManifest](n1: Int, n2: Int, n3: Int, n4: Int): Array[Array[Array[Array[T]]]] = + def ofDim[T: ArrayTag](n1: Int, n2: Int, n3: Int, n4: Int): Array[Array[Array[Array[T]]]] = tabulate(n1)(_ => ofDim[T](n2, n3, n4)) /** Creates a 5-dimensional array */ - def ofDim[T: ClassManifest](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int): Array[Array[Array[Array[Array[T]]]]] = + def ofDim[T: ArrayTag](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int): Array[Array[Array[Array[Array[T]]]]] = tabulate(n1)(_ => ofDim[T](n2, n3, n4, n5)) /** Concatenates all arrays into a single array. @@ -218,7 +218,7 @@ object Array extends FallbackArrayBuilding { * @param xss the given arrays * @return the array created from concatenating `xss` */ - def concat[T: ClassManifest](xss: Array[T]*): Array[T] = { + def concat[T: ArrayTag](xss: Array[T]*): Array[T] = { val b = newBuilder[T] b.sizeHint(xss.map(_.size).sum) for (xs <- xss) b ++= xs @@ -239,7 +239,7 @@ object Array extends FallbackArrayBuilding { * @return an Array of size n, where each element contains the result of computing * `elem`. */ - def fill[T: ClassManifest](n: Int)(elem: => T): Array[T] = { + def fill[T: ArrayTag](n: Int)(elem: => T): Array[T] = { val b = newBuilder[T] b.sizeHint(n) var i = 0 @@ -257,7 +257,7 @@ object Array extends FallbackArrayBuilding { * @param n2 the number of elements in the 2nd dimension * @param elem the element computation */ - def fill[T: ClassManifest](n1: Int, n2: Int)(elem: => T): Array[Array[T]] = + def fill[T: ArrayTag](n1: Int, n2: Int)(elem: => T): Array[Array[T]] = tabulate(n1)(_ => fill(n2)(elem)) /** Returns a three-dimensional array that contains the results of some element @@ -268,7 +268,7 @@ object Array extends FallbackArrayBuilding { * @param n3 the number of elements in the 3nd dimension * @param elem the element computation */ - def fill[T: ClassManifest](n1: Int, n2: Int, n3: Int)(elem: => T): Array[Array[Array[T]]] = + def fill[T: ArrayTag](n1: Int, n2: Int, n3: Int)(elem: => T): Array[Array[Array[T]]] = tabulate(n1)(_ => fill(n2, n3)(elem)) /** Returns a four-dimensional array that contains the results of some element @@ -280,7 +280,7 @@ object Array extends FallbackArrayBuilding { * @param n4 the number of elements in the 4th dimension * @param elem the element computation */ - def fill[T: ClassManifest](n1: Int, n2: Int, n3: Int, n4: Int)(elem: => T): Array[Array[Array[Array[T]]]] = + def fill[T: ArrayTag](n1: Int, n2: Int, n3: Int, n4: Int)(elem: => T): Array[Array[Array[Array[T]]]] = tabulate(n1)(_ => fill(n2, n3, n4)(elem)) /** Returns a five-dimensional array that contains the results of some element @@ -293,7 +293,7 @@ object Array extends FallbackArrayBuilding { * @param n5 the number of elements in the 5th dimension * @param elem the element computation */ - def fill[T: ClassManifest](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int)(elem: => T): Array[Array[Array[Array[Array[T]]]]] = + def fill[T: ArrayTag](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int)(elem: => T): Array[Array[Array[Array[Array[T]]]]] = tabulate(n1)(_ => fill(n2, n3, n4, n5)(elem)) /** Returns an array containing values of a given function over a range of integer @@ -303,7 +303,7 @@ object Array extends FallbackArrayBuilding { * @param f The function computing element values * @return A traversable consisting of elements `f(0),f(1), ..., f(n - 1)` */ - def tabulate[T: ClassManifest](n: Int)(f: Int => T): Array[T] = { + def tabulate[T: ArrayTag](n: Int)(f: Int => T): Array[T] = { val b = newBuilder[T] b.sizeHint(n) var i = 0 @@ -321,7 +321,7 @@ object Array extends FallbackArrayBuilding { * @param n2 the number of elements in the 2nd dimension * @param f The function computing element values */ - def tabulate[T: ClassManifest](n1: Int, n2: Int)(f: (Int, Int) => T): Array[Array[T]] = + def tabulate[T: ArrayTag](n1: Int, n2: Int)(f: (Int, Int) => T): Array[Array[T]] = tabulate(n1)(i1 => tabulate(n2)(f(i1, _))) /** Returns a three-dimensional array containing values of a given function @@ -332,7 +332,7 @@ object Array extends FallbackArrayBuilding { * @param n3 the number of elements in the 3rd dimension * @param f The function computing element values */ - def tabulate[T: ClassManifest](n1: Int, n2: Int, n3: Int)(f: (Int, Int, Int) => T): Array[Array[Array[T]]] = + def tabulate[T: ArrayTag](n1: Int, n2: Int, n3: Int)(f: (Int, Int, Int) => T): Array[Array[Array[T]]] = tabulate(n1)(i1 => tabulate(n2, n3)(f(i1, _, _))) /** Returns a four-dimensional array containing values of a given function @@ -344,7 +344,7 @@ object Array extends FallbackArrayBuilding { * @param n4 the number of elements in the 4th dimension * @param f The function computing element values */ - def tabulate[T: ClassManifest](n1: Int, n2: Int, n3: Int, n4: Int)(f: (Int, Int, Int, Int) => T): Array[Array[Array[Array[T]]]] = + def tabulate[T: ArrayTag](n1: Int, n2: Int, n3: Int, n4: Int)(f: (Int, Int, Int, Int) => T): Array[Array[Array[Array[T]]]] = tabulate(n1)(i1 => tabulate(n2, n3, n4)(f(i1, _, _, _))) /** Returns a five-dimensional array containing values of a given function @@ -357,7 +357,7 @@ object Array extends FallbackArrayBuilding { * @param n5 the number of elements in the 5th dimension * @param f The function computing element values */ - def tabulate[T: ClassManifest](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int)(f: (Int, Int, Int, Int, Int) => T): Array[Array[Array[Array[Array[T]]]]] = + def tabulate[T: ArrayTag](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int)(f: (Int, Int, Int, Int, Int) => T): Array[Array[Array[Array[Array[T]]]]] = tabulate(n1)(i1 => tabulate(n2, n3, n4, n5)(f(i1, _, _, _, _))) /** Returns an array containing a sequence of increasing integers in a range. @@ -396,7 +396,7 @@ object Array extends FallbackArrayBuilding { * @param f the function that is repeatedly applied * @return the array returning `len` values in the sequence `start, f(start), f(f(start)), ...` */ - def iterate[T: ClassManifest](start: T, len: Int)(f: T => T): Array[T] = { + def iterate[T: ArrayTag](start: T, len: Int)(f: T => T): Array[T] = { val b = newBuilder[T] if (len > 0) { @@ -476,7 +476,7 @@ object Array extends FallbackArrayBuilding { * @define collectExample * @define undefinedorder * @define thatinfo the class of the returned collection. In the standard library configuration, - * `That` is either `Array[B]` if a ClassManifest is available for B or `ArraySeq[B]` otherwise. + * `That` is either `Array[B]` if an ArrayTag is available for B or `ArraySeq[B]` otherwise. * @define zipthatinfo $thatinfo * @define bfinfo an implicit value of class `CanBuildFrom` which determines the result class `That` from the current * representation type `Repr` and the new element type `B`. diff --git a/src/library/scala/collection/GenTraversableOnce.scala b/src/library/scala/collection/GenTraversableOnce.scala index a7ec7618b7..fd8595ccb8 100644 --- a/src/library/scala/collection/GenTraversableOnce.scala +++ b/src/library/scala/collection/GenTraversableOnce.scala @@ -459,7 +459,7 @@ trait GenTraversableOnce[+A] extends Any { /** Converts this $coll to an array. * - * @tparam B the type of the elements of the array. A `ClassManifest` for + * @tparam B the type of the elements of the array. An `ArrayTag` for * this type must be available. * @return an array containing all elements of this $coll. * @@ -469,9 +469,9 @@ trait GenTraversableOnce[+A] extends Any { * $willNotTerminateInf * * @return an array containing all elements of this $coll. - * A `ClassManifest` must be available for the element type of this $coll. + * An `ArrayTag` must be available for the element type of this $coll. */ - def toArray[A1 >: A: ClassManifest]: Array[A1] + def toArray[A1 >: A: ArrayTag]: Array[A1] /** Converts this $coll to a list. * $willNotTerminateInf diff --git a/src/library/scala/collection/Traversable.scala b/src/library/scala/collection/Traversable.scala index 3fba3dfa79..a65be3ffcc 100644 --- a/src/library/scala/collection/Traversable.scala +++ b/src/library/scala/collection/Traversable.scala @@ -75,7 +75,7 @@ trait Traversable[+A] extends TraversableLike[A, Traversable[A]] override def copyToBuffer[B >: A](dest: Buffer[B]) override def copyToArray[B >: A](xs: Array[B], start: Int, len: Int) override def copyToArray[B >: A](xs: Array[B], start: Int) - override def toArray[B >: A : ClassManifest]: Array[B] + override def toArray[B >: A : ArrayTag]: Array[B] override def toList: List[A] override def toIterable: Iterable[A] override def toSeq: Seq[A] diff --git a/src/library/scala/collection/TraversableOnce.scala b/src/library/scala/collection/TraversableOnce.scala index e68ef9e4de..5b5cee7f1b 100644 --- a/src/library/scala/collection/TraversableOnce.scala +++ b/src/library/scala/collection/TraversableOnce.scala @@ -229,7 +229,7 @@ trait TraversableOnce[+A] extends Any with GenTraversableOnce[A] { def copyToArray[B >: A](xs: Array[B]): Unit = copyToArray(xs, 0, xs.length) - def toArray[B >: A : ClassManifest]: Array[B] = { + def toArray[B >: A : ArrayTag]: Array[B] = { if (isTraversableAgain) { val result = new Array[B](size) copyToArray(result, 0) diff --git a/src/library/scala/collection/TraversableProxyLike.scala b/src/library/scala/collection/TraversableProxyLike.scala index e7e797391e..20880e369d 100644 --- a/src/library/scala/collection/TraversableProxyLike.scala +++ b/src/library/scala/collection/TraversableProxyLike.scala @@ -73,7 +73,7 @@ trait TraversableProxyLike[+A, +Repr <: TraversableLike[A, Repr] with Traversabl override def copyToArray[B >: A](xs: Array[B], start: Int, len: Int) = self.copyToArray(xs, start, len) override def copyToArray[B >: A](xs: Array[B], start: Int) = self.copyToArray(xs, start) override def copyToArray[B >: A](xs: Array[B]) = self.copyToArray(xs) - override def toArray[B >: A: ClassManifest]: Array[B] = self.toArray + override def toArray[B >: A: ArrayTag]: Array[B] = self.toArray override def toList: List[A] = self.toList override def toIterable: Iterable[A] = self.toIterable override def toSeq: Seq[A] = self.toSeq diff --git a/src/library/scala/collection/generic/ArrayTagTraversableFactory.scala b/src/library/scala/collection/generic/ArrayTagTraversableFactory.scala new file mode 100644 index 0000000000..d9ab17559e --- /dev/null +++ b/src/library/scala/collection/generic/ArrayTagTraversableFactory.scala @@ -0,0 +1,31 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2010-2011, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +package scala.collection +package generic + +import language.higherKinds + +/** A template for companion objects of `ClassTagTraversable` and + * subclasses thereof. + * + * @define coll collection + * @define Coll Traversable + * @define genericCanBuildFromInfo + * The standard `CanBuildFrom` instance for $Coll objects. + * @author Aleksandar Prokopec + * @since 2.8 + */ +abstract class ArrayTagTraversableFactory[CC[X] <: Traversable[X] with GenericArrayTagTraversableTemplate[X, CC]] + extends GenericArrayTagCompanion[CC] { + + class GenericCanBuildFrom[A](implicit tag: ArrayTag[A]) extends CanBuildFrom[CC[_], A, CC[A]] { + def apply(from: CC[_]) = from.genericArrayTagBuilder[A] + def apply = newBuilder[A] + } +} diff --git a/src/library/scala/collection/generic/ClassManifestTraversableFactory.scala b/src/library/scala/collection/generic/ClassManifestTraversableFactory.scala deleted file mode 100644 index e418ca623f..0000000000 --- a/src/library/scala/collection/generic/ClassManifestTraversableFactory.scala +++ /dev/null @@ -1,31 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2010-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -package scala.collection -package generic - -import language.higherKinds - -/** A template for companion objects of `ClassManifestTraversable` and - * subclasses thereof. - * - * @define coll collection - * @define Coll Traversable - * @define genericCanBuildFromInfo - * The standard `CanBuildFrom` instance for $Coll objects. - * @author Aleksandar Prokopec - * @since 2.8 - */ -abstract class ClassManifestTraversableFactory[CC[X] <: Traversable[X] with GenericClassManifestTraversableTemplate[X, CC]] - extends GenericClassManifestCompanion[CC] { - - class GenericCanBuildFrom[A](implicit manif: ClassManifest[A]) extends CanBuildFrom[CC[_], A, CC[A]] { - def apply(from: CC[_]) = from.genericClassManifestBuilder[A] - def apply = newBuilder[A] - } -} diff --git a/src/library/scala/collection/generic/GenericArrayTagCompanion.scala b/src/library/scala/collection/generic/GenericArrayTagCompanion.scala new file mode 100644 index 0000000000..959adbce6d --- /dev/null +++ b/src/library/scala/collection/generic/GenericArrayTagCompanion.scala @@ -0,0 +1,32 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +package scala.collection +package generic + +import mutable.Builder +import language.higherKinds + +/** This class represents companions of classes which require ArrayTags + * for their element types. + * + * @author Aleksandar Prokopec + */ +abstract class GenericArrayTagCompanion[+CC[X] <: Traversable[X]] { + type Coll = CC[_] + + def newBuilder[A](implicit ord: ArrayTag[A]): Builder[A, CC[A]] + + def empty[A: ArrayTag]: CC[A] = newBuilder[A].result + + def apply[A](elems: A*)(implicit ord: ArrayTag[A]): CC[A] = { + val b = newBuilder[A] + b ++= elems + b.result + } +} diff --git a/src/library/scala/collection/generic/GenericArrayTagTraversableTemplate.scala b/src/library/scala/collection/generic/GenericArrayTagTraversableTemplate.scala new file mode 100644 index 0000000000..ac84683c59 --- /dev/null +++ b/src/library/scala/collection/generic/GenericArrayTagTraversableTemplate.scala @@ -0,0 +1,30 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2010-2011, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +package scala.collection +package generic + +import mutable.Builder +import annotation.unchecked.uncheckedVariance +import language.higherKinds + +/** This trait represents collections classes which require array + * tags for their element types. + * + * @author Aleksandar Prokopec + * @since 2.8 + */ +trait GenericArrayTagTraversableTemplate[+A, +CC[X] <: Traversable[X]] extends HasNewBuilder[A, CC[A] @uncheckedVariance] { + implicit protected[this] val tag: ArrayTag[A] + def arrayTagCompanion: GenericArrayTagCompanion[CC] + def genericArrayTagBuilder[B](implicit tag: ArrayTag[B]): Builder[B, CC[B]] = arrayTagCompanion.newBuilder[B] + @deprecated("use arrayTagCompanion instead", "2.10.0") + def classManifestCompanion: GenericClassManifestCompanion[CC] = arrayTagCompanion + @deprecated("use genericArrayTagBuilder instead", "2.10.0") + def genericClassManifestBuilder[B](implicit manifest: ClassManifest[B]): Builder[B, CC[B]] = genericArrayTagBuilder[B](manifest) +} diff --git a/src/library/scala/collection/generic/GenericClassManifestCompanion.scala b/src/library/scala/collection/generic/GenericClassManifestCompanion.scala deleted file mode 100644 index f357091361..0000000000 --- a/src/library/scala/collection/generic/GenericClassManifestCompanion.scala +++ /dev/null @@ -1,32 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -package scala.collection -package generic - -import mutable.Builder -import language.higherKinds - -/** This class represents companions of classes which require ClassManifests - * for their element types. - * - * @author Aleksandar Prokopec - */ -abstract class GenericClassManifestCompanion[+CC[X] <: Traversable[X]] { - type Coll = CC[_] - - def newBuilder[A](implicit ord: ClassManifest[A]): Builder[A, CC[A]] - - def empty[A: ClassManifest]: CC[A] = newBuilder[A].result - - def apply[A](elems: A*)(implicit ord: ClassManifest[A]): CC[A] = { - val b = newBuilder[A] - b ++= elems - b.result - } -} diff --git a/src/library/scala/collection/generic/GenericClassManifestTraversableTemplate.scala b/src/library/scala/collection/generic/GenericClassManifestTraversableTemplate.scala deleted file mode 100644 index 1a5db4bab2..0000000000 --- a/src/library/scala/collection/generic/GenericClassManifestTraversableTemplate.scala +++ /dev/null @@ -1,26 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2010-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -package scala.collection -package generic - -import mutable.Builder -import annotation.unchecked.uncheckedVariance -import language.higherKinds - -/** This trait represents collections classes which require class - * manifests for their element types. - * - * @author Aleksandar Prokopec - * @since 2.8 - */ -trait GenericClassManifestTraversableTemplate[+A, +CC[X] <: Traversable[X]] extends HasNewBuilder[A, CC[A] @uncheckedVariance] { - implicit protected[this] val manifest: ClassManifest[A] - def classManifestCompanion: GenericClassManifestCompanion[CC] - def genericClassManifestBuilder[B](implicit man: ClassManifest[B]): Builder[B, CC[B]] = classManifestCompanion.newBuilder[B] -} diff --git a/src/library/scala/collection/generic/TraversableForwarder.scala b/src/library/scala/collection/generic/TraversableForwarder.scala index 3d723a1feb..3d5bc2704f 100644 --- a/src/library/scala/collection/generic/TraversableForwarder.scala +++ b/src/library/scala/collection/generic/TraversableForwarder.scala @@ -57,7 +57,7 @@ trait TraversableForwarder[+A] extends Traversable[A] { override def copyToArray[B >: A](xs: Array[B], start: Int, len: Int) = underlying.copyToArray(xs, start, len) override def copyToArray[B >: A](xs: Array[B], start: Int) = underlying.copyToArray(xs, start) override def copyToArray[B >: A](xs: Array[B]) = underlying.copyToArray(xs) - override def toArray[B >: A: ClassManifest]: Array[B] = underlying.toArray + override def toArray[B >: A: ArrayTag]: Array[B] = underlying.toArray override def toList: List[A] = underlying.toList override def toIterable: Iterable[A] = underlying.toIterable override def toSeq: Seq[A] = underlying.toSeq diff --git a/src/library/scala/collection/generic/package.scala b/src/library/scala/collection/generic/package.scala index 0457fef227..32006b4bf0 100644 --- a/src/library/scala/collection/generic/package.scala +++ b/src/library/scala/collection/generic/package.scala @@ -3,4 +3,13 @@ import generic.CanBuildFrom package object generic { type CanBuild[-Elem, +To] = CanBuildFrom[Nothing, Elem, To] + + @deprecated("use ArrayTagTraversableFactory instead", "2.10.0") + type ClassManifestTraversableFactory[CC[X] <: Traversable[X] with GenericClassManifestTraversableTemplate[X, CC]] = ArrayTagTraversableFactory[CC] + + @deprecated("use GenericArrayTagCompanion instead", "2.10.0") + type GenericClassManifestCompanion[+CC[X] <: Traversable[X]] = GenericArrayTagCompanion[CC] + + @deprecated("use GenericArrayTagTraversableTemplate instead", "2.10.0") + type GenericClassManifestTraversableTemplate[+A, +CC[X] <: Traversable[X]] = GenericArrayTagTraversableTemplate[A, CC] } \ No newline at end of file diff --git a/src/library/scala/collection/immutable/PagedSeq.scala b/src/library/scala/collection/immutable/PagedSeq.scala index 97c7c789f8..68c75ee586 100644 --- a/src/library/scala/collection/immutable/PagedSeq.scala +++ b/src/library/scala/collection/immutable/PagedSeq.scala @@ -25,7 +25,7 @@ object PagedSeq { final val UndeterminedEnd = Int.MaxValue /** Constructs a paged sequence from an iterator */ - def fromIterator[T: ClassManifest](source: Iterator[T]): PagedSeq[T] = + def fromIterator[T: ArrayTag](source: Iterator[T]): PagedSeq[T] = new PagedSeq[T]((data: Array[T], start: Int, len: Int) => { var i = 0 while (i < len && source.hasNext) { @@ -36,7 +36,7 @@ object PagedSeq { }) /** Constructs a paged sequence from an iterable */ - def fromIterable[T: ClassManifest](source: Iterable[T]): PagedSeq[T] = + def fromIterable[T: ArrayTag](source: Iterable[T]): PagedSeq[T] = fromIterator(source.iterator) /** Constructs a paged character sequence from a string iterator */ @@ -115,7 +115,7 @@ import PagedSeq._ * It returns the number of elements produced, or -1 if end of logical input stream was reached * before reading any element. * - * @tparam T the type of the elements contained in this paged sequence, with a `ClassManifest` context bound. + * @tparam T the type of the elements contained in this paged sequence, with an `ArrayTag` context bound. * * @author Martin Odersky * @since 2.7 @@ -124,7 +124,7 @@ import PagedSeq._ * @define mayNotTerminateInf * @define willNotTerminateInf */ -class PagedSeq[T: ClassManifest] protected( +class PagedSeq[T: ArrayTag] protected( more: (Array[T], Int, Int) => Int, first1: Page[T], start: Int, @@ -205,7 +205,7 @@ extends scala.collection.AbstractSeq[T] /** Page containing up to PageSize characters of the input sequence. */ -private class Page[T: ClassManifest](val num: Int) { +private class Page[T: ArrayTag](val num: Int) { private final val PageSize = 4096 diff --git a/src/library/scala/collection/immutable/StringLike.scala b/src/library/scala/collection/immutable/StringLike.scala index 06f09f359f..52032a1cde 100644 --- a/src/library/scala/collection/immutable/StringLike.scala +++ b/src/library/scala/collection/immutable/StringLike.scala @@ -239,7 +239,7 @@ self => else throw new IllegalArgumentException("For input string: \"null\"") - override def toArray[B >: Char : ClassManifest]: Array[B] = + override def toArray[B >: Char : ArrayTag]: Array[B] = toString.toCharArray.asInstanceOf[Array[B]] private def unwrapArg(arg: Any): AnyRef = arg match { diff --git a/src/library/scala/collection/interfaces/IterableMethods.scala b/src/library/scala/collection/interfaces/IterableMethods.scala index 2054922e59..8efc3fe6f9 100644 --- a/src/library/scala/collection/interfaces/IterableMethods.scala +++ b/src/library/scala/collection/interfaces/IterableMethods.scala @@ -11,7 +11,6 @@ package interfaces import generic._ import mutable.Buffer -import scala.reflect.ClassManifest import annotation.unchecked.uncheckedVariance /** diff --git a/src/library/scala/collection/interfaces/SeqMethods.scala b/src/library/scala/collection/interfaces/SeqMethods.scala index 1f5b08d036..4327073d21 100644 --- a/src/library/scala/collection/interfaces/SeqMethods.scala +++ b/src/library/scala/collection/interfaces/SeqMethods.scala @@ -11,7 +11,6 @@ package interfaces import generic._ import mutable.Buffer -import scala.reflect.ClassManifest /** * @since 2.8 diff --git a/src/library/scala/collection/interfaces/SetMethods.scala b/src/library/scala/collection/interfaces/SetMethods.scala index ffe141ed82..3b6214f45c 100644 --- a/src/library/scala/collection/interfaces/SetMethods.scala +++ b/src/library/scala/collection/interfaces/SetMethods.scala @@ -11,7 +11,6 @@ package interfaces import generic._ import mutable.Buffer -import scala.reflect.ClassManifest import annotation.unchecked.uncheckedVariance /** diff --git a/src/library/scala/collection/interfaces/TraversableOnceMethods.scala b/src/library/scala/collection/interfaces/TraversableOnceMethods.scala index 471e977134..543d59d118 100644 --- a/src/library/scala/collection/interfaces/TraversableOnceMethods.scala +++ b/src/library/scala/collection/interfaces/TraversableOnceMethods.scala @@ -46,7 +46,7 @@ trait TraversableOnceMethods[+A] { def copyToBuffer[B >: A](dest: mutable.Buffer[B]): Unit // conversions - def toArray[B >: A : ClassManifest]: Array[B] + def toArray[B >: A : ArrayTag]: Array[B] def toBuffer[B >: A]: mutable.Buffer[B] def toIndexedSeq: immutable.IndexedSeq[A] def toIterable: Iterable[A] diff --git a/src/library/scala/collection/mutable/ArrayBuilder.scala b/src/library/scala/collection/mutable/ArrayBuilder.scala index e396b0695e..293e85a97e 100644 --- a/src/library/scala/collection/mutable/ArrayBuilder.scala +++ b/src/library/scala/collection/mutable/ArrayBuilder.scala @@ -12,7 +12,8 @@ package scala.collection package mutable import generic._ -import scala.reflect.ClassManifest +import scala.reflect.ArrayTag +import scala.runtime.ScalaRunTime /** A builder class for arrays. * @@ -30,12 +31,12 @@ object ArrayBuilder { /** Creates a new arraybuilder of type `T`. * - * @tparam T type of the elements for the array builder, with a `ClassManifest` context bound. + * @tparam T type of the elements for the array builder, with a `ArrayTag` context bound. * @return a new empty array builder. */ - def make[T: ClassManifest](): ArrayBuilder[T] = { - val manifest = implicitly[ClassManifest[T]] - val erasure = manifest.erasure + def make[T: ArrayTag](): ArrayBuilder[T] = { + val tag = implicitly[ArrayTag[T]] + val erasure = ScalaRunTime.arrayElementClass(tag) erasure match { case java.lang.Byte.TYPE => new ArrayBuilder.ofByte().asInstanceOf[ArrayBuilder[T]] case java.lang.Short.TYPE => new ArrayBuilder.ofShort().asInstanceOf[ArrayBuilder[T]] @@ -46,15 +47,15 @@ object ArrayBuilder { case java.lang.Double.TYPE => new ArrayBuilder.ofDouble().asInstanceOf[ArrayBuilder[T]] case java.lang.Boolean.TYPE => new ArrayBuilder.ofBoolean().asInstanceOf[ArrayBuilder[T]] case java.lang.Void.TYPE => new ArrayBuilder.ofUnit().asInstanceOf[ArrayBuilder[T]] - case _ => new ArrayBuilder.ofRef[T with AnyRef]()(manifest.asInstanceOf[ClassManifest[T with AnyRef]]).asInstanceOf[ArrayBuilder[T]] + case _ => new ArrayBuilder.ofRef[T with AnyRef]()(tag.asInstanceOf[ArrayTag[T with AnyRef]]).asInstanceOf[ArrayBuilder[T]] } } /** A class for array builders for arrays of reference types. * - * @tparam T type of elements for the array builder, subtype of `AnyRef` with a `ClassManifest` context bound. + * @tparam T type of elements for the array builder, subtype of `AnyRef` with a `ArrayTag` context bound. */ - class ofRef[T <: AnyRef : ClassManifest] extends ArrayBuilder[T] { + class ofRef[T <: AnyRef : ArrayTag] extends ArrayBuilder[T] { private var elems: Array[T] = _ private var capacity: Int = 0 diff --git a/src/library/scala/collection/mutable/ArrayOps.scala b/src/library/scala/collection/mutable/ArrayOps.scala index 875030ade0..5f0e1e1071 100644 --- a/src/library/scala/collection/mutable/ArrayOps.scala +++ b/src/library/scala/collection/mutable/ArrayOps.scala @@ -12,7 +12,8 @@ package scala.collection package mutable import compat.Platform.arraycopy -import scala.reflect.ClassManifest +import scala.reflect.ArrayTag +import scala.runtime.ScalaRunTime._ import parallel.mutable.ParArray @@ -37,10 +38,8 @@ import parallel.mutable.ParArray */ abstract class ArrayOps[T] extends ArrayLike[T, Array[T]] with CustomParallelizable[T, ParArray[T]] { - private def rowBuilder[U]: Builder[U, Array[U]] = - Array.newBuilder( - ClassManifest[U]( - repr.getClass.getComponentType.getComponentType)) + private def elementClass: Class[_] = + arrayElementClass(repr.getClass) override def copyToArray[U >: T](xs: Array[U], start: Int, len: Int) { var l = math.min(len, repr.length) @@ -48,11 +47,13 @@ abstract class ArrayOps[T] extends ArrayLike[T, Array[T]] with CustomParalleliza Array.copy(repr, 0, xs, start, l) } - override def toArray[U >: T : ClassManifest]: Array[U] = - if (implicitly[ClassManifest[U]].erasure eq repr.getClass.getComponentType) + override def toArray[U >: T : ArrayTag]: Array[U] = { + val thatElementClass = arrayElementClass(implicitly[ArrayTag[U]]) + if (elementClass eq thatElementClass) repr.asInstanceOf[Array[U]] else super.toArray[U] + } override def par = ParArray.handoff(repr) @@ -63,7 +64,7 @@ abstract class ArrayOps[T] extends ArrayLike[T, Array[T]] with CustomParalleliza * @param asArray A function that converts elements of this array to rows - arrays of type `U`. * @return An array obtained by concatenating rows of this array. */ - def flatten[U, To](implicit asTrav: T => collection.Traversable[U], m: ClassManifest[U]): Array[U] = { + def flatten[U, To](implicit asTrav: T => collection.Traversable[U], m: ArrayTag[U]): Array[U] = { val b = Array.newBuilder[U] b.sizeHint(map{case is: collection.IndexedSeq[_] => is.size case _ => 0}.sum) for (xs <- this) @@ -78,7 +79,8 @@ abstract class ArrayOps[T] extends ArrayLike[T, Array[T]] with CustomParalleliza * @return An array obtained by replacing elements of this arrays with rows the represent. */ def transpose[U](implicit asArray: T => Array[U]): Array[Array[U]] = { - val bs = asArray(head) map (_ => rowBuilder[U]) + def mkRowBuilder() = Array.newBuilder(ClassTag[U](arrayElementClass(elementClass))) + val bs = asArray(head) map (_ => mkRowBuilder()) for (xs <- this) { var i = 0 for (x <- asArray(xs)) { @@ -86,9 +88,7 @@ abstract class ArrayOps[T] extends ArrayLike[T, Array[T]] with CustomParalleliza i += 1 } } - val bb: Builder[Array[U], Array[Array[U]]] = Array.newBuilder( - ClassManifest[Array[U]]( - repr.getClass.getComponentType)) + val bb: Builder[Array[U], Array[Array[U]]] = Array.newBuilder(ClassTag[Array[U]](elementClass)) for (b <- bs) bb += b.result bb.result } @@ -109,8 +109,7 @@ object ArrayOps { override protected[this] def thisCollection: WrappedArray[T] = new WrappedArray.ofRef[T](repr) override protected[this] def toCollection(repr: Array[T]): WrappedArray[T] = new WrappedArray.ofRef[T](repr) - override protected[this] def newBuilder = new ArrayBuilder.ofRef[T]()( - ClassManifest[T](repr.getClass.getComponentType)) + override protected[this] def newBuilder = new ArrayBuilder.ofRef[T]()(ClassTag[T](arrayElementClass(repr.getClass))) def length: Int = repr.length def apply(index: Int): T = repr(index) diff --git a/src/library/scala/collection/mutable/ArrayStack.scala b/src/library/scala/collection/mutable/ArrayStack.scala index f5287312b9..b3a0534826 100644 --- a/src/library/scala/collection/mutable/ArrayStack.scala +++ b/src/library/scala/collection/mutable/ArrayStack.scala @@ -21,7 +21,7 @@ object ArrayStack extends SeqFactory[ArrayStack] { implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, ArrayStack[A]] = ReusableCBF.asInstanceOf[GenericCanBuildFrom[A]] def newBuilder[A]: Builder[A, ArrayStack[A]] = new ArrayStack[A] def empty: ArrayStack[Nothing] = new ArrayStack() - def apply[A: ClassManifest](elems: A*): ArrayStack[A] = { + def apply[A: ArrayTag](elems: A*): ArrayStack[A] = { val els: Array[AnyRef] = elems.reverseMap(_.asInstanceOf[AnyRef])(breakOut) if (els.length == 0) new ArrayStack() else new ArrayStack[A](els, els.length) diff --git a/src/library/scala/collection/mutable/FlatArray.scala b/src/library/scala/collection/mutable/FlatArray.scala index 3e43b66ecf..5b4b5e777f 100644 --- a/src/library/scala/collection/mutable/FlatArray.scala +++ b/src/library/scala/collection/mutable/FlatArray.scala @@ -11,7 +11,7 @@ package scala.collection package mutable -import scala.reflect.ClassManifest +import scala.reflect.ArrayTag import generic.CanBuildFrom /** @@ -62,16 +62,16 @@ object FlatArray { def ofDim[Boxed, Unboxed](size:Int) (implicit boxings: BoxingConversions[Boxed, Unboxed], - manifest: ClassManifest[Unboxed]): FlatArray[Boxed] = { + tag: ArrayTag[Unboxed]): FlatArray[Boxed] = { val elems = Array.ofDim[Unboxed](size) - new FlatArray.Impl(elems, boxings, manifest) + new FlatArray.Impl(elems, boxings, tag) } def empty[Boxed, Unboxed](implicit boxings: BoxingConversions[Boxed, Unboxed], - elemManifest: ClassManifest[Unboxed]): FlatArray[Boxed] = apply() + elemTag: ArrayTag[Unboxed]): FlatArray[Boxed] = apply() def apply[Boxed, Unboxed](elems: Boxed*) - (implicit boxings: BoxingConversions[Boxed, Unboxed], elemManifest: ClassManifest[Unboxed]): FlatArray[Boxed] = { + (implicit boxings: BoxingConversions[Boxed, Unboxed], elemTag: ArrayTag[Unboxed]): FlatArray[Boxed] = { val b = newBuilder[Boxed, Unboxed] b.sizeHint(elems.length) b ++= elems @@ -79,13 +79,13 @@ object FlatArray { } def newBuilder[Boxed, Unboxed] - (implicit boxings: BoxingConversions[Boxed, Unboxed], elemManifest: ClassManifest[Unboxed]): Builder[Boxed, FlatArray[Boxed]] = - new Bldr[Boxed, Unboxed](boxings, elemManifest) + (implicit boxings: BoxingConversions[Boxed, Unboxed], elemTag: ArrayTag[Unboxed]): Builder[Boxed, FlatArray[Boxed]] = + new Bldr[Boxed, Unboxed](boxings, elemTag) implicit def canBuildFrom[Boxed, Unboxed]( implicit boxings: BoxingConversions[Boxed, Unboxed], - elemManifest: ClassManifest[Unboxed]): CanBuildFrom[FlatArray[_], Boxed, FlatArray[Boxed]] = + elemTag: ArrayTag[Unboxed]): CanBuildFrom[FlatArray[_], Boxed, FlatArray[Boxed]] = new CanBuildFrom[FlatArray[_], Boxed, FlatArray[Boxed]] { def apply(from: FlatArray[_]): Builder[Boxed, FlatArray[Boxed]] = newBuilder[Boxed, Unboxed] @@ -93,14 +93,14 @@ object FlatArray { newBuilder[Boxed, Unboxed] } - private class Bldr[Boxed, Unboxed](boxings: BoxingConversions[Boxed, Unboxed], manifest: ClassManifest[Unboxed]) extends Builder[Boxed, FlatArray[Boxed]] { + private class Bldr[Boxed, Unboxed](boxings: BoxingConversions[Boxed, Unboxed], tag: ArrayTag[Unboxed]) extends Builder[Boxed, FlatArray[Boxed]] { private var elems: Array[Unboxed] = _ private var capacity: Int = 0 private var size: Int = 0 private def resize(size: Int) { - val newelems = manifest.newArray(size) + val newelems = tag.newArray(size) if (this.size > 0) Array.copy(elems, 0, newelems, 0, this.size) elems = newelems capacity = size @@ -131,14 +131,14 @@ object FlatArray { def result(): FlatArray[Boxed] = { if (capacity == 0 || capacity != size) resize(size) - new FlatArray.Impl(elems, boxings, manifest) + new FlatArray.Impl(elems, boxings, tag) } } private class Impl[Boxed, Unboxed]( elems: Array[Unboxed], boxings: BoxingConversions[Boxed, Unboxed], - elemManifest: ClassManifest[Unboxed]) extends FlatArray[Boxed] { + elemTag: ArrayTag[Unboxed]) extends FlatArray[Boxed] { def length = elems.length @@ -149,9 +149,9 @@ object FlatArray { /** Creates new builder for this collection ==> move to subclasses */ override protected[this] def newBuilder: Builder[Boxed, FlatArray[Boxed]] = - new Bldr[Boxed, Unboxed](boxings, elemManifest) + new Bldr[Boxed, Unboxed](boxings, elemTag) /** Clones this object, including the underlying Array. */ - override def clone: FlatArray[Boxed] = new Impl[Boxed, Unboxed](elems.clone(), boxings, elemManifest) + override def clone: FlatArray[Boxed] = new Impl[Boxed, Unboxed](elems.clone(), boxings, elemTag) } } diff --git a/src/library/scala/collection/mutable/UnrolledBuffer.scala b/src/library/scala/collection/mutable/UnrolledBuffer.scala index 09e6088782..889768d471 100644 --- a/src/library/scala/collection/mutable/UnrolledBuffer.scala +++ b/src/library/scala/collection/mutable/UnrolledBuffer.scala @@ -41,11 +41,11 @@ import annotation.tailrec * */ @SerialVersionUID(1L) -class UnrolledBuffer[T](implicit val manifest: ClassManifest[T]) +class UnrolledBuffer[T](implicit val tag: ArrayTag[T]) extends collection.mutable.AbstractBuffer[T] with collection.mutable.Buffer[T] with collection.mutable.BufferLike[T, UnrolledBuffer[T]] - with GenericClassManifestTraversableTemplate[T, UnrolledBuffer] + with GenericArrayTagTraversableTemplate[T, UnrolledBuffer] with collection.mutable.Builder[T, UnrolledBuffer[T]] with Serializable { @@ -67,7 +67,7 @@ extends collection.mutable.AbstractBuffer[T] private[collection] def calcNextLength(sz: Int) = sz - def classManifestCompanion = UnrolledBuffer + def arrayTagCompanion = UnrolledBuffer /** Concatenates the targer unrolled buffer to this unrolled buffer. * @@ -183,11 +183,11 @@ extends collection.mutable.AbstractBuffer[T] } -object UnrolledBuffer extends ClassManifestTraversableFactory[UnrolledBuffer] { +object UnrolledBuffer extends ArrayTagTraversableFactory[UnrolledBuffer] { /** $genericCanBuildFromInfo */ - implicit def canBuildFrom[T](implicit m: ClassManifest[T]): CanBuildFrom[Coll, T, UnrolledBuffer[T]] = + implicit def canBuildFrom[T](implicit t: ArrayTag[T]): CanBuildFrom[Coll, T, UnrolledBuffer[T]] = new GenericCanBuildFrom[T] - def newBuilder[T](implicit m: ClassManifest[T]): Builder[T, UnrolledBuffer[T]] = new UnrolledBuffer[T] + def newBuilder[T](implicit t: ArrayTag[T]): Builder[T, UnrolledBuffer[T]] = new UnrolledBuffer[T] val waterline = 50 val waterlineDelim = 100 @@ -195,7 +195,7 @@ object UnrolledBuffer extends ClassManifestTraversableFactory[UnrolledBuffer] { /** Unrolled buffer node. */ - class Unrolled[T: ClassManifest] private[collection] (var size: Int, var array: Array[T], var next: Unrolled[T], val buff: UnrolledBuffer[T] = null) { + class Unrolled[T: ArrayTag] private[collection] (var size: Int, var array: Array[T], var next: Unrolled[T], val buff: UnrolledBuffer[T] = null) { private[collection] def this() = this(0, new Array[T](unrolledlength), null, null) private[collection] def this(b: UnrolledBuffer[T]) = this(0, new Array[T](unrolledlength), null, b) diff --git a/src/library/scala/collection/mutable/WrappedArray.scala b/src/library/scala/collection/mutable/WrappedArray.scala index fac4eb77bb..5e20f4ec61 100644 --- a/src/library/scala/collection/mutable/WrappedArray.scala +++ b/src/library/scala/collection/mutable/WrappedArray.scala @@ -11,7 +11,8 @@ package scala.collection package mutable -import scala.reflect.ClassManifest +import scala.reflect.ArrayTag +import scala.runtime.ScalaRunTime._ import scala.collection.generic._ import scala.collection.parallel.mutable.ParArray @@ -40,8 +41,11 @@ extends AbstractSeq[T] override protected[this] def thisCollection: WrappedArray[T] = this override protected[this] def toCollection(repr: WrappedArray[T]): WrappedArray[T] = repr - /** The manifest of the element type */ - def elemManifest: ClassManifest[T] + /** The tag of the element type */ + def elemTag: ArrayTag[T] + + @deprecated("use elemTag instead", "2.10.0") + def elemManifest: ClassManifest[T] = ClassManifest[T](arrayElementClass(elemTag)) /** The length of the array */ def length: Int @@ -57,11 +61,16 @@ extends AbstractSeq[T] override def par = ParArray.handoff(array) - override def toArray[U >: T : ClassManifest]: Array[U] = - if (implicitly[ClassManifest[U]].erasure eq array.getClass.getComponentType) + private def elementClass: Class[_] = + arrayElementClass(repr.getClass) + + override def toArray[U >: T : ArrayTag]: Array[U] = { + val thatElementClass = arrayElementClass(implicitly[ArrayTag[U]]) + if (elementClass eq thatElementClass) array.asInstanceOf[Array[U]] else super.toArray[U] + } override def stringPrefix = "WrappedArray" @@ -71,7 +80,7 @@ extends AbstractSeq[T] /** Creates new builder for this collection ==> move to subclasses */ override protected[this] def newBuilder: Builder[T, WrappedArray[T]] = - new WrappedArrayBuilder[T](elemManifest) + new WrappedArrayBuilder[T](elemTag) } @@ -101,7 +110,7 @@ object WrappedArray { case x: Array[Unit] => new ofUnit(x) }).asInstanceOf[WrappedArray[T]] - implicit def canBuildFrom[T](implicit m: ClassManifest[T]): CanBuildFrom[WrappedArray[_], T, WrappedArray[T]] = + implicit def canBuildFrom[T](implicit m: ArrayTag[T]): CanBuildFrom[WrappedArray[_], T, WrappedArray[T]] = new CanBuildFrom[WrappedArray[_], T, WrappedArray[T]] { def apply(from: WrappedArray[_]): Builder[T, WrappedArray[T]] = ArrayBuilder.make[T]()(m) mapResult WrappedArray.make[T] @@ -112,70 +121,70 @@ object WrappedArray { def newBuilder[A]: Builder[A, IndexedSeq[A]] = new ArrayBuffer final class ofRef[T <: AnyRef](val array: Array[T]) extends WrappedArray[T] with Serializable { - lazy val elemManifest = ClassManifest[T](array.getClass.getComponentType) + lazy val elemTag = ClassTag[T](arrayElementClass(array.getClass)) def length: Int = array.length def apply(index: Int): T = array(index).asInstanceOf[T] def update(index: Int, elem: T) { array(index) = elem } } final class ofByte(val array: Array[Byte]) extends WrappedArray[Byte] with Serializable { - def elemManifest = ClassManifest.Byte + def elemTag = ClassTag.Byte def length: Int = array.length def apply(index: Int): Byte = array(index) def update(index: Int, elem: Byte) { array(index) = elem } } final class ofShort(val array: Array[Short]) extends WrappedArray[Short] with Serializable { - def elemManifest = ClassManifest.Short + def elemTag = ClassTag.Short def length: Int = array.length def apply(index: Int): Short = array(index) def update(index: Int, elem: Short) { array(index) = elem } } final class ofChar(val array: Array[Char]) extends WrappedArray[Char] with Serializable { - def elemManifest = ClassManifest.Char + def elemTag = ClassTag.Char def length: Int = array.length def apply(index: Int): Char = array(index) def update(index: Int, elem: Char) { array(index) = elem } } final class ofInt(val array: Array[Int]) extends WrappedArray[Int] with Serializable { - def elemManifest = ClassManifest.Int + def elemTag = ClassTag.Int def length: Int = array.length def apply(index: Int): Int = array(index) def update(index: Int, elem: Int) { array(index) = elem } } final class ofLong(val array: Array[Long]) extends WrappedArray[Long] with Serializable { - def elemManifest = ClassManifest.Long + def elemTag = ClassTag.Long def length: Int = array.length def apply(index: Int): Long = array(index) def update(index: Int, elem: Long) { array(index) = elem } } final class ofFloat(val array: Array[Float]) extends WrappedArray[Float] with Serializable { - def elemManifest = ClassManifest.Float + def elemTag = ClassTag.Float def length: Int = array.length def apply(index: Int): Float = array(index) def update(index: Int, elem: Float) { array(index) = elem } } final class ofDouble(val array: Array[Double]) extends WrappedArray[Double] with Serializable { - def elemManifest = ClassManifest.Double + def elemTag = ClassTag.Double def length: Int = array.length def apply(index: Int): Double = array(index) def update(index: Int, elem: Double) { array(index) = elem } } final class ofBoolean(val array: Array[Boolean]) extends WrappedArray[Boolean] with Serializable { - def elemManifest = ClassManifest.Boolean + def elemTag = ClassTag.Boolean def length: Int = array.length def apply(index: Int): Boolean = array(index) def update(index: Int, elem: Boolean) { array(index) = elem } } final class ofUnit(val array: Array[Unit]) extends WrappedArray[Unit] with Serializable { - def elemManifest = ClassManifest.Unit + def elemTag = ClassTag.Unit def length: Int = array.length def apply(index: Int): Unit = array(index) def update(index: Int, elem: Unit) { array(index) = elem } diff --git a/src/library/scala/collection/mutable/WrappedArrayBuilder.scala b/src/library/scala/collection/mutable/WrappedArrayBuilder.scala index fce65468e9..99a0b0ede3 100644 --- a/src/library/scala/collection/mutable/WrappedArrayBuilder.scala +++ b/src/library/scala/collection/mutable/WrappedArrayBuilder.scala @@ -12,23 +12,27 @@ package scala.collection package mutable import generic._ -import scala.reflect.ClassManifest +import scala.reflect.ArrayTag +import scala.runtime.ScalaRunTime._ /** A builder class for arrays. * - * @tparam A type of elements that can be added to this builder. - * @param manifest class manifest for objects of type `A`. + * @tparam A type of elements that can be added to this builder. + * @param tag class tag for objects of type `A`. * * @since 2.8 */ -class WrappedArrayBuilder[A](manifest: ClassManifest[A]) extends Builder[A, WrappedArray[A]] { +class WrappedArrayBuilder[A](tag: ArrayTag[A]) extends Builder[A, WrappedArray[A]] { + + @deprecated("use tag instead", "2.10.0") + val manifest: ArrayTag[A] = tag private var elems: WrappedArray[A] = _ private var capacity: Int = 0 private var size: Int = 0 private def mkArray(size: Int): WrappedArray[A] = { - val erasure = manifest.erasure + val erasure = arrayElementClass(tag) val newelems = erasure 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]] @@ -39,7 +43,7 @@ class WrappedArrayBuilder[A](manifest: ClassManifest[A]) extends Builder[A, Wrap case java.lang.Double.TYPE => new WrappedArray.ofDouble(new Array[Double](size)).asInstanceOf[WrappedArray[A]] case java.lang.Boolean.TYPE => new WrappedArray.ofBoolean(new Array[Boolean](size)).asInstanceOf[WrappedArray[A]] case java.lang.Void.TYPE => new WrappedArray.ofUnit(new Array[Unit](size)).asInstanceOf[WrappedArray[A]] - case _ => new WrappedArray.ofRef[A with AnyRef](manifest.newArray(size).asInstanceOf[Array[A with AnyRef]]).asInstanceOf[WrappedArray[A]] + case _ => new WrappedArray.ofRef[A with AnyRef](tag.newArray(size).asInstanceOf[Array[A with AnyRef]]).asInstanceOf[WrappedArray[A]] } if (this.size > 0) Array.copy(elems.array, 0, newelems.array, 0, this.size) newelems diff --git a/src/library/scala/collection/parallel/ParIterableLike.scala b/src/library/scala/collection/parallel/ParIterableLike.scala index 5bf338f560..014b9b1a42 100644 --- a/src/library/scala/collection/parallel/ParIterableLike.scala +++ b/src/library/scala/collection/parallel/ParIterableLike.scala @@ -155,15 +155,15 @@ extends GenIterableLike[T, Repr] with HasNewCombiner[T, Repr] { self: ParIterableLike[T, Repr, Sequential] => - + @transient @volatile private var _tasksupport = defaultTaskSupport - + protected def initTaskSupport() { _tasksupport = defaultTaskSupport } - + def tasksupport = { val ts = _tasksupport if (ts eq null) { @@ -171,9 +171,9 @@ self: ParIterableLike[T, Repr, Sequential] => defaultTaskSupport } else ts } - + def tasksupport_=(ts: TaskSupport) = _tasksupport = ts - + def seq: Sequential def repr: Repr = this.asInstanceOf[Repr] @@ -240,7 +240,7 @@ self: ParIterableLike[T, Repr, Sequential] => trait BuilderOps[Elem, To] { trait Otherwise[Cmb] { - def otherwise(notbody: => Unit)(implicit m: ClassManifest[Cmb]): Unit + def otherwise(notbody: => Unit)(implicit t: ClassTag[Cmb]): Unit } def ifIs[Cmb](isbody: Cmb => Unit): Otherwise[Cmb] @@ -282,8 +282,8 @@ 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 m: ClassManifest[Cmb]) { - if (cb.getClass == m.erasure) isbody(cb.asInstanceOf[Cmb]) else notbody + def otherwise(notbody: => Unit)(implicit t: ClassTag[Cmb]) { + if (cb.getClass == t.erasure) isbody(cb.asInstanceOf[Cmb]) else notbody } } def isCombiner = cb.isInstanceOf[Combiner[_, _]] @@ -754,7 +754,7 @@ self: ParIterableLike[T, Repr, Sequential] => cntx.setIndexFlag(Int.MaxValue) tasksupport.executeAndWaitResult( new Span(0, pred, combinerFactory, combinerFactory, splitter assign cntx) mapResult { - _._2.resultWithTaskSupport + _._2.resultWithTaskSupport } ) } @@ -802,7 +802,7 @@ self: ParIterableLike[T, Repr, Sequential] => def size = splitter.remaining } - override def toArray[U >: T: ClassManifest]: Array[U] = { + override def toArray[U >: T: ArrayTag]: Array[U] = { val arr = new Array[U](size) copyToArray(arr) arr diff --git a/src/library/scala/collection/parallel/mutable/ParArray.scala b/src/library/scala/collection/parallel/mutable/ParArray.scala index 8cc0b95997..92ba701f7c 100644 --- a/src/library/scala/collection/parallel/mutable/ParArray.scala +++ b/src/library/scala/collection/parallel/mutable/ParArray.scala @@ -676,7 +676,7 @@ self => private def readObject(in: java.io.ObjectInputStream) { in.defaultReadObject - + // get raw array from arrayseq array = arrayseq.array.asInstanceOf[Array[Any]] } @@ -706,7 +706,7 @@ object ParArray extends ParFactory[ParArray] { case _ => new ParArray[T](new ExposedArraySeq[T](runtime.ScalaRunTime.toObjectArray(arr), sz)) } - def createFromCopy[T <: AnyRef : ClassManifest](arr: Array[T]): ParArray[T] = { + def createFromCopy[T <: AnyRef : ArrayTag](arr: Array[T]): ParArray[T] = { val newarr = new Array[T](arr.length) Array.copy(arr, 0, newarr, 0, arr.length) handoff(newarr) diff --git a/src/library/scala/collection/parallel/mutable/UnrolledParArrayCombiner.scala b/src/library/scala/collection/parallel/mutable/UnrolledParArrayCombiner.scala index 410b542a68..43d40776bf 100644 --- a/src/library/scala/collection/parallel/mutable/UnrolledParArrayCombiner.scala +++ b/src/library/scala/collection/parallel/mutable/UnrolledParArrayCombiner.scala @@ -26,7 +26,7 @@ import scala.collection.parallel.Task -private[mutable] class DoublingUnrolledBuffer[T](implicit m: ClassManifest[T]) extends UnrolledBuffer[T]()(m) { +private[mutable] class DoublingUnrolledBuffer[T](implicit t: ArrayTag[T]) extends UnrolledBuffer[T]()(t) { override def calcNextLength(sz: Int) = if (sz < 10000) sz * 2 else sz protected override def newUnrolled = new Unrolled[T](0, new Array[T](4), null, this) } diff --git a/src/library/scala/concurrent/Future.scala b/src/library/scala/concurrent/Future.scala index 9aaf05dbd6..def086bc03 100644 --- a/src/library/scala/concurrent/Future.scala +++ b/src/library/scala/concurrent/Future.scala @@ -134,26 +134,26 @@ trait Future[+T] extends Awaitable[T] { /** Creates a new promise. */ protected def newPromise[S]: Promise[S] - + /** Returns whether the future has already been completed with * a value or an exception. - * + * * $nonDeterministic - * + * * @return `true` if the future is already completed, `false` otherwise */ def isCompleted: Boolean - + /** The value of this `Future`. - * + * * If the future is not completed the returned value will be `None`. * If the future is completed the value will be `Some(Success(t))` * if it contains a valid result, or `Some(Failure(error))` if it contains * an exception. */ def value: Option[Either[Throwable, T]] - - + + /* Projections */ /** Returns a failed projection of this future. @@ -421,11 +421,11 @@ trait Future[+T] extends Awaitable[T] { } p.future } - + /** Creates a new `Future[S]` which is completed with this `Future`'s result if * that conforms to `S`'s erased type or a `ClassCastException` otherwise. */ - def mapTo[S](implicit m: Manifest[S]): Future[S] = { + def mapTo[S](implicit tag: ClassTag[S]): Future[S] = { import java.{ lang => jl } val toBoxed = Map[Class[_], Class[_]]( classOf[Boolean] -> classOf[jl.Boolean], @@ -444,20 +444,20 @@ trait Future[+T] extends Awaitable[T] { } val p = newPromise[S] - + onComplete { case l: Left[Throwable, _] => p complete l.asInstanceOf[Either[Throwable, S]] case Right(t) => p complete (try { - Right(boxedType(m.erasure).cast(t).asInstanceOf[S]) + Right(boxedType(tag.erasure).cast(t).asInstanceOf[S]) } catch { case e: ClassCastException => Left(e) }) } - + p.future } - + /** Applies the side-effecting function to the result of this future, and returns * a new future with the result of this future. * @@ -591,7 +591,7 @@ object Future { * The fold is performed on the thread where the last future is completed, * the result will be the first failure of any of the futures, or any failure in the actual fold, * or the result of the fold. - * + * * Example: * {{{ * val result = Await.result(Future.fold(futures)(0)(_ + _), 5 seconds) @@ -603,7 +603,7 @@ object Future { } /** Initiates a fold over the supplied futures where the fold-zero is the result value of the `Future` that's completed first. - * + * * Example: * {{{ * val result = Await.result(Futures.reduce(futures)(_ + _), 5 seconds) @@ -613,11 +613,11 @@ object Future { if (futures.isEmpty) Promise[R].failure(new NoSuchElementException("reduce attempted on empty collection")).future else sequence(futures).map(_ reduceLeft op) } - + /** Transforms a `Traversable[A]` into a `Future[Traversable[B]]` using the provided function `A => Future[B]`. * This is useful for performing a parallel map. For example, to apply a function to all items of a list * in parallel: - * + * * {{{ * val myFutureList = Future.traverse(myList)(x => Future(myFunc(x))) * }}} @@ -627,7 +627,7 @@ object Future { val fb = fn(a.asInstanceOf[A]) for (r <- fr; b <- fb) yield (r += b) }.map(_.result) - + } diff --git a/src/library/scala/reflect/DummyMirror.scala b/src/library/scala/reflect/DummyMirror.scala index 8b2ddde2a1..276237fce4 100644 --- a/src/library/scala/reflect/DummyMirror.scala +++ b/src/library/scala/reflect/DummyMirror.scala @@ -5,9 +5,10 @@ import scala.reflect.api.Attachment import scala.reflect.api.Modifier import scala.reflect.api.Universe +// todo. make Dummy objects not equal to themselves class DummyMirror(cl: ClassLoader) extends api.Mirror { // Members declared in scala.reflect.api.AnnotationInfos - implicit def classfileAnnotArgManifest: scala.reflect.ClassManifest[ClassfileAnnotArg] = notSupported() + implicit def classfileAnnotArgTag: scala.reflect.ClassTag[ClassfileAnnotArg] = notSupported() type AnnotationInfo = DummyAnnotationInfo.type object DummyAnnotationInfo val AnnotationInfo: AnnotationInfoExtractor = DummyAnnotationInfoExtractor diff --git a/src/library/scala/reflect/api/AnnotationInfos.scala b/src/library/scala/reflect/api/AnnotationInfos.scala index 96a65606e5..cc1c4d2b6b 100755 --- a/src/library/scala/reflect/api/AnnotationInfos.scala +++ b/src/library/scala/reflect/api/AnnotationInfos.scala @@ -12,7 +12,7 @@ trait AnnotationInfos { self: Universe => } type ClassfileAnnotArg <: AnyRef - implicit def classfileAnnotArgManifest: ClassManifest[ClassfileAnnotArg] // need a precise manifest to pass to UnPickle's toArray call + implicit def classfileAnnotArgTag: ArrayTag[ClassfileAnnotArg] // need a precise tag to pass to UnPickle's toArray call type LiteralAnnotArg <: ClassfileAnnotArg val LiteralAnnotArg: LiteralAnnotArgExtractor diff --git a/src/library/scala/util/Marshal.scala b/src/library/scala/util/Marshal.scala index 6eb58e8570..e2ebe7851c 100644 --- a/src/library/scala/util/Marshal.scala +++ b/src/library/scala/util/Marshal.scala @@ -48,4 +48,4 @@ object Marshal { "\n required: "+expected) } } -} \ No newline at end of file +} diff --git a/src/library/scala/util/Sorting.scala b/src/library/scala/util/Sorting.scala index bf460a118f..7d98e57741 100644 --- a/src/library/scala/util/Sorting.scala +++ b/src/library/scala/util/Sorting.scala @@ -8,7 +8,7 @@ package scala.util -import scala.reflect.ClassManifest +import scala.reflect.ClassTag import scala.math.Ordering /** The Sorting object provides functions that can sort various kinds of @@ -39,14 +39,14 @@ object Sorting { /** Sort an array of K where K is Ordered, preserving the existing order * where the values are equal. */ - def stableSort[K: ClassManifest: Ordering](a: Array[K]) { + def stableSort[K: ArrayTag: Ordering](a: Array[K]) { stableSort(a, 0, a.length-1, new Array[K](a.length), Ordering[K].lt _) } /** Sorts an array of `K` given an ordering function `f`. * `f` should return `true` iff its first parameter is strictly less than its second parameter. */ - def stableSort[K: ClassManifest](a: Array[K], f: (K, K) => Boolean) { + def stableSort[K: ArrayTag](a: Array[K], f: (K, K) => Boolean) { stableSort(a, 0, a.length-1, new Array[K](a.length), f) } @@ -57,14 +57,14 @@ object Sorting { * @param f the comparison function. * @return the sorted sequence of items. */ - def stableSort[K: ClassManifest](a: Seq[K], f: (K, K) => Boolean): Array[K] = { + def stableSort[K: ArrayTag](a: Seq[K], f: (K, K) => Boolean): Array[K] = { val ret = a.toArray stableSort(ret, f) ret } /** Sorts an arbitrary sequence of items that are viewable as ordered. */ - def stableSort[K: ClassManifest: Ordering](a: Seq[K]): Array[K] = + def stableSort[K: ArrayTag: Ordering](a: Seq[K]): Array[K] = stableSort(a, Ordering[K].lt _) /** Stably sorts a sequence of items given an extraction function that will @@ -74,8 +74,8 @@ object Sorting { * @param f the comparison function. * @return the sorted sequence of items. */ - def stableSort[K: ClassManifest, M: Ordering](a: Seq[K], f: K => M): Array[K] = - stableSort(a)(implicitly[ClassManifest[K]], Ordering[M] on f) + def stableSort[K: ArrayTag, M: Ordering](a: Seq[K], f: K => M): Array[K] = + stableSort(a)(implicitly[ArrayTag[K]], Ordering[M] on f) private def sort1[K: Ordering](x: Array[K], off: Int, len: Int) { val ord = Ordering[K] @@ -498,7 +498,7 @@ object Sorting { sort2(off, len) } - private def stableSort[K : ClassManifest](a: Array[K], lo: Int, hi: Int, scratch: Array[K], f: (K,K) => Boolean) { + private def stableSort[K : ArrayTag](a: Array[K], lo: Int, hi: Int, scratch: Array[K], f: (K,K) => Boolean) { if (lo < hi) { val mid = (lo+hi) / 2 stableSort(a, lo, mid, scratch, f) diff --git a/src/library/scala/util/control/Exception.scala b/src/library/scala/util/control/Exception.scala index 1cae8088f5..38f4abb20a 100644 --- a/src/library/scala/util/control/Exception.scala +++ b/src/library/scala/util/control/Exception.scala @@ -30,9 +30,9 @@ import language.implicitConversions object Exception { type Catcher[+T] = PartialFunction[Throwable, T] - def mkCatcher[Ex <: Throwable: ClassManifest, T](isDef: Ex => Boolean, f: Ex => T) = new Catcher[T] { + def mkCatcher[Ex <: Throwable: ClassTag, T](isDef: Ex => Boolean, f: Ex => T) = new Catcher[T] { private def downcast(x: Throwable): Option[Ex] = - if (classManifest[Ex].erasure.isAssignableFrom(x.getClass)) Some(x.asInstanceOf[Ex]) + if (classTag[Ex].erasure.isAssignableFrom(x.getClass)) Some(x.asInstanceOf[Ex]) else None def isDefinedAt(x: Throwable) = downcast(x) exists isDef @@ -41,7 +41,7 @@ object Exception { def mkThrowableCatcher[T](isDef: Throwable => Boolean, f: Throwable => T) = mkCatcher(isDef, f) - implicit def throwableSubtypeToCatcher[Ex <: Throwable: ClassManifest, T](pf: PartialFunction[Ex, T]) = + implicit def throwableSubtypeToCatcher[Ex <: Throwable: ClassTag, T](pf: PartialFunction[Ex, T]) = mkCatcher(pf.isDefinedAt _, pf.apply _) /** !!! Not at all sure of every factor which goes into this, diff --git a/src/partest/scala/tools/partest/CompilerTest.scala b/src/partest/scala/tools/partest/CompilerTest.scala index aaea4416dd..86678760be 100644 --- a/src/partest/scala/tools/partest/CompilerTest.scala +++ b/src/partest/scala/tools/partest/CompilerTest.scala @@ -5,6 +5,7 @@ package scala.tools.partest +import scala.reflect.{mirror => rm} import scala.tools.nsc._ /** For testing compiler internals directly. @@ -29,13 +30,13 @@ abstract class CompilerTest extends DirectTest { // Override at least one of these... def code = "" def sources: List[String] = List(code) - + // Utility functions - + class MkType(sym: Symbol) { - def apply[M](implicit m1: Manifest[M]): Type = + def apply[M](implicit t: rm.TypeTag[M]): Type = if (sym eq NoSymbol) NoType - else appliedType(sym, manifestToType(m1)) + else appliedType(sym, compilerTypeFromTag(t)) } implicit def mkMkType(sym: Symbol) = new MkType(sym) @@ -47,7 +48,7 @@ abstract class CompilerTest extends DirectTest { } loop(Set(), List(root)) } - + class SymsInPackage(pkgName: String) { def pkg = getRequiredModule(pkgName) def classes = allMembers(pkg) filter (_.isClass) diff --git a/src/partest/scala/tools/partest/SigTest.scala b/src/partest/scala/tools/partest/SigTest.scala index 072ec006f9..999d901d21 100644 --- a/src/partest/scala/tools/partest/SigTest.scala +++ b/src/partest/scala/tools/partest/SigTest.scala @@ -20,31 +20,31 @@ trait SigTest { def isObjectMethodName(name: String) = classOf[Object].getMethods exists (_.getName == name) - def fields[T: ClassManifest](p: JField => Boolean) = { - val cl = classManifest[T].erasure + def fields[T: ClassTag](p: JField => Boolean) = { + val cl = classTag[T].erasure val fs = (cl.getFields ++ cl.getDeclaredFields).distinct sortBy (_.getName) fs filter p } - def methods[T: ClassManifest](p: JMethod => Boolean) = { - val cl = classManifest[T].erasure + def methods[T: ClassTag](p: JMethod => Boolean) = { + val cl = classTag[T].erasure val ms = (cl.getMethods ++ cl.getDeclaredMethods).distinct sortBy (x => (x.getName, x.isBridge)) ms filter p } - def allFields[T: ClassManifest]() = fields[T](_ => true) - def allMethods[T: ClassManifest]() = methods[T](m => !isObjectMethodName(m.getName)) - def fieldsNamed[T: ClassManifest](name: String) = fields[T](_.getName == name) - def methodsNamed[T: ClassManifest](name: String) = methods[T](_.getName == name) + def allFields[T: ClassTag]() = fields[T](_ => true) + def allMethods[T: ClassTag]() = methods[T](m => !isObjectMethodName(m.getName)) + def fieldsNamed[T: ClassTag](name: String) = fields[T](_.getName == name) + def methodsNamed[T: ClassTag](name: String) = methods[T](_.getName == name) - def allGenericStrings[T: ClassManifest]() = + def allGenericStrings[T: ClassTag]() = (allMethods[T]() map mstr) ++ (allFields[T]() map fstr) - def genericStrings[T: ClassManifest](name: String) = + def genericStrings[T: ClassTag](name: String) = (methodsNamed[T](name) map mstr) ++ (fieldsNamed[T](name) map fstr) - def show[T: ClassManifest](name: String = "") = { - println(classManifest[T].erasure.getName) + def show[T: ClassTag](name: String = "") = { + println(classTag[T].erasure.getName) if (name == "") allGenericStrings[T]() foreach println else genericStrings[T](name) foreach println } diff --git a/src/scalacheck/org/scalacheck/Arbitrary.scala b/src/scalacheck/org/scalacheck/Arbitrary.scala index 91d56b0aec..9bb235f917 100644 --- a/src/scalacheck/org/scalacheck/Arbitrary.scala +++ b/src/scalacheck/org/scalacheck/Arbitrary.scala @@ -263,7 +263,7 @@ object Arbitrary { ): Arbitrary[C[T]] = Arbitrary(containerOf[C,T](arbitrary[T])) /** Arbitrary instance of any array. */ - implicit def arbArray[T](implicit a: Arbitrary[T], c: ClassManifest[T] + implicit def arbArray[T](implicit a: Arbitrary[T], c: ClassTag[T] ): Arbitrary[Array[T]] = Arbitrary(containerOf[Array,T](arbitrary[T])) diff --git a/src/scalacheck/org/scalacheck/util/Buildable.scala b/src/scalacheck/org/scalacheck/util/Buildable.scala index 6378e72d4f..662bc6146b 100644 --- a/src/scalacheck/org/scalacheck/util/Buildable.scala +++ b/src/scalacheck/org/scalacheck/util/Buildable.scala @@ -30,7 +30,7 @@ object Buildable { def builder = (new mutable.ListBuffer[T]).mapResult(_.toStream) } - implicit def buildableArray[T](implicit cm: ClassManifest[T]) = + implicit def buildableArray[T](implicit t: ClassTag[T]) = new Buildable[T,Array] { def builder = mutable.ArrayBuilder.make[T] } diff --git a/src/swing/scala/swing/Font.scala.disabled b/src/swing/scala/swing/Font.scala.disabled index 6eebd667bd..9e21eb859c 100644 --- a/src/swing/scala/swing/Font.scala.disabled +++ b/src/swing/scala/swing/Font.scala.disabled @@ -1,36 +1,36 @@ package scala.swing -/*object Font { - def apply(fontFormat: Int, fontFile: java.io.File) = java.awt.Font.createFont(fontFormat, fontFile) - def apply(fontFormat: Int, fontStream: java.io.InputStream) = java.awt.Font.createFont(fontFormat, fontStream) +/*object Font { + def apply(fontFormat: Int, fontFile: java.io.File) = java.awt.Font.createFont(fontFormat, fontFile) + def apply(fontFormat: Int, fontStream: java.io.InputStream) = java.awt.Font.createFont(fontFormat, fontStream) def decode(str: String) = java.awt.Font.decode(str) - + /* TODO: finish implementation /** * See [java.awt.Font.getFont]. */ - def get(attributes: Map[_ <: java.text.AttributedCharacterIterator.Attribute, _]) = + def get(attributes: Map[_ <: java.text.AttributedCharacterIterator.Attribute, _]) = java.awt.Font.getFont(ImmutableMapWrapper(attributes)) - + import java.{util => ju} - private case class ImmutableMapWrapper[A, B](underlying : Map[A, B])(m : ClassManifest[A]) extends ju.AbstractMap[A, B] { + private case class ImmutableMapWrapper[A, B](underlying : Map[A, B])(t : ClassTag[A]) extends ju.AbstractMap[A, B] { self => override def size = underlying.size - override def put(k : A, v : B) = + override def put(k : A, v : B) = throw new UnsupportedOperationException("This is a wrapper that does not support mutation") - override def remove(k : AnyRef) = + override def remove(k : AnyRef) = throw new UnsupportedOperationException("This is a wrapper that does not support mutation") - + override def entrySet : ju.Set[ju.Map.Entry[A, B]] = new ju.AbstractSet[ju.Map.Entry[A, B]] { def size = self.size def iterator = new ju.Iterator[ju.Map.Entry[A, B]] { val ui = underlying.iterator var prev : Option[A] = None - + def hasNext = ui.hasNext - + def next = { val (k, v) = ui.next prev = Some(k) @@ -44,7 +44,7 @@ package scala.swing } } } - + def remove = prev match { case Some(k) => val v = self.remove(k.asInstanceOf[AnyRef]) ; prev = None ; v case _ => throw new IllegalStateException("next must be called at least once before remove") @@ -53,7 +53,7 @@ package scala.swing } } */ - + /** * See [java.awt.Font.getFont]. */ @@ -62,9 +62,9 @@ package scala.swing * See [java.awt.Font.getFont]. */ def get(nm: String, font: Font) = java.awt.Font.getFont(nm, font) - + def Insets(x: Int, y: Int, width: Int, height: Int) = new Insets(x, y, width, height) def Rectangle(x: Int, y: Int, width: Int, height: Int) = new Insets(x, y, width, height) def Point(x: Int, y: Int) = new Point(x, y) - def Dimension(x: Int, y: Int) = new Dimension(x, y) + def Dimension(x: Int, y: Int) = new Dimension(x, y) }*/ \ No newline at end of file diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/Resetting.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/Resetting.scala index e6feb59fcd..22d2107f62 100644 --- a/test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/Resetting.scala +++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/Resetting.scala @@ -4,19 +4,19 @@ package scala.collection.parallel.benchmarks.arrays import scala.collection.parallel.benchmarks._ -abstract class Resetting[T: Manifest](elemcreate: Int => T, sz: Int, p: Int, what: String) +abstract class Resetting[T: ClassTag](elemcreate: Int => T, sz: Int, p: Int, what: String) extends Bench { val size = sz val parallelism = p val runWhat = what - + var anyarray: Array[Any] = null var castarray: AnyRef = null var gencastarray: Array[T] = null var manifarray: Array[T] = null - + reset - + def reset = what match { case "any" => anyarray = new Array[Any](sz) diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/MatrixMultiplication.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/MatrixMultiplication.scala index 5f902ff483..6d5b189c3a 100644 --- a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/MatrixMultiplication.scala +++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/MatrixMultiplication.scala @@ -16,54 +16,54 @@ class MatrixMultiplication(sz: Int, p: Int, what: String) extends Resettable(sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont]) { def companion = MatrixMultiplication collection.parallel.tasksupport.environment = forkjoinpool - + val a = Matrix.unit[Int](sz) val b = Matrix.unit[Int](sz) var c = new Matrix[Int](sz) - + def runpar = c = a * b //{ c.assignProduct(a, b) } //; println("--------"); c.output } def runseq = throw new UnsupportedOperationException def comparisonMap = collection.Map() - - class Matrix[T](n: Int)(implicit num: Numeric[T], man: Manifest[T]) { + + class Matrix[T](n: Int)(implicit num: Numeric[T], tag: ClassTag[T]) { val array = new Array[T](n * n) - + def apply(y: Int, x: Int) = array(y * n + x) - + def update(y: Int, x: Int, elem: T) = array(y * n + x) = elem - + def *(b: Matrix[T]) = { val m = new Matrix[T](n) m.assignProduct(this, b) m } - + def assignProduct(a: Matrix[T], b: Matrix[T]) = { val range = ParRange(0, n * n, 1, false) for (i <- range) this(i / n, i % n) = calcProduct(a, b, i / n, i % n); } - + private def calcProduct(a: Matrix[T], b: Matrix[T], y: Int, x: Int): T = { import num._ var sum = zero for (i <- 0 until n) sum += a(y, i) * b(i, x) sum } - + def output = for (y <- 0 until n) { for (x <- 0 until n) print(this(y, x)) println } } - + object Matrix { - def unit[T](n: Int)(implicit num: Numeric[T], man: Manifest[T]) = { + def unit[T](n: Int)(implicit num: Numeric[T], tag: ClassTag[T]) = { val m = new Matrix[T](n) for (i <- 0 until n) m(i, i) = num.one m } } - + } diff --git a/test/disabled/presentation/akka.check b/test/disabled/presentation/akka.check index 9cd20ffb1c..5105d85a00 100644 --- a/test/disabled/presentation/akka.check +++ b/test/disabled/presentation/akka.check @@ -153,11 +153,11 @@ retrieved 131 members `method spawn(clazz: Class[_ <: akka.actor.Actor])akka.actor.ActorRef` `method spawnLink(clazz: Class[_ <: akka.actor.Actor])akka.actor.ActorRef` `method spawnLinkRemote(clazz: Class[_ <: akka.actor.Actor], hostname: String, port: Int, timeout: Long)akka.actor.ActorRef` -`method spawnLinkRemote[T <: akka.actor.Actor](hostname: String, port: Int, timeout: Long)(implicit evidence$4: Manifest[T])akka.actor.ActorRef` -`method spawnLink[T <: akka.actor.Actor](implicit evidence$3: Manifest[T])akka.actor.ActorRef` +`method spawnLinkRemote[T <: akka.actor.Actor](hostname: String, port: Int, timeout: Long)(implicit evidence$4: ClassTag[T])akka.actor.ActorRef` +`method spawnLink[T <: akka.actor.Actor](implicit evidence$3: ClassTag[T])akka.actor.ActorRef` `method spawnRemote(clazz: Class[_ <: akka.actor.Actor], hostname: String, port: Int, timeout: Long)akka.actor.ActorRef` -`method spawnRemote[T <: akka.actor.Actor](hostname: String, port: Int, timeout: Long)(implicit evidence$2: Manifest[T])akka.actor.ActorRef` -`method spawn[T <: akka.actor.Actor](implicit evidence$1: Manifest[T])akka.actor.ActorRef` +`method spawnRemote[T <: akka.actor.Actor](hostname: String, port: Int, timeout: Long)(implicit evidence$2: ClassTag[T])akka.actor.ActorRef` +`method spawn[T <: akka.actor.Actor](implicit evidence$1: ClassTag[T])akka.actor.ActorRef` `method start()akka.actor.ActorRef` `method startLink(actorRef: akka.actor.ActorRef)Unit` `method stop()Unit` @@ -286,11 +286,11 @@ retrieved 131 members `method spawn(clazz: Class[_ <: akka.actor.Actor])akka.actor.ActorRef` `method spawnLink(clazz: Class[_ <: akka.actor.Actor])akka.actor.ActorRef` `method spawnLinkRemote(clazz: Class[_ <: akka.actor.Actor], hostname: String, port: Int, timeout: Long)akka.actor.ActorRef` -`method spawnLinkRemote[T <: akka.actor.Actor](hostname: String, port: Int, timeout: Long)(implicit evidence$4: Manifest[T])akka.actor.ActorRef` -`method spawnLink[T <: akka.actor.Actor](implicit evidence$3: Manifest[T])akka.actor.ActorRef` +`method spawnLinkRemote[T <: akka.actor.Actor](hostname: String, port: Int, timeout: Long)(implicit evidence$4: ClassTag[T])akka.actor.ActorRef` +`method spawnLink[T <: akka.actor.Actor](implicit evidence$3: ClassTag[T])akka.actor.ActorRef` `method spawnRemote(clazz: Class[_ <: akka.actor.Actor], hostname: String, port: Int, timeout: Long)akka.actor.ActorRef` -`method spawnRemote[T <: akka.actor.Actor](hostname: String, port: Int, timeout: Long)(implicit evidence$2: Manifest[T])akka.actor.ActorRef` -`method spawn[T <: akka.actor.Actor](implicit evidence$1: Manifest[T])akka.actor.ActorRef` +`method spawnRemote[T <: akka.actor.Actor](hostname: String, port: Int, timeout: Long)(implicit evidence$2: ClassTag[T])akka.actor.ActorRef` +`method spawn[T <: akka.actor.Actor](implicit evidence$1: ClassTag[T])akka.actor.ActorRef` `method start()akka.actor.ActorRef` `method startLink(actorRef: akka.actor.ActorRef)Unit` `method stop()Unit` @@ -419,11 +419,11 @@ retrieved 131 members `method spawn(clazz: Class[_ <: akka.actor.Actor])akka.actor.ActorRef` `method spawnLink(clazz: Class[_ <: akka.actor.Actor])akka.actor.ActorRef` `method spawnLinkRemote(clazz: Class[_ <: akka.actor.Actor], hostname: String, port: Int, timeout: Long)akka.actor.ActorRef` -`method spawnLinkRemote[T <: akka.actor.Actor](hostname: String, port: Int, timeout: Long)(implicit evidence$4: Manifest[T])akka.actor.ActorRef` -`method spawnLink[T <: akka.actor.Actor](implicit evidence$3: Manifest[T])akka.actor.ActorRef` +`method spawnLinkRemote[T <: akka.actor.Actor](hostname: String, port: Int, timeout: Long)(implicit evidence$4: ClassTag[T])akka.actor.ActorRef` +`method spawnLink[T <: akka.actor.Actor](implicit evidence$3: ClassTag[T])akka.actor.ActorRef` `method spawnRemote(clazz: Class[_ <: akka.actor.Actor], hostname: String, port: Int, timeout: Long)akka.actor.ActorRef` -`method spawnRemote[T <: akka.actor.Actor](hostname: String, port: Int, timeout: Long)(implicit evidence$2: Manifest[T])akka.actor.ActorRef` -`method spawn[T <: akka.actor.Actor](implicit evidence$1: Manifest[T])akka.actor.ActorRef` +`method spawnRemote[T <: akka.actor.Actor](hostname: String, port: Int, timeout: Long)(implicit evidence$2: ClassTag[T])akka.actor.ActorRef` +`method spawn[T <: akka.actor.Actor](implicit evidence$1: ClassTag[T])akka.actor.ActorRef` `method start()akka.actor.ActorRef` `method startLink(actorRef: akka.actor.ActorRef)Unit` `method stop()Unit` diff --git a/test/disabled/presentation/akka/src/akka/actor/Actor.scala b/test/disabled/presentation/akka/src/akka/actor/Actor.scala index b955c4c38b..b9bc51b635 100644 --- a/test/disabled/presentation/akka/src/akka/actor/Actor.scala +++ b/test/disabled/presentation/akka/src/akka/actor/Actor.scala @@ -135,7 +135,7 @@ object Actor extends ListenerManagement { * val actor = actorOf[MyActor].start() * */ - def actorOf[T <: Actor: Manifest]: ActorRef = actorOf(manifest[T].erasure.asInstanceOf[Class[_ <: Actor]]) + def actorOf[T <: Actor: ClassTag]: ActorRef = actorOf(classTag[T].erasure.asInstanceOf[Class[_ <: Actor]]) /** Creates an ActorRef out of the Actor of the specified Class. *
@@ -481,7 +481,7 @@ private[actor] class AnyOptionAsTypedOption(anyOption: Option[Any]) {
   /** Convenience helper to cast the given Option of Any to an Option of the given type. Will swallow a possible
    *  ClassCastException and return None in that case.
    */
-  def asSilently[T: Manifest]: Option[T] = narrowSilently[T](anyOption)
+  def asSilently[T: ClassTag]: Option[T] = narrowSilently[T](anyOption)
 }
 
 /** Marker interface for proxyable actors (such as typed actor).
diff --git a/test/disabled/presentation/akka/src/akka/actor/ActorRef.scala b/test/disabled/presentation/akka/src/akka/actor/ActorRef.scala
index ff67c9468e..da0b63006a 100644
--- a/test/disabled/presentation/akka/src/akka/actor/ActorRef.scala
+++ b/test/disabled/presentation/akka/src/akka/actor/ActorRef.scala
@@ -1406,28 +1406,28 @@ trait ScalaActorRef extends ActorRefShared { ref: ActorRef =>
   /**
    * Atomically create (from actor class) and start an actor.
    */
-  def spawn[T <: Actor: Manifest]: ActorRef =
-    spawn(manifest[T].erasure.asInstanceOf[Class[_ <: Actor]])
+  def spawn[T <: Actor: ClassTag]: ActorRef =
+    spawn(classTag[T].erasure.asInstanceOf[Class[_ <: Actor]])
 
   /**
    * Atomically create (from actor class), start and make an actor remote.
    */
-  def spawnRemote[T <: Actor: Manifest](hostname: String, port: Int, timeout: Long): ActorRef = {
+  def spawnRemote[T <: Actor: ClassTag](hostname: String, port: Int, timeout: Long): ActorRef = {
     ensureRemotingEnabled
-    spawnRemote(manifest[T].erasure.asInstanceOf[Class[_ <: Actor]], hostname, port, timeout)
+    spawnRemote(classTag[T].erasure.asInstanceOf[Class[_ <: Actor]], hostname, port, timeout)
   }
 
   /**
    * Atomically create (from actor class), start and link an actor.
    */
-  def spawnLink[T <: Actor: Manifest]: ActorRef =
-    spawnLink(manifest[T].erasure.asInstanceOf[Class[_ <: Actor]])
+  def spawnLink[T <: Actor: ClassTag]: ActorRef =
+    spawnLink(classTag[T].erasure.asInstanceOf[Class[_ <: Actor]])
 
   /**
    * Atomically create (from actor class), start, link and make an actor remote.
    */
-  def spawnLinkRemote[T <: Actor: Manifest](hostname: String, port: Int, timeout: Long): ActorRef = {
+  def spawnLinkRemote[T <: Actor: ClassTag](hostname: String, port: Int, timeout: Long): ActorRef = {
     ensureRemotingEnabled
-    spawnLinkRemote(manifest[T].erasure.asInstanceOf[Class[_ <: Actor]], hostname, port, timeout)
+    spawnLinkRemote(classTag[T].erasure.asInstanceOf[Class[_ <: Actor]], hostname, port, timeout)
   }
 }
diff --git a/test/disabled/presentation/akka/src/akka/actor/ActorRegistry.scala b/test/disabled/presentation/akka/src/akka/actor/ActorRegistry.scala
index df335dc8b4..5d649fcd36 100644
--- a/test/disabled/presentation/akka/src/akka/actor/ActorRegistry.scala
+++ b/test/disabled/presentation/akka/src/akka/actor/ActorRegistry.scala
@@ -5,7 +5,7 @@
 package akka.actor
 
 import scala.collection.mutable.{ ListBuffer, Map }
-import scala.reflect.Manifest
+import scala.reflect.ArrayTag
 
 import java.util.concurrent.{ ConcurrentSkipListSet, ConcurrentHashMap }
 import java.util.{ Set => JSet }
@@ -74,10 +74,10 @@ final class ActorRegistry private[actor] () extends ListenerManagement {
   }
 
   /**
-   * Finds all actors that are subtypes of the class passed in as the Manifest argument and supporting passed message.
+   * Finds all actors that are subtypes of the class passed in as the ClassTag argument and supporting passed message.
    */
-  def actorsFor[T <: Actor](message: Any)(implicit manifest: Manifest[T]): Array[ActorRef] =
-    filter(a => manifest.erasure.isAssignableFrom(a.actor.getClass) && a.isDefinedAt(message))
+  def actorsFor[T <: Actor](message: Any)(implicit classTag: ClassTag[T]): Array[ActorRef] =
+    filter(a => classTag.erasure.isAssignableFrom(a.actor.getClass) && a.isDefinedAt(message))
 
   /**
    * Finds all actors that satisfy a predicate.
@@ -93,16 +93,16 @@ final class ActorRegistry private[actor] () extends ListenerManagement {
   }
 
   /**
-   * Finds all actors that are subtypes of the class passed in as the Manifest argument.
+   * Finds all actors that are subtypes of the class passed in as the ClassTag argument.
    */
-  def actorsFor[T <: Actor](implicit manifest: Manifest[T]): Array[ActorRef] =
-    actorsFor[T](manifest.erasure.asInstanceOf[Class[T]])
+  def actorsFor[T <: Actor](implicit classTag: ClassTag[T]): Array[ActorRef] =
+    actorsFor[T](classTag.erasure.asInstanceOf[Class[T]])
 
   /**
    * Finds any actor that matches T. Very expensive, traverses ALL alive actors.
    */
-  def actorFor[T <: Actor](implicit manifest: Manifest[T]): Option[ActorRef] =
-    find({ case a: ActorRef if manifest.erasure.isAssignableFrom(a.actor.getClass) => a })
+  def actorFor[T <: Actor](implicit classTag: ClassTag[T]): Option[ActorRef] =
+    find({ case a: ActorRef if classTag.erasure.isAssignableFrom(a.actor.getClass) => a })
 
   /**
    * Finds all actors of type or sub-type specified by the class passed in as the Class argument.
@@ -166,21 +166,21 @@ final class ActorRegistry private[actor] () extends ListenerManagement {
   }
 
   /**
-   * Finds all typed actors that are subtypes of the class passed in as the Manifest argument.
+   * Finds all typed actors that are subtypes of the class passed in as the ClassTag argument.
    */
-  def typedActorsFor[T <: AnyRef](implicit manifest: Manifest[T]): Array[AnyRef] = {
+  def typedActorsFor[T <: AnyRef](implicit classTag: ClassTag[T]): Array[AnyRef] = {
     TypedActorModule.ensureEnabled
-    typedActorsFor[T](manifest.erasure.asInstanceOf[Class[T]])
+    typedActorsFor[T](classTag.erasure.asInstanceOf[Class[T]])
   }
 
   /**
    * Finds any typed actor that matches T.
    */
-  def typedActorFor[T <: AnyRef](implicit manifest: Manifest[T]): Option[AnyRef] = {
+  def typedActorFor[T <: AnyRef](implicit classTag: ClassTag[T]): Option[AnyRef] = {
     TypedActorModule.ensureEnabled
     def predicate(proxy: AnyRef): Boolean = {
       val actorRef = TypedActorModule.typedActorObjectInstance.get.actorFor(proxy)
-      actorRef.isDefined && manifest.erasure.isAssignableFrom(actorRef.get.actor.getClass)
+      actorRef.isDefined && classTag.erasure.isAssignableFrom(actorRef.get.actor.getClass)
     }
     findTypedActor({ case a: Some[AnyRef] if predicate(a.get) => a })
   }
@@ -279,7 +279,7 @@ final class ActorRegistry private[actor] () extends ListenerManagement {
  *
  * @author Viktor Klang
  */
-class Index[K <: AnyRef, V <: AnyRef: Manifest] {
+class Index[K <: AnyRef, V <: AnyRef: ArrayTag] {
   private val Naught = Array[V]() //Nil for Arrays
   private val container = new ConcurrentHashMap[K, JSet[V]]
   private val emptySet = new ConcurrentSkipListSet[V]
diff --git a/test/disabled/presentation/akka/src/akka/event/EventHandler.scala b/test/disabled/presentation/akka/src/akka/event/EventHandler.scala
index f3176b7c21..af2fee6c47 100644
--- a/test/disabled/presentation/akka/src/akka/event/EventHandler.scala
+++ b/test/disabled/presentation/akka/src/akka/event/EventHandler.scala
@@ -115,8 +115,8 @@ object EventHandler extends ListenerManagement {
       notifyListeners(event)
   }
 
-  def notify[T <: Event: ClassManifest](event: => T) {
-    if (level >= levelFor(classManifest[T].erasure.asInstanceOf[Class[_ <: Event]])) notifyListeners(event)
+  def notify[T <: Event: ClassTag](event: => T) {
+    if (level >= levelFor(classTag[T].erasure.asInstanceOf[Class[_ <: Event]])) notifyListeners(event)
   }
 
   def error(cause: Throwable, instance: AnyRef, message: => String) {
diff --git a/test/disabled/presentation/akka/src/akka/remoteinterface/RemoteInterface.scala b/test/disabled/presentation/akka/src/akka/remoteinterface/RemoteInterface.scala
index 0c5da82294..5219c49dcb 100644
--- a/test/disabled/presentation/akka/src/akka/remoteinterface/RemoteInterface.scala
+++ b/test/disabled/presentation/akka/src/akka/remoteinterface/RemoteInterface.scala
@@ -206,8 +206,8 @@ abstract class RemoteSupport extends ListenerManagement with RemoteServerModule
    * 
*/ @deprecated("Will be removed after 1.1", "1.1") - def actorOf[T <: Actor: Manifest](host: String, port: Int): ActorRef = - clientManagedActorOf(() => createActorFromClass(manifest.erasure), host, port) + def actorOf[T <: Actor: ClassTag](host: String, port: Int): ActorRef = + clientManagedActorOf(() => createActorFromClass(classTag[T].erasure), host, port) protected def createActorFromClass(clazz: Class[_]): Actor = { import ReflectiveAccess.{ createInstance, noParams, noArgs } diff --git a/test/disabled/presentation/akka/src/akka/util/Helpers.scala b/test/disabled/presentation/akka/src/akka/util/Helpers.scala index 48477426c9..0ff45408d0 100644 --- a/test/disabled/presentation/akka/src/akka/util/Helpers.scala +++ b/test/disabled/presentation/akka/src/akka/util/Helpers.scala @@ -37,7 +37,7 @@ object Helpers { * Convenience helper to cast the given Option of Any to an Option of the given type. Will swallow a possible * ClassCastException and return None in that case. */ - def narrowSilently[T: Manifest](o: Option[Any]): Option[T] = + def narrowSilently[T: ClassTag](o: Option[Any]): Option[T] = try { narrow(o) } catch { diff --git a/test/disabled/presentation/simple-tests.check b/test/disabled/presentation/simple-tests.check index b90dfce77c..cdb80ed987 100644 --- a/test/disabled/presentation/simple-tests.check +++ b/test/disabled/presentation/simple-tests.check @@ -244,7 +244,7 @@ TypeMember(method disable,(s: Tester.this.settings.Setting)scala.collection.muta TypeMember(value disable,Tester.this.settings.MultiStringSetting,false,true,) TypeMember(value elidebelow,Tester.this.settings.IntSetting,false,true,) TypeMember(method embeddedDefaults,(loader: java.lang.ClassLoader)Unit,true,true,) -TypeMember(method embeddedDefaults,[T](implicit evidence$1: Manifest[T])Unit,true,true,) +TypeMember(method embeddedDefaults,[T](implicit evidence$1: ClassTag[T])Unit,true,true,) TypeMember(value encoding,Tester.this.settings.StringSetting,false,true,) TypeMember(method ensuring,(cond: (scala.tools.nsc.Settings) => Boolean,msg: => Any)scala.tools.nsc.Settings,true,false,method any2Ensuring) TypeMember(method ensuring,(cond: (scala.tools.nsc.Settings) => Boolean)scala.tools.nsc.Settings,true,false,method any2Ensuring) diff --git a/test/files/jvm/manifests-new.check b/test/files/jvm/manifests-new.check new file mode 100644 index 0000000000..9fca856970 --- /dev/null +++ b/test/files/jvm/manifests-new.check @@ -0,0 +1,58 @@ +x=(), t=ConcreteTypeTag[Unit], k=TypeRef, s=class Unit +x=true, t=ConcreteTypeTag[Boolean], k=TypeRef, s=class Boolean +x=a, t=ConcreteTypeTag[Char], k=TypeRef, s=class Char +x=1, t=ConcreteTypeTag[Int], k=TypeRef, s=class Int +x=abc, t=ConcreteTypeTag[String], k=TypeRef, s=class String +x='abc, t=ConcreteTypeTag[Symbol], k=TypeRef, s=class Symbol + +x=List(()), t=ConcreteTypeTag[List[Unit]], k=TypeRef, s=class List +x=List(true), t=ConcreteTypeTag[List[Boolean]], k=TypeRef, s=class List +x=List(1), t=ConcreteTypeTag[List[Int]], k=TypeRef, s=class List +x=List(abc), t=ConcreteTypeTag[List[String]], k=TypeRef, s=class List +x=List('abc), t=ConcreteTypeTag[List[Symbol]], k=TypeRef, s=class List + +x=[Z, t=ConcreteTypeTag[Array[Boolean]], k=TypeRef, s=class Array +x=[C, t=ConcreteTypeTag[Array[Char]], k=TypeRef, s=class Array +x=[I, t=ConcreteTypeTag[Array[Int]], k=TypeRef, s=class Array +x=[Ljava.lang.String;, t=ConcreteTypeTag[Array[String]], k=TypeRef, s=class Array +x=[Lscala.Symbol;, t=ConcreteTypeTag[Array[Symbol]], k=TypeRef, s=class Array + +x=((),()), t=ConcreteTypeTag[(Unit, Unit)], k=TypeRef, s=class Tuple2 +x=(true,false), t=ConcreteTypeTag[(Boolean, Boolean)], k=TypeRef, s=class Tuple2 +x=(1,2), t=ConcreteTypeTag[(Int, Int)], k=TypeRef, s=class Tuple2 +x=(abc,xyz), t=ConcreteTypeTag[(String, String)], k=TypeRef, s=class Tuple2 +x=('abc,'xyz), t=ConcreteTypeTag[(Symbol, Symbol)], k=TypeRef, s=class Tuple2 + +x=Test$, t=ConcreteTypeTag[Test.type], k=TypeRef, s=object Test +x=scala.collection.immutable.List$, t=ConcreteTypeTag[scala.collection.immutable.List.type], k=TypeRef, s=object List + +x=Foo, t=ConcreteTypeTag[Foo[Int]], k=TypeRef, s=class Foo +x=Foo, t=ConcreteTypeTag[Foo[List[Int]]], k=TypeRef, s=class Foo +x=Foo, t=ConcreteTypeTag[Foo[Foo[Int]]], k=TypeRef, s=class Foo +x=Foo, t=ConcreteTypeTag[Foo[List[Foo[Int]]]], k=TypeRef, s=class Foo + +x=Test1$$anon$1, t=ConcreteTypeTag[Bar[String]], k=RefinedType, s= +x=Test1$$anon$2, t=ConcreteTypeTag[Bar[String]], k=RefinedType, s= + +()=() +true=true +a=a +1=1 +'abc='abc + +List(())=List(()) +List(true)=List(true) +List('abc)=List('abc) + +Array()=Array() +Array(true)=Array(true) +Array(a)=Array(a) +Array(1)=Array(1) + +((),())=((),()) +(true,false)=(true,false) + +List(List(1), List(2))=List(List(1), List(2)) + +Array(Array(1), Array(2))=Array(Array(1), Array(2)) + diff --git a/test/files/jvm/manifests-new.scala b/test/files/jvm/manifests-new.scala new file mode 100644 index 0000000000..d02f6ee608 --- /dev/null +++ b/test/files/jvm/manifests-new.scala @@ -0,0 +1,109 @@ +object Test extends App { + Test1 + Test2 +} + +class Foo[T](x: T) +trait Bar[T] { def f: T } + +object Test1 extends TestUtil { + print(()) + print(true) + print('a') + print(1) + print("abc") + print('abc) + println() + + print(List(())) + print(List(true)) + print(List(1)) + print(List("abc")) + print(List('abc)) + println() + + //print(Array(())) //Illegal class name "[V" in class file Test$ + print(Array(true)) + print(Array('a')) + print(Array(1)) + print(Array("abc")) + print(Array('abc)) + println() + + print(((), ())) + print((true, false)) + print((1, 2)) + print(("abc", "xyz")) + print(('abc, 'xyz)) + println() + + print(Test) + print(List) + println() + + print(new Foo(2)) + print(new Foo(List(2))) + print(new Foo(new Foo(2))) + print(new Foo(List(new Foo(2)))) + println() + + print(new Bar[String] { def f = "abc" }); + {print(new Bar[String] { def f = "abc" })} + println() +} + +object Test2 { + import scala.util.Marshal._ + println("()="+load[Unit](dump(()))) + println("true="+load[Boolean](dump(true))) + println("a="+load[Char](dump('a'))) + println("1="+load[Int](dump(1))) + println("'abc="+load[Symbol](dump('abc))) + println() + + println("List(())="+load[List[Unit]](dump(List(())))) + println("List(true)="+load[List[Boolean]](dump(List(true)))) + println("List('abc)="+load[List[Symbol]](dump(List('abc)))) + println() + + def loadArray[T](x: Array[Byte])(implicit t: reflect.ClassTag[Array[T]]) = + load[Array[T]](x)(t).deep.toString + println("Array()="+loadArray[Int](dump(Array(): Array[Int]))) + println("Array(true)="+loadArray[Boolean](dump(Array(true)))) + println("Array(a)="+loadArray[Char](dump(Array('a')))) + println("Array(1)="+loadArray[Int](dump(Array(1)))) + println() + + println("((),())="+load[(Unit, Unit)](dump(((), ())))) + println("(true,false)="+load[(Boolean, Boolean)](dump((true, false)))) + println() + + println("List(List(1), List(2))="+load[List[List[Int]]](dump(List(List(1), List(2))))) + println() + + println("Array(Array(1), Array(2))="+loadArray[Array[Int]](dump(Array(Array(1), Array(2))))) + println() +} + +trait TestUtil { + import java.io._ + def write[A](o: A): Array[Byte] = { + val ba = new ByteArrayOutputStream(512) + val out = new ObjectOutputStream(ba) + out.writeObject(o) + out.close() + ba.toByteArray() + } + def read[A](buffer: Array[Byte]): A = { + val in = new ObjectInputStream(new ByteArrayInputStream(buffer)) + in.readObject().asInstanceOf[A] + } + import scala.reflect._ + def print[T](x: T)(implicit t: ConcreteTypeTag[T]) { + // todo. type tags are not yet serializable +// val t1: ConcreteTypeTag[T] = read(write(t)) + val t1: ConcreteTypeTag[T] = t + val x1 = x.toString.replaceAll("@[0-9a-z]+$", "") + println("x="+x1+", t="+t1+", k="+t1.tpe.kind+", s="+t1.sym.toString) + } +} diff --git a/test/files/jvm/manifests.check b/test/files/jvm/manifests.check deleted file mode 100644 index be8ec2bb5b..0000000000 --- a/test/files/jvm/manifests.check +++ /dev/null @@ -1,56 +0,0 @@ -x=(), m=ConcreteTypeTag[Unit], k=TypeRef, s=class Unit -x=true, m=ConcreteTypeTag[Boolean], k=TypeRef, s=class Boolean -x=a, m=ConcreteTypeTag[Char], k=TypeRef, s=class Char -x=1, m=ConcreteTypeTag[Int], k=TypeRef, s=class Int -x=abc, m=ConcreteTypeTag[String], k=TypeRef, s=class String -x='abc, m=ConcreteTypeTag[Symbol], k=TypeRef, s=class Symbol - -x=List(()), m=ConcreteTypeTag[List[Unit]], k=TypeRef, s=class List -x=List(true), m=ConcreteTypeTag[List[Boolean]], k=TypeRef, s=class List -x=List(1), m=ConcreteTypeTag[List[Int]], k=TypeRef, s=class List -x=List(abc), m=ConcreteTypeTag[List[String]], k=TypeRef, s=class List -x=List('abc), m=ConcreteTypeTag[List[Symbol]], k=TypeRef, s=class List - -x=[Z, m=ConcreteTypeTag[Array[Boolean]], k=TypeRef, s=class Array -x=[C, m=ConcreteTypeTag[Array[Char]], k=TypeRef, s=class Array -x=[I, m=ConcreteTypeTag[Array[Int]], k=TypeRef, s=class Array -x=[Ljava.lang.String;, m=ConcreteTypeTag[Array[String]], k=TypeRef, s=class Array -x=[Lscala.Symbol;, m=ConcreteTypeTag[Array[Symbol]], k=TypeRef, s=class Array - -x=((),()), m=ConcreteTypeTag[(Unit, Unit)], k=TypeRef, s=class Tuple2 -x=(true,false), m=ConcreteTypeTag[(Boolean, Boolean)], k=TypeRef, s=class Tuple2 -x=(1,2), m=ConcreteTypeTag[(Int, Int)], k=TypeRef, s=class Tuple2 -x=(abc,xyz), m=ConcreteTypeTag[(String, String)], k=TypeRef, s=class Tuple2 -x=('abc,'xyz), m=ConcreteTypeTag[(Symbol, Symbol)], k=TypeRef, s=class Tuple2 - - -x=Foo, m=ConcreteTypeTag[Foo[Int]], k=TypeRef, s=class Foo -x=Foo, m=ConcreteTypeTag[Foo[List[Int]]], k=TypeRef, s=class Foo -x=Foo, m=ConcreteTypeTag[Foo[Foo[Int]]], k=TypeRef, s=class Foo -x=Foo, m=ConcreteTypeTag[Foo[List[Foo[Int]]]], k=TypeRef, s=class Foo - -x=Test1$$anon$1, m=ConcreteTypeTag[Bar[String]], k=RefinedType, s= -x=Test1$$anon$2, m=ConcreteTypeTag[Bar[String]], k=RefinedType, s= - -()=() -true=true -a=a -1=1 -'abc='abc - -List(())=List(()) -List(true)=List(true) -List('abc)=List('abc) - -Array()=Array() -Array(true)=Array(true) -Array(a)=Array(a) -Array(1)=Array(1) - -((),())=((),()) -(true,false)=(true,false) - -List(List(1), List(2))=List(List(1), List(2)) - -Array(Array(1), Array(2))=Array(Array(1), Array(2)) - diff --git a/test/files/jvm/manifests.scala b/test/files/jvm/manifests.scala deleted file mode 100644 index 935427f5d4..0000000000 --- a/test/files/jvm/manifests.scala +++ /dev/null @@ -1,112 +0,0 @@ -object Test extends App { - Test1 - Test2 -} - -class Foo[T](x: T) -trait Bar[T] { def f: T } - -object Test1 extends TestUtil { - print(()) - print(true) - print('a') - print(1) - print("abc") - print('abc) - println() - - print(List(())) - print(List(true)) - print(List(1)) - print(List("abc")) - print(List('abc)) - println() - - //print(Array(())) //Illegal class name "[V" in class file Test$ - print(Array(true)) - print(Array('a')) - print(Array(1)) - print(Array("abc")) - print(Array('abc)) - println() - - print(((), ())) - print((true, false)) - print((1, 2)) - print(("abc", "xyz")) - print(('abc, 'xyz)) - println() - - // Disabled: should these work? changing the inference for objects from - // "object Test" to "Test.type" drags in a singleton manifest which for - // some reason leads to serialization failure. - // print(Test) - // print(List) - println() - - print(new Foo(2)) - print(new Foo(List(2))) - print(new Foo(new Foo(2))) - print(new Foo(List(new Foo(2)))) - println() - - print(new Bar[String] { def f = "abc" }); - {print(new Bar[String] { def f = "abc" })} - println() -} - -object Test2 { - import scala.util.Marshal._ - println("()="+load[Unit](dump(()))) - println("true="+load[Boolean](dump(true))) - println("a="+load[Char](dump('a'))) - println("1="+load[Int](dump(1))) - println("'abc="+load[Symbol](dump('abc))) - println() - - println("List(())="+load[List[Unit]](dump(List(())))) - println("List(true)="+load[List[Boolean]](dump(List(true)))) - println("List('abc)="+load[List[Symbol]](dump(List('abc)))) - println() - - def loadArray[T](x: Array[Byte])(implicit m: reflect.Manifest[Array[T]]) = - load[Array[T]](x)(m).deep.toString - println("Array()="+loadArray[Int](dump(Array(): Array[Int]))) - println("Array(true)="+loadArray[Boolean](dump(Array(true)))) - println("Array(a)="+loadArray[Char](dump(Array('a')))) - println("Array(1)="+loadArray[Int](dump(Array(1)))) - println() - - println("((),())="+load[(Unit, Unit)](dump(((), ())))) - println("(true,false)="+load[(Boolean, Boolean)](dump((true, false)))) - println() - - println("List(List(1), List(2))="+load[List[List[Int]]](dump(List(List(1), List(2))))) - println() - - println("Array(Array(1), Array(2))="+loadArray[Array[Int]](dump(Array(Array(1), Array(2))))) - println() -} - -trait TestUtil { - import java.io._ - def write[A](o: A): Array[Byte] = { - val ba = new ByteArrayOutputStream(512) - val out = new ObjectOutputStream(ba) - out.writeObject(o) - out.close() - ba.toByteArray() - } - def read[A](buffer: Array[Byte]): A = { - val in = new ObjectInputStream(new ByteArrayInputStream(buffer)) - in.readObject().asInstanceOf[A] - } - import scala.reflect._ - def print[T](x: T)(implicit m: Manifest[T]) { - // manifests are no longer serializable -// val m1: Manifest[T] = read(write(m)) - val m1: Manifest[T] = m - val x1 = x.toString.replaceAll("@[0-9a-z]+$", "") - println("x="+x1+", m="+m1+", k="+m1.tpe.kind+", s="+m1.sym.toString) - } -} diff --git a/test/files/jvm/serialization-new.check b/test/files/jvm/serialization-new.check new file mode 100644 index 0000000000..fa51c6a879 --- /dev/null +++ b/test/files/jvm/serialization-new.check @@ -0,0 +1,313 @@ +a1 = Array[1,2,3] +_a1 = Array[1,2,3] +arrayEquals(a1, _a1): true + +e1 = Left(1) +_e1 = Left(1) +e1 eq _e1: false, _e1 eq e1: false +e1 equals _e1: true, _e1 equals e1: true + +x7 = RoundingMode +y7 = RoundingMode +x7 eq y7: true, y7 eq x7: true +x7 equals y7: true, y7 equals x7: true + +x8 = WeekDay +y8 = WeekDay +x8 eq y8: true, y8 eq x8: true +x8 equals y8: true, y8 equals x8: true + +x9 = UP +y9 = UP +x9 eq y9: true, y9 eq x9: true +x9 equals y9: true, y9 equals x9: true + +x10 = Monday +y10 = Monday +x10 eq y10: true, y10 eq x10: true +x10 equals y10: true, y10 equals x10: true + +x9 eq x10: false, x10 eq x9: false +x9 equals x10: false, x10 equals x9: false +x9 eq y10: false, y10 eq x9: false +x9 equals y10: false, y10 equals x9: false + +f1 = +_f1 = +f1(2): 4, _f1(2): 4 + +xs0 = List(1, 2, 3) +_xs0 = List(1, 2, 3) +xs0 eq _xs0: false, _xs0 eq xs0: false +xs0 equals _xs0: true, _xs0 equals xs0: true + +xs1 = List() +_xs1 = List() +xs1 eq _xs1: true, _xs1 eq xs1: true + +o1 = None +_o1 = None +o1 eq _o1: true, _o1 eq o1: true + +o2 = Some(1) +_o2 = Some(1) +o2 eq _o2: false, _o2 eq o2: false +o2 equals _o2: true, _o2 equals o2: true + +s1 = 'hello +_s1 = 'hello +s1 eq _s1: true, _s1 eq s1: true +s1 equals _s1: true, _s1 equals s1: true + +t1 = (BannerLimit,12345) +_t1 = (BannerLimit,12345) +t1 eq _t1: false, _t1 eq t1: false +t1 equals _t1: true, _t1 equals t1: true + +x = BitSet(1, 2) +y = BitSet(1, 2) +x equals y: true, y equals x: true + +x = BitSet(2, 3) +y = BitSet(2, 3) +x equals y: true, y equals x: true + +x = Map(1 -> A, 2 -> B, 3 -> C) +y = Map(1 -> A, 2 -> B, 3 -> C) +x equals y: true, y equals x: true + +x = Set(1, 2) +y = Set(1, 2) +x equals y: true, y equals x: true + +x = List((buffers,20), (layers,2), (title,3)) +y = List((buffers,20), (layers,2), (title,3)) +x equals y: true, y equals x: true + +x = Map(buffers -> 20, layers -> 2, title -> 3) +y = Map(buffers -> 20, layers -> 2, title -> 3) +x equals y: true, y equals x: true + +x = ListSet(5, 3) +y = ListSet(5, 3) +x equals y: true, y equals x: true + +x = Queue(a, b, c) +y = Queue(a, b, c) +x equals y: true, y equals x: true + +x = Range(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) +y = Range(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) +x equals y: true, y equals x: true + +x = NumericRange(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) +y = NumericRange(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) +x equals y: true, y equals x: true + +x = Map(1 -> A, 2 -> B, 3 -> C) +y = Map(1 -> A, 2 -> B, 3 -> C) +x equals y: true, y equals x: true + +x = TreeSet(1, 2, 3) +y = TreeSet(1, 2, 3) +x equals y: true, y equals x: true + +x = Stack(c, b, a) +y = Stack(c, b, a) +x equals y: true, y equals x: true + +x = Stream(0, ?) +y = Stream(0, ?) +x equals y: true, y equals x: true + +x = Map(42 -> FortyTwo) +y = Map(42 -> FortyTwo) +x equals y: true, y equals x: true + +x = TreeSet(0, 2) +y = TreeSet(0, 2) +x equals y: true, y equals x: true + +x = Vector('a, 'b, 'c) +y = Vector('a, 'b, 'c) +x equals y: true, y equals x: true + +x = ArrayBuffer(one, two) +y = ArrayBuffer(one, two) +x equals y: true, y equals x: true + +x = ArrayBuilder.ofLong +y = ArrayBuilder.ofLong +x equals y: true, y equals x: true + +x = ArrayBuilder.ofFloat +y = ArrayBuilder.ofFloat +x equals y: true, y equals x: true + +x = ArraySeq(1, 2, 3) +y = ArraySeq(1, 2, 3) +x equals y: true, y equals x: true + +x = ArrayStack(3, 2, 20) +y = ArrayStack(3, 2, 20) +x equals y: true, y equals x: true + +x = BitSet(0, 8, 9) +y = BitSet(0, 8, 9) +x equals y: true, y equals x: true + +x = Map(A -> 1, C -> 3, B -> 2) +y = Map(A -> 1, C -> 3, B -> 2) +x equals y: true, y equals x: true + +x = Set(buffers, title, layers) +y = Set(buffers, title, layers) +x equals y: true, y equals x: true + +x = History() +y = History() +x equals y: true, y equals x: true + +x = ListBuffer(white, black) +y = ListBuffer(white, black) +x equals y: true, y equals x: true + +x = Queue(20, 2, 3) +y = Queue(20, 2, 3) +x equals y: true, y equals x: true + +x = Stack(3, 2, 20) +y = Stack(3, 2, 20) +x equals y: true, y equals x: true + +x = abc +y = abc +x equals y: true, y equals x: true + +x = WrappedArray(1, 2, 3) +y = WrappedArray(1, 2, 3) +x equals y: true, y equals x: true + +x = TreeSet(1, 2, 3) +y = TreeSet(1, 2, 3) +x equals y: true, y equals x: true + +x = TrieMap(1 -> one, 2 -> two, 3 -> three) +y = TrieMap(1 -> one, 2 -> two, 3 -> three) +x equals y: true, y equals x: true + +x = xml:src="hello" +y = xml:src="hello" +x equals y: true, y equals x: true + +x = +y = +x equals y: true, y equals x: true + +x = title +y = title +x equals y: true, y equals x: true + +x = + + + + + + + + + + + + + + + + +
Last NameFirst Name
Tom 20
Bob 22
James 19
+ + +y = + + + + + + + + + + + + + + + + +
Last NameFirst Name
Tom 20
Bob 22
James 19
+ + +x equals y: true, y equals x: true + +x = Tim +y = Tim +x equals y: true, y equals x: true + +x = Bob +y = Bob +x equals y: true, y equals x: true + +x = John +y = John +x equals y: true, y equals x: true + +x = Bill +y = Bill +x equals y: true, y equals x: true + +x = Paul +y = Paul +x equals y: true, y equals x: true + +1 +2 +1 +2 + +x = UnrolledBuffer(one, two) +y = UnrolledBuffer(one, two) +x equals y: true, y equals x: true + +x = ParArray(abc, def, etc) +y = ParArray(abc, def, etc) +x equals y: true, y equals x: true + +x = ParHashMap(2 -> 4, 1 -> 2) +y = ParHashMap(2 -> 4, 1 -> 2) +x equals y: true, y equals x: true + +x = ParTrieMap(1 -> 2, 2 -> 4) +y = ParTrieMap(1 -> 2, 2 -> 4) +x equals y: true, y equals x: true + +x = ParHashSet(1, 2, 3) +y = ParHashSet(1, 2, 3) +x equals y: true, y equals x: true + +x = ParRange(0, 1, 2, 3, 4) +y = ParRange(0, 1, 2, 3, 4) +x equals y: true, y equals x: true + +x = ParRange(0, 1, 2, 3) +y = ParRange(0, 1, 2, 3) +x equals y: true, y equals x: true + +x = ParMap(5 -> 1, 10 -> 2) +y = ParMap(5 -> 1, 10 -> 2) +x equals y: true, y equals x: true + +x = ParSet(two, one) +y = ParSet(two, one) +x equals y: true, y equals x: true + diff --git a/test/files/jvm/serialization-new.scala b/test/files/jvm/serialization-new.scala new file mode 100644 index 0000000000..bb971fdf36 --- /dev/null +++ b/test/files/jvm/serialization-new.scala @@ -0,0 +1,651 @@ +//############################################################################ +// Serialization +//############################################################################ + +object Serialize { + @throws(classOf[java.io.IOException]) + def write[A](o: A): Array[Byte] = { + val ba = new java.io.ByteArrayOutputStream(512) + val out = new java.io.ObjectOutputStream(ba) + out.writeObject(o) + out.close() + ba.toByteArray() + } + @throws(classOf[java.io.IOException]) + @throws(classOf[ClassNotFoundException]) + def read[A](buffer: Array[Byte]): A = { + val in = + new java.io.ObjectInputStream(new java.io.ByteArrayInputStream(buffer)) + in.readObject().asInstanceOf[A] + } + def check[A, B](x: A, y: B) { + println("x = " + x) + println("y = " + y) + println("x equals y: " + (x equals y) + ", y equals x: " + (y equals x)) + assert((x equals y) && (y equals x)) + println() + } +} +import Serialize._ + +//############################################################################ +// Test classes in package "scala" + +object Test1_scala { + + private def arrayToString[A](arr: Array[A]): String = + arr.mkString("Array[",",","]") + + private def arrayEquals[A, B](a1: Array[A], a2: Array[B]): Boolean = + (a1.length == a2.length) && + (Iterator.range(0, a1.length) forall { i => a1(i) == a2(i) }) + + object WeekDay extends Enumeration { + type WeekDay = Value + val Monday, Tuesday, Wednesday, Thusday, Friday, Saturday, Sunday = Value + } + import WeekDay._, BigDecimal._, RoundingMode._ + + // in alphabetic order + try { + // Array + val a1 = Array(1, 2, 3) + val _a1: Array[Int] = read(write(a1)) + println("a1 = " + arrayToString(a1)) + println("_a1 = " + arrayToString(_a1)) + println("arrayEquals(a1, _a1): " + arrayEquals(a1, _a1)) + println() + + // Either + val e1 = Left(1) + val _e1: Either[Int, String] = read(write(e1)) + println("e1 = " + e1) + println("_e1 = " + _e1) + println("e1 eq _e1: " + (e1 eq _e1) + ", _e1 eq e1: " + (_e1 eq e1)) + println("e1 equals _e1: " + (e1 equals _e1) + ", _e1 equals e1: " + (_e1 equals e1)) + println() + + // Enumeration + val x7 = BigDecimal.RoundingMode + val y7: RoundingMode.type = read(write(x7)) + println("x7 = " + x7) + println("y7 = " + y7) + println("x7 eq y7: " + (x7 eq y7) + ", y7 eq x7: " + (y7 eq x7)) + println("x7 equals y7: " + (x7 equals y7) + ", y7 equals x7: " + (y7 equals x7)) + println() + + val x8 = WeekDay + val y8: WeekDay.type = read(write(x8)) + println("x8 = " + x8) + println("y8 = " + y8) + println("x8 eq y8: " + (x8 eq y8) + ", y8 eq x8: " + (y8 eq x8)) + println("x8 equals y8: " + (x8 equals y8) + ", y8 equals x8: " + (y8 equals x8)) + println() + + val x9 = UP + val y9: RoundingMode = read(write(x9)) + println("x9 = " + x9) + println("y9 = " + y9) + println("x9 eq y9: " + (x9 eq y9) + ", y9 eq x9: " + (y9 eq x9)) + println("x9 equals y9: " + (x9 equals y9) + ", y9 equals x9: " + (y9 equals x9)) + println() + + val x10 = Monday + val y10: WeekDay = read(write(x10)) + println("x10 = " + x10) + println("y10 = " + y10) + println("x10 eq y10: " + (x10 eq y10) + ", y10 eq x10: " + (y10 eq x10)) + println("x10 equals y10: " + (x10 equals y10) + ", y10 equals x10: " + (y10 equals x10)) + println() + + println("x9 eq x10: " + (x9 eq x10) + ", x10 eq x9: " + (x10 eq x9)) + println("x9 equals x10: " + (x9 equals x10) + ", x10 equals x9: " + (x10 equals x9)) + println("x9 eq y10: " + (x9 eq y10) + ", y10 eq x9: " + (y10 eq x9)) + println("x9 equals y10: " + (x9 equals y10) + ", y10 equals x9: " + (y10 equals x9)) + println() + + // Function + val f1 = { x: Int => 2 * x } + val _f1: Function[Int, Int] = read(write(f1)) + println("f1 = ") + println("_f1 = ") + println("f1(2): " + f1(2) + ", _f1(2): " + _f1(2)) + println() + + // List + val xs0 = List(1, 2, 3) + val _xs0: List[Int] = read(write(xs0)) + println("xs0 = " + xs0) + println("_xs0 = " + _xs0) + println("xs0 eq _xs0: " + (xs0 eq _xs0) + ", _xs0 eq xs0: " + (_xs0 eq xs0)) + println("xs0 equals _xs0: " + (xs0 equals _xs0) + ", _xs0 equals xs0: " + (_xs0 equals xs0)) + println() + + val xs1 = Nil + val _xs1: List[Nothing] = read(write(xs1)) + println("xs1 = " + xs1) + println("_xs1 = " + _xs1) + println("xs1 eq _xs1: " + (xs1 eq _xs1) + ", _xs1 eq xs1: " + (_xs1 eq xs1)) + println() + + // Option + val o1 = None + val _o1: Option[Nothing] = read(write(o1)) + println("o1 = " + o1) + println("_o1 = " + _o1) + println("o1 eq _o1: " + (o1 eq _o1) + ", _o1 eq o1: " + (_o1 eq o1)) + println() + + val o2 = Some(1) + val _o2: Option[Int] = read(write(o2)) + println("o2 = " + o2) + println("_o2 = " + _o2) + println("o2 eq _o2: " + (o2 eq _o2) + ", _o2 eq o2: " + (_o2 eq o2)) + println("o2 equals _o2: " + (o2 equals _o2) + ", _o2 equals o2: " + (_o2 equals o2)) + println() +/* + // Responder + val r1 = Responder.constant("xyz") + val _r1: Responder[String] = read(write(r1)) + check(r1, _r1) +*/ + // Symbol + val s1 = 'hello + val _s1: Symbol = read(write(s1)) + println("s1 = " + s1) + println("_s1 = " + _s1) + println("s1 eq _s1: " + (s1 eq _s1) + ", _s1 eq s1: " + (_s1 eq s1)) + println("s1 equals _s1: " + (s1 equals _s1) + ", _s1 equals s1: " + (_s1 equals s1)) + println() + + // Tuple + val t1 = ("BannerLimit", 12345) + val _t1: (String, Int) = read(write(t1)) + println("t1 = " + t1) + println("_t1 = " + _t1) + println("t1 eq _t1: " + (t1 eq _t1) + ", _t1 eq t1: " + (_t1 eq t1)) + println("t1 equals _t1: " + (t1 equals _t1) + ", _t1 equals t1: " + (_t1 equals t1)) + println() + } + catch { + case e: Exception => + println("Error in Test1_scala: " + e) + throw e + } +} + +//############################################################################ +// Test classes in package "scala.collection.immutable" + +object Test2_immutable { + import scala.collection.immutable.{ + BitSet, HashMap, HashSet, ListMap, ListSet, Queue, Range, SortedMap, + SortedSet, Stack, Stream, TreeMap, TreeSet, Vector} + + // in alphabetic order + try { + // BitSet + val bs1 = BitSet.empty + 1 + 2 + val _bs1: BitSet = read(write(bs1)) + check(bs1, _bs1) + + val bs2 = { + val bs = new collection.mutable.BitSet() + bs += 2; bs += 3 + bs.toImmutable + } + val _bs2: BitSet = read(write(bs2)) + check(bs2, _bs2) + + // HashMap + val hm1 = new HashMap[Int, String] + (1 -> "A", 2 -> "B", 3 -> "C") + val _hm1: HashMap[Int, String] = read(write(hm1)) + check(hm1, _hm1) + + // HashSet + val hs1 = new HashSet[Int] + 1 + 2 + val _hs1: HashSet[Int] = read(write(hs1)) + check(hs1, _hs1) + + // List + val xs1 = List(("buffers", 20), ("layers", 2), ("title", 3)) + val _xs1: List[(String, Int)] = read(write(xs1)) + check(xs1, _xs1) + + // ListMap + val lm1 = new ListMap[String, Int] + ("buffers" -> 20, "layers" -> 2, "title" -> 3) + val _lm1: ListMap[String, Int] = read(write(lm1)) + check(lm1, _lm1) + + // ListSet + val ls1 = new ListSet[Int] + 3 + 5 + val _ls1: ListSet[Int] = read(write(ls1)) + check(ls1, _ls1) + + // Queue + val q1 = Queue("a", "b", "c") + val _q1: Queue[String] = read(write(q1)) + check(q1, _q1) + + // Range + val r1 = 0 until 10 + val _r1: Range = read(write(r1)) + check(r1, _r1) + + val r2 = Range.Long(0L, 10L, 1) + val _r2: r2.type = read(write(r2)) + check(r2, _r2) + + // SortedMap + val sm1 = SortedMap.empty[Int, String] + (2 -> "B", 3 -> "C", 1 -> "A") + val _sm1: SortedMap[Int, String] = read(write(sm1)) + check(sm1, _sm1) + + // SortedSet + val ss1 = SortedSet.empty[Int] + 2 + 3 + 1 + val _ss1: SortedSet[Int] = read(write(ss1)) + check(ss1, _ss1) + + // Stack + val s1 = new Stack().push("a", "b", "c") + val _s1: Stack[String] = read(write(s1)) + check(s1, _s1) + + // Stream + val st1 = Stream.range(0, 10) + val _st1: Stream[Int] = read(write(st1)) + check(st1, _st1) + + // TreeMap + val tm1 = new TreeMap[Int, String] + (42 -> "FortyTwo") + val _tm1: TreeMap[Int, String] = read(write(tm1)) + check(tm1, _tm1) + + // TreeSet + val ts1 = new TreeSet[Int]() + 2 + 0 + val _ts1: TreeSet[Int] = read(write(ts1)) + check(ts1, _ts1) + + // Vector + val v1 = Vector('a, 'b, 'c) + val _v1: Vector[Symbol] = read(write(v1)) + check(v1, _v1) + } + catch { + case e: Exception => + println("Error in Test2_immutable: " + e) + throw e + } +} + +//############################################################################ +// Test classes in package "scala.collection.mutable" + +object Test3_mutable { + import scala.reflect.ArrayTag + import scala.collection.mutable.{ + ArrayBuffer, ArrayBuilder, ArraySeq, ArrayStack, BitSet, DoubleLinkedList, + HashMap, HashSet, History, LinkedList, ListBuffer, Publisher, Queue, + Stack, StringBuilder, WrappedArray, TreeSet} + import scala.collection.concurrent.TrieMap + + // in alphabetic order + try { + // ArrayBuffer + val ab1 = new ArrayBuffer[String] + ab1 ++= List("one", "two") + val _ab1: ArrayBuffer[String] = read(write(ab1)) + check(ab1, _ab1) + + // ArrayBuilder + val abu1 = ArrayBuilder.make[Long] + val _abu1: ArrayBuilder[ArrayTag[Long]] = read(write(abu1)) + check(abu1, _abu1) + + val abu2 = ArrayBuilder.make[Float] + val _abu2: ArrayBuilder[ArrayTag[Float]] = read(write(abu2)) + check(abu2, _abu2) + + // ArraySeq + val aq1 = ArraySeq(1, 2, 3) + val _aq1: ArraySeq[Int] = read(write(aq1)) + check(aq1, _aq1) + + // ArrayStack + val as1 = new ArrayStack[Int] + as1 ++= List(20, 2, 3).iterator + val _as1: ArrayStack[Int] = read(write(as1)) + check(as1, _as1) + + // BitSet + val bs1 = new BitSet() + bs1 += 0 + bs1 += 8 + bs1 += 9 + val _bs1: BitSet = read(write(bs1)) + check(bs1, _bs1) +/* + // DoubleLinkedList + val dl1 = new DoubleLinkedList[Int](2, null) + dl1.append(new DoubleLinkedList(3, null)) + val _dl1: DoubleLinkedList[Int] = read(write(dl1)) + check(dl1, _dl1) +*/ + // HashMap + val hm1 = new HashMap[String, Int] + hm1 ++= List(("A", 1), ("B", 2), ("C", 3)).iterator + val _hm1: HashMap[String, Int] = read(write(hm1)) + check(hm1, _hm1) + + // HashSet + val hs1 = new HashSet[String] + hs1 ++= List("layers", "buffers", "title").iterator + val _hs1: HashSet[String] = read(write(hs1)) + check(hs1, _hs1) + + val h1 = new History[String, Int] + val _h1: History[String, Int] = read(write(h1)) + check(h1, _h1) +/* + // LinkedList + val ll1 = new LinkedList[Int](2, null) + ll1.append(new LinkedList(3, null)) + val _ll1: LinkedList[Int] = read(write(ll1)) + check(ll1, _ll1) +*/ + // ListBuffer + val lb1 = new ListBuffer[String] + lb1 ++= List("white", "black") + val _lb1: ListBuffer[String] = read(write(lb1)) + check(lb1, _lb1) + + // Queue + val q1 = new Queue[Int] + q1 ++= List(20, 2, 3).iterator + val _q1: Queue[Int] = read(write(q1)) + check(q1, _q1) + + // Stack + val s1 = new Stack[Int] + s1 pushAll q1 + val _s1: Stack[Int] = read(write(s1)) + check(s1, _s1) + + // StringBuilder + val sb1 = new StringBuilder + sb1 append "abc" + val _sb1: StringBuilder = read(write(sb1)) + check(sb1, _sb1) + + // WrappedArray + val wa1 = WrappedArray.make(Array(1, 2, 3)) + val _wa1: WrappedArray[Int] = read(write(wa1)) + check(wa1, _wa1) + + // TreeSet + val ts1 = TreeSet[Int]() ++= Array(1, 2, 3) + val _ts1: TreeSet[Int] = read(write(ts1)) + check(ts1, _ts1) + + // concurrent.TrieMap + val ct1 = TrieMap[Int, String]() ++= Array(1 -> "one", 2 -> "two", 3 -> "three") + val _ct1: TrieMap[Int, String] = read(write(ct1)) + check(ct1, _ct1) + } + catch { + case e: Exception => + println("Error in Test3_mutable: " + e) + throw e + } +} + + +//############################################################################ +// Test classes in package "scala.xml" + +object Test4_xml { + import scala.xml.{Attribute, Document, Elem, Null, PrefixedAttribute, Text} + + case class Person(name: String, age: Int) + + try { + // Attribute + val a1 = new PrefixedAttribute("xml", "src", Text("hello"), Null) + val _a1: Attribute = read(write(a1)) + check(a1, _a1) + + // Document + val d1 = new Document + d1.docElem = + d1.encoding = Some("UTF-8") + val _d1: Document = read(write(d1)) + check(d1, _d1) + + // Elem + val e1 = title; + val _e1: Elem = read(write(e1)) + check(e1, _e1) + + class AddressBook(a: Person*) { + private val people: List[Person] = a.toList + def toXHTML = + + + + + + { for (p <- people) yield + + + + } +
Last NameFirst Name
{ p.name } { p.age.toString() }
; + } + + val people = new AddressBook( + Person("Tom", 20), + Person("Bob", 22), + Person("James", 19)) + + val e2 = + + + { people.toXHTML } + + ; + val _e2: Elem = read(write(e2)) + check(e2, _e2) + } + catch { + case e: Exception => + println("Error in Test4_xml: " + e) + throw e + } +} + +//############################################################################ +// Test user-defined classes WITHOUT nesting + +class Person(_name: String) extends Serializable { + private var name = _name + override def toString() = name + override def equals(that: Any): Boolean = + that.isInstanceOf[Person] && + (name == that.asInstanceOf[Person].name) +} + +class Employee(_name: String) extends Serializable { + private var name = _name + override def toString() = name +} + +object bob extends Employee("Bob") + +object Test5 { + val x1 = new Person("Tim") + val x2 = bob + + try { + val y1: Person = read(write(x1)) + val y2: Employee = read(write(x2)) + + check(x1, y1) + check(x2, y2) + } + catch { + case e: Exception => + println("Error in Test5: " + e) + } +} + +//############################################################################ +// Test user-defined classes WITH nesting + +object Test6 { + object bill extends Employee("Bill") { + val x = paul + } + object paul extends Person("Paul") { + val x = 4 // bill; => StackOverflowException !!! + } + val x1 = new Person("John") + val x2 = bill + val x3 = paul + + try { + val y1: Person = read(write(x1)) + val y2: Employee = read(write(x2)) + val y3: Person = read(write(x3)) + + check(x1, y1) + check(x2, y2) + check(x3, y3) + } + catch { + case e: Exception => + println("Error in Test6: " + e) + } +} + +//############################################################################ +// Nested objects cannot get readresolve automatically because after deserialization +// they would be null (they are treated as lazy vals) +class Outer extends Serializable { + object Inner extends Serializable +} + +object Test7 { + val x = new Outer + x.Inner // initialize + val y:Outer = read(write(x)) + if (y.Inner == null) + println("Inner object is null") +} + +// Verify that transient lazy vals don't get serialized +class WithTransient extends Serializable { + @transient lazy val a1 = 1 + @transient private lazy val a2 = 2 + @transient object B extends Serializable + @transient private object C extends Serializable + + def test = { + println(a1) + println(a2) + if (B == null || C == null) + println("Transient nested object failed to serialize properly") + } +} + +object Test8 { + val x = new WithTransient + x.test + try { + val y:WithTransient = read(write(x)) + y.test + } + catch { + case e: Exception => + println("Error in Test8: " + e) + } +} + +//############################################################################ +// Test code + +object Test { + def main(args: Array[String]) { + Test1_scala + Test2_immutable + Test3_mutable + Test4_xml + Test5 + Test6 + Test7 + Test8 + Test9_parallel + } +} + +//############################################################################ + + +//############################################################################ +// Test classes in package "scala.collection.parallel" and subpackages +object Test9_parallel { + import scala.collection.parallel._ + + try { + println() + + // UnrolledBuffer + val ub = new collection.mutable.UnrolledBuffer[String] + ub ++= List("one", "two") + val _ub: collection.mutable.UnrolledBuffer[String] = read(write(ub)) + check(ub, _ub) + + // mutable.ParArray + val pa = mutable.ParArray("abc", "def", "etc") + val _pa: mutable.ParArray[String] = read(write(pa)) + check(pa, _pa) + + // mutable.ParHashMap + val mpm = mutable.ParHashMap(1 -> 2, 2 -> 4) + val _mpm: mutable.ParHashMap[Int, Int] = read(write(mpm)) + check(mpm, _mpm) + + // mutable.ParTrieMap + val mpc = mutable.ParTrieMap(1 -> 2, 2 -> 4) + val _mpc: mutable.ParTrieMap[Int, Int] = read(write(mpc)) + check(mpc, _mpc) + + // mutable.ParHashSet + val mps = mutable.ParHashSet(1, 2, 3) + val _mps: mutable.ParHashSet[Int] = read(write(mps)) + check(mps, _mps) + + // immutable.ParRange + val pr1 = immutable.ParRange(0, 4, 1, true) + val _pr1: immutable.ParRange = read(write(pr1)) + check(pr1, _pr1) + + val pr2 = immutable.ParRange(0, 4, 1, false) + val _pr2: immutable.ParRange = read(write(pr2)) + check(pr2, _pr2) + + // immutable.ParHashMap + val ipm = immutable.ParHashMap(5 -> 1, 10 -> 2) + val _ipm: immutable.ParHashMap[Int, Int] = read(write(ipm)) + check(ipm, _ipm) + + // immutable.ParHashSet + val ips = immutable.ParHashSet("one", "two") + val _ips: immutable.ParHashSet[String] = read(write(ips)) + check(ips, _ips) + + } catch { + case e: Exception => + println("Error in Test5_parallel: " + e) + throw e + } +} diff --git a/test/files/jvm/serialization.check b/test/files/jvm/serialization.check deleted file mode 100644 index fa51c6a879..0000000000 --- a/test/files/jvm/serialization.check +++ /dev/null @@ -1,313 +0,0 @@ -a1 = Array[1,2,3] -_a1 = Array[1,2,3] -arrayEquals(a1, _a1): true - -e1 = Left(1) -_e1 = Left(1) -e1 eq _e1: false, _e1 eq e1: false -e1 equals _e1: true, _e1 equals e1: true - -x7 = RoundingMode -y7 = RoundingMode -x7 eq y7: true, y7 eq x7: true -x7 equals y7: true, y7 equals x7: true - -x8 = WeekDay -y8 = WeekDay -x8 eq y8: true, y8 eq x8: true -x8 equals y8: true, y8 equals x8: true - -x9 = UP -y9 = UP -x9 eq y9: true, y9 eq x9: true -x9 equals y9: true, y9 equals x9: true - -x10 = Monday -y10 = Monday -x10 eq y10: true, y10 eq x10: true -x10 equals y10: true, y10 equals x10: true - -x9 eq x10: false, x10 eq x9: false -x9 equals x10: false, x10 equals x9: false -x9 eq y10: false, y10 eq x9: false -x9 equals y10: false, y10 equals x9: false - -f1 = -_f1 = -f1(2): 4, _f1(2): 4 - -xs0 = List(1, 2, 3) -_xs0 = List(1, 2, 3) -xs0 eq _xs0: false, _xs0 eq xs0: false -xs0 equals _xs0: true, _xs0 equals xs0: true - -xs1 = List() -_xs1 = List() -xs1 eq _xs1: true, _xs1 eq xs1: true - -o1 = None -_o1 = None -o1 eq _o1: true, _o1 eq o1: true - -o2 = Some(1) -_o2 = Some(1) -o2 eq _o2: false, _o2 eq o2: false -o2 equals _o2: true, _o2 equals o2: true - -s1 = 'hello -_s1 = 'hello -s1 eq _s1: true, _s1 eq s1: true -s1 equals _s1: true, _s1 equals s1: true - -t1 = (BannerLimit,12345) -_t1 = (BannerLimit,12345) -t1 eq _t1: false, _t1 eq t1: false -t1 equals _t1: true, _t1 equals t1: true - -x = BitSet(1, 2) -y = BitSet(1, 2) -x equals y: true, y equals x: true - -x = BitSet(2, 3) -y = BitSet(2, 3) -x equals y: true, y equals x: true - -x = Map(1 -> A, 2 -> B, 3 -> C) -y = Map(1 -> A, 2 -> B, 3 -> C) -x equals y: true, y equals x: true - -x = Set(1, 2) -y = Set(1, 2) -x equals y: true, y equals x: true - -x = List((buffers,20), (layers,2), (title,3)) -y = List((buffers,20), (layers,2), (title,3)) -x equals y: true, y equals x: true - -x = Map(buffers -> 20, layers -> 2, title -> 3) -y = Map(buffers -> 20, layers -> 2, title -> 3) -x equals y: true, y equals x: true - -x = ListSet(5, 3) -y = ListSet(5, 3) -x equals y: true, y equals x: true - -x = Queue(a, b, c) -y = Queue(a, b, c) -x equals y: true, y equals x: true - -x = Range(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) -y = Range(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) -x equals y: true, y equals x: true - -x = NumericRange(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) -y = NumericRange(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) -x equals y: true, y equals x: true - -x = Map(1 -> A, 2 -> B, 3 -> C) -y = Map(1 -> A, 2 -> B, 3 -> C) -x equals y: true, y equals x: true - -x = TreeSet(1, 2, 3) -y = TreeSet(1, 2, 3) -x equals y: true, y equals x: true - -x = Stack(c, b, a) -y = Stack(c, b, a) -x equals y: true, y equals x: true - -x = Stream(0, ?) -y = Stream(0, ?) -x equals y: true, y equals x: true - -x = Map(42 -> FortyTwo) -y = Map(42 -> FortyTwo) -x equals y: true, y equals x: true - -x = TreeSet(0, 2) -y = TreeSet(0, 2) -x equals y: true, y equals x: true - -x = Vector('a, 'b, 'c) -y = Vector('a, 'b, 'c) -x equals y: true, y equals x: true - -x = ArrayBuffer(one, two) -y = ArrayBuffer(one, two) -x equals y: true, y equals x: true - -x = ArrayBuilder.ofLong -y = ArrayBuilder.ofLong -x equals y: true, y equals x: true - -x = ArrayBuilder.ofFloat -y = ArrayBuilder.ofFloat -x equals y: true, y equals x: true - -x = ArraySeq(1, 2, 3) -y = ArraySeq(1, 2, 3) -x equals y: true, y equals x: true - -x = ArrayStack(3, 2, 20) -y = ArrayStack(3, 2, 20) -x equals y: true, y equals x: true - -x = BitSet(0, 8, 9) -y = BitSet(0, 8, 9) -x equals y: true, y equals x: true - -x = Map(A -> 1, C -> 3, B -> 2) -y = Map(A -> 1, C -> 3, B -> 2) -x equals y: true, y equals x: true - -x = Set(buffers, title, layers) -y = Set(buffers, title, layers) -x equals y: true, y equals x: true - -x = History() -y = History() -x equals y: true, y equals x: true - -x = ListBuffer(white, black) -y = ListBuffer(white, black) -x equals y: true, y equals x: true - -x = Queue(20, 2, 3) -y = Queue(20, 2, 3) -x equals y: true, y equals x: true - -x = Stack(3, 2, 20) -y = Stack(3, 2, 20) -x equals y: true, y equals x: true - -x = abc -y = abc -x equals y: true, y equals x: true - -x = WrappedArray(1, 2, 3) -y = WrappedArray(1, 2, 3) -x equals y: true, y equals x: true - -x = TreeSet(1, 2, 3) -y = TreeSet(1, 2, 3) -x equals y: true, y equals x: true - -x = TrieMap(1 -> one, 2 -> two, 3 -> three) -y = TrieMap(1 -> one, 2 -> two, 3 -> three) -x equals y: true, y equals x: true - -x = xml:src="hello" -y = xml:src="hello" -x equals y: true, y equals x: true - -x = -y = -x equals y: true, y equals x: true - -x = title -y = title -x equals y: true, y equals x: true - -x = - - - - - - - - - - - - - - - - -
Last NameFirst Name
Tom 20
Bob 22
James 19
- - -y = - - - - - - - - - - - - - - - - -
Last NameFirst Name
Tom 20
Bob 22
James 19
- - -x equals y: true, y equals x: true - -x = Tim -y = Tim -x equals y: true, y equals x: true - -x = Bob -y = Bob -x equals y: true, y equals x: true - -x = John -y = John -x equals y: true, y equals x: true - -x = Bill -y = Bill -x equals y: true, y equals x: true - -x = Paul -y = Paul -x equals y: true, y equals x: true - -1 -2 -1 -2 - -x = UnrolledBuffer(one, two) -y = UnrolledBuffer(one, two) -x equals y: true, y equals x: true - -x = ParArray(abc, def, etc) -y = ParArray(abc, def, etc) -x equals y: true, y equals x: true - -x = ParHashMap(2 -> 4, 1 -> 2) -y = ParHashMap(2 -> 4, 1 -> 2) -x equals y: true, y equals x: true - -x = ParTrieMap(1 -> 2, 2 -> 4) -y = ParTrieMap(1 -> 2, 2 -> 4) -x equals y: true, y equals x: true - -x = ParHashSet(1, 2, 3) -y = ParHashSet(1, 2, 3) -x equals y: true, y equals x: true - -x = ParRange(0, 1, 2, 3, 4) -y = ParRange(0, 1, 2, 3, 4) -x equals y: true, y equals x: true - -x = ParRange(0, 1, 2, 3) -y = ParRange(0, 1, 2, 3) -x equals y: true, y equals x: true - -x = ParMap(5 -> 1, 10 -> 2) -y = ParMap(5 -> 1, 10 -> 2) -x equals y: true, y equals x: true - -x = ParSet(two, one) -y = ParSet(two, one) -x equals y: true, y equals x: true - diff --git a/test/files/jvm/serialization.scala b/test/files/jvm/serialization.scala deleted file mode 100644 index 9c2f2acdbf..0000000000 --- a/test/files/jvm/serialization.scala +++ /dev/null @@ -1,651 +0,0 @@ -//############################################################################ -// Serialization -//############################################################################ - -object Serialize { - @throws(classOf[java.io.IOException]) - def write[A](o: A): Array[Byte] = { - val ba = new java.io.ByteArrayOutputStream(512) - val out = new java.io.ObjectOutputStream(ba) - out.writeObject(o) - out.close() - ba.toByteArray() - } - @throws(classOf[java.io.IOException]) - @throws(classOf[ClassNotFoundException]) - def read[A](buffer: Array[Byte]): A = { - val in = - new java.io.ObjectInputStream(new java.io.ByteArrayInputStream(buffer)) - in.readObject().asInstanceOf[A] - } - def check[A, B](x: A, y: B) { - println("x = " + x) - println("y = " + y) - println("x equals y: " + (x equals y) + ", y equals x: " + (y equals x)) - assert((x equals y) && (y equals x)) - println() - } -} -import Serialize._ - -//############################################################################ -// Test classes in package "scala" - -object Test1_scala { - - private def arrayToString[A](arr: Array[A]): String = - arr.mkString("Array[",",","]") - - private def arrayEquals[A, B](a1: Array[A], a2: Array[B]): Boolean = - (a1.length == a2.length) && - (Iterator.range(0, a1.length) forall { i => a1(i) == a2(i) }) - - object WeekDay extends Enumeration { - type WeekDay = Value - val Monday, Tuesday, Wednesday, Thusday, Friday, Saturday, Sunday = Value - } - import WeekDay._, BigDecimal._, RoundingMode._ - - // in alphabetic order - try { - // Array - val a1 = Array(1, 2, 3) - val _a1: Array[Int] = read(write(a1)) - println("a1 = " + arrayToString(a1)) - println("_a1 = " + arrayToString(_a1)) - println("arrayEquals(a1, _a1): " + arrayEquals(a1, _a1)) - println() - - // Either - val e1 = Left(1) - val _e1: Either[Int, String] = read(write(e1)) - println("e1 = " + e1) - println("_e1 = " + _e1) - println("e1 eq _e1: " + (e1 eq _e1) + ", _e1 eq e1: " + (_e1 eq e1)) - println("e1 equals _e1: " + (e1 equals _e1) + ", _e1 equals e1: " + (_e1 equals e1)) - println() - - // Enumeration - val x7 = BigDecimal.RoundingMode - val y7: RoundingMode.type = read(write(x7)) - println("x7 = " + x7) - println("y7 = " + y7) - println("x7 eq y7: " + (x7 eq y7) + ", y7 eq x7: " + (y7 eq x7)) - println("x7 equals y7: " + (x7 equals y7) + ", y7 equals x7: " + (y7 equals x7)) - println() - - val x8 = WeekDay - val y8: WeekDay.type = read(write(x8)) - println("x8 = " + x8) - println("y8 = " + y8) - println("x8 eq y8: " + (x8 eq y8) + ", y8 eq x8: " + (y8 eq x8)) - println("x8 equals y8: " + (x8 equals y8) + ", y8 equals x8: " + (y8 equals x8)) - println() - - val x9 = UP - val y9: RoundingMode = read(write(x9)) - println("x9 = " + x9) - println("y9 = " + y9) - println("x9 eq y9: " + (x9 eq y9) + ", y9 eq x9: " + (y9 eq x9)) - println("x9 equals y9: " + (x9 equals y9) + ", y9 equals x9: " + (y9 equals x9)) - println() - - val x10 = Monday - val y10: WeekDay = read(write(x10)) - println("x10 = " + x10) - println("y10 = " + y10) - println("x10 eq y10: " + (x10 eq y10) + ", y10 eq x10: " + (y10 eq x10)) - println("x10 equals y10: " + (x10 equals y10) + ", y10 equals x10: " + (y10 equals x10)) - println() - - println("x9 eq x10: " + (x9 eq x10) + ", x10 eq x9: " + (x10 eq x9)) - println("x9 equals x10: " + (x9 equals x10) + ", x10 equals x9: " + (x10 equals x9)) - println("x9 eq y10: " + (x9 eq y10) + ", y10 eq x9: " + (y10 eq x9)) - println("x9 equals y10: " + (x9 equals y10) + ", y10 equals x9: " + (y10 equals x9)) - println() - - // Function - val f1 = { x: Int => 2 * x } - val _f1: Function[Int, Int] = read(write(f1)) - println("f1 = ") - println("_f1 = ") - println("f1(2): " + f1(2) + ", _f1(2): " + _f1(2)) - println() - - // List - val xs0 = List(1, 2, 3) - val _xs0: List[Int] = read(write(xs0)) - println("xs0 = " + xs0) - println("_xs0 = " + _xs0) - println("xs0 eq _xs0: " + (xs0 eq _xs0) + ", _xs0 eq xs0: " + (_xs0 eq xs0)) - println("xs0 equals _xs0: " + (xs0 equals _xs0) + ", _xs0 equals xs0: " + (_xs0 equals xs0)) - println() - - val xs1 = Nil - val _xs1: List[Nothing] = read(write(xs1)) - println("xs1 = " + xs1) - println("_xs1 = " + _xs1) - println("xs1 eq _xs1: " + (xs1 eq _xs1) + ", _xs1 eq xs1: " + (_xs1 eq xs1)) - println() - - // Option - val o1 = None - val _o1: Option[Nothing] = read(write(o1)) - println("o1 = " + o1) - println("_o1 = " + _o1) - println("o1 eq _o1: " + (o1 eq _o1) + ", _o1 eq o1: " + (_o1 eq o1)) - println() - - val o2 = Some(1) - val _o2: Option[Int] = read(write(o2)) - println("o2 = " + o2) - println("_o2 = " + _o2) - println("o2 eq _o2: " + (o2 eq _o2) + ", _o2 eq o2: " + (_o2 eq o2)) - println("o2 equals _o2: " + (o2 equals _o2) + ", _o2 equals o2: " + (_o2 equals o2)) - println() -/* - // Responder - val r1 = Responder.constant("xyz") - val _r1: Responder[String] = read(write(r1)) - check(r1, _r1) -*/ - // Symbol - val s1 = 'hello - val _s1: Symbol = read(write(s1)) - println("s1 = " + s1) - println("_s1 = " + _s1) - println("s1 eq _s1: " + (s1 eq _s1) + ", _s1 eq s1: " + (_s1 eq s1)) - println("s1 equals _s1: " + (s1 equals _s1) + ", _s1 equals s1: " + (_s1 equals s1)) - println() - - // Tuple - val t1 = ("BannerLimit", 12345) - val _t1: (String, Int) = read(write(t1)) - println("t1 = " + t1) - println("_t1 = " + _t1) - println("t1 eq _t1: " + (t1 eq _t1) + ", _t1 eq t1: " + (_t1 eq t1)) - println("t1 equals _t1: " + (t1 equals _t1) + ", _t1 equals t1: " + (_t1 equals t1)) - println() - } - catch { - case e: Exception => - println("Error in Test1_scala: " + e) - throw e - } -} - -//############################################################################ -// Test classes in package "scala.collection.immutable" - -object Test2_immutable { - import scala.collection.immutable.{ - BitSet, HashMap, HashSet, ListMap, ListSet, Queue, Range, SortedMap, - SortedSet, Stack, Stream, TreeMap, TreeSet, Vector} - - // in alphabetic order - try { - // BitSet - val bs1 = BitSet.empty + 1 + 2 - val _bs1: BitSet = read(write(bs1)) - check(bs1, _bs1) - - val bs2 = { - val bs = new collection.mutable.BitSet() - bs += 2; bs += 3 - bs.toImmutable - } - val _bs2: BitSet = read(write(bs2)) - check(bs2, _bs2) - - // HashMap - val hm1 = new HashMap[Int, String] + (1 -> "A", 2 -> "B", 3 -> "C") - val _hm1: HashMap[Int, String] = read(write(hm1)) - check(hm1, _hm1) - - // HashSet - val hs1 = new HashSet[Int] + 1 + 2 - val _hs1: HashSet[Int] = read(write(hs1)) - check(hs1, _hs1) - - // List - val xs1 = List(("buffers", 20), ("layers", 2), ("title", 3)) - val _xs1: List[(String, Int)] = read(write(xs1)) - check(xs1, _xs1) - - // ListMap - val lm1 = new ListMap[String, Int] + ("buffers" -> 20, "layers" -> 2, "title" -> 3) - val _lm1: ListMap[String, Int] = read(write(lm1)) - check(lm1, _lm1) - - // ListSet - val ls1 = new ListSet[Int] + 3 + 5 - val _ls1: ListSet[Int] = read(write(ls1)) - check(ls1, _ls1) - - // Queue - val q1 = Queue("a", "b", "c") - val _q1: Queue[String] = read(write(q1)) - check(q1, _q1) - - // Range - val r1 = 0 until 10 - val _r1: Range = read(write(r1)) - check(r1, _r1) - - val r2 = Range.Long(0L, 10L, 1) - val _r2: r2.type = read(write(r2)) - check(r2, _r2) - - // SortedMap - val sm1 = SortedMap.empty[Int, String] + (2 -> "B", 3 -> "C", 1 -> "A") - val _sm1: SortedMap[Int, String] = read(write(sm1)) - check(sm1, _sm1) - - // SortedSet - val ss1 = SortedSet.empty[Int] + 2 + 3 + 1 - val _ss1: SortedSet[Int] = read(write(ss1)) - check(ss1, _ss1) - - // Stack - val s1 = new Stack().push("a", "b", "c") - val _s1: Stack[String] = read(write(s1)) - check(s1, _s1) - - // Stream - val st1 = Stream.range(0, 10) - val _st1: Stream[Int] = read(write(st1)) - check(st1, _st1) - - // TreeMap - val tm1 = new TreeMap[Int, String] + (42 -> "FortyTwo") - val _tm1: TreeMap[Int, String] = read(write(tm1)) - check(tm1, _tm1) - - // TreeSet - val ts1 = new TreeSet[Int]() + 2 + 0 - val _ts1: TreeSet[Int] = read(write(ts1)) - check(ts1, _ts1) - - // Vector - val v1 = Vector('a, 'b, 'c) - val _v1: Vector[Symbol] = read(write(v1)) - check(v1, _v1) - } - catch { - case e: Exception => - println("Error in Test2_immutable: " + e) - throw e - } -} - -//############################################################################ -// Test classes in package "scala.collection.mutable" - -object Test3_mutable { - import scala.reflect.ClassManifest - import scala.collection.mutable.{ - ArrayBuffer, ArrayBuilder, ArraySeq, ArrayStack, BitSet, DoubleLinkedList, - HashMap, HashSet, History, LinkedList, ListBuffer, Publisher, Queue, - Stack, StringBuilder, WrappedArray, TreeSet} - import scala.collection.concurrent.TrieMap - - // in alphabetic order - try { - // ArrayBuffer - val ab1 = new ArrayBuffer[String] - ab1 ++= List("one", "two") - val _ab1: ArrayBuffer[String] = read(write(ab1)) - check(ab1, _ab1) - - // ArrayBuilder - val abu1 = ArrayBuilder.make[Long] - val _abu1: ArrayBuilder[ClassManifest[Long]] = read(write(abu1)) - check(abu1, _abu1) - - val abu2 = ArrayBuilder.make[Float] - val _abu2: ArrayBuilder[ClassManifest[Float]] = read(write(abu2)) - check(abu2, _abu2) - - // ArraySeq - val aq1 = ArraySeq(1, 2, 3) - val _aq1: ArraySeq[Int] = read(write(aq1)) - check(aq1, _aq1) - - // ArrayStack - val as1 = new ArrayStack[Int] - as1 ++= List(20, 2, 3).iterator - val _as1: ArrayStack[Int] = read(write(as1)) - check(as1, _as1) - - // BitSet - val bs1 = new BitSet() - bs1 += 0 - bs1 += 8 - bs1 += 9 - val _bs1: BitSet = read(write(bs1)) - check(bs1, _bs1) -/* - // DoubleLinkedList - val dl1 = new DoubleLinkedList[Int](2, null) - dl1.append(new DoubleLinkedList(3, null)) - val _dl1: DoubleLinkedList[Int] = read(write(dl1)) - check(dl1, _dl1) -*/ - // HashMap - val hm1 = new HashMap[String, Int] - hm1 ++= List(("A", 1), ("B", 2), ("C", 3)).iterator - val _hm1: HashMap[String, Int] = read(write(hm1)) - check(hm1, _hm1) - - // HashSet - val hs1 = new HashSet[String] - hs1 ++= List("layers", "buffers", "title").iterator - val _hs1: HashSet[String] = read(write(hs1)) - check(hs1, _hs1) - - val h1 = new History[String, Int] - val _h1: History[String, Int] = read(write(h1)) - check(h1, _h1) -/* - // LinkedList - val ll1 = new LinkedList[Int](2, null) - ll1.append(new LinkedList(3, null)) - val _ll1: LinkedList[Int] = read(write(ll1)) - check(ll1, _ll1) -*/ - // ListBuffer - val lb1 = new ListBuffer[String] - lb1 ++= List("white", "black") - val _lb1: ListBuffer[String] = read(write(lb1)) - check(lb1, _lb1) - - // Queue - val q1 = new Queue[Int] - q1 ++= List(20, 2, 3).iterator - val _q1: Queue[Int] = read(write(q1)) - check(q1, _q1) - - // Stack - val s1 = new Stack[Int] - s1 pushAll q1 - val _s1: Stack[Int] = read(write(s1)) - check(s1, _s1) - - // StringBuilder - val sb1 = new StringBuilder - sb1 append "abc" - val _sb1: StringBuilder = read(write(sb1)) - check(sb1, _sb1) - - // WrappedArray - val wa1 = WrappedArray.make(Array(1, 2, 3)) - val _wa1: WrappedArray[Int] = read(write(wa1)) - check(wa1, _wa1) - - // TreeSet - val ts1 = TreeSet[Int]() ++= Array(1, 2, 3) - val _ts1: TreeSet[Int] = read(write(ts1)) - check(ts1, _ts1) - - // concurrent.TrieMap - val ct1 = TrieMap[Int, String]() ++= Array(1 -> "one", 2 -> "two", 3 -> "three") - val _ct1: TrieMap[Int, String] = read(write(ct1)) - check(ct1, _ct1) - } - catch { - case e: Exception => - println("Error in Test3_mutable: " + e) - throw e - } -} - - -//############################################################################ -// Test classes in package "scala.xml" - -object Test4_xml { - import scala.xml.{Attribute, Document, Elem, Null, PrefixedAttribute, Text} - - case class Person(name: String, age: Int) - - try { - // Attribute - val a1 = new PrefixedAttribute("xml", "src", Text("hello"), Null) - val _a1: Attribute = read(write(a1)) - check(a1, _a1) - - // Document - val d1 = new Document - d1.docElem = - d1.encoding = Some("UTF-8") - val _d1: Document = read(write(d1)) - check(d1, _d1) - - // Elem - val e1 = title; - val _e1: Elem = read(write(e1)) - check(e1, _e1) - - class AddressBook(a: Person*) { - private val people: List[Person] = a.toList - def toXHTML = - - - - - - { for (p <- people) yield - - - - } -
Last NameFirst Name
{ p.name } { p.age.toString() }
; - } - - val people = new AddressBook( - Person("Tom", 20), - Person("Bob", 22), - Person("James", 19)) - - val e2 = - - - { people.toXHTML } - - ; - val _e2: Elem = read(write(e2)) - check(e2, _e2) - } - catch { - case e: Exception => - println("Error in Test4_xml: " + e) - throw e - } -} - -//############################################################################ -// Test user-defined classes WITHOUT nesting - -class Person(_name: String) extends Serializable { - private var name = _name - override def toString() = name - override def equals(that: Any): Boolean = - that.isInstanceOf[Person] && - (name == that.asInstanceOf[Person].name) -} - -class Employee(_name: String) extends Serializable { - private var name = _name - override def toString() = name -} - -object bob extends Employee("Bob") - -object Test5 { - val x1 = new Person("Tim") - val x2 = bob - - try { - val y1: Person = read(write(x1)) - val y2: Employee = read(write(x2)) - - check(x1, y1) - check(x2, y2) - } - catch { - case e: Exception => - println("Error in Test5: " + e) - } -} - -//############################################################################ -// Test user-defined classes WITH nesting - -object Test6 { - object bill extends Employee("Bill") { - val x = paul - } - object paul extends Person("Paul") { - val x = 4 // bill; => StackOverflowException !!! - } - val x1 = new Person("John") - val x2 = bill - val x3 = paul - - try { - val y1: Person = read(write(x1)) - val y2: Employee = read(write(x2)) - val y3: Person = read(write(x3)) - - check(x1, y1) - check(x2, y2) - check(x3, y3) - } - catch { - case e: Exception => - println("Error in Test6: " + e) - } -} - -//############################################################################ -// Nested objects cannot get readresolve automatically because after deserialization -// they would be null (they are treated as lazy vals) -class Outer extends Serializable { - object Inner extends Serializable -} - -object Test7 { - val x = new Outer - x.Inner // initialize - val y:Outer = read(write(x)) - if (y.Inner == null) - println("Inner object is null") -} - -// Verify that transient lazy vals don't get serialized -class WithTransient extends Serializable { - @transient lazy val a1 = 1 - @transient private lazy val a2 = 2 - @transient object B extends Serializable - @transient private object C extends Serializable - - def test = { - println(a1) - println(a2) - if (B == null || C == null) - println("Transient nested object failed to serialize properly") - } -} - -object Test8 { - val x = new WithTransient - x.test - try { - val y:WithTransient = read(write(x)) - y.test - } - catch { - case e: Exception => - println("Error in Test8: " + e) - } -} - -//############################################################################ -// Test code - -object Test { - def main(args: Array[String]) { - Test1_scala - Test2_immutable - Test3_mutable - Test4_xml - Test5 - Test6 - Test7 - Test8 - Test9_parallel - } -} - -//############################################################################ - - -//############################################################################ -// Test classes in package "scala.collection.parallel" and subpackages -object Test9_parallel { - import scala.collection.parallel._ - - try { - println() - - // UnrolledBuffer - val ub = new collection.mutable.UnrolledBuffer[String] - ub ++= List("one", "two") - val _ub: collection.mutable.UnrolledBuffer[String] = read(write(ub)) - check(ub, _ub) - - // mutable.ParArray - val pa = mutable.ParArray("abc", "def", "etc") - val _pa: mutable.ParArray[String] = read(write(pa)) - check(pa, _pa) - - // mutable.ParHashMap - val mpm = mutable.ParHashMap(1 -> 2, 2 -> 4) - val _mpm: mutable.ParHashMap[Int, Int] = read(write(mpm)) - check(mpm, _mpm) - - // mutable.ParTrieMap - val mpc = mutable.ParTrieMap(1 -> 2, 2 -> 4) - val _mpc: mutable.ParTrieMap[Int, Int] = read(write(mpc)) - check(mpc, _mpc) - - // mutable.ParHashSet - val mps = mutable.ParHashSet(1, 2, 3) - val _mps: mutable.ParHashSet[Int] = read(write(mps)) - check(mps, _mps) - - // immutable.ParRange - val pr1 = immutable.ParRange(0, 4, 1, true) - val _pr1: immutable.ParRange = read(write(pr1)) - check(pr1, _pr1) - - val pr2 = immutable.ParRange(0, 4, 1, false) - val _pr2: immutable.ParRange = read(write(pr2)) - check(pr2, _pr2) - - // immutable.ParHashMap - val ipm = immutable.ParHashMap(5 -> 1, 10 -> 2) - val _ipm: immutable.ParHashMap[Int, Int] = read(write(ipm)) - check(ipm, _ipm) - - // immutable.ParHashSet - val ips = immutable.ParHashSet("one", "two") - val _ips: immutable.ParHashSet[String] = read(write(ips)) - check(ips, _ips) - - } catch { - case e: Exception => - println("Error in Test5_parallel: " + e) - throw e - } -} diff --git a/test/files/neg/t2386.check b/test/files/neg/t2386.check deleted file mode 100644 index f70f12535f..0000000000 --- a/test/files/neg/t2386.check +++ /dev/null @@ -1,4 +0,0 @@ -t2386.scala:2: error: No ClassTag available for Array[_ >: String with Int] - val a = Array(Array(1, 2), Array("a","b")) - ^ -one error found diff --git a/test/files/neg/t2386.scala b/test/files/neg/t2386.scala deleted file mode 100644 index 56146cc5c3..0000000000 --- a/test/files/neg/t2386.scala +++ /dev/null @@ -1,3 +0,0 @@ -object Test { - val a = Array(Array(1, 2), Array("a","b")) -} diff --git a/test/files/neg/t3692-new.check b/test/files/neg/t3692-new.check new file mode 100644 index 0000000000..e013daca74 --- /dev/null +++ b/test/files/neg/t3692-new.check @@ -0,0 +1,4 @@ +t3692-new.scala:15: error: unreachable code + case m2: Map[T, Int] => new java.util.HashMap[T, Integer] + ^ +one error found diff --git a/test/files/neg/t3692-new.flags b/test/files/neg/t3692-new.flags new file mode 100644 index 0000000000..82becdfbfd --- /dev/null +++ b/test/files/neg/t3692-new.flags @@ -0,0 +1 @@ + -Xoldpatmat \ No newline at end of file diff --git a/test/files/neg/t3692-new.scala b/test/files/neg/t3692-new.scala new file mode 100644 index 0000000000..46874b02e3 --- /dev/null +++ b/test/files/neg/t3692-new.scala @@ -0,0 +1,19 @@ +import java.lang.Integer + +object Tester { + def main(args: Array[String]) = { + val map = Map("John" -> 1, "Josh" -> 2) + new Tester().toJavaMap(map) + } +} + +class Tester { + private final def toJavaMap[T, V](map: Map[T, V])(implicit m1: ClassTag[T], m2: ClassTag[V]): java.util.Map[_, _] = { + map match { + case m0: Map[Int, Int] => new java.util.HashMap[Integer, Integer] + case m1: Map[Int, V] => new java.util.HashMap[Integer, V] + case m2: Map[T, Int] => new java.util.HashMap[T, Integer] + case _ => new java.util.HashMap[T, V] + } + } +} \ No newline at end of file diff --git a/test/files/neg/t3692.check b/test/files/neg/t3692.check deleted file mode 100644 index d83abd31e2..0000000000 --- a/test/files/neg/t3692.check +++ /dev/null @@ -1,11 +0,0 @@ -t3692.scala:11: warning: type Manifest in object Predef is deprecated: Use `@scala.reflect.ConcreteTypeTag` instead - private final def toJavaMap[T, V](map: Map[T, V])(implicit m1: Manifest[T], m2: Manifest[V]): java.util.Map[_, _] = { - ^ -t3692.scala:11: warning: type Manifest in object Predef is deprecated: Use `@scala.reflect.ConcreteTypeTag` instead - private final def toJavaMap[T, V](map: Map[T, V])(implicit m1: Manifest[T], m2: Manifest[V]): java.util.Map[_, _] = { - ^ -t3692.scala:15: error: unreachable code - case m2: Map[T, Int] => new java.util.HashMap[T, Integer] - ^ -two warnings found -one error found diff --git a/test/files/neg/t3692.flags b/test/files/neg/t3692.flags deleted file mode 100644 index 82becdfbfd..0000000000 --- a/test/files/neg/t3692.flags +++ /dev/null @@ -1 +0,0 @@ - -Xoldpatmat \ No newline at end of file diff --git a/test/files/neg/t3692.scala b/test/files/neg/t3692.scala deleted file mode 100644 index 151535ae94..0000000000 --- a/test/files/neg/t3692.scala +++ /dev/null @@ -1,19 +0,0 @@ -import java.lang.Integer - -object ManifestTester { - def main(args: Array[String]) = { - val map = Map("John" -> 1, "Josh" -> 2) - new ManifestTester().toJavaMap(map) - } -} - -class ManifestTester { - private final def toJavaMap[T, V](map: Map[T, V])(implicit m1: Manifest[T], m2: Manifest[V]): java.util.Map[_, _] = { - map match { - case m0: Map[Int, Int] => new java.util.HashMap[Integer, Integer] - case m1: Map[Int, V] => new java.util.HashMap[Integer, V] - case m2: Map[T, Int] => new java.util.HashMap[T, Integer] - case _ => new java.util.HashMap[T, V] - } - } -} \ No newline at end of file diff --git a/test/files/neg/t5452-new.check b/test/files/neg/t5452-new.check new file mode 100644 index 0000000000..bbd3734f74 --- /dev/null +++ b/test/files/neg/t5452-new.check @@ -0,0 +1,8 @@ +t5452-new.scala:28: error: overloaded method value apply with alternatives: + ()Queryable[CoffeesTable] + (t: Tree)(implicit evidence$2: ClassTag[CoffeesTable])Nothing + (implicit evidence$1: ClassTag[CoffeesTable])Nothing + cannot be applied to (Queryable[CoffeesTable]) + Queryable[CoffeesTable]( q.treeFilter(null) ) + ^ +one error found diff --git a/test/files/neg/t5452-new.scala b/test/files/neg/t5452-new.scala new file mode 100644 index 0000000000..c829de7d7c --- /dev/null +++ b/test/files/neg/t5452-new.scala @@ -0,0 +1,29 @@ +// /scala/trac/5452/a.scala +// Mon Feb 13 22:52:36 PST 2012 + +// import scala.reflect.mirror._ + +trait Tree + +object Bip { + def ??? = sys.error("") +} +import Bip._ + +case class Queryable[T]() { + def treeFilter( t:Tree ) : Queryable[T] = ??? +} + +object Queryable { + def apply[T:ClassTag] = ??? + def apply[T:ClassTag]( t:Tree ) = ??? +} + +trait CoffeesTable{ + def sales : Int +} + +object Test extends App{ + val q = new Queryable[CoffeesTable] + Queryable[CoffeesTable]( q.treeFilter(null) ) +} diff --git a/test/files/neg/t5452.check b/test/files/neg/t5452.check deleted file mode 100644 index 2f35a45509..0000000000 --- a/test/files/neg/t5452.check +++ /dev/null @@ -1,8 +0,0 @@ -t5452.scala:28: error: overloaded method value apply with alternatives: - ()Queryable[CoffeesTable] - (t: Tree)(implicit evidence$2: Manifest[CoffeesTable])Nothing - (implicit evidence$1: Manifest[CoffeesTable])Nothing - cannot be applied to (Queryable[CoffeesTable]) - Queryable[CoffeesTable]( q.treeFilter(null) ) - ^ -one error found diff --git a/test/files/neg/t5452.scala b/test/files/neg/t5452.scala deleted file mode 100644 index 1032db7a4b..0000000000 --- a/test/files/neg/t5452.scala +++ /dev/null @@ -1,29 +0,0 @@ -// /scala/trac/5452/a.scala -// Mon Feb 13 22:52:36 PST 2012 - -// import scala.reflect.mirror._ - -trait Tree - -object Bip { - def ??? = sys.error("") -} -import Bip._ - -case class Queryable[T]() { - def treeFilter( t:Tree ) : Queryable[T] = ??? -} - -object Queryable { - def apply[T:Manifest] = ??? - def apply[T:Manifest]( t:Tree ) = ??? -} - -trait CoffeesTable{ - def sales : Int -} - -object Test extends App{ - val q = new Queryable[CoffeesTable] - Queryable[CoffeesTable]( q.treeFilter(null) ) -} diff --git a/test/files/pos/contextbounds-implicits-new.scala b/test/files/pos/contextbounds-implicits-new.scala new file mode 100644 index 0000000000..71b3cca36f --- /dev/null +++ b/test/files/pos/contextbounds-implicits-new.scala @@ -0,0 +1,8 @@ +/* Tests implicit parameters in the presence of context bounds. + * See Section 7.4 of the Scala Language Specification. + */ +class C { + + def f[T: TypeTag, S: TypeTag](x: T, y: S)(implicit p: C) { } + +} diff --git a/test/files/pos/contextbounds-implicits.scala b/test/files/pos/contextbounds-implicits.scala deleted file mode 100644 index f9113ee320..0000000000 --- a/test/files/pos/contextbounds-implicits.scala +++ /dev/null @@ -1,8 +0,0 @@ -/* Tests implicit parameters in the presence of context bounds. - * See Section 7.4 of the Scala Language Specification. - */ -class C { - - def f[T: Manifest, S: Manifest](x: T, y: S)(implicit p: C) { } - -} diff --git a/test/files/pos/implicits-new.scala b/test/files/pos/implicits-new.scala new file mode 100644 index 0000000000..7eb7e100c3 --- /dev/null +++ b/test/files/pos/implicits-new.scala @@ -0,0 +1,89 @@ +// #1435 +object t1435 { + implicit def a(s:String):String = error("") + implicit def a(i:Int):String = error("") + implicit def b(i:Int):String = error("") +} + +class C1435 { + val v:String = { + import t1435.a + 2 + } +} + +// #1492 +class C1492 { + + class X + + def foo(x: X => X) {} + + foo ( implicit x => implicitly[X] ) + foo { implicit x => implicitly[X] } +} + +// #1579 +object Test1579 { + class Column + class Query[E](val value: E) + class Invoker(q: Any) { val foo = null } + + implicit def unwrap[C](q: Query[C]) = q.value + implicit def invoker(q: Query[Column]) = new Invoker(q) + + val q = new Query(new Column) + q.foo +} +// #1625 +object Test1625 { + + class Wrapped(x:Any) { + def unwrap() = x + } + + implicit def byName[A](x: =>A) = new Wrapped(x) + + implicit def byVal[A](x: A) = x + + def main(args: Array[String]) = { + +// val res:Wrapped = 7 // works + + val res = 7.unwrap() // doesn't work + + println("=> result: " + res) + } +} + +object Test2188 { + implicit def toJavaList[A: ArrayTag](t:collection.Seq[A]):java.util.List[A] = java.util.Arrays.asList(t.toArray:_*) + + val x: java.util.List[String] = List("foo") +} + +object TestNumericWidening { + val y = 1 + val x: java.lang.Long = y +} + +// #2709 +package foo2709 { + class A + class B + + package object bar { + implicit def a2b(a: A): B = new B + } + + package bar { + object test { + new A: B + } + } +} + +// Problem with specs +object specsProblem { + println(implicitly[ConcreteTypeTag[Class[_]]]) +} diff --git a/test/files/pos/implicits.scala b/test/files/pos/implicits.scala deleted file mode 100644 index 2c01dd0ba8..0000000000 --- a/test/files/pos/implicits.scala +++ /dev/null @@ -1,89 +0,0 @@ -// #1435 -object t1435 { - implicit def a(s:String):String = error("") - implicit def a(i:Int):String = error("") - implicit def b(i:Int):String = error("") -} - -class C1435 { - val v:String = { - import t1435.a - 2 - } -} - -// #1492 -class C1492 { - - class X - - def foo(x: X => X) {} - - foo ( implicit x => implicitly[X] ) - foo { implicit x => implicitly[X] } -} - -// #1579 -object Test1579 { - class Column - class Query[E](val value: E) - class Invoker(q: Any) { val foo = null } - - implicit def unwrap[C](q: Query[C]) = q.value - implicit def invoker(q: Query[Column]) = new Invoker(q) - - val q = new Query(new Column) - q.foo -} -// #1625 -object Test1625 { - - class Wrapped(x:Any) { - def unwrap() = x - } - - implicit def byName[A](x: =>A) = new Wrapped(x) - - implicit def byVal[A](x: A) = x - - def main(args: Array[String]) = { - -// val res:Wrapped = 7 // works - - val res = 7.unwrap() // doesn't work - - println("=> result: " + res) - } -} - -object Test2188 { - implicit def toJavaList[A: ClassManifest](t:collection.Seq[A]):java.util.List[A] = java.util.Arrays.asList(t.toArray:_*) - - val x: java.util.List[String] = List("foo") -} - -object TestNumericWidening { - val y = 1 - val x: java.lang.Long = y -} - -// #2709 -package foo2709 { - class A - class B - - package object bar { - implicit def a2b(a: A): B = new B - } - - package bar { - object test { - new A: B - } - } -} - -// Problem with specs -object specsProblem { - println(implicitly[Manifest[Class[_]]]) -} diff --git a/test/files/pos/manifest1-new.scala b/test/files/pos/manifest1-new.scala new file mode 100644 index 0000000000..645bd42665 --- /dev/null +++ b/test/files/pos/manifest1-new.scala @@ -0,0 +1,21 @@ +import scala.reflect.TypeTag + +object Test { + def foo[T](x: T)(implicit m: TypeTag[T]) { + foo(List(x)) + } + foo(1) + foo("abc") + foo(List(1, 2, 3)) + val x: List[Int] with Ordered[List[Int]] = null + foo(x) + foo[x.type](x) + abstract class C { type T = String; val x: T } + val c = new C { val x = "abc" } + foo(c.x) + abstract class D { type T; implicit val m: TypeTag[T]; val x: T } + val stringm = implicitly[TypeTag[String]] + val d: D = new D { type T = String; val m = stringm; val x = "x" } + import d.m + foo(d.x) +} diff --git a/test/files/pos/manifest1.scala b/test/files/pos/manifest1.scala deleted file mode 100644 index 8901aa7437..0000000000 --- a/test/files/pos/manifest1.scala +++ /dev/null @@ -1,21 +0,0 @@ -import scala.reflect.Manifest - -object Test { - def foo[T](x: T)(implicit m: Manifest[T]) { - foo(List(x)) - } - foo(1) - foo("abc") - foo(List(1, 2, 3)) - val x: List[Int] with Ordered[List[Int]] = null - foo(x) - foo[x.type](x) - abstract class C { type T = String; val x: T } - val c = new C { val x = "abc" } - foo(c.x) - abstract class D { type T; implicit val m: Manifest[T]; val x: T } - val stringm = implicitly[Manifest[String]] - val d: D = new D { type T = String; val m = stringm; val x = "x" } - import d.m - foo(d.x) -} diff --git a/test/files/pos/nothing_manifest_disambig-new.scala b/test/files/pos/nothing_manifest_disambig-new.scala new file mode 100644 index 0000000000..a60b0fdbf8 --- /dev/null +++ b/test/files/pos/nothing_manifest_disambig-new.scala @@ -0,0 +1,10 @@ +object Test { + def mani[T: TypeTag](xs: T) = xs + mani(List()) + + def listElMani[T: TypeTag](xs: List[T]) = xs + listElMani(List()) + + def foo[A, C](m : C)(implicit ev: C <:< Traversable[A], mani: TypeTag[A]): (C, A, TypeTag[A]) = (m, m.head, mani) + foo(List(1,2,3)) +} \ No newline at end of file diff --git a/test/files/pos/nothing_manifest_disambig.scala b/test/files/pos/nothing_manifest_disambig.scala deleted file mode 100644 index 076742033f..0000000000 --- a/test/files/pos/nothing_manifest_disambig.scala +++ /dev/null @@ -1,10 +0,0 @@ -object Test { - def mani[T: Manifest](xs: T) = xs - mani(List()) - - def listElMani[T: Manifest](xs: List[T]) = xs - listElMani(List()) - - def foo[A, C](m : C)(implicit ev: C <:< Traversable[A], mani: Manifest[A]): (C, A, Manifest[A]) = (m, m.head, mani) - foo(List(1,2,3)) -} \ No newline at end of file diff --git a/test/files/pos/spec-constr-new.scala b/test/files/pos/spec-constr-new.scala new file mode 100644 index 0000000000..7cd02b0680 --- /dev/null +++ b/test/files/pos/spec-constr-new.scala @@ -0,0 +1,7 @@ +class SparseArray2[@specialized(Int) T:ArrayTag](val maxSize: Int, initialLength:Int = 3) { + private var data = new Array[T](initialLength); + private var index = new Array[Int](initialLength); + + // comment out to compile correctly + data.length + 3; +} diff --git a/test/files/pos/spec-constr.scala b/test/files/pos/spec-constr.scala deleted file mode 100644 index e908b65a41..0000000000 --- a/test/files/pos/spec-constr.scala +++ /dev/null @@ -1,7 +0,0 @@ -class SparseArray2[@specialized(Int) T:ClassManifest](val maxSize: Int, initialLength:Int = 3) { - private var data = new Array[T](initialLength); - private var index = new Array[Int](initialLength); - - // comment out to compile correctly - data.length + 3; -} diff --git a/test/files/pos/spec-doubledef-new.scala b/test/files/pos/spec-doubledef-new.scala new file mode 100644 index 0000000000..33f1e82b6e --- /dev/null +++ b/test/files/pos/spec-doubledef-new.scala @@ -0,0 +1,28 @@ +object Test { + def fn[@specialized T, @specialized U](t : T => Int, u : U => Int) : T = + null.asInstanceOf[T] +} + +trait A[@specialized(Int) T] { + var value: T + def getWith[@specialized(Int) Z](f: T => Z) = f(value) +} + +class C extends A[Int] { + var value = 10 + override def getWith[@specialized(Int) Z](f: Int => Z) = f(value) +} + +abstract class B[T, @specialized(scala.Int) U : TypeTag, @specialized(scala.Int) V <% Ordered[V]] { + val u: U + val v: V + + def f(t: T, v2: V): Pair[U, V] = { + val m: Array[U] = null + if (m.isEmpty) { + Pair(u, v) + } else { + Pair(u, v2) + } + } +} diff --git a/test/files/pos/spec-doubledef.scala b/test/files/pos/spec-doubledef.scala deleted file mode 100644 index 86b0d857d3..0000000000 --- a/test/files/pos/spec-doubledef.scala +++ /dev/null @@ -1,28 +0,0 @@ -object Test { - def fn[@specialized T, @specialized U](t : T => Int, u : U => Int) : T = - null.asInstanceOf[T] -} - -trait A[@specialized(Int) T] { - var value: T - def getWith[@specialized(Int) Z](f: T => Z) = f(value) -} - -class C extends A[Int] { - var value = 10 - override def getWith[@specialized(Int) Z](f: Int => Z) = f(value) -} - -abstract class B[T, @specialized(scala.Int) U : Manifest, @specialized(scala.Int) V <% Ordered[V]] { - val u: U - val v: V - - def f(t: T, v2: V): Pair[U, V] = { - val m: Array[U] = null - if (m.isEmpty) { - Pair(u, v) - } else { - Pair(u, v2) - } - } -} diff --git a/test/files/pos/spec-fields-new.scala b/test/files/pos/spec-fields-new.scala new file mode 100644 index 0000000000..ddd8bd6624 --- /dev/null +++ b/test/files/pos/spec-fields-new.scala @@ -0,0 +1,10 @@ +abstract class Foo[@specialized T: ArrayTag, U <: Ordered[U]](x: T, size: Int) { + var y: T + var z: T = x + + def initialSize = 16 + val array = new Array[T](initialSize + size) + + def getZ = z + def setZ(zz: T) = z = zz +} diff --git a/test/files/pos/spec-fields.scala b/test/files/pos/spec-fields.scala deleted file mode 100644 index 26a8c4ffbd..0000000000 --- a/test/files/pos/spec-fields.scala +++ /dev/null @@ -1,10 +0,0 @@ -abstract class Foo[@specialized T: ClassManifest, U <: Ordered[U]](x: T, size: Int) { - var y: T - var z: T = x - - def initialSize = 16 - val array = new Array[T](initialSize + size) - - def getZ = z - def setZ(zz: T) = z = zz -} diff --git a/test/files/pos/spec-params-new.scala b/test/files/pos/spec-params-new.scala new file mode 100644 index 0000000000..5fe0c82d40 --- /dev/null +++ b/test/files/pos/spec-params-new.scala @@ -0,0 +1,32 @@ +class Foo[@specialized A: ArrayTag] { + + // conflicting in bounds, expect a normalized member calling m + // and bridge + implementation in specialized subclasses + // and overloads here according to specialization on A + def m1[@specialized B <: A](x: B, y: A) = + goal(x) + + // conflicting, unsolvable, expect a warning + def m2[@specialized B <: String](x: B) = x.concat("a") + + // conflicting in bounds, no mention of other spec members + // expect an overload here plus implementation in + // compatible specialized subclasses + def m3[@specialized B >: A](x: B) = () + + // non-conflicting, expect a normalized overload implementation here + def m4[@specialized T, U <: Ordered[T]](x: T, y: U) = () + + // non-conflicting, expect a normalized overload implementation here + def m5[@specialized B](x: B) = x + + // non-conflicting, expect a normalized implementation here + // and specialized implementations for all expansions in specialized subclasses + def m6[@specialized B](x: B, y: A) = + goal(y) + + def goal(x: A) = { + val xs = new Array[A](1) + xs(0) = x + } +} diff --git a/test/files/pos/spec-params.scala b/test/files/pos/spec-params.scala deleted file mode 100644 index f522512846..0000000000 --- a/test/files/pos/spec-params.scala +++ /dev/null @@ -1,32 +0,0 @@ -class Foo[@specialized A: ClassManifest] { - - // conflicting in bounds, expect a normalized member calling m - // and bridge + implementation in specialized subclasses - // and overloads here according to specialization on A - def m1[@specialized B <: A](x: B, y: A) = - goal(x) - - // conflicting, unsolvable, expect a warning - def m2[@specialized B <: String](x: B) = x.concat("a") - - // conflicting in bounds, no mention of other spec members - // expect an overload here plus implementation in - // compatible specialized subclasses - def m3[@specialized B >: A](x: B) = () - - // non-conflicting, expect a normalized overload implementation here - def m4[@specialized T, U <: Ordered[T]](x: T, y: U) = () - - // non-conflicting, expect a normalized overload implementation here - def m5[@specialized B](x: B) = x - - // non-conflicting, expect a normalized implementation here - // and specialized implementations for all expansions in specialized subclasses - def m6[@specialized B](x: B, y: A) = - goal(y) - - def goal(x: A) = { - val xs = new Array[A](1) - xs(0) = x - } -} diff --git a/test/files/pos/spec-sparsearray-new.scala b/test/files/pos/spec-sparsearray-new.scala new file mode 100644 index 0000000000..0659bf7926 --- /dev/null +++ b/test/files/pos/spec-sparsearray-new.scala @@ -0,0 +1,24 @@ +import scala.collection.mutable.MapLike + +class SparseArray[@specialized(Int) T:ArrayTag] extends collection.mutable.Map[Int,T] with collection.mutable.MapLike[Int,T,SparseArray[T]] { + override def get(x: Int) = { + val ind = findOffset(x) + if(ind < 0) None else Some(error("ignore")) + } + + /** + * Returns the offset into index and data for the requested vector + * index. If the requested index is not found, the return value is + * negative and can be converted into an insertion point with -(rv+1). + */ + private def findOffset(i : Int) : Int = { + error("impl doesn't matter") + } + + override def apply(i : Int) : T = { error("ignore") } + override def update(i : Int, value : T) = error("ignore") + override def empty = new SparseArray[T] + def -=(ind: Int) = error("ignore") + def +=(kv: (Int,T)) = error("ignore") + override final def iterator = error("ignore") +} diff --git a/test/files/pos/spec-sparsearray.scala b/test/files/pos/spec-sparsearray.scala deleted file mode 100644 index ea7710a785..0000000000 --- a/test/files/pos/spec-sparsearray.scala +++ /dev/null @@ -1,24 +0,0 @@ -import scala.collection.mutable.MapLike - -class SparseArray[@specialized(Int) T:ClassManifest] extends collection.mutable.Map[Int,T] with collection.mutable.MapLike[Int,T,SparseArray[T]] { - override def get(x: Int) = { - val ind = findOffset(x) - if(ind < 0) None else Some(error("ignore")) - } - - /** - * Returns the offset into index and data for the requested vector - * index. If the requested index is not found, the return value is - * negative and can be converted into an insertion point with -(rv+1). - */ - private def findOffset(i : Int) : Int = { - error("impl doesn't matter") - } - - override def apply(i : Int) : T = { error("ignore") } - override def update(i : Int, value : T) = error("ignore") - override def empty = new SparseArray[T] - def -=(ind: Int) = error("ignore") - def +=(kv: (Int,T)) = error("ignore") - override final def iterator = error("ignore") -} diff --git a/test/files/pos/t1381-new.scala b/test/files/pos/t1381-new.scala new file mode 100644 index 0000000000..8781ef4fdb --- /dev/null +++ b/test/files/pos/t1381-new.scala @@ -0,0 +1,31 @@ +import scala.reflect.TypeTag + +class D[V <: Variable] + +class ID[V<:IV] extends D[V] { + type E = V#ValueType + def index(value:E) : Int = 0 + // Comment this out to eliminate crash. Or see below + def index(values:E*) : Iterable[Int] = null +} + +abstract class Variable { + type VT <: Variable + def d : D[VT] = null +} + +abstract class PV[T](initval:T) extends Variable { + type VT <: PV[T] + type ValueType = T +} + +trait IV extends Variable { + type ValueType +} + +abstract class EV[T](initval:T) extends PV[T](initval) with IV { + type VT <: EV[T] + override def d : ID[VT] = null + // Comment this out to eliminate crash + protected var indx = d.index(initval) +} diff --git a/test/files/pos/t1381.scala b/test/files/pos/t1381.scala deleted file mode 100644 index 0762891898..0000000000 --- a/test/files/pos/t1381.scala +++ /dev/null @@ -1,31 +0,0 @@ -import scala.reflect.Manifest - -class D[V <: Variable] - -class ID[V<:IV] extends D[V] { - type E = V#ValueType - def index(value:E) : Int = 0 - // Comment this out to eliminate crash. Or see below - def index(values:E*) : Iterable[Int] = null -} - -abstract class Variable { - type VT <: Variable - def d : D[VT] = null -} - -abstract class PV[T](initval:T) extends Variable { - type VT <: PV[T] - type ValueType = T -} - -trait IV extends Variable { - type ValueType -} - -abstract class EV[T](initval:T) extends PV[T](initval) with IV { - type VT <: EV[T] - override def d : ID[VT] = null - // Comment this out to eliminate crash - protected var indx = d.index(initval) -} diff --git a/test/files/pos/t2795-new.scala b/test/files/pos/t2795-new.scala new file mode 100644 index 0000000000..af9c4e8b1c --- /dev/null +++ b/test/files/pos/t2795-new.scala @@ -0,0 +1,17 @@ +package t1 + +trait Element[T] { +} + +trait Config { + type T <: Element[T] + implicit val m: ArrayTag[T] + // XXX Following works fine: + // type T <: Element[_] +} + +trait Transform { self: Config => + def processBlock(block: Array[T]): Unit = { + var X = new Array[T](1) + } +} diff --git a/test/files/pos/t2795.scala b/test/files/pos/t2795.scala deleted file mode 100644 index 935cb1f444..0000000000 --- a/test/files/pos/t2795.scala +++ /dev/null @@ -1,17 +0,0 @@ -package t1 - -trait Element[T] { -} - -trait Config { - type T <: Element[T] - implicit val m: ClassManifest[T] - // XXX Following works fine: - // type T <: Element[_] -} - -trait Transform { self: Config => - def processBlock(block: Array[T]): Unit = { - var X = new Array[T](1) - } -} diff --git a/test/files/pos/t3363-new.scala b/test/files/pos/t3363-new.scala new file mode 100644 index 0000000000..270462745c --- /dev/null +++ b/test/files/pos/t3363-new.scala @@ -0,0 +1,18 @@ +object TestCase { + + //now matter if you put (abstract) class or trait it will fail in all cases + trait MapOps[T] + + //if fs was reduced to List (generic type with one parameter) then the code compiles + //if you inherit from MapOps[T] instead of MapOps[F] then code compiles fine + implicit def map2ops[T,F](fs: Map[T,F]) = new MapOps[F] { + //if you remove this line, then code compiles + lazy val m: TypeTag[T] = error("just something to make it compile") + def is(xs: List[T]) = List(xs) + } + + def main(args: Array[String]) { + println(Map(1 -> "2") is List(2)) + } + + } diff --git a/test/files/pos/t3363.scala b/test/files/pos/t3363.scala deleted file mode 100755 index bae54084ea..0000000000 --- a/test/files/pos/t3363.scala +++ /dev/null @@ -1,18 +0,0 @@ -object TestCase { - - //now matter if you put (abstract) class or trait it will fail in all cases - trait MapOps[T] - - //if fs was reduced to List (generic type with one parameter) then the code compiles - //if you inherit from MapOps[T] instead of MapOps[F] then code compiles fine - implicit def map2ops[T,F](fs: Map[T,F]) = new MapOps[F] { - //if you remove this line, then code compiles - lazy val m: Manifest[T] = error("just something to make it compile") - def is(xs: List[T]) = List(xs) - } - - def main(args: Array[String]) { - println(Map(1 -> "2") is List(2)) - } - - } diff --git a/test/files/pos/t3498-new.scala b/test/files/pos/t3498-new.scala new file mode 100644 index 0000000000..653c50042a --- /dev/null +++ b/test/files/pos/t3498-new.scala @@ -0,0 +1,15 @@ +abstract class A[T, @specialized(scala.Int) U : ArrayTag] { + def f(state: T): Array[U] +} + +abstract class B extends A[ Array[Byte], Int ] { + type T = Array[Byte] + type U = Int + + val N = 0 + + def f(state: T): Array[U] = + { + new Array[U](N + state(N)) + } +} \ No newline at end of file diff --git a/test/files/pos/t3498.scala b/test/files/pos/t3498.scala deleted file mode 100644 index bcc90ca64c..0000000000 --- a/test/files/pos/t3498.scala +++ /dev/null @@ -1,15 +0,0 @@ -abstract class A[T, @specialized(scala.Int) U : Manifest] { - def f(state: T): Array[U] -} - -abstract class B extends A[ Array[Byte], Int ] { - type T = Array[Byte] - type U = Int - - val N = 0 - - def f(state: T): Array[U] = - { - new Array[U](N + state(N)) - } -} \ No newline at end of file diff --git a/test/files/presentation/ide-bug-1000531.check b/test/files/presentation/ide-bug-1000531.check index ae202001eb..2b48a80d38 100644 --- a/test/files/presentation/ide-bug-1000531.check +++ b/test/files/presentation/ide-bug-1000531.check @@ -99,7 +99,7 @@ retrieved 123 members `method synchronized[T0](x$1: T0)T0` `method take(n: Int)Iterator[B]` `method takeWhile(p: B => Boolean)Iterator[B]` -`method toArray[B >: B](implicit evidence$1: ClassManifest[B])Array[B]` +`method toArray[B >: B](implicit evidence$1: ArrayTag[B])Array[B]` `method toBuffer[B >: B]=> scala.collection.mutable.Buffer[B]` `method toIndexedSeq=> scala.collection.immutable.IndexedSeq[B]` `method toIterable=> Iterable[B]` diff --git a/test/files/run/arrayclone-new.scala b/test/files/run/arrayclone-new.scala new file mode 100644 index 0000000000..a4ba021409 --- /dev/null +++ b/test/files/run/arrayclone-new.scala @@ -0,0 +1,106 @@ +object Test extends App{ + BooleanArrayClone; + ByteArrayClone; + ShortArrayClone; + CharArrayClone; + IntArrayClone; + LongArrayClone; + FloatArrayClone; + DoubleArrayClone; + ObjectArrayClone; + PolymorphicArrayClone; +} + +object BooleanArrayClone{ + val it : Array[Boolean] = Array(true, false); + val cloned = it.clone(); + assert(cloned.sameElements(it)); + cloned(0) = false; + assert(it(0) == true) +} + +object ByteArrayClone{ + val it : Array[Byte] = Array(1, 0); + val cloned = it.clone(); + assert(cloned.sameElements(it)); + cloned(0) = 0; + assert(it(0) == 1) +} + +object ShortArrayClone{ + val it : Array[Short] = Array(1, 0); + val cloned = it.clone(); + assert(cloned.sameElements(it)); + cloned(0) = 0; + assert(it(0) == 1) +} + +object CharArrayClone{ + val it : Array[Char] = Array(1, 0); + val cloned = it.clone(); + assert(cloned.sameElements(it)); + cloned(0) = 0; + assert(it(0) == 1) +} + +object IntArrayClone{ + val it : Array[Int] = Array(1, 0); + val cloned = it.clone(); + assert(cloned.sameElements(it)); + cloned(0) = 0; + assert(it(0) == 1) +} + +object LongArrayClone{ + val it : Array[Long] = Array(1, 0); + val cloned = it.clone(); + assert(cloned.sameElements(it)); + cloned(0) = 0; + assert(it(0) == 1) +} + +object FloatArrayClone{ + val it : Array[Float] = Array(1, 0); + val cloned = it.clone(); + assert(cloned.sameElements(it)); + cloned(0) = 0; + assert(it(0) == 1) +} + +object DoubleArrayClone{ + val it : Array[Double] = Array(1, 0); + val cloned = it.clone(); + assert(cloned.sameElements(it)); + cloned(0) = 0; + assert(it(0) == 1) +} + +object ObjectArrayClone{ + val it : Array[String] = Array("1", "0"); + val cloned = it.clone(); + assert(cloned.sameElements(it)); + cloned(0) = "0"; + assert(it(0) == "1") +} + +object PolymorphicArrayClone{ + def testIt[T](it : Array[T], one : T, zero : T) = { + val cloned = it.clone(); + assert(cloned.sameElements(it)); + cloned(0) = zero; + assert(it(0) == one) + } + + testIt(Array("one", "two"), "one", "two"); + + class Mangler[T: ArrayTag](ts : T*){ + // this will always be a BoxedAnyArray even after we've unboxed its contents. + val it = ts.toArray[T]; + } + + val mangled = new Mangler[Int](0, 1); + + val y : Array[Int] = mangled.it; // make sure it's unboxed + + testIt(mangled.it, 0, 1); +} diff --git a/test/files/run/arrayclone.scala b/test/files/run/arrayclone.scala deleted file mode 100644 index c9f7556b47..0000000000 --- a/test/files/run/arrayclone.scala +++ /dev/null @@ -1,106 +0,0 @@ -object Test extends App{ - BooleanArrayClone; - ByteArrayClone; - ShortArrayClone; - CharArrayClone; - IntArrayClone; - LongArrayClone; - FloatArrayClone; - DoubleArrayClone; - ObjectArrayClone; - PolymorphicArrayClone; -} - -object BooleanArrayClone{ - val it : Array[Boolean] = Array(true, false); - val cloned = it.clone(); - assert(cloned.sameElements(it)); - cloned(0) = false; - assert(it(0) == true) -} - -object ByteArrayClone{ - val it : Array[Byte] = Array(1, 0); - val cloned = it.clone(); - assert(cloned.sameElements(it)); - cloned(0) = 0; - assert(it(0) == 1) -} - -object ShortArrayClone{ - val it : Array[Short] = Array(1, 0); - val cloned = it.clone(); - assert(cloned.sameElements(it)); - cloned(0) = 0; - assert(it(0) == 1) -} - -object CharArrayClone{ - val it : Array[Char] = Array(1, 0); - val cloned = it.clone(); - assert(cloned.sameElements(it)); - cloned(0) = 0; - assert(it(0) == 1) -} - -object IntArrayClone{ - val it : Array[Int] = Array(1, 0); - val cloned = it.clone(); - assert(cloned.sameElements(it)); - cloned(0) = 0; - assert(it(0) == 1) -} - -object LongArrayClone{ - val it : Array[Long] = Array(1, 0); - val cloned = it.clone(); - assert(cloned.sameElements(it)); - cloned(0) = 0; - assert(it(0) == 1) -} - -object FloatArrayClone{ - val it : Array[Float] = Array(1, 0); - val cloned = it.clone(); - assert(cloned.sameElements(it)); - cloned(0) = 0; - assert(it(0) == 1) -} - -object DoubleArrayClone{ - val it : Array[Double] = Array(1, 0); - val cloned = it.clone(); - assert(cloned.sameElements(it)); - cloned(0) = 0; - assert(it(0) == 1) -} - -object ObjectArrayClone{ - val it : Array[String] = Array("1", "0"); - val cloned = it.clone(); - assert(cloned.sameElements(it)); - cloned(0) = "0"; - assert(it(0) == "1") -} - -object PolymorphicArrayClone{ - def testIt[T](it : Array[T], one : T, zero : T) = { - val cloned = it.clone(); - assert(cloned.sameElements(it)); - cloned(0) = zero; - assert(it(0) == one) - } - - testIt(Array("one", "two"), "one", "two"); - - class Mangler[T: Manifest](ts : T*){ - // this will always be a BoxedAnyArray even after we've unboxed its contents. - val it = ts.toArray[T]; - } - - val mangled = new Mangler[Int](0, 1); - - val y : Array[Int] = mangled.it; // make sure it's unboxed - - testIt(mangled.it, 0, 1); -} diff --git a/test/files/run/ctries-new/DumbHash.scala b/test/files/run/ctries-new/DumbHash.scala new file mode 100644 index 0000000000..8ef325b67c --- /dev/null +++ b/test/files/run/ctries-new/DumbHash.scala @@ -0,0 +1,14 @@ + + + + + + +class DumbHash(val i: Int) { + override def equals(other: Any) = other match { + case that: DumbHash => that.i == this.i + case _ => false + } + override def hashCode = i % 5 + override def toString = "DH(%s)".format(i) +} diff --git a/test/files/run/ctries-new/Wrap.scala b/test/files/run/ctries-new/Wrap.scala new file mode 100644 index 0000000000..7b645c1612 --- /dev/null +++ b/test/files/run/ctries-new/Wrap.scala @@ -0,0 +1,9 @@ + + + + + + +case class Wrap(i: Int) { + override def hashCode = i * 0x9e3775cd +} diff --git a/test/files/run/ctries-new/concmap.scala b/test/files/run/ctries-new/concmap.scala new file mode 100644 index 0000000000..3ec0256afb --- /dev/null +++ b/test/files/run/ctries-new/concmap.scala @@ -0,0 +1,188 @@ + + + +import collection.concurrent.TrieMap + + +object ConcurrentMapSpec extends Spec { + + val initsz = 500 + val secondsz = 750 + + def test() { + "support put" in { + val ct = new TrieMap[Wrap, Int] + for (i <- 0 until initsz) assert(ct.put(new Wrap(i), i) == None) + for (i <- 0 until initsz) assert(ct.put(new Wrap(i), -i) == Some(i)) + } + + "support put if absent" in { + val ct = new TrieMap[Wrap, Int] + for (i <- 0 until initsz) ct.update(new Wrap(i), i) + for (i <- 0 until initsz) assert(ct.putIfAbsent(new Wrap(i), -i) == Some(i)) + for (i <- 0 until initsz) assert(ct.putIfAbsent(new Wrap(i), -i) == Some(i)) + for (i <- initsz until secondsz) assert(ct.putIfAbsent(new Wrap(i), -i) == None) + for (i <- initsz until secondsz) assert(ct.putIfAbsent(new Wrap(i), i) == Some(-i)) + } + + "support remove if mapped to a specific value" in { + val ct = new TrieMap[Wrap, Int] + for (i <- 0 until initsz) ct.update(new Wrap(i), i) + for (i <- 0 until initsz) assert(ct.remove(new Wrap(i), -i - 1) == false) + for (i <- 0 until initsz) assert(ct.remove(new Wrap(i), i) == true) + for (i <- 0 until initsz) assert(ct.remove(new Wrap(i), i) == false) + } + + "support replace if mapped to a specific value" in { + val ct = new TrieMap[Wrap, Int] + for (i <- 0 until initsz) ct.update(new Wrap(i), i) + for (i <- 0 until initsz) assert(ct.replace(new Wrap(i), -i - 1, -i - 2) == false) + for (i <- 0 until initsz) assert(ct.replace(new Wrap(i), i, -i - 2) == true) + for (i <- 0 until initsz) assert(ct.replace(new Wrap(i), i, -i - 2) == false) + for (i <- initsz until secondsz) assert(ct.replace(new Wrap(i), i, 0) == false) + } + + "support replace if present" in { + val ct = new TrieMap[Wrap, Int] + for (i <- 0 until initsz) ct.update(new Wrap(i), i) + for (i <- 0 until initsz) assert(ct.replace(new Wrap(i), -i) == Some(i)) + for (i <- 0 until initsz) assert(ct.replace(new Wrap(i), i) == Some(-i)) + for (i <- initsz until secondsz) assert(ct.replace(new Wrap(i), i) == None) + } + + def assertEqual(a: Any, b: Any) = { + if (a != b) println(a, b) + assert(a == b) + } + + "support replace if mapped to a specific value, using several threads" in { + val ct = new TrieMap[Wrap, Int] + val sz = 55000 + for (i <- 0 until sz) ct.update(new Wrap(i), i) + + class Updater(index: Int, offs: Int) extends Thread { + override def run() { + var repeats = 0 + for (i <- 0 until sz) { + val j = (offs + i) % sz + var k = Int.MaxValue + do { + if (k != Int.MaxValue) repeats += 1 + k = ct.lookup(new Wrap(j)) + } while (!ct.replace(new Wrap(j), k, -k)) + } + //println("Thread %d repeats: %d".format(index, repeats)) + } + } + + val threads = for (i <- 0 until 16) yield new Updater(i, sz / 32 * i) + threads.foreach(_.start()) + threads.foreach(_.join()) + + for (i <- 0 until sz) assertEqual(ct(new Wrap(i)), i) + + val threads2 = for (i <- 0 until 15) yield new Updater(i, sz / 32 * i) + threads2.foreach(_.start()) + threads2.foreach(_.join()) + + for (i <- 0 until sz) assertEqual(ct(new Wrap(i)), -i) + } + + "support put if absent, several threads" in { + val ct = new TrieMap[Wrap, Int] + val sz = 110000 + + class Updater(offs: Int) extends Thread { + override def run() { + for (i <- 0 until sz) { + val j = (offs + i) % sz + ct.putIfAbsent(new Wrap(j), j) + assert(ct.lookup(new Wrap(j)) == j) + } + } + } + + val threads = for (i <- 0 until 16) yield new Updater(sz / 32 * i) + threads.foreach(_.start()) + threads.foreach(_.join()) + + for (i <- 0 until sz) assert(ct(new Wrap(i)) == i) + } + + "support remove if mapped to a specific value, several threads" in { + val ct = new TrieMap[Wrap, Int] + val sz = 55000 + for (i <- 0 until sz) ct.update(new Wrap(i), i) + + class Remover(offs: Int) extends Thread { + override def run() { + for (i <- 0 until sz) { + val j = (offs + i) % sz + ct.remove(new Wrap(j), j) + assert(ct.get(new Wrap(j)) == None) + } + } + } + + val threads = for (i <- 0 until 16) yield new Remover(sz / 32 * i) + threads.foreach(_.start()) + threads.foreach(_.join()) + + for (i <- 0 until sz) assert(ct.get(new Wrap(i)) == None) + } + + "have all or none of the elements depending on the oddity" in { + val ct = new TrieMap[Wrap, Int] + val sz = 65000 + for (i <- 0 until sz) ct(new Wrap(i)) = i + + class Modifier(index: Int, offs: Int) extends Thread { + override def run() { + for (j <- 0 until sz) { + val i = (offs + j) % sz + var success = false + do { + if (ct.contains(new Wrap(i))) { + success = ct.remove(new Wrap(i)) != None + } else { + success = ct.putIfAbsent(new Wrap(i), i) == None + } + } while (!success) + } + } + } + + def modify(n: Int) = { + val threads = for (i <- 0 until n) yield new Modifier(i, sz / n * i) + threads.foreach(_.start()) + threads.foreach(_.join()) + } + + modify(16) + for (i <- 0 until sz) assertEqual(ct.get(new Wrap(i)), Some(i)) + modify(15) + for (i <- 0 until sz) assertEqual(ct.get(new Wrap(i)), None) + } + + "compute size correctly" in { + val ct = new TrieMap[Wrap, Int] + val sz = 36450 + for (i <- 0 until sz) ct(new Wrap(i)) = i + + assertEqual(ct.size, sz) + assertEqual(ct.size, sz) + } + + "compute size correctly in parallel" in { + val ct = new TrieMap[Wrap, Int] + val sz = 36450 + for (i <- 0 until sz) ct(new Wrap(i)) = i + val pct = ct.par + + assertEqual(pct.size, sz) + assertEqual(pct.size, sz) + } + + } + +} diff --git a/test/files/run/ctries-new/iterator.scala b/test/files/run/ctries-new/iterator.scala new file mode 100644 index 0000000000..b953a40e00 --- /dev/null +++ b/test/files/run/ctries-new/iterator.scala @@ -0,0 +1,289 @@ + + + + +import collection._ +import collection.concurrent.TrieMap + + + +object IteratorSpec extends Spec { + + def test() { + "work for an empty trie" in { + val ct = new TrieMap + val it = ct.iterator + + it.hasNext shouldEqual (false) + evaluating { it.next() }.shouldProduce [NoSuchElementException] + } + + def nonEmptyIteratorCheck(sz: Int) { + val ct = new TrieMap[Wrap, Int] + for (i <- 0 until sz) ct.put(new Wrap(i), i) + + val it = ct.iterator + val tracker = mutable.Map[Wrap, Int]() + for (i <- 0 until sz) { + assert(it.hasNext == true) + tracker += it.next + } + + it.hasNext shouldEqual (false) + evaluating { it.next() }.shouldProduce [NoSuchElementException] + tracker.size shouldEqual (sz) + tracker shouldEqual (ct) + } + + "work for a 1 element trie" in { + nonEmptyIteratorCheck(1) + } + + "work for a 2 element trie" in { + nonEmptyIteratorCheck(2) + } + + "work for a 3 element trie" in { + nonEmptyIteratorCheck(3) + } + + "work for a 5 element trie" in { + nonEmptyIteratorCheck(5) + } + + "work for a 10 element trie" in { + nonEmptyIteratorCheck(10) + } + + "work for a 20 element trie" in { + nonEmptyIteratorCheck(20) + } + + "work for a 50 element trie" in { + nonEmptyIteratorCheck(50) + } + + "work for a 100 element trie" in { + nonEmptyIteratorCheck(100) + } + + "work for a 1k element trie" in { + nonEmptyIteratorCheck(1000) + } + + "work for a 5k element trie" in { + nonEmptyIteratorCheck(5000) + } + + "work for a 75k element trie" in { + nonEmptyIteratorCheck(75000) + } + + "work for a 250k element trie" in { + nonEmptyIteratorCheck(500000) + } + + def nonEmptyCollideCheck(sz: Int) { + val ct = new TrieMap[DumbHash, Int] + for (i <- 0 until sz) ct.put(new DumbHash(i), i) + + val it = ct.iterator + val tracker = mutable.Map[DumbHash, Int]() + for (i <- 0 until sz) { + assert(it.hasNext == true) + tracker += it.next + } + + it.hasNext shouldEqual (false) + evaluating { it.next() }.shouldProduce [NoSuchElementException] + tracker.size shouldEqual (sz) + tracker shouldEqual (ct) + } + + "work for colliding hashcodes, 2 element trie" in { + nonEmptyCollideCheck(2) + } + + "work for colliding hashcodes, 3 element trie" in { + nonEmptyCollideCheck(3) + } + + "work for colliding hashcodes, 5 element trie" in { + nonEmptyCollideCheck(5) + } + + "work for colliding hashcodes, 10 element trie" in { + nonEmptyCollideCheck(10) + } + + "work for colliding hashcodes, 100 element trie" in { + nonEmptyCollideCheck(100) + } + + "work for colliding hashcodes, 500 element trie" in { + nonEmptyCollideCheck(500) + } + + "work for colliding hashcodes, 5k element trie" in { + nonEmptyCollideCheck(5000) + } + + def assertEqual(a: Map[Wrap, Int], b: Map[Wrap, Int]) { + if (a != b) { + println(a.size + " vs " + b.size) + // println(a) + // println(b) + // println(a.toSeq.sortBy((x: (Wrap, Int)) => x._1.i)) + // println(b.toSeq.sortBy((x: (Wrap, Int)) => x._1.i)) + } + assert(a == b) + } + + "be consistent when taken with concurrent modifications" in { + val sz = 25000 + val W = 15 + val S = 5 + val checks = 5 + val ct = new TrieMap[Wrap, Int] + for (i <- 0 until sz) ct.put(new Wrap(i), i) + + class Modifier extends Thread { + override def run() { + for (i <- 0 until sz) ct.putIfAbsent(new Wrap(i), i) match { + case Some(_) => ct.remove(new Wrap(i)) + case None => + } + } + } + + def consistentIteration(ct: TrieMap[Wrap, Int], checks: Int) { + class Iter extends Thread { + override def run() { + val snap = ct.readOnlySnapshot() + val initial = mutable.Map[Wrap, Int]() + for (kv <- snap) initial += kv + + for (i <- 0 until checks) { + assertEqual(snap.iterator.toMap, initial) + } + } + } + + val iter = new Iter + iter.start() + iter.join() + } + + val threads = for (_ <- 0 until W) yield new Modifier + threads.foreach(_.start()) + for (_ <- 0 until S) consistentIteration(ct, checks) + threads.foreach(_.join()) + } + + "be consistent with a concurrent removal with a well defined order" in { + val sz = 150000 + val sgroupsize = 10 + val sgroupnum = 5 + val removerslowdown = 50 + val ct = new TrieMap[Wrap, Int] + for (i <- 0 until sz) ct.put(new Wrap(i), i) + + class Remover extends Thread { + override def run() { + for (i <- 0 until sz) { + assert(ct.remove(new Wrap(i)) == Some(i)) + for (i <- 0 until removerslowdown) ct.get(new Wrap(i)) // slow down, mate + } + //println("done removing") + } + } + + def consistentIteration(it: Iterator[(Wrap, Int)]) = { + class Iter extends Thread { + override def run() { + val elems = it.toBuffer + if (elems.nonEmpty) { + val minelem = elems.minBy((x: (Wrap, Int)) => x._1.i)._1.i + assert(elems.forall(_._1.i >= minelem)) + } + } + } + new Iter + } + + val remover = new Remover + remover.start() + for (_ <- 0 until sgroupnum) { + val iters = for (_ <- 0 until sgroupsize) yield consistentIteration(ct.iterator) + iters.foreach(_.start()) + iters.foreach(_.join()) + } + //println("done with iterators") + remover.join() + } + + "be consistent with a concurrent insertion with a well defined order" in { + val sz = 150000 + val sgroupsize = 10 + val sgroupnum = 10 + val inserterslowdown = 50 + val ct = new TrieMap[Wrap, Int] + + class Inserter extends Thread { + override def run() { + for (i <- 0 until sz) { + assert(ct.put(new Wrap(i), i) == None) + for (i <- 0 until inserterslowdown) ct.get(new Wrap(i)) // slow down, mate + } + //println("done inserting") + } + } + + def consistentIteration(it: Iterator[(Wrap, Int)]) = { + class Iter extends Thread { + override def run() { + val elems = it.toSeq + if (elems.nonEmpty) { + val maxelem = elems.maxBy((x: (Wrap, Int)) => x._1.i)._1.i + assert(elems.forall(_._1.i <= maxelem)) + } + } + } + new Iter + } + + val inserter = new Inserter + inserter.start() + for (_ <- 0 until sgroupnum) { + val iters = for (_ <- 0 until sgroupsize) yield consistentIteration(ct.iterator) + iters.foreach(_.start()) + iters.foreach(_.join()) + } + //println("done with iterators") + inserter.join() + } + + "work on a yet unevaluated snapshot" in { + val sz = 50000 + val ct = new TrieMap[Wrap, Int] + for (i <- 0 until sz) ct.update(new Wrap(i), i) + + val snap = ct.snapshot() + val it = snap.iterator + + while (it.hasNext) it.next() + } + + "be duplicated" in { + val sz = 50 + val ct = collection.parallel.mutable.ParTrieMap((0 until sz) zip (0 until sz): _*) + val it = ct.splitter + for (_ <- 0 until (sz / 2)) it.next() + val dupit = it.dup + + it.toList shouldEqual dupit.toList + } + + } + +} diff --git a/test/files/run/ctries-new/lnode.scala b/test/files/run/ctries-new/lnode.scala new file mode 100644 index 0000000000..92a31088e5 --- /dev/null +++ b/test/files/run/ctries-new/lnode.scala @@ -0,0 +1,61 @@ + + + +import collection.concurrent.TrieMap + + +object LNodeSpec extends Spec { + + val initsz = 1500 + val secondsz = 1750 + + def test() { + "accept elements with the same hash codes" in { + val ct = new TrieMap[DumbHash, Int] + for (i <- 0 until initsz) ct.update(new DumbHash(i), i) + } + + "lookup elements with the same hash codes" in { + val ct = new TrieMap[DumbHash, Int] + for (i <- 0 until initsz) ct.update(new DumbHash(i), i) + for (i <- 0 until initsz) assert(ct.get(new DumbHash(i)) == Some(i)) + for (i <- initsz until secondsz) assert(ct.get(new DumbHash(i)) == None) + } + + "remove elements with the same hash codes" in { + val ct = new TrieMap[DumbHash, Int] + for (i <- 0 until initsz) ct.update(new DumbHash(i), i) + for (i <- 0 until initsz) { + val remelem = ct.remove(new DumbHash(i)) + assert(remelem == Some(i), "removing " + i + " yields " + remelem) + } + for (i <- 0 until initsz) assert(ct.get(new DumbHash(i)) == None) + } + + "put elements with the same hash codes if absent" in { + val ct = new TrieMap[DumbHash, Int] + for (i <- 0 until initsz) ct.put(new DumbHash(i), i) + for (i <- 0 until initsz) assert(ct.lookup(new DumbHash(i)) == i) + for (i <- 0 until initsz) assert(ct.putIfAbsent(new DumbHash(i), i) == Some(i)) + for (i <- initsz until secondsz) assert(ct.putIfAbsent(new DumbHash(i), i) == None) + for (i <- initsz until secondsz) assert(ct.lookup(new DumbHash(i)) == i) + } + + "replace elements with the same hash codes" in { + val ct = new TrieMap[DumbHash, Int] + for (i <- 0 until initsz) assert(ct.put(new DumbHash(i), i) == None) + for (i <- 0 until initsz) assert(ct.lookup(new DumbHash(i)) == i) + for (i <- 0 until initsz) assert(ct.replace(new DumbHash(i), -i) == Some(i)) + for (i <- 0 until initsz) assert(ct.lookup(new DumbHash(i)) == -i) + for (i <- 0 until initsz) assert(ct.replace(new DumbHash(i), -i, i) == true) + } + + "remove elements with the same hash codes if mapped to a specific value" in { + val ct = new TrieMap[DumbHash, Int] + for (i <- 0 until initsz) assert(ct.put(new DumbHash(i), i) == None) + for (i <- 0 until initsz) assert(ct.remove(new DumbHash(i), i) == true) + } + + } + +} diff --git a/test/files/run/ctries-new/main.scala b/test/files/run/ctries-new/main.scala new file mode 100644 index 0000000000..1d40dab6c5 --- /dev/null +++ b/test/files/run/ctries-new/main.scala @@ -0,0 +1,45 @@ + + + + + + + +object Test { + + def main(args: Array[String]) { + ConcurrentMapSpec.test() + IteratorSpec.test() + LNodeSpec.test() + SnapshotSpec.test() + } + +} + + +trait Spec { + + implicit def str2ops(s: String) = new { + def in[U](body: =>U) { + // just execute body + body + } + } + + implicit def any2ops(a: Any) = new { + def shouldEqual(other: Any) = assert(a == other) + } + + def evaluating[U](body: =>U) = new { + def shouldProduce[T <: Throwable: ClassTag]() = { + var produced = false + try body + catch { + case e => if (e.getClass == implicitly[ClassTag[T]].erasure) produced = true + } finally { + assert(produced, "Did not produce exception of type: " + implicitly[ClassTag[T]]) + } + } + } + +} diff --git a/test/files/run/ctries-new/snapshot.scala b/test/files/run/ctries-new/snapshot.scala new file mode 100644 index 0000000000..5fe77d445b --- /dev/null +++ b/test/files/run/ctries-new/snapshot.scala @@ -0,0 +1,267 @@ + + + + +import collection._ +import collection.concurrent.TrieMap + + + +object SnapshotSpec extends Spec { + + def test() { + "support snapshots" in { + val ctn = new TrieMap + ctn.snapshot() + ctn.readOnlySnapshot() + + val ct = new TrieMap[Int, Int] + for (i <- 0 until 100) ct.put(i, i) + ct.snapshot() + ct.readOnlySnapshot() + } + + "empty 2 quiescent snapshots in isolation" in { + val sz = 4000 + + class Worker(trie: TrieMap[Wrap, Int]) extends Thread { + override def run() { + for (i <- 0 until sz) { + assert(trie.remove(new Wrap(i)) == Some(i)) + for (j <- 0 until sz) + if (j <= i) assert(trie.get(new Wrap(j)) == None) + else assert(trie.get(new Wrap(j)) == Some(j)) + } + } + } + + val ct = new TrieMap[Wrap, Int] + for (i <- 0 until sz) ct.put(new Wrap(i), i) + val snapt = ct.snapshot() + + val original = new Worker(ct) + val snapshot = new Worker(snapt) + original.start() + snapshot.start() + original.join() + snapshot.join() + + for (i <- 0 until sz) { + assert(ct.get(new Wrap(i)) == None) + assert(snapt.get(new Wrap(i)) == None) + } + } + + def consistentReadOnly(name: String, readonly: Map[Wrap, Int], sz: Int, N: Int) { + @volatile var e: Exception = null + + // reads possible entries once and stores them + // then reads all these N more times to check if the + // state stayed the same + class Reader(trie: Map[Wrap, Int]) extends Thread { + setName("Reader " + name) + + override def run() = + try check() + catch { + case ex: Exception => e = ex + } + + def check() { + val initial = mutable.Map[Wrap, Int]() + for (i <- 0 until sz) trie.get(new Wrap(i)) match { + case Some(i) => initial.put(new Wrap(i), i) + case None => // do nothing + } + + for (k <- 0 until N) { + for (i <- 0 until sz) { + val tres = trie.get(new Wrap(i)) + val ires = initial.get(new Wrap(i)) + if (tres != ires) println(i, "initially: " + ires, "traversal %d: %s".format(k, tres)) + assert(tres == ires) + } + } + } + } + + val reader = new Reader(readonly) + reader.start() + reader.join() + + if (e ne null) { + e.printStackTrace() + throw e + } + } + + // traverses the trie `rep` times and modifies each entry + class Modifier(trie: TrieMap[Wrap, Int], index: Int, rep: Int, sz: Int) extends Thread { + setName("Modifier %d".format(index)) + + override def run() { + for (k <- 0 until rep) { + for (i <- 0 until sz) trie.putIfAbsent(new Wrap(i), i) match { + case Some(_) => trie.remove(new Wrap(i)) + case None => // do nothing + } + } + } + } + + // removes all the elements from the trie + class Remover(trie: TrieMap[Wrap, Int], index: Int, totremovers: Int, sz: Int) extends Thread { + setName("Remover %d".format(index)) + + override def run() { + for (i <- 0 until sz) trie.remove(new Wrap((i + sz / totremovers * index) % sz)) + } + } + + "have a consistent quiescent read-only snapshot" in { + val sz = 10000 + val N = 100 + val W = 10 + + val ct = new TrieMap[Wrap, Int] + for (i <- 0 until sz) ct(new Wrap(i)) = i + val readonly = ct.readOnlySnapshot() + val threads = for (i <- 0 until W) yield new Modifier(ct, i, N, sz) + + threads.foreach(_.start()) + consistentReadOnly("qm", readonly, sz, N) + threads.foreach(_.join()) + } + + // now, we check non-quiescent snapshots, as these permit situations + // where a thread is caught in the middle of the update when a snapshot is taken + + "have a consistent non-quiescent read-only snapshot, concurrent with removes only" in { + val sz = 1250 + val W = 100 + val S = 5000 + + val ct = new TrieMap[Wrap, Int] + for (i <- 0 until sz) ct(new Wrap(i)) = i + val threads = for (i <- 0 until W) yield new Remover(ct, i, W, sz) + + threads.foreach(_.start()) + for (i <- 0 until S) consistentReadOnly("non-qr", ct.readOnlySnapshot(), sz, 5) + threads.foreach(_.join()) + } + + "have a consistent non-quiescent read-only snapshot, concurrent with modifications" in { + val sz = 1000 + val N = 7000 + val W = 10 + val S = 7000 + + val ct = new TrieMap[Wrap, Int] + for (i <- 0 until sz) ct(new Wrap(i)) = i + val threads = for (i <- 0 until W) yield new Modifier(ct, i, N, sz) + + threads.foreach(_.start()) + for (i <- 0 until S) consistentReadOnly("non-qm", ct.readOnlySnapshot(), sz, 5) + threads.foreach(_.join()) + } + + def consistentNonReadOnly(name: String, trie: TrieMap[Wrap, Int], sz: Int, N: Int) { + @volatile var e: Exception = null + + // reads possible entries once and stores them + // then reads all these N more times to check if the + // state stayed the same + class Worker extends Thread { + setName("Worker " + name) + + override def run() = + try check() + catch { + case ex: Exception => e = ex + } + + def check() { + val initial = mutable.Map[Wrap, Int]() + for (i <- 0 until sz) trie.get(new Wrap(i)) match { + case Some(i) => initial.put(new Wrap(i), i) + case None => // do nothing + } + + for (k <- 0 until N) { + // modify + for ((key, value) <- initial) { + val oldv = if (k % 2 == 0) value else -value + val newv = -oldv + trie.replace(key, oldv, newv) + } + + // check + for (i <- 0 until sz) if (initial.contains(new Wrap(i))) { + val expected = if (k % 2 == 0) -i else i + //println(trie.get(new Wrap(i))) + assert(trie.get(new Wrap(i)) == Some(expected)) + } else { + assert(trie.get(new Wrap(i)) == None) + } + } + } + } + + val worker = new Worker + worker.start() + worker.join() + + if (e ne null) { + e.printStackTrace() + throw e + } + } + + "have a consistent non-quiescent snapshot, concurrent with modifications" in { + val sz = 9000 + val N = 1000 + val W = 10 + val S = 400 + + val ct = new TrieMap[Wrap, Int] + for (i <- 0 until sz) ct(new Wrap(i)) = i + val threads = for (i <- 0 until W) yield new Modifier(ct, i, N, sz) + + threads.foreach(_.start()) + for (i <- 0 until S) { + consistentReadOnly("non-qm", ct.snapshot(), sz, 5) + consistentNonReadOnly("non-qsnap", ct.snapshot(), sz, 5) + } + threads.foreach(_.join()) + } + + "work when many concurrent snapshots are taken, concurrent with modifications" in { + val sz = 12000 + val W = 10 + val S = 10 + val modifytimes = 1200 + val snaptimes = 600 + val ct = new TrieMap[Wrap, Int] + for (i <- 0 until sz) ct(new Wrap(i)) = i + + class Snapshooter extends Thread { + setName("Snapshooter") + override def run() { + for (k <- 0 until snaptimes) { + val snap = ct.snapshot() + for (i <- 0 until sz) snap.remove(new Wrap(i)) + for (i <- 0 until sz) assert(!snap.contains(new Wrap(i))) + } + } + } + + val mods = for (i <- 0 until W) yield new Modifier(ct, i, modifytimes, sz) + val shooters = for (i <- 0 until S) yield new Snapshooter + val threads = mods ++ shooters + threads.foreach(_.start()) + threads.foreach(_.join()) + } + + } + +} diff --git a/test/files/run/ctries/DumbHash.scala b/test/files/run/ctries/DumbHash.scala deleted file mode 100644 index 8ef325b67c..0000000000 --- a/test/files/run/ctries/DumbHash.scala +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - -class DumbHash(val i: Int) { - override def equals(other: Any) = other match { - case that: DumbHash => that.i == this.i - case _ => false - } - override def hashCode = i % 5 - override def toString = "DH(%s)".format(i) -} diff --git a/test/files/run/ctries/Wrap.scala b/test/files/run/ctries/Wrap.scala deleted file mode 100644 index 7b645c1612..0000000000 --- a/test/files/run/ctries/Wrap.scala +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - -case class Wrap(i: Int) { - override def hashCode = i * 0x9e3775cd -} diff --git a/test/files/run/ctries/concmap.scala b/test/files/run/ctries/concmap.scala deleted file mode 100644 index 3ec0256afb..0000000000 --- a/test/files/run/ctries/concmap.scala +++ /dev/null @@ -1,188 +0,0 @@ - - - -import collection.concurrent.TrieMap - - -object ConcurrentMapSpec extends Spec { - - val initsz = 500 - val secondsz = 750 - - def test() { - "support put" in { - val ct = new TrieMap[Wrap, Int] - for (i <- 0 until initsz) assert(ct.put(new Wrap(i), i) == None) - for (i <- 0 until initsz) assert(ct.put(new Wrap(i), -i) == Some(i)) - } - - "support put if absent" in { - val ct = new TrieMap[Wrap, Int] - for (i <- 0 until initsz) ct.update(new Wrap(i), i) - for (i <- 0 until initsz) assert(ct.putIfAbsent(new Wrap(i), -i) == Some(i)) - for (i <- 0 until initsz) assert(ct.putIfAbsent(new Wrap(i), -i) == Some(i)) - for (i <- initsz until secondsz) assert(ct.putIfAbsent(new Wrap(i), -i) == None) - for (i <- initsz until secondsz) assert(ct.putIfAbsent(new Wrap(i), i) == Some(-i)) - } - - "support remove if mapped to a specific value" in { - val ct = new TrieMap[Wrap, Int] - for (i <- 0 until initsz) ct.update(new Wrap(i), i) - for (i <- 0 until initsz) assert(ct.remove(new Wrap(i), -i - 1) == false) - for (i <- 0 until initsz) assert(ct.remove(new Wrap(i), i) == true) - for (i <- 0 until initsz) assert(ct.remove(new Wrap(i), i) == false) - } - - "support replace if mapped to a specific value" in { - val ct = new TrieMap[Wrap, Int] - for (i <- 0 until initsz) ct.update(new Wrap(i), i) - for (i <- 0 until initsz) assert(ct.replace(new Wrap(i), -i - 1, -i - 2) == false) - for (i <- 0 until initsz) assert(ct.replace(new Wrap(i), i, -i - 2) == true) - for (i <- 0 until initsz) assert(ct.replace(new Wrap(i), i, -i - 2) == false) - for (i <- initsz until secondsz) assert(ct.replace(new Wrap(i), i, 0) == false) - } - - "support replace if present" in { - val ct = new TrieMap[Wrap, Int] - for (i <- 0 until initsz) ct.update(new Wrap(i), i) - for (i <- 0 until initsz) assert(ct.replace(new Wrap(i), -i) == Some(i)) - for (i <- 0 until initsz) assert(ct.replace(new Wrap(i), i) == Some(-i)) - for (i <- initsz until secondsz) assert(ct.replace(new Wrap(i), i) == None) - } - - def assertEqual(a: Any, b: Any) = { - if (a != b) println(a, b) - assert(a == b) - } - - "support replace if mapped to a specific value, using several threads" in { - val ct = new TrieMap[Wrap, Int] - val sz = 55000 - for (i <- 0 until sz) ct.update(new Wrap(i), i) - - class Updater(index: Int, offs: Int) extends Thread { - override def run() { - var repeats = 0 - for (i <- 0 until sz) { - val j = (offs + i) % sz - var k = Int.MaxValue - do { - if (k != Int.MaxValue) repeats += 1 - k = ct.lookup(new Wrap(j)) - } while (!ct.replace(new Wrap(j), k, -k)) - } - //println("Thread %d repeats: %d".format(index, repeats)) - } - } - - val threads = for (i <- 0 until 16) yield new Updater(i, sz / 32 * i) - threads.foreach(_.start()) - threads.foreach(_.join()) - - for (i <- 0 until sz) assertEqual(ct(new Wrap(i)), i) - - val threads2 = for (i <- 0 until 15) yield new Updater(i, sz / 32 * i) - threads2.foreach(_.start()) - threads2.foreach(_.join()) - - for (i <- 0 until sz) assertEqual(ct(new Wrap(i)), -i) - } - - "support put if absent, several threads" in { - val ct = new TrieMap[Wrap, Int] - val sz = 110000 - - class Updater(offs: Int) extends Thread { - override def run() { - for (i <- 0 until sz) { - val j = (offs + i) % sz - ct.putIfAbsent(new Wrap(j), j) - assert(ct.lookup(new Wrap(j)) == j) - } - } - } - - val threads = for (i <- 0 until 16) yield new Updater(sz / 32 * i) - threads.foreach(_.start()) - threads.foreach(_.join()) - - for (i <- 0 until sz) assert(ct(new Wrap(i)) == i) - } - - "support remove if mapped to a specific value, several threads" in { - val ct = new TrieMap[Wrap, Int] - val sz = 55000 - for (i <- 0 until sz) ct.update(new Wrap(i), i) - - class Remover(offs: Int) extends Thread { - override def run() { - for (i <- 0 until sz) { - val j = (offs + i) % sz - ct.remove(new Wrap(j), j) - assert(ct.get(new Wrap(j)) == None) - } - } - } - - val threads = for (i <- 0 until 16) yield new Remover(sz / 32 * i) - threads.foreach(_.start()) - threads.foreach(_.join()) - - for (i <- 0 until sz) assert(ct.get(new Wrap(i)) == None) - } - - "have all or none of the elements depending on the oddity" in { - val ct = new TrieMap[Wrap, Int] - val sz = 65000 - for (i <- 0 until sz) ct(new Wrap(i)) = i - - class Modifier(index: Int, offs: Int) extends Thread { - override def run() { - for (j <- 0 until sz) { - val i = (offs + j) % sz - var success = false - do { - if (ct.contains(new Wrap(i))) { - success = ct.remove(new Wrap(i)) != None - } else { - success = ct.putIfAbsent(new Wrap(i), i) == None - } - } while (!success) - } - } - } - - def modify(n: Int) = { - val threads = for (i <- 0 until n) yield new Modifier(i, sz / n * i) - threads.foreach(_.start()) - threads.foreach(_.join()) - } - - modify(16) - for (i <- 0 until sz) assertEqual(ct.get(new Wrap(i)), Some(i)) - modify(15) - for (i <- 0 until sz) assertEqual(ct.get(new Wrap(i)), None) - } - - "compute size correctly" in { - val ct = new TrieMap[Wrap, Int] - val sz = 36450 - for (i <- 0 until sz) ct(new Wrap(i)) = i - - assertEqual(ct.size, sz) - assertEqual(ct.size, sz) - } - - "compute size correctly in parallel" in { - val ct = new TrieMap[Wrap, Int] - val sz = 36450 - for (i <- 0 until sz) ct(new Wrap(i)) = i - val pct = ct.par - - assertEqual(pct.size, sz) - assertEqual(pct.size, sz) - } - - } - -} diff --git a/test/files/run/ctries/iterator.scala b/test/files/run/ctries/iterator.scala deleted file mode 100644 index b953a40e00..0000000000 --- a/test/files/run/ctries/iterator.scala +++ /dev/null @@ -1,289 +0,0 @@ - - - - -import collection._ -import collection.concurrent.TrieMap - - - -object IteratorSpec extends Spec { - - def test() { - "work for an empty trie" in { - val ct = new TrieMap - val it = ct.iterator - - it.hasNext shouldEqual (false) - evaluating { it.next() }.shouldProduce [NoSuchElementException] - } - - def nonEmptyIteratorCheck(sz: Int) { - val ct = new TrieMap[Wrap, Int] - for (i <- 0 until sz) ct.put(new Wrap(i), i) - - val it = ct.iterator - val tracker = mutable.Map[Wrap, Int]() - for (i <- 0 until sz) { - assert(it.hasNext == true) - tracker += it.next - } - - it.hasNext shouldEqual (false) - evaluating { it.next() }.shouldProduce [NoSuchElementException] - tracker.size shouldEqual (sz) - tracker shouldEqual (ct) - } - - "work for a 1 element trie" in { - nonEmptyIteratorCheck(1) - } - - "work for a 2 element trie" in { - nonEmptyIteratorCheck(2) - } - - "work for a 3 element trie" in { - nonEmptyIteratorCheck(3) - } - - "work for a 5 element trie" in { - nonEmptyIteratorCheck(5) - } - - "work for a 10 element trie" in { - nonEmptyIteratorCheck(10) - } - - "work for a 20 element trie" in { - nonEmptyIteratorCheck(20) - } - - "work for a 50 element trie" in { - nonEmptyIteratorCheck(50) - } - - "work for a 100 element trie" in { - nonEmptyIteratorCheck(100) - } - - "work for a 1k element trie" in { - nonEmptyIteratorCheck(1000) - } - - "work for a 5k element trie" in { - nonEmptyIteratorCheck(5000) - } - - "work for a 75k element trie" in { - nonEmptyIteratorCheck(75000) - } - - "work for a 250k element trie" in { - nonEmptyIteratorCheck(500000) - } - - def nonEmptyCollideCheck(sz: Int) { - val ct = new TrieMap[DumbHash, Int] - for (i <- 0 until sz) ct.put(new DumbHash(i), i) - - val it = ct.iterator - val tracker = mutable.Map[DumbHash, Int]() - for (i <- 0 until sz) { - assert(it.hasNext == true) - tracker += it.next - } - - it.hasNext shouldEqual (false) - evaluating { it.next() }.shouldProduce [NoSuchElementException] - tracker.size shouldEqual (sz) - tracker shouldEqual (ct) - } - - "work for colliding hashcodes, 2 element trie" in { - nonEmptyCollideCheck(2) - } - - "work for colliding hashcodes, 3 element trie" in { - nonEmptyCollideCheck(3) - } - - "work for colliding hashcodes, 5 element trie" in { - nonEmptyCollideCheck(5) - } - - "work for colliding hashcodes, 10 element trie" in { - nonEmptyCollideCheck(10) - } - - "work for colliding hashcodes, 100 element trie" in { - nonEmptyCollideCheck(100) - } - - "work for colliding hashcodes, 500 element trie" in { - nonEmptyCollideCheck(500) - } - - "work for colliding hashcodes, 5k element trie" in { - nonEmptyCollideCheck(5000) - } - - def assertEqual(a: Map[Wrap, Int], b: Map[Wrap, Int]) { - if (a != b) { - println(a.size + " vs " + b.size) - // println(a) - // println(b) - // println(a.toSeq.sortBy((x: (Wrap, Int)) => x._1.i)) - // println(b.toSeq.sortBy((x: (Wrap, Int)) => x._1.i)) - } - assert(a == b) - } - - "be consistent when taken with concurrent modifications" in { - val sz = 25000 - val W = 15 - val S = 5 - val checks = 5 - val ct = new TrieMap[Wrap, Int] - for (i <- 0 until sz) ct.put(new Wrap(i), i) - - class Modifier extends Thread { - override def run() { - for (i <- 0 until sz) ct.putIfAbsent(new Wrap(i), i) match { - case Some(_) => ct.remove(new Wrap(i)) - case None => - } - } - } - - def consistentIteration(ct: TrieMap[Wrap, Int], checks: Int) { - class Iter extends Thread { - override def run() { - val snap = ct.readOnlySnapshot() - val initial = mutable.Map[Wrap, Int]() - for (kv <- snap) initial += kv - - for (i <- 0 until checks) { - assertEqual(snap.iterator.toMap, initial) - } - } - } - - val iter = new Iter - iter.start() - iter.join() - } - - val threads = for (_ <- 0 until W) yield new Modifier - threads.foreach(_.start()) - for (_ <- 0 until S) consistentIteration(ct, checks) - threads.foreach(_.join()) - } - - "be consistent with a concurrent removal with a well defined order" in { - val sz = 150000 - val sgroupsize = 10 - val sgroupnum = 5 - val removerslowdown = 50 - val ct = new TrieMap[Wrap, Int] - for (i <- 0 until sz) ct.put(new Wrap(i), i) - - class Remover extends Thread { - override def run() { - for (i <- 0 until sz) { - assert(ct.remove(new Wrap(i)) == Some(i)) - for (i <- 0 until removerslowdown) ct.get(new Wrap(i)) // slow down, mate - } - //println("done removing") - } - } - - def consistentIteration(it: Iterator[(Wrap, Int)]) = { - class Iter extends Thread { - override def run() { - val elems = it.toBuffer - if (elems.nonEmpty) { - val minelem = elems.minBy((x: (Wrap, Int)) => x._1.i)._1.i - assert(elems.forall(_._1.i >= minelem)) - } - } - } - new Iter - } - - val remover = new Remover - remover.start() - for (_ <- 0 until sgroupnum) { - val iters = for (_ <- 0 until sgroupsize) yield consistentIteration(ct.iterator) - iters.foreach(_.start()) - iters.foreach(_.join()) - } - //println("done with iterators") - remover.join() - } - - "be consistent with a concurrent insertion with a well defined order" in { - val sz = 150000 - val sgroupsize = 10 - val sgroupnum = 10 - val inserterslowdown = 50 - val ct = new TrieMap[Wrap, Int] - - class Inserter extends Thread { - override def run() { - for (i <- 0 until sz) { - assert(ct.put(new Wrap(i), i) == None) - for (i <- 0 until inserterslowdown) ct.get(new Wrap(i)) // slow down, mate - } - //println("done inserting") - } - } - - def consistentIteration(it: Iterator[(Wrap, Int)]) = { - class Iter extends Thread { - override def run() { - val elems = it.toSeq - if (elems.nonEmpty) { - val maxelem = elems.maxBy((x: (Wrap, Int)) => x._1.i)._1.i - assert(elems.forall(_._1.i <= maxelem)) - } - } - } - new Iter - } - - val inserter = new Inserter - inserter.start() - for (_ <- 0 until sgroupnum) { - val iters = for (_ <- 0 until sgroupsize) yield consistentIteration(ct.iterator) - iters.foreach(_.start()) - iters.foreach(_.join()) - } - //println("done with iterators") - inserter.join() - } - - "work on a yet unevaluated snapshot" in { - val sz = 50000 - val ct = new TrieMap[Wrap, Int] - for (i <- 0 until sz) ct.update(new Wrap(i), i) - - val snap = ct.snapshot() - val it = snap.iterator - - while (it.hasNext) it.next() - } - - "be duplicated" in { - val sz = 50 - val ct = collection.parallel.mutable.ParTrieMap((0 until sz) zip (0 until sz): _*) - val it = ct.splitter - for (_ <- 0 until (sz / 2)) it.next() - val dupit = it.dup - - it.toList shouldEqual dupit.toList - } - - } - -} diff --git a/test/files/run/ctries/lnode.scala b/test/files/run/ctries/lnode.scala deleted file mode 100644 index 92a31088e5..0000000000 --- a/test/files/run/ctries/lnode.scala +++ /dev/null @@ -1,61 +0,0 @@ - - - -import collection.concurrent.TrieMap - - -object LNodeSpec extends Spec { - - val initsz = 1500 - val secondsz = 1750 - - def test() { - "accept elements with the same hash codes" in { - val ct = new TrieMap[DumbHash, Int] - for (i <- 0 until initsz) ct.update(new DumbHash(i), i) - } - - "lookup elements with the same hash codes" in { - val ct = new TrieMap[DumbHash, Int] - for (i <- 0 until initsz) ct.update(new DumbHash(i), i) - for (i <- 0 until initsz) assert(ct.get(new DumbHash(i)) == Some(i)) - for (i <- initsz until secondsz) assert(ct.get(new DumbHash(i)) == None) - } - - "remove elements with the same hash codes" in { - val ct = new TrieMap[DumbHash, Int] - for (i <- 0 until initsz) ct.update(new DumbHash(i), i) - for (i <- 0 until initsz) { - val remelem = ct.remove(new DumbHash(i)) - assert(remelem == Some(i), "removing " + i + " yields " + remelem) - } - for (i <- 0 until initsz) assert(ct.get(new DumbHash(i)) == None) - } - - "put elements with the same hash codes if absent" in { - val ct = new TrieMap[DumbHash, Int] - for (i <- 0 until initsz) ct.put(new DumbHash(i), i) - for (i <- 0 until initsz) assert(ct.lookup(new DumbHash(i)) == i) - for (i <- 0 until initsz) assert(ct.putIfAbsent(new DumbHash(i), i) == Some(i)) - for (i <- initsz until secondsz) assert(ct.putIfAbsent(new DumbHash(i), i) == None) - for (i <- initsz until secondsz) assert(ct.lookup(new DumbHash(i)) == i) - } - - "replace elements with the same hash codes" in { - val ct = new TrieMap[DumbHash, Int] - for (i <- 0 until initsz) assert(ct.put(new DumbHash(i), i) == None) - for (i <- 0 until initsz) assert(ct.lookup(new DumbHash(i)) == i) - for (i <- 0 until initsz) assert(ct.replace(new DumbHash(i), -i) == Some(i)) - for (i <- 0 until initsz) assert(ct.lookup(new DumbHash(i)) == -i) - for (i <- 0 until initsz) assert(ct.replace(new DumbHash(i), -i, i) == true) - } - - "remove elements with the same hash codes if mapped to a specific value" in { - val ct = new TrieMap[DumbHash, Int] - for (i <- 0 until initsz) assert(ct.put(new DumbHash(i), i) == None) - for (i <- 0 until initsz) assert(ct.remove(new DumbHash(i), i) == true) - } - - } - -} diff --git a/test/files/run/ctries/main.scala b/test/files/run/ctries/main.scala deleted file mode 100644 index 8db7fcef54..0000000000 --- a/test/files/run/ctries/main.scala +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - -object Test { - - def main(args: Array[String]) { - ConcurrentMapSpec.test() - IteratorSpec.test() - LNodeSpec.test() - SnapshotSpec.test() - } - -} - - -trait Spec { - - implicit def str2ops(s: String) = new { - def in[U](body: =>U) { - // just execute body - body - } - } - - implicit def any2ops(a: Any) = new { - def shouldEqual(other: Any) = assert(a == other) - } - - def evaluating[U](body: =>U) = new { - def shouldProduce[T <: Throwable: ClassManifest]() = { - var produced = false - try body - catch { - case e => if (e.getClass == implicitly[ClassManifest[T]].erasure) produced = true - } finally { - assert(produced, "Did not produce exception of type: " + implicitly[ClassManifest[T]]) - } - } - } - -} diff --git a/test/files/run/ctries/snapshot.scala b/test/files/run/ctries/snapshot.scala deleted file mode 100644 index 5fe77d445b..0000000000 --- a/test/files/run/ctries/snapshot.scala +++ /dev/null @@ -1,267 +0,0 @@ - - - - -import collection._ -import collection.concurrent.TrieMap - - - -object SnapshotSpec extends Spec { - - def test() { - "support snapshots" in { - val ctn = new TrieMap - ctn.snapshot() - ctn.readOnlySnapshot() - - val ct = new TrieMap[Int, Int] - for (i <- 0 until 100) ct.put(i, i) - ct.snapshot() - ct.readOnlySnapshot() - } - - "empty 2 quiescent snapshots in isolation" in { - val sz = 4000 - - class Worker(trie: TrieMap[Wrap, Int]) extends Thread { - override def run() { - for (i <- 0 until sz) { - assert(trie.remove(new Wrap(i)) == Some(i)) - for (j <- 0 until sz) - if (j <= i) assert(trie.get(new Wrap(j)) == None) - else assert(trie.get(new Wrap(j)) == Some(j)) - } - } - } - - val ct = new TrieMap[Wrap, Int] - for (i <- 0 until sz) ct.put(new Wrap(i), i) - val snapt = ct.snapshot() - - val original = new Worker(ct) - val snapshot = new Worker(snapt) - original.start() - snapshot.start() - original.join() - snapshot.join() - - for (i <- 0 until sz) { - assert(ct.get(new Wrap(i)) == None) - assert(snapt.get(new Wrap(i)) == None) - } - } - - def consistentReadOnly(name: String, readonly: Map[Wrap, Int], sz: Int, N: Int) { - @volatile var e: Exception = null - - // reads possible entries once and stores them - // then reads all these N more times to check if the - // state stayed the same - class Reader(trie: Map[Wrap, Int]) extends Thread { - setName("Reader " + name) - - override def run() = - try check() - catch { - case ex: Exception => e = ex - } - - def check() { - val initial = mutable.Map[Wrap, Int]() - for (i <- 0 until sz) trie.get(new Wrap(i)) match { - case Some(i) => initial.put(new Wrap(i), i) - case None => // do nothing - } - - for (k <- 0 until N) { - for (i <- 0 until sz) { - val tres = trie.get(new Wrap(i)) - val ires = initial.get(new Wrap(i)) - if (tres != ires) println(i, "initially: " + ires, "traversal %d: %s".format(k, tres)) - assert(tres == ires) - } - } - } - } - - val reader = new Reader(readonly) - reader.start() - reader.join() - - if (e ne null) { - e.printStackTrace() - throw e - } - } - - // traverses the trie `rep` times and modifies each entry - class Modifier(trie: TrieMap[Wrap, Int], index: Int, rep: Int, sz: Int) extends Thread { - setName("Modifier %d".format(index)) - - override def run() { - for (k <- 0 until rep) { - for (i <- 0 until sz) trie.putIfAbsent(new Wrap(i), i) match { - case Some(_) => trie.remove(new Wrap(i)) - case None => // do nothing - } - } - } - } - - // removes all the elements from the trie - class Remover(trie: TrieMap[Wrap, Int], index: Int, totremovers: Int, sz: Int) extends Thread { - setName("Remover %d".format(index)) - - override def run() { - for (i <- 0 until sz) trie.remove(new Wrap((i + sz / totremovers * index) % sz)) - } - } - - "have a consistent quiescent read-only snapshot" in { - val sz = 10000 - val N = 100 - val W = 10 - - val ct = new TrieMap[Wrap, Int] - for (i <- 0 until sz) ct(new Wrap(i)) = i - val readonly = ct.readOnlySnapshot() - val threads = for (i <- 0 until W) yield new Modifier(ct, i, N, sz) - - threads.foreach(_.start()) - consistentReadOnly("qm", readonly, sz, N) - threads.foreach(_.join()) - } - - // now, we check non-quiescent snapshots, as these permit situations - // where a thread is caught in the middle of the update when a snapshot is taken - - "have a consistent non-quiescent read-only snapshot, concurrent with removes only" in { - val sz = 1250 - val W = 100 - val S = 5000 - - val ct = new TrieMap[Wrap, Int] - for (i <- 0 until sz) ct(new Wrap(i)) = i - val threads = for (i <- 0 until W) yield new Remover(ct, i, W, sz) - - threads.foreach(_.start()) - for (i <- 0 until S) consistentReadOnly("non-qr", ct.readOnlySnapshot(), sz, 5) - threads.foreach(_.join()) - } - - "have a consistent non-quiescent read-only snapshot, concurrent with modifications" in { - val sz = 1000 - val N = 7000 - val W = 10 - val S = 7000 - - val ct = new TrieMap[Wrap, Int] - for (i <- 0 until sz) ct(new Wrap(i)) = i - val threads = for (i <- 0 until W) yield new Modifier(ct, i, N, sz) - - threads.foreach(_.start()) - for (i <- 0 until S) consistentReadOnly("non-qm", ct.readOnlySnapshot(), sz, 5) - threads.foreach(_.join()) - } - - def consistentNonReadOnly(name: String, trie: TrieMap[Wrap, Int], sz: Int, N: Int) { - @volatile var e: Exception = null - - // reads possible entries once and stores them - // then reads all these N more times to check if the - // state stayed the same - class Worker extends Thread { - setName("Worker " + name) - - override def run() = - try check() - catch { - case ex: Exception => e = ex - } - - def check() { - val initial = mutable.Map[Wrap, Int]() - for (i <- 0 until sz) trie.get(new Wrap(i)) match { - case Some(i) => initial.put(new Wrap(i), i) - case None => // do nothing - } - - for (k <- 0 until N) { - // modify - for ((key, value) <- initial) { - val oldv = if (k % 2 == 0) value else -value - val newv = -oldv - trie.replace(key, oldv, newv) - } - - // check - for (i <- 0 until sz) if (initial.contains(new Wrap(i))) { - val expected = if (k % 2 == 0) -i else i - //println(trie.get(new Wrap(i))) - assert(trie.get(new Wrap(i)) == Some(expected)) - } else { - assert(trie.get(new Wrap(i)) == None) - } - } - } - } - - val worker = new Worker - worker.start() - worker.join() - - if (e ne null) { - e.printStackTrace() - throw e - } - } - - "have a consistent non-quiescent snapshot, concurrent with modifications" in { - val sz = 9000 - val N = 1000 - val W = 10 - val S = 400 - - val ct = new TrieMap[Wrap, Int] - for (i <- 0 until sz) ct(new Wrap(i)) = i - val threads = for (i <- 0 until W) yield new Modifier(ct, i, N, sz) - - threads.foreach(_.start()) - for (i <- 0 until S) { - consistentReadOnly("non-qm", ct.snapshot(), sz, 5) - consistentNonReadOnly("non-qsnap", ct.snapshot(), sz, 5) - } - threads.foreach(_.join()) - } - - "work when many concurrent snapshots are taken, concurrent with modifications" in { - val sz = 12000 - val W = 10 - val S = 10 - val modifytimes = 1200 - val snaptimes = 600 - val ct = new TrieMap[Wrap, Int] - for (i <- 0 until sz) ct(new Wrap(i)) = i - - class Snapshooter extends Thread { - setName("Snapshooter") - override def run() { - for (k <- 0 until snaptimes) { - val snap = ct.snapshot() - for (i <- 0 until sz) snap.remove(new Wrap(i)) - for (i <- 0 until sz) assert(!snap.contains(new Wrap(i))) - } - } - } - - val mods = for (i <- 0 until W) yield new Modifier(ct, i, modifytimes, sz) - val shooters = for (i <- 0 until S) yield new Snapshooter - val threads = mods ++ shooters - threads.foreach(_.start()) - threads.foreach(_.join()) - } - - } - -} diff --git a/test/files/run/existentials3-new.check b/test/files/run/existentials3-new.check new file mode 100644 index 0000000000..66674fbbd6 --- /dev/null +++ b/test/files/run/existentials3-new.check @@ -0,0 +1,24 @@ +ConcreteTypeTag[Bar.type], t=AbstractTypeRef, s= <: scala.runtime.AbstractFunction0[Bar] with Serializable{case def unapply(x$0: Bar): Boolean} with Singleton +ConcreteTypeTag[Bar], t=AbstractTypeRef, s= <: Test.ToS with Product with Serializable{def copy(): Bar} +ConcreteTypeTag[Test.ToS], t=RefinedType, s=f3 +ConcreteTypeTag[Test.ToS], t=RefinedType, s=f4 +ConcreteTypeTag[Test.ToS], t=RefinedType, s=f5 +ConcreteTypeTag[() => Test.ToS], t=TypeRef, s=class Function0 +ConcreteTypeTag[() => Test.ToS], t=TypeRef, s=class Function0 +ConcreteTypeTag[$anon], t=AbstractTypeRef, s= <: B with Test.ToS +ConcreteTypeTag[$anon], t=AbstractTypeRef, s= <: B with A with Test.ToS +TypeTag[List[Object{type T1}#T1]], t=TypeRef, s=class List +ConcreteTypeTag[List[Seq[Int]]], t=TypeRef, s=class List +ConcreteTypeTag[List[Seq[U forSome { type U <: Int }]]], t=TypeRef, s=class List +ConcreteTypeTag[Bar.type], t=AbstractTypeRef, s= <: scala.runtime.AbstractFunction0[Bar] with Serializable{case def unapply(x$0: Bar): Boolean} with Singleton +ConcreteTypeTag[Bar], t=AbstractTypeRef, s= <: Test.ToS with Product with Serializable{def copy(): Bar} +ConcreteTypeTag[Test.ToS], t=RefinedType, s=g3 +ConcreteTypeTag[Test.ToS], t=RefinedType, s=g4 +ConcreteTypeTag[Test.ToS], t=RefinedType, s=g5 +ConcreteTypeTag[() => Test.ToS], t=TypeRef, s=class Function0 +ConcreteTypeTag[() => Test.ToS], t=TypeRef, s=class Function0 +ConcreteTypeTag[$anon], t=AbstractTypeRef, s= <: B with Test.ToS +ConcreteTypeTag[$anon], t=AbstractTypeRef, s= <: B with A with Test.ToS +TypeTag[List[Object{type T1}#T1]], t=TypeRef, s=class List +ConcreteTypeTag[List[Seq[Int]]], t=TypeRef, s=class List +ConcreteTypeTag[List[Seq[U forSome { type U <: Int }]]], t=TypeRef, s=class List diff --git a/test/files/run/existentials3-new.scala b/test/files/run/existentials3-new.scala new file mode 100644 index 0000000000..32129a04c6 --- /dev/null +++ b/test/files/run/existentials3-new.scala @@ -0,0 +1,78 @@ +object Test { + trait ToS { final override def toString = getClass.getName } + + def f1 = { case class Bar() extends ToS; Bar } + def f2 = { case class Bar() extends ToS; Bar() } + def f3 = { class Bar() extends ToS; object Bar extends ToS; Bar } + def f4 = { class Bar() extends ToS; new Bar() } + def f5 = { object Bar extends ToS; Bar } + def f6 = { () => { object Bar extends ToS ; Bar } } + def f7 = { val f = { () => { object Bar extends ToS ; Bar } } ; f } + + def f8 = { trait A ; trait B extends A ; class C extends B with ToS; new C { } } + def f9 = { trait A ; trait B ; class C extends B with A with ToS; new C { } } + + def f10 = { class A { type T1 } ; List[A#T1]() } + def f11 = { abstract class A extends Seq[Int] ; List[A]() } + def f12 = { abstract class A extends Seq[U forSome { type U <: Int }] ; List[A]() } + + val g1 = { case class Bar() extends ToS; Bar } + val g2 = { case class Bar() extends ToS; Bar() } + val g3 = { class Bar() extends ToS; object Bar extends ToS; Bar } + val g4 = { class Bar() extends ToS; new Bar() } + val g5 = { object Bar extends ToS; Bar } + val g6 = { () => { object Bar extends ToS ; Bar } } + val g7 = { val f = { () => { object Bar extends ToS ; Bar } } ; f } + + val g8 = { trait A ; trait B extends A ; class C extends B with ToS; new C { } } + val g9 = { trait A ; trait B ; class C extends B with A with ToS; new C { } } + + val g10 = { class A { type T1 } ; List[A#T1]() } + val g11 = { abstract class A extends Seq[Int] ; List[A]() } + val g12 = { abstract class A extends Seq[U forSome { type U <: Int }] ; List[A]() } + + def printTag(t: TypeTag[_]) = { + val s = if (t.sym.isFreeType) t.sym.typeSignature.toString else t.sym.toString + println("%s, t=%s, s=%s".format(t, t.tpe.kind, s)) + } + def m[T: ConcreteTypeTag](x: T) = printTag(concreteTypeTag[T]) + def m2[T: TypeTag](x: T) = printTag(typeTag[T]) + + // tags do work for f10/g10 + def main(args: Array[String]): Unit = { + m(f1) + m(f2) + m(f3) + m(f4) + m(f5) + m(f6) + m(f7) + m(f8) + m(f9) + m2(f10) + m(f11) + m(f12) + m(g1) + m(g2) + m(g3) + m(g4) + m(g5) + m(g6) + m(g7) + m(g8) + m(g9) + m2(g10) + m(g11) + m(g12) + } +} + +object Misc { + trait Bippy { def bippy = "I'm Bippy!" } + object o1 { + def f1 = { trait A extends Seq[U forSome { type U <: Bippy }] ; abstract class B extends A ; trait C extends B ; (null: C) } + def f2 = f1.head.bippy + } + def g1 = o1.f1 _ + def g2 = o1.f2 _ +} diff --git a/test/files/run/existentials3.check b/test/files/run/existentials3.check deleted file mode 100644 index e2c9382ab4..0000000000 --- a/test/files/run/existentials3.check +++ /dev/null @@ -1,24 +0,0 @@ -ConcreteTypeTag[Bar.type], t=AbstractTypeRef, s= <: scala.runtime.AbstractFunction0[Bar] with Serializable{case def unapply(x$0: Bar): Boolean} with Singleton -ConcreteTypeTag[Bar], t=AbstractTypeRef, s= <: Test.ToS with Product with Serializable{def copy(): Bar} -ConcreteTypeTag[Test.ToS], t=RefinedType, s=f3 -ConcreteTypeTag[Test.ToS], t=RefinedType, s=f4 -ConcreteTypeTag[Test.ToS], t=RefinedType, s=f5 -ConcreteTypeTag[() => Test.ToS], t=TypeRef, s=class Function0 -ConcreteTypeTag[() => Test.ToS], t=TypeRef, s=class Function0 -ConcreteTypeTag[$anon], t=AbstractTypeRef, s= <: B with Test.ToS -ConcreteTypeTag[$anon], t=AbstractTypeRef, s= <: B with A with Test.ToS -TypeTag[List[Object{type T1}#T1]], t=TypeRef, s=class List -ConcreteTypeTag[List[Seq[Int]]], t=TypeRef, s=class List -ConcreteTypeTag[List[Seq[U forSome { type U <: Int }]]], t=TypeRef, s=class List -ConcreteTypeTag[Bar.type], t=AbstractTypeRef, s= <: scala.runtime.AbstractFunction0[Bar] with Serializable{case def unapply(x$0: Bar): Boolean} with Singleton -ConcreteTypeTag[Bar], t=AbstractTypeRef, s= <: Test.ToS with Product with Serializable{def copy(): Bar} -ConcreteTypeTag[Test.ToS], t=RefinedType, s=g3 -ConcreteTypeTag[Test.ToS], t=RefinedType, s=g4 -ConcreteTypeTag[Test.ToS], t=RefinedType, s=g5 -ConcreteTypeTag[() => Test.ToS], t=TypeRef, s=class Function0 -ConcreteTypeTag[() => Test.ToS], t=TypeRef, s=class Function0 -ConcreteTypeTag[$anon], t=AbstractTypeRef, s= <: B with Test.ToS -ConcreteTypeTag[$anon], t=AbstractTypeRef, s= <: B with A with Test.ToS -TypeTag[List[Object{type T1}#T1]], t=TypeRef, s=class List -ConcreteTypeTag[List[Seq[Int]]], t=TypeRef, s=class List -ConcreteTypeTag[List[Seq[U forSome { type U <: Int }]]], t=TypeRef, s=class List diff --git a/test/files/run/existentials3.scala b/test/files/run/existentials3.scala deleted file mode 100644 index d6d5612687..0000000000 --- a/test/files/run/existentials3.scala +++ /dev/null @@ -1,79 +0,0 @@ -object Test { - trait ToS { final override def toString = getClass.getName } - - def f1 = { case class Bar() extends ToS; Bar } - def f2 = { case class Bar() extends ToS; Bar() } - def f3 = { class Bar() extends ToS; object Bar extends ToS; Bar } - def f4 = { class Bar() extends ToS; new Bar() } - def f5 = { object Bar extends ToS; Bar } - def f6 = { () => { object Bar extends ToS ; Bar } } - def f7 = { val f = { () => { object Bar extends ToS ; Bar } } ; f } - - def f8 = { trait A ; trait B extends A ; class C extends B with ToS; new C { } } - def f9 = { trait A ; trait B ; class C extends B with A with ToS; new C { } } - - def f10 = { class A { type T1 } ; List[A#T1]() } - def f11 = { abstract class A extends Seq[Int] ; List[A]() } - def f12 = { abstract class A extends Seq[U forSome { type U <: Int }] ; List[A]() } - - val g1 = { case class Bar() extends ToS; Bar } - val g2 = { case class Bar() extends ToS; Bar() } - val g3 = { class Bar() extends ToS; object Bar extends ToS; Bar } - val g4 = { class Bar() extends ToS; new Bar() } - val g5 = { object Bar extends ToS; Bar } - val g6 = { () => { object Bar extends ToS ; Bar } } - val g7 = { val f = { () => { object Bar extends ToS ; Bar } } ; f } - - val g8 = { trait A ; trait B extends A ; class C extends B with ToS; new C { } } - val g9 = { trait A ; trait B ; class C extends B with A with ToS; new C { } } - - val g10 = { class A { type T1 } ; List[A#T1]() } - val g11 = { abstract class A extends Seq[Int] ; List[A]() } - val g12 = { abstract class A extends Seq[U forSome { type U <: Int }] ; List[A]() } - - def printTag(t: TypeTag[_]) = { - val s = if (t.sym.isFreeType) t.sym.typeSignature.toString else t.sym.toString - println("%s, t=%s, s=%s".format(t, t.tpe.kind, s)) - } - def m[T: ConcreteTypeTag](x: T) = printTag(concreteTypeTag[T]) - def m2[T: TypeTag](x: T) = printTag(typeTag[T]) - - // manifests don't work for f10/g10 - // oh, they do now :) - def main(args: Array[String]): Unit = { - m(f1) - m(f2) - m(f3) - m(f4) - m(f5) - m(f6) - m(f7) - m(f8) - m(f9) - m2(f10) - m(f11) - m(f12) - m(g1) - m(g2) - m(g3) - m(g4) - m(g5) - m(g6) - m(g7) - m(g8) - m(g9) - m2(g10) - m(g11) - m(g12) - } -} - -object Misc { - trait Bippy { def bippy = "I'm Bippy!" } - object o1 { - def f1 = { trait A extends Seq[U forSome { type U <: Bippy }] ; abstract class B extends A ; trait C extends B ; (null: C) } - def f2 = f1.head.bippy - } - def g1 = o1.f1 _ - def g2 = o1.f2 _ -} diff --git a/test/files/run/getClassTest-new.check b/test/files/run/getClassTest-new.check new file mode 100644 index 0000000000..94e86c3889 --- /dev/null +++ b/test/files/run/getClassTest-new.check @@ -0,0 +1,18 @@ +f1: java.lang.Class +f2: java.lang.Class +f3: java.lang.Class +f4: java.lang.Class +f5: java.lang.Class +f0: T +f1: class java.lang.Object +f2: class java.lang.Object +f3: class AnyRefs$A +f4: class AnyRefs$B +f5: class java.lang.Object +f6: class java.lang.Object +f7: class AnyRefs$A +f8: class AnyRefs$B +f1: java.lang.Class +f2: java.lang.Class +f3: java.lang.Class +f4: java.lang.Class diff --git a/test/files/run/getClassTest-new.scala b/test/files/run/getClassTest-new.scala new file mode 100644 index 0000000000..89778ca2d3 --- /dev/null +++ b/test/files/run/getClassTest-new.scala @@ -0,0 +1,66 @@ +class AnyVals { + def f1 = (5: Any).getClass + def f2 = (5: AnyVal).getClass + def f3 = 5.getClass + def f4 = (5: java.lang.Integer).getClass + def f5 = (5.asInstanceOf[AnyRef]).getClass + + // scalap says: + // + // def f1 : java.lang.Class[?0] forSome {type ?0} = { /* compiled code */ } + // def f2 : java.lang.Class[?0] forSome {type ?0} = { /* compiled code */ } + // def f3 : java.lang.Class[scala.Int] = { /* compiled code */ } + // def f4 : java.lang.Class[?0] forSome {type ?0 <: java.lang.Integer} = { /* compiled code */ } + // def f5 : java.lang.Class[?0] forSome {type ?0 <: scala.AnyRef} = { /* compiled code */ } + // + // java generic signature says: + // + // f1: java.lang.Class + // f2: java.lang.Class + // f3: java.lang.Class + // f4: java.lang.Class + // f5: java.lang.Class +} + +class AnyRefs { + class A + class B extends A + + def f1 = (new B: Any).getClass().newInstance() + def f2 = (new B: AnyRef).getClass().newInstance() + def f3 = (new B: A).getClass().newInstance() + def f4 = (new B: B).getClass().newInstance() + + def f0[T >: B] = (new B: T).getClass().newInstance() + + def f5 = f0[Any] + def f6 = f0[AnyRef] + def f7 = f0[A] + def f8 = f0[B] +} + +class MoreAnyRefs { + trait A + trait B + + // don't leak anon/refinements + def f1 = (new A with B { }).getClass() + def f2 = (new B with A { }).getClass() + def f3 = (new { def bippy() = 5 }).getClass() + def f4 = (new A { def bippy() = 5 }).getClass() +} + +object Test { + def returnTypes[T: ClassTag] = ( + classTag[T].erasure.getMethods.toList + filter (_.getName startsWith "f") + sortBy (_.getName) + map (m => m.getName + ": " + m.getGenericReturnType.toString) + ) + + def main(args: Array[String]): Unit = { + returnTypes[AnyVals] foreach println + returnTypes[AnyRefs] foreach println + returnTypes[MoreAnyRefs] foreach println + } +} diff --git a/test/files/run/getClassTest.check b/test/files/run/getClassTest.check deleted file mode 100644 index 94e86c3889..0000000000 --- a/test/files/run/getClassTest.check +++ /dev/null @@ -1,18 +0,0 @@ -f1: java.lang.Class -f2: java.lang.Class -f3: java.lang.Class -f4: java.lang.Class -f5: java.lang.Class -f0: T -f1: class java.lang.Object -f2: class java.lang.Object -f3: class AnyRefs$A -f4: class AnyRefs$B -f5: class java.lang.Object -f6: class java.lang.Object -f7: class AnyRefs$A -f8: class AnyRefs$B -f1: java.lang.Class -f2: java.lang.Class -f3: java.lang.Class -f4: java.lang.Class diff --git a/test/files/run/getClassTest.scala b/test/files/run/getClassTest.scala deleted file mode 100644 index 2485cd2c71..0000000000 --- a/test/files/run/getClassTest.scala +++ /dev/null @@ -1,66 +0,0 @@ -class AnyVals { - def f1 = (5: Any).getClass - def f2 = (5: AnyVal).getClass - def f3 = 5.getClass - def f4 = (5: java.lang.Integer).getClass - def f5 = (5.asInstanceOf[AnyRef]).getClass - - // scalap says: - // - // def f1 : java.lang.Class[?0] forSome {type ?0} = { /* compiled code */ } - // def f2 : java.lang.Class[?0] forSome {type ?0} = { /* compiled code */ } - // def f3 : java.lang.Class[scala.Int] = { /* compiled code */ } - // def f4 : java.lang.Class[?0] forSome {type ?0 <: java.lang.Integer} = { /* compiled code */ } - // def f5 : java.lang.Class[?0] forSome {type ?0 <: scala.AnyRef} = { /* compiled code */ } - // - // java generic signature says: - // - // f1: java.lang.Class - // f2: java.lang.Class - // f3: java.lang.Class - // f4: java.lang.Class - // f5: java.lang.Class -} - -class AnyRefs { - class A - class B extends A - - def f1 = (new B: Any).getClass().newInstance() - def f2 = (new B: AnyRef).getClass().newInstance() - def f3 = (new B: A).getClass().newInstance() - def f4 = (new B: B).getClass().newInstance() - - def f0[T >: B] = (new B: T).getClass().newInstance() - - def f5 = f0[Any] - def f6 = f0[AnyRef] - def f7 = f0[A] - def f8 = f0[B] -} - -class MoreAnyRefs { - trait A - trait B - - // don't leak anon/refinements - def f1 = (new A with B { }).getClass() - def f2 = (new B with A { }).getClass() - def f3 = (new { def bippy() = 5 }).getClass() - def f4 = (new A { def bippy() = 5 }).getClass() -} - -object Test { - def returnTypes[T: Manifest] = ( - manifest[T].erasure.getMethods.toList - filter (_.getName startsWith "f") - sortBy (_.getName) - map (m => m.getName + ": " + m.getGenericReturnType.toString) - ) - - def main(args: Array[String]): Unit = { - returnTypes[AnyVals] foreach println - returnTypes[AnyRefs] foreach println - returnTypes[MoreAnyRefs] foreach println - } -} diff --git a/test/files/run/manifests-new.scala b/test/files/run/manifests-new.scala new file mode 100644 index 0000000000..4485ce9124 --- /dev/null +++ b/test/files/run/manifests-new.scala @@ -0,0 +1,147 @@ +object Test +{ + object Variances extends Enumeration { + val CO, IN, CONTRA = Value + } + import Variances.{ CO, IN, CONTRA } + + object SubtypeRelationship extends Enumeration { + val NONE, SAME, SUB, SUPER = Value + } + import SubtypeRelationship.{ NONE, SAME, SUB, SUPER } + + class VarianceTester[T, U, CC[_]](expected: Variances.Value)( + implicit ev1: TypeTag[T], ev2: TypeTag[U], ev3: TypeTag[CC[T]], ev4: TypeTag[CC[U]]) { + + def elements = List(ev1.tpe <:< ev2.tpe, ev2.tpe <:< ev1.tpe) + def containers = List(ev3.tpe <:< ev4.tpe, ev4.tpe <:< ev3.tpe) + + def isUnrelated = typeCompare[T, U] == NONE + def isSame = typeCompare[T, U] == SAME + def isSub = typeCompare[T, U] == SUB + def isSuper = typeCompare[T, U] == SUPER + + def showsCovariance = (elements == containers) + def showsContravariance = (elements == containers.reverse) + def showsInvariance = containers forall (_ == isSame) + + def allContainerVariances = List(showsCovariance, showsInvariance, showsContravariance) + + def showsExpectedVariance = + if (isUnrelated) allContainerVariances forall (_ == false) + else if (isSame) allContainerVariances forall (_ == true) + else expected match { + case CO => showsCovariance && !showsContravariance && !showsInvariance + case IN => showsInvariance && !showsCovariance && !showsContravariance + case CONTRA => showsContravariance && !showsCovariance && !showsInvariance + } + } + + def showsCovariance[T, U, CC[_]](implicit ev1: TypeTag[T], ev2: TypeTag[U], ev3: TypeTag[CC[T]], ev4: TypeTag[CC[U]]) = + new VarianceTester[T, U, CC](CO) showsExpectedVariance + + def showsInvariance[T, U, CC[_]](implicit ev1: TypeTag[T], ev2: TypeTag[U], ev3: TypeTag[CC[T]], ev4: TypeTag[CC[U]]) = + new VarianceTester[T, U, CC](IN) showsExpectedVariance + + def showsContravariance[T, U, CC[_]](implicit ev1: TypeTag[T], ev2: TypeTag[U], ev3: TypeTag[CC[T]], ev4: TypeTag[CC[U]]) = + new VarianceTester[T, U, CC](CONTRA) showsExpectedVariance + + def typeCompare[T, U](implicit ev1: TypeTag[T], ev2: TypeTag[U]) = (ev1.tpe <:< ev2.tpe, ev2.tpe <:< ev1.tpe) match { + case (true, true) => SAME + case (true, false) => SUB + case (false, true) => SUPER + case (false, false) => NONE + } + + def assertAnyRef[T: TypeTag] = List( + typeTag[T].tpe <:< typeTag[Any].tpe, + typeTag[T].tpe <:< typeTag[AnyRef].tpe, + !(typeTag[T].tpe <:< typeTag[AnyVal].tpe) + ) foreach (assert(_, "assertAnyRef")) + + def assertAnyVal[T: TypeTag] = List( + typeTag[T].tpe <:< typeTag[Any].tpe, + !(typeTag[T].tpe <:< typeTag[AnyRef].tpe), + typeTag[T].tpe <:< typeTag[AnyVal].tpe + ) foreach (assert(_, "assertAnyVal")) + + def assertSameType[T: TypeTag, U: TypeTag] = assert(typeCompare[T, U] == SAME, "assertSameType") + def assertSuperType[T: TypeTag, U: TypeTag] = assert(typeCompare[T, U] == SUPER, "assertSuperType") + def assertSubType[T: TypeTag, U: TypeTag] = assert(typeCompare[T, U] == SUB, "assertSubType") + def assertNoRelationship[T: TypeTag, U: TypeTag] = assert(typeCompare[T, U] == NONE, "assertNoRelationship") + + def testVariancesVia[T: TypeTag, U: TypeTag] = assert( + typeCompare[T, U] == SUB && + showsCovariance[T, U, List] && + showsInvariance[T, U, Set], + "testVariancesVia" + ) + + def runAllTests = { + assertAnyVal[AnyVal] + assertAnyVal[Unit] + assertAnyVal[Int] + assertAnyVal[Double] + assertAnyVal[Boolean] + assertAnyVal[Char] + + assertAnyRef[AnyRef] + assertAnyRef[java.lang.Object] + assertAnyRef[java.lang.Integer] + assertAnyRef[java.lang.Double] + assertAnyRef[java.lang.Boolean] + assertAnyRef[java.lang.Character] + assertAnyRef[String] + assertAnyRef[scala.List[String]] + assertAnyRef[scala.List[_]] + + // variance doesn't work yet + // testVariancesVia[String, Any] + // testVariancesVia[String, AnyRef] + + assertSubType[List[String], List[Any]] + assertSubType[List[String], List[AnyRef]] + assertNoRelationship[List[String], List[AnyVal]] + + assertSubType[List[Int], List[Any]] + assertSubType[List[Int], List[AnyVal]] + assertNoRelationship[List[Int], List[AnyRef]] + + // Nothing + assertSubType[Nothing, Any] + assertSubType[Nothing, AnyVal] + assertSubType[Nothing, AnyRef] + assertSubType[Nothing, String] + assertSubType[Nothing, List[String]] + assertSubType[Nothing, Null] + assertSameType[Nothing, Nothing] + + // Null + assertSubType[Null, Any] + assertNoRelationship[Null, AnyVal] + assertSubType[Null, AnyRef] + assertSubType[Null, String] + assertSubType[Null, List[String]] + assertSameType[Null, Null] + assertSuperType[Null, Nothing] + + // Any + assertSameType[Any, Any] + assertSuperType[Any, AnyVal] + assertSuperType[Any, AnyRef] + assertSuperType[Any, String] + assertSuperType[Any, List[String]] + assertSuperType[Any, Null] + assertSuperType[Any, Nothing] + + // Misc unrelated types + assertNoRelationship[Unit, AnyRef] + assertNoRelationship[Unit, Int] + assertNoRelationship[Int, Long] + assertNoRelationship[Boolean, String] + assertNoRelationship[List[Boolean], List[String]] + assertNoRelationship[Set[Boolean], Set[String]] + } + + def main(args: Array[String]): Unit = runAllTests +} diff --git a/test/files/run/manifests.scala b/test/files/run/manifests.scala deleted file mode 100644 index 2d64bf18a9..0000000000 --- a/test/files/run/manifests.scala +++ /dev/null @@ -1,149 +0,0 @@ -object Test -{ - object Variances extends Enumeration { - val CO, IN, CONTRA = Value - } - import Variances.{ CO, IN, CONTRA } - - object SubtypeRelationship extends Enumeration { - val NONE, SAME, SUB, SUPER = Value - } - import SubtypeRelationship.{ NONE, SAME, SUB, SUPER } - - class VarianceTester[T, U, CC[_]](expected: Variances.Value)( - implicit ev1: Manifest[T], ev2: Manifest[U], ev3: Manifest[CC[T]], ev4: Manifest[CC[U]]) { - - def elements = List(ev1.tpe <:< ev2.tpe, ev2.tpe <:< ev1.tpe) - def containers = List(ev3.tpe <:< ev4.tpe, ev4.tpe <:< ev3.tpe) - - def isUnrelated = typeCompare[T, U] == NONE - def isSame = typeCompare[T, U] == SAME - def isSub = typeCompare[T, U] == SUB - def isSuper = typeCompare[T, U] == SUPER - - def showsCovariance = (elements == containers) - def showsContravariance = (elements == containers.reverse) - def showsInvariance = containers forall (_ == isSame) - - def allContainerVariances = List(showsCovariance, showsInvariance, showsContravariance) - - def showsExpectedVariance = - if (isUnrelated) allContainerVariances forall (_ == false) - else if (isSame) allContainerVariances forall (_ == true) - else expected match { - case CO => showsCovariance && !showsContravariance && !showsInvariance - case IN => showsInvariance && !showsCovariance && !showsContravariance - case CONTRA => showsContravariance && !showsCovariance && !showsInvariance - } - } - - def showsCovariance[T, U, CC[_]](implicit ev1: Manifest[T], ev2: Manifest[U], ev3: Manifest[CC[T]], ev4: Manifest[CC[U]]) = - new VarianceTester[T, U, CC](CO) showsExpectedVariance - - def showsInvariance[T, U, CC[_]](implicit ev1: Manifest[T], ev2: Manifest[U], ev3: Manifest[CC[T]], ev4: Manifest[CC[U]]) = - new VarianceTester[T, U, CC](IN) showsExpectedVariance - - def showsContravariance[T, U, CC[_]](implicit ev1: Manifest[T], ev2: Manifest[U], ev3: Manifest[CC[T]], ev4: Manifest[CC[U]]) = - new VarianceTester[T, U, CC](CONTRA) showsExpectedVariance - - def typeCompare[T, U](implicit ev1: Manifest[T], ev2: Manifest[U]) = { - (ev1.tpe <:< ev2.tpe, ev2.tpe <:< ev1.tpe) match { - case (true, true) => SAME - case (true, false) => SUB - case (false, true) => SUPER - case (false, false) => NONE - } - } - - def assertAnyRef[T: Manifest] = List( - manifest[T].tpe <:< manifest[Any].tpe, - manifest[T].tpe <:< manifest[AnyRef].tpe, - !(manifest[T].tpe <:< manifest[AnyVal].tpe) - ) foreach (assert(_, "assertAnyRef")) - - def assertAnyVal[T: Manifest] = List( - manifest[T].tpe <:< manifest[Any].tpe, - !(manifest[T].tpe <:< manifest[AnyRef].tpe), - manifest[T].tpe <:< manifest[AnyVal].tpe - ) foreach (assert(_, "assertAnyVal")) - - def assertSameType[T: Manifest, U: Manifest] = assert(typeCompare[T, U] == SAME, "assertSameType") - def assertSuperType[T: Manifest, U: Manifest] = assert(typeCompare[T, U] == SUPER, "assertSuperType") - def assertSubType[T: Manifest, U: Manifest] = assert(typeCompare[T, U] == SUB, "assertSubType") - def assertNoRelationship[T: Manifest, U: Manifest] = assert(typeCompare[T, U] == NONE, "assertNoRelationship") - - def testVariancesVia[T: Manifest, U: Manifest] = assert( - typeCompare[T, U] == SUB && - showsCovariance[T, U, List] && - showsInvariance[T, U, Set], - "testVariancesVia" - ) - - def runAllTests = { - assertAnyVal[AnyVal] - assertAnyVal[Unit] - assertAnyVal[Int] - assertAnyVal[Double] - assertAnyVal[Boolean] - assertAnyVal[Char] - - assertAnyRef[AnyRef] - assertAnyRef[java.lang.Object] - assertAnyRef[java.lang.Integer] - assertAnyRef[java.lang.Double] - assertAnyRef[java.lang.Boolean] - assertAnyRef[java.lang.Character] - assertAnyRef[String] - assertAnyRef[scala.List[String]] - assertAnyRef[scala.List[_]] - - // variance doesn't work yet - // testVariancesVia[String, Any] - // testVariancesVia[String, AnyRef] - - assertSubType[List[String], List[Any]] - assertSubType[List[String], List[AnyRef]] - assertNoRelationship[List[String], List[AnyVal]] - - assertSubType[List[Int], List[Any]] - assertSubType[List[Int], List[AnyVal]] - assertNoRelationship[List[Int], List[AnyRef]] - - // Nothing - assertSubType[Nothing, Any] - assertSubType[Nothing, AnyVal] - assertSubType[Nothing, AnyRef] - assertSubType[Nothing, String] - assertSubType[Nothing, List[String]] - assertSubType[Nothing, Null] - assertSameType[Nothing, Nothing] - - // Null - assertSubType[Null, Any] - assertNoRelationship[Null, AnyVal] - assertSubType[Null, AnyRef] - assertSubType[Null, String] - assertSubType[Null, List[String]] - assertSameType[Null, Null] - assertSuperType[Null, Nothing] - - // Any - assertSameType[Any, Any] - assertSuperType[Any, AnyVal] - assertSuperType[Any, AnyRef] - assertSuperType[Any, String] - assertSuperType[Any, List[String]] - assertSuperType[Any, Null] - assertSuperType[Any, Nothing] - - // Misc unrelated types - assertNoRelationship[Unit, AnyRef] - assertNoRelationship[Unit, Int] - assertNoRelationship[Int, Long] - assertNoRelationship[Boolean, String] - assertNoRelationship[List[Boolean], List[String]] - assertNoRelationship[Set[Boolean], Set[String]] - } - - def main(args: Array[String]): Unit = runAllTests -} diff --git a/test/files/run/patmat_unapp_abstype-new.check b/test/files/run/patmat_unapp_abstype-new.check new file mode 100644 index 0000000000..72239d16cd --- /dev/null +++ b/test/files/run/patmat_unapp_abstype-new.check @@ -0,0 +1,4 @@ +TypeRef +none of the above +Bar +Foo diff --git a/test/files/run/patmat_unapp_abstype-new.flags b/test/files/run/patmat_unapp_abstype-new.flags new file mode 100644 index 0000000000..ba80cad69b --- /dev/null +++ b/test/files/run/patmat_unapp_abstype-new.flags @@ -0,0 +1 @@ +-Xoldpatmat diff --git a/test/files/run/patmat_unapp_abstype-new.scala b/test/files/run/patmat_unapp_abstype-new.scala new file mode 100644 index 0000000000..45496f08a2 --- /dev/null +++ b/test/files/run/patmat_unapp_abstype-new.scala @@ -0,0 +1,83 @@ +// abstract types and extractors, oh my! +trait TypesAPI { + trait Type + + // an alternative fix (implemented in the virtual pattern matcher, is to replace the isInstanceOf by a manifest-based run-time test) + // that's what typeRefMani is for + type TypeRef <: Type //; implicit def typeRefMani: Manifest[TypeRef] + val TypeRef: TypeRefExtractor; trait TypeRefExtractor { + def apply(x: Int): TypeRef + def unapply(x: TypeRef): Option[(Int)] + } + + // just for illustration, should follow the same pattern as TypeRef + case class MethodType(n: Int) extends Type +} + +// user should not be exposed to the implementation +trait TypesUser extends TypesAPI { + def shouldNotCrash(tp: Type): Unit = { + tp match { + case TypeRef(x) => println("TypeRef") + // the above checks tp.isInstanceOf[TypeRef], which is erased to tp.isInstanceOf[Type] + // before calling TypeRef.unapply(tp), which will then crash unless tp.isInstanceOf[TypesImpl#TypeRef] (which is not implied by tp.isInstanceOf[Type]) + // tp.isInstanceOf[TypesImpl#TypeRef] is equivalent to classOf[TypesImpl#TypeRef].isAssignableFrom(tp.getClass) + // this is equivalent to manifest + // it is NOT equivalent to manifest[Type] <:< typeRefMani + case MethodType(x) => println("MethodType") + case _ => println("none of the above") + } + } +} + +trait TypesImpl extends TypesAPI { + object TypeRef extends TypeRefExtractor // this will have a bridged unapply(x: Type) = unapply(x.asInstanceOf[TypeRef]) + case class TypeRef(n: Int) extends Type // this has a bridge from TypesAPI#Type to TypesImpl#TypeRef + // --> the cast in the bridge will fail because the pattern matcher can't type test against the abstract types in TypesUser + //lazy val typeRefMani = manifest[TypeRef] +} + +trait Foos { + trait Bar + type Foo <: Bar + trait FooExtractor { + def unapply(foo: Foo): Option[Int] + } + val Foo: FooExtractor +} + +trait RealFoos extends Foos { + class Foo(val x: Int) extends Bar + object Foo extends FooExtractor { + def unapply(foo: Foo): Option[Int] = Some(foo.x) + } +} + +trait Intermed extends Foos { + def crash(bar: Bar): Unit = + bar match { + case Foo(x) => println("Foo") + case _ => println("Bar") + } +} + +object TestUnappStaticallyKnownSynthetic extends TypesImpl with TypesUser { + def test() = { + shouldNotCrash(TypeRef(10)) // should and does print "TypeRef" + // once #1697/#2337 are fixed, this should generate the correct output + shouldNotCrash(MethodType(10)) // should print "MethodType" but prints "none of the above" -- good one, pattern matcher! + } +} + +object TestUnappDynamicSynth extends RealFoos with Intermed { + case class FooToo(n: Int) extends Bar + def test() = { + crash(FooToo(10)) + crash(new Foo(5)) + } +} + +object Test extends App { + TestUnappStaticallyKnownSynthetic.test() + TestUnappDynamicSynth.test() +} diff --git a/test/files/run/patmat_unapp_abstype.check b/test/files/run/patmat_unapp_abstype.check deleted file mode 100644 index 72239d16cd..0000000000 --- a/test/files/run/patmat_unapp_abstype.check +++ /dev/null @@ -1,4 +0,0 @@ -TypeRef -none of the above -Bar -Foo diff --git a/test/files/run/patmat_unapp_abstype.flags b/test/files/run/patmat_unapp_abstype.flags deleted file mode 100644 index ba80cad69b..0000000000 --- a/test/files/run/patmat_unapp_abstype.flags +++ /dev/null @@ -1 +0,0 @@ --Xoldpatmat diff --git a/test/files/run/patmat_unapp_abstype.scala b/test/files/run/patmat_unapp_abstype.scala deleted file mode 100644 index 45496f08a2..0000000000 --- a/test/files/run/patmat_unapp_abstype.scala +++ /dev/null @@ -1,83 +0,0 @@ -// abstract types and extractors, oh my! -trait TypesAPI { - trait Type - - // an alternative fix (implemented in the virtual pattern matcher, is to replace the isInstanceOf by a manifest-based run-time test) - // that's what typeRefMani is for - type TypeRef <: Type //; implicit def typeRefMani: Manifest[TypeRef] - val TypeRef: TypeRefExtractor; trait TypeRefExtractor { - def apply(x: Int): TypeRef - def unapply(x: TypeRef): Option[(Int)] - } - - // just for illustration, should follow the same pattern as TypeRef - case class MethodType(n: Int) extends Type -} - -// user should not be exposed to the implementation -trait TypesUser extends TypesAPI { - def shouldNotCrash(tp: Type): Unit = { - tp match { - case TypeRef(x) => println("TypeRef") - // the above checks tp.isInstanceOf[TypeRef], which is erased to tp.isInstanceOf[Type] - // before calling TypeRef.unapply(tp), which will then crash unless tp.isInstanceOf[TypesImpl#TypeRef] (which is not implied by tp.isInstanceOf[Type]) - // tp.isInstanceOf[TypesImpl#TypeRef] is equivalent to classOf[TypesImpl#TypeRef].isAssignableFrom(tp.getClass) - // this is equivalent to manifest - // it is NOT equivalent to manifest[Type] <:< typeRefMani - case MethodType(x) => println("MethodType") - case _ => println("none of the above") - } - } -} - -trait TypesImpl extends TypesAPI { - object TypeRef extends TypeRefExtractor // this will have a bridged unapply(x: Type) = unapply(x.asInstanceOf[TypeRef]) - case class TypeRef(n: Int) extends Type // this has a bridge from TypesAPI#Type to TypesImpl#TypeRef - // --> the cast in the bridge will fail because the pattern matcher can't type test against the abstract types in TypesUser - //lazy val typeRefMani = manifest[TypeRef] -} - -trait Foos { - trait Bar - type Foo <: Bar - trait FooExtractor { - def unapply(foo: Foo): Option[Int] - } - val Foo: FooExtractor -} - -trait RealFoos extends Foos { - class Foo(val x: Int) extends Bar - object Foo extends FooExtractor { - def unapply(foo: Foo): Option[Int] = Some(foo.x) - } -} - -trait Intermed extends Foos { - def crash(bar: Bar): Unit = - bar match { - case Foo(x) => println("Foo") - case _ => println("Bar") - } -} - -object TestUnappStaticallyKnownSynthetic extends TypesImpl with TypesUser { - def test() = { - shouldNotCrash(TypeRef(10)) // should and does print "TypeRef" - // once #1697/#2337 are fixed, this should generate the correct output - shouldNotCrash(MethodType(10)) // should print "MethodType" but prints "none of the above" -- good one, pattern matcher! - } -} - -object TestUnappDynamicSynth extends RealFoos with Intermed { - case class FooToo(n: Int) extends Bar - def test() = { - crash(FooToo(10)) - crash(new Foo(5)) - } -} - -object Test extends App { - TestUnappStaticallyKnownSynthetic.test() - TestUnappDynamicSynth.test() -} diff --git a/test/files/run/primitive-sigs-2-new.check b/test/files/run/primitive-sigs-2-new.check new file mode 100644 index 0000000000..b82ddbeaff --- /dev/null +++ b/test/files/run/primitive-sigs-2-new.check @@ -0,0 +1,7 @@ +T +List(A, char, class java.lang.Object) +a +public java.lang.Object Arr.arr4(java.lang.Object[],scala.reflect.ArrayTag) +public float[] Arr.arr3(float[][]) +public scala.collection.immutable.List Arr.arr2(java.lang.Character[]) +public scala.collection.immutable.List Arr.arr1(int[]) diff --git a/test/files/run/primitive-sigs-2-new.scala b/test/files/run/primitive-sigs-2-new.scala new file mode 100644 index 0000000000..7e13014cb2 --- /dev/null +++ b/test/files/run/primitive-sigs-2-new.scala @@ -0,0 +1,31 @@ +import java.{ lang => jl } + +trait T[A] { + def f(): A +} +class C extends T[Char] { + def f(): Char = 'a' +} +class Arr { + def arr1(xs: Array[Int]): List[Int] = xs.toList + def arr2(xs: Array[jl.Character]): List[jl.Character] = xs.toList + def arr3(xss: Array[Array[Float]]): Array[Float] = xss map (_.sum) + def arr4[T: ArrayTag](xss: Array[Array[T]]): Array[T] = xss map (_.head) +} + +object Test { + val c1: Class[_] = classOf[T[_]] + val c2: Class[_] = classOf[C] + val c3: Class[_] = classOf[Arr] + + val c1m = c1.getMethods.toList filter (_.getName == "f") map (_.getGenericReturnType.toString) + val c2m = c2.getMethods.toList filter (_.getName == "f") map (_.getGenericReturnType.toString) + val c3m = c3.getDeclaredMethods.toList map (_.toGenericString) + + def main(args: Array[String]): Unit = { + println(c2.getGenericInterfaces.map(_.toString).sorted mkString " ") + println(c1m ++ c2m sorted) + println(new C f) + c3m.sorted foreach println + } +} diff --git a/test/files/run/primitive-sigs-2.check b/test/files/run/primitive-sigs-2.check deleted file mode 100644 index 1b6e24ed20..0000000000 --- a/test/files/run/primitive-sigs-2.check +++ /dev/null @@ -1,7 +0,0 @@ -T -List(A, char, class java.lang.Object) -a -public java.lang.Object Arr.arr4(java.lang.Object[],scala.reflect.api.TypeTags.scala.reflect.api.TypeTags$ConcreteTypeTag) -public float[] Arr.arr3(float[][]) -public scala.collection.immutable.List Arr.arr2(java.lang.Character[]) -public scala.collection.immutable.List Arr.arr1(int[]) diff --git a/test/files/run/primitive-sigs-2.scala b/test/files/run/primitive-sigs-2.scala deleted file mode 100644 index b7152f7e3d..0000000000 --- a/test/files/run/primitive-sigs-2.scala +++ /dev/null @@ -1,39 +0,0 @@ -import java.{ lang => jl } - -trait T[A] { - def f(): A -} -class C extends T[Char] { - def f(): Char = 'a' -} -class Arr { - def arr1(xs: Array[Int]): List[Int] = xs.toList - def arr2(xs: Array[jl.Character]): List[jl.Character] = xs.toList - def arr3(xss: Array[Array[Float]]): Array[Float] = xss map (_.sum) - // This gets a signature like - // public java.lang.Object Arr.arr4(java.lang.Object[],scala.reflect.Manifest) - // - // instead of the more appealing version from the past - // public T[] Arr.arr4(T[][],scala.reflect.Manifest) - // - // because java inflict's its reference-only generic-arrays on us. - // - def arr4[T: Manifest](xss: Array[Array[T]]): Array[T] = xss map (_.head) -} - -object Test { - val c1: Class[_] = classOf[T[_]] - val c2: Class[_] = classOf[C] - val c3: Class[_] = classOf[Arr] - - val c1m = c1.getMethods.toList filter (_.getName == "f") map (_.getGenericReturnType.toString) - val c2m = c2.getMethods.toList filter (_.getName == "f") map (_.getGenericReturnType.toString) - val c3m = c3.getDeclaredMethods.toList map (_.toGenericString) - - def main(args: Array[String]): Unit = { - println(c2.getGenericInterfaces.map(_.toString).sorted mkString " ") - println(c1m ++ c2m sorted) - println(new C f) - c3m.sorted foreach println - } -} diff --git a/test/files/run/reflection-implClass-new.scala b/test/files/run/reflection-implClass-new.scala new file mode 100644 index 0000000000..27374f2106 --- /dev/null +++ b/test/files/run/reflection-implClass-new.scala @@ -0,0 +1,38 @@ +/** + * Tries to load a symbol for the `Foo$class` using Scala reflection. + * Since trait implementation classes do not get pickling information + * symbol for them should be created using fallback mechanism + * that exposes Java reflection information dressed up in + * a Scala symbol. + */ +object Test extends App with Outer { + import scala.reflect.mirror + + assert(mirror.classToSymbol(classTag[Foo].erasure).typeSignature.declaration(mirror.newTermName("bar")).typeSignature == + mirror.classToSymbol(classTag[Bar].erasure).typeSignature.declaration(mirror.newTermName("foo")).typeSignature) + + val s1 = implClass(classTag[Foo].erasure) + assert(s1 != mirror.NoSymbol) + assert(s1.typeSignature != mirror.NoType) + assert(s1.companionSymbol.typeSignature != mirror.NoType) + assert(s1.companionSymbol.typeSignature.declaration(mirror.newTermName("bar")) != mirror.NoSymbol) + val s2 = implClass(classTag[Bar].erasure) + assert(s2 != mirror.NoSymbol) + assert(s2.typeSignature != mirror.NoType) + assert(s2.companionSymbol.typeSignature != mirror.NoType) + assert(s2.companionSymbol.typeSignature.declaration(mirror.newTermName("foo")) != mirror.NoSymbol) + def implClass(clazz: Class[_]) = { + val implClass = Class.forName(clazz.getName + "$class") + mirror.classToSymbol(implClass) + } +} + +trait Foo { + def bar = 1 +} + +trait Outer { + trait Bar { + def foo = 1 + } +} diff --git a/test/files/run/reflection-implClass.scala b/test/files/run/reflection-implClass.scala deleted file mode 100644 index 7718b52f33..0000000000 --- a/test/files/run/reflection-implClass.scala +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Tries to load a symbol for the `Foo$class` using Scala reflection. - * Since trait implementation classes do not get pickling information - * symbol for them should be created using fallback mechanism - * that exposes Java reflection information dressed up in - * a Scala symbol. - */ -object Test extends App with Outer { - import scala.reflect.mirror - - assert(mirror.classToSymbol(manifest[Foo].erasure).typeSignature.declaration(mirror.newTermName("bar")).typeSignature == - mirror.classToSymbol(manifest[Bar].erasure).typeSignature.declaration(mirror.newTermName("foo")).typeSignature) - - val s1 = implClass(manifest[Foo].erasure) - assert(s1 != mirror.NoSymbol) - assert(s1.typeSignature != mirror.NoType) - assert(s1.companionSymbol.typeSignature != mirror.NoType) - assert(s1.companionSymbol.typeSignature.declaration(mirror.newTermName("bar")) != mirror.NoSymbol) - val s2 = implClass(manifest[Bar].erasure) - assert(s2 != mirror.NoSymbol) - assert(s2.typeSignature != mirror.NoType) - assert(s2.companionSymbol.typeSignature != mirror.NoType) - assert(s2.companionSymbol.typeSignature.declaration(mirror.newTermName("foo")) != mirror.NoSymbol) - def implClass(clazz: Class[_]) = { - val implClass = Class.forName(clazz.getName + "$class") - mirror.classToSymbol(implClass) - } -} - -trait Foo { - def bar = 1 -} - -trait Outer { - trait Bar { - def foo = 1 - } -} diff --git a/test/files/run/reify_implicits-new.check b/test/files/run/reify_implicits-new.check new file mode 100644 index 0000000000..e3aeb20f6b --- /dev/null +++ b/test/files/run/reify_implicits-new.check @@ -0,0 +1 @@ +x = List(1, 2, 3, 4) diff --git a/test/files/run/reify_implicits-new.scala b/test/files/run/reify_implicits-new.scala new file mode 100644 index 0000000000..69198391d1 --- /dev/null +++ b/test/files/run/reify_implicits-new.scala @@ -0,0 +1,14 @@ +import scala.reflect.mirror._ + +object Test extends App { + reify { + implicit def arrayWrapper[A : ArrayTag](x: Array[A]) = + new { + def sort(p: (A, A) => Boolean) = { + util.Sorting.stableSort(x, p); x + } + } + val x = Array(2, 3, 1, 4) + println("x = "+ x.sort((x: Int, y: Int) => x < y).toList) + }.eval +} diff --git a/test/files/run/reify_implicits.check b/test/files/run/reify_implicits.check deleted file mode 100644 index e3aeb20f6b..0000000000 --- a/test/files/run/reify_implicits.check +++ /dev/null @@ -1 +0,0 @@ -x = List(1, 2, 3, 4) diff --git a/test/files/run/reify_implicits.scala b/test/files/run/reify_implicits.scala deleted file mode 100644 index 60971c3cfb..0000000000 --- a/test/files/run/reify_implicits.scala +++ /dev/null @@ -1,14 +0,0 @@ -import scala.reflect.mirror._ - -object Test extends App { - reify { - implicit def arrayWrapper[A : ClassManifest](x: Array[A]) = - new { - def sort(p: (A, A) => Boolean) = { - util.Sorting.stableSort(x, p); x - } - } - val x = Array(2, 3, 1, 4) - println("x = "+ x.sort((x: Int, y: Int) => x < y).toList) - }.eval -} diff --git a/test/files/run/repl-power.check b/test/files/run/repl-power.check index 1e7b6f0cd8..c509434116 100644 --- a/test/files/run/repl-power.check +++ b/test/files/run/repl-power.check @@ -1,32 +1,32 @@ -Type in expressions to have them evaluated. -Type :help for more information. - -scala> :power -** Power User mode enabled - BEEP WHIR GYVE ** -** :phase has been set to 'typer'. ** -** scala.tools.nsc._ has been imported ** -** global._, definitions._ also imported ** -** Try :help, :vals, power. ** - -scala> // guarding against "error: reference to global is ambiguous" - -scala> global.emptyValDef // "it is imported twice in the same scope by ..." -res0: $r.global.emptyValDef.type = private val _ = _ - -scala> val tp = ArrayClass[scala.util.Random] // magic with manifests -tp: $r.global.Type = Array[scala.util.Random] - -scala> tp.memberType(Array_apply) // evidence -res1: $r.global.Type = (i: Int)scala.util.Random - -scala> val m = LIT(10) MATCH (CASE(LIT(5)) ==> FALSE, DEFAULT ==> TRUE) // treedsl -m: $r.treedsl.global.Match = -10 match { - case 5 => false - case _ => true -} - -scala> typed(m).tpe // typed is in scope -res2: $r.treedsl.global.Type = Boolean - -scala> +Type in expressions to have them evaluated. +Type :help for more information. + +scala> :power +** Power User mode enabled - BEEP WHIR GYVE ** +** :phase has been set to 'typer'. ** +** scala.tools.nsc._ has been imported ** +** global._, definitions._ also imported ** +** Try :help, :vals, power. ** + +scala> // guarding against "error: reference to global is ambiguous" + +scala> global.emptyValDef // "it is imported twice in the same scope by ..." +res0: $r.global.emptyValDef.type = private val _ = _ + +scala> val tp = ArrayClass[scala.util.Random] // magic with tags +tp: $r.global.Type = Array[scala.util.Random] + +scala> tp.memberType(Array_apply) // evidence +res1: $r.global.Type = (i: Int)scala.util.Random + +scala> val m = LIT(10) MATCH (CASE(LIT(5)) ==> FALSE, DEFAULT ==> TRUE) // treedsl +m: $r.treedsl.global.Match = +10 match { + case 5 => false + case _ => true +} + +scala> typed(m).tpe // typed is in scope +res2: $r.treedsl.global.Type = Boolean + +scala> diff --git a/test/files/run/repl-power.scala b/test/files/run/repl-power.scala index 27da3df106..f7c88c63ff 100644 --- a/test/files/run/repl-power.scala +++ b/test/files/run/repl-power.scala @@ -5,10 +5,9 @@ object Test extends ReplTest { :power // guarding against "error: reference to global is ambiguous" global.emptyValDef // "it is imported twice in the same scope by ..." -val tp = ArrayClass[scala.util.Random] // magic with manifests +val tp = ArrayClass[scala.util.Random] // magic with tags tp.memberType(Array_apply) // evidence val m = LIT(10) MATCH (CASE(LIT(5)) ==> FALSE, DEFAULT ==> TRUE) // treedsl typed(m).tpe // typed is in scope """.trim } - diff --git a/test/files/run/t0421-new.check b/test/files/run/t0421-new.check new file mode 100644 index 0000000000..cdcf042f19 --- /dev/null +++ b/test/files/run/t0421-new.check @@ -0,0 +1,3 @@ +[Array(0, 1),Array(2, 3),Array(4, 5)] +[Array(31.0)] +[Array(24.0, 32.0)] diff --git a/test/files/run/t0421-new.scala b/test/files/run/t0421-new.scala new file mode 100644 index 0000000000..7de6b7f2c4 --- /dev/null +++ b/test/files/run/t0421-new.scala @@ -0,0 +1,30 @@ +// ticket #421 +object Test extends App { + + def transpose[A: ArrayTag](xss: Array[Array[A]]) = { + for (i <- Array.range(0, xss(0).length)) yield + for (xs <- xss) yield xs(i) + } + + def scalprod(xs: Array[Double], ys: Array[Double]) = { + var acc = 0.0 + for ((x, y) <- xs zip ys) acc = acc + x * y + acc + } + + def matmul(xss: Array[Array[Double]], yss: Array[Array[Double]]) = { + val ysst = transpose(yss) + val ysst1: Array[Array[Double]] = yss.transpose + assert(ysst.deep == ysst1.deep) + for (xs <- xss) yield + for (yst <- ysst) yield + scalprod(xs, yst) + } + + val a1 = Array(Array(0, 2, 4), Array(1, 3, 5)) + println(transpose(a1).deep.mkString("[", ",", "]")) + + println(matmul(Array(Array(2, 3)), Array(Array(5), Array(7))).deep.mkString("[", ",", "]")) + + println(matmul(Array(Array(4)), Array(Array(6, 8))).deep.mkString("[", ",", "]")) +} diff --git a/test/files/run/t0421.check b/test/files/run/t0421.check deleted file mode 100644 index cdcf042f19..0000000000 --- a/test/files/run/t0421.check +++ /dev/null @@ -1,3 +0,0 @@ -[Array(0, 1),Array(2, 3),Array(4, 5)] -[Array(31.0)] -[Array(24.0, 32.0)] diff --git a/test/files/run/t0421.scala b/test/files/run/t0421.scala deleted file mode 100644 index 8d51013924..0000000000 --- a/test/files/run/t0421.scala +++ /dev/null @@ -1,30 +0,0 @@ -// ticket #421 -object Test extends App { - - def transpose[A: ClassManifest](xss: Array[Array[A]]) = { - for (i <- Array.range(0, xss(0).length)) yield - for (xs <- xss) yield xs(i) - } - - def scalprod(xs: Array[Double], ys: Array[Double]) = { - var acc = 0.0 - for ((x, y) <- xs zip ys) acc = acc + x * y - acc - } - - def matmul(xss: Array[Array[Double]], yss: Array[Array[Double]]) = { - val ysst = transpose(yss) - val ysst1: Array[Array[Double]] = yss.transpose - assert(ysst.deep == ysst1.deep) - for (xs <- xss) yield - for (yst <- ysst) yield - scalprod(xs, yst) - } - - val a1 = Array(Array(0, 2, 4), Array(1, 3, 5)) - println(transpose(a1).deep.mkString("[", ",", "]")) - - println(matmul(Array(Array(2, 3)), Array(Array(5), Array(7))).deep.mkString("[", ",", "]")) - - println(matmul(Array(Array(4)), Array(Array(6, 8))).deep.mkString("[", ",", "]")) -} diff --git a/test/files/run/t0677-new.scala b/test/files/run/t0677-new.scala new file mode 100644 index 0000000000..bf7a3971dc --- /dev/null +++ b/test/files/run/t0677-new.scala @@ -0,0 +1,8 @@ +object Test extends App { + class X[T: ArrayTag] { + val a = Array.ofDim[T](3, 4) + } + val x = new X[String] + x.a(1)(2) = "hello" + assert(x.a(1)(2) == "hello") +} diff --git a/test/files/run/t0677.scala b/test/files/run/t0677.scala deleted file mode 100644 index 6c8a3a7e99..0000000000 --- a/test/files/run/t0677.scala +++ /dev/null @@ -1,8 +0,0 @@ -object Test extends App { - class X[T: ClassManifest] { - val a = Array.ofDim[T](3, 4) - } - val x = new X[String] - x.a(1)(2) = "hello" - assert(x.a(1)(2) == "hello") -} diff --git a/test/files/run/t1195-new.check b/test/files/run/t1195-new.check new file mode 100644 index 0000000000..554e3fd03d --- /dev/null +++ b/test/files/run/t1195-new.check @@ -0,0 +1,6 @@ +ConcreteTypeTag[Bar.type], underlying = <: scala.runtime.AbstractFunction1[Int,Bar] with Serializable{case def unapply(x$0: Bar): Option[Int]} with Singleton +ConcreteTypeTag[Bar], underlying = <: Product with Serializable{val x: Int; def copy(x: Int): Bar; def copy$default$1: Int; def _1: Int} +ConcreteTypeTag[Product with Serializable], underlying = Product with Serializable +ConcreteTypeTag[Bar.type], underlying = <: scala.runtime.AbstractFunction1[Int,Bar] with Serializable{case def unapply(x$0: Bar): Option[Int]} with Singleton +ConcreteTypeTag[Bar], underlying = <: Product with Serializable{val x: Int; def copy(x: Int): Bar; def copy$default$1: Int; def _1: Int} +ConcreteTypeTag[Product with Serializable], underlying = Product with Serializable diff --git a/test/files/run/t1195-new.scala b/test/files/run/t1195-new.scala new file mode 100644 index 0000000000..6f28a4a167 --- /dev/null +++ b/test/files/run/t1195-new.scala @@ -0,0 +1,26 @@ +object Test { + def f() = { case class Bar(x: Int); Bar } + def g() = { case class Bar(x: Int); Bar(5) } + def h() = { case object Bar ; Bar } + + val f1 = f() + val g1 = g() + val h1 = h() + + def m[T: TypeTag](x: T) = println(typeTag[T] + ", underlying = " + typeTag[T].sym.typeSignature) + + def main(args: Array[String]): Unit = { + m(f) + m(g) + m(h) + m(f1) + m(g1) + m(h1) + } +} + +class A1[T] { + class B1[U] { + def f = { case class D(x: Int) extends A1[String] ; new D(5) } + } +} diff --git a/test/files/run/t1195.check b/test/files/run/t1195.check deleted file mode 100644 index 554e3fd03d..0000000000 --- a/test/files/run/t1195.check +++ /dev/null @@ -1,6 +0,0 @@ -ConcreteTypeTag[Bar.type], underlying = <: scala.runtime.AbstractFunction1[Int,Bar] with Serializable{case def unapply(x$0: Bar): Option[Int]} with Singleton -ConcreteTypeTag[Bar], underlying = <: Product with Serializable{val x: Int; def copy(x: Int): Bar; def copy$default$1: Int; def _1: Int} -ConcreteTypeTag[Product with Serializable], underlying = Product with Serializable -ConcreteTypeTag[Bar.type], underlying = <: scala.runtime.AbstractFunction1[Int,Bar] with Serializable{case def unapply(x$0: Bar): Option[Int]} with Singleton -ConcreteTypeTag[Bar], underlying = <: Product with Serializable{val x: Int; def copy(x: Int): Bar; def copy$default$1: Int; def _1: Int} -ConcreteTypeTag[Product with Serializable], underlying = Product with Serializable diff --git a/test/files/run/t1195.scala b/test/files/run/t1195.scala deleted file mode 100644 index 93b1dcbd07..0000000000 --- a/test/files/run/t1195.scala +++ /dev/null @@ -1,26 +0,0 @@ -object Test { - def f() = { case class Bar(x: Int); Bar } - def g() = { case class Bar(x: Int); Bar(5) } - def h() = { case object Bar ; Bar } - - val f1 = f() - val g1 = g() - val h1 = h() - - def m[T: Manifest](x: T) = println(manifest[T] + ", underlying = " + manifest[T].sym.typeSignature) - - def main(args: Array[String]): Unit = { - m(f) - m(g) - m(h) - m(f1) - m(g1) - m(h1) - } -} - -class A1[T] { - class B1[U] { - def f = { case class D(x: Int) extends A1[String] ; new D(5) } - } -} diff --git a/test/files/run/t2236-new.scala b/test/files/run/t2236-new.scala new file mode 100644 index 0000000000..bbabe8e7d9 --- /dev/null +++ b/test/files/run/t2236-new.scala @@ -0,0 +1,17 @@ +class T[A](implicit val m:TypeTag[A]) +class Foo +class Bar extends T[Foo] +object Test extends App { + new Bar +} + +object EvidenceTest { + trait E[T] + trait A[T] { implicit val e: E[T] = null } + class B[T : E] extends A[T] { override val e = null } + + def f[T] { + implicit val e: E[T] = null + new B[T]{} + } +} diff --git a/test/files/run/t2236.scala b/test/files/run/t2236.scala deleted file mode 100755 index 64ed18c805..0000000000 --- a/test/files/run/t2236.scala +++ /dev/null @@ -1,17 +0,0 @@ -class T[A](implicit val m:Manifest[A]) -class Foo -class Bar extends T[Foo] -object Test extends App { - new Bar -} - -object EvidenceTest { - trait E[T] - trait A[T] { implicit val e: E[T] = null } - class B[T : E] extends A[T] { override val e = null } - - def f[T] { - implicit val e: E[T] = null - new B[T]{} - } -} diff --git a/test/files/run/t2386-new.check b/test/files/run/t2386-new.check new file mode 100644 index 0000000000..98e226f946 --- /dev/null +++ b/test/files/run/t2386-new.check @@ -0,0 +1,2 @@ +a(0) = Array(1, 2) +a(1) = Array("a", "b") diff --git a/test/files/run/t2386-new.scala b/test/files/run/t2386-new.scala new file mode 100644 index 0000000000..15d1859759 --- /dev/null +++ b/test/files/run/t2386-new.scala @@ -0,0 +1,5 @@ +object Test extends App { + val a = Array(Array(1, 2), Array("a","b")) + println("a(0) = Array(" + (a(0) mkString ", ") + ")") + println("a(1) = Array(" + (a(1) map (s => "\"" + s + "\"") mkString ", ") + ")") +} diff --git a/test/files/run/t3507-new.check b/test/files/run/t3507-new.check new file mode 100644 index 0000000000..6e4fa4170e --- /dev/null +++ b/test/files/run/t3507-new.check @@ -0,0 +1 @@ +ConcreteTypeTag[_1.b.c.type] diff --git a/test/files/run/t3507-new.scala b/test/files/run/t3507-new.scala new file mode 100644 index 0000000000..c7a529e8b8 --- /dev/null +++ b/test/files/run/t3507-new.scala @@ -0,0 +1,15 @@ +class A { + object b { + object c + } + def m = b.c +} + +object Test extends App { + var a: A = new A // mutable + val c /*: object _1.b.c forSome { val _1: A } */ = a.m // widening using existential + + def mani[T: TypeTag](x: T) = println(typeTag[T]) + mani/*[object _1.b.c]*/(c) // kaboom in manifestOfType / TreeGen.mkAttributedQualifier + // --> _1 is not in scope here +} \ No newline at end of file diff --git a/test/files/run/t3507.check b/test/files/run/t3507.check deleted file mode 100644 index 6e4fa4170e..0000000000 --- a/test/files/run/t3507.check +++ /dev/null @@ -1 +0,0 @@ -ConcreteTypeTag[_1.b.c.type] diff --git a/test/files/run/t3507.scala b/test/files/run/t3507.scala deleted file mode 100644 index 3cdd40a881..0000000000 --- a/test/files/run/t3507.scala +++ /dev/null @@ -1,15 +0,0 @@ -class A { - object b { - object c - } - def m = b.c -} - -object Test extends App { - var a: A = new A // mutable - val c /*: object _1.b.c forSome { val _1: A } */ = a.m // widening using existential - - def mani[T: Manifest](x: T) = println(manifest[T]) - mani/*[object _1.b.c]*/(c) // kaboom in manifestOfType / TreeGen.mkAttributedQualifier - // --> _1 is not in scope here -} \ No newline at end of file diff --git a/test/files/run/t3758.check b/test/files/run/t3758.check deleted file mode 100644 index 9c6ab655a3..0000000000 --- a/test/files/run/t3758.check +++ /dev/null @@ -1,6 +0,0 @@ -List(String) -List(Int) -List(Float) -List(String) -List(Int) -List(Float) diff --git a/test/files/run/t3758.scala b/test/files/run/t3758.scala deleted file mode 100644 index 10bfb5724b..0000000000 --- a/test/files/run/t3758.scala +++ /dev/null @@ -1,10 +0,0 @@ -object Test { - def main(args: Array[String]): Unit = { - println(classManifest[Array[String]].tpe.typeArguments) - println(classManifest[Array[Int]].tpe.typeArguments) - println(classManifest[Array[Float]].tpe.typeArguments) - println(manifest[Array[String]].tpe.typeArguments) - println(manifest[Array[Int]].tpe.typeArguments) - println(manifest[Array[Float]].tpe.typeArguments) - } -} diff --git a/test/files/run/t4110-new.check b/test/files/run/t4110-new.check new file mode 100644 index 0000000000..28f220e1fe --- /dev/null +++ b/test/files/run/t4110-new.check @@ -0,0 +1,2 @@ +ConcreteTypeTag[Test.A with Test.B] +ConcreteTypeTag[Test.A with Test.B] diff --git a/test/files/run/t4110-new.scala b/test/files/run/t4110-new.scala new file mode 100644 index 0000000000..3285b82c61 --- /dev/null +++ b/test/files/run/t4110-new.scala @@ -0,0 +1,11 @@ +object Test extends App { + def inferredType[T : TypeTag](v : T) = println(typeTag[T]) + + trait A + trait B + + inferredType(new A with B) + + val name = new A with B + inferredType(name) +} \ No newline at end of file diff --git a/test/files/run/t4110.check b/test/files/run/t4110.check deleted file mode 100644 index 28f220e1fe..0000000000 --- a/test/files/run/t4110.check +++ /dev/null @@ -1,2 +0,0 @@ -ConcreteTypeTag[Test.A with Test.B] -ConcreteTypeTag[Test.A with Test.B] diff --git a/test/files/run/t4110.scala b/test/files/run/t4110.scala deleted file mode 100644 index 4bd377b73e..0000000000 --- a/test/files/run/t4110.scala +++ /dev/null @@ -1,11 +0,0 @@ -object Test extends App { - def inferredType[T : Manifest](v : T) = println(manifest[T]) - - trait A - trait B - - inferredType(new A with B) - - val name = new A with B - inferredType(name) -} \ No newline at end of file diff --git a/test/files/scalacheck/array-new.scala b/test/files/scalacheck/array-new.scala new file mode 100644 index 0000000000..18d577ca6d --- /dev/null +++ b/test/files/scalacheck/array-new.scala @@ -0,0 +1,36 @@ +import org.scalacheck._ +import Prop._ +import Gen._ +import Arbitrary._ +import util._ +import Buildable._ +import scala.collection.mutable.ArraySeq + +object Test extends Properties("Array") { + /** At this moment the authentic scalacheck Array Builder/Arb bits are commented out. + */ + implicit def arbArray[T](implicit a: Arbitrary[T], m: ArrayTag[T]): Arbitrary[Array[T]] = + Arbitrary(containerOf[List,T](arbitrary[T]) map (_.toArray)) + + val arrGen: Gen[Array[_]] = oneOf( + arbitrary[Array[Int]], + arbitrary[Array[Array[Int]]], + arbitrary[Array[List[String]]], + arbitrary[Array[String]], + arbitrary[Array[Boolean]], + arbitrary[Array[AnyVal]] + ) + + // inspired by #1857 and #2352 + property("eq/ne") = forAll(arrGen, arrGen) { (c1, c2) => + (c1 eq c2) || (c1 ne c2) + } + + // inspired by #2299 + def smallInt = choose(1, 10) + property("ofDim") = forAll(smallInt, smallInt, smallInt) { (i1, i2, i3) => + val arr = Array.ofDim[String](i1, i2, i3) + val flattened = arr flatMap (x => x) flatMap (x => x) + flattened.length == i1 * i2 * i3 + } +} diff --git a/test/files/scalacheck/array.scala b/test/files/scalacheck/array.scala deleted file mode 100644 index f262bc6320..0000000000 --- a/test/files/scalacheck/array.scala +++ /dev/null @@ -1,37 +0,0 @@ -import org.scalacheck._ -import Prop._ -import Gen._ -import Arbitrary._ -import util._ -import Buildable._ -import scala.collection.mutable.ArraySeq - -object Test extends Properties("Array") { - /** At this moment the authentic scalacheck Array Builder/Arb bits are commented out. - */ - implicit def arbArray[T](implicit a: Arbitrary[T], m: Manifest[T]): Arbitrary[Array[T]] = - Arbitrary(containerOf[List,T](arbitrary[T]) map (_.toArray)) - - val arrGen: Gen[Array[_]] = oneOf( - arbitrary[Array[Int]], - arbitrary[Array[Array[Int]]], - arbitrary[Array[List[String]]], - arbitrary[Array[String]], - arbitrary[Array[Boolean]], - arbitrary[Array[AnyVal]] - ) - - // inspired by #1857 and #2352 - property("eq/ne") = forAll(arrGen, arrGen) { (c1, c2) => - (c1 eq c2) || (c1 ne c2) - } - - // inspired by #2299 - def smallInt = choose(1, 10) - property("ofDim") = forAll(smallInt, smallInt, smallInt) { (i1, i2, i3) => - val arr = Array.ofDim[String](i1, i2, i3) - val flattened = arr flatMap (x => x) flatMap (x => x) - flattened.length == i1 * i2 * i3 - } -} - diff --git a/test/files/specialized/spec-matrix-new.check b/test/files/specialized/spec-matrix-new.check new file mode 100644 index 0000000000..5ec3e84597 --- /dev/null +++ b/test/files/specialized/spec-matrix-new.check @@ -0,0 +1,2 @@ +251437.0 +Boxed doubles: 1 diff --git a/test/files/specialized/spec-matrix-new.scala b/test/files/specialized/spec-matrix-new.scala new file mode 100644 index 0000000000..65b46e8d48 --- /dev/null +++ b/test/files/specialized/spec-matrix-new.scala @@ -0,0 +1,80 @@ +/** Test matrix multiplication with specialization. + */ + +class Matrix[@specialized A: ArrayTag](val rows: Int, val cols: Int) { + private val arr: Array[Array[A]] = Array.ofDim[A](rows, cols) + + def apply(i: Int, j: Int): A = { + if (i < 0 || i >= rows || j < 0 || j >= cols) + throw new NoSuchElementException("Indexes out of bounds: " + (i, j)) + + arr(i)(j) + } + + def update(i: Int, j: Int, e: A) { + arr(i)(j) = e + } + + def rowsIterator: Iterator[Array[A]] = new Iterator[Array[A]] { + var idx = 0; + def hasNext = idx < rows + def next = { + idx += 1 + arr(idx - 1) + } + } +} + +object Test { + def main(args: Array[String]) { + val m = randomMatrix(200, 100) + val n = randomMatrix(100, 200) + + val p = mult(m, n) + println(p(0, 0)) + println("Boxed doubles: " + runtime.BoxesRunTime.doubleBoxCount) +// println("Boxed integers: " + runtime.BoxesRunTime.integerBoxCount) + } + + def randomMatrix(n: Int, m: Int) = { + val r = new util.Random(10) + val x = new Matrix[Double](n, m) + for (i <- 0 until n; j <- 0 until m) + x(i, j) = (r.nextInt % 1000).toDouble + x + } + + def printMatrix[Double](m: Matrix[Double]) { + for (i <- 0 until m.rows) { + for (j <- 0 until m.cols) + print("%5.3f ".format(m(i, j))) + println + } + } + + def multTag[@specialized(Int) T](m: Matrix[T], n: Matrix[T])(implicit at: ArrayTag[T], num: Numeric[T]) { + val p = new Matrix[T](m.rows, n.cols) + import num._ + + for (i <- 0 until m.rows) + for (j <- 0 until n.cols) { + var sum = num.zero + for (k <- 0 until n.rows) + sum += m(i, k) * n(k, j) + p(i, j) = sum + } + } + + def mult(m: Matrix[Double], n: Matrix[Double]) = { + val p = new Matrix[Double](m.rows, n.cols) + + for (i <- 0 until m.rows) + for (j <- 0 until n.cols) { + var sum = 0.0 + for (k <- 0 until n.rows) + sum += m(i, k) * n(k, j) + p(i, j) = sum + } + p + } +} diff --git a/test/files/specialized/spec-matrix.check b/test/files/specialized/spec-matrix.check deleted file mode 100644 index 5ec3e84597..0000000000 --- a/test/files/specialized/spec-matrix.check +++ /dev/null @@ -1,2 +0,0 @@ -251437.0 -Boxed doubles: 1 diff --git a/test/files/specialized/spec-matrix.scala b/test/files/specialized/spec-matrix.scala deleted file mode 100644 index 98735c8c03..0000000000 --- a/test/files/specialized/spec-matrix.scala +++ /dev/null @@ -1,80 +0,0 @@ -/** Test matrix multiplication with specialization. - */ - -class Matrix[@specialized A: ClassManifest](val rows: Int, val cols: Int) { - private val arr: Array[Array[A]] = Array.ofDim[A](rows, cols) - - def apply(i: Int, j: Int): A = { - if (i < 0 || i >= rows || j < 0 || j >= cols) - throw new NoSuchElementException("Indexes out of bounds: " + (i, j)) - - arr(i)(j) - } - - def update(i: Int, j: Int, e: A) { - arr(i)(j) = e - } - - def rowsIterator: Iterator[Array[A]] = new Iterator[Array[A]] { - var idx = 0; - def hasNext = idx < rows - def next = { - idx += 1 - arr(idx - 1) - } - } -} - -object Test { - def main(args: Array[String]) { - val m = randomMatrix(200, 100) - val n = randomMatrix(100, 200) - - val p = mult(m, n) - println(p(0, 0)) - println("Boxed doubles: " + runtime.BoxesRunTime.doubleBoxCount) -// println("Boxed integers: " + runtime.BoxesRunTime.integerBoxCount) - } - - def randomMatrix(n: Int, m: Int) = { - val r = new util.Random(10) - val x = new Matrix[Double](n, m) - for (i <- 0 until n; j <- 0 until m) - x(i, j) = (r.nextInt % 1000).toDouble - x - } - - def printMatrix[Double](m: Matrix[Double]) { - for (i <- 0 until m.rows) { - for (j <- 0 until m.cols) - print("%5.3f ".format(m(i, j))) - println - } - } - - def multManifest[@specialized(Int) T](m: Matrix[T], n: Matrix[T])(implicit cm: ClassManifest[T], num: Numeric[T]) { - val p = new Matrix[T](m.rows, n.cols) - import num._ - - for (i <- 0 until m.rows) - for (j <- 0 until n.cols) { - var sum = num.zero - for (k <- 0 until n.rows) - sum += m(i, k) * n(k, j) - p(i, j) = sum - } - } - - def mult(m: Matrix[Double], n: Matrix[Double]) = { - val p = new Matrix[Double](m.rows, n.cols) - - for (i <- 0 until m.rows) - for (j <- 0 until n.cols) { - var sum = 0.0 - for (k <- 0 until n.rows) - sum += m(i, k) * n(k, j) - p(i, j) = sum - } - p - } -} diff --git a/test/pending/pos/inference.scala b/test/pending/pos/inference.scala index d28d003435..3672351fca 100644 --- a/test/pending/pos/inference.scala +++ b/test/pending/pos/inference.scala @@ -1,15 +1,15 @@ // inference illuminator object Test { - class D1[T1 : Manifest, T2 <: T1 : Manifest](x: T1) { println(manifest[(T1, T2)]) } - class D2[T1 : Manifest, T2 >: T1 : Manifest](x: T1) { println(manifest[(T1, T2)]) } - class D3[+T1 : Manifest, T2 <: T1 : Manifest](x: T1) { println(manifest[(T1, T2)]) } - class D4[-T1 : Manifest, T2 >: T1 : Manifest](x: T1) { println(manifest[(T1, T2)]) } - - class E1[T1 : Manifest, T2 <: T1 : Manifest](x: D1[T1, T2]) { println(manifest[(T1, T2)]) } - class E2[T1 : Manifest, T2 >: T1 : Manifest](x: D2[T1, T2]) { println(manifest[(T1, T2)]) } - class E3[+T1 : Manifest, T2 <: T1 : Manifest](x: D3[T1, T2]) { println(manifest[(T1, T2)]) } - class E4[-T1 : Manifest, T2 >: T1 : Manifest](x: D4[T1, T2]) { println(manifest[(T1, T2)]) } - + class D1[T1 : TypeTag, T2 <: T1 : TypeTag](x: T1) { println(typeTag[(T1, T2)]) } + class D2[T1 : TypeTag, T2 >: T1 : TypeTag](x: T1) { println(typeTag[(T1, T2)]) } + class D3[+T1 : TypeTag, T2 <: T1 : TypeTag](x: T1) { println(typeTag[(T1, T2)]) } + class D4[-T1 : TypeTag, T2 >: T1 : TypeTag](x: T1) { println(typeTag[(T1, T2)]) } + + class E1[T1 : TypeTag, T2 <: T1 : TypeTag](x: D1[T1, T2]) { println(typeTag[(T1, T2)]) } + class E2[T1 : TypeTag, T2 >: T1 : TypeTag](x: D2[T1, T2]) { println(typeTag[(T1, T2)]) } + class E3[+T1 : TypeTag, T2 <: T1 : TypeTag](x: D3[T1, T2]) { println(typeTag[(T1, T2)]) } + class E4[-T1 : TypeTag, T2 >: T1 : TypeTag](x: D4[T1, T2]) { println(typeTag[(T1, T2)]) } + def main(args: Array[String]): Unit = { // WHY YOU NO LIKE NOTHING SO MUCH SCALAC? val d1 = new D1(5) diff --git a/test/pending/shootout/meteor.scala b/test/pending/shootout/meteor.scala index 2fd702753a..154695533b 100644 --- a/test/pending/shootout/meteor.scala +++ b/test/pending/shootout/meteor.scala @@ -19,7 +19,7 @@ object meteor { -// Solver.scala +// Solver.scala // import scala.collection.mutable._ final class Solver (n: Int) { @@ -29,8 +29,8 @@ final class Solver (n: Int) { private val board = new Board() - val pieces = Array( - new Piece(0), new Piece(1), new Piece(2), new Piece(3), new Piece(4), + val pieces = Array( + new Piece(0), new Piece(1), new Piece(2), new Piece(3), new Piece(4), new Piece(5), new Piece(6), new Piece(7), new Piece(8), new Piece(9) ) val unplaced = new BitSet(pieces.length) @@ -71,8 +71,8 @@ final class Solver (n: Int) { private def puzzleSolved() = { val b = board.asString - if (first == null){ - first = b; last = b + if (first == null){ + first = b; last = b } else { if (b < first){ first = b } else { if (b > last){ last = b } } } @@ -81,7 +81,7 @@ final class Solver (n: Int) { private def shouldPrune() = { board.unmark - !board.cells.forall(c => c.contiguousEmptyCells % Piece.size == 0) + !board.cells.forall(c => c.contiguousEmptyCells % Piece.size == 0) } @@ -108,8 +108,8 @@ final class Solver (n: Int) { } /* - def printPieces() = - for (i <- Iterator.range(0,Board.pieces)) pieces(i).print + def printPieces() = + for (i <- Iterator.range(0,Board.pieces)) pieces(i).print */ } @@ -126,7 +126,7 @@ object Board { val size = rows * cols } -final class Board { +final class Board { val cells = boardCells() val cellsPieceWillFill = new Array[BoardCell](Piece.size) @@ -134,9 +134,9 @@ final class Board { def unmark() = for (c <- cells) c.unmark - def asString() = - new String( cells map( - c => if (c.piece == null) '-'.toByte + def asString() = + new String( cells map( + c => if (c.piece == null) '-'.toByte else (c.piece.number + 48).toByte )) def firstEmptyCellIndex() = cells.findIndexOf(c => c.isEmpty) @@ -144,13 +144,13 @@ final class Board { def add(pieceIndex: Int, boardIndex: Int, p: Piece) = { cellCount = 0 p.unmark - + find( p.cells(pieceIndex), cells(boardIndex)) - val boardHasSpace = cellCount == Piece.size && - cellsPieceWillFill.forall(c => c.isEmpty) + val boardHasSpace = cellCount == Piece.size && + cellsPieceWillFill.forall(c => c.isEmpty) - if (boardHasSpace) cellsPieceWillFill.foreach(c => c.piece = p) + if (boardHasSpace) cellsPieceWillFill.foreach(c => c.piece = p) boardHasSpace } @@ -180,10 +180,10 @@ final class Board { if (row % 2 == 1) { if (!isLast) c.next(Cell.NE) = a(i-(Board.cols-1)) - c.next(Cell.NW) = a(i-Board.cols) + c.next(Cell.NW) = a(i-Board.cols) if (row != m) { if (!isLast) c.next(Cell.SE) = a(i+(Board.cols+1)) - c.next(Cell.SW) = a(i+Board.cols) + c.next(Cell.SW) = a(i+Board.cols) } } else { if (row != 0) { @@ -212,9 +212,9 @@ final class Board { Console.print(i + "\t") for (j <- Iterator.range(0,Cell.sides)){ val c = cells(i).next(j) - if (c == null) - Console.print("-- ") - else + if (c == null) + Console.print("-- ") + else Console.printf("{0,number,00} ")(c.number) } Console.println("") @@ -241,7 +241,7 @@ final class Piece(_number: Int) { val number = _number val cells = for (i <- Array.range(0,Piece.size)) yield new PieceCell() - { + { number match { case 0 => make0 case 1 => make1 @@ -252,7 +252,7 @@ final class Piece(_number: Int) { case 6 => make6 case 7 => make7 case 8 => make8 - case 9 => make9 + case 9 => make9 } } @@ -395,12 +395,12 @@ final class Piece(_number: Int) { Console.print(i + "\t") for (j <- Iterator.range(0,Cell.sides)){ val c = cells(i).next(j) - if (c == null) - Console.print("-- ") - else + if (c == null) + Console.print("-- ") + else for (k <- Iterator.range(0,Piece.size)){ if (cells(k) == c) Console.printf(" {0,number,0} ")(k) - } + } } Console.println("") } @@ -418,13 +418,13 @@ final class Piece(_number: Int) { object Cell { val NW = 0; val NE = 1 val W = 2; val E = 3 - val SW = 4; val SE = 5 + val SW = 4; val SE = 5 val sides = 6 } abstract class Cell { - implicit def m: Manifest[T] + implicit def t: ClassTag[T] type T val next = new Array[T](Cell.sides) var marked = false @@ -437,7 +437,7 @@ abstract class Cell { final class BoardCell(_number: Int) extends { type T = BoardCell - implicit val m = manifest[BoardCell] + implicit val t = classTag[BoardCell] } with Cell { val number = _number var piece: Piece = _ @@ -448,10 +448,10 @@ final class BoardCell(_number: Int) extends { def contiguousEmptyCells(): Int = { if (!marked && isEmpty){ mark - var count = 1 + var count = 1 for (neighbour <- next) - if (neighbour != null && neighbour.isEmpty) + if (neighbour != null && neighbour.isEmpty) count = count + neighbour.contiguousEmptyCells count } else { 0 } diff --git a/test/scaladoc/resources/implicits-base-res.scala b/test/scaladoc/resources/implicits-base-res.scala index 3e3d0f01a6..65d7bdf67c 100644 --- a/test/scaladoc/resources/implicits-base-res.scala +++ b/test/scaladoc/resources/implicits-base-res.scala @@ -137,6 +137,8 @@ class ManifestA[W: Manifest](a: A[W]) { def convToManifestA(x: W): W = sys.error("dunno") } +// [Eugene to Vlad] how do I test typetags here? + /** MyTraversableOps class
* - checks if any abstract members are added - should not happen! */ @@ -144,4 +146,3 @@ trait MyTraversableOps[S] { /** The convToTraversableOps: S documentation... */ def convToTraversableOps(x: S): S } - -- cgit v1.2.3