summaryrefslogtreecommitdiff
path: root/test/files/pos/erasure-nsquared.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2013-08-05 16:41:54 -0700
committerPaul Phillips <paulp@improving.org>2013-08-05 18:23:21 -0700
commit466b7d29f1c70018aea965961e830f50cf0facd4 (patch)
tree70cb04fabc30f4da987c88475172d6acea796792 /test/files/pos/erasure-nsquared.scala
parent46616ea2e94fa6ac7100b1cde66295f68338e18e (diff)
downloadscala-466b7d29f1c70018aea965961e830f50cf0facd4.tar.gz
scala-466b7d29f1c70018aea965961e830f50cf0facd4.tar.bz2
scala-466b7d29f1c70018aea965961e830f50cf0facd4.zip
Fix N^2 spot in erasure.
An expression containing nested casts would type the same tree 2^N times where N is the number of nested casts. This was particularly visible in Vector.scala where one can find a six-cast expression. It's currently line "why was six afraid of seven", aka line 789. display5((index >> 25) & 31) .asInstanceOf[Array[AnyRef]]((index >> 20) & 31) .asInstanceOf[Array[AnyRef]]((index >> 15) & 31) .asInstanceOf[Array[AnyRef]]((index >> 10) & 31) .asInstanceOf[Array[AnyRef]]((index >> 5) & 31) .asInstanceOf[Array[AnyRef]](index & 31) .asInstanceOf[T] Compiling Vector.scala, before/after. < #unique types : 10805 > #unique types : 9722 < #created tree nodes : 26716 > #created tree nodes : 25647 I found a similar bug about a year ago in 39f01d4f48. It's interesting to consider how little defense we have against bugs of this nature - visually non-obvious differences in tree traversal can have spectacular impact on complexity.
Diffstat (limited to 'test/files/pos/erasure-nsquared.scala')
-rw-r--r--test/files/pos/erasure-nsquared.scala35
1 files changed, 35 insertions, 0 deletions
diff --git a/test/files/pos/erasure-nsquared.scala b/test/files/pos/erasure-nsquared.scala
new file mode 100644
index 0000000000..b0e30ade58
--- /dev/null
+++ b/test/files/pos/erasure-nsquared.scala
@@ -0,0 +1,35 @@
+trait BigCast {
+ def bar(x: Int): AnyRef = (
+ null
+ .asInstanceOf[List[AnyRef]].head
+ .asInstanceOf[List[AnyRef]].head
+ .asInstanceOf[List[AnyRef]].head
+ .asInstanceOf[List[AnyRef]].head
+ .asInstanceOf[List[AnyRef]].head
+ .asInstanceOf[List[AnyRef]].head
+ .asInstanceOf[List[AnyRef]].head
+ .asInstanceOf[List[AnyRef]].head
+ .asInstanceOf[List[AnyRef]].head
+ .asInstanceOf[List[AnyRef]].head
+ .asInstanceOf[List[AnyRef]].head
+ .asInstanceOf[List[AnyRef]].head
+ .asInstanceOf[List[AnyRef]].head
+ .asInstanceOf[List[AnyRef]].head
+ .asInstanceOf[List[AnyRef]].head
+ .asInstanceOf[List[AnyRef]].head
+ .asInstanceOf[List[AnyRef]].head
+ .asInstanceOf[List[AnyRef]].head
+ .asInstanceOf[List[AnyRef]].head
+ .asInstanceOf[List[AnyRef]].head
+ .asInstanceOf[List[AnyRef]].head
+ .asInstanceOf[List[AnyRef]].head
+ .asInstanceOf[List[AnyRef]].head
+ .asInstanceOf[List[AnyRef]].head
+ .asInstanceOf[List[AnyRef]].head
+ .asInstanceOf[List[AnyRef]].head
+ .asInstanceOf[List[AnyRef]].head
+ .asInstanceOf[List[AnyRef]].head
+ .asInstanceOf[List[AnyRef]].head
+ .asInstanceOf[List[AnyRef]].head
+ )
+}