From a47a8008023ea04ff7f8d708567fb6a2c516caaa Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 2 Sep 2016 14:06:08 +0200 Subject: Simplify enclosingInlineds - represent directly as a list - can replace separate inlineCount --- src/dotty/tools/dotc/core/Contexts.scala | 4 ---- src/dotty/tools/dotc/core/Decorators.scala | 7 +++---- src/dotty/tools/dotc/typer/Inliner.scala | 23 +++++++---------------- 3 files changed, 10 insertions(+), 24 deletions(-) diff --git a/src/dotty/tools/dotc/core/Contexts.scala b/src/dotty/tools/dotc/core/Contexts.scala index f2a1fe53e..313ea3124 100644 --- a/src/dotty/tools/dotc/core/Contexts.scala +++ b/src/dotty/tools/dotc/core/Contexts.scala @@ -672,10 +672,6 @@ object Contexts { */ private[dotty] var unsafeNonvariant: RunId = NoRunId - // Typer state - - private[dotty] var inlineCount = 0 - // Phases state private[core] var phasesPlan: List[List[Phase]] = _ diff --git a/src/dotty/tools/dotc/core/Decorators.scala b/src/dotty/tools/dotc/core/Decorators.scala index fc546667d..cd4941c72 100644 --- a/src/dotty/tools/dotc/core/Decorators.scala +++ b/src/dotty/tools/dotc/core/Decorators.scala @@ -151,10 +151,9 @@ object Decorators { } implicit def sourcePos(pos: Position)(implicit ctx: Context): SourcePosition = { - def recur(inlineds: Stream[Inlined], pos: Position): SourcePosition = inlineds match { - case inlined #:: rest => - Inliner.sourceFile(inlined).atPos(pos) - .withOuter(recur(rest, inlined.call.pos)) + def recur(inlineds: List[Inlined], pos: Position): SourcePosition = inlineds match { + case inlined :: rest => + Inliner.sourceFile(inlined).atPos(pos).withOuter(recur(rest, inlined.call.pos)) case empty => ctx.source.atPos(pos) } diff --git a/src/dotty/tools/dotc/typer/Inliner.scala b/src/dotty/tools/dotc/typer/Inliner.scala index c6177eb8d..06eea9113 100644 --- a/src/dotty/tools/dotc/typer/Inliner.scala +++ b/src/dotty/tools/dotc/typer/Inliner.scala @@ -31,7 +31,7 @@ object Inliner { private val InlinedBody = new Property.Key[InlinedBody] // to be used as attachment - val InlinedCall = new Property.Key[tpd.Inlined] // to be used in context + private val InlinedCall = new Property.Key[List[tpd.Inlined]] // to be used in context def attachBody(inlineAnnot: Annotation, tree: => Tree)(implicit ctx: Context): Unit = inlineAnnot.tree.putAttachment(InlinedBody, new InlinedBody(tree)) @@ -72,12 +72,10 @@ object Inliner { } def inlineCall(tree: Tree, pt: Type)(implicit ctx: Context): Tree = { - if (ctx.inlineCount < ctx.settings.xmaxInlines.value) { - ctx.inlineCount += 1 + if (enclosingInlineds.length < ctx.settings.xmaxInlines.value) { val rhs = inlinedBody(tree.symbol) val inlined = new Inliner(tree, rhs).inlined - try new Typer().typedUnadapted(inlined, pt) - finally ctx.inlineCount -= 1 + new Typer().typedUnadapted(inlined, pt) } else errorTree(tree, i"""Maximal number of successive inlines (${ctx.settings.xmaxInlines.value}) exceeded, | Maybe this is caused by a recursive inline method? @@ -93,17 +91,10 @@ object Inliner { } def inlineContext(tree: untpd.Inlined)(implicit ctx: Context): Context = - ctx.fresh.setProperty(InlinedCall, tree) - - def enclosingInlineds(implicit ctx: Context): Stream[Inlined] = - ctx.property(InlinedCall) match { - case found @ Some(inlined) => - inlined #:: - enclosingInlineds( - ctx.outersIterator.dropWhile(_.property(InlinedCall) == found).next) - case _ => - Stream.Empty - } + ctx.fresh.setProperty(InlinedCall, tree :: enclosingInlineds) + + def enclosingInlineds(implicit ctx: Context): List[Inlined] = + ctx.property(InlinedCall).getOrElse(Nil) def sourceFile(inlined: Inlined)(implicit ctx: Context) = { val file = inlined.call.symbol.sourceFile -- cgit v1.2.3