Skip to content

Commit af72f8a

Browse files
oderskyWojciechMazur
authored andcommitted
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 b1235b9]
1 parent cc4f5c1 commit af72f8a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Diff for: compiler/src/dotty/tools/dotc/parsing/Scanners.scala

+7-3
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,15 @@ object Scanners {
305305
println(s"\nSTART SKIP AT ${sourcePos().line + 1}, $this in $currentRegion")
306306
var noProgress = 0
307307
// Defensive measure to ensure we always get out of the following while loop
308-
// even if source file is weirly formatted (i.e. we never reach EOF
308+
// even if source file is weirly formatted (i.e. we never reach EOF)
309+
var prevOffset = offset
309310
while !atStop && noProgress < 3 do
310-
val prevOffset = offset
311311
nextToken()
312-
if offset == prevOffset then noProgress += 1 else noProgress = 0
312+
if offset <= prevOffset then
313+
noProgress += 1
314+
else
315+
prevOffset = offset
316+
noProgress = 0
313317
if debugTokenStream then
314318
println(s"\nSTOP SKIP AT ${sourcePos().line + 1}, $this in $currentRegion")
315319
if token == OUTDENT then dropUntil(_.isInstanceOf[Indented])

0 commit comments

Comments
 (0)