Skip to content

Commit d2b54c2

Browse files
committedJul 19, 2023
Parallelize read/write SemanticDB
1 parent f17fb5f commit d2b54c2

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed
 

‎compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala

+24-12
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ import transform.SymUtils._
2121

2222
import scala.collection.mutable
2323
import scala.annotation.{ threadUnsafe => tu, tailrec }
24+
import scala.jdk.CollectionConverters._
2425
import scala.PartialFunction.condOpt
26+
import typer.ImportInfo.withRootImports
2527

2628
import dotty.tools.dotc.{semanticdb => s}
2729
import dotty.tools.io.{AbstractFile, JarArchive}
@@ -59,18 +61,28 @@ class ExtractSemanticDB private (phaseMode: ExtractSemanticDB.PhaseMode, suffix:
5961
// Check not needed since it does not transform trees
6062
override def isCheckable: Boolean = false
6163

62-
override def run(using Context): Unit =
63-
val unit = ctx.compilationUnit
64-
if (phaseMode == ExtractSemanticDB.PhaseMode.PostTyper)
65-
val extractor = ExtractSemanticDB.Extractor()
66-
extractor.extract(unit.tpdTree)
67-
ExtractSemanticDB.write(unit.source, extractor.occurrences.toList, extractor.symbolInfos.toList, extractor.synthetics.toList)
68-
else
69-
val warnings = ctx.reporter.allWarnings.collect {
70-
case w if w.pos.source == ctx.source => w.toSemanticDiagnostic
71-
}
72-
if (warnings.nonEmpty)
73-
ExtractSemanticDB.appendDiagnostics(unit.source, warnings)
64+
override def runOn(units: List[CompilationUnit])(using ctx: Context): List[CompilationUnit] = {
65+
val appendWarnings = phaseMode == ExtractSemanticDB.PhaseMode.PostInlining
66+
val warnings =
67+
if (appendWarnings)
68+
ctx.reporter.allWarnings.groupBy(w => w.pos.source)
69+
else Map.empty
70+
71+
units.asJava.parallelStream().map { unit =>
72+
val unitCtx = ctx.fresh.setCompilationUnit(unit).withRootImports
73+
if (appendWarnings)
74+
warnings.get(unit.source).foreach { ws =>
75+
ExtractSemanticDB.appendDiagnostics(unit.source, ws.map(_.toSemanticDiagnostic))
76+
}
77+
else
78+
val extractor = ExtractSemanticDB.Extractor()
79+
extractor.extract(unit.tpdTree)
80+
ExtractSemanticDB.write(unit.source, extractor.occurrences.toList, extractor.symbolInfos.toList, extractor.synthetics.toList)
81+
unit
82+
}.toList().asScala.toList
83+
}
84+
85+
def run(using Context): Unit = unsupported("run")
7486
end ExtractSemanticDB
7587

7688
object ExtractSemanticDB:

0 commit comments

Comments
 (0)
Please sign in to comment.