@@ -64,21 +64,21 @@ object Inlines:
64
64
65
65
/** Should call be inlined in this context? */
66
66
def needsInlining (tree : Tree )(using Context ): Boolean =
67
- val isInlineableInCtx =
67
+ def isInlineableInCtx =
68
68
StagingLevel .level == 0
69
69
&& (
70
70
ctx.phase == Phases .inliningPhase
71
71
|| (ctx.phase == Phases .typerPhase && needsTransparentInlining(tree))
72
72
)
73
73
&& ! ctx.typer.hasInliningErrors
74
74
&& ! ctx.base.stopInlining
75
- && ! ctx.owner.isInlineTrait
75
+ && ! ctx.owner.ownersIterator.exists(_. isInlineTrait)
76
76
77
77
tree match
78
78
case Block (_, expr) =>
79
79
needsInlining(expr)
80
80
case tdef @ TypeDef (_, impl : Template ) =>
81
- ! tdef.symbol.isInlineTrait && impl.parents.map(symbolFromParent).exists(_.isInlineTrait) && isInlineableInCtx
81
+ impl.parents.map(symbolFromParent).exists(_.isInlineTrait) && isInlineableInCtx
82
82
case _ =>
83
83
isInlineable(tree.symbol) && ! tree.tpe.widenTermRefExpr.isInstanceOf [MethodOrPoly ] && isInlineableInCtx
84
84
@@ -571,16 +571,22 @@ object Inlines:
571
571
inlinedValDef(stat, inlinedSym)
572
572
case stat : DefDef =>
573
573
inlinedDefDef(stat, inlinedSym)
574
- case stat @ TypeDef (_, impl : Template ) =>
575
- inlinedClassDef(stat, impl, inlinedSym.asClass)
574
+ case stat @ TypeDef (_, _ : Template ) =>
575
+ inlinedClassDef(stat, inlinedSym.asClass)
576
576
case stat : TypeDef =>
577
577
inlinedTypeDef(stat, inlinedSym)
578
578
579
579
private def inlinedMember (sym : Symbol )(using Context ): Symbol =
580
580
sym.info match {
581
581
case ClassInfo (prefix, cls, declaredParents, scope, selfInfo) =>
582
- val inlinedInfo = ClassInfo (prefix, cls, declaredParents, Scopes .newScope, selfInfo) // TODO adapt parents
583
- sym.copy(owner = ctx.owner, info = inlinedInfo, coord = spanCoord(parent.span)).entered.asClass
582
+ val inlinedSym = newClassSymbol(
583
+ ctx.owner,
584
+ sym.asType.name,
585
+ sym.flags | Synthetic ,
586
+ clsSym => ClassInfo (inlinerTypeMap(prefix), clsSym, declaredParents :+ ThisType .raw(ctx.owner.typeRef).select(sym), Scopes .newScope, selfInfo)
587
+ )
588
+ inlinedSym.setTargetName(sym.name ++ str.NAME_JOIN ++ ctx.owner.name)
589
+ inlinedSym
584
590
case _ =>
585
591
var name = sym.name
586
592
var flags = sym.flags | Synthetic
@@ -598,11 +604,13 @@ object Inlines:
598
604
coord = spanCoord(parent.span)).entered
599
605
}
600
606
601
- private def inlinedStat (stat : Tree )(using Context ): Tree = stat match {
602
- // TODO check if symbols must be copied
603
- case tree : DefDef => inlinedDefDef(tree, tree.symbol)
604
- case tree : ValDef => inlinedValDef(tree, tree.symbol)
605
- }
607
+ private def inlinedStat (stat : Tree )(using Context ): Tree =
608
+ val inlinedSym = inlinedMember(stat.symbol)
609
+ stat match {
610
+ // TODO check if symbols must be copied
611
+ case tree : DefDef => inlinedDefDef(tree, inlinedSym)
612
+ case tree : ValDef => inlinedValDef(tree, inlinedSym)
613
+ }
606
614
607
615
private def inlinedValDef (vdef : ValDef , inlinedSym : Symbol )(using Context ): ValDef =
608
616
val rhs =
@@ -625,14 +633,18 @@ object Inlines:
625
633
626
634
private def inlinedPrimaryConstructorDefDef (ddef : DefDef )(using Context ): DefDef =
627
635
// TODO check if symbol must be copied
628
- val constr = inlinedDefDef(ddef, ddef.symbol)
636
+ val inlinedSym = inlinedMember(ddef.symbol)
637
+ inlinedSym.resetFlag(Override )
638
+ val constr = inlinedDefDef(ddef, inlinedSym)
629
639
cpy.DefDef (constr)(tpt = TypeTree (defn.UnitType ), rhs = EmptyTree )
630
640
631
- private def inlinedClassDef (clDef : TypeDef , impl : Template , inlinedCls : ClassSymbol )(using Context ): Tree =
632
- val (constr, body) = inContext(ctx.withOwner(inlinedCls)) {
633
- (inlinedPrimaryConstructorDefDef(impl.constr), impl.body.map(inlinedStat))
641
+ private def inlinedClassDef (clsDef : TypeDef , inlinedSym : ClassSymbol )(using Context ): Tree =
642
+ val TypeDef (_, tmpl : Template ) = clsDef : @ unchecked
643
+ val (constr, body) = inContext(ctx.withOwner(inlinedSym)) {
644
+ (inlinedPrimaryConstructorDefDef(tmpl.constr), tmpl.body.map(inlinedStat))
634
645
}
635
- inlined(tpd.ClassDefWithParents (inlinedCls, constr, impl.parents, body))._2.withSpan(clDef.span) // TODO adapt parents
646
+ val clsDef1 = tpd.ClassDefWithParents (inlinedSym, constr, tmpl.parents :+ This (ctx.owner.asClass).select(clsDef.symbol), body)
647
+ inlined(clsDef1)._2.withSpan(clsDef.span) // TODO adapt parents
636
648
637
649
private def inlinedTypeDef (tdef : TypeDef , inlinedSym : Symbol )(using Context ): TypeDef =
638
650
tpd.TypeDef (inlinedSym.asType).withSpan(parent.span)
0 commit comments