@@ -32,7 +32,6 @@ import dotty.tools.dotc.core.quoted._
3232 * val x2 = ???
3333 * ...
3434 * ~{ ... '{ ... x1 ... x2 ...} ... }
35- * ~{ ... /* no references to xi */ ... }
3635 * ...
3736 * }
3837 * ```
@@ -45,7 +44,6 @@ import dotty.tools.dotc.core.quoted._
4544 * val x2 = ???
4645 * ...
4746 * Hole(0 | x1, x2)
48- * Hole(1 | )
4947 * ...
5048 * ]],
5149 * List(
@@ -54,8 +52,7 @@ import dotty.tools.dotc.core.quoted._
5452 * val x2$1 = args(1).asInstanceOf[Expr[T]] // can be asInstanceOf[Type[T]]
5553 * ...
5654 * { ... '{ ... x1$1.unary_~ ... x2$1.unary_~ ...} ... }
57- * },
58- * { ... /* no references to xi */ ... } // optimized to not create lambda
55+ * }
5956 * )
6057 * )
6158 * ```
@@ -69,12 +66,12 @@ import dotty.tools.dotc.core.quoted._
6966 * ```
7067 * to
7168 * ```
72- * inline def foo[T1, ...](inline x1: X, ..., y1: Y, ....): Object = { (args: Seq[Any]) => {
69+ * inline def foo[T1, ...](inline x1: X, ..., y1: Y, ....): Seq[Any] => Object = { (args: Seq[Any]) => {
7370 * val T1$1 = args(0).asInstanceOf[Type[T1]]
7471 * ...
75- * val x1$1 = args(.. ).asInstanceOf[X]
72+ * val x1$1 = args(0 ).asInstanceOf[X]
7673 * ...
77- * val y1$1 = args(.. ).asInstanceOf[Expr[Y]]
74+ * val y1$1 = args(1 ).asInstanceOf[Expr[Y]]
7875 * ...
7976 * { ... T1$1.unary_~ ... x ... '(y1$1.unary_~) ... }
8077 * }
@@ -448,8 +445,6 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
448445 * val y$1 = args(1).asInstanceOf[Expr[Any]] // or .asInstanceOf[Type[Any]]
449446 * { ... '{ ... x$1.unary_~ ... y$1.unary_~ ... } ... }
450447 * }
451- * or if the spliced subexpression has no captures it will be transformed to
452- * { ... '{ ... x$1.unary_~ ... y$1.unary_~ ... } ... }
453448 *
454449 * See: `capture`
455450 *
@@ -462,19 +457,6 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
462457 * }
463458 */
464459 private def makeLambda (tree : Tree )(implicit ctx : Context ): Tree = {
465- var treeWithoutCaptures : Tree = null
466- def transformWithCapturer (tree : Tree )(capturer : mutable.Map [Symbol , Tree ] => Tree => Tree )(implicit ctx : Context ): Tree = {
467- val captured = mutable.LinkedHashMap .empty[Symbol , Tree ]
468- val captured2 = capturer(captured)
469- outer.enteredSyms.foreach(s => capturers.put(s, captured2))
470- if (ctx.owner.owner.is(Macro ))
471- outer.enteredSyms.reverse.foreach(s => captured2(ref(s)))
472- val tree2 = transform(tree)
473- capturers --= outer.enteredSyms
474- if (captured.isEmpty)
475- treeWithoutCaptures = tree2
476- seq(captured.result().valuesIterator.toList, tree2)
477- }
478460 def body (arg : Tree )(implicit ctx : Context ): Tree = {
479461 var i = 0
480462 transformWithCapturer(tree)(
@@ -502,10 +484,18 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
502484 val lambdaOwner = ctx.owner.ownersIterator.find(o => levelOf.getOrElse(o, level) == level).get
503485 val tpe = MethodType (defn.SeqType .appliedTo(defn.AnyType ) :: Nil , tree.tpe.widen)
504486 val meth = ctx.newSymbol(lambdaOwner, UniqueName .fresh(nme.ANON_FUN ), Synthetic | Method , tpe)
505- val closure = Closure (meth, tss => body(tss.head.head)(ctx.withOwner(meth)).changeOwner(ctx.owner, meth))
487+ Closure (meth, tss => body(tss.head.head)(ctx.withOwner(meth)).changeOwner(ctx.owner, meth))
488+ }
506489
507- if (treeWithoutCaptures == null || ctx.owner.is(Macro )) closure
508- else treeWithoutCaptures
490+ private def transformWithCapturer (tree : Tree )(capturer : mutable.Map [Symbol , Tree ] => Tree => Tree )(implicit ctx : Context ): Tree = {
491+ val captured = mutable.LinkedHashMap .empty[Symbol , Tree ]
492+ val captured2 = capturer(captured)
493+ outer.enteredSyms.foreach(s => capturers.put(s, captured2))
494+ if (ctx.owner.owner.is(Macro ))
495+ outer.enteredSyms.reverse.foreach(s => captured2(ref(s)))
496+ val tree2 = transform(tree)
497+ capturers --= outer.enteredSyms
498+ seq(captured.result().valuesIterator.toList, tree2)
509499 }
510500
511501 /** Returns true if this tree will be captured by `makeLambda` */
0 commit comments