@@ -32,7 +32,6 @@ import dotty.tools.dotc.core.quoted._
32
32
* val x2 = ???
33
33
* ...
34
34
* ~{ ... '{ ... x1 ... x2 ...} ... }
35
- * ~{ ... /* no references to xi */ ... }
36
35
* ...
37
36
* }
38
37
* ```
@@ -45,7 +44,6 @@ import dotty.tools.dotc.core.quoted._
45
44
* val x2 = ???
46
45
* ...
47
46
* Hole(0 | x1, x2)
48
- * Hole(1 | )
49
47
* ...
50
48
* ]],
51
49
* List(
@@ -54,8 +52,7 @@ import dotty.tools.dotc.core.quoted._
54
52
* val x2$1 = args(1).asInstanceOf[Expr[T]] // can be asInstanceOf[Type[T]]
55
53
* ...
56
54
* { ... '{ ... x1$1.unary_~ ... x2$1.unary_~ ...} ... }
57
- * },
58
- * { ... /* no references to xi */ ... } // optimized to not create lambda
55
+ * }
59
56
* )
60
57
* )
61
58
* ```
@@ -69,12 +66,12 @@ import dotty.tools.dotc.core.quoted._
69
66
* ```
70
67
* to
71
68
* ```
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]) => {
73
70
* val T1$1 = args(0).asInstanceOf[Type[T1]]
74
71
* ...
75
- * val x1$1 = args(.. ).asInstanceOf[X]
72
+ * val x1$1 = args(0 ).asInstanceOf[X]
76
73
* ...
77
- * val y1$1 = args(.. ).asInstanceOf[Expr[Y]]
74
+ * val y1$1 = args(1 ).asInstanceOf[Expr[Y]]
78
75
* ...
79
76
* { ... T1$1.unary_~ ... x ... '(y1$1.unary_~) ... }
80
77
* }
@@ -448,8 +445,6 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
448
445
* val y$1 = args(1).asInstanceOf[Expr[Any]] // or .asInstanceOf[Type[Any]]
449
446
* { ... '{ ... x$1.unary_~ ... y$1.unary_~ ... } ... }
450
447
* }
451
- * or if the spliced subexpression has no captures it will be transformed to
452
- * { ... '{ ... x$1.unary_~ ... y$1.unary_~ ... } ... }
453
448
*
454
449
* See: `capture`
455
450
*
@@ -462,19 +457,6 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
462
457
* }
463
458
*/
464
459
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
- }
478
460
def body (arg : Tree )(implicit ctx : Context ): Tree = {
479
461
var i = 0
480
462
transformWithCapturer(tree)(
@@ -502,10 +484,18 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
502
484
val lambdaOwner = ctx.owner.ownersIterator.find(o => levelOf.getOrElse(o, level) == level).get
503
485
val tpe = MethodType (defn.SeqType .appliedTo(defn.AnyType ) :: Nil , tree.tpe.widen)
504
486
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
+ }
506
489
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)
509
499
}
510
500
511
501
/** Returns true if this tree will be captured by `makeLambda` */
0 commit comments