@@ -2,7 +2,12 @@ package dotty.tools.dotc
2
2
package transform
3
3
4
4
import core ._
5
- import Decorators ._ , Flags ._ , Types ._ , Contexts ._ , Symbols ._ , Constants ._
5
+ import Decorators ._
6
+ import Flags ._
7
+ import Types ._
8
+ import Contexts ._
9
+ import Symbols ._
10
+ import Constants ._
6
11
import Flags ._
7
12
import ast .Trees ._
8
13
import ast .{TreeTypeMap , untpd }
@@ -13,6 +18,7 @@ import MegaPhase.MiniPhase
13
18
import SymUtils ._
14
19
import NameKinds ._
15
20
import dotty .tools .dotc .ast .tpd .Tree
21
+ import dotty .tools .dotc .core .DenotTransformers .InfoTransformer
16
22
import typer .Implicits .SearchFailureType
17
23
18
24
import scala .collection .mutable
@@ -57,7 +63,7 @@ import dotty.tools.dotc.core.quoted._
57
63
* ```
58
64
* and then performs the same transformation on `'{ ... x1$1.unary_~ ... x2$1.unary_~ ...}`.
59
65
*/
60
- class ReifyQuotes extends MacroTransformWithImplicits {
66
+ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
61
67
import ast .tpd ._
62
68
63
69
override def phaseName : String = " reifyQuotes"
@@ -493,12 +499,6 @@ class ReifyQuotes extends MacroTransformWithImplicits {
493
499
case tree : Select if tree.symbol.isSplice =>
494
500
splice(tree)
495
501
case tree : RefTree if isCaptured(tree, level) =>
496
- println(" ================" )
497
- println(tree.show)
498
- println(tree)
499
- println()
500
- println()
501
- println()
502
502
val capturer = capturers(tree.symbol)
503
503
if (tree.symbol.is(Inline )) capturer(tree)
504
504
else splice(capturer(tree).select(if (tree.isTerm) nme.UNARY_~ else tpnme.UNARY_~ ))
@@ -514,7 +514,20 @@ class ReifyQuotes extends MacroTransformWithImplicits {
514
514
}
515
515
516
516
val tree1 =
517
- if (level == 0 ) cpy.Inlined (tree)(call, stagedBindings, Splicer .splice(seq(splicedBindings, body).withPos(tree.pos)))
517
+ if (level == 0 ) {
518
+ println(" ========================" )
519
+ println(tree.show)
520
+ println()
521
+ println(call.show)
522
+ println(call)
523
+ println()
524
+ println()
525
+ println()
526
+ println()
527
+ println()
528
+
529
+ cpy.Inlined (tree)(call, stagedBindings, Splicer .splice(seq(splicedBindings, body).withPos(tree.pos)))
530
+ }
518
531
else seq(stagedBindings, cpy.Select (expansion)(cpy.Inlined (tree)(call, splicedBindings, body), name))
519
532
val tree2 = transform(tree1)
520
533
@@ -526,18 +539,10 @@ class ReifyQuotes extends MacroTransformWithImplicits {
526
539
case tree : DefDef if tree.symbol.is(Macro ) && level == 0 =>
527
540
markDef(tree)
528
541
val reifier = nested(isQuote = true )
529
- val b = reifier.transform(tree)
542
+ reifier.transform(tree) // Ignore output, we only need the its embedding
530
543
val macroLambda = reifier.embedded.head
531
- println(b.show)
532
- println()
533
- println()
534
- println(macroLambda.show)
535
- println()
536
- println()
537
- println()
538
- println()
539
- // check macro code as it if appeared in a quoted context
540
- cpy.DefDef (tree)(rhs = EmptyTree )
544
+ // replace macro code by lambda used to evaluate the macro expansion
545
+ cpy.DefDef (tree)(tpt = TypeTree (defn.ObjectType ), rhs = macroLambda)
541
546
case _ =>
542
547
markDef(tree)
543
548
checkLevel(mapOverTree(enteredSyms))
@@ -564,6 +569,22 @@ class ReifyQuotes extends MacroTransformWithImplicits {
564
569
}
565
570
}
566
571
}
572
+
573
+ def transformInfo (tp : Type , sym : Symbol )(implicit ctx : Context ): Type = {
574
+ /** Transforms the return type
575
+ * inline def foo(...): X = ~(...)
576
+ * to
577
+ * inline def foo(...): Object = (args: Seq[Any]) => ...
578
+ */
579
+ def transform (tp : Type ): Type = tp match {
580
+ case tp : PolyType => PolyType (tp.paramNames, tp.paramInfos, transform(tp.resType))
581
+ case tp : MethodType => MethodType (tp.paramNames, tp.paramInfos, transform(tp.resType))
582
+ case _ => defn.ObjectType
583
+ }
584
+ transform(tp)
585
+ }
586
+
587
+ override protected def mayChange (sym : Symbol )(implicit ctx : Context ) = sym.is(Macro )
567
588
}
568
589
569
590
object ReifyQuotes {
0 commit comments