@@ -21,7 +21,9 @@ import transform.SymUtils._
2121
2222import scala .collection .mutable
2323import scala .annotation .{ threadUnsafe => tu , tailrec }
24+ import scala .jdk .CollectionConverters ._
2425import scala .PartialFunction .condOpt
26+ import typer .ImportInfo .withRootImports
2527
2628import dotty .tools .dotc .{semanticdb => s }
2729import 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" )
7486end ExtractSemanticDB
7587
7688object ExtractSemanticDB :
0 commit comments