Skip to content

Commit

Permalink
Do not run toSemanticDiagnosic in parallel
Browse files Browse the repository at this point in the history
Message#msg involves a lot of mutability
we can't avoid thread unsafty in toSemanticDiagnostic
  • Loading branch information
tanishiking committed Oct 16, 2023
1 parent b28b425 commit d54d8a2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
25 changes: 12 additions & 13 deletions compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,19 @@ 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.map { unit =>
val unitCtx = ctx.fresh.setCompilationUnit(unit).withRootImports
val outputDir =
ExtractSemanticDB.semanticdbPath(
unit.source,
ExtractSemanticDB.outputDirectory(using unitCtx),
sourceRoot
)
val source = unit.source
(outputDir, source)
}.asJava.parallelStream().forEach { case (out, source) =>
warnings.get(source).foreach { ws =>
ExtractSemanticDB.appendDiagnostics(ws.map(_.toSemanticDiagnostic), out)
units.flatMap { unit =>
warnings.get(unit.source).map { ws =>
val unitCtx = ctx.fresh.setCompilationUnit(unit).withRootImports
val outputDir =
ExtractSemanticDB.semanticdbPath(
unit.source,
ExtractSemanticDB.outputDirectory(using unitCtx),
sourceRoot
)
(outputDir, ws.map(_.toSemanticDiagnostic))
}
}.asJava.parallelStream().forEach { case (out, warnings) =>
ExtractSemanticDB.appendDiagnostics(warnings, out)
}
else
val writeSemanticdbText = ctx.settings.semanticdbText.value
Expand Down
6 changes: 3 additions & 3 deletions tests/semanticdb/metac.expect
Original file line number Diff line number Diff line change
Expand Up @@ -3887,9 +3887,9 @@ Occurrences:
[40:10..40:18): rightVar -> local4

Diagnostics:
[30:11..30:18): [warning] unset local variable
[30:20..30:28): [warning] unset local variable
[31:15..31:25): [warning] unset local variable
[30:11..30:18): [warning] unset local variable, consider using an immutable val instead
[30:20..30:28): [warning] unset local variable, consider using an immutable val instead
[31:15..31:25): [warning] unset local variable, consider using an immutable val instead

Synthetics:
[5:6..5:10):Some => *.unapply[Int]
Expand Down

0 comments on commit d54d8a2

Please sign in to comment.