Skip to content

Commit d54d8a2

Browse files
committed
Do not run toSemanticDiagnosic in parallel
Message#msg involves a lot of mutability we can't avoid thread unsafty in toSemanticDiagnostic
1 parent b28b425 commit d54d8a2

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,19 @@ class ExtractSemanticDB private (phaseMode: ExtractSemanticDB.PhaseMode) extends
6565
val appendDiagnostics = phaseMode == ExtractSemanticDB.PhaseMode.AppendDiagnostics
6666
if (appendDiagnostics)
6767
val warnings = ctx.reporter.allWarnings.groupBy(w => w.pos.source)
68-
units.map { unit =>
69-
val unitCtx = ctx.fresh.setCompilationUnit(unit).withRootImports
70-
val outputDir =
71-
ExtractSemanticDB.semanticdbPath(
72-
unit.source,
73-
ExtractSemanticDB.outputDirectory(using unitCtx),
74-
sourceRoot
75-
)
76-
val source = unit.source
77-
(outputDir, source)
78-
}.asJava.parallelStream().forEach { case (out, source) =>
79-
warnings.get(source).foreach { ws =>
80-
ExtractSemanticDB.appendDiagnostics(ws.map(_.toSemanticDiagnostic), out)
68+
units.flatMap { unit =>
69+
warnings.get(unit.source).map { ws =>
70+
val unitCtx = ctx.fresh.setCompilationUnit(unit).withRootImports
71+
val outputDir =
72+
ExtractSemanticDB.semanticdbPath(
73+
unit.source,
74+
ExtractSemanticDB.outputDirectory(using unitCtx),
75+
sourceRoot
76+
)
77+
(outputDir, ws.map(_.toSemanticDiagnostic))
8178
}
79+
}.asJava.parallelStream().forEach { case (out, warnings) =>
80+
ExtractSemanticDB.appendDiagnostics(warnings, out)
8281
}
8382
else
8483
val writeSemanticdbText = ctx.settings.semanticdbText.value

tests/semanticdb/metac.expect

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3887,9 +3887,9 @@ Occurrences:
38873887
[40:10..40:18): rightVar -> local4
38883888

38893889
Diagnostics:
3890-
[30:11..30:18): [warning] unset local variable
3891-
[30:20..30:28): [warning] unset local variable
3892-
[31:15..31:25): [warning] unset local variable
3890+
[30:11..30:18): [warning] unset local variable, consider using an immutable val instead
3891+
[30:20..30:28): [warning] unset local variable, consider using an immutable val instead
3892+
[31:15..31:25): [warning] unset local variable, consider using an immutable val instead
38933893

38943894
Synthetics:
38953895
[5:6..5:10):Some => *.unapply[Int]

0 commit comments

Comments
 (0)