Skip to content

Commit 03ff49d

Browse files
committed
Fix deterministically adding additional interfaces
When a class contains calls to 'super' for traits it does not directly implement, these are added to the list of interfaces of the generated class. Previously, because these interfaces were determined using set logic, the ordering of that list was not deterministic. This makes the order deterministic assuming the order in which these calls are registered using `registerSuperCall` in the `CollectSuperCalls` phase is deterministic within each class. This seems likely to me but it'd be great if someone could confirm. To add a test for this change, creating a class that has many 'additional' traits and checking they are generated in the right order would make sense, but I couldn't find an obvious place for such a test. Any recommendations? Fixes scala#20496
1 parent c1b25d6 commit 03ff49d

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

compiler/src/dotty/tools/backend/jvm/BTypesFromSymbols.scala

+5-3
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,13 @@ class BTypesFromSymbols[I <: DottyBackendInterface](val int: I, val frontendAcce
113113
val directlyInheritedTraits = sym.directlyInheritedTraits
114114
val directlyInheritedTraitsSet = directlyInheritedTraits.toSet
115115
val allBaseClasses = directlyInheritedTraits.iterator.flatMap(_.asClass.baseClasses.drop(1)).toSet
116-
val superCalls = superCallsMap.getOrElse(sym, Set.empty)
117-
val additional = (superCalls -- directlyInheritedTraitsSet).filter(_.is(Trait))
116+
val superCalls = superCallsMap.getOrElse(sym, List.empty)
117+
val superCallsSet = superCalls.toSet
118+
val additional = superCalls.foldLeft(List())((acc, t) =>
119+
if !acc.contains(t) && !directlyInheritedTraitsSet(t) && t.is(Trait) then acc :+ t else acc)
118120
// if (additional.nonEmpty)
119121
// println(s"$fullName: adding supertraits $additional")
120-
directlyInheritedTraits.filter(t => !allBaseClasses(t) || superCalls(t)) ++ additional
122+
directlyInheritedTraits.filter(t => !allBaseClasses(t) || superCallsSet(t)) ++ additional
121123
}
122124

123125
val interfaces = classSym.superInterfaces.map(classBTypeFromSymbol)

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import StdNames.nme
2525
import NameKinds.{LazyBitMapName, LazyLocalName}
2626
import Names.Name
2727

28-
class DottyBackendInterface(val superCallsMap: ReadOnlyMap[Symbol, Set[ClassSymbol]])(using val ctx: Context) {
28+
class DottyBackendInterface(val superCallsMap: ReadOnlyMap[Symbol, List[ClassSymbol]])(using val ctx: Context) {
2929

3030
private val desugared = new java.util.IdentityHashMap[Type, tpd.Select]
3131

compiler/src/dotty/tools/backend/jvm/GenBCode.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ class GenBCode extends Phase { self =>
2323

2424
override def isRunnable(using Context) = super.isRunnable && !ctx.usedBestEffortTasty
2525

26-
private val superCallsMap = new MutableSymbolMap[Set[ClassSymbol]]
26+
private val superCallsMap = new MutableSymbolMap[List[ClassSymbol]]
2727
def registerSuperCall(sym: Symbol, calls: ClassSymbol): Unit = {
28-
val old = superCallsMap.getOrElse(sym, Set.empty)
29-
superCallsMap.update(sym, old + calls)
28+
val old = superCallsMap.getOrElse(sym, List.empty)
29+
superCallsMap.update(sym, old :+ calls)
3030
}
3131

3232
private val entryPoints = new mutable.HashSet[String]()

0 commit comments

Comments
 (0)