From f38f027d139672603ff8c3f9956bf8d5f4b4f8c5 Mon Sep 17 00:00:00 2001 From: jvican Date: Mon, 9 May 2016 23:19:51 +0200 Subject: [PATCH] Add big improvement in the implicit search * Change all the implicit definitions to return `AbstractPicklerUnpickler` instead of `Pickler[T] with Unpickler[T]`. The former one has more precedence than the latter one. This avoids to call the generator macro EVERY TIME we ask for an implicit pickler/unpickler. * Make sure that the `LowPriorityImplicits` are placed in the right location of the `Defaults` trait. * This addresses a big deal of #422 although more changes will come, especially affecting `preferringAlternativeImplicits`. * Do some minor cleanup and formatting changes (trying out scalafmt) in the project. * Remove explicit registerings of picklers that were not necessary because of `AutoRegister`. * Register myself to the TODOs that are concerned with the creation of runtime picklers/unpicklers. @jsuereth, I've stolen you some TODOs ;) --- README.md | 2 +- .../pickler/AllPicklerUnpicklers.scala | 21 ++-- .../scala/scala/pickling/pickler/Array.scala | 9 +- .../scala/pickling/pickler/ArrayBuffer.scala | 12 ++- .../scala/scala/pickling/pickler/Date.scala | 50 +++++----- .../pickler/GenPicklersUnpicklers.scala | 4 +- .../pickling/pickler/GeneratorRegistry.scala | 20 +++- .../scala/pickling/pickler/Iterable.scala | 96 +++++++++---------- .../pickling/pickler/JavaBigDecimal.scala | 8 +- .../pickling/pickler/JavaBigInteger.scala | 8 +- .../pickling/pickler/JavaUUIDPickler.scala | 8 +- .../scala/scala/pickling/pickler/Map.scala | 54 ++++++----- .../pickling/pickler/PrimitiveArrays.scala | 16 ++-- .../scala/pickling/pickler/Primitives.scala | 24 ++--- .../scala/scala/pickling/pickler/Ref.scala | 20 +++- .../scala/scala/pickling/pickler/Seq.scala | 33 ++++--- .../scala/scala/pickling/pickler/Set.scala | 40 +++++--- .../scala/pickling/pickler/TypeTags.scala | 26 ++--- .../scala/scala/pickling/pickler/Vector.scala | 12 ++- .../SealedTraitStaticAnnotatedTest.scala | 2 +- .../StaticOnlyWithManualPicklerTest.scala | 6 +- .../generator/SingletonGenerator.scala | 4 +- 22 files changed, 271 insertions(+), 204 deletions(-) diff --git a/README.md b/README.md index e917c086e0..955de870d1 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ import scala.pickling.Defaults.{ pickleOps, unpickleOps } // import scala.pickling.functions._ // Import picklers for specific types -import scala.pickling.Defaults.{ stringPickler, intPickler, refUnpickler, nullPickler } +import scala.pickling.Defaults.{ stringPickler, intPickler, refPicklerUnpickler, nullPickler } case class Pumpkin(kind: String) // Manually generate a pickler using macro diff --git a/core/src/main/scala/scala/pickling/pickler/AllPicklerUnpicklers.scala b/core/src/main/scala/scala/pickling/pickler/AllPicklerUnpicklers.scala index d85ed9f27f..3c2d4ecfa1 100644 --- a/core/src/main/scala/scala/pickling/pickler/AllPicklerUnpicklers.scala +++ b/core/src/main/scala/scala/pickling/pickler/AllPicklerUnpicklers.scala @@ -1,9 +1,9 @@ package scala.pickling package pickler -/** All pickler instances. - */ -trait AllPicklers extends PrimitivePicklers +/** All pickler instances, including the low priority implicits. */ +trait AllPicklers extends LowPriorityPicklers + with PrimitivePicklers with DatePicklers with JavaBigDecimalPicklers with JavaBigIntegerPicklers @@ -15,11 +15,8 @@ trait AllPicklers extends PrimitivePicklers with CollectionPicklers {} object AllPicklers extends AllPicklers {} -/** All picklers for collections with exception of List which is handled by macro. - * - * These need to be between the big picklers and the gen picklers. - */ -trait CollectionPicklers extends AllGenPicklers with MutableMapPicklers +/** All collection picklers except [[List]] which is handled by a macro. */ +trait CollectionPicklers extends MutableMapPicklers with ImmutableSortedMapPicklers with MapPicklers with MutableSortedSetPicklers @@ -34,9 +31,5 @@ trait CollectionPicklers extends AllGenPicklers with MutableMapPicklers with SeqPicklers with IterablePicklers {} -// Gen picklers need to be BELOW the collection implicits so that we can use the collection ones. -trait AllGenPicklers extends LowPriorityPicklers - with GenPicklersUnpicklers {} - -// We force any to be the last pickler. -trait LowPriorityPicklers extends AnyUnpicklers {} +// Force `Any` to be the last pickler to be picked in the implicit search +trait LowPriorityPicklers extends GenPicklersUnpicklers with AnyUnpicklers {} diff --git a/core/src/main/scala/scala/pickling/pickler/Array.scala b/core/src/main/scala/scala/pickling/pickler/Array.scala index 3dc384254d..bc4355d4af 100644 --- a/core/src/main/scala/scala/pickling/pickler/Array.scala +++ b/core/src/main/scala/scala/pickling/pickler/Array.scala @@ -4,7 +4,10 @@ package pickler import scala.collection.generic.CanBuildFrom trait ArrayPicklers { - implicit def arrayPickler[T >: Null: FastTypeTag](implicit elemPickler: Pickler[T], elemUnpickler: Unpickler[T], - collTag: FastTypeTag[Array[T]], cbf: CanBuildFrom[Array[T], T, Array[T]]): - Pickler[Array[T]] with Unpickler[Array[T]] = TravPickler[T, Array[T]] + implicit def arrayPickler[T >: Null : FastTypeTag]( + implicit elemPickler: Pickler[T], + elemUnpickler: Unpickler[T], + collTag: FastTypeTag[Array[T]], + cbf: CanBuildFrom[Array[T], T, Array[T]] + ): AbstractPicklerUnpickler[Array[T]] = TravPickler[T, Array[T]] } diff --git a/core/src/main/scala/scala/pickling/pickler/ArrayBuffer.scala b/core/src/main/scala/scala/pickling/pickler/ArrayBuffer.scala index 890b63f0d3..f426ebd635 100644 --- a/core/src/main/scala/scala/pickling/pickler/ArrayBuffer.scala +++ b/core/src/main/scala/scala/pickling/pickler/ArrayBuffer.scala @@ -5,9 +5,11 @@ import scala.collection.generic.CanBuildFrom import scala.collection.mutable.ArrayBuffer trait ArrayBufferPicklers { - // TODO(jsuereth) - Add pickler generator - implicit def arrayBufferPickler[T: FastTypeTag](implicit elemPickler: Pickler[T], elemUnpickler: Unpickler[T], - collTag: FastTypeTag[ArrayBuffer[T]], cbf: CanBuildFrom[ArrayBuffer[T], T, ArrayBuffer[T]]): - Pickler[ArrayBuffer[T]] with Unpickler[ArrayBuffer[T]] = - SeqSetPickler[T, ArrayBuffer] + // TODO(jvican) - Add pickler generator + implicit def arrayBufferPickler[T : FastTypeTag]( + implicit elemPickler: Pickler[T], + elemUnpickler: Unpickler[T], + collTag: FastTypeTag[ArrayBuffer[T]], + cbf: CanBuildFrom[ArrayBuffer[T], T, ArrayBuffer[T]] + ): AbstractPicklerUnpickler[ArrayBuffer[T]] = SeqSetPickler[T, ArrayBuffer] } diff --git a/core/src/main/scala/scala/pickling/pickler/Date.scala b/core/src/main/scala/scala/pickling/pickler/Date.scala index d6ed4a577e..08533db106 100644 --- a/core/src/main/scala/scala/pickling/pickler/Date.scala +++ b/core/src/main/scala/scala/pickling/pickler/Date.scala @@ -6,32 +6,36 @@ import java.text.SimpleDateFormat trait DatePicklers extends PrimitivePicklers { implicit val datePickler: Pickler[Date] with Unpickler[Date] = - new AbstractPicklerUnpickler[Date] with AutoRegister[Date] { - private val dateFormatTemplate = { - val format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") //use ISO_8601 format - format.setLenient(false) - format.setTimeZone(TimeZone.getTimeZone("UTC")) - format - } - private def dateFormat = dateFormatTemplate.clone.asInstanceOf[SimpleDateFormat] + new AbstractPicklerUnpickler[Date] with AutoRegister[Date] { + private val dateFormatTemplate = { + val format = + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") //use ISO_8601 format + format.setLenient(false) + format.setTimeZone(TimeZone.getTimeZone("UTC")) + format + } + private def dateFormat = + dateFormatTemplate.clone.asInstanceOf[SimpleDateFormat] - lazy val tag = FastTypeTag[Date]("java.util.Date") - def pickle(picklee: Date, builder: PBuilder): Unit = { - builder.beginEntry(picklee, tag) + lazy val tag = FastTypeTag[Date]("java.util.Date") + def pickle(picklee: Date, builder: PBuilder): Unit = { + builder.beginEntry(picklee, tag) - builder.putField("value", b => { - b.hintElidedType(implicitly[FastTypeTag[String]]) - stringPickler.pickle(dateFormat.format(picklee), b) - }) + builder.putField( + "value", + b => { + b.hintElidedType(implicitly[FastTypeTag[String]]) + stringPickler.pickle(dateFormat.format(picklee), b) + }) - builder.endEntry() - } - def unpickle(tag: String, reader: PReader): Any = { - val reader1 = reader.readField("value") - reader1.hintElidedType(implicitly[FastTypeTag[String]]) - val result = stringPickler.unpickleEntry(reader1) - dateFormat.parse(result.asInstanceOf[String]) + builder.endEntry() + } + def unpickle(tag: String, reader: PReader): Any = { + val reader1 = reader.readField("value") + reader1.hintElidedType(implicitly[FastTypeTag[String]]) + val result = stringPickler.unpickleEntry(reader1) + dateFormat.parse(result.asInstanceOf[String]) + } } - } internal.currentRuntime.picklers.registerPicklerUnpickler(datePickler) } diff --git a/core/src/main/scala/scala/pickling/pickler/GenPicklersUnpicklers.scala b/core/src/main/scala/scala/pickling/pickler/GenPicklersUnpicklers.scala index d0edb85d76..e70d4f01bc 100644 --- a/core/src/main/scala/scala/pickling/pickler/GenPicklersUnpicklers.scala +++ b/core/src/main/scala/scala/pickling/pickler/GenPicklersUnpicklers.scala @@ -8,14 +8,14 @@ import scala.language.experimental.macros */ trait GenPicklersUnpicklers { - def genPickler[T]: AbstractPicklerUnpickler[T] = + implicit def genPickler[T]: AbstractPicklerUnpickler[T] = macro generator.Compat.genPicklerUnpickler_impl[T] def genUnpickler[T]: AbstractPicklerUnpickler[T] with Generated = macro generator.Compat.genPicklerUnpickler_impl[T] // The only implicit definition, otherwise there's a clash - implicit def genPicklerUnpickler[T]: AbstractPicklerUnpickler[T] with Generated = + def genPicklerUnpickler[T]: AbstractPicklerUnpickler[T] with Generated = macro generator.Compat.genPicklerUnpickler_impl[T] } diff --git a/core/src/main/scala/scala/pickling/pickler/GeneratorRegistry.scala b/core/src/main/scala/scala/pickling/pickler/GeneratorRegistry.scala index 1ca1e9ee59..a19824f38f 100644 --- a/core/src/main/scala/scala/pickling/pickler/GeneratorRegistry.scala +++ b/core/src/main/scala/scala/pickling/pickler/GeneratorRegistry.scala @@ -49,7 +49,6 @@ trait GeneratorHelper { else query(key).getOrElse(throw error).asInstanceOf[PU[S]] } - /** Get a pickler from the registry or throw exception otherwise. */ def getPickler[T, S](tpe: FastTypeTag[T], fullTpe: FastTypeTag[S]) = get[Pickler, T](currentRuntime.picklers.lookupPickler, tpe.key, @@ -73,13 +72,30 @@ trait GeneratorHelper { def specialize[T](tag: FastTypeTag[_]): FastTypeTag[T] = tag.asInstanceOf[FastTypeTag[T]] + /** Extract one type parameter from a type constructor and + * cast them to a concrete type [[T]]. + * + * @tparam T Type we want to convert to + * + * @return A tag holding information about [[T]] + */ + def oneArgumentTagExtractor[T](tpe: FastTypeTag[_]): FastTypeTag[T] = { + val typeArgs = tpe.typeArgs + typeArgs match { + case List(one) => one.asInstanceOf[FastTypeTag[T]] + // TODO: Remove this hack to handle `Nil.type` as a tag + case List() => FastTypeTag.Any.asInstanceOf[FastTypeTag[T]] + case x => throw TypeMismatch(List(tpe), typeArgs) + } + } + /** Extract two type parameters from a type constructor and * cast them to some concrete types [[T]] and [[S]]. * * @tparam T First type we want to convert to * @tparam S Second type we want to convert to * - * @return A tuple of tags of (T, S) + * @return A tuple of tags of ([[T]], [[S]]) */ def twoArgumentTagExtractor[T, S](tpe: FastTypeTag[_]): (FastTypeTag[T], FastTypeTag[S]) = { val typeArgs = tpe.typeArgs diff --git a/core/src/main/scala/scala/pickling/pickler/Iterable.scala b/core/src/main/scala/scala/pickling/pickler/Iterable.scala index 051ad02706..0ab1903f08 100644 --- a/core/src/main/scala/scala/pickling/pickler/Iterable.scala +++ b/core/src/main/scala/scala/pickling/pickler/Iterable.scala @@ -1,82 +1,70 @@ package scala.pickling package pickler -import scala.pickling.PicklingErrors.TypeMismatch import scala.collection.generic.CanBuildFrom import scala.language.higherKinds import scala.pickling.spi.PicklerRegistry.PicklerUnpicklerGen trait IterablePicklers extends GeneratorRegistry { - implicit def iterablePickler[T: FastTypeTag] - (implicit elemPickler: Pickler[T], elemUnpickler: Unpickler[T], - collTag: FastTypeTag[Iterable[T]], - cbf: CanBuildFrom[Iterable[T], T, Iterable[T]] - ): Pickler[Iterable[T]] with Unpickler[Iterable[T]] = TravPickler[T, Iterable[T]] + implicit def iterablePickler[T : FastTypeTag]( + implicit elemPickler: Pickler[T], + elemUnpickler: Unpickler[T], + collTag: FastTypeTag[Iterable[T]], + cbf: CanBuildFrom[Iterable[T], T, Iterable[T]] + ): AbstractPicklerUnpickler[Iterable[T]] = TravPickler[T, Iterable[T]] - implicit def listPickler[T: FastTypeTag] - (implicit elemPickler: Pickler[T], elemUnpickler: Unpickler[T], - colTag: FastTypeTag[List[T]], - cbf: CanBuildFrom[List[T], T, List[T]] - ): Pickler[List[T]] with Unpickler[List[T]] = TravPickler[T, List[T]] + implicit def listPickler[T : FastTypeTag]( + implicit elemPickler: Pickler[T], + elemUnpickler: Unpickler[T], + colTag: FastTypeTag[List[T]], + cbf: CanBuildFrom[List[T], T, List[T]] + ): AbstractPicklerUnpickler[List[T]] = TravPickler[T, List[T]] locally { val cbf = implicitly[CanBuildFrom[List[Any], Any, List[Any]]] - val generator: PicklerUnpicklerGen[List[Any]] = + val generator: PicklerUnpicklerGen[List[Any]] = { TravPickler.generate(cbf, identity[List[Any]]) { tpe => TravPickler.oneArgumentTagExtractor(tpe) } + } // TODO: Deserialize directly Nil and remove this hack. registerGen("scala.collection.immutable.Nil.type", generator) registerGen("scala.collection.immutable.$colon$colon", generator) registerGen("scala.collection.immutable.List", generator) - } locally { val cbf = implicitly[CanBuildFrom[Iterable[Any], Any, Iterable[Any]]] - val generator: PicklerUnpicklerGen[Iterable[Any]] = + val generator: PicklerUnpicklerGen[Iterable[Any]] = { TravPickler.generate(cbf, identity[Iterable[Any]]) { tpe => TravPickler.oneArgumentTagExtractor(tpe) } + } registerGen("scala.collection.Iterable", generator) - } - } object TravPickler extends GeneratorHelper { - private val ANY_TAG = FastTypeTag.Any - - def oneArgumentTagExtractor[T](tpe: FastTypeTag[_]): FastTypeTag[T] = { - val typeArgs = tpe.typeArgs - typeArgs match { - case List(one) => one.asInstanceOf[FastTypeTag[T]] - // TODO: Remove this hack to handle `Nil.type` as a tag - case List() => ANY_TAG.asInstanceOf[FastTypeTag[T]] - case x => throw TypeMismatch(List(tpe), typeArgs) - } - } - /** Creates a pickling generator for any [[Traversable]] to be used at runtime. */ - def generate[T, C](cbf: CanBuildFrom[C,T,C], asTrav: C => Traversable[_]) - (elementTagExtractor: FastTypeTagSpecializer[T]) - (tpe: FastTypeTag[_]): AbstractPicklerUnpickler[C] = { + def generate[T, C](cbf: CanBuildFrom[C, T, C], asTrav: C => Traversable[_])( + elementTagExtractor: FastTypeTagSpecializer[T])( + tpe: FastTypeTag[_]): AbstractPicklerUnpickler[C] = { val (elemPickler, elemUnpickler) = generateHelper(elementTagExtractor)(tpe) - apply[T,C](asTrav, elemPickler, elemUnpickler, cbf, specialize[C](tpe)) - + apply[T, C](asTrav, elemPickler, elemUnpickler, cbf, specialize[C](tpe)) } - - def apply[T, C](implicit asTrav: C => Traversable[_], elemPickler: Pickler[T], - elemUnpickler: Unpickler[T], cbf: CanBuildFrom[C, T, C], - collTag: FastTypeTag[C]): AbstractPicklerUnpickler[C] = { + def apply[T, C](implicit asTrav: C => Traversable[_], + elemPickler: Pickler[T], + elemUnpickler: Unpickler[T], + cbf: CanBuildFrom[C, T, C], + collTag: FastTypeTag[C]): AbstractPicklerUnpickler[C] = { new AbstractPicklerUnpickler[C] with AutoRegister[C] { val elemTag = elemPickler.tag @@ -86,7 +74,8 @@ object TravPickler extends GeneratorHelper { def pickle(coll: C, builder: PBuilder): Unit = { // TODO Can we do the same for other type tags? - if (elemTag == FastTypeTag.Int) builder.hintKnownSize(coll.size * 4 + 100) + if (elemTag == FastTypeTag.Int) + builder.hintKnownSize(coll.size * 4 + 100) builder.beginEntry(coll, tag) builder.beginCollection(coll.size) @@ -96,10 +85,11 @@ object TravPickler extends GeneratorHelper { builder.pinHints() } - (coll: Traversable[_]).asInstanceOf[Traversable[T]].foreach { (elem: T) => - builder putElement { b => - elemPickler.pickle(elem, b) - } + (coll: Traversable[_]).asInstanceOf[Traversable[T]].foreach { + (elem: T) => + builder putElement { b => + elemPickler.pickle(elem, b) + } } builder.popHints() @@ -135,17 +125,19 @@ object TravPickler extends GeneratorHelper { } object SeqSetPickler { - def apply[T: FastTypeTag, Coll[_] <: Traversable[_]] - (implicit elemPickler: Pickler[T], elemUnpickler: Unpickler[T], - cbf: CanBuildFrom[Coll[T], T, Coll[T]], - collTag: FastTypeTag[Coll[T]]): Pickler[Coll[T]] with Unpickler[Coll[T]] = - TravPickler[T, Coll[T]] + def apply[T : FastTypeTag, Coll[_] <: Traversable[_]]( + implicit elemPickler: Pickler[T], + elemUnpickler: Unpickler[T], + cbf: CanBuildFrom[Coll[T], T, Coll[T]], + collTag: FastTypeTag[Coll[T]] + ): AbstractPicklerUnpickler[Coll[T]] = TravPickler[T, Coll[T]] } object MapPickler { - def apply[K: FastTypeTag, V: FastTypeTag, M[_, _] <: collection.Map[_, _]] - (implicit elemPickler: Pickler[(K, V)], elemUnpickler: Unpickler[(K, V)], - cbf: CanBuildFrom[M[K, V], (K, V), M[K, V]], - collTag: FastTypeTag[M[K, V]]): Pickler[M[K, V]] with Unpickler[M[K, V]] = - TravPickler[(K, V), M[K, V]] + def apply[K : FastTypeTag, V : FastTypeTag, M[_, _] <: collection.Map[_, _]]( + implicit elemPickler: Pickler[(K, V)], + elemUnpickler: Unpickler[(K, V)], + cbf: CanBuildFrom[M[K, V], (K, V), M[K, V]], + collTag: FastTypeTag[M[K, V]] + ): AbstractPicklerUnpickler[M[K, V]] = TravPickler[(K, V), M[K, V]] } diff --git a/core/src/main/scala/scala/pickling/pickler/JavaBigDecimal.scala b/core/src/main/scala/scala/pickling/pickler/JavaBigDecimal.scala index 1abf15a407..d193b9dadf 100644 --- a/core/src/main/scala/scala/pickling/pickler/JavaBigDecimal.scala +++ b/core/src/main/scala/scala/pickling/pickler/JavaBigDecimal.scala @@ -7,9 +7,11 @@ import java.math.BigDecimal * Note; This currently serialzies as a string. */ trait JavaBigDecimalPicklers extends PrimitivePicklers { - implicit val javaBigDecimalPickler: Pickler[BigDecimal] with Unpickler[BigDecimal] = + + implicit val javaBigDecimalPickler: AbstractPicklerUnpickler[BigDecimal] = { new AbstractPicklerUnpickler[BigDecimal] with AutoRegister[BigDecimal] { lazy val tag = FastTypeTag[BigDecimal]("java.math.BigDecimal") + def pickle(picklee: BigDecimal, builder: PBuilder): Unit = { builder.beginEntry(picklee, tag) builder.putField("value", b => { @@ -18,6 +20,7 @@ trait JavaBigDecimalPicklers extends PrimitivePicklers { }) builder.endEntry() } + def unpickle(tag: String, reader: PReader): Any = { val reader1 = reader.readField("value") reader1.hintElidedType(implicitly[FastTypeTag[String]]) @@ -25,5 +28,6 @@ trait JavaBigDecimalPicklers extends PrimitivePicklers { new BigDecimal(result.asInstanceOf[String]) } } - internal.currentRuntime.picklers.registerPicklerUnpickler(javaBigDecimalPickler) + } + } diff --git a/core/src/main/scala/scala/pickling/pickler/JavaBigInteger.scala b/core/src/main/scala/scala/pickling/pickler/JavaBigInteger.scala index 0706ad3035..b1f06818c0 100644 --- a/core/src/main/scala/scala/pickling/pickler/JavaBigInteger.scala +++ b/core/src/main/scala/scala/pickling/pickler/JavaBigInteger.scala @@ -6,9 +6,11 @@ import java.math.BigInteger /** This contains implicits which can serialize java.math.BigInteger values. */ trait JavaBigIntegerPicklers extends PrimitivePicklers { - implicit val javaBigIntegerPickler: Pickler[BigInteger] with Unpickler[BigInteger] = + + implicit val javaBigIntegerPickler: AbstractPicklerUnpickler[BigInteger] = { new AbstractPicklerUnpickler[BigInteger] with AutoRegister[BigInteger] { lazy val tag = FastTypeTag[BigInteger]("java.math.BigInteger") + def pickle(picklee: BigInteger, builder: PBuilder): Unit = { builder.beginEntry(picklee, tag) @@ -19,6 +21,7 @@ trait JavaBigIntegerPicklers extends PrimitivePicklers { builder.endEntry() } + def unpickle(tag: String, reader: PReader): Any = { val reader1 = reader.readField("value") reader1.hintElidedType(FastTypeTag.String) @@ -26,5 +29,6 @@ trait JavaBigIntegerPicklers extends PrimitivePicklers { new BigInteger(result.asInstanceOf[String]) } } - internal.currentRuntime.picklers.registerPicklerUnpickler(javaBigIntegerPickler) + } + } diff --git a/core/src/main/scala/scala/pickling/pickler/JavaUUIDPickler.scala b/core/src/main/scala/scala/pickling/pickler/JavaUUIDPickler.scala index e400373eb9..ecc9df298b 100644 --- a/core/src/main/scala/scala/pickling/pickler/JavaUUIDPickler.scala +++ b/core/src/main/scala/scala/pickling/pickler/JavaUUIDPickler.scala @@ -5,10 +5,11 @@ import java.util.UUID trait JavaUUIDPicklers extends PrimitivePicklers { - implicit val javaUUIDPickler: Pickler[UUID] with Unpickler[UUID] = + implicit val javaUUIDPickler: AbstractPicklerUnpickler[UUID] = { new AbstractPicklerUnpickler[UUID] with AutoRegister[UUID] { lazy val tag = FastTypeTag[UUID]("java.util.UUID") - def pickle(picklee: java.util.UUID, builder: PBuilder):Unit = { + + def pickle(picklee: java.util.UUID, builder: PBuilder): Unit = { builder.beginEntry(picklee, tag) builder.putField("msb", { b => @@ -37,5 +38,6 @@ trait JavaUUIDPicklers extends PrimitivePicklers { new java.util.UUID(msb, lsb) } } - internal.currentRuntime.picklers.registerPicklerUnpickler(javaUUIDPickler) + } + } diff --git a/core/src/main/scala/scala/pickling/pickler/Map.scala b/core/src/main/scala/scala/pickling/pickler/Map.scala index c07d5f2f04..17c3724420 100644 --- a/core/src/main/scala/scala/pickling/pickler/Map.scala +++ b/core/src/main/scala/scala/pickling/pickler/Map.scala @@ -2,27 +2,35 @@ package scala.pickling package pickler import scala.collection.generic.CanBuildFrom -import scala.collection.{ immutable, mutable } +import scala.collection.{immutable, mutable} import scala.pickling.PicklingErrors.TypeMismatch import scala.pickling.spi.PicklerRegistry.PicklerUnpicklerGen object MapPicklerHelper { - def tupleTagExtractor[T,U](tpe: FastTypeTag[_]): FastTypeTag[(T, U)] = + def tupleTagExtractor[T, U](tpe: FastTypeTag[_]): FastTypeTag[(T, U)] = tpe.typeArgs match { case List(one, two) => tpe.asInstanceOf[FastTypeTag[(T, U)]] // Note: This is what we do to handle empty map types when singleton types are used. - case List() => FastTypeTag.apply("scala.Tuple2").asInstanceOf[FastTypeTag[(T,U)]] + case List() => + FastTypeTag.apply("scala.Tuple2").asInstanceOf[FastTypeTag[(T, U)]] case x => throw TypeMismatch(List(tpe), x) } } trait MapPicklers extends GeneratorRegistry { - implicit def mapPickler[K: FastTypeTag, V: FastTypeTag](implicit elemPickler: Pickler[(K, V)], elemUnpickler: Unpickler[(K, V)], pairTag: FastTypeTag[(K, V)], collTag: FastTypeTag[Map[K, V]], cbf: CanBuildFrom[Map[K, V], (K, V), Map[K, V]]): Pickler[Map[K, V]] with Unpickler[Map[K, V]] = - MapPickler[K, V, Map] + + implicit def mapPickler[K : FastTypeTag, V : FastTypeTag]( + implicit elemPickler: Pickler[(K, V)], + elemUnpickler: Unpickler[(K, V)], + pairTag: FastTypeTag[(K, V)], + collTag: FastTypeTag[Map[K, V]], + cbf: CanBuildFrom[Map[K, V], (K, V), Map[K, V]] + ): AbstractPicklerUnpickler[Map[K, V]] = MapPickler[K, V, Map] locally { - val cbf = implicitly[CanBuildFrom[Map[Any, Any], (Any, Any), Map[Any, Any]]] + val cbf = + implicitly[CanBuildFrom[Map[Any, Any], (Any, Any), Map[Any, Any]]] val generator: PicklerUnpicklerGen[Map[Any, Any]] = TravPickler.generate(cbf, identity[Map[Any, Any]]) { tpe => MapPicklerHelper.tupleTagExtractor(tpe) @@ -34,43 +42,45 @@ trait MapPicklers extends GeneratorRegistry { registerGen("scala.collection.immutable.Map.Map3", generator) registerGen("scala.collection.immutable.Map.Map4", generator) registerGen("scala.collection.immutable.HashMap.HashTrieMap", generator) - } } trait ImmutableSortedMapPicklers { - implicit def immutableSortedMapPickler[K: FastTypeTag, V: FastTypeTag] - (implicit elemPickler: Pickler[(K, V)], elemUnpickler: Unpickler[(K, V)], - pairTag: FastTypeTag[(K, V)], collTag: FastTypeTag[immutable.SortedMap[K, V]], - cbf: CanBuildFrom[immutable.SortedMap[K, V], (K, V), immutable.SortedMap[K, V]] - ): Pickler[immutable.SortedMap[K, V]] with Unpickler[immutable.SortedMap[K, V]] = - MapPickler[K, V, immutable.SortedMap] + implicit def immutableSortedMapPickler[K : FastTypeTag, V : FastTypeTag]( + implicit elemPickler: Pickler[(K, V)], + elemUnpickler: Unpickler[(K, V)], + pairTag: FastTypeTag[(K, V)], + collTag: FastTypeTag[immutable.SortedMap[K, V]], + cbf: CanBuildFrom[ + immutable.SortedMap[K, V], (K, V), immutable.SortedMap[K, V]] + ): AbstractPicklerUnpickler[immutable.SortedMap[K, V]] = + MapPickler[K, V, immutable.SortedMap] // TODO - SortedMap runtime generation involves using a specialized pickler that can remember the ordering of elements. Currently our pickler does not do that. - } trait MutableMapPicklers extends GeneratorRegistry { import mutable.{Map => Mmap} - implicit def mutableMapPickler[K: FastTypeTag, V: FastTypeTag] - (implicit elemPickler: Pickler[(K, V)], elemUnpickler: Unpickler[(K, V)], - pairTag: FastTypeTag[(K, V)], collTag: FastTypeTag[Mmap[K, V]], - cbf: CanBuildFrom[Mmap[K, V], (K, V), Mmap[K, V]] - ): Pickler[Mmap[K, V]] with Unpickler[Mmap[K, V]] = - MapPickler[K, V, Mmap] + implicit def mutableMapPickler[K : FastTypeTag, V : FastTypeTag]( + implicit elemPickler: Pickler[(K, V)], + elemUnpickler: Unpickler[(K, V)], + pairTag: FastTypeTag[(K, V)], + collTag: FastTypeTag[Mmap[K, V]], + cbf: CanBuildFrom[Mmap[K, V], (K, V), Mmap[K, V]] + ): AbstractPicklerUnpickler[Mmap[K, V]] = MapPickler[K, V, Mmap] locally { - val cbf = implicitly[CanBuildFrom[Mmap[Any, Any], (Any, Any), Mmap[Any,Any]]] + val cbf = + implicitly[CanBuildFrom[Mmap[Any, Any], (Any, Any), Mmap[Any, Any]]] val generator: PicklerUnpicklerGen[Mmap[Any, Any]] = TravPickler.generate(cbf, identity[Mmap[Any, Any]]) { tpe => MapPicklerHelper.tupleTagExtractor(tpe) } registerGen("scala.collection.mutable.Map", generator) - } } diff --git a/core/src/main/scala/scala/pickling/pickler/PrimitiveArrays.scala b/core/src/main/scala/scala/pickling/pickler/PrimitiveArrays.scala index bb5bf761f0..7d66e63479 100644 --- a/core/src/main/scala/scala/pickling/pickler/PrimitiveArrays.scala +++ b/core/src/main/scala/scala/pickling/pickler/PrimitiveArrays.scala @@ -4,12 +4,12 @@ package pickler /** Picklers for primitive arrays. */ trait PrimitiveArrayPicklers { - implicit val byteArrayPickler: Pickler[Array[Byte]] with Unpickler[Array[Byte]] = PrimitivePickler[Array[Byte]] - implicit val shortArrayPickler: Pickler[Array[Short]] with Unpickler[Array[Short]] = PrimitivePickler[Array[Short]] - implicit val charArrayPickler: Pickler[Array[Char]] with Unpickler[Array[Char]] = PrimitivePickler[Array[Char]] - implicit val intArrayPickler: Pickler[Array[Int]] with Unpickler[Array[Int]] = PrimitivePickler[Array[Int]] - implicit val longArrayPickler: Pickler[Array[Long]] with Unpickler[Array[Long]] = PrimitivePickler[Array[Long]] - implicit val booleanArrayPickler: Pickler[Array[Boolean]] with Unpickler[Array[Boolean]] = PrimitivePickler[Array[Boolean]] - implicit val floatArrayPickler: Pickler[Array[Float]] with Unpickler[Array[Float]] = PrimitivePickler[Array[Float]] - implicit val doubleArrayPickler: Pickler[Array[Double]] with Unpickler[Array[Double]] = PrimitivePickler[Array[Double]] + implicit val byteArrayPickler: AbstractPicklerUnpickler[Array[Byte]] = PrimitivePickler[Array[Byte]] + implicit val shortArrayPickler: AbstractPicklerUnpickler[Array[Short]] = PrimitivePickler[Array[Short]] + implicit val charArrayPickler: AbstractPicklerUnpickler[Array[Char]] = PrimitivePickler[Array[Char]] + implicit val intArrayPickler: AbstractPicklerUnpickler[Array[Int]] = PrimitivePickler[Array[Int]] + implicit val longArrayPickler: AbstractPicklerUnpickler[Array[Long]] = PrimitivePickler[Array[Long]] + implicit val booleanArrayPickler: AbstractPicklerUnpickler[Array[Boolean]] = PrimitivePickler[Array[Boolean]] + implicit val floatArrayPickler: AbstractPicklerUnpickler[Array[Float]] = PrimitivePickler[Array[Float]] + implicit val doubleArrayPickler: AbstractPicklerUnpickler[Array[Double]] with Unpickler[Array[Double]] = PrimitivePickler[Array[Double]] } diff --git a/core/src/main/scala/scala/pickling/pickler/Primitives.scala b/core/src/main/scala/scala/pickling/pickler/Primitives.scala index 4967d0a9d1..48e9e8cb1f 100644 --- a/core/src/main/scala/scala/pickling/pickler/Primitives.scala +++ b/core/src/main/scala/scala/pickling/pickler/Primitives.scala @@ -9,17 +9,17 @@ import scala.pickling.PicklingErrors.{FailedUnpickling, BasePicklingException} * [[Boolean]], [[Float]], [[Double]], [[Null]], [[String]] and [[Unit]]. */ trait PrimitivePicklers { - implicit val bytePickler: Pickler[Byte] with Unpickler[Byte] = PrimitivePickler[Byte] - implicit val shortPickler: Pickler[Short] with Unpickler[Short] = PrimitivePickler[Short] - implicit val charPickler: Pickler[Char] with Unpickler[Char] = PrimitivePickler[Char] - implicit val intPickler: Pickler[Int] with Unpickler[Int] = PrimitivePickler[Int] - implicit val longPickler: Pickler[Long] with Unpickler[Long] = PrimitivePickler[Long] - implicit val booleanPickler: Pickler[Boolean] with Unpickler[Boolean] = PrimitivePickler[Boolean] - implicit val floatPickler: Pickler[Float] with Unpickler[Float] = PrimitivePickler[Float] - implicit val doublePickler: Pickler[Double] with Unpickler[Double] = PrimitivePickler[Double] - implicit val nullPickler: Pickler[Null] with Unpickler[Null] = PrimitivePickler[Null] - implicit val stringPickler: Pickler[String] with Unpickler[String] = PrimitivePickler[String] - implicit val unitPickler: Pickler[Unit] with Unpickler[Unit] = PrimitivePickler[Unit] + implicit val bytePickler: AbstractPicklerUnpickler[Byte] = PrimitivePickler[Byte] + implicit val shortPickler: AbstractPicklerUnpickler[Short] = PrimitivePickler[Short] + implicit val charPickler: AbstractPicklerUnpickler[Char] = PrimitivePickler[Char] + implicit val intPickler: AbstractPicklerUnpickler[Int] = PrimitivePickler[Int] + implicit val longPickler: AbstractPicklerUnpickler[Long] = PrimitivePickler[Long] + implicit val booleanPickler: AbstractPicklerUnpickler[Boolean] = PrimitivePickler[Boolean] + implicit val floatPickler: AbstractPicklerUnpickler[Float] = PrimitivePickler[Float] + implicit val doublePickler: AbstractPicklerUnpickler[Double] = PrimitivePickler[Double] + implicit val nullPickler: AbstractPicklerUnpickler[Null] = PrimitivePickler[Null] + implicit val stringPickler: AbstractPicklerUnpickler[String] = PrimitivePickler[String] + implicit val unitPickler: AbstractPicklerUnpickler[Unit] = PrimitivePickler[Unit] } class PrimitivePickler[T: FastTypeTag](name: String) @@ -43,6 +43,6 @@ class PrimitivePickler[T: FastTypeTag](name: String) } } object PrimitivePickler { - def apply[A: FastTypeTag]: Pickler[A] with Unpickler[A] = + def apply[A: FastTypeTag]: AbstractPicklerUnpickler[A] = new PrimitivePickler[A](FastTypeTag.valueTypeName(implicitly[FastTypeTag[A]])) } diff --git a/core/src/main/scala/scala/pickling/pickler/Ref.scala b/core/src/main/scala/scala/pickling/pickler/Ref.scala index b0414da87d..a9554fe043 100644 --- a/core/src/main/scala/scala/pickling/pickler/Ref.scala +++ b/core/src/main/scala/scala/pickling/pickler/Ref.scala @@ -1,9 +1,25 @@ package scala.pickling package pickler +import scala.pickling.PicklingErrors.LogicPicklingError + @deprecated("Sharing is not guaranteed to be safe w/ all possible picklers.") trait RefPicklers { + + @deprecated("Sharing is not guaranteed to be safe w/ all possible picklers.") + implicit val refPicklerUnpickler: AbstractPicklerUnpickler[refs.Ref] = { + val name = FastTypeTag.valueTypeName(implicitly[FastTypeTag[refs.Ref]]) + new PrimitivePickler[refs.Ref](name) { + final override def pickle(picklee: refs.Ref, builder: PBuilder): Unit = { + throw LogicPicklingError("`Ref`s cannot be pickled, only unpickled.") + } + } + } + @deprecated("Sharing is not guaranteed to be safe w/ all possible picklers.") - implicit def refPickler: Pickler[refs.Ref] = throw new Error("cannot pickle refs") - implicit val refUnpickler: Unpickler[refs.Ref] = PrimitivePickler[refs.Ref] + val refPickler: Pickler[refs.Ref] = refPicklerUnpickler + + @deprecated("Use `refPicklerUnpickler` instead, this one is not implicit anymore", "0.11.0") + val refUnpickler: Unpickler[refs.Ref] = refPicklerUnpickler + } diff --git a/core/src/main/scala/scala/pickling/pickler/Seq.scala b/core/src/main/scala/scala/pickling/pickler/Seq.scala index 3728fafc23..a8b981854f 100644 --- a/core/src/main/scala/scala/pickling/pickler/Seq.scala +++ b/core/src/main/scala/scala/pickling/pickler/Seq.scala @@ -2,26 +2,33 @@ package scala.pickling package pickler import scala.collection.generic.CanBuildFrom -import scala.collection.{ IndexedSeq, LinearSeq } +import scala.collection.{IndexedSeq, LinearSeq} -// TODO(jsuereth) - Register runtime pickler generators +// TODO(jvican) - Register runtime pickler generators trait SeqPicklers { - implicit def seqPickler[T: FastTypeTag](implicit elemPickler: Pickler[T], elemUnpickler: Unpickler[T], - collTag: FastTypeTag[Seq[T]], cbf: CanBuildFrom[Seq[T], T, Seq[T]]): Pickler[Seq[T]] with Unpickler[Seq[T]] = - SeqSetPickler[T, Seq] + implicit def seqPickler[T : FastTypeTag]( + implicit elemPickler: Pickler[T], + elemUnpickler: Unpickler[T], + collTag: FastTypeTag[Seq[T]], + cbf: CanBuildFrom[Seq[T], T, Seq[T]] + ): AbstractPicklerUnpickler[Seq[T]] = SeqSetPickler[T, Seq] } trait IndexedSeqPicklers { - implicit def indexedSeqPickler[T: FastTypeTag](implicit elemPickler: Pickler[T], elemUnpickler: Unpickler[T], - collTag: FastTypeTag[IndexedSeq[T]], cbf: CanBuildFrom[IndexedSeq[T], T, IndexedSeq[T]]): - Pickler[IndexedSeq[T]] with Unpickler[IndexedSeq[T]] = - SeqSetPickler[T, IndexedSeq] + implicit def indexedSeqPickler[T : FastTypeTag]( + implicit elemPickler: Pickler[T], + elemUnpickler: Unpickler[T], + collTag: FastTypeTag[IndexedSeq[T]], + cbf: CanBuildFrom[IndexedSeq[T], T, IndexedSeq[T]] + ): AbstractPicklerUnpickler[IndexedSeq[T]] = SeqSetPickler[T, IndexedSeq] } trait LinearSeqPicklers { - implicit def linearSeqPickler[T: FastTypeTag](implicit elemPickler: Pickler[T], elemUnpickler: Unpickler[T], - collTag: FastTypeTag[LinearSeq[T]], cbf: CanBuildFrom[LinearSeq[T], T, LinearSeq[T]]): - Pickler[LinearSeq[T]] with Unpickler[LinearSeq[T]] = - SeqSetPickler[T, LinearSeq] + implicit def linearSeqPickler[T : FastTypeTag]( + implicit elemPickler: Pickler[T], + elemUnpickler: Unpickler[T], + collTag: FastTypeTag[LinearSeq[T]], + cbf: CanBuildFrom[LinearSeq[T], T, LinearSeq[T]] + ): AbstractPicklerUnpickler[LinearSeq[T]] = SeqSetPickler[T, LinearSeq] } diff --git a/core/src/main/scala/scala/pickling/pickler/Set.scala b/core/src/main/scala/scala/pickling/pickler/Set.scala index 6246facccd..81ce14b484 100644 --- a/core/src/main/scala/scala/pickling/pickler/Set.scala +++ b/core/src/main/scala/scala/pickling/pickler/Set.scala @@ -2,33 +2,45 @@ package scala.pickling package pickler import scala.collection.generic.CanBuildFrom -import scala.collection.{ immutable, mutable } +import scala.collection.{immutable, mutable} -// TODO(jsuereth) - Register runtime pickler generators +// TODO(jvican) - Register runtime pickler generators trait SetPicklers { - implicit def setPickler[T: FastTypeTag](implicit elemPickler: Pickler[T], elemUnpickler: Unpickler[T], - collTag: FastTypeTag[Set[T]], cbf: CanBuildFrom[Set[T], T, Set[T]]): Pickler[Set[T]] with Unpickler[Set[T]] = - SeqSetPickler[T, Set] + implicit def setPickler[T : FastTypeTag]( + implicit elemPickler: Pickler[T], + elemUnpickler: Unpickler[T], + collTag: FastTypeTag[Set[T]], + cbf: CanBuildFrom[Set[T], T, Set[T]] + ): AbstractPicklerUnpickler[Set[T]] = SeqSetPickler[T, Set] } trait ImmutableSortedSetPicklers { - implicit def immutableSortedSetPickler[T: FastTypeTag](implicit elemPickler: Pickler[T], elemUnpickler: Unpickler[T], - collTag: FastTypeTag[immutable.SortedSet[T]], cbf: CanBuildFrom[immutable.SortedSet[T], T, immutable.SortedSet[T]]): - Pickler[immutable.SortedSet[T]] with Unpickler[immutable.SortedSet[T]] = + implicit def immutableSortedSetPickler[T : FastTypeTag]( + implicit elemPickler: Pickler[T], + elemUnpickler: Unpickler[T], + collTag: FastTypeTag[immutable.SortedSet[T]], + cbf: CanBuildFrom[immutable.SortedSet[T], T, immutable.SortedSet[T]] + ): AbstractPicklerUnpickler[immutable.SortedSet[T]] = SeqSetPickler[T, immutable.SortedSet] } trait MutableSetPicklers { - implicit def mutableSetPickler[T: FastTypeTag](implicit elemPickler: Pickler[T], elemUnpickler: Unpickler[T], - collTag: FastTypeTag[mutable.Set[T]], cbf: CanBuildFrom[mutable.Set[T], T, mutable.Set[T]]): - Pickler[mutable.Set[T]] with Unpickler[mutable.Set[T]] = + implicit def mutableSetPickler[T : FastTypeTag]( + implicit elemPickler: Pickler[T], + elemUnpickler: Unpickler[T], + collTag: FastTypeTag[mutable.Set[T]], + cbf: CanBuildFrom[mutable.Set[T], T, mutable.Set[T]] + ): AbstractPicklerUnpickler[mutable.Set[T]] = SeqSetPickler[T, mutable.Set] } trait MutableSortedSetPicklers { - implicit def mutableSortedSetPickler[T: FastTypeTag](implicit elemPickler: Pickler[T], elemUnpickler: Unpickler[T], - collTag: FastTypeTag[mutable.SortedSet[T]], cbf: CanBuildFrom[mutable.SortedSet[T], T, mutable.SortedSet[T]]): - Pickler[mutable.SortedSet[T]] with Unpickler[mutable.SortedSet[T]] = + implicit def mutableSortedSetPickler[T : FastTypeTag]( + implicit elemPickler: Pickler[T], + elemUnpickler: Unpickler[T], + collTag: FastTypeTag[mutable.SortedSet[T]], + cbf: CanBuildFrom[mutable.SortedSet[T], T, mutable.SortedSet[T]] + ): AbstractPicklerUnpickler[mutable.SortedSet[T]] = SeqSetPickler[T, mutable.SortedSet] } diff --git a/core/src/main/scala/scala/pickling/pickler/TypeTags.scala b/core/src/main/scala/scala/pickling/pickler/TypeTags.scala index f277bddd27..c5ceb115ae 100644 --- a/core/src/main/scala/scala/pickling/pickler/TypeTags.scala +++ b/core/src/main/scala/scala/pickling/pickler/TypeTags.scala @@ -2,15 +2,18 @@ package scala.pickling package pickler /** - * Pickler implicits for type tags. - */ -trait TypeTagPicklers extends PrimitivePicklers with GeneratorRegistry { - implicit def typeTagPickler[T]: AbstractPicklerUnpickler[FastTypeTag[T]] = - FastTypeTagPicklerUnpickler.asInstanceOf[AbstractPicklerUnpickler[FastTypeTag[T]]] + * Pickler implicits for type tags. + */ +trait TypeTagPicklers extends GeneratorRegistry { + this: PrimitivePicklers => + implicit def typeTagPickler[T]: AbstractPicklerUnpickler[FastTypeTag[T]] = + FastTypeTagPicklerUnpickler + .asInstanceOf[AbstractPicklerUnpickler[FastTypeTag[T]]] private[pickler] object FastTypeTagPicklerUnpickler - extends AbstractPicklerUnpickler[FastTypeTag[_]] with AutoRegister[FastTypeTag[_]] { + extends AbstractPicklerUnpickler[FastTypeTag[_]] + with AutoRegister[FastTypeTag[_]] { override def pickle(picklee: FastTypeTag[_], builder: PBuilder): Unit = { builder.beginEntry(picklee, tag) builder.putField("key", { b => @@ -37,15 +40,14 @@ trait TypeTagPicklers extends PrimitivePicklers with GeneratorRegistry { val key = stringPickler.unpickleEntry(rk).toString FastTypeTag.apply(key) } - override lazy val tag: FastTypeTag[FastTypeTag[_]] = FastTypeTag.apply("scala.pickling.pickler.FastTypeTag").asInstanceOf[FastTypeTag[FastTypeTag[_]]] - + override lazy val tag: FastTypeTag[FastTypeTag[_]] = FastTypeTag + .apply("scala.pickling.pickler.FastTypeTag") + .asInstanceOf[FastTypeTag[FastTypeTag[_]]] } // Ensure we register for runtime deserialization. - locally{ + locally { registerGen("scala.pickling.pickler.FastTypeTag", - ignore => FastTypeTagPicklerUnpickler) + ignore => FastTypeTagPicklerUnpickler) } - } - diff --git a/core/src/main/scala/scala/pickling/pickler/Vector.scala b/core/src/main/scala/scala/pickling/pickler/Vector.scala index 32019c45fb..f8e4a8d5dd 100644 --- a/core/src/main/scala/scala/pickling/pickler/Vector.scala +++ b/core/src/main/scala/scala/pickling/pickler/Vector.scala @@ -3,11 +3,13 @@ package pickler import scala.collection.generic.CanBuildFrom -// TODO(jsuereth) - Register runtime pickler generators +// TODO(jvican) - Register runtime pickler generators trait VectorPicklers { - implicit def vectorPickler[T: FastTypeTag](implicit elemPickler: Pickler[T], - elemUnpickler: Unpickler[T], collTag: FastTypeTag[Vector[T]], cbf: CanBuildFrom[Vector[T], T, Vector[T]]): - Pickler[Vector[T]] with Unpickler[Vector[T]] = - SeqSetPickler[T, Vector] + implicit def vectorPickler[T : FastTypeTag]( + implicit elemPickler: Pickler[T], + elemUnpickler: Unpickler[T], + collTag: FastTypeTag[Vector[T]], + cbf: CanBuildFrom[Vector[T], T, Vector[T]] + ): AbstractPicklerUnpickler[Vector[T]] = SeqSetPickler[T, Vector] } diff --git a/core/src/test/scala/scala/pickling/generation/SealedTraitStaticAnnotatedTest.scala b/core/src/test/scala/scala/pickling/generation/SealedTraitStaticAnnotatedTest.scala index 2de23d4e8c..0f4c71711e 100644 --- a/core/src/test/scala/scala/pickling/generation/SealedTraitStaticAnnotatedTest.scala +++ b/core/src/test/scala/scala/pickling/generation/SealedTraitStaticAnnotatedTest.scala @@ -3,7 +3,7 @@ package scala.pickling.test.sealedtraitstaticannotated import scala.pickling._ import scala.pickling.static._ import scala.pickling.json._ -import Defaults.{ stringPickler, intPickler, refUnpickler, nullPickler } +import Defaults.{ stringPickler, intPickler, refPicklerUnpickler, nullPickler } import Defaults.{ pickleOps, unpickleOps } import org.scalatest.FunSuite diff --git a/core/src/test/scala/scala/pickling/generation/StaticOnlyWithManualPicklerTest.scala b/core/src/test/scala/scala/pickling/generation/StaticOnlyWithManualPicklerTest.scala index 46a61f2903..d3ef6a39c0 100644 --- a/core/src/test/scala/scala/pickling/generation/StaticOnlyWithManualPicklerTest.scala +++ b/core/src/test/scala/scala/pickling/generation/StaticOnlyWithManualPicklerTest.scala @@ -43,8 +43,7 @@ class StaticOnlyWithManualPicklerTest extends FunSuite { // Test that you can generate Pickler without having ops._ imported on the callsite. test ("manually generated pickler") { import scala.pickling.Defaults.intPickler - import scala.pickling.Defaults.refPickler - import scala.pickling.Defaults.refUnpickler + import scala.pickling.Defaults.refPicklerUnpickler implicit val applePickler: Pickler[Apple] = Pickler.generate[Apple] implicit val appleUnpickler: Unpickler[Apple] = Unpickler.generate[Apple] val pkl: JSONPickle = pickle(Apple(1)) @@ -56,8 +55,7 @@ class StaticOnlyWithManualPicklerTest extends FunSuite { // and unpickle test ("manually generated picklerunpickler") { import scala.pickling.Defaults.intPickler - import scala.pickling.Defaults.refPickler - import scala.pickling.Defaults.refUnpickler + import scala.pickling.Defaults.refPicklerUnpickler implicit val applePicklerUnpickler = PicklerUnpickler.generate[Apple] val pkl: JSONPickle = pickle(Apple(1)) val unpickled = unpickle[Apple](pkl) diff --git a/core/src/test/scala/scala/pickling/generation/generator/SingletonGenerator.scala b/core/src/test/scala/scala/pickling/generation/generator/SingletonGenerator.scala index 90b7dbe013..8acde428d5 100644 --- a/core/src/test/scala/scala/pickling/generation/generator/SingletonGenerator.scala +++ b/core/src/test/scala/scala/pickling/generation/generator/SingletonGenerator.scala @@ -7,15 +7,15 @@ object TopLevelObject class SingletonGeneratorTest extends FunSuite { - test("topLevelObject") { - import scala.pickling.Defaults.{refUnpickler} + import scala.pickling.Defaults.refPicklerUnpickler import scala.pickling.json._ implicit val p = PicklerUnpickler.generate[TopLevelObject.type] val x: TopLevelObject.type = TopLevelObject val pickle = scala.pickling.functions.pickle(x) val y: TopLevelObject.type = scala.pickling.functions.unpickle[TopLevelObject.type](pickle) assert(x == y) + } }