diff --git a/.travis.yml b/.travis.yml index 11e28910b3..8a54e162f8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,11 +18,10 @@ cache: language: scala scala: - - 2.11.8 - - 2.10.6 + - 2.12.2 + - 2.11.11 jdk: - - openjdk7 - - oraclejdk7 + - oraclejdk8 notifications: email: diff --git a/build.sbt b/build.sbt index bc33c746a0..c07807b6b5 100644 --- a/build.sbt +++ b/build.sbt @@ -3,7 +3,7 @@ import Dependencies._ // see project/Dependencies.scala import scala.xml.{Node => XmlNode, NodeSeq => XmlNodeSeq, _} import scala.xml.transform.{RewriteRule, RuleTransformer} -val buildVersion = "0.11.0-M2" +val buildVersion = "0.12.0" def commonSettings = Seq( version in ThisBuild := buildVersion, @@ -13,6 +13,7 @@ def commonSettings = Seq( case "2.10" => Seq("-Xmax-classfile-name", "254") case _ => Seq() }), + scalacOptions ++= Seq("-deprecation"), organization in ThisBuild := "org.scala-lang.modules", organizationName in ThisBuild := "LAMP/EPFL", organizationHomepage in ThisBuild := Some(url("http://lamp.epfl.ch")), @@ -143,7 +144,11 @@ lazy val benchmark: Project = (project in file("benchmark")). dependsOn(core). settings(commonSettings ++ noPublish ++ benchmarkSettings: _*). settings( - scalacOptions ++= Seq("-optimise"), + // -optimise is deprecated: In 2.12, + // -optimise enables -opt:l:classpath. + // Check -opt:help for using the Scala 2.12 optimizer. + //scalacOptions ++= Seq("-optimise"), + scalacOptions ++= Seq("-Xlog-implicits"), libraryDependencies ++= Seq( "org.scala-lang" % "scala-compiler" % scalaVersion.value, kryoSerializers, kryo) diff --git a/core/src/main/scala/scala/pickling/Compat.scala b/core/src/main/scala/scala/pickling/Compat.scala index faf8f46e3e..5dce17ea91 100644 --- a/core/src/main/scala/scala/pickling/Compat.scala +++ b/core/src/main/scala/scala/pickling/Compat.scala @@ -2,8 +2,7 @@ package scala.pickling import scala.language.experimental.macros import scala.language.existentials - -import scala.reflect.macros.Context +import scala.reflect.macros.whitebox.Context import scala.reflect.runtime.{universe => ru} // this is only necessary because 2.10.x doesn't support macro bundles diff --git a/core/src/main/scala/scala/pickling/Macros.scala b/core/src/main/scala/scala/pickling/Macros.scala index b645b1dd00..919b407559 100644 --- a/core/src/main/scala/scala/pickling/Macros.scala +++ b/core/src/main/scala/scala/pickling/Macros.scala @@ -50,8 +50,8 @@ trait PickleMacros extends Macro with TypeAnalysis { val tpe = weakTypeOf[T] val q"${_}($pickleeArg)" = c.prefix.tree val endPickle = if (shouldBotherAboutCleaning(tpe)) q"clearPicklees()" else q""; - val pickleeName = newTermName("picklee$pickleTo$") - val builderName = newTermName("builder$pickleTo$") + val pickleeName = TermName("picklee$pickleTo$") + val builderName = TermName("builder$pickleTo$") q""" import _root_.scala.pickling._ import _root_.scala.pickling.internal._ diff --git a/core/src/main/scala/scala/pickling/PicklingErrors.scala b/core/src/main/scala/scala/pickling/PicklingErrors.scala index cf912cc735..ab73dc706c 100644 --- a/core/src/main/scala/scala/pickling/PicklingErrors.scala +++ b/core/src/main/scala/scala/pickling/PicklingErrors.scala @@ -17,7 +17,7 @@ private[pickling] object Feedback { private[pickling] object MacrosErrors { - import scala.reflect.macros.Context + import scala.reflect.macros.whitebox.Context def failedGeneration(culprit: String)(implicit c: Context, l: AlgorithmLogger): Nothing = { l.error(s"Failed pickler/unpickler generation for $culprit") diff --git a/core/src/main/scala/scala/pickling/Tools.scala b/core/src/main/scala/scala/pickling/Tools.scala index 7239e1f316..5eaf37bfa5 100644 --- a/core/src/main/scala/scala/pickling/Tools.scala +++ b/core/src/main/scala/scala/pickling/Tools.scala @@ -4,13 +4,12 @@ import scala.pickling.internal._ import scala.language.existentials -import scala.reflect.macros.Context +import scala.reflect.macros.whitebox.Context import scala.reflect.api.Universe import scala.collection.mutable.{Map => MutableMap, ListBuffer => MutableList, WeakHashMap} import java.lang.ref.WeakReference - -import HasCompat._ +import sun.misc.Unsafe object Tools { private val subclassCaches = new WeakHashMap[AnyRef, WeakReference[AnyRef]]() @@ -33,6 +32,12 @@ object Tools { value } } + + lazy val unsafe: Unsafe = { + val ctor = classOf[Unsafe].getDeclaredConstructor() + ctor.setAccessible(true) + ctor.newInstance() + } } class Tools[C <: Context](val c: C) { @@ -47,7 +52,7 @@ class Tools[C <: Context](val c: C) { annotation }).headOption map { annotation => - annotation.javaArgs(newTermName("value")) match { + annotation.javaArgs(TermName("value")) match { case ArrayArgument(klasses) => klasses.toList map { case LiteralArgument(constant) => constant.value.asInstanceOf[Type].typeSymbol.asType @@ -76,7 +81,7 @@ class Tools[C <: Context](val c: C) { def isRelevantSubclass(baseSym: Symbol, subSym: Symbol) = { !blackList(baseSym) && !blackList(subSym) && subSym.isClass && { val subClass = subSym.asClass - subClass.baseClasses.contains(baseSym) && !subClass.isAbstractClass && !subClass.isTrait + subClass.baseClasses.contains(baseSym) && !subClass.isAbstract && !subClass.isTrait } } @@ -152,7 +157,7 @@ class Tools[C <: Context](val c: C) { val pkgMembers = pkg.typeSignature.members pkgMembers foreach (m => { def analyze(m: Symbol): Unit = { - if (m.name.decoded.contains("$")) () // SI-7251 + if (m.name.decodedName.toString.contains("$")) () // SI-7251 else if (m.isClass) m.asClass.baseClasses foreach (bc => updateCache(bc, m)) else if (m.isModule) analyze(m.asModule.moduleClass) else () @@ -193,7 +198,7 @@ class Tools[C <: Context](val c: C) { // NOTE: this is an extremely naïve heuristics // see http://groups.google.com/group/scala-internals/browse_thread/thread/3a43a6364b97b521 for more information if (tparamsMatch && targsAreConcrete) appliedType(subSym.toTypeConstructor, baseTargs) - else existentialAbstraction(subSym.typeParams, subSym.toType) + else u.internal.existentialAbstraction(subSym.typeParams, subSym.toType) }) subTpes } @@ -335,30 +340,30 @@ abstract class Macro extends RichTypes { self => } def syntheticPackageName: String = "scala.pickling.synthetic" - def syntheticBaseName(tpe: Type): TypeName = { + def syntheticBaseName(tpe: Type): String = { val raw = tpe.toString.split('.').map(_.capitalize).mkString("") - val encoded = newTypeName(raw).encoded - newTypeName(encoded) + val encoded = TypeName(raw).encodedName.toString + encoded } - def syntheticBaseQualifiedName(tpe: Type): TypeName = newTypeName(syntheticPackageName + "." + syntheticBaseName(tpe).toString) + def syntheticBaseQualifiedName(tpe: Type): String = syntheticPackageName + "." + syntheticBaseName(tpe) - def syntheticPicklerName(tpe: Type): TypeName = syntheticBaseName(tpe) + syntheticPicklerSuffix() - def syntheticPicklerQualifiedName(tpe: Type): TypeName = syntheticBaseQualifiedName(tpe) + syntheticPicklerSuffix() + def syntheticPicklerName(tpe: Type): TypeName = TypeName(syntheticBaseName(tpe) + syntheticPicklerSuffix()) + def syntheticPicklerQualifiedName(tpe: Type): TypeName = TypeName(syntheticBaseQualifiedName(tpe) + syntheticPicklerSuffix()) def syntheticPicklerSuffix(): String = "Pickler" - def syntheticUnpicklerName(tpe: Type): TypeName = syntheticBaseName(tpe) + syntheticUnpicklerSuffix() - def syntheticUnpicklerQualifiedName(tpe: Type): TypeName = syntheticBaseQualifiedName(tpe) + syntheticUnpicklerSuffix() + def syntheticUnpicklerName(tpe: Type): TypeName = TypeName(syntheticBaseName(tpe) + syntheticUnpicklerSuffix()) + def syntheticUnpicklerQualifiedName(tpe: Type): TypeName = TypeName(syntheticBaseQualifiedName(tpe) + syntheticUnpicklerSuffix()) def syntheticUnpicklerSuffix(): String = "Unpickler" - def syntheticPicklerUnpicklerName(tpe: Type): TypeName = syntheticBaseName(tpe) + syntheticPicklerUnpicklerSuffix() - def syntheticPicklerUnpicklerQualifiedName(tpe: Type): TypeName = syntheticBaseQualifiedName(tpe) + syntheticPicklerUnpicklerSuffix() + def syntheticPicklerUnpicklerName(tpe: Type): TypeName = TypeName(syntheticBaseName(tpe) + syntheticPicklerUnpicklerSuffix()) + def syntheticPicklerUnpicklerQualifiedName(tpe: Type): TypeName = TypeName(syntheticBaseQualifiedName(tpe) + syntheticPicklerUnpicklerSuffix()) def syntheticPicklerUnpicklerSuffix(): String = "PicklerUnpickler" private var reflectivePrologueEmitted = false // TODO: come up with something better - def reflectively(target: String, fir: FieldIR)(body: Tree => Tree): List[Tree] = reflectively(newTermName(target), fir)(body) + def reflectively(target: String, fir: FieldIR)(body: Tree => Tree): List[Tree] = reflectively(TermName(target), fir)(body) def reflectivelyWithoutGetter(target: String, fir: FieldIR)(body: Tree => Tree): List[Tree] = { - val pickleeName = newTermName(target) + val pickleeName = TermName(target) val getFieldValue = q""" val clazz = $pickleeName.getClass scala.util.Try(clazz.getDeclaredField(${fir.name})).map { javaField => @@ -389,8 +394,8 @@ abstract class Macro extends RichTypes { self => // val field = fir.field.get val owner = if (fir.param.nonEmpty) fir.param.get.owner else fir.accessor.get.owner - val ownerSymbol = c.fresh(newTermName(fir.name + "Owner")) - val firSymbol = c.fresh(newTermName(fir.name + "Symbol")) + val ownerSymbol = c.freshName(TermName(fir.name + "Owner")) + val firSymbol = c.freshName(TermName(fir.name + "Symbol")) // TODO: make sure this works for: // 1) private[this] fields // 2) inherited private[this] fields diff --git a/core/src/main/scala/scala/pickling/binary/Util.scala b/core/src/main/scala/scala/pickling/binary/Util.scala index b3970ae2a5..a47802c782 100644 --- a/core/src/main/scala/scala/pickling/binary/Util.scala +++ b/core/src/main/scala/scala/pickling/binary/Util.scala @@ -2,8 +2,8 @@ package scala.pickling.binary object UnsafeMemory { import sun.misc.Unsafe - private[pickling] val unsafe: Unsafe = - scala.concurrent.util.Unsafe.instance + import scala.pickling.Tools + private[pickling] val unsafe: Unsafe = Tools.unsafe private[pickling] val byteArrayOffset: Long = unsafe.arrayBaseOffset(classOf[Array[Byte]]) private[pickling] val shortArrayOffset: Long = unsafe.arrayBaseOffset(classOf[Array[Short]]) private[pickling] val intArrayOffset: Long = unsafe.arrayBaseOffset(classOf[Array[Int]]) diff --git a/core/src/main/scala/scala/pickling/generator/Compat.scala b/core/src/main/scala/scala/pickling/generator/Compat.scala index c728fa6f4d..610816a86a 100644 --- a/core/src/main/scala/scala/pickling/generator/Compat.scala +++ b/core/src/main/scala/scala/pickling/generator/Compat.scala @@ -4,8 +4,7 @@ package generator import scala.language.experimental.macros import scala.language.existentials import scala.pickling.Pickler - -import scala.reflect.macros.Context +import scala.reflect.macros.whitebox.Context import scala.reflect.runtime.{universe => ru} private[pickling] object Compat { diff --git a/core/src/main/scala/scala/pickling/generator/ScalaSymbols.scala b/core/src/main/scala/scala/pickling/generator/ScalaSymbols.scala index 47d43b5172..1acb143912 100644 --- a/core/src/main/scala/scala/pickling/generator/ScalaSymbols.scala +++ b/core/src/main/scala/scala/pickling/generator/ScalaSymbols.scala @@ -4,7 +4,7 @@ package generator import HasCompat._ import scala.reflect.api.Universe -import scala.reflect.macros.Context +import scala.reflect.macros.whitebox.Context private[pickling] class UnclosedSubclassesException(errors: Seq[String]) extends Exception(errors.mkString("\n")) { @@ -68,13 +68,13 @@ private[pickling] class IrScalaSymbols[U <: Universe with Singleton, C <: Contex override def className: String = classSymbol.fullName override def isTrait: Boolean = classSymbol.isTrait override def isAbstract: Boolean = { - classSymbol.isAbstractType - // NOte: This doesn't exist on scala 2.10 + classSymbol.isAbstract + // Note: This doesn't exist on scala 2.10 //classSymbol.isAbstract - classSymbol.isAbstractClass + classSymbol.isAbstract } override def primaryConstructor: Option[IrConstructor] = { - tpe.declaration(nme.CONSTRUCTOR) match { + tpe.decl(termNames.CONSTRUCTOR) match { // NOTE: primary ctor is always the first in the list case overloaded: TermSymbol => Some(new ScalaIrConstructor(overloaded.alternatives.head.asMethod, this)) case primaryCtor: MethodSymbol => Some(new ScalaIrConstructor(primaryCtor, this)) @@ -90,7 +90,7 @@ private[pickling] class IrScalaSymbols[U <: Universe with Singleton, C <: Contex }.toList //System.err.println(s"$tpe has constructor args:\n - ${constructorArgs.mkString("\n - ")}") // NOTE - This will only collect memeber vals/vals. It's possible some things come from the constructor. - val declaredVars = (tpe.declarations).collect { case meth: MethodSymbol => meth }.toList + val declaredVars = (tpe.decls).collect { case meth: MethodSymbol => meth }.toList // NOTE - There can be duplication between 'constructor args' and 'declared vars' we'd like to avoid. declaredVars } @@ -111,13 +111,15 @@ private[pickling] class IrScalaSymbols[U <: Universe with Singleton, C <: Contex def isConstructorArg(x: TermSymbol): Boolean = { // Note available in scala 2.10 // x.owner.isConstructor - x.owner.name == nme.CONSTRUCTOR + x.owner.name == termNames.CONSTRUCTOR } tpe.members.filter(_.isTerm).map(_.asTerm).filter(x => x.isVal || x.isVar).map(x => new ScalaIrField(x, this)).toList } override def companion: Option[IrClass] = { if(tpe.typeSymbol.isType) { - val tmp = tpe.typeSymbol.asType.companionSymbol + // method companionSymbol in trait SymbolApi is deprecated: + // Use `companion` instead, but beware of possible changes in behavior + val tmp = tpe.typeSymbol.asType.companion if(tmp.isType) { val cp = tmp.asType.toType if (cp != NoType) Some(new ScalaIrClass(cp, quantified, rawType)) @@ -173,7 +175,7 @@ private[pickling] class IrScalaSymbols[U <: Universe with Singleton, C <: Contex //System.err.println(s"baseSymTpe: ${baseSymTpe.toString}") val rawSymTpe = baseSymTpe match { case NullaryMethodType(ntpe) => ntpe; case ntpe => ntpe } - val result = existentialAbstraction(quantified, rawSymTpe) + val result = internal.existentialAbstraction(quantified, rawSymTpe) //System.err.println(s"result = ${result.toString}") result @@ -189,9 +191,9 @@ private[pickling] class IrScalaSymbols[U <: Universe with Singleton, C <: Contex override def isMarkedTransient: Boolean = { val tr = scala.util.Try { - ((field.accessed != NoSymbol) && field.accessed.annotations.exists(_.tpe =:= typeOf[scala.transient])) || - ((field.getter != NoSymbol) && field.getter.annotations.exists(_.tpe =:= typeOf[scala.transient])) || - (field.annotations.exists(_.tpe =:= typeOf[scala.transient])) + ((field.accessed != NoSymbol) && field.accessed.annotations.exists(_.tree.tpe =:= typeOf[scala.transient])) || + ((field.getter != NoSymbol) && field.getter.annotations.exists(_.tree.tpe =:= typeOf[scala.transient])) || + (field.annotations.exists(_.tree.tpe =:= typeOf[scala.transient])) } // Here we wrokaround a scala symbol issue where the field is never annotated with transient. val isSameNameAsTransientVar = owner.transientArgNames(fieldName) @@ -229,18 +231,18 @@ private[pickling] class IrScalaSymbols[U <: Universe with Singleton, C <: Contex private class ScalaIrMethod(mthd: MethodSymbol, override val owner: ScalaIrClass) extends IrMethod { import owner.fillParameters override def parameterNames: List[List[String]] = - mthd.paramss.map(_.map(_.name.toString)) + mthd.paramLists.map(_.map(_.name.toString)) override def parameterTypes[U <: Universe with Singleton](u: U): List[List[u.Type]] = { - mthd.paramss.map(_.map(x => fillParameters(x).asSeenFrom(owner.tpe, owner.tpe.typeSymbol)).map(_.asInstanceOf[u.Type])) + mthd.paramLists.map(_.map(x => fillParameters(x).asSeenFrom(owner.tpe, owner.tpe.typeSymbol)).map(_.asInstanceOf[u.Type])) } override def isMarkedTransient: Boolean = { // TODO - is this correct? val tr = scala.util.Try { - ((mthd.accessed != NoSymbol) && mthd.accessed.annotations.exists(_.tpe =:= typeOf[scala.transient])) || - ((mthd.getter != NoSymbol) && mthd.getter.annotations.exists(_.tpe =:= typeOf[scala.transient])) || - (mthd.annotations.exists(_.tpe =:= typeOf[scala.transient])) + ((mthd.accessed != NoSymbol) && mthd.accessed.annotations.exists(_.tree.tpe =:= typeOf[scala.transient])) || + ((mthd.getter != NoSymbol) && mthd.getter.annotations.exists(_.tree.tpe =:= typeOf[scala.transient])) || + (mthd.annotations.exists(_.tree.tpe =:= typeOf[scala.transient])) } tr.getOrElse(false) } diff --git a/core/src/main/scala/scala/pickling/generator/sourcegen.scala b/core/src/main/scala/scala/pickling/generator/sourcegen.scala index 1b15ed7eeb..77b06f5e80 100644 --- a/core/src/main/scala/scala/pickling/generator/sourcegen.scala +++ b/core/src/main/scala/scala/pickling/generator/sourcegen.scala @@ -27,7 +27,7 @@ private[pickling] trait SourceGenerator extends Macro with tags.FastTypeTagMacro def genGetField(x: GetField): c.Tree = { def pickleLogic(isStaticallyElided: Boolean, fieldValue: Tree, tpe: Type): Tree = { - val fieldPickler = c.fresh(newTermName("fieldPickler")) + val fieldPickler = c.freshName(TermName("fieldPickler")) val elideHint = if (isStaticallyElided) q"b.hintElidedType($fieldPickler.tag)" else q"" // NOTE; This will look up an IMPLICIT pickler for the value, based on the type. @@ -48,12 +48,12 @@ private[pickling] trait SourceGenerator extends Macro with tags.FastTypeTagMacro if(x.isScala || !x.isPublic) { // We always have to use reflection for scala fields right now. Additionally, for Scala fields, we // actually have no idea if they exist at runtime, so we allow failure for now, which is EVIL, but we have no alternative. - val result = reflectivelyGet(newTermName("picklee"), x)(fm => fm) - val rTerm = c.fresh(newTermName("result")) + val result = reflectivelyGet(TermName("picklee"), x)(fm => fm) + val rTerm = c.freshName(TermName("result")) val logic = q"""val $rTerm = { ..$result } ${putField(q"$rTerm.asInstanceOf[$tpe]", staticallyElided, tpe)}""" if(x.isScala) allowNonExistentField(logic) else logic - } else putField(q"picklee.${newTermName(x.fieldName)}", staticallyElided, tpe) + } else putField(q"picklee.${TermName(x.fieldName)}", staticallyElided, tpe) case _: IrConstructor => // This is a logic erorr sys.error(s"Pickling logic error. Found constructor when trying to pickle field ${x.name}.") @@ -63,9 +63,9 @@ private[pickling] trait SourceGenerator extends Macro with tags.FastTypeTagMacro // TODO - This is too naive of a determination. In practice, we almost want an "always elide" and "never elide" mode. tpe.isEffectivelyFinal || tpe.isEffectivelyPrimitive } - if (y.isPublic) putField(q"picklee.${newTermName(y.methodName)}", staticallyElided, tpe) + if (y.isPublic) putField(q"picklee.${TermName(y.methodName)}", staticallyElided, tpe) else { - val result = reflectivelyGet(newTermName("picklee"), y)(fm => putField(q"${fm}.asInstanceOf[${y.returnType(u).asInstanceOf[c.Type]}]", staticallyElided, tpe)) + val result = reflectivelyGet(TermName("picklee"), y)(fm => putField(q"${fm}.asInstanceOf[${y.returnType(u).asInstanceOf[c.Type]}]", staticallyElided, tpe)) q"""..$result""" } } @@ -76,12 +76,12 @@ private[pickling] trait SourceGenerator extends Macro with tags.FastTypeTagMacro def genSubclassDispatch(x: SubclassDispatch): c.Tree = { val tpe = x.parent.tpe[c.universe.type](c.universe) - val clazz = newTermName("clazz") + val clazz = TermName("clazz") val compileTimeDispatch: List[CaseDef] = (x.subClasses map { subtpe => val tpe = subtpe.tpe[c.universe.type](c.universe) CaseDef( - Bind(clazz, Ident(nme.WILDCARD)), + Bind(clazz, Ident(termNames.WILDCARD)), q"_root_.scala.pickling.util.ClassMapper.areSameClasses($clazz, classOf[$tpe])", createPickler(tpe, q"builder") ) @@ -89,16 +89,16 @@ private[pickling] trait SourceGenerator extends Macro with tags.FastTypeTagMacro val failDispatch = { val dispatcheeNames = x.subClasses.map(_.className).mkString(", ") - val otherTermName = newTermName("other") + val otherTermName = TermName("other") val throwUnknownTag = if(x.subClasses.isEmpty) { q"""throw $unrecognizedClass(clazz, None)""" } else q"""throw $unrecognizedClass(clazz, Some("looking for one of: " + $dispatcheeNames))""" - CaseDef(Bind(otherTermName, Ident(nme.WILDCARD)), throwUnknownTag) + CaseDef(Bind(otherTermName, Ident(termNames.WILDCARD)), throwUnknownTag) } - val runtimeDispatch = CaseDef(Ident(nme.WILDCARD), EmptyTree, createRuntimePickler(q"builder")) + val runtimeDispatch = CaseDef(Ident(termNames.WILDCARD), EmptyTree, createRuntimePickler(q"builder")) val unknownDispatch = if(x.lookupRuntime) List(runtimeDispatch) else List(failDispatch) @@ -125,7 +125,7 @@ private[pickling] trait SourceGenerator extends Macro with tags.FastTypeTagMacro def genPickleEntry(op: PickleEntry): c.Tree = { val nested = op.ops.toList map genPickleOp - val oid = c.fresh(newTermName("oid")) + val oid = c.freshName(TermName("oid")) // TODO - hint known size val shareHint: List[c.Tree] = if(shareNothing) List(q"()") @@ -146,7 +146,7 @@ private[pickling] trait SourceGenerator extends Macro with tags.FastTypeTagMacro case x: GetField => genGetField(x) case x: PickleEntry => genPickleEntry(x) case x: SubclassDispatch => genSubclassDispatch(x) - case x: PickleExternalizable => genExternalizablePickle(newTermName("picklee"), newTermName("builder"), x) + case x: PickleExternalizable => genExternalizablePickle(TermName("picklee"), TermName("builder"), x) } genPickleOp(picklerAst) } @@ -200,12 +200,12 @@ private[pickling] trait SourceGenerator extends Macro with tags.FastTypeTagMacro } def readField(name: String, tpe: Type): c.Tree = { - val readerName = c.fresh(newTermName("reader")) - val unpicklerName = c.fresh(newTermName("unpickler$unpickle$")) + val readerName = c.freshName(TermName("reader")) + val unpicklerName = c.freshName(TermName("unpickler$unpickle$")) // TODO - is this the right place to do this? val staticHint = if (tpe.isEffectivelyFinal) q"$readerName.hintElidedType($unpicklerName.tag)" else q""; - val resultName = c.fresh(newTermName("result")) + val resultName = c.freshName(TermName("result")) // TODO - may be able to drop locally. q""" _root_.scala.Predef.locally { @@ -262,9 +262,9 @@ private[pickling] trait SourceGenerator extends Macro with tags.FastTypeTagMacro // TODO - Handle reflective case. val result = if(cons.requiresReflection) sys.error(s"Unable to reflectively call factory methods, currently.") else { - if(cons.factoryMethod.parameterNames.isEmpty) q"${tpe}.${newTermName(cons.factoryMethod.methodName)}()" + if(cons.factoryMethod.parameterNames.isEmpty) q"${tpe}.${TermName(cons.factoryMethod.methodName)}()" else { - q"${tpe}.${newTermName(cons.factoryMethod.methodName)}(...$argss)" + q"${tpe}.${TermName(cons.factoryMethod.methodName)}(...$argss)" } } result @@ -282,9 +282,9 @@ private[pickling] trait SourceGenerator extends Macro with tags.FastTypeTagMacro val read = readField(s.name, tpe) if(x.isPublic) { q""" - result.${newTermName(x.methodName)}($read) + result.${TermName(x.methodName)}($read) """ - } else reflectivelySet(newTermName("result"), x, read) + } else reflectivelySet(TermName("result"), x, read) case x => sys.error(s"Cannot handle a setting method that does not take exactly one parameter, found parameters: $x") } @@ -293,8 +293,8 @@ private[pickling] trait SourceGenerator extends Macro with tags.FastTypeTagMacro val read = readField(s.name, tpe) val staticallyElided = tpe.isEffectivelyFinal || tpe.isEffectivelyPrimitive if(x.isScala || !x.isPublic || x.isFinal) { - reflectivelySet(newTermName("result"), x, read) - } else q"""result.${newTermName(x.fieldName)} = $read""" + reflectivelySet(TermName("result"), x, read) + } else q"""result.${TermName(x.fieldName)} = $read""" } } @@ -327,9 +327,9 @@ private[pickling] trait SourceGenerator extends Macro with tags.FastTypeTagMacro val tpe = x.parent.tpe[c.universe.type](c.universe) val defaultCase = if(x.lookupRuntime) - CaseDef(Ident(nme.WILDCARD), EmptyTree, + CaseDef(Ident(termNames.WILDCARD), EmptyTree, q"_root_.scala.pickling.internal.`package`.currentRuntime.picklers.genUnpickler(_root_.scala.pickling.internal.`package`.currentMirror, tagKey)") - else CaseDef(Ident(nme.WILDCARD), EmptyTree, + else CaseDef(Ident(termNames.WILDCARD), EmptyTree, q"""throw $unrecognizedTagPath(tagKey, "unpickling")""") val subClassCases = x.subClasses.toList map { sc => @@ -356,7 +356,7 @@ private[pickling] trait SourceGenerator extends Macro with tags.FastTypeTagMacro def genAllocateInstance(x: AllocateInstance): c.Tree = { val tpe = x.tpe.tpe[c.universe.type](c.universe) - q"""_root_.scala.concurrent.util.Unsafe.instance.allocateInstance(classOf[$tpe]).asInstanceOf[$tpe]""" + q"""_root_.scala.pickling.Tools.unsafe.allocateInstance(classOf[$tpe]).asInstanceOf[$tpe]""" } def generateUnpickleImplFromAst(unpicklerAst: UnpicklerAst): c.Tree = { @@ -368,7 +368,7 @@ private[pickling] trait SourceGenerator extends Macro with tags.FastTypeTagMacro case x: UnpickleSingleton => genUnpickleSingleton(x) case x: AllocateInstance => genAllocateInstance(x) // TODO - This is kind of hacky, should be a temproary workaround for a better solution. - case x: UnpickleExternalizable => genExternalizablUnPickle(newTermName("reader"), x) + case x: UnpickleExternalizable => genExternalizablUnPickle(TermName("reader"), x) case x: UnpickleBehavior => val behavior = x.operations.map(generateUnpickleImplFromAst).toList // TODO - This is kind of hacky. We're trying to make sure during unpickling we always register/unregister appropriately... @@ -415,7 +415,7 @@ private[pickling] trait SourceGenerator extends Macro with tags.FastTypeTagMacro def generatePicklerUnpicklerClass[T: c.WeakTypeTag](impl: PickleUnpickleImplementation): c.Tree = { val tpe = computeType[T] - val name = c.fresh(newTermName(syntheticBaseName(tpe) + "PicklerUnpickler")) + val name = c.freshName(TermName(syntheticBaseName(tpe) + "PicklerUnpickler")) val createTagTree = super[FastTypeTagMacros].impl[T] val unpickleLogic = genUnpicklerLogic[T](impl.unpickle) val pickleLogic = genPicklerLogic[T](impl.pickle) @@ -446,7 +446,7 @@ private[pickling] trait SourceGenerator extends Macro with tags.FastTypeTagMacro */ def registerUnPickledRef(instantiationLogic: c.Tree): c.Tree = { // TODO - We may not want to ALWAYS do this, some kind of enabling flag... - val instance = c.fresh(newTermName("instance")) + val instance = c.freshName(TermName("instance")) q""" val oid = _root_.scala.pickling.internal.`package`.currentRuntime.refRegistry.unpickle.preregisterUnpicklee() val $instance = $instantiationLogic @@ -466,7 +466,7 @@ private[pickling] trait SourceGenerator extends Macro with tags.FastTypeTagMacro // -- Externalizable Hackery -- def genExternalizablePickle(target: TermName, builder: TermName, pe: PickleExternalizable): c.Tree = { - val out = c.fresh(newTermName("out")) + val out = c.freshName(TermName("out")) val objectOutTpe = typeOf[scala.pickling.util.GenObjectOutput] val fieldName = "$ext" q"""val $out = new _root_.scala.pickling.util.GenObjectOutput @@ -479,12 +479,12 @@ private[pickling] trait SourceGenerator extends Macro with tags.FastTypeTagMacro def genExternalizablUnPickle(reader: TermName, pe: UnpickleExternalizable): c.Tree = { val tpe = pe.tpe.tpe[c.universe.type](c.universe) - val readerName = c.fresh(newTermName("readerName")) - val target = c.fresh(newTermName("out")) + val readerName = c.freshName(TermName("readerName")) + val target = c.freshName(TermName("out")) val objectOutTpe = typeOf[scala.pickling.util.GenObjectOutput] val fieldName = "$ext" q""" - val $target = _root_.scala.concurrent.util.Unsafe.instance.allocateInstance(classOf[$tpe]).asInstanceOf[$tpe] + val $target = _root_.scala.pickling.Tools.unsafe.allocateInstance(classOf[$tpe]).asInstanceOf[$tpe] val $readerName = reader.readField($fieldName) val out = { val up = _root_.scala.Predef.implicitly[_root_.scala.pickling.Unpickler[$objectOutTpe]] @@ -506,7 +506,7 @@ private[pickling] trait SourceGenerator extends Macro with tags.FastTypeTagMacro val valueTree = value match { case field: IrField => - val fieldTerm = c.fresh(newTermName("field")) + val fieldTerm = c.freshName(TermName("field")) val get = q""" val $fieldTerm = _root_.scala.pickling.internal.Reflect.getField($target.getClass, ${field.javaReflectionName}) $fieldTerm.setAccessible(true) @@ -516,14 +516,14 @@ private[pickling] trait SourceGenerator extends Macro with tags.FastTypeTagMacro // Private scala methods may not encode normally for case classes. This is a hack which goes after the field. // TODO - We should update this to look for the accessor method which scala generally exposes for the deconstructor. case mthd: IrMethod if mthd.isScala && mthd.isPrivate => - val methodTerm = c.fresh(newTermName("mthd")) + val methodTerm = c.freshName(TermName("mthd")) // TODO - We may need to do a specialied lookup for magic named methods. q"""val $methodTerm = _root_.scala.pickling.internal.Reflect.getMethod($target.getClass, ${mthd.javaReflectionName}, Array()) $methodTerm.setAccessible(true) $methodTerm.invoke($target) """ case mthd: IrMethod => - val methodTerm = c.fresh(newTermName("mthd")) + val methodTerm = c.freshName(TermName("mthd")) q"""val $methodTerm = _root_.scala.pickling.internal.Reflect.getMethod($target.getClass, ${mthd.javaReflectionName}, Array()) $methodTerm.setAccessible(true) $methodTerm.invoke($target)""" @@ -537,7 +537,7 @@ private[pickling] trait SourceGenerator extends Macro with tags.FastTypeTagMacro // looking them up all the time. setter match { case field: IrField => - val fieldTerm = c.fresh(newTermName("field")) + val fieldTerm = c.freshName(TermName("field")) val result = q""" val $fieldTerm = _root_.scala.pickling.internal.Reflect.getField($target.getClass, ${field.javaReflectionName}) $fieldTerm.setAccessible(true) @@ -545,7 +545,7 @@ private[pickling] trait SourceGenerator extends Macro with tags.FastTypeTagMacro // Workaround for issues with not being able to accurate read scala symbols. if(field.isScala) allowNonExistentField(result) else result case mthd: IrMethod => - val methodTerm = c.fresh(newTermName("mthd")) + val methodTerm = c.freshName(TermName("mthd")) // TODO - We should ensure types align. val List(List(tpe)) = mthd.parameterTypes[c.universe.type](c.universe) q""" diff --git a/core/src/main/scala/scala/pickling/ir/IRs.scala b/core/src/main/scala/scala/pickling/ir/IRs.scala index 1df9d10d3f..e3d9335d9d 100644 --- a/core/src/main/scala/scala/pickling/ir/IRs.scala +++ b/core/src/main/scala/scala/pickling/ir/IRs.scala @@ -29,7 +29,7 @@ class IRs[U <: Universe with Singleton](val uni: U) { def field = accessor.map(_.accessed.asTerm) def getter = accessor.map(_.getter).flatMap(sym => if (sym != NoSymbol) Some(sym) else None) def setter = accessor.map(_.setter).flatMap(sym => if (sym != NoSymbol) Some(sym) else None) - def isParam = param.map(_.owner.name == nme.CONSTRUCTOR).getOrElse(false) + def isParam = param.map(_.owner.name == termNames.CONSTRUCTOR).getOrElse(false) def isPublic = param.nonEmpty || accessor.map(_.isPublic).getOrElse(false) @@ -49,7 +49,7 @@ class IRs[U <: Universe with Singleton](val uni: U) { def nonParamFieldIRsOf(tpe: Type): Iterable[FieldIR] = { val (quantified, rawTpe) = tpe match { case ExistentialType(quantified, rtpe) => (quantified, rtpe); case rtpe => (Nil, rtpe) } - val allAccessors = tpe.declarations.collect { case meth: MethodSymbol if meth.isAccessor || meth.isParamAccessor => meth } + val allAccessors = tpe.decls.collect { case meth: MethodSymbol if meth.isAccessor || meth.isParamAccessor => meth } val (filteredAccessors, _) = allAccessors.partition(notMarkedTransient) @@ -60,7 +60,7 @@ class IRs[U <: Universe with Singleton](val uni: U) { goodAccessorsNotParamsVars.map { symSetter: MethodSymbol => val sym = symSetter.getter.asMethod val rawSymTpe = sym.typeSignatureIn(rawTpe) match { case NullaryMethodType(ntpe) => ntpe; case ntpe => ntpe } - val symTpe = existentialAbstraction(quantified, rawSymTpe) + val symTpe = internal.existentialAbstraction(quantified, rawSymTpe) FieldIR(sym.name.toString, symTpe, None, Some(sym)) } } @@ -68,10 +68,10 @@ class IRs[U <: Universe with Singleton](val uni: U) { def nonAbstractVars(tpe: Type, quantified: List[Symbol], rawTpeOfOwner: Type, isJava: Boolean): List[FieldIR] = { val javaFieldIRs = if (isJava) { // candidates for setter/getter combo - val candidates = tpe.declarations.collect { + val candidates = tpe.decls.collect { case sym: MethodSymbol if sym.name.toString.startsWith("get") => sym.name.toString.substring(3) } - tpe.declarations.flatMap { + tpe.decls.flatMap { case sym: MethodSymbol if sym.name.toString.startsWith("set") => val shortName = sym.name.toString.substring(3) if (candidates.exists(_ == shortName) && shortName.length > 0) { @@ -80,7 +80,7 @@ class IRs[U <: Universe with Singleton](val uni: U) { case _ => throw new LogicException( s"Expected method type for method ${sym.name.toString}") } - val symTpe = existentialAbstraction(quantified, rawSymTpe) + val symTpe = internal.existentialAbstraction(quantified, rawSymTpe) List(FieldIR(shortName, symTpe, None, None, Some(JavaProperty(shortName, tpe.toString, sym.isPublic)))) } else { @@ -93,12 +93,12 @@ class IRs[U <: Universe with Singleton](val uni: U) { List() } - (tpe.declarations.collect { + (tpe.decls.collect { case sym: MethodSymbol if !sym.isParamAccessor && sym.isSetter && sym.accessed != NoSymbol => val rawSymTpe = sym.getter.typeSignatureIn(rawTpeOfOwner) match { case NullaryMethodType(ntpe) => ntpe; case ntpe => ntpe } val symTpe = - existentialAbstraction(quantified, rawSymTpe) + internal.existentialAbstraction(quantified, rawSymTpe) FieldIR(sym.getter.name.toString, symTpe, None, Some(sym.getter.asMethod)) }).toList ++ javaFieldIRs } @@ -112,7 +112,7 @@ class IRs[U <: Universe with Singleton](val uni: U) { // param.nonEmpty iff field is param of primary ctor // accessor.nonEmpty iff field has getter and possibly a setter - val primaryCtor = tpe.declaration(nme.CONSTRUCTOR) match { + val primaryCtor = tpe.decl(termNames.CONSTRUCTOR) match { case overloaded: TermSymbol => overloaded.alternatives.head.asMethod // NOTE: primary ctor is always the first in the list case primaryCtor: MethodSymbol => primaryCtor case NoSymbol => NoSymbol @@ -120,11 +120,11 @@ class IRs[U <: Universe with Singleton](val uni: U) { // we need all accessors to filter out transient ctor params // main diff: members instead of declarations - val allAccessors = tpe.declarations.collect { case meth: MethodSymbol if meth.isAccessor || meth.isParamAccessor => meth } + val allAccessors = tpe.decls.collect { case meth: MethodSymbol if meth.isAccessor || meth.isParamAccessor => meth } val (filteredAccessors, transientAccessors) = allAccessors.partition(notMarkedTransient) val primaryCtorParamsOpt = - if (primaryCtor.isMethod) Some(primaryCtor.asMethod.paramss.flatten) + if (primaryCtor.isMethod) Some(primaryCtor.asMethod.paramLists.flatten) else None val canCallCtor = @@ -167,7 +167,7 @@ class IRs[U <: Universe with Singleton](val uni: U) { // println(s"baseSymTpe: ${baseSymTpe.toString}") val rawSymTpe = baseSymTpe match { case NullaryMethodType(ntpe) => ntpe; case ntpe => ntpe } - val symTpe = existentialAbstraction(quantified, rawSymTpe) + val symTpe = internal.existentialAbstraction(quantified, rawSymTpe) FieldIR(sym.name.toString, symTpe, if (sym.isVal) Some(sym) else None, if (sym.isVal) None else Some(sym.getter.asMethod)) } @@ -185,7 +185,7 @@ class IRs[U <: Universe with Singleton](val uni: U) { // (a) all vals or vars (even if abstract!!) val fieldIRs1 = baseClasses.flatMap { baseClass => val stpe = tpe.baseType(baseClass) - val allGetters = stpe.declarations.collect { + val allGetters = stpe.decls.collect { case sym: MethodSymbol if sym.isGetter && notMarkedTransient(sym) => sym } @@ -193,7 +193,7 @@ class IRs[U <: Universe with Singleton](val uni: U) { allGetters.map { getter => val rawSymTpe = getter.typeSignatureIn(rawTpe) match { case NullaryMethodType(ntpe) => ntpe; case ntpe => ntpe } - val symTpe = existentialAbstraction(quantified, rawSymTpe) + val symTpe = internal.existentialAbstraction(quantified, rawSymTpe) FieldIR(getter.name.toString, symTpe, None, Some(getter)) } @@ -203,7 +203,7 @@ class IRs[U <: Universe with Singleton](val uni: U) { // also add ctor params that are not accessors (need Java reflection for those!) val reflectionGetters = { if (primaryCtor.isMethod) { - primaryCtor.asMethod.paramss.flatten.filter { s => + primaryCtor.asMethod.paramLists.flatten.filter { s => val acc = allAccessors.find(_.name == s.name) acc.isEmpty } @@ -213,7 +213,7 @@ class IRs[U <: Universe with Singleton](val uni: U) { reflectionGetters.map { sym => val rawSymTpe = sym.typeSignatureIn(rawTpe) match { case NullaryMethodType(ntpe) => ntpe; case ntpe => ntpe } - val symTpe = existentialAbstraction(quantified, rawSymTpe) + val symTpe = internal.existentialAbstraction(quantified, rawSymTpe) FieldIR(sym.name.toString, symTpe, None, None) } @@ -262,7 +262,7 @@ class IRs[U <: Universe with Singleton](val uni: U) { def notMarkedTransient(sym: TermSymbol): Boolean = { val tr = scala.util.Try { (sym.accessed == NoSymbol) || // if there is no backing field, then it cannot be marked transient - !sym.accessed.annotations.exists(_.tpe =:= typeOf[scala.transient]) + !sym.accessed.annotations.exists(_.tree.tpe =:= typeOf[scala.transient]) } tr.isFailure || tr.get } @@ -270,17 +270,17 @@ class IRs[U <: Universe with Singleton](val uni: U) { /** Creates FieldIRs for the given type, tp. */ private def fields(tp: Type): Q = { - val ctor = tp.declaration(nme.CONSTRUCTOR) match { + val ctor = tp.decl(termNames.CONSTRUCTOR) match { case overloaded: TermSymbol => overloaded.alternatives.head.asMethod // NOTE: primary ctor is always the first in the list case primaryCtor: MethodSymbol => primaryCtor case NoSymbol => NoSymbol } - val allAccessors = tp.declarations.collect { case meth: MethodSymbol if meth.isAccessor || meth.isParamAccessor => meth } + val allAccessors = tp.decls.collect { case meth: MethodSymbol if meth.isAccessor || meth.isParamAccessor => meth } val (filteredAccessors, transientAccessors) = allAccessors.partition(notMarkedTransient) - val ctorParams = if (ctor != NoSymbol) ctor.asMethod.paramss.flatten.flatMap { sym => + val ctorParams = if (ctor != NoSymbol) ctor.asMethod.paramLists.flatten.flatMap { sym => if (transientAccessors.exists(acc => acc.name.toString == sym.name.toString)) List() else List(sym.asTerm) } else Nil @@ -290,7 +290,7 @@ class IRs[U <: Universe with Singleton](val uni: U) { def mkFieldIR(sym: TermSymbol, param: Option[TermSymbol], accessor: Option[MethodSymbol]) = { val (quantified, rawTp) = tp match { case ExistentialType(quantified, tpe) => (quantified, tpe); case tpe => (Nil, tpe) } val rawSymTp = accessor.getOrElse(sym).typeSignatureIn(rawTp) match { case NullaryMethodType(tpe) => tpe; case tpe => tpe } - val symTp = existentialAbstraction(quantified, rawSymTp) + val symTp = internal.existentialAbstraction(quantified, rawSymTp) FieldIR(sym.name.toString.trim, symTp, param, accessor) } diff --git a/core/src/main/scala/scala/pickling/runtime/Runtime.scala b/core/src/main/scala/scala/pickling/runtime/Runtime.scala index 52ae742b44..62d91c6913 100644 --- a/core/src/main/scala/scala/pickling/runtime/Runtime.scala +++ b/core/src/main/scala/scala/pickling/runtime/Runtime.scala @@ -28,6 +28,8 @@ abstract class PicklerRuntime(classLoader: ClassLoader, preclazz: Class[_], shar import definitions._ import scala.reflect.runtime.{universe => ru} import compat._ + import ru.internal.existentialAbstraction + val clazz = if (preclazz != null) Runtime.toUnboxed.getOrElse(preclazz, preclazz) else null val mirror = runtimeMirror(classLoader) @@ -233,7 +235,7 @@ class InterpretedUnpicklerRuntime(val mirror: Mirror, typeTag: String)(implicit // TODO: need to support modules and other special guys here // TODO: in principle, we could invoke a constructor here - val inst = scala.concurrent.util.Unsafe.instance.allocateInstance(clazz) + val inst = Tools.unsafe.allocateInstance(clazz) if (shouldBotherAboutSharing(tpe)) registerUnpicklee(inst, preregisterUnpicklee()) val im = mirror.reflect(inst) @@ -332,7 +334,7 @@ class ShareNothingInterpretedUnpicklerRuntime(val mirror: Mirror, typeTag: Strin // TODO: need to support modules and other special guys here // TODO: in principle, we could invoke a constructor here - val inst = scala.concurrent.util.Unsafe.instance.allocateInstance(clazz) + val inst = Tools.unsafe.allocateInstance(clazz) val im = mirror.reflect(inst) //debug(s"pendingFields: ${pendingFields.size}") diff --git a/core/src/main/scala/scala/pickling/runtime/RuntimePickler.scala b/core/src/main/scala/scala/pickling/runtime/RuntimePickler.scala index 288cae4db2..dcb5f17d42 100644 --- a/core/src/main/scala/scala/pickling/runtime/RuntimePickler.scala +++ b/core/src/main/scala/scala/pickling/runtime/RuntimePickler.scala @@ -176,7 +176,7 @@ class RuntimePickler(classLoader: ClassLoader, clazz: Class[_], fastTag: FastTyp if (fir.accessor.nonEmpty) List( if (fir.tpe.typeSymbol.isEffectivelyFinal) new EffectivelyFinalLogic(fir) - else if (fir.tpe.typeSymbol.asType.isAbstractType) new AbstractLogic(fir) + else if (fir.tpe.typeSymbol.asType.isAbstract) new AbstractLogic(fir) else new DefaultLogic(fir) ) else diff --git a/core/src/main/scala/scala/pickling/tags/Compat.scala b/core/src/main/scala/scala/pickling/tags/Compat.scala index 3de38c89f2..fa98fc2b30 100644 --- a/core/src/main/scala/scala/pickling/tags/Compat.scala +++ b/core/src/main/scala/scala/pickling/tags/Compat.scala @@ -2,7 +2,7 @@ package scala.pickling package tags import scala.language.experimental.macros -import scala.reflect.macros.Context +import scala.reflect.macros.whitebox.Context // this is only necessary because 2.10.x doesn't support macro bundles object Compat { diff --git a/core/src/main/scala-2.11/scala/pickling/tags/FastTypeTagMacros.scala b/core/src/main/scala/scala/pickling/tags/FastTypeTagMacros.scala similarity index 97% rename from core/src/main/scala-2.11/scala/pickling/tags/FastTypeTagMacros.scala rename to core/src/main/scala/scala/pickling/tags/FastTypeTagMacros.scala index 86c51a5001..3335c619b4 100644 --- a/core/src/main/scala-2.11/scala/pickling/tags/FastTypeTagMacros.scala +++ b/core/src/main/scala/scala/pickling/tags/FastTypeTagMacros.scala @@ -1,7 +1,7 @@ -package scala.pickling -package tags +package scala.pickling.tags import scala.language.experimental.macros +import scala.pickling.Macro /** Macros which take compiler types and turn them into * runtime string we can use to tag ADTs. @@ -48,7 +48,6 @@ trait FastTypeTagMacros extends Macro { // TODO(joshuasuereth): This is may duplicate functionality with the `.tag` extension method on `Type`. def impl[T: c.WeakTypeTag]: c.Tree = { import c.universe._ - import compat._ val T = weakTypeOf[T] if (T.typeSymbol.isParameter) c.abort(c.enclosingPosition, s"cannot generate FastTypeTag for type parameter $T, FastTypeTag can only be generated for concrete types") diff --git a/core/src/main/scala/scala/pickling/util/Externalizables.scala b/core/src/main/scala/scala/pickling/util/Externalizables.scala index 364c758a83..68ff3d7131 100644 --- a/core/src/main/scala/scala/pickling/util/Externalizables.scala +++ b/core/src/main/scala/scala/pickling/util/Externalizables.scala @@ -2,7 +2,7 @@ package scala.pickling.util import scala.language.experimental.macros -import scala.reflect.macros.Context +import scala.reflect.macros.whitebox.Context import java.io.ObjectInput @@ -54,20 +54,20 @@ object Externalizables { def readTree(is: List[Int]): Tree = if (is.isEmpty) q"???" else if (is.size == 1) { - val argName = newTermName("x" + is.head) + val argName = TermName("x" + is.head) q"state += 1; $argName" } else if (is.size == 2) { - val argName0 = newTermName("x" + is.head) - val argName1 = newTermName("x" + is.tail.head) + val argName0 = TermName("x" + is.head) + val argName1 = TermName("x" + is.tail.head) q""" state += 1 if (state == ${is.head}) $argName0 else $argName1 """ } else if (is.size == 3) { - val argName0 = newTermName("x" + is.head) - val argName1 = newTermName("x" + is.tail.head) - val argName2 = newTermName("x" + is.tail.tail.head) + val argName0 = TermName("x" + is.head) + val argName1 = TermName("x" + is.tail.head) + val argName2 = TermName("x" + is.tail.tail.head) q""" state += 1 if (state == ${is.head}) $argName0 @@ -80,7 +80,7 @@ object Externalizables { // create class parameter list // (val x0: Int, val x1: Int, val x2: Array[Byte], val x3: Int, val x4: Long, ...) val params = for ((targ, i) <- targs.zipWithIndex) yield { - val name = newTermName("x" + i) + val name = TermName("x" + i) q"val $name: $targ" } @@ -97,13 +97,13 @@ object Externalizables { if (arrIndices.isEmpty) { // Array[Byte] unused q"???" } else { - val name = newTermName("x" + arrIndices.head) + val name = TermName("x" + arrIndices.head) // TODO: faster array copy using Unsafe? q"System.arraycopy($name, 0, x, 0, x.length)" } } - val dummyName = c.fresh(newTypeName("DummyObjectInput")) + val dummyName = c.freshName(TypeName("DummyObjectInput")) val instance: Tree = q""" class $dummyName(..$params) extends java.io.ObjectInput { var state = -1 @@ -175,7 +175,7 @@ object Externalizables { // we assume the methods corresponding to the "writeTree" bodies are called in the right order def writeTree(is: List[Int], tpeName: String): Tree = { - val fldName = newTermName(tpeName + "Arr") + val fldName = TermName(tpeName + "Arr") if (is.isEmpty) q"???" else if (is.size == 1) { q"{ state += 1; $fldName(0) = x }" @@ -207,7 +207,7 @@ object Externalizables { val fields = (for (targ <- storage.keys) yield { val TypeRef(_, classSym, _) = targ val tpestr = classSym.name.toString.toLowerCase - val name = newTermName(tpestr + "Arr") + val name = TermName(tpestr + "Arr") val storageTpe = storage(targ) val size = perType.getOrElse(targ, List[Int]()).size q"val $name: Array[$storageTpe] = Array.ofDim[$storageTpe]($size)" @@ -222,7 +222,7 @@ object Externalizables { def finalTree(tpe: Type, tpeName: String): Tree = writeTree(perType.getOrElse(tpe, List[Int]()), tpeName) - val dummyName = c.fresh(newTypeName("DummyObjectOutput")) + val dummyName = c.freshName(TypeName("DummyObjectOutput")) val instance: Tree = q""" class $dummyName extends scala.pickling.util.ArrayObjectOutput { var state = -1 diff --git a/macro-test/src/main/scala/scala/pickling/generator/scalasymbols/Compat.scala b/macro-test/src/main/scala/scala/pickling/generator/scalasymbols/Compat.scala index 080fb86f58..864a743889 100644 --- a/macro-test/src/main/scala/scala/pickling/generator/scalasymbols/Compat.scala +++ b/macro-test/src/main/scala/scala/pickling/generator/scalasymbols/Compat.scala @@ -2,7 +2,7 @@ package scala.pickling.generator.scalasymbols import scala.pickling.Macro import scala.pickling.generator.{IrSymbol, IrScalaSymbols} -import scala.reflect.macros.Context +import scala.reflect.macros.whitebox.Context import scala.reflect.runtime.{universe => ru} import scala.language.experimental.macros diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 8cff1c64c0..e2ea10ee1d 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -2,9 +2,9 @@ import sbt._ import Keys._ object Dependencies { - lazy val scalaTest = "org.scalatest" %% "scalatest" % "3.0.0-M15" + lazy val scalaTest = "org.scalatest" %% "scalatest" % "3.0.1" lazy val scalaCheck = "org.scalacheck" %% "scalacheck" % "1.11.6" - lazy val parserCombinators = "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.2" + lazy val parserCombinators = "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.5" lazy val macroParadise = "org.scalamacros" % "paradise" % "2.0.1" cross CrossVersion.full lazy val quasiquotes = "org.scalamacros" %% "quasiquotes" % "2.0.1" lazy val kryoSerializers = "de.javakaffee" % "kryo-serializers" % "0.22" diff --git a/project/Util.scala b/project/Util.scala index ce5900cf9f..ee0d530285 100644 --- a/project/Util.scala +++ b/project/Util.scala @@ -2,8 +2,8 @@ import sbt._ import Keys._ object Util { - val buildScalaVersion = System.getProperty("scala.version", "2.11.8") - val buildScalaVersions = Seq("2.11.8", "2.10.6") + val buildScalaVersion = System.getProperty("scala.version", "2.12.1") + val buildScalaVersions = Seq("2.12.1", "2.11.8") val javaVersion = System.getProperty("java.version") def loadCredentials(): List[Credentials] = { diff --git a/project/build.properties b/project/build.properties index 35c88bab7d..64317fdae5 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=0.13.12 +sbt.version=0.13.15