diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2016-06-06 14:24:38 +1000 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2016-06-28 09:18:34 -0700 |
commit | 91b066aac5edf53ca18603f8486eb255514b3118 (patch) | |
tree | f080d3593134e1bb48841d953259f3bd7e3b94e1 /src/compiler | |
parent | d3c0885a1a88e9d52902a527650319010d7ced67 (diff) | |
download | scala-91b066aac5edf53ca18603f8486eb255514b3118.tar.gz scala-91b066aac5edf53ca18603f8486eb255514b3118.tar.bz2 scala-91b066aac5edf53ca18603f8486eb255514b3118.zip |
Revert pruning of redundant Java parents
This partially reverts the fix for SI-5278 made in 7a99c03da.
The original motivation for this case to avoid bytecode that
stretched platform limitations in Android.
For super calls to Scala defined trait methods, we won't
use `invokespecial`, but rather use `invokestatic` to a
static trait implementation method. As such, we can continue
to prune redundant Scala interfaces.
It might be worth considering removing the pruning of
redundant parents altoghether, though:
- We no longer include `ScalaObject` as a parent of every class,
which was mentioned as a problem in SI-5728.
- Scala 2.12 has left Android behind for the time being
due to use of Java 8 facilities.
- javac doesn't do this, so why should we?
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/Erasure.scala | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala index 5e903946c1..db8e203c1c 100644 --- a/src/compiler/scala/tools/nsc/transform/Erasure.scala +++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala @@ -189,18 +189,23 @@ abstract class Erasure extends AddInterfaces /* Drop redundant types (ones which are implemented by some other parent) from the immediate parents. * This is important on Android because there is otherwise an interface explosion. + * This is now restricted to Scala defined ancestors: a Java defined ancestor may need to be listed + * as an immediate parent to support an `invokespecial`. */ def minimizeParents(parents: List[Type]): List[Type] = if (parents.isEmpty) parents else { - def isInterfaceOrTrait(sym: Symbol) = sym.isInterface || sym.isTrait + def isRedundantParent(sym: Symbol) = sym.isInterface || sym.isTrait var rest = parents.tail var leaves = collection.mutable.ListBuffer.empty[Type] += parents.head while(rest.nonEmpty) { val candidate = rest.head - val nonLeaf = leaves exists { t => t.typeSymbol isSubClass candidate.typeSymbol } - if(!nonLeaf) { - leaves = leaves filterNot { t => isInterfaceOrTrait(t.typeSymbol) && (candidate.typeSymbol isSubClass t.typeSymbol) } - leaves += candidate + if (candidate.typeSymbol.isJavaDefined && candidate.typeSymbol.isInterface) leaves += candidate + else { + val nonLeaf = leaves exists { t => t.typeSymbol isSubClass candidate.typeSymbol } + if (!nonLeaf) { + leaves = leaves filterNot { t => isRedundantParent(t.typeSymbol) && (candidate.typeSymbol isSubClass t.typeSymbol) } + leaves += candidate + } } rest = rest.tail } |