Skip to content

Commit a5db091

Browse files
oderskyallanrenucci
authored andcommitted
Track inline proxies
Track proxies of inline arguments with a flag. Note: Some of the optimizations of the inliner don't update the defTree of the argument symbol even if they change the definition. But most of these optimizations will go away anyway. We should review once the inliner stabilizes.
1 parent d1ce179 commit a5db091

File tree

6 files changed

+22
-7
lines changed

6 files changed

+22
-7
lines changed

compiler/src/dotty/tools/dotc/core/Flags.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,9 @@ object Flags {
351351
/** A bridge method. Set by Erasure */
352352
final val Bridge = termFlag(34, "<bridge>")
353353

354+
/** A proxy for an argument to an inline method */
355+
final val InlineProxy = termFlag(35, "<inline proxy>")
356+
354357
/** Symbol is a method which should be marked ACC_SYNCHRONIZED */
355358
final val Synchronized = termFlag(36, "<synchronized>")
356359

@@ -545,6 +548,9 @@ object Flags {
545548
/** Either method or lazy or deferred */
546549
final val MethodOrLazyOrDeferred = Method | Lazy | Deferred
547550

551+
/** An inline method or inline argument proxy */
552+
final val InlineOrProxy = Inline | InlineProxy
553+
548554
/** Assumed to be pure */
549555
final val StableOrErased = Stable | Erased
550556

compiler/src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,8 @@ object Symbols {
447447
*/
448448
def retainsDefTree(implicit ctx: Context): Boolean =
449449
ctx.settings.YretainTrees.value ||
450-
denot.owner.isTerm || // no risk of leaking memory after a run for these
451-
denot.is(Inline) // need to keep inline info
450+
denot.owner.isTerm || // no risk of leaking memory after a run for these
451+
denot.is(InlineOrProxy) // need to keep inline info
452452

453453
/** The last denotation of this symbol */
454454
private[this] var lastDenot: SymDenotation = _

compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ Standard-Section: "ASTs" TopLevelStat*
186186
OVERRIDE
187187
INLINE
188188
MACRO // inline method containing toplevel splices
189+
INLINEPROXY // symbol of binding representing an inline parameter
189190
STATIC // mapped to static Java member
190191
OBJECT // an object or its class
191192
TRAIT // a trait
@@ -299,7 +300,7 @@ object TastyFormat {
299300
final val IMPLICIT = 13
300301
final val LAZY = 14
301302
final val OVERRIDE = 15
302-
303+
final val INLINEPROXY = 16
303304
final val INLINE = 17
304305
final val STATIC = 18
305306
final val OBJECT = 19
@@ -483,6 +484,7 @@ object TastyFormat {
483484
| LAZY
484485
| OVERRIDE
485486
| INLINE
487+
| INLINEPROXY
486488
| MACRO
487489
| STATIC
488490
| OBJECT
@@ -540,6 +542,7 @@ object TastyFormat {
540542
case LAZY => "LAZY"
541543
case OVERRIDE => "OVERRIDE"
542544
case INLINE => "INLINE"
545+
case INLINEPROXY => "INLINEPROXY"
543546
case MACRO => "MACRO"
544547
case STATIC => "STATIC"
545548
case OBJECT => "OBJECT"

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ class TreePickler(pickler: TastyPickler) {
620620
if (flags is Case) writeByte(CASE)
621621
if (flags is Override) writeByte(OVERRIDE)
622622
if (flags is Inline) writeByte(INLINE)
623+
if (flags is InlineProxy) writeByte(INLINEPROXY)
623624
if (flags is Macro) writeByte(MACRO)
624625
if (flags is JavaStatic) writeByte(STATIC)
625626
if (flags is Module) writeByte(OBJECT)

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ class TreeUnpickler(reader: TastyReader,
599599
case LAZY => addFlag(Lazy)
600600
case OVERRIDE => addFlag(Override)
601601
case INLINE => addFlag(Inline)
602+
case INLINEPROXY => addFlag(InlineProxy)
602603
case MACRO => addFlag(Macro)
603604
case STATIC => addFlag(JavaStatic)
604605
case OBJECT => addFlag(Module)

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,16 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
236236
bindingsBuf: mutable.ListBuffer[MemberDef]): MemberDef = {
237237
val argtpe = arg.tpe.dealiasKeepAnnots
238238
val isByName = paramtp.dealias.isInstanceOf[ExprType]
239-
val inlineFlag = if (paramtp.hasAnnotation(defn.InlineParamAnnot)) Inline else EmptyFlags
239+
var inlineFlag = InlineProxy
240+
if (paramtp.hasAnnotation(defn.InlineParamAnnot)) inlineFlag |= Inline
240241
val (bindingFlags, bindingType) =
241-
if (isByName) (Method, ExprType(argtpe.widen))
242+
if (isByName) (Method | InlineProxy, ExprType(argtpe.widen))
242243
else (inlineFlag, argtpe.widen)
243244
val boundSym = newSym(name, bindingFlags, bindingType).asTerm
244245
val binding =
245246
if (isByName) DefDef(boundSym, arg.changeOwner(ctx.owner, boundSym))
246247
else ValDef(boundSym, arg)
248+
boundSym.defTree = binding
247249
bindingsBuf += binding
248250
binding
249251
}
@@ -295,7 +297,9 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
295297
ref(rhsClsSym.sourceModule)
296298
else
297299
inlineCallPrefix
298-
bindingsBuf += ValDef(selfSym.asTerm, rhs)
300+
val binding = ValDef(selfSym.asTerm, rhs)
301+
bindingsBuf += binding
302+
selfSym.defTree = binding
299303
inlining.println(i"proxy at $level: $selfSym = ${bindingsBuf.last}")
300304
lastSelf = selfSym
301305
lastLevel = level
@@ -323,7 +327,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
323327
case tpe: ThisType if !canElideThis(tpe) && !thisProxy.contains(tpe.cls) =>
324328
val proxyName = s"${tpe.cls.name}_this".toTermName
325329
val proxyType = tpe.asSeenFrom(inlineCallPrefix.tpe, inlinedMethod.owner)
326-
thisProxy(tpe.cls) = newSym(proxyName, Synthetic, proxyType).termRef
330+
thisProxy(tpe.cls) = newSym(proxyName, InlineProxy, proxyType).termRef
327331
if (!tpe.cls.isStaticOwner)
328332
registerType(inlinedMethod.owner.thisType) // make sure we have a base from which to outer-select
329333
case tpe: NamedType

0 commit comments

Comments
 (0)