Skip to content

Commit 89719e5

Browse files
committed
Fix #11885: Avoid non-determinism of idempotency tests on Windows
The cause of the problem is that we use parallelism in Pickler: if !Pickler.ParallelPickling || ctx.settings.YtestPickler.value then force() Sometimes on Windows, the futures run a little slower, and the later phase `Inlining` can change the positions of the trees to be pickled, thus non-determinism.
1 parent f01c14d commit 89719e5

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

compiler/src/dotty/tools/dotc/CompilationUnit.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,21 @@ class CompilationUnit protected (val source: SourceFile) {
8585
def assignmentSpans(using Context): Map[Int, List[Span]] =
8686
if myAssignmentSpans == null then myAssignmentSpans = Nullables.assignmentSpans
8787
myAssignmentSpans
88+
89+
/** Force pickling at end of Pickler phase for determinism
90+
*
91+
* On Windows we observe non-deterministic failure for the
92+
* idempotency test tests/pos/i6507b.scala. The cause of the
93+
* non-determinism is that the positions of the to be pickled
94+
* trees might change in a later phase `Inlining` after pickling.
95+
* Depending on how fast the futures are run, sometimes it may
96+
* observe the mutations in the later phase.
97+
*/
98+
def forcePickling()(using Context): Unit =
99+
pickled = pickled.map { (sym, fn) =>
100+
val bytes = fn()
101+
(sym, () => bytes)
102+
}
88103
}
89104

90105
object CompilationUnit {

compiler/src/dotty/tools/dotc/transform/Pickler.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class Pickler extends Phase {
117117
.addMode(Mode.ReadPositions)
118118
.addMode(Mode.ReadComments)
119119
.addMode(Mode.PrintShowExceptions))
120+
units.foreach(_.forcePickling())
120121
result
121122
}
122123

0 commit comments

Comments
 (0)