Skip to content

Commit

Permalink
Merge pull request #3480 from paulp/pr/publicize-abstract-star
Browse files Browse the repository at this point in the history
 Make the Abstract* classes public.
  • Loading branch information
gkossakowski committed Feb 10, 2014
2 parents 2ee1328 + 51ec62a commit 90aa12e
Show file tree
Hide file tree
Showing 15 changed files with 205 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/library/scala/collection/Iterable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ object Iterable extends TraversableFactory[Iterable] {
}

/** Explicit instantiation of the `Iterable` trait to reduce class file size in subclasses. */
private[scala] abstract class AbstractIterable[+A] extends AbstractTraversable[A] with Iterable[A]
abstract class AbstractIterable[+A] extends AbstractTraversable[A] with Iterable[A]
2 changes: 1 addition & 1 deletion src/library/scala/collection/Iterator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1171,4 +1171,4 @@ trait Iterator[+A] extends TraversableOnce[A] {
}

/** Explicit instantiation of the `Iterator` trait to reduce class file size in subclasses. */
private[scala] abstract class AbstractIterator[+A] extends Iterator[A]
abstract class AbstractIterator[+A] extends Iterator[A]
2 changes: 1 addition & 1 deletion src/library/scala/collection/Map.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ object Map extends MapFactory[Map] {
}

/** Explicit instantiation of the `Map` trait to reduce class file size in subclasses. */
private[scala] abstract class AbstractMap[A, +B] extends AbstractIterable[(A, B)] with Map[A, B]
abstract class AbstractMap[A, +B] extends AbstractIterable[(A, B)] with Map[A, B]
2 changes: 1 addition & 1 deletion src/library/scala/collection/Seq.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ object Seq extends SeqFactory[Seq] {
}

/** Explicit instantiation of the `Seq` trait to reduce class file size in subclasses. */
private[scala] abstract class AbstractSeq[+A] extends AbstractIterable[A] with Seq[A]
abstract class AbstractSeq[+A] extends AbstractIterable[A] with Seq[A]
2 changes: 1 addition & 1 deletion src/library/scala/collection/Set.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ object Set extends SetFactory[Set] {
}

/** Explicit instantiation of the `Set` trait to reduce class file size in subclasses. */
private[scala] abstract class AbstractSet[A] extends AbstractIterable[A] with Set[A]
abstract class AbstractSet[A] extends AbstractIterable[A] with Set[A]
2 changes: 1 addition & 1 deletion src/library/scala/collection/Traversable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ object Traversable extends TraversableFactory[Traversable] { self =>
}

/** Explicit instantiation of the `Traversable` trait to reduce class file size in subclasses. */
private[scala] abstract class AbstractTraversable[+A] extends Traversable[A]
abstract class AbstractTraversable[+A] extends Traversable[A]
6 changes: 3 additions & 3 deletions src/library/scala/collection/immutable/Map.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ trait Map[A, +B] extends Iterable[(A, B)]
with MapLike[A, B, Map[A, B]] { self =>

override def empty: Map[A, B] = Map.empty

/** Returns this $coll as an immutable map.
*
*
* A new map will not be built; lazy collections will stay lazy.
*/
@deprecatedOverriding("Immutable maps should do nothing on toMap except return themselves cast as a map.", "2.11.0")
Expand Down Expand Up @@ -191,4 +191,4 @@ object Map extends ImmutableMapFactory[Map] {
}

/** Explicit instantiation of the `Map` trait to reduce class file size in subclasses. */
private[scala] abstract class AbstractMap[A, +B] extends scala.collection.AbstractMap[A, B] with Map[A, B]
abstract class AbstractMap[A, +B] extends scala.collection.AbstractMap[A, B] with Map[A, B]
2 changes: 1 addition & 1 deletion src/library/scala/collection/mutable/Buffer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ object Buffer extends SeqFactory[Buffer] {
}

/** Explicit instantiation of the `Buffer` trait to reduce class file size in subclasses. */
private[scala] abstract class AbstractBuffer[A] extends AbstractSeq[A] with Buffer[A]
abstract class AbstractBuffer[A] extends AbstractSeq[A] with Buffer[A]
2 changes: 1 addition & 1 deletion src/library/scala/collection/mutable/Iterable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ object Iterable extends TraversableFactory[Iterable] {
}

/** Explicit instantiation of the `Iterable` trait to reduce class file size in subclasses. */
private[scala] abstract class AbstractIterable[A] extends scala.collection.AbstractIterable[A] with Iterable[A]
abstract class AbstractIterable[A] extends scala.collection.AbstractIterable[A] with Iterable[A]
2 changes: 1 addition & 1 deletion src/library/scala/collection/mutable/Map.scala
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ object Map extends MutableMapFactory[Map] {
}

/** Explicit instantiation of the `Map` trait to reduce class file size in subclasses. */
private[scala] abstract class AbstractMap[A, B] extends scala.collection.AbstractMap[A, B] with Map[A, B]
abstract class AbstractMap[A, B] extends scala.collection.AbstractMap[A, B] with Map[A, B]
2 changes: 1 addition & 1 deletion src/library/scala/collection/mutable/Seq.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ object Seq extends SeqFactory[Seq] {
}

/** Explicit instantiation of the `Seq` trait to reduce class file size in subclasses. */
private[scala] abstract class AbstractSeq[A] extends scala.collection.AbstractSeq[A] with Seq[A]
abstract class AbstractSeq[A] extends scala.collection.AbstractSeq[A] with Seq[A]
2 changes: 1 addition & 1 deletion src/library/scala/collection/mutable/Set.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ object Set extends MutableSetFactory[Set] {
}

/** Explicit instantiation of the `Set` trait to reduce class file size in subclasses. */
private[scala] abstract class AbstractSet[A] extends AbstractIterable[A] with Set[A]
abstract class AbstractSet[A] extends AbstractIterable[A] with Set[A]
10 changes: 10 additions & 0 deletions test/files/pos/t6948.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
object t6948 {
val rand = new scala.util.Random()
def a1 = rand.shuffle(0 to 5)
// Tis not to be
// def a2 = rand.shuffle(0 until 5)
def a3 = rand.shuffle(Vector(1, 2, 3))
def a4 = rand.shuffle(scala.collection.Seq(1, 2, 3))
def a5 = rand.shuffle(scala.collection.immutable.Seq(1, 2, 3))
def a6 = rand.shuffle(scala.collection.mutable.Seq(1, 2, 3))
}
56 changes: 56 additions & 0 deletions test/files/run/inferred-type-constructors.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
warning: there were 2 feature warning(s); re-run with -feature for details
p.Iterable[Int]
p.Set[Int]
p.Seq[Int]
p.m.Set[Int]
p.m.Seq[Int]
private[m] p.m.ASet[Int]
p.i.Seq[Int]
private[i] p.i.ASet[Int]
private[i] p.i.ASeq[Int]
p.Iterable[Int]
p.Iterable[Int]
p.Iterable[Int]
p.Iterable[Int]
p.Iterable[Int]
p.Iterable[Int]
p.Iterable[Int]
p.Iterable[Int]
p.Iterable[Int]
p.Set[Int]
p.Iterable[Int]
p.Set[Int]
p.Iterable[Int]
p.Set[Int]
p.Iterable[Int]
p.Iterable[Int]
p.Seq[Int]
p.Iterable[Int]
p.Seq[Int]
p.Iterable[Int]
p.Seq[Int]
p.Iterable[Int]
p.m.Set[Int]
p.Iterable[Int]
p.Set[Int]
p.Iterable[Int]
p.Iterable[Int]
p.Seq[Int]
p.Iterable[Int]
p.Seq[Int]
p.Iterable[Int]
private[p] p.ASet[Int]
private[p] p.AIterable[Int]
p.Iterable[Int]
p.i.Seq[Int]
private[p] p.AIterable[Int]
List[Nothing]
scala.collection.immutable.Vector[Nothing]
scala.collection.immutable.Iterable[(Int, Int)]
scala.collection.immutable.Set[Int]
Seq[Int]
Array[Int]
scala.collection.AbstractSet[Int]
Comparable[java.lang.String]
scala.collection.immutable.LinearSeq[Int]
Iterable[Int]
125 changes: 125 additions & 0 deletions test/files/run/inferred-type-constructors.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package p {
trait TCon[+CC[X]] {
def fPublic: CC[Int] = ???
private[p] def fPackagePrivate: CC[Int] = ???
protected[p] def fPackageProtected: CC[Int] = ???
}
trait Iterable[+A] extends TCon[Iterable]
trait Set[A] extends Iterable[A] with TCon[Set]
trait Seq[+A] extends Iterable[A] with TCon[Seq]

private[p] abstract class AIterable[+A] extends Iterable[A]
private[p] abstract class ASeq[+A] extends AIterable[A] with Seq[A]
private[p] abstract class ASet[A] extends AIterable[A] with Set[A]

package m {
private[m] abstract class ASeq[A] extends p.ASeq[A] with Seq[A]
private[m] abstract class ASet[A] extends p.ASet[A] with Set[A]
trait Set[A] extends p.Set[A] with TCon[Set]
trait Seq[A] extends p.Seq[A] with TCon[Seq]
trait BitSet extends ASet[Int]
trait IntSeq extends ASeq[Int]
}

package i {
private[i] abstract class ASeq[+A] extends p.ASeq[A] with Seq[A]
private[i] abstract class ASet[A] extends p.ASet[A] with Set[A]
trait Set[A] extends p.Set[A] with TCon[Set]
trait Seq[+A] extends p.Seq[A] with TCon[Seq]
trait BitSet extends ASet[Int]
trait IntSeq extends ASeq[Int]
}
}

object Test {
import scala.reflect.runtime.universe._
// Complicated by the absence of usable type constructor type tags.
def extract[A, CC[X]](xs: CC[A]): CC[A] = xs
def whatis[T: TypeTag](x: T): Unit = {
val tpe = typeOf[T]
val access = tpe.typeSymbol.asInstanceOf[scala.reflect.internal.HasFlags].accessString.replaceAllLiterally("package ", "")
println(f"$access%15s $tpe")
}

trait IntIterable extends p.Iterable[Int]
trait IntSet extends p.Set[Int]
trait IntSeq extends p.Seq[Int]

trait MutableIntSet extends p.m.Set[Int]
trait MutableIntSeq extends p.m.Seq[Int]

trait ImmutableIntSet extends p.i.Set[Int]
trait ImmutableIntSeq extends p.i.Seq[Int]

def f1: IntIterable = null
def f2: IntSet = null
def f3: IntSeq = null

def g1: MutableIntSet = null
def g2: MutableIntSeq = null
def g3: p.m.BitSet = null

def h1: ImmutableIntSeq = null
def h2: p.i.BitSet = null
def h3: p.i.IntSeq = null

def main(args: Array[String]): Unit = {
whatis(extract(f1))
whatis(extract(f2))
whatis(extract(f3))
whatis(extract(g1))
whatis(extract(g2))
whatis(extract(g3))
whatis(extract(h1))
whatis(extract(h2))
whatis(extract(h3))

whatis(extract(if (true) f1 else f2))
whatis(extract(if (true) f1 else f3))
whatis(extract(if (true) f1 else g1))
whatis(extract(if (true) f1 else g2))
whatis(extract(if (true) f1 else g3))
whatis(extract(if (true) f1 else h1))
whatis(extract(if (true) f1 else h2))
whatis(extract(if (true) f1 else h3))
whatis(extract(if (true) f2 else f3))
whatis(extract(if (true) f2 else g1))
whatis(extract(if (true) f2 else g2))
whatis(extract(if (true) f2 else g3))
whatis(extract(if (true) f2 else h1))
whatis(extract(if (true) f2 else h2))
whatis(extract(if (true) f2 else h3))
whatis(extract(if (true) f3 else g1))
whatis(extract(if (true) f3 else g2))
whatis(extract(if (true) f3 else g3))
whatis(extract(if (true) f3 else h1))
whatis(extract(if (true) f3 else h2))
whatis(extract(if (true) f3 else h3))
whatis(extract(if (true) g1 else g2))
whatis(extract(if (true) g1 else g3))
whatis(extract(if (true) g1 else h1))
whatis(extract(if (true) g1 else h2))
whatis(extract(if (true) g1 else h3))
whatis(extract(if (true) g2 else g3))
whatis(extract(if (true) g2 else h1))
whatis(extract(if (true) g2 else h2))
whatis(extract(if (true) g2 else h3))
whatis(extract(if (true) g3 else h1))
whatis(extract(if (true) g3 else h2))
whatis(extract(if (true) g3 else h3))
whatis(extract(if (true) h1 else h2))
whatis(extract(if (true) h1 else h3))
whatis(extract(if (true) h2 else h3))

whatis(extract(Nil))
whatis(extract(Vector()))
whatis(extract(Map[Int,Int]()))
whatis(extract(Set[Int]()))
whatis(extract(Seq[Int]()))
whatis(extract(Array[Int]()))
whatis(extract(scala.collection.immutable.BitSet(1)))
whatis(extract("abc"))
whatis(extract(if (true) Stream(1) else List(1)))
whatis(extract(if (true) Seq(1) else Set(1)))
}
}

0 comments on commit 90aa12e

Please sign in to comment.