summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala')
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala72
1 files changed, 51 insertions, 21 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala
index abe3bc512c..86a69b92ea 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala
@@ -9,6 +9,7 @@ package backend.jvm
import scala.collection.{ mutable, immutable }
import scala.reflect.internal.pickling.{ PickleFormat, PickleBuffer }
+import scala.tools.nsc.backend.jvm.opt.InlineInfoAttribute
import scala.tools.nsc.symtab._
import scala.tools.asm
import asm.Label
@@ -532,7 +533,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters { self =>
}
bytecodeWriter.writeClass(label, jclassName, arr, outF)
} catch {
- case e: java.lang.RuntimeException if e != null && (e.getMessage contains "too large!") =>
+ case e: java.lang.RuntimeException if e.getMessage != null && (e.getMessage contains "too large!") =>
reporter.error(sym.pos,
s"Could not write class $jclassName because it exceeds JVM code size limits. ${e.getMessage}")
}
@@ -595,7 +596,8 @@ abstract class GenASM extends SubComponent with BytecodeWriters { self =>
val x = innerClassSymbolFor(s)
if(x ne NoSymbol) {
assert(x.isClass, "not an inner-class symbol")
- val isInner = !x.rawowner.isPackageClass
+ // impl classes are considered top-level, see comment in BTypes
+ val isInner = !considerAsTopLevelImplementationArtifact(s) && !x.rawowner.isPackageClass
if (isInner) {
innerClassBuffer += x
collectInnerClass(x.rawowner)
@@ -692,30 +694,55 @@ abstract class GenASM extends SubComponent with BytecodeWriters { self =>
}
}
- def innerName(innerSym: Symbol): String =
- if (innerSym.isAnonymousClass || innerSym.isAnonymousFunction)
- null
- else
- innerSym.rawname + innerSym.moduleSuffix
+ def innerName(innerSym: Symbol): String = {
+ // phase travel necessary: after flatten, the name includes the name of outer classes.
+ // if some outer name contains $anon, a non-anon class is considered anon.
+ if (exitingPickler(innerSym.isAnonymousClass || innerSym.isAnonymousFunction)) null
+ else innerSym.rawname + innerSym.moduleSuffix
+ }
+
+ val linkedClass = exitingPickler(csym.linkedClassOfClass) // linkedCoC does not work properly in late phases
innerClassBuffer ++= {
- val members = exitingPickler(memberClassesOf(csym))
+ val members = exitingPickler(memberClassesForInnerClassTable(csym))
// lambdalift makes all classes (also local, anonymous) members of their enclosing class
- val allNested = exitingPhase(currentRun.lambdaliftPhase)(memberClassesOf(csym))
+ val allNested = exitingPhase(currentRun.lambdaliftPhase)(memberClassesForInnerClassTable(csym))
+ val nested = {
+ // Classes nested in value classes are nested in the companion at this point. For InnerClass /
+ // EnclosingMethod, we use the value class as the outer class. So we remove nested classes
+ // from the companion that were originally nested in the value class.
+ if (exitingPickler(linkedClass.isDerivedValueClass)) allNested.filterNot(classOriginallyNestedInClass(_, linkedClass))
+ else allNested
+ }
- // for the mirror class, we take the members of the companion module class (Java compat,
- // see doc in BTypes.scala). for module classes, we filter out those members.
- if (isMirror) members
- else if (isTopLevelModule(csym)) allNested diff members
- else allNested
- }
+ // for the mirror class, we take the members of the companion module class (Java compat, see doc in BTypes.scala).
+ // for module classes, we filter out those members.
+ if (isMirror) members
+ else if (isTopLevelModule(csym)) nested diff members
+ else nested
+ }
+
+ if (!considerAsTopLevelImplementationArtifact(csym)) {
+ // If this is a top-level non-impl class, add members of the companion object. These are the
+ // classes for which we change the InnerClass entry to allow using them from Java.
+ // We exclude impl classes: if the classfile for the impl class exists on the classpath, a
+ // linkedClass symbol is found for which isTopLevelModule is true, so we end up searching
+ // members of that weird impl-class-module-class-symbol. that search probably cannot return
+ // any classes, but it's better to exclude it.
+ if (linkedClass != NoSymbol && isTopLevelModule(linkedClass)) {
+ // phase travel to exitingPickler: this makes sure that memberClassesForInnerClassTable only
+ // sees member classes, not local classes that were lifted by lambdalift.
+ innerClassBuffer ++= exitingPickler(memberClassesForInnerClassTable(linkedClass))
+ }
- // If this is a top-level class, add members of the companion object.
- val linkedClass = exitingPickler(csym.linkedClassOfClass) // linkedCoC does not work properly in late phases
- if (isTopLevelModule(linkedClass)) {
- // phase travel to exitingPickler: this makes sure that memberClassesOf only sees member classes,
- // not local classes that were lifted by lambdalift.
- innerClassBuffer ++= exitingPickler(memberClassesOf(linkedClass))
+ // Classes nested in value classes are nested in the companion at this point. For InnerClass /
+ // EnclosingMethod we use the value class as enclosing class. Here we search nested classes
+ // in the companion that were originally nested in the value class, and we add them as nested
+ // in the value class.
+ if (linkedClass != NoSymbol && exitingPickler(csym.isDerivedValueClass)) {
+ val moduleMemberClasses = exitingPhase(currentRun.lambdaliftPhase)(memberClassesForInnerClassTable(linkedClass))
+ innerClassBuffer ++= moduleMemberClasses.filter(classOriginallyNestedInClass(_, csym))
+ }
}
val allInners: List[Symbol] = innerClassBuffer.toList filterNot deadCode.elidedClosures
@@ -1266,6 +1293,9 @@ abstract class GenASM extends SubComponent with BytecodeWriters { self =>
jclass.visitAttribute(if(ssa.isDefined) pickleMarkerLocal else pickleMarkerForeign)
emitAnnotations(jclass, c.symbol.annotations ++ ssa)
+ if (!settings.YskipInlineInfoAttribute.value)
+ jclass.visitAttribute(InlineInfoAttribute(buildInlineInfoFromClassSymbol(c.symbol, javaName, javaType(_).getDescriptor)))
+
// typestate: entering mode with valid call sequences:
// ( visitInnerClass | visitField | visitMethod )* visitEnd