-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Using HLists instead of tuples for inference. * Upgrading method signatures * Trying to force cast * Duck typing generics to collide HList types if enclosing type is found. * Removing useless printlns * Adding more documentation and dealing with warnings. * Adding more documentation. * Adding shapeless implementation. * Removing unused imports. * Removing println statements, tweaking echo and info usage and fixing SingleGenerics * A bit more work and tests * Cheating * Fixing logging for batch staments. * Upgrading batch query mechanism. * Adding macro paradise plugin dependency * Adding more docs. * Fixing recurvise call * Renaming batch method [version skip]
- Loading branch information
1 parent
26a1b88
commit a565a15
Showing
23 changed files
with
502 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
phantom-dsl/src/main/scala/com/outworkers/phantom/macros/==:==.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright 2013 - 2017 Outworkers Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.outworkers.phantom.macros | ||
|
||
import shapeless.{HList, HNil} | ||
|
||
import scala.annotation.tailrec | ||
import scala.reflect.macros.whitebox | ||
|
||
/** | ||
* A special implicitly materialized typeclass that compares HLists for equality. | ||
* This also prints more useful information to the end user if the HLists don't match. | ||
* However, it is required because the standard [[=:=]] type class in Scala | ||
* is not able to see through an HList generated as an abstract type member of another | ||
* implicitly materialized type class. | ||
* @tparam LL The left [[shapeless.HList]] type. | ||
* @tparam RR The right [[shapeless.HList]] type. | ||
*/ | ||
trait ==:==[LL <: HList, RR <: HList] | ||
|
||
object ==:== { | ||
|
||
def apply[LL <: HList, RR <: HList](implicit ev: LL ==:== RR): ==:==[LL, RR] = ev | ||
|
||
implicit def materialize[ | ||
LL <: HList, | ||
RR <: HList | ||
]: ==:==[LL, RR] = macro EqsMacro.materialize[LL, RR] | ||
} | ||
|
||
|
||
@macrocompat.bundle | ||
class EqsMacro(val c: whitebox.Context) extends WhiteboxToolbelt with HListHelpers { | ||
|
||
import c.universe._ | ||
|
||
protected[this] val macroPkg = q"_root_.com.outworkers.phantom.macros" | ||
|
||
|
||
def mkEqs(left: Type, right: Type): Tree = { | ||
if (left =:= right) { | ||
val tree = q"""new $macroPkg.==:==[$left, $right] {}""" | ||
if (showTrees) { | ||
echo(showCode(tree)) | ||
} | ||
|
||
tree | ||
} else { | ||
val debugString = s"Types ${showHList(left)} did not equal ${showHList(right)}" | ||
error(debugString) | ||
abort( debugString) | ||
} | ||
} | ||
|
||
def materialize[LL <: HList : c.WeakTypeTag, RR <: HList : c.WeakTypeTag]: Tree = { | ||
val left = weakTypeOf[LL] | ||
val right = weakTypeOf[RR] | ||
|
||
memoize[(Type, Type), Tree]( | ||
WhiteboxToolbelt.specialEqsCache | ||
)(Tuple2(left, right), { case (t, s) => mkEqs(t, s)}) | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.