Skip to content

Commit cd62f52

Browse files
committed
rather than info.parents, superClass and mixinClasses are enough
1 parent 1c9a3e8 commit cd62f52

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed

src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,10 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with
215215
}
216216

217217
// Additional interface parents based on annotations and other cues
218-
def newParentForAttr(attr: Symbol): Option[Type] = attr match {
219-
case SerializableAttr => Some(SerializableClass.tpe)
220-
case CloneableAttr => Some(JavaCloneableClass.tpe)
221-
case RemoteAttr => Some(RemoteInterfaceClass.tpe)
218+
def newParentForAttr(attr: Symbol): Option[Symbol] = attr match {
219+
case SerializableAttr => Some(SerializableClass)
220+
case CloneableAttr => Some(JavaCloneableClass)
221+
case RemoteAttr => Some(RemoteInterfaceClass)
222222
case _ => None
223223
}
224224

@@ -378,38 +378,44 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with
378378

379379
private var innerClassBuffer = mutable.LinkedHashSet[Symbol]()
380380

381-
/** Drop redundant interfaces (ones which are implemented by some
382-
* other parent) from the immediate parents. This is important on
383-
* android because there is otherwise an interface explosion.
381+
/** Drop redundant interfaces (ones which are implemented by some other parent) from the immediate parents.
382+
* This is important on Android because there is otherwise an interface explosion.
384383
*/
385-
private def minimizeInterfaces(interfaces: List[Symbol]): List[Symbol] = (
386-
interfaces filterNot (int1 =>
387-
interfaces exists (int2 =>
388-
(int1 ne int2) && (int2 isSubClass int1)
389-
)
390-
)
391-
)
384+
private def minimizeInterfaces(interfaces: List[Symbol]): List[Symbol] = {
385+
var rest = interfaces
386+
var leaves = List.empty[Symbol]
387+
while(!rest.isEmpty) {
388+
val candidate = rest.head
389+
val nonLeaf = leaves exists { lsym => lsym isSubClass candidate }
390+
if(!nonLeaf) {
391+
leaves = candidate :: (leaves filterNot { lsym => candidate isSubClass lsym })
392+
}
393+
rest = rest.tail
394+
}
395+
396+
leaves
397+
}
392398

393399
def genClass(c: IClass) {
394400
clasz = c
395401
innerClassBuffer.clear()
396402

397403
val name = javaName(c.symbol)
398-
val superClass :: superInterfaces = {
399-
val parents0 = c.symbol.info.parents match {
400-
case Nil => List(ObjectClass.tpe)
401-
case ps => ps
402-
}
403-
parents0 ++ c.symbol.annotations.flatMap(ann => newParentForAttr(ann.symbol)) distinct
404-
}
405-
val ifaces = superInterfaces match {
406-
case Nil => JClass.NO_INTERFACES
407-
case _ => mkArray(minimizeInterfaces(superInterfaces map (_.typeSymbol)) map javaName)
408-
}
404+
405+
val ps = c.symbol.info.parents
406+
407+
val superClass: Symbol = if(ps.isEmpty) ObjectClass else ps.head.typeSymbol;
408+
409+
val superInterfaces0: List[Symbol] = if(ps.isEmpty) Nil else c.symbol.mixinClasses;
410+
val superInterfaces = superInterfaces0 ++ c.symbol.annotations.flatMap(ann => newParentForAttr(ann.symbol)) distinct
411+
412+
val ifaces =
413+
if(superInterfaces.isEmpty) JClass.NO_INTERFACES
414+
else mkArray(minimizeInterfaces(superInterfaces) map javaName)
409415

410416
jclass = fjbgContext.JClass(javaFlags(c.symbol),
411417
name,
412-
javaName(superClass.typeSymbol),
418+
javaName(superClass),
413419
ifaces,
414420
c.cunit.source.toString)
415421

0 commit comments

Comments
 (0)