@@ -36,15 +36,6 @@ object Inliner {
3636
3737 val typedInline = true
3838
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-
4839 /** `sym` is an inline method with a known body to inline (note: definitions coming
4940 * from Scala2x class files might be `@forceInline`, but still lack that body).
5041 */
@@ -120,12 +111,7 @@ object Inliner {
120111 else if (enclosingInlineds.length < ctx.settings.XmaxInlines .value) {
121112 val body = bodyToInline(tree.symbol) // can typecheck the tree and thereby produce errors
122113 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)
129115 }
130116 else
131117 errorTree(
@@ -218,7 +204,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
218204 private val thisProxy = new mutable.HashMap [ClassSymbol , TermRef ]
219205
220206 /** 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 ]
222208
223209 private def newSym (name : Name , flags : FlagSet , info : Type ): Symbol =
224210 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) {
233219 * @param bindingsBuf the buffer to which the definition should be appended
234220 */
235221 private def paramBindingDef (name : Name , paramtp : Type , arg : Tree ,
236- bindingsBuf : mutable.ListBuffer [MemberDef ]): MemberDef = {
222+ bindingsBuf : mutable.ListBuffer [ValOrDefDef ]): ValOrDefDef = {
237223 val argtpe = arg.tpe.dealiasKeepAnnots
238224 val isByName = paramtp.dealias.isInstanceOf [ExprType ]
239225 var inlineFlag = InlineProxy
@@ -431,26 +417,8 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
431417 )(inlineCtx)
432418
433419 // 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))
454422
455423 def issueError () = callValueArgss match {
456424 case (msgArg :: rest) :: Nil =>
@@ -512,7 +480,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
512480 private object InlineableArg {
513481 lazy val paramProxies = paramProxy.values.toSet
514482 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)
516484 if (paramProxies.contains(tree.typeOpt))
517485 search(bindingsBuf) match {
518486 case Some (vdef : ValDef ) if vdef.symbol.is(Inline ) =>
@@ -555,7 +523,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
555523 case Apply (Select (cl @ closureDef(ddef), nme.apply), args) if defn.isFunctionType(cl.tpe) =>
556524 ddef.tpe.widen match {
557525 case mt : MethodType if ddef.vparamss.head.length == args.length =>
558- val bindingsBuf = new mutable.ListBuffer [MemberDef ]
526+ val bindingsBuf = new mutable.ListBuffer [ValOrDefDef ]
559527 val argSyms = (mt.paramNames, mt.paramInfos, args).zipped.map { (name, paramtp, arg) =>
560528 arg.tpe.dealias match {
561529 case ref @ TermRef (NoPrefix , _) => ref.symbol
@@ -636,12 +604,12 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
636604 /** Drop any side-effect-free bindings that are unused in expansion or other reachable bindings.
637605 * Inline def bindings that are used only once.
638606 */
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 ) = {
640608 val refCount = newMutableSymbolMap[Int ]
641- val bindingOfSym = newMutableSymbolMap[MemberDef ]
609+ val bindingOfSym = newMutableSymbolMap[ValOrDefDef ]
642610 val dealiased = new java.util.IdentityHashMap [Type , Type ]()
643611
644- def isInlineable (binding : MemberDef ) = binding match {
612+ def isInlineable (binding : ValOrDefDef ) = binding match {
645613 case DefDef (_, Nil , Nil , _, _) => true
646614 case vdef @ ValDef (_, _, _) => isPureExpr(vdef.rhs)
647615 case _ => false
@@ -739,7 +707,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
739707 }
740708
741709 val dealiasedTermBindings =
742- termBindings.mapconserve(dealiasTypeBindings.transform).asInstanceOf [List [MemberDef ]]
710+ termBindings.mapconserve(dealiasTypeBindings.transform).asInstanceOf [List [ValOrDefDef ]]
743711 val dealiasedTree = dealiasTypeBindings.transform(tree)
744712
745713 val retained = dealiasedTermBindings.filterConserve(binding => retain(binding.symbol))
0 commit comments