Skip to content

Commit 0f9b83c

Browse files
committed
Rename reify -> unpickle
Also, add test
1 parent 1a995eb commit 0f9b83c

File tree

5 files changed

+47
-18
lines changed

5 files changed

+47
-18
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,8 @@ class Definitions {
602602
def MetaType_~(implicit ctx: Context) =
603603
MetaTypeClass.info.member(tpnme.UNARY_~).symbol.asType
604604

605-
def Reifier_reifyExpr = ctx.requiredMethod("scala.meta.Reifier.reifyExpr")
606-
def Reifier_reifyType = ctx.requiredMethod("scala.meta.Reifier.reifyType")
605+
def Unpickler_unpickleExpr = ctx.requiredMethod("scala.meta.Unpickler.unpickleExpr")
606+
def Unpickler_unpickleType = ctx.requiredMethod("scala.meta.Unpickler.unpickleType")
607607

608608
lazy val EqType = ctx.requiredClassRef("scala.Eq")
609609
def EqClass(implicit ctx: Context) = EqType.symbol.asClass

compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class ReifyQuotes extends MiniPhase {
2525
* the `qual` part will be of the form `Typed(EmptyTree, TypeTree(<underlying type>))`,
2626
* but that knowledge is not needed to uniquely identify a splice node.
2727
*/
28-
def reifyTree(tree: Tree)(implicit ctx: Context): String = tree.show // TODO: replace with TASTY
28+
def pickleTree(tree: Tree, isType: Boolean)(implicit ctx: Context): String =
29+
tree.show // TODO: replace with TASTY
2930

3031
private def reifyCall(body: Tree, isType: Boolean)(implicit ctx: Context) = {
3132

@@ -34,21 +35,23 @@ class ReifyQuotes extends MiniPhase {
3435
override def transform(tree: Tree)(implicit ctx: Context) = tree match {
3536
case tree @ Select(qual, name)
3637
if tree.symbol == defn.MetaExpr_~ || tree.symbol == defn.MetaType_~ =>
37-
splices += qual
38+
splices += {
39+
if (isType) // transform splice again because embedded type trees were not rewritten before
40+
transformAllDeep(qual)(ctx.retractMode(Mode.InQuotedType))
41+
else qual
42+
}
3843
val placeHolder = Typed(EmptyTree, TypeTree(qual.tpe.widen))
3944
cpy.Select(tree)(placeHolder, name)
4045
case _ =>
4146
super.transform(tree)
4247
}
4348
}
4449

45-
val reified = reifyTree(liftSplices.transform(body))
46-
var splices = liftSplices.splices.toList
47-
if (isType) // transform splices again because embedded type trees were not rewritten before
48-
splices = splices.map(transformAllDeep(_)(ctx.retractMode(Mode.InQuotedType)))
50+
val reified = pickleTree(liftSplices.transform(body), isType)
51+
val splices = liftSplices.splices.toList
4952
val spliceType = if (isType) defn.MetaTypeType else defn.MetaExprType
5053

51-
ref(if (isType) defn.Reifier_reifyType else defn.Reifier_reifyExpr)
54+
ref(if (isType) defn.Unpickler_unpickleType else defn.Unpickler_unpickleExpr)
5255
.appliedToType(if (isType) body.tpe else body.tpe.widen)
5356
.appliedTo(
5457
Literal(Constant(reified)),

library/src/scala/meta/Reifier.scala

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package scala.meta
2+
3+
/** Provides methods to unpickle `Expr` and `Type` trees. */
4+
object Unpickler {
5+
6+
/** Representation of pickled trees. For now it's String, but it
7+
* should be changed to some kind of TASTY bundle.
8+
*/
9+
type Pickled = String
10+
11+
/** Unpickle `repr` which represents a pickled `Expr` tree,
12+
* replacing splice nodes with `args`
13+
*/
14+
def unpickleExpr[T](repr: Pickled, args: Seq[Expr[_]]): Expr[T] = ???
15+
16+
/** Unpickle `repr` which represents a pickled `Type` tree,
17+
* replacing splice nodes with `args`
18+
*/
19+
def unpickleType[T](repr: Pickled, args: Seq[Type[_]]): Type[T] = ???
20+
}

tests/pos/quoteTest.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import scala.meta._
2+
3+
object Test {
4+
5+
def f[T](t: Type[T], x: Expr[T]) = {
6+
val y: t.unary_~ = x.unary_~
7+
val z: ~t = ~x
8+
}
9+
10+
f('[Int], '(2))
11+
f('[Boolean], '{ true })
12+
13+
def g(es: Expr[String], t: Type[String]) =
14+
f('[List[~t]], '{ (~es + "!") :: Nil })
15+
}

0 commit comments

Comments
 (0)