Skip to content

Commit ae1831a

Browse files
committed
Fixed data race in ResolveSuper
The datarace happened because for method "transform" implemented by ResolveSuper which disambiguated overridden methods. Previously, there was a reference FirstTransform.this.transform of type termRefWithSig to the method implemented in a super trait. Now the same reference points to the newly implemented method. Solved because ResolveSuper now generates symbolic references.
1 parent fbb824c commit ae1831a

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ object Phases {
220220
private var myErasedTypes = false
221221
private var myFlatClasses = false
222222
private var myRefChecked = false
223+
private var mySymbolicRefs = false
223224

224225
/** The sequence position of this phase in the given context where 0
225226
* is reserved for NoPhase and the first real phase is at position 1.
@@ -231,18 +232,20 @@ object Phases {
231232
def start = myPeriod.firstPhaseId
232233
def end = myPeriod.lastPhaseId
233234

234-
final def erasedTypes = myErasedTypes
235-
final def flatClasses = myFlatClasses
236-
final def refChecked = myRefChecked
235+
final def erasedTypes = myErasedTypes // Phase is after erasure
236+
final def flatClasses = myFlatClasses // Phase is after flatten
237+
final def refChecked = myRefChecked // Phase is after RefChecks
238+
final def symbolicRefs = mySymbolicRefs // Phase is after ResolveSuper, newly generated TermRefs should be symbolic
237239

238240
protected[Phases] def init(base: ContextBase, start: Int, end:Int): Unit = {
239241
if (start >= FirstPhaseId)
240242
assert(myPeriod == Periods.InvalidPeriod, s"phase $this has already been used once; cannot be reused")
241243
myBase = base
242244
myPeriod = Period(start, end)
243-
myErasedTypes = prev.getClass == classOf[Erasure] || prev.erasedTypes
244-
myFlatClasses = prev.getClass == classOf[Flatten] || prev.flatClasses
245-
myRefChecked = prev.getClass == classOf[RefChecks] || prev.refChecked
245+
myErasedTypes = prev.getClass == classOf[Erasure] || prev.erasedTypes
246+
myFlatClasses = prev.getClass == classOf[Flatten] || prev.flatClasses
247+
myRefChecked = prev.getClass == classOf[RefChecks] || prev.refChecked
248+
mySymbolicRefs = prev.getClass == classOf[ResolveSuper] || prev.symbolicRefs
246249
}
247250

248251
protected[Phases] def init(base: ContextBase, id: Int): Unit = init(base, id, id)

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,6 +1526,8 @@ object Types {
15261526

15271527
object TermRef {
15281528

1529+
private def symbolicRefs(implicit ctx: Context) = ctx.phase.symbolicRefs
1530+
15291531
/** Create term ref with given name, without specifying a signature.
15301532
* Its meaning is the (potentially multi-) denotation of the member(s)
15311533
* of prefix with given name.
@@ -1546,7 +1548,7 @@ object Types {
15461548
* signature, if denotation is not yet completed.
15471549
*/
15481550
def apply(prefix: Type, name: TermName, denot: Denotation)(implicit ctx: Context): TermRef = {
1549-
if ((prefix eq NoPrefix) || denot.symbol.isFresh || ctx.erasedTypes)
1551+
if ((prefix eq NoPrefix) || denot.symbol.isFresh || symbolicRefs)
15501552
apply(prefix, denot.symbol.asTerm)
15511553
else denot match {
15521554
case denot: SymDenotation if denot.isCompleted => withSig(prefix, name, denot.signature)
@@ -1568,7 +1570,7 @@ object Types {
15681570
* (2) The name in the term ref need not be the same as the name of the Symbol.
15691571
*/
15701572
def withSymAndName(prefix: Type, sym: TermSymbol, name: TermName)(implicit ctx: Context): TermRef =
1571-
if ((prefix eq NoPrefix) || sym.isFresh || ctx.erasedTypes)
1573+
if ((prefix eq NoPrefix) || sym.isFresh || symbolicRefs)
15721574
withFixedSym(prefix, name, sym)
15731575
else if (sym.defRunId != NoRunId && sym.isCompleted)
15741576
withSig(prefix, name, sym.signature) withSym (sym, sym.signature)
@@ -1579,7 +1581,7 @@ object Types {
15791581
* (which must be completed).
15801582
*/
15811583
def withSig(prefix: Type, sym: TermSymbol)(implicit ctx: Context): TermRef =
1582-
if ((prefix eq NoPrefix) || sym.isFresh || ctx.erasedTypes) withFixedSym(prefix, sym.name, sym)
1584+
if ((prefix eq NoPrefix) || sym.isFresh || symbolicRefs) withFixedSym(prefix, sym.name, sym)
15831585
else withSig(prefix, sym.name, sym.signature).withSym(sym, sym.signature)
15841586

15851587
/** Create a term ref with given prefix, name and signature */
@@ -1588,7 +1590,7 @@ object Types {
15881590

15891591
/** Create a term ref with given prefix, name, signature, and initial denotation */
15901592
def withSigAndDenot(prefix: Type, name: TermName, sig: Signature, denot: Denotation)(implicit ctx: Context): TermRef = {
1591-
if ((prefix eq NoPrefix) || denot.symbol.isFresh || ctx.erasedTypes)
1593+
if ((prefix eq NoPrefix) || denot.symbol.isFresh || symbolicRefs)
15921594
withFixedSym(prefix, denot.symbol.asTerm.name, denot.symbol.asTerm)
15931595
else
15941596
withSig(prefix, name, sig)

test/dotc/tests.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ class tests extends CompilerTest {
113113
@Test def dotc_config = compileDir(dotcDir + "tools/dotc/config", twice)
114114
@Test def dotc_core = compileDir(dotcDir + "tools/dotc/core", twice)(allowDeepSubtypes)
115115
@Test def dotc_core_pickling = compileDir(dotcDir + "tools/dotc/core/pickling", twice)(allowDeepSubtypes)
116-
// @Test def dotc_transform = compileDir(dotcDir + "tools/dotc/transform", twice)
117-
// @odersky causes race error in ResolveSuper
116+
@Test def dotc_transform = compileDir(dotcDir + "tools/dotc/transform", twice)
118117

119118
@Test def dotc_parsing = compileDir(dotcDir + "tools/dotc/parsing", twice)
120119
@Test def dotc_printing = compileDir(dotcDir + "tools/dotc/printing", twice)

0 commit comments

Comments
 (0)