summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/transform/CleanUp.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-11-05 12:10:30 -0800
committerPaul Phillips <paulp@improving.org>2012-11-05 12:10:30 -0800
commit757a3a738cbb373f8f10fdc1f01e9ab6176a7076 (patch)
tree4ebbc8cd4163c7ec470cec0940d33d0812fd312f /src/compiler/scala/tools/nsc/transform/CleanUp.scala
parent3d248efcc1925acb7f73b2b2db2184f8d33b68ad (diff)
parent092345a24c22a821204fb358d33272ae8f7353be (diff)
downloadscala-757a3a738cbb373f8f10fdc1f01e9ab6176a7076.tar.gz
scala-757a3a738cbb373f8f10fdc1f01e9ab6176a7076.tar.bz2
scala-757a3a738cbb373f8f10fdc1f01e9ab6176a7076.zip
Merge pull request #1568 from retronym/ticket/6611
SI-6611 Tighten up an unsafe array optimization
Diffstat (limited to 'src/compiler/scala/tools/nsc/transform/CleanUp.scala')
-rw-r--r--src/compiler/scala/tools/nsc/transform/CleanUp.scala19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/CleanUp.scala b/src/compiler/scala/tools/nsc/transform/CleanUp.scala
index 2e504af47f..3b74cb1168 100644
--- a/src/compiler/scala/tools/nsc/transform/CleanUp.scala
+++ b/src/compiler/scala/tools/nsc/transform/CleanUp.scala
@@ -15,6 +15,7 @@ abstract class CleanUp extends Transform with ast.TreeDSL {
import global._
import definitions._
import CODE._
+ import treeInfo.StripCast
/** the following two members override abstract members in Transform */
val phaseName: String = "cleanup"
@@ -618,14 +619,16 @@ abstract class CleanUp extends Transform with ast.TreeDSL {
}
transformApply
- // This transform replaces Array(Predef.wrapArray(Array(...)), <tag>)
- // with just Array(...)
- case Apply(appMeth, List(Apply(wrapRefArrayMeth, List(array)), _))
- if (wrapRefArrayMeth.symbol == Predef_wrapRefArray &&
- appMeth.symbol == ArrayModule_overloadedApply.suchThat {
- _.tpe.resultType.dealias.typeSymbol == ObjectClass
- }) =>
- super.transform(array)
+ // Replaces `Array(Predef.wrapArray(ArrayValue(...).$asInstanceOf[...]), <tag>)`
+ // with just `ArrayValue(...).$asInstanceOf[...]`
+ //
+ // See SI-6611; we must *only* do this for literal vararg arrays.
+ case Apply(appMeth, List(Apply(wrapRefArrayMeth, List(arg @ StripCast(ArrayValue(_, _)))), _))
+ if wrapRefArrayMeth.symbol == Predef_wrapRefArray && appMeth.symbol == ArrayModule_genericApply =>
+ super.transform(arg)
+ case Apply(appMeth, List(elem0, Apply(wrapArrayMeth, List(rest @ ArrayValue(elemtpt, _)))))
+ if wrapArrayMeth.symbol == Predef_wrapArray(elemtpt.tpe) && appMeth.symbol == ArrayModule_apply(elemtpt.tpe) =>
+ super.transform(rest.copy(elems = elem0 :: rest.elems))
case _ =>
super.transform(tree)