@@ -493,32 +493,34 @@ class Inliner(call: tpd.Tree, rhs: tpd.Tree)(implicit ctx: Context) {
493
493
val expansion1 = InlineTyper .typed(expansion, pt)(inlineCtx)
494
494
495
495
/** Does given definition bind a closure that will be inlined? */
496
- def bindsDeadClosure (defn : ValOrDefDef ) = Ident (defn.symbol.termRef) match {
497
- case InlineableClosure (_) => ! InlineTyper .retainedClosures .contains(defn.symbol)
496
+ def bindsDeadInlineable (defn : ValOrDefDef ) = Ident (defn.symbol.termRef) match {
497
+ case InlineableArg (_) => ! InlineTyper .retainedInlineables .contains(defn.symbol)
498
498
case _ => false
499
499
}
500
500
501
501
/** All bindings in `bindingsBuf` except bindings of inlineable closures */
502
- val bindings = bindingsBuf.toList.filterNot(bindsDeadClosure ).map(_.withPos(call.pos))
502
+ val bindings = bindingsBuf.toList.filterNot(bindsDeadInlineable ).map(_.withPos(call.pos))
503
503
504
504
tpd.Inlined (call, bindings, expansion1)
505
505
}
506
506
}
507
507
508
- /** An extractor for references to closure arguments that refer to `@inline` methods */
509
- private object InlineableClosure {
508
+ /** An extractor for references to inlineable arguments. These are :
509
+ * - by-value arguments marked with `inline`
510
+ * - all by-name arguments
511
+ */
512
+ private object InlineableArg {
510
513
lazy val paramProxies = paramProxy.values.toSet
511
514
def unapply (tree : Ident )(implicit ctx : Context ): Option [Tree ] =
512
- if (paramProxies.contains(tree.tpe)) {
515
+ if (paramProxies.contains(tree.tpe))
513
516
bindingsBuf.find(_.name == tree.name) match {
514
- case Some (ddef : ValDef ) if ddef.symbol.is(Inline ) =>
515
- ddef.rhs match {
516
- case closure(_, meth, _) => Some (meth)
517
- case _ => None
518
- }
517
+ case Some (vdef : ValDef ) if vdef.symbol.is(Inline ) =>
518
+ Some (vdef.rhs.changeOwner(vdef.symbol, ctx.owner))
519
+ case Some (ddef : DefDef ) =>
520
+ Some (ddef.rhs.changeOwner(ddef.symbol, ctx.owner))
519
521
case _ => None
520
522
}
521
- } else None
523
+ else None
522
524
}
523
525
524
526
/** A typer for inlined code. Its purpose is:
@@ -530,16 +532,13 @@ class Inliner(call: tpd.Tree, rhs: tpd.Tree)(implicit ctx: Context) {
530
532
*/
531
533
private object InlineTyper extends ReTyper {
532
534
533
- var retainedClosures = Set [Symbol ]()
535
+ var retainedInlineables = Set [Symbol ]()
534
536
535
- override def typedIdent (tree : untpd.Ident , pt : Type )(implicit ctx : Context ) = {
536
- val tree1 = super .typedIdent(tree, pt)
537
- tree1 match {
538
- case InlineableClosure (_) => retainedClosures += tree.symbol
539
- case _ =>
537
+ override def typedIdent (tree : untpd.Ident , pt : Type )(implicit ctx : Context ) =
538
+ tree.asInstanceOf [tpd.Tree ] match {
539
+ case InlineableArg (rhs) => inlining.println(i " inline arg $tree -> $rhs" ); rhs
540
+ case _ => super .typedIdent(tree, pt)
540
541
}
541
- tree1
542
- }
543
542
544
543
override def typedSelect (tree : untpd.Select , pt : Type )(implicit ctx : Context ): Tree = {
545
544
assert(tree.hasType, tree)
@@ -562,12 +561,13 @@ class Inliner(call: tpd.Tree, rhs: tpd.Tree)(implicit ctx: Context) {
562
561
}
563
562
}
564
563
565
- override def typedApply (tree : untpd.Apply , pt : Type )(implicit ctx : Context ) = tree.asInstanceOf [tpd.Tree ] match {
566
- case Apply (Select (InlineableClosure (fn), nme.apply), args) =>
567
- inlining.println(i " reducing $tree with closure $fn" )
568
- typed(fn.appliedToArgs(args), pt)
569
- case _ =>
570
- super .typedApply(tree, pt)
571
- }
564
+ override def typedApply (tree : untpd.Apply , pt : Type )(implicit ctx : Context ) =
565
+ tree.asInstanceOf [tpd.Tree ] match {
566
+ case Apply (Select (InlineableArg (closure(_, fn, _)), nme.apply), args) =>
567
+ inlining.println(i " reducing $tree with closure $fn" )
568
+ typed(fn.appliedToArgs(args), pt)
569
+ case _ =>
570
+ super .typedApply(tree, pt)
571
+ }
572
572
}
573
573
}
0 commit comments