@@ -56,7 +56,7 @@ object Inlines:
56
56
57
57
/** Can a call to method `meth` be inlined? */
58
58
def isInlineable (meth : Symbol )(using Context ): Boolean =
59
- meth.is( Inline ) && meth.hasAnnotation(defn.BodyAnnot ) && ! inInlineMethod
59
+ meth.isInlineMethod && meth.hasAnnotation(defn.BodyAnnot ) && ! inInlineMethod
60
60
61
61
def isInlineableFromInlineTrait (inlinedTraitSym : ClassSymbol , member : tpd.Tree )(using Context ): Boolean =
62
62
! (member.isInstanceOf [tpd.TypeDef ] && inlinedTraitSym.typeParams.contains(member.symbol))
@@ -72,15 +72,19 @@ object Inlines:
72
72
)
73
73
&& ! ctx.typer.hasInliningErrors
74
74
&& ! ctx.base.stopInlining
75
+ && ! ctx.owner.isInlineTrait
75
76
76
77
tree match
77
78
case Block (_, expr) =>
78
79
needsInlining(expr)
79
80
case tdef @ TypeDef (_, impl : Template ) =>
80
- ! tdef.symbol.isInlineTrait && impl.parents.exists(_.symbol .isInlineTrait) && isInlineableInCtx
81
+ ! tdef.symbol.isInlineTrait && impl.parents.map(symbolFromParent). exists(_.isInlineTrait) && isInlineableInCtx
81
82
case _ =>
82
83
isInlineable(tree.symbol) && ! tree.tpe.widenTermRefExpr.isInstanceOf [MethodOrPoly ] && isInlineableInCtx
83
84
85
+ private def symbolFromParent (parent : Tree )(using Context ): Symbol =
86
+ if parent.symbol.isConstructor then parent.symbol.owner else parent.symbol
87
+
84
88
private def needsTransparentInlining (tree : Tree )(using Context ): Boolean =
85
89
tree.symbol.is(Transparent )
86
90
|| ctx.mode.is(Mode .ForceInline )
@@ -184,10 +188,22 @@ object Inlines:
184
188
tree2
185
189
end inlineCall
186
190
187
- def inlineParentTrait (parent : tpd.Tree , overriddenDecls : Set [Symbol ])(using Context ): List [Tree ] =
188
- val traitSym = if parent.symbol.isConstructor then parent.symbol.owner else parent.symbol
189
- if traitSym.isInlineTrait then InlineParentTrait (parent, traitSym.asClass).expandDefs(overriddenDecls)
190
- else Nil
191
+ def inlineParentInlineTraits (cls : Tree )(using Context ): Tree =
192
+ cls match {
193
+ case cls @ TypeDef (_, impl : Template ) =>
194
+ val overriddenSyms = cls.symbol.info.decls.toList.flatMap(_.allOverriddenSymbols).toSet
195
+ val inlineDefs = impl.parents.flatMap(
196
+ parent =>
197
+ if symbolFromParent(parent).isInlineTrait then
198
+ InlineParentTrait (parent)(using ctx.withOwner(cls.symbol)).expandDefs(overriddenSyms)
199
+ else
200
+ Nil
201
+ )
202
+ val impl1 = cpy.Template (impl)(body = inlineDefs ::: impl.body)
203
+ cpy.TypeDef (cls)(rhs = impl1)
204
+ case _ =>
205
+ cls
206
+ }
191
207
192
208
/** Try to inline a pattern with an inline unapply method. Fail with error if the maximal
193
209
* inline depth is exceeded.
@@ -480,10 +496,12 @@ object Inlines:
480
496
end expand
481
497
end InlineCall
482
498
483
- private class InlineParentTrait (parent : tpd.Tree , parentSym : ClassSymbol )(using Context ) extends Inliner (parent):
499
+ private class InlineParentTrait (parent : tpd.Tree )(using Context ) extends Inliner (parent):
484
500
import tpd ._
485
501
import Inlines .*
486
502
503
+ private val parentSym = symbolFromParent(parent)
504
+
487
505
private val thisInlineTrait = ThisType .raw(TypeRef (ctx.owner.prefix, ctx.owner))
488
506
489
507
def expandDefs (overriddenDecls : Set [Symbol ]): List [Tree ] =
0 commit comments