Skip to content
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

Merged
merged 6 commits into from
Jun 18, 2015

Conversation

ianoc
Copy link
Collaborator

@ianoc ianoc commented Jun 14, 2015

… 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") {
Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry cleanup typo. updated

@johnynek
Copy link
Collaborator

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 = {
Copy link
Collaborator

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.

@ianoc
Copy link
Collaborator Author

ianoc commented Jun 17, 2015

@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)
Copy link
Collaborator

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

Copy link
Collaborator Author

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 :/

Copy link
Collaborator Author

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

johnynek added a commit that referenced this pull request Jun 18, 2015
…zationMacro

Added a sealed trait ordered serializer. When it works its great. Not…
@johnynek johnynek merged commit 8581d12 into develop Jun 18, 2015
@johnynek johnynek deleted the ioconnell/addSealedTraitSerializationMacro branch June 18, 2015 19:34
@ianoc ianoc mentioned this pull request Aug 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants