@@ -237,7 +237,7 @@ class ReifyQuotes extends MacroTransformWithImplicits {
237
237
def levelOK (sym : Symbol )(implicit ctx : Context ): Boolean = levelOf.get(sym) match {
238
238
case Some (l) =>
239
239
l == level ||
240
- l == 0 && level == - 1 && isStageNegOneValue( sym)
240
+ level == - 1 && sym == defn. TastyTopLevelSplice_tastyContext
241
241
case None =>
242
242
! sym.is(Param ) || levelOK(sym.owner)
243
243
}
@@ -371,18 +371,12 @@ class ReifyQuotes extends MacroTransformWithImplicits {
371
371
}
372
372
else body match {
373
373
case body : RefTree if isCaptured(body.symbol, level + 1 ) =>
374
- if (isStageNegOneValue(body.symbol)) {
375
- // Optimization: avoid the full conversion when capturing inlined `x`
376
- // in '{ x } to '{ x$1.toExpr.unary_~ } and go directly to `x$1.toExpr`
377
- liftInlineParamValue(capturers(body.symbol)(body))
378
- } else {
379
- // Optimization: avoid the full conversion when capturing `x`
380
- // in '{ x } to '{ x$1.unary_~ } and go directly to `x$1`
381
- capturers(body.symbol)(body)
382
- }
374
+ // Optimization: avoid the full conversion when capturing `x`
375
+ // in '{ x } to '{ x$1.unary_~ } and go directly to `x$1`
376
+ capturers(body.symbol)(body)
383
377
case _=>
384
378
val (body1, splices) = nested(isQuote = true ).split(body)
385
- if (level >= 0 ) pickledQuote(body1, splices, body.tpe, isType).withPos(quote.pos)
379
+ if (level == 0 && ! ctx.inTransparentMethod ) pickledQuote(body1, splices, body.tpe, isType).withPos(quote.pos)
386
380
else {
387
381
// In top-level splice in an transparent def. Keep the tree as it is, it will be transformed at inline site.
388
382
body
@@ -476,7 +470,6 @@ class ReifyQuotes extends MacroTransformWithImplicits {
476
470
val tpw = tree.tpe.widen
477
471
val argTpe =
478
472
if (tree.isType) defn.QuotedTypeType .appliedTo(tpw)
479
- else if (isStageNegOneValue(tree.symbol)) tpw
480
473
else defn.QuotedExprType .appliedTo(tpw)
481
474
val selectArg = arg.select(nme.apply).appliedTo(Literal (Constant (i))).asInstance(argTpe)
482
475
val capturedArg = SyntheticValDef (UniqueName .fresh(tree.symbol.name.toTermName).toTermName, selectArg)
@@ -501,21 +494,17 @@ class ReifyQuotes extends MacroTransformWithImplicits {
501
494
val captured = mutable.LinkedHashMap .empty[Symbol , Tree ]
502
495
val captured2 = capturer(captured)
503
496
504
- outer.enteredSyms.foreach(sym => capturers.put(sym, captured2))
497
+ outer.enteredSyms.foreach(sym => if ( ! sym.is( Transparent )) capturers.put(sym, captured2))
505
498
506
499
val tree2 = transform(tree)
507
500
capturers --= outer.enteredSyms
508
501
509
502
seq(captured.result().valuesIterator.toList, tree2)
510
503
}
511
504
512
- /** Returns true if this tree will be captured by `makeLambda` */
513
- private def isCaptured (sym : Symbol , level : Int )(implicit ctx : Context ): Boolean = {
514
- // Check phase consistency and presence of capturer
515
- ( (level == 1 && levelOf.get(sym).contains(1 )) ||
516
- (level == 0 && isStageNegOneValue(sym))
517
- ) && capturers.contains(sym)
518
- }
505
+ /** Returns true if this tree will be captured by `makeLambda`. Checks phase consistency and presence of capturer. */
506
+ private def isCaptured (sym : Symbol , level : Int )(implicit ctx : Context ): Boolean =
507
+ level == 1 && levelOf.get(sym).contains(1 ) && capturers.contains(sym)
519
508
520
509
/** Transform `tree` and return the resulting tree and all `embedded` quotes
521
510
* or splices as a pair, after performing the `addTags` transform.
@@ -551,13 +540,11 @@ class ReifyQuotes extends MacroTransformWithImplicits {
551
540
splice(ref(splicedType).select(tpnme.UNARY_~ ).withPos(tree.pos))
552
541
case tree : Select if tree.symbol.isSplice =>
553
542
splice(tree)
543
+ case tree : RefTree if tree.symbol.is(Transparent ) && tree.symbol.is(Param ) =>
544
+ tree
554
545
case tree : RefTree if isCaptured(tree.symbol, level) =>
555
- val capturer = capturers(tree.symbol)
556
- def captureAndSplice (t : Tree ) =
557
- splice(t.select(if (tree.isTerm) nme.UNARY_~ else tpnme.UNARY_~ ))
558
- if (! isStageNegOneValue(tree.symbol)) captureAndSplice(capturer(tree))
559
- else if (level == 0 ) capturer(tree)
560
- else captureAndSplice(liftInlineParamValue(capturer(tree)))
546
+ val t = capturers(tree.symbol).apply(tree)
547
+ splice(t.select(if (tree.isTerm) nme.UNARY_~ else tpnme.UNARY_~ ))
561
548
case Block (stats, _) =>
562
549
val last = enteredSyms
563
550
stats.foreach(markDef)
@@ -601,28 +588,6 @@ class ReifyQuotes extends MacroTransformWithImplicits {
601
588
}
602
589
}
603
590
604
- /** Takes a reference to an transparent parameter `tree` and lifts it to an Expr */
605
- private def liftInlineParamValue (tree : Tree )(implicit ctx : Context ): Tree = {
606
- val tpSym = tree.tpe.widenDealias.classSymbol
607
-
608
- val lifter =
609
- if (tpSym eq defn.BooleanClass ) defn.QuotedLiftable_BooleanIsLiftable
610
- else if (tpSym eq defn.ByteClass ) defn.QuotedLiftable_ByteIsLiftable
611
- else if (tpSym eq defn.CharClass ) defn.QuotedLiftable_CharIsLiftable
612
- else if (tpSym eq defn.ShortClass ) defn.QuotedLiftable_ShortIsLiftable
613
- else if (tpSym eq defn.IntClass ) defn.QuotedLiftable_IntIsLiftable
614
- else if (tpSym eq defn.LongClass ) defn.QuotedLiftable_LongIsLiftable
615
- else if (tpSym eq defn.FloatClass ) defn.QuotedLiftable_FloatIsLiftable
616
- else if (tpSym eq defn.DoubleClass ) defn.QuotedLiftable_DoubleIsLiftable
617
- else defn.QuotedLiftable_StringIsLiftable
618
-
619
- ref(lifter).select(" toExpr" .toTermName).appliedTo(tree)
620
- }
621
-
622
- private def isStageNegOneValue (sym : Symbol )(implicit ctx : Context ): Boolean =
623
- (sym.is(Transparent ) && sym.owner.is(Transparent ) && ! defn.isFunctionType(sym.info)) ||
624
- sym == defn.TastyTopLevelSplice_tastyContext // intrinsic value at stage 0
625
-
626
591
private def liftList (list : List [Tree ], tpe : Type )(implicit ctx : Context ): Tree = {
627
592
list.foldRight[Tree ](ref(defn.NilModule )) { (x, acc) =>
628
593
acc.select(" ::" .toTermName).appliedToType(tpe).appliedTo(x)
0 commit comments