Skip to content

Commit

Permalink
add progress tracking/cancellation to extractSemanticDB
Browse files Browse the repository at this point in the history
  • Loading branch information
bishabosha committed Oct 25, 2023
1 parent 7ccdd40 commit 51abd42
Showing 1 changed file with 37 additions and 28 deletions.
65 changes: 37 additions & 28 deletions compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import dotty.tools.dotc.{semanticdb => s}
import dotty.tools.io.{AbstractFile, JarArchive}
import dotty.tools.dotc.semanticdb.DiagnosticOps.*
import scala.util.{Using, Failure, Success}
import java.nio.file.Path


/** Extract symbol references and uses to semanticdb files.
Expand Down Expand Up @@ -65,41 +66,49 @@ class ExtractSemanticDB private (phaseMode: ExtractSemanticDB.PhaseMode) extends
val appendDiagnostics = phaseMode == ExtractSemanticDB.PhaseMode.AppendDiagnostics
if (appendDiagnostics)
val warnings = ctx.reporter.allWarnings.groupBy(w => w.pos.source)
units.flatMap { unit =>
warnings.get(unit.source).map { ws =>
val unitCtx = ctx.fresh.setCompilationUnit(unit).withRootImports
val outputDir =
ExtractSemanticDB.semanticdbPath(
unit.source,
ExtractSemanticDB.semanticdbOutDir(using unitCtx),
sourceRoot
)
(outputDir, ws.map(_.toSemanticDiagnostic))
val buf = mutable.ListBuffer.empty[(Path, Seq[Diagnostic])]
units.foreach { unit =>
val unitCtx = ctx.fresh.setCompilationUnit(unit).withRootImports
monitor(phaseName) {
warnings.get(unit.source).foreach { ws =>
val outputDir =
ExtractSemanticDB.semanticdbPath(
unit.source,
ExtractSemanticDB.semanticdbOutDir(using unitCtx),
sourceRoot
)
buf += ((outputDir, ws.map(_.toSemanticDiagnostic)))
}
}(using unitCtx)
}
cancellable {
buf.toList.asJava.parallelStream().forEach { case (out, warnings) =>
ExtractSemanticDB.appendDiagnostics(warnings, out)
}
}.asJava.parallelStream().forEach { case (out, warnings) =>
ExtractSemanticDB.appendDiagnostics(warnings, out)
}
else
val writeSemanticdbText = ctx.settings.semanticdbText.value
units.foreach { unit =>
val unitCtx = ctx.fresh.setCompilationUnit(unit).withRootImports
val outputDir =
ExtractSemanticDB.semanticdbPath(
monitor(phaseName) {
val outputDir =
ExtractSemanticDB.semanticdbPath(
unit.source,
ExtractSemanticDB.semanticdbOutDir(using unitCtx),
sourceRoot
)
val extractor = ExtractSemanticDB.Extractor()
extractor.extract(unit.tpdTree)(using unitCtx)
ExtractSemanticDB.write(
unit.source,
ExtractSemanticDB.semanticdbOutDir(using unitCtx),
sourceRoot
extractor.occurrences.toList,
extractor.symbolInfos.toList,
extractor.synthetics.toList,
outputDir,
sourceRoot,
writeSemanticdbText
)
val extractor = ExtractSemanticDB.Extractor()
extractor.extract(unit.tpdTree)(using unitCtx)
ExtractSemanticDB.write(
unit.source,
extractor.occurrences.toList,
extractor.symbolInfos.toList,
extractor.synthetics.toList,
outputDir,
sourceRoot,
writeSemanticdbText
)
}(using unitCtx)
}
units
}
Expand Down Expand Up @@ -611,4 +620,4 @@ object ExtractSemanticDB:
traverse(vparam.tpt)
tparams.foreach(tp => traverse(tp.rhs))
end Extractor
end ExtractSemanticDB
end ExtractSemanticDB

0 comments on commit 51abd42

Please sign in to comment.