Skip to content

Commit 5b2d94a

Browse files
committed
Check that access to context base is singlethreaded.
ContextBase is not intended to be threadsafe, We now test that indeed it is not shared by compileUnits calls operating on different threads.
1 parent ac34748 commit 5b2d94a

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/dotty/tools/dotc/Run.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class Run(comp: Compiler)(implicit ctx: Context) {
5050
}
5151

5252
protected def compileUnits() = Stats.monitorHeartBeat {
53+
ctx.checkSingleThreaded()
5354
val phases = ctx.squashPhases(ctx.phasePlan,
5455
ctx.settings.Yskip.value, ctx.settings.YstopBefore.value, ctx.settings.YstopAfter.value, ctx.settings.Ycheck.value)
5556
ctx.usePhases(phases)

src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,16 @@ object Contexts {
611611
superIdOfClass.clear()
612612
lastSuperId = -1
613613
}
614+
615+
// Test that access is single threaded
616+
617+
/** The thread on which `checkSingleThreaded was invoked last */
618+
@sharable private var thread: Thread = null
619+
620+
/** Check that we are on the same thread as before */
621+
def checkSingleThreaded() =
622+
if (thread == null) thread = Thread.currentThread()
623+
else assert(thread == Thread.currentThread(), "illegal multithreaded access to ContextBase")
614624
}
615625

616626
object Context {

0 commit comments

Comments
 (0)