-
Notifications
You must be signed in to change notification settings - Fork 707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added a sealed trait ordered serializer. When it works its great. Not… #1320
Conversation
… as reliable as we'd like. But hopefully restrictions on it will do the job
@@ -572,6 +602,14 @@ class MacroOrderingProperties extends FunSuite with PropertyChecks with ShouldMa | |||
checkCollisions[TestCC] | |||
} | |||
|
|||
test("Test out Sealed Trait") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't we want one that does:
check[SealedTraitTest]
the test below looks like it is just using the case class stuff you had before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry cleanup typo. updated
This is awesome. Really this should be all we need (sealed traits give us sum types, tuples/case classes give us product types). |
|
||
object SealedTraitLike { | ||
|
||
def compareBinary(c: Context)(inputStreamA: c.TermName, inputStreamB: c.TermName)(subData: List[(Int, c.Type, Option[TreeOrderedBuf[c.type]])]): c.Tree = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you comment what is in the subData. I am trying to figure that out, but I'll probably forget by the time I look at it again.
…ase objects in them
@johnynek Have i think it in a better shape now, does the case objects. I'll see if working without Either + Option ordered serializations is good now too |
case Some(s) => | ||
Some(q""" | ||
if($element.isInstanceOf[$tpe]) { | ||
$elementHash ^ _root_.com.twitter.scalding.serialization.Hasher.int.hash($idx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_root_.com.twitter.scalding.serialization.Hasher.int.hash($idx)
is a constant known at compile time. Can we evaluate that using something like:
val treeHash: c.Tree = c.resetLocalAttrs(q"_root_.com.twitter.scalding.serialization.Hasher.int.hash($idx)")
val intHash: Int = c.eval(c.Expr[Int](treeHash))
// then:
q"""$elementHash ^ $intHash"""
Found some discussion here that leads me to believe this might work:
http://stackoverflow.com/questions/21580206/how-to-evaluate-an-expression-inside-a-scala-macro
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Evals are pretty much totally broken and unreliable. -- we've tried to use them for a few things before, its never worked :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But your points valid, i'm not sure we need to eval or do anything special here. We can probably just call the method itself
…zationMacro Added a sealed trait ordered serializer. When it works its great. Not…
… as reliable as we'd like. But hopefully restrictions on it will do the job