@@ -32,6 +32,15 @@ import util.Property
32
32
object Inliner {
33
33
import tpd ._
34
34
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
+
35
44
class InlineAccessors extends AccessProxies {
36
45
37
46
/** A tree map which inserts accessors for all non-public term members accessed
@@ -144,10 +153,11 @@ object Inliner {
144
153
val nameAtPos = mutable.Map [Position , Name ]()
145
154
val implicitSyms = mutable.Set [Symbol ]()
146
155
val implicitRefs = new mutable.ListBuffer [Tree ]
147
- def registerIfImplicit (tree : Tree ) = tree match {
156
+ def registerIfContextualImplicit (tree : Tree ) = tree match {
148
157
case tree : RefTree
149
- if tree.pos.start == tree.pos.end && tree.symbol.is(Implicit ) &&
150
- isExternal(tree.symbol) && ! implicitSyms.contains(tree.symbol) =>
158
+ if tree.removeAttachment(ContextualImplicit ).isDefined &&
159
+ isExternal(tree.symbol) &&
160
+ ! implicitSyms.contains(tree.symbol) =>
151
161
if (tree.existsSubTree(t => isLocal(tree.symbol, inlineMethod)))
152
162
ctx.warning(" implicit reference $tree is dropped at inline site because it refers to local symbol(s)" , tree.pos)
153
163
else {
@@ -169,7 +179,7 @@ object Inliner {
169
179
nameAtPos(tree.pos.toSynthetic) = tree.symbol.name
170
180
case _ =>
171
181
}
172
- registerIfImplicit (tree)
182
+ registerIfContextualImplicit (tree)
173
183
traverseChildren(tree)
174
184
}
175
185
}
@@ -521,21 +531,18 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
521
531
522
532
trace(i " inlining $call\n , BINDINGS = \n ${bindingsBuf.toList}% \n % \n EXPANSION = \n $expansion" , inlining, show = true ) {
523
533
524
- // println(i"body = $rhsToInline")
525
- // println(i"expansion = $expansion")
534
+ // println(i"body = $rhsToInline")
526
535
527
536
// The final expansion runs a typing pass over the inlined tree. See InlineTyper for details.
528
537
val expansion1 = inlineTyper.typed(expansion, pt)(inlineCtx)
529
538
530
- // println(i"typed expansion = $expansion1")
531
-
532
539
/** All bindings in `bindingsBuf` except bindings of inlineable closures */
533
540
val bindings = bindingsBuf.toList.map(_.withPos(call.pos))
534
541
535
- val (finalBindings, finalExpansion) = dropUnusedDefs(bindings, expansion1)
542
+ inlining.println(i " original bindings = $bindings% \n % " )
543
+ inlining.println(i " original expansion = $expansion1" )
536
544
537
- // println(i"bindings buf = ${bindingsBuf.toList}%; %")
538
- // println(i"bindings = ${bindings.toList}%; %")
545
+ val (finalBindings, finalExpansion) = dropUnusedDefs(bindings, expansion1)
539
546
540
547
tpd.Inlined (call, finalBindings, finalExpansion)
541
548
}
0 commit comments