aboutsummaryrefslogtreecommitdiff
path: root/tests/pos/IterableSelfRec.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-05-20 12:11:14 +0200
committerMartin Odersky <odersky@gmail.com>2015-05-21 17:41:16 +0200
commit78640ebad658ddd38e86a9d98c6bbcdd83708397 (patch)
tree9c5a71e27b902322ae1bbf68784b1136fac1ebab /tests/pos/IterableSelfRec.scala
parent10bb6a0e5efa8cc76f7bd6215ca3d2a44070850a (diff)
downloaddotty-78640ebad658ddd38e86a9d98c6bbcdd83708397.tar.gz
dotty-78640ebad658ddd38e86a9d98c6bbcdd83708397.tar.bz2
dotty-78640ebad658ddd38e86a9d98c6bbcdd83708397.zip
Calibrate findMember logging thresholds and test case
Adds IterableSelfRec.scala which caused lockup of the compiler. After a lot of work the problem was determined to be polyomial or exponential behavior of the compiler when executing findMember on refined types that contain several bindings where the resutling & causes a recursive invokation of findMember with the same name. We do have a stop for this now, but if the stop comes too late the runtime will grow very fast. Problem addressed by kiccking in earlier with the stopping logic.
Diffstat (limited to 'tests/pos/IterableSelfRec.scala')
-rw-r--r--tests/pos/IterableSelfRec.scala52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/pos/IterableSelfRec.scala b/tests/pos/IterableSelfRec.scala
new file mode 100644
index 000000000..bba7a82d2
--- /dev/null
+++ b/tests/pos/IterableSelfRec.scala
@@ -0,0 +1,52 @@
+package dotty.collection
+package immutable
+
+import annotation.unchecked.uncheckedVariance
+
+trait Collection[T] { self =>
+ type This <: Collection { type This <: self.This }
+ def companion: CollectionCompanion[This]
+}
+
+trait Iterable[T] extends Collection[T] { self =>
+ type This <: Iterable { type This <: self.This }
+ override def companion: IterableCompanion[This] = Iterable.asInstanceOf
+
+ def iterator: Iterator[T]
+}
+
+trait Seq[T] extends Iterable[T] { self =>
+ type This <: Seq { type This <: self.This }
+ override def companion: IterableCompanion[This] = Seq.asInstanceOf
+
+ def apply(x: Int): T
+}
+
+abstract class CollectionCompanion[+CC <: Collection { type This <: CC }]
+
+abstract class IterableCompanion[+CC <: Iterable { type This <: CC }] extends CollectionCompanion[CC] {
+ def fromIterator[T](it: Iterator[T]): CC[T]
+ def map[T, U](xs: Iterable[T], f: T => U): CC[U] =
+ fromIterator(xs.iterator.map(f))
+ def filter[T](xs: Iterable[T], p: T => Boolean): CC[T] =
+ fromIterator(xs.iterator.filter(p))
+ def flatMap[T, U](xs: Iterable[T], f: T => TraversableOnce[U]): CC[U] =
+ fromIterator(xs.iterator.flatMap(f))
+
+ implicit def transformOps[T](xs: CC[T] @uncheckedVariance): TransformOps[CC, T] = ??? // new TransformOps[CC, T](xs)
+}
+
+class TransformOps[+CC <: Iterable { type This <: CC }, T] (val xs: CC[T]) extends AnyVal {
+ def companion[T](xs: CC[T] @uncheckedVariance): IterableCompanion[CC] = xs.companion
+ def map[U](f: T => U): CC[U] = companion(xs).map(xs, f)
+ def filter(p: T => Boolean): CC[T] = companion(xs).filter(xs, p)
+ def flatMap[U](f: T => TraversableOnce[U]): CC[U] = companion(xs).flatMap(xs, f)
+}
+
+object Iterable extends IterableCompanion[Iterable] {
+ def fromIterator[T](it: Iterator[T]): Iterable[T] = ???
+}
+object Seq extends IterableCompanion[Seq] {
+ def fromIterator[T](it: Iterator[T]): Seq[T] = ???
+}
+