Skip to content

Commit

Permalink
Fix macro hygiene problems
Browse files Browse the repository at this point in the history
  • Loading branch information
travisbrown committed Mar 29, 2018
1 parent c944a6e commit fe4eea2
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 44 deletions.
Expand Up @@ -67,7 +67,7 @@ object ProductLike {
}

q"""
var $currentHash: Int = _root_.com.twitter.scalding.serialization.MurmurHashUtils.seed
var $currentHash: _root_.scala.Int = _root_.com.twitter.scalding.serialization.MurmurHashUtils.seed
..${hashUpdates}
_root_.com.twitter.scalding.serialization.MurmurHashUtils.fmix($currentHash, ${elementData.size})
"""
Expand Down Expand Up @@ -173,7 +173,7 @@ object ProductLike {
case (tpe, accessorSymbol, tBuf) =>
val curCmp = freshT("curCmp")
val cmpTree = q"""
val $curCmp: Int = {
val $curCmp: _root_.scala.Int = {
val $innerElementA = $elementA.$accessorSymbol
val $innerElementB = $elementB.$accessorSymbol
${tBuf.compare(innerElementA, innerElementB)}
Expand Down
Expand Up @@ -100,10 +100,10 @@ object TreeOrderedBuf {
val tempLen = freshT("tempLen")
val lensLen = freshT("lensLen")
val element = freshT("element")
val callDynamic = (q"""override def staticSize: _root_.scala.Option[Int] = _root_.scala.None""",
val callDynamic = (q"""override def staticSize: _root_.scala.Option[_root_.scala.Int] = _root_.scala.None""",
q"""

override def dynamicSize($element: $typeName): _root_.scala.Option[Int] = {
override def dynamicSize($element: $typeName): _root_.scala.Option[_root_.scala.Int] = {
if(skipLenCalc) _root_.scala.None else {
val $tempLen = payloadLength($element) match {
case _root_.com.twitter.scalding.serialization.macros.impl.ordered_serialization.runtime_helpers.NoLengthCalculation =>
Expand All @@ -117,18 +117,18 @@ object TreeOrderedBuf {
val innerLen = $tempLen.get
val $lensLen = posVarIntSize(innerLen)
_root_.scala.Some(innerLen + $lensLen)
} else _root_.scala.None): _root_.scala.Option[Int]
} else _root_.scala.None): _root_.scala.Option[_root_.scala.Int]
}
}
""")

t.length(q"$element") match {
case _: NoLengthCalculationAvailable[_] => (q"""
override def staticSize: _root_.scala.Option[Int] = _root_.scala.None""", q"""
override def dynamicSize($element: $typeName): _root_.scala.Option[Int] = _root_.scala.None""")
override def staticSize: _root_.scala.Option[_root_.scala.Int] = _root_.scala.None""", q"""
override def dynamicSize($element: $typeName): _root_.scala.Option[_root_.scala.Int] = _root_.scala.None""")
case const: ConstantLengthCalculation[_] => (q"""
override val staticSize: _root_.scala.Option[Int] = _root_.scala.Some(${const.toInt})""", q"""
override def dynamicSize($element: $typeName): _root_.scala.Option[Int] = staticSize""")
override val staticSize: _root_.scala.Option[_root_.scala.Int] = _root_.scala.Some(${const.toInt})""", q"""
override def dynamicSize($element: $typeName): _root_.scala.Option[_root_.scala.Int] = staticSize""")
case f: FastLengthCalculation[_] => callDynamic
case m: MaybeLengthCalculation[_] => callDynamic
}
Expand Down Expand Up @@ -230,11 +230,11 @@ object TreeOrderedBuf {

t.ctx.Expr[OrderedSerialization[T]](q"""
new _root_.com.twitter.scalding.serialization.macros.impl.ordered_serialization.runtime_helpers.MacroEqualityOrderedSerialization[$T] {
override val uniqueId: String = ${T.tpe.toString}
override val uniqueId: _root_.java.lang.String = ${T.tpe.toString}

private[this] var lengthCalculationAttempts: Long = 0L
private[this] var couldNotLenCalc: Long = 0L
private[this] var skipLenCalc: Boolean = false
private[this] var lengthCalculationAttempts: _root_.scala.Long = 0L
private[this] var couldNotLenCalc: _root_.scala.Long = 0L
private[this] var skipLenCalc:_root_.scala.Boolean = false

import _root_.com.twitter.scalding.serialization.JavaStreamEnrichments._
..$lazyVariables
Expand All @@ -258,11 +258,11 @@ object TreeOrderedBuf {
_root_.com.twitter.scalding.serialization.OrderedSerialization.CompareFailure(e)
}

override def hash(passedInObjectToHash: $T): Int = {
override def hash(passedInObjectToHash: $T): _root_.scala.Int = {
${t.hash(TermName("passedInObjectToHash"))}
}

private[this] def failedLengthCalc(): Unit = {
private[this] def failedLengthCalc(): _root_.scala.Unit = {
couldNotLenCalc += 1L
if(lengthCalculationAttempts > 50 && (couldNotLenCalc.toDouble / lengthCalculationAttempts) > 0.4f) {
skipLenCalc = true
Expand Down Expand Up @@ -299,7 +299,7 @@ object TreeOrderedBuf {
}
}

override def compare(x: $T, y: $T): Int = {
override def compare(x: $T, y: $T): _root_.scala.Int = {
${t.compare(TermName("x"), TermName("y"))}
}
}
Expand Down
Expand Up @@ -51,8 +51,8 @@ object ByteBufferOrderedBuf {
val incr = freshT("incr")
val state = freshT("state")
q"""
val $lenA: Int = $inputStreamA.readPosVarInt
val $lenB: Int = $inputStreamB.readPosVarInt
val $lenA: _root_.scala.Int = $inputStreamA.readPosVarInt
val $lenB: _root_.scala.Int = $inputStreamB.readPosVarInt

val $queryLength = _root_.scala.math.min($lenA, $lenB)
var $incr = 0
Expand Down Expand Up @@ -80,7 +80,7 @@ object ByteBufferOrderedBuf {
val bytes = freshT("bytes")
q"""
val $lenA = $inputStream.readPosVarInt
val $bytes = new Array[Byte]($lenA)
val $bytes = new _root_.scala.Array[Byte]($lenA)
$inputStream.readFully($bytes)
_root_.java.nio.ByteBuffer.wrap($bytes)
"""
Expand Down
Expand Up @@ -87,8 +87,8 @@ object EitherOrderedBuf {
val tmpGetHolder = freshT("tmpGetHolder")
q"""
val $tmpGetHolder = $inputStreamA.readByte
if($tmpGetHolder == (0: _root_.scala.Byte)) Left(${leftBuf.get(inputStreamA)})
else Right(${rightBuf.get(inputStreamA)})
if($tmpGetHolder == (0: _root_.scala.Byte)) _root_.scala.util.Left(${leftBuf.get(inputStreamA)})
else _root_.scala.util.Right(${rightBuf.get(inputStreamA)})
"""
}

Expand Down
Expand Up @@ -60,12 +60,12 @@ object ImplicitOrderedBuf {
override def length(element: Tree) =
CompileTimeLengthTypes.MaybeLengthCalculation(c)(q"""
($variableName.staticSize match {
case Some(s) => _root_.com.twitter.scalding.serialization.macros.impl.ordered_serialization.runtime_helpers.ConstLen(s)
case None =>
case _root_.scala.Some(s) => _root_.com.twitter.scalding.serialization.macros.impl.ordered_serialization.runtime_helpers.ConstLen(s)
case _root_.scala.None =>
$variableName.dynamicSize($element) match {
case Some(s) =>
case _root_.scala.Some(s) =>
_root_.com.twitter.scalding.serialization.macros.impl.ordered_serialization.runtime_helpers.DynamicLen(s)
case None =>
case _root_.scala.None =>
_root_.com.twitter.scalding.serialization.macros.impl.ordered_serialization.runtime_helpers.NoLengthCalculation
}
}): _root_.com.twitter.scalding.serialization.macros.impl.ordered_serialization.runtime_helpers.MaybeLength
Expand Down
Expand Up @@ -75,8 +75,8 @@ object OptionOrderedBuf {
val tmpGetHolder = freshT("tmpGetHolder")
q"""
val $tmpGetHolder = $inputStreamA.readByte
if($tmpGetHolder == (0: _root_.scala.Byte)) None
else Some(${innerBuf.get(inputStreamA)})
if($tmpGetHolder == (0: _root_.scala.Byte)) _root_.scala.None
else _root_.scala.Some(${innerBuf.get(inputStreamA)})
"""
}

Expand Down
Expand Up @@ -65,9 +65,9 @@ object StringOrderedBuf {
q"""
// Ascii is very common, so if the string is short,
// we check if it is ascii:
def isShortAscii(size: Int, str: String): Boolean = (size < 65) && {
def isShortAscii(size: _root_.scala.Int, str: _root_.java.lang.String): _root_.scala.Boolean = (size < 65) && {
var pos = 0
var ascii: Boolean = true
var ascii: _root_.scala.Boolean = true
while((pos < size) && ascii) {
ascii = (str.charAt(pos) < 128)
pos += 1
Expand All @@ -80,7 +80,7 @@ object StringOrderedBuf {
$inputStream.writePosVarInt(0)
}
else if (isShortAscii($charLen, $element)) {
val $bytes = new Array[Byte]($charLen)
val $bytes = new _root_.scala.Array[Byte]($charLen)
// This deprecated gets ascii bytes out, but is incorrect
// for non-ascii data.
_root_.com.twitter.scalding.serialization.Undeprecated.getAsciiBytes($element, 0, $charLen, $bytes, 0)
Expand All @@ -106,9 +106,9 @@ object StringOrderedBuf {
q"""
val $len = $inputStream.readPosVarInt
if($len > 0) {
val $strBytes = new Array[Byte]($len)
val $strBytes = new _root_.scala.Array[Byte]($len)
$inputStream.readFully($strBytes)
new String($strBytes, "UTF-8")
new _root_.java.lang.String($strBytes, "UTF-8")
} else {
""
}
Expand Down
Expand Up @@ -227,7 +227,7 @@ object TraversablesOrderedBuf {
val iter = freshT("iter")
val extractionTree = maybeArray match {
case IsArray =>
q"""val $travBuilder = new Array[..$innerTypes]($len)
q"""val $travBuilder = new _root_.scala.Array[..$innerTypes]($len)
var $iter = 0
while($iter < $len) {
$travBuilder($iter) = ${innerBuf.get(inputStream)}
Expand All @@ -247,7 +247,7 @@ object TraversablesOrderedBuf {
"""
}
q"""
val $len: Int = $inputStream.readPosVarInt
val $len: _root_.scala.Int = $inputStream.readPosVarInt
if($len > 0) {
if($len == 1) {
val $firstVal: $innerType = ${innerBuf.get(inputStream)}
Expand Down
Expand Up @@ -53,7 +53,7 @@ object ScroogeEnumOrderedBuf {
q"${outerType.typeSymbol.companionSymbol}.apply($inputStream.readPosVarInt)"
override def compare(elementA: ctx.TermName, elementB: ctx.TermName): ctx.Tree =
q"""
_root_.java.lang.Integer.compare($elementA.value, $elementB.value) : Int
_root_.java.lang.Integer.compare($elementA.value, $elementB.value) : _root_.scala.Int
"""

override def length(element: Tree): CompileTimeLengthTypes[c.type] = CompileTimeLengthTypes.FastLengthCalculation(c)(q"posVarIntSize($element.value)")
Expand Down
Expand Up @@ -45,7 +45,7 @@ object ScroogeOuterOrderedBuf {
val variableID = (outerType.typeSymbol.fullName.hashCode.toLong + Int.MaxValue.toLong).toString
val variableNameStr = s"bufferable_$variableID"
val variableName = newTermName(variableNameStr)
val implicitInstanciator = q"""implicitly[_root_.com.twitter.scalding.serialization.OrderedSerialization[$outerType]]"""
val implicitInstanciator = q"""_root_.scala.Predef.implicitly[_root_.com.twitter.scalding.serialization.OrderedSerialization[$outerType]]"""

new TreeOrderedBuf[c.type] {
override val ctx: c.type = c
Expand All @@ -60,12 +60,12 @@ object ScroogeOuterOrderedBuf {
override def length(element: Tree) =
CompileTimeLengthTypes.MaybeLengthCalculation(c)(q"""
($variableName.staticSize match {
case Some(s) => _root_.com.twitter.scalding.serialization.macros.impl.ordered_serialization.runtime_helpers.ConstLen(s)
case None =>
case _root_.scala.Some(s) => _root_.com.twitter.scalding.serialization.macros.impl.ordered_serialization.runtime_helpers.ConstLen(s)
case _root_.scala.None =>
$variableName.dynamicSize($element) match {
case Some(s) =>
case _root_.scala.Some(s) =>
_root_.com.twitter.scalding.serialization.macros.impl.ordered_serialization.runtime_helpers.DynamicLen(s)
case None =>
case _root_.scala.None =>
_root_.com.twitter.scalding.serialization.macros.impl.ordered_serialization.runtime_helpers.NoLengthCalculation
}
}): _root_.com.twitter.scalding.serialization.macros.impl.ordered_serialization.runtime_helpers.MaybeLength
Expand Down
Expand Up @@ -54,15 +54,15 @@ object UnionLike {
if($valueA == $idx) {
$commonCmp
} else {
sys.error("Unable to compare unknown type")
_root_.scala.sys.error("Unable to compare unknown type")
}""")
}
}.get

q"""
val $valueA: Int = $inputStreamA.readByte.toInt
val $valueB: Int = $inputStreamB.readByte.toInt
val $idxCmp: Int = _root_.java.lang.Integer.compare($valueA, $valueB)
val $valueA: _root_.scala.Int = $inputStreamA.readByte.toInt
val $valueB: _root_.scala.Int = $inputStreamB.readByte.toInt
val $idxCmp: _root_.scala.Int = _root_.java.lang.Integer.compare($valueA, $valueB)
if($idxCmp != 0) {
$idxCmp
} else {
Expand Down

0 comments on commit fe4eea2

Please sign in to comment.