@@ -76,6 +76,10 @@ import dotty.tools.dotc.core.quoted._
76
76
* { ... x1$1 .... '{ ... T1$1.unary_~ ... x1$1.toExpr.unary_~ ... y1$1.unary_~ ... } ... }
77
77
* }
78
78
* ```
79
+ * Where `inline` parameters with type Boolean, Byte, Short, Int, Long, Float, Double, Char and String are
80
+ * passed as their actual runtime value. See `isStage0Value`. Other `inline` arguments such as functions are handled
81
+ * like `y1: Y`.
82
+ *
79
83
* Note: the parameters of `foo` are kept for simple overloading resolution but they are not used in the body of `foo`.
80
84
*
81
85
* At inline site we will call reflectively the static method `foo` with dummy parameters, which will return a
@@ -243,7 +247,7 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
243
247
def levelOK (sym : Symbol )(implicit ctx : Context ): Boolean = levelOf.get(sym) match {
244
248
case Some (l) =>
245
249
l == level ||
246
- sym.is( Inline ) && sym.owner.is( Macro ) && sym.info.isValueType && l - 1 == level
250
+ l == 1 && level == 0 && isStage0Value(sym)
247
251
case None =>
248
252
! sym.is(Param ) || levelOK(sym.owner)
249
253
}
@@ -374,8 +378,8 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
374
378
else ref(defn.QuotedExpr_apply ).appliedToType(body1.tpe.widen).appliedTo(body1)
375
379
}
376
380
else body match {
377
- case body : RefTree if isCaptured(body, level + 1 ) =>
378
- if (body.symbol.is( Inline )) {
381
+ case body : RefTree if isCaptured(body.symbol , level + 1 ) =>
382
+ if (isStage0Value( body.symbol)) {
379
383
// Optimization: avoid the full conversion when capturing inlined `x`
380
384
// in '{ x } to '{ x$1.toExpr.unary_~ } and go directly to `x$1.toExpr`
381
385
liftValue(capturers(body.symbol)(body))
@@ -476,7 +480,7 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
476
480
val tpw = tree.tpe.widen
477
481
val argTpe =
478
482
if (tree.isType) defn.QuotedTypeType .appliedTo(tpw)
479
- else if (tree.symbol.is( Inline )) tpw // inlined term
483
+ else if (isStage0Value( tree.symbol)) tpw
480
484
else defn.QuotedExprType .appliedTo(tpw)
481
485
val selectArg = arg.select(nme.apply).appliedTo(Literal (Constant (i))).asInstance(argTpe)
482
486
val capturedArg = SyntheticValDef (UniqueName .fresh(tree.symbol.name.toTermName).toTermName, selectArg)
@@ -509,11 +513,11 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
509
513
}
510
514
511
515
/** Returns true if this tree will be captured by `makeLambda` */
512
- private def isCaptured (tree : RefTree , level : Int )(implicit ctx : Context ): Boolean = {
516
+ private def isCaptured (sym : Symbol , level : Int )(implicit ctx : Context ): Boolean = {
513
517
// Check phase consistency and presence of capturer
514
- ( (level == 1 && levelOf.get(tree.symbol ).contains(1 )) ||
515
- (level == 0 && tree.symbol.is( Inline ))
516
- ) && capturers.contains(tree.symbol )
518
+ ( (level == 1 && levelOf.get(sym ).contains(1 )) ||
519
+ (level == 0 && isStage0Value(sym ))
520
+ ) && capturers.contains(sym )
517
521
}
518
522
519
523
/** Transform `tree` and return the resulting tree and all `embedded` quotes
@@ -550,13 +554,13 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
550
554
splice(ref(splicedType).select(tpnme.UNARY_~ ))
551
555
case tree : Select if tree.symbol.isSplice =>
552
556
splice(tree)
553
- case tree : RefTree if isCaptured(tree, level) =>
557
+ case tree : RefTree if isCaptured(tree.symbol , level) =>
554
558
val capturer = capturers(tree.symbol)
555
559
def captureAndSplice (t : Tree ) =
556
560
splice(t.select(if (tree.isTerm) nme.UNARY_~ else tpnme.UNARY_~ ))
557
- if (tree.symbol.is( Inline ) && level == 0 ) capturer(tree)
558
- else if (tree.symbol.is( Inline )) captureAndSplice(liftValue( capturer(tree)) )
559
- else captureAndSplice(capturer(tree))
561
+ if (! isStage0Value( tree.symbol)) captureAndSplice( capturer(tree) )
562
+ else if (level == 0 ) capturer(tree)
563
+ else captureAndSplice(liftValue( capturer(tree) ))
560
564
case Block (stats, _) =>
561
565
val last = enteredSyms
562
566
stats.foreach(markDef)
@@ -626,6 +630,9 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
626
630
}
627
631
}
628
632
633
+ private def isStage0Value (sym : Symbol )(implicit ctx : Context ): Boolean =
634
+ sym.is(Inline ) && sym.owner.is(Macro ) && ! defn.isFunctionType(sym.info)
635
+
629
636
private def liftList (list : List [Tree ], tpe : Type )(implicit ctx : Context ): Tree = {
630
637
list.foldRight[Tree ](ref(defn.NilModule )) { (x, acc) =>
631
638
acc.select(" ::" .toTermName).appliedToType(tpe).appliedTo(x)
0 commit comments