@@ -27,10 +27,20 @@ import collection.mutable
2727import transform .TypeUtils ._
2828import reporting .trace
2929import util .Positions .Position
30+ import util .Property
3031
3132object Inliner {
3233 import tpd ._
3334
35+ /** Marks an implicit reference found in the context (as opposed to the implicit scope)
36+ * from an inlineable body. Such references will be carried along with the body to
37+ * the expansion site.
38+ */
39+ private val ContextualImplicit = new Property .StickyKey [Unit ]
40+
41+ def markContextualImplicit (tree : Tree )(implicit ctx : Context ): Unit =
42+ methPart(tree).putAttachment(ContextualImplicit , ())
43+
3444 class InlineAccessors extends AccessProxies {
3545
3646 /** A tree map which inserts accessors for all non-public term members accessed
@@ -104,7 +114,7 @@ object Inliner {
104114 * to have the inlined method as owner.
105115 */
106116 def registerInlineInfo (
107- sym : SymDenotation , treeExpr : Context => Tree )(implicit ctx : Context ): Unit = {
117+ sym : SymDenotation , originalBody : untpd. Tree , treeExpr : Context => Tree )(implicit ctx : Context ): Unit = {
108118 sym.unforcedAnnotation(defn.BodyAnnot ) match {
109119 case Some (ann : ConcreteBodyAnnotation ) =>
110120 case Some (ann : LazyBodyAnnotation ) if ann.isEvaluated =>
@@ -173,10 +183,10 @@ object Inliner {
173183
174184/** Produces an inlined version of `call` via its `inlined` method.
175185 *
176- * @param call The original call to a `@inline` method
177- * @param rhs The body of the inline method that replaces the call.
186+ * @param call the original call to a `@inline` method
187+ * @param rhsToInline the body of the inline method that replaces the call.
178188 */
179- class Inliner (call : tpd.Tree , rhs : tpd.Tree )(implicit ctx : Context ) {
189+ class Inliner (call : tpd.Tree , rhsToInline : tpd.Tree )(implicit ctx : Context ) {
180190 import tpd ._
181191 import Inliner ._
182192
@@ -200,7 +210,7 @@ class Inliner(call: tpd.Tree, rhs: tpd.Tree)(implicit ctx: Context) {
200210 */
201211 private val paramProxy = new mutable.HashMap [Type , Type ]
202212
203- /** A map from the classes of (direct and outer) this references in `rhs `
213+ /** A map from the classes of (direct and outer) this references in `rhsToInline `
204214 * to references of their proxies.
205215 * Note that we can't index by the ThisType itself since there are several
206216 * possible forms to express what is logicaly the same ThisType. E.g.
@@ -315,7 +325,7 @@ class Inliner(call: tpd.Tree, rhs: tpd.Tree)(implicit ctx: Context) {
315325 if (! isIdempotentExpr(prefix)) registerType(meth.owner.thisType)
316326
317327 // Register types of all leaves of inlined body so that the `paramProxy` and `thisProxy` maps are defined.
318- rhs .foreachSubTree(registerLeaf)
328+ rhsToInline .foreachSubTree(registerLeaf)
319329
320330 // The class that the this-proxy `selfSym` represents
321331 def classOf (selfSym : Symbol ) = selfSym.info.widen.classSymbol
@@ -387,7 +397,7 @@ class Inliner(call: tpd.Tree, rhs: tpd.Tree)(implicit ctx: Context) {
387397 // the owner from the inlined method to the current owner.
388398 val inliner = new TreeTypeMap (typeMap, treeMap, meth :: Nil , ctx.owner :: Nil )(inlineCtx)
389399
390- val expansion = inliner(rhs .withPos(call.pos))
400+ val expansion = inliner(rhsToInline .withPos(call.pos))
391401 trace(i " inlining $call\n , BINDINGS = \n ${bindingsBuf.toList}% \n % \n EXPANSION = \n $expansion" , inlining, show = true ) {
392402
393403 // The final expansion runs a typing pass over the inlined tree. See InlineTyper for details.
0 commit comments