Skip to content

Commit a47a800

Browse files
committed
Simplify enclosingInlineds
- represent directly as a list - can replace separate inlineCount
1 parent fd7b60c commit a47a800

File tree

3 files changed

+10
-24
lines changed

3 files changed

+10
-24
lines changed

src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -672,10 +672,6 @@ object Contexts {
672672
*/
673673
private[dotty] var unsafeNonvariant: RunId = NoRunId
674674

675-
// Typer state
676-
677-
private[dotty] var inlineCount = 0
678-
679675
// Phases state
680676

681677
private[core] var phasesPlan: List[List[Phase]] = _

src/dotty/tools/dotc/core/Decorators.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,9 @@ object Decorators {
151151
}
152152

153153
implicit def sourcePos(pos: Position)(implicit ctx: Context): SourcePosition = {
154-
def recur(inlineds: Stream[Inlined], pos: Position): SourcePosition = inlineds match {
155-
case inlined #:: rest =>
156-
Inliner.sourceFile(inlined).atPos(pos)
157-
.withOuter(recur(rest, inlined.call.pos))
154+
def recur(inlineds: List[Inlined], pos: Position): SourcePosition = inlineds match {
155+
case inlined :: rest =>
156+
Inliner.sourceFile(inlined).atPos(pos).withOuter(recur(rest, inlined.call.pos))
158157
case empty =>
159158
ctx.source.atPos(pos)
160159
}

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

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ object Inliner {
3131

3232
private val InlinedBody = new Property.Key[InlinedBody] // to be used as attachment
3333

34-
val InlinedCall = new Property.Key[tpd.Inlined] // to be used in context
34+
private val InlinedCall = new Property.Key[List[tpd.Inlined]] // to be used in context
3535

3636
def attachBody(inlineAnnot: Annotation, tree: => Tree)(implicit ctx: Context): Unit =
3737
inlineAnnot.tree.putAttachment(InlinedBody, new InlinedBody(tree))
@@ -72,12 +72,10 @@ object Inliner {
7272
}
7373

7474
def inlineCall(tree: Tree, pt: Type)(implicit ctx: Context): Tree = {
75-
if (ctx.inlineCount < ctx.settings.xmaxInlines.value) {
76-
ctx.inlineCount += 1
75+
if (enclosingInlineds.length < ctx.settings.xmaxInlines.value) {
7776
val rhs = inlinedBody(tree.symbol)
7877
val inlined = new Inliner(tree, rhs).inlined
79-
try new Typer().typedUnadapted(inlined, pt)
80-
finally ctx.inlineCount -= 1
78+
new Typer().typedUnadapted(inlined, pt)
8179
} else errorTree(tree,
8280
i"""Maximal number of successive inlines (${ctx.settings.xmaxInlines.value}) exceeded,
8381
| Maybe this is caused by a recursive inline method?
@@ -93,17 +91,10 @@ object Inliner {
9391
}
9492

9593
def inlineContext(tree: untpd.Inlined)(implicit ctx: Context): Context =
96-
ctx.fresh.setProperty(InlinedCall, tree)
97-
98-
def enclosingInlineds(implicit ctx: Context): Stream[Inlined] =
99-
ctx.property(InlinedCall) match {
100-
case found @ Some(inlined) =>
101-
inlined #::
102-
enclosingInlineds(
103-
ctx.outersIterator.dropWhile(_.property(InlinedCall) == found).next)
104-
case _ =>
105-
Stream.Empty
106-
}
94+
ctx.fresh.setProperty(InlinedCall, tree :: enclosingInlineds)
95+
96+
def enclosingInlineds(implicit ctx: Context): List[Inlined] =
97+
ctx.property(InlinedCall).getOrElse(Nil)
10798

10899
def sourceFile(inlined: Inlined)(implicit ctx: Context) = {
109100
val file = inlined.call.symbol.sourceFile

0 commit comments

Comments
 (0)