From 67b2cecf0d633b85b42bf19381b1b464dcec08ff Mon Sep 17 00:00:00 2001 From: odersky Date: Wed, 18 Sep 2024 14:04:19 +0200 Subject: [PATCH] Harden skip in Scanner I sometimes see a rogue java process at 100% even after I closed down sbt and vscode. With jstack I got the following stack trace: java.lang.Thread.State: RUNNABLE at dotty.tools.dotc.parsing.Scanners$Scanner.handleNewLine(Scanners.scala:613) at dotty.tools.dotc.parsing.Scanners$Scanner.nextToken(Scanners.scala:396) at dotty.tools.dotc.parsing.Scanners$Scanner.skip(Scanners.scala:312) at dotty.tools.dotc.parsing.Parsers$Parser.skip(Parsers.scala:280) at dotty.tools.dotc.parsing.Parsers$Parser.recur$2(Parsers.scala:376) at dotty.tools.dotc.parsing.Parsers$Parser.statSepOrEnd(Parsers.scala:380) It could be that the loop in skip gives two alternate offsets that would not bump the progress counter. I changed the loop so that it catches more looping conditions. [Cherry-picked b1235b95d42506804d5ba17dcabcb52653163e95] --- compiler/src/dotty/tools/dotc/parsing/Scanners.scala | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala index 43ff4ed5c1af..aadedde612f7 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala @@ -305,11 +305,15 @@ object Scanners { println(s"\nSTART SKIP AT ${sourcePos().line + 1}, $this in $currentRegion") var noProgress = 0 // Defensive measure to ensure we always get out of the following while loop - // even if source file is weirly formatted (i.e. we never reach EOF + // even if source file is weirly formatted (i.e. we never reach EOF) + var prevOffset = offset while !atStop && noProgress < 3 do - val prevOffset = offset nextToken() - if offset == prevOffset then noProgress += 1 else noProgress = 0 + if offset <= prevOffset then + noProgress += 1 + else + prevOffset = offset + noProgress = 0 if debugTokenStream then println(s"\nSTOP SKIP AT ${sourcePos().line + 1}, $this in $currentRegion") if token == OUTDENT then dropUntil(_.isInstanceOf[Indented])