Skip to content

Commit df99c94

Browse files
Factorize code to know what to inline from inline trait
1 parent 5fa112a commit df99c94

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import NamerOps._
2323
import ContextOps._
2424
import Variances.Invariant
2525
import TastyUnpickler.NameTable
26+
import typer.Typer
2627
import typer.ConstFold
2728
import typer.Checking.checkNonCyclic
2829
import typer.Nullables._
@@ -1063,11 +1064,7 @@ class TreeUnpickler(reader: TastyReader,
10631064

10641065
val fork = forkAt(statsStart)
10651066
val stats = fork.readIndexedStats(localDummy, end)
1066-
val inlinedMembers = (tparams ++ vparams ++ stats).filter { stat =>
1067-
!(stat.isInstanceOf[TypeDef] && cls.typeParams.contains(stat.symbol)) // !isConstructor
1068-
&& !stat.symbol.is(Deferred)
1069-
&& !stat.symbol.isAllOf(Inline)
1070-
}
1067+
val inlinedMembers = (tparams ++ vparams ++ stats).filter(member => Typer.isInlineableFromInlineTrait(cls, member))
10711068
Block(inlinedMembers, unitLiteral).withSpan(cls.span)
10721069
}
10731070
})

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ object Typer {
108108
def rememberSearchFailure(tree: tpd.Tree, fail: SearchFailure) =
109109
tree.putAttachment(HiddenSearchFailure,
110110
fail :: tree.attachmentOrElse(HiddenSearchFailure, Nil))
111+
112+
def isInlineableFromInlineTrait(inlinedTraitSym: ClassSymbol, member: tpd.Tree)(using Context): Boolean =
113+
!(member.isInstanceOf[tpd.TypeDef] && inlinedTraitSym.typeParams.contains(member.symbol))
114+
&& !member.symbol.is(Deferred)
115+
&& !member.symbol.isAllOf(Inline)
111116
}
112117
/** Typecheck trees, the main entry point is `typed`.
113118
*
@@ -2662,13 +2667,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
26622667
val body1 = addAccessorDefs(cls, typedStats(impl.body, dummy)(using ctx.inClassContext(self1.symbol))._1) ::: inlineTraitDefs
26632668

26642669
if !ctx.isAfterTyper && cls.isInlineTrait then
2665-
def isConstructorType(t: Tree) = t.isInstanceOf[TypeDef] && cls.typeParams.contains(t.symbol)
2666-
// If the following is changed, remember to adapt TreeUnpickler.scala as well
2667-
val membersToInline = body1.filter { t =>
2668-
!isConstructorType(t)
2669-
&& !t.symbol.is(Deferred)
2670-
&& !t.symbol.isAllOf(Inline)
2671-
}
2670+
val membersToInline = body1.filter(member => isInlineableFromInlineTrait(cls, member))
26722671
val wrappedMembersToInline = Block(membersToInline, unitLiteral).withSpan(cdef.span)
26732672
PrepareInlineable.registerInlineInfo(cls, wrappedMembersToInline)
26742673

0 commit comments

Comments
 (0)