summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2013-03-13 23:30:05 +0100
committerJason Zaugg <jzaugg@gmail.com>2013-03-13 23:35:22 +0100
commit552b6234dbbb4ff1e971e2c0f87ecd4090dd36a5 (patch)
tree50c72971b13daedd3c2825030327fdf2abe5f1be /src
parentb7b4f877326acd6a8a24ff60fa1638cc18143c45 (diff)
downloadscala-552b6234dbbb4ff1e971e2c0f87ecd4090dd36a5.tar.gz
scala-552b6234dbbb4ff1e971e2c0f87ecd4090dd36a5.tar.bz2
scala-552b6234dbbb4ff1e971e2c0f87ecd4090dd36a5.zip
SI-7249 Reign in overzealous Function0 optimization.
The fix for SI-1247 went too far, and could result in premature evaluation of the expression that yields the Function0. This commit checks that said expression is safe to inline. If not, a wrapper `() => ....` is still required. The optimization is still enabled in sitations like the original test case, run/t1247.scala.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/transform/UnCurry.scala6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala
index e9f403aea0..66328e23bb 100644
--- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala
+++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala
@@ -492,10 +492,14 @@ abstract class UnCurry extends InfoTransform
}
else {
log(s"Argument '$arg' at line ${arg.pos.safeLine} is $formal from ${fun.fullName}")
+ def canUseDirectly(recv: Tree) = (
+ recv.tpe.typeSymbol.isSubClass(FunctionClass(0))
+ && treeInfo.isExprSafeToInline(recv)
+ )
arg match {
// don't add a thunk for by-name argument if argument already is an application of
// a Function0. We can then remove the application and use the existing Function0.
- case Apply(Select(recv, nme.apply), Nil) if recv.tpe.typeSymbol isSubClass FunctionClass(0) =>
+ case Apply(Select(recv, nme.apply), Nil) if canUseDirectly(recv) =>
recv
case _ =>
newFunction0(arg)