summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2014-06-02 13:20:58 +0200
committerJason Zaugg <jzaugg@gmail.com>2015-04-10 12:04:34 +1000
commitea61b3f66007b1a0029a5f22a7de334924390f7c (patch)
tree5a204a737f83d56e05b94c10bdb15d32b661060a /src/compiler
parentd14e065eb792a1eb77289f4a1320071c57c5d09b (diff)
downloadscala-ea61b3f66007b1a0029a5f22a7de334924390f7c.tar.gz
scala-ea61b3f66007b1a0029a5f22a7de334924390f7c.tar.bz2
scala-ea61b3f66007b1a0029a5f22a7de334924390f7c.zip
Disable -Ydelambdafy:method for specialized FunctionN
The Delambdafy phase generates its `FunctionN` subclasses after the specialization phase. As such, `((x: Int) => x).apply(42)` incurs boxing. This commit falls back to the `-Ydelambdafy:inline` in this case. This is done by running the specialization type map over the type of the function, and seeing if anything changes. To make this work robustly, we first need to ensure that the specialization info transformer has processed all the function types. This is not a fundamental limitation; we could in principle generate the specialized code. A followup change will use `-Ydelambdafy:method` as the basis for invokedymnamic lambdas. As part of that stream of work, we will synthesize specialization-aware lambdas, and remove the fallback to `-Ydelambdafy:inline`. I have updated some tests that intend to test the delambdafy transform to avoid use of specialized function types.
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/transform/UnCurry.scala18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala
index 3544dc9966..001fd71bfb 100644
--- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala
+++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala
@@ -70,6 +70,14 @@ abstract class UnCurry extends InfoTransform
private val noApply = mutable.HashSet[Tree]()
private val newMembers = mutable.Map[Symbol, mutable.Buffer[Tree]]()
+ private lazy val forceSpecializationInfoTransformOfFunctionN: Unit = {
+ if (currentRun.specializePhase != NoPhase) { // be robust in case of -Ystop-after:uncurry
+ exitingSpecialize {
+ FunctionClass.seq.foreach(cls => cls.info)
+ }
+ }
+ }
+
/** Add a new synthetic member for `currentOwner` */
private def addNewMember(t: Tree): Unit =
newMembers.getOrElseUpdate(currentOwner, mutable.Buffer()) += t
@@ -220,8 +228,16 @@ abstract class UnCurry extends InfoTransform
def mkMethod(owner: Symbol, name: TermName, additionalFlags: FlagSet = NoFlags): DefDef =
gen.mkMethodFromFunction(localTyper)(fun, owner, name, additionalFlags)
- val canUseDelamdafyMethod = (inConstructorFlag == 0) // Avoiding synthesizing code prone to SI-6666, SI-8363 by using old-style lambda translation
+ def isSpecialized = {
+ forceSpecializationInfoTransformOfFunctionN
+ val specialized = specializeTypes.specializedType(fun.tpe)
+ !(specialized =:= fun.tpe)
+ }
+ def canUseDelamdafyMethod = (
+ (inConstructorFlag == 0) // Avoiding synthesizing code prone to SI-6666, SI-8363 by using old-style lambda translation
+ && !isSpecialized // DelambdafyTransformer currently only emits generic FunctionN-s, use the old style in the meantime
+ )
if (inlineFunctionExpansion || !canUseDelamdafyMethod) {
val parents = addSerializable(abstractFunctionForFunctionType(fun.tpe))
val anonClass = fun.symbol.owner newAnonymousFunctionClass(fun.pos, inConstructorFlag) addAnnotation SerialVersionUIDAnnotation