@@ -225,7 +225,7 @@ class ReifyQuotes extends MacroTransformWithImplicits {
225
225
def levelOK (sym : Symbol )(implicit ctx : Context ): Boolean = levelOf.get(sym) match {
226
226
case Some (l) =>
227
227
l == level ||
228
- l == 0 && level == - 1 && isStageNegOneValue( sym)
228
+ level == - 1 && sym == defn. TastyTopLevelSplice_tastyContext
229
229
case None =>
230
230
! sym.is(Param ) || levelOK(sym.owner)
231
231
}
@@ -355,18 +355,12 @@ class ReifyQuotes extends MacroTransformWithImplicits {
355
355
}
356
356
else body match {
357
357
case body : RefTree if isCaptured(body.symbol, level + 1 ) =>
358
- if (isStageNegOneValue(body.symbol)) {
359
- // Optimization: avoid the full conversion when capturing inlined `x`
360
- // in '{ x } to '{ x$1.toExpr.unary_~ } and go directly to `x$1.toExpr`
361
- liftInlineParamValue(capturers(body.symbol)(body))
362
- } else {
363
- // Optimization: avoid the full conversion when capturing `x`
364
- // in '{ x } to '{ x$1.unary_~ } and go directly to `x$1`
365
- capturers(body.symbol)(body)
366
- }
358
+ // Optimization: avoid the full conversion when capturing `x`
359
+ // in '{ x } to '{ x$1.unary_~ } and go directly to `x$1`
360
+ capturers(body.symbol)(body)
367
361
case _=>
368
362
val (body1, splices) = nested(isQuote = true ).split(body)
369
- if (level >= 0 ) pickledQuote(body1, splices, body.tpe, isType).withPos(quote.pos)
363
+ if (level == 0 && ! ctx.owner.ownersIterator.exists(_.isTransparentMethod) ) pickledQuote(body1, splices, body.tpe, isType).withPos(quote.pos)
370
364
else {
371
365
// In top-level splice in an transparent def. Keep the tree as it is, it will be transformed at inline site.
372
366
body
@@ -474,7 +468,6 @@ class ReifyQuotes extends MacroTransformWithImplicits {
474
468
val tpw = tree.tpe.widen
475
469
val argTpe =
476
470
if (tree.isType) defn.QuotedTypeType .appliedTo(tpw)
477
- else if (isStageNegOneValue(tree.symbol)) tpw
478
471
else defn.QuotedExprType .appliedTo(tpw)
479
472
val selectArg = arg.select(nme.apply).appliedTo(Literal (Constant (i))).asInstance(argTpe)
480
473
val capturedArg = SyntheticValDef (UniqueName .fresh(tree.symbol.name.toTermName).toTermName, selectArg)
@@ -499,21 +492,17 @@ class ReifyQuotes extends MacroTransformWithImplicits {
499
492
val captured = mutable.LinkedHashMap .empty[Symbol , Tree ]
500
493
val captured2 = capturer(captured)
501
494
502
- outer.enteredSyms.foreach(sym => capturers.put(sym, captured2))
495
+ outer.enteredSyms.foreach(sym => if ( ! sym.is( Transparent )) capturers.put(sym, captured2))
503
496
504
497
val tree2 = transform(tree)
505
498
capturers --= outer.enteredSyms
506
499
507
500
seq(captured.result().valuesIterator.toList, tree2)
508
501
}
509
502
510
- /** Returns true if this tree will be captured by `makeLambda` */
511
- private def isCaptured (sym : Symbol , level : Int )(implicit ctx : Context ): Boolean = {
512
- // Check phase consistency and presence of capturer
513
- ( (level == 1 && levelOf.get(sym).contains(1 )) ||
514
- (level == 0 && isStageNegOneValue(sym))
515
- ) && capturers.contains(sym)
516
- }
503
+ /** Returns true if this tree will be captured by `makeLambda`. Checks phase consistency and presence of capturer. */
504
+ private def isCaptured (sym : Symbol , level : Int )(implicit ctx : Context ): Boolean =
505
+ level == 1 && levelOf.get(sym).contains(1 ) && capturers.contains(sym) //
517
506
518
507
/** Transform `tree` and return the resulting tree and all `embedded` quotes
519
508
* or splices as a pair, after performing the `addTags` transform.
@@ -549,13 +538,11 @@ class ReifyQuotes extends MacroTransformWithImplicits {
549
538
splice(ref(splicedType).select(tpnme.UNARY_~ ).withPos(tree.pos))
550
539
case tree : Select if tree.symbol.isSplice =>
551
540
splice(tree)
541
+ case tree : RefTree if tree.symbol.is(Transparent ) && tree.symbol.is(Param ) =>
542
+ tree
552
543
case tree : RefTree if isCaptured(tree.symbol, level) =>
553
- val capturer = capturers(tree.symbol)
554
- def captureAndSplice (t : Tree ) =
555
- splice(t.select(if (tree.isTerm) nme.UNARY_~ else tpnme.UNARY_~ ))
556
- if (! isStageNegOneValue(tree.symbol)) captureAndSplice(capturer(tree))
557
- else if (level == 0 ) capturer(tree)
558
- else captureAndSplice(liftInlineParamValue(capturer(tree)))
544
+ val t = capturers(tree.symbol).apply(tree)
545
+ splice(t.select(if (tree.isTerm) nme.UNARY_~ else tpnme.UNARY_~ ))
559
546
case Block (stats, _) =>
560
547
val last = enteredSyms
561
548
stats.foreach(markDef)
@@ -570,28 +557,6 @@ class ReifyQuotes extends MacroTransformWithImplicits {
570
557
}
571
558
}
572
559
573
- /** Takes a reference to an transparent parameter `tree` and lifts it to an Expr */
574
- private def liftInlineParamValue (tree : Tree )(implicit ctx : Context ): Tree = {
575
- val tpSym = tree.tpe.widenDealias.classSymbol
576
-
577
- val lifter =
578
- if (tpSym eq defn.BooleanClass ) defn.QuotedLiftable_BooleanIsLiftable
579
- else if (tpSym eq defn.ByteClass ) defn.QuotedLiftable_ByteIsLiftable
580
- else if (tpSym eq defn.CharClass ) defn.QuotedLiftable_CharIsLiftable
581
- else if (tpSym eq defn.ShortClass ) defn.QuotedLiftable_ShortIsLiftable
582
- else if (tpSym eq defn.IntClass ) defn.QuotedLiftable_IntIsLiftable
583
- else if (tpSym eq defn.LongClass ) defn.QuotedLiftable_LongIsLiftable
584
- else if (tpSym eq defn.FloatClass ) defn.QuotedLiftable_FloatIsLiftable
585
- else if (tpSym eq defn.DoubleClass ) defn.QuotedLiftable_DoubleIsLiftable
586
- else defn.QuotedLiftable_StringIsLiftable
587
-
588
- ref(lifter).select(" toExpr" .toTermName).appliedTo(tree)
589
- }
590
-
591
- private def isStageNegOneValue (sym : Symbol )(implicit ctx : Context ): Boolean =
592
- (sym.is(Transparent ) && sym.owner.is(Transparent ) && ! defn.isFunctionType(sym.info)) ||
593
- sym == defn.TastyTopLevelSplice_tastyContext // intrinsic value at stage 0
594
-
595
560
private def liftList (list : List [Tree ], tpe : Type )(implicit ctx : Context ): Tree = {
596
561
list.foldRight[Tree ](ref(defn.NilModule )) { (x, acc) =>
597
562
acc.select(" ::" .toTermName).appliedToType(tpe).appliedTo(x)
0 commit comments