summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/backend
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2016-03-31 16:06:56 -0700
committerAdriaan Moors <adriaan.moors@typesafe.com>2016-03-31 16:06:56 -0700
commit5654ebddb63d078f9f79dcf84fbb8489030136f6 (patch)
treed4bfc365cdf8e4993113275136f14803ceab3abd /src/compiler/scala/tools/nsc/backend
parent4fc7d5517c7152d43745960efde5042febe29422 (diff)
parent5e5ab186fe5b8cf047fd3da58da29dbc8f9fbd71 (diff)
downloadscala-5654ebddb63d078f9f79dcf84fbb8489030136f6.tar.gz
scala-5654ebddb63d078f9f79dcf84fbb8489030136f6.tar.bz2
scala-5654ebddb63d078f9f79dcf84fbb8489030136f6.zip
Merge pull request #4971 from adriaanm/genbcode-delambdafy
Unify treatment of built-in functions and SAMs
Diffstat (limited to 'src/compiler/scala/tools/nsc/backend')
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/BCodeBodyBuilder.scala5
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala4
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/CoreBTypes.scala14
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/analysis/BackendUtils.scala4
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/opt/CopyProp.scala4
5 files changed, 15 insertions, 16 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BCodeBodyBuilder.scala b/src/compiler/scala/tools/nsc/backend/jvm/BCodeBodyBuilder.scala
index b4d645d4bb..08b5a0afa1 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/BCodeBodyBuilder.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/BCodeBodyBuilder.scala
@@ -659,7 +659,7 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
case Apply(fun, args) if app.hasAttachment[delambdafy.LambdaMetaFactoryCapable] =>
val attachment = app.attachments.get[delambdafy.LambdaMetaFactoryCapable].get
genLoadArguments(args, paramTKs(app))
- genInvokeDynamicLambda(attachment.target, attachment.arity, attachment.functionalInterface)
+ genInvokeDynamicLambda(attachment.target, attachment.arity, attachment.functionalInterface, attachment.sam)
generatedType = methodBTypeFromSymbol(fun.symbol).returnType
case Apply(fun @ _, List(expr)) if currentRun.runDefinitions.isBox(fun.symbol) =>
@@ -1360,7 +1360,7 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
def genSynchronized(tree: Apply, expectedType: BType): BType
def genLoadTry(tree: Try): BType
- def genInvokeDynamicLambda(lambdaTarget: Symbol, arity: Int, functionalInterface: Symbol) {
+ def genInvokeDynamicLambda(lambdaTarget: Symbol, arity: Int, functionalInterface: Symbol, sam: Symbol) {
val isStaticMethod = lambdaTarget.hasFlag(Flags.STATIC)
def asmType(sym: Symbol) = classBTypeFromSymbol(sym).toASMType
@@ -1375,7 +1375,6 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
val invokedType = asm.Type.getMethodDescriptor(asmType(functionalInterface), (receiver ::: capturedParams).map(sym => typeToBType(sym.info).toASMType): _*)
val constrainedType = new MethodBType(lambdaParams.map(p => typeToBType(p.tpe)), typeToBType(lambdaTarget.tpe.resultType)).toASMType
- val sam = functionalInterface.info.decls.find(_.isDeferred).getOrElse(functionalInterface.info.member(nme.apply))
val samName = sam.name.toString
val samMethodType = methodBTypeFromSymbol(sam).toASMType
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala b/src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala
index 324fc10eae..807e0cc72f 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala
@@ -61,6 +61,8 @@ abstract class BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
assert(classSym.isClass, s"not a class: $classSym")
val r = exitingPickler(classSym.isAnonymousClass) || !classSym.originalOwner.isClass
if (r) {
+ // lambda lift renames symbols and may accidentally introduce `$lambda` into a class name, making `isDelambdafyFunction` true.
+ // we prevent this, see `nonAnon` in LambdaLift.
// phase travel necessary: after flatten, the name includes the name of outer classes.
// if some outer name contains $lambda, a non-lambda class is considered lambda.
assert(exitingPickler(!classSym.isDelambdafyFunction), classSym.name)
@@ -260,7 +262,7 @@ abstract class BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
else {
// Phase travel necessary. For example, nullary methods (getter of an abstract val) get an
// empty parameter list in later phases and would therefore be picked as SAM.
- val samSym = exitingPickler(definitions.findSam(classSym.tpe))
+ val samSym = exitingPickler(definitions.samOf(classSym.tpe))
if (samSym == NoSymbol) None
else Some(samSym.javaSimpleName.toString + methodSymToDescriptor(samSym))
}
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/CoreBTypes.scala b/src/compiler/scala/tools/nsc/backend/jvm/CoreBTypes.scala
index 696a164c56..ab9fd94a93 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/CoreBTypes.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/CoreBTypes.scala
@@ -219,14 +219,12 @@ class CoreBTypes[BTFS <: BTypesFromSymbols[_ <: Global]](val bTypes: BTFS) {
// enumeration of specialized classes is temporary, while we still use the java-defined JFunctionN.
// once we switch to ordinary FunctionN, we can use specializedSubclasses just like for tuples.
- private def functionClasses(base: String): Set[Symbol] = {
- def primitives = Iterator("B", "S", "I", "J", "C", "F", "D", "Z", "V")
+ private def specializedJFunctionSymbols(base: String): Seq[Symbol] = {
+ def primitives = Seq("B", "S", "I", "J", "C", "F", "D", "Z", "V")
def ijfd = Iterator("I", "J", "F", "D")
def ijfdzv = Iterator("I", "J", "F", "D", "Z", "V")
def ijd = Iterator("I", "J", "D")
- val classNames = Set.empty[String] ++ {
- (0 to 22).map(base + _)
- } ++ {
+ val classNames = {
primitives.map(base + "0$mc" + _ + "$sp") // Function0
} ++ {
// return type specializations appear first in the name string (alphabetical sorting)
@@ -237,7 +235,7 @@ class CoreBTypes[BTFS <: BTypesFromSymbols[_ <: Global]](val bTypes: BTFS) {
classNames map getRequiredClass
}
- lazy val srJFunctionRefs: Set[InternalName] = functionClasses("scala.runtime.java8.JFunction").map(classBTypeFromSymbol(_).internalName)
+ lazy val functionRefs: Set[InternalName] = (FunctionClass.seq ++ specializedJFunctionSymbols("scala.runtime.java8.JFunction")).map(classBTypeFromSymbol(_).internalName).toSet
lazy val typeOfArrayOp: Map[Int, BType] = {
import scalaPrimitives._
@@ -343,7 +341,7 @@ trait CoreBTypesProxyGlobalIndependent[BTS <: BTypes] {
def srRefConstructors : Map[InternalName, MethodNameAndType]
def tupleClassConstructors : Map[InternalName, MethodNameAndType]
- def srJFunctionRefs: Set[InternalName]
+ def functionRefs: Set[InternalName]
def lambdaMetaFactoryBootstrapHandle : asm.Handle
def lambdaDeserializeBootstrapHandle : asm.Handle
@@ -410,7 +408,7 @@ final class CoreBTypesProxy[BTFS <: BTypesFromSymbols[_ <: Global]](val bTypes:
def srRefConstructors : Map[InternalName, MethodNameAndType] = _coreBTypes.srRefConstructors
def tupleClassConstructors : Map[InternalName, MethodNameAndType] = _coreBTypes.tupleClassConstructors
- def srJFunctionRefs: Set[InternalName] = _coreBTypes.srJFunctionRefs
+ def functionRefs: Set[InternalName] = _coreBTypes.functionRefs
def srSymbolLiteral : ClassBType = _coreBTypes.srSymbolLiteral
def srStructuralCallSite : ClassBType = _coreBTypes.srStructuralCallSite
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/analysis/BackendUtils.scala b/src/compiler/scala/tools/nsc/backend/jvm/analysis/BackendUtils.scala
index bd7d5d2608..a6b9faa933 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/analysis/BackendUtils.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/analysis/BackendUtils.scala
@@ -125,7 +125,7 @@ class BackendUtils[BT <: BTypes](val btypes: BT) {
private val anonfunAdaptedName = """.*\$anonfun\$\d+\$adapted""".r
def hasAdaptedImplMethod(closureInit: ClosureInstantiation): Boolean = {
- isrJFunctionType(Type.getReturnType(closureInit.lambdaMetaFactoryCall.indy.desc).getInternalName) &&
+ isBuiltinFunctionType(Type.getReturnType(closureInit.lambdaMetaFactoryCall.indy.desc).getInternalName) &&
anonfunAdaptedName.pattern.matcher(closureInit.lambdaMetaFactoryCall.implMethod.getName).matches
}
@@ -250,7 +250,7 @@ class BackendUtils[BT <: BTypes](val btypes: BT) {
}
}
- def isrJFunctionType(internalName: InternalName): Boolean = srJFunctionRefs(internalName)
+ def isBuiltinFunctionType(internalName: InternalName): Boolean = functionRefs(internalName)
/**
* Visit the class node and collect all referenced nested classes.
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/opt/CopyProp.scala b/src/compiler/scala/tools/nsc/backend/jvm/opt/CopyProp.scala
index f1eaebd27c..d28565b9bc 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/opt/CopyProp.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/opt/CopyProp.scala
@@ -296,11 +296,11 @@ class CopyProp[BT <: BTypes](val btypes: BT) {
/**
* Eliminate the closure value produced by `indy`. If the SAM type is known to construct
- * without side-effects (e.g. scala/runtime/java8/JFunctionN), the `indy` and its inputs
+ * without side-effects (e.g. scala/FunctionN), the `indy` and its inputs
* are eliminated, otherwise a POP is inserted.
*/
def handleClosureInst(indy: InvokeDynamicInsnNode): Unit = {
- if (isrJFunctionType(Type.getReturnType(indy.desc).getInternalName)) {
+ if (isBuiltinFunctionType(Type.getReturnType(indy.desc).getInternalName)) {
toRemove += indy
callGraph.removeClosureInstantiation(indy, method)
handleInputs(indy, Type.getArgumentTypes(indy.desc).length)