@@ -36,15 +36,6 @@ object Inliner {
36
36
37
37
val typedInline = true
38
38
39
- /** A key to be used in a context property that provides a map from enclosing implicit
40
- * value bindings to their right hand sides.
41
- */
42
- private val InlineBindings = new Property .Key [MutableSymbolMap [Tree ]]
43
-
44
- /** A map from the symbols of all enclosing inline value bindings to their right hand sides */
45
- def inlineBindings (implicit ctx : Context ): MutableSymbolMap [Tree ] =
46
- ctx.property(InlineBindings ).get
47
-
48
39
/** `sym` is an inline method with a known body to inline (note: definitions coming
49
40
* from Scala2x class files might be `@forceInline`, but still lack that body).
50
41
*/
@@ -120,12 +111,7 @@ object Inliner {
120
111
else if (enclosingInlineds.length < ctx.settings.XmaxInlines .value) {
121
112
val body = bodyToInline(tree.symbol) // can typecheck the tree and thereby produce errors
122
113
if (ctx.reporter.hasErrors) tree
123
- else {
124
- val inlinerCtx =
125
- if (ctx.property(InlineBindings ).isDefined) ctx
126
- else ctx.fresh.setProperty(InlineBindings , newMutableSymbolMap[Tree ])
127
- new Inliner (tree, body)(inlinerCtx).inlined(pt)
128
- }
114
+ else new Inliner (tree, body).inlined(pt)
129
115
}
130
116
else
131
117
errorTree(
@@ -218,7 +204,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
218
204
private val thisProxy = new mutable.HashMap [ClassSymbol , TermRef ]
219
205
220
206
/** A buffer for bindings that define proxies for actual arguments */
221
- private val bindingsBuf = new mutable.ListBuffer [MemberDef ]
207
+ private val bindingsBuf = new mutable.ListBuffer [ValOrDefDef ]
222
208
223
209
private def newSym (name : Name , flags : FlagSet , info : Type ): Symbol =
224
210
ctx.newSymbol(ctx.owner, name, flags, info, coord = call.pos)
@@ -233,7 +219,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
233
219
* @param bindingsBuf the buffer to which the definition should be appended
234
220
*/
235
221
private def paramBindingDef (name : Name , paramtp : Type , arg : Tree ,
236
- bindingsBuf : mutable.ListBuffer [MemberDef ]): MemberDef = {
222
+ bindingsBuf : mutable.ListBuffer [ValOrDefDef ]): ValOrDefDef = {
237
223
val argtpe = arg.tpe.dealiasKeepAnnots
238
224
val isByName = paramtp.dealias.isInstanceOf [ExprType ]
239
225
var inlineFlag = InlineProxy
@@ -431,26 +417,8 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
431
417
)(inlineCtx)
432
418
433
419
// Apply inliner to `rhsToInline`, split off any implicit bindings from result, and
434
- // make them part of `bindingsBuf`. The expansion is then the untyped tree that remains.
435
- val expansion = inliner.transform(rhsToInline.withPos(call.pos)) match {
436
- case Block (implicits, tpd.UntypedSplice (expansion)) =>
437
- val prevOwners = implicits.map(_.symbol.owner).distinct
438
- val localizer = new TreeTypeMap (oldOwners = prevOwners, newOwners = prevOwners.map(_ => ctx.owner))
439
- val (_, implicits1) = localizer.transformDefs(implicits)
440
- for (idef <- implicits1) {
441
- bindingsBuf += idef.withType(idef.symbol.typeRef).asInstanceOf [ValOrDefDef ]
442
- // Note: Substituting new symbols does not automatically lead to good prefixes
443
- // if the previous symbol was owned by a class. That's why we need to set the type
444
- // of `idef` explicitly. It would be nice if substituters were smarter, but
445
- // it seems non-trivial to come up with rules that work in all cases.
446
- inlineCtx.enter(idef.symbol)
447
- }
448
- expansion
449
- case tpd.UntypedSplice (expansion) =>
450
- expansion
451
- case expansion =>
452
- expansion
453
- }
420
+ // make them part of `bindingsBuf`. The expansion is then the tree that remains.
421
+ val expansion = inliner.transform(rhsToInline.withPos(call.pos))
454
422
455
423
def issueError () = callValueArgss match {
456
424
case (msgArg :: rest) :: Nil =>
@@ -512,7 +480,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
512
480
private object InlineableArg {
513
481
lazy val paramProxies = paramProxy.values.toSet
514
482
def unapply (tree : Trees .Ident [_])(implicit ctx : Context ): Option [Tree ] = {
515
- def search (buf : mutable.ListBuffer [MemberDef ]) = buf.find(_.name == tree.name)
483
+ def search (buf : mutable.ListBuffer [ValOrDefDef ]) = buf.find(_.name == tree.name)
516
484
if (paramProxies.contains(tree.typeOpt))
517
485
search(bindingsBuf) match {
518
486
case Some (vdef : ValDef ) if vdef.symbol.is(Inline ) =>
@@ -555,7 +523,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
555
523
case Apply (Select (cl @ closureDef(ddef), nme.apply), args) if defn.isFunctionType(cl.tpe) =>
556
524
ddef.tpe.widen match {
557
525
case mt : MethodType if ddef.vparamss.head.length == args.length =>
558
- val bindingsBuf = new mutable.ListBuffer [MemberDef ]
526
+ val bindingsBuf = new mutable.ListBuffer [ValOrDefDef ]
559
527
val argSyms = (mt.paramNames, mt.paramInfos, args).zipped.map { (name, paramtp, arg) =>
560
528
arg.tpe.dealias match {
561
529
case ref @ TermRef (NoPrefix , _) => ref.symbol
@@ -636,12 +604,12 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
636
604
/** Drop any side-effect-free bindings that are unused in expansion or other reachable bindings.
637
605
* Inline def bindings that are used only once.
638
606
*/
639
- def dropUnusedDefs (bindings : List [MemberDef ], tree : Tree )(implicit ctx : Context ): (List [MemberDef ], Tree ) = {
607
+ def dropUnusedDefs (bindings : List [ValOrDefDef ], tree : Tree )(implicit ctx : Context ): (List [ValOrDefDef ], Tree ) = {
640
608
val refCount = newMutableSymbolMap[Int ]
641
- val bindingOfSym = newMutableSymbolMap[MemberDef ]
609
+ val bindingOfSym = newMutableSymbolMap[ValOrDefDef ]
642
610
val dealiased = new java.util.IdentityHashMap [Type , Type ]()
643
611
644
- def isInlineable (binding : MemberDef ) = binding match {
612
+ def isInlineable (binding : ValOrDefDef ) = binding match {
645
613
case DefDef (_, Nil , Nil , _, _) => true
646
614
case vdef @ ValDef (_, _, _) => isPureExpr(vdef.rhs)
647
615
case _ => false
@@ -739,7 +707,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
739
707
}
740
708
741
709
val dealiasedTermBindings =
742
- termBindings.mapconserve(dealiasTypeBindings.transform).asInstanceOf [List [MemberDef ]]
710
+ termBindings.mapconserve(dealiasTypeBindings.transform).asInstanceOf [List [ValOrDefDef ]]
743
711
val dealiasedTree = dealiasTypeBindings.transform(tree)
744
712
745
713
val retained = dealiasedTermBindings.filterConserve(binding => retain(binding.symbol))
0 commit comments