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