diff options
author | Antonio Cunei <antonio.cunei@epfl.ch> | 2010-05-12 07:45:22 +0000 |
---|---|---|
committer | Antonio Cunei <antonio.cunei@epfl.ch> | 2010-05-12 07:45:22 +0000 |
commit | c932ec58f9e6fc90c9497bb4cbfb09f2b398e7ea (patch) | |
tree | 1bbb00aca2f6bc710a8cc1d25e61153f261496b2 | |
parent | 64609f93548ea7637718057b23d0fb19d998e812 (diff) | |
download | scala-c932ec58f9e6fc90c9497bb4cbfb09f2b398e7ea.tar.gz scala-c932ec58f9e6fc90c9497bb4cbfb09f2b398e7ea.tar.bz2 scala-c932ec58f9e6fc90c9497bb4cbfb09f2b398e7ea.zip |
Merged revisions 21881-21882,21884-21886,21888,...
Merged revisions
21881-21882,21884-21886,21888,21891,21897-21898,21901,21908 via svnmerge
from https://lampsvn.epfl.ch/svn-repos/scala/scala/trunk
........
r21881 | dragos | 2010-05-10 17:36:17 +0200 (Mon, 10 May 2010) | 1 line
Fixed -Xcheckinit build.no review.
........
r21882 | odersky | 2010-05-10 17:40:08 +0200 (Mon, 10 May 2010) | 1 line
Disabled scalacheck tests because they interfere with library
refactorings (refactorings break scalacheck). ........ r21884 | odersky
| 2010-05-10 17:50:23 +0200 (Mon, 10 May 2010) | 1 line
made MathCommon a class to gain some speed.
........
r21885 | odersky | 2010-05-10 17:51:46 +0200 (Mon, 10 May 2010) | 1 line
Made builder in MutableMapFactory use += instead of +. ........ r21886
| odersky | 2010-05-10 17:52:25 +0200 (Mon, 10 May 2010) | 1 line
Added sizeHints to operations where it made sense. Made sizeHint
interface more flexible. ........ r21888 | dragos | 2010-05-10 18:21:40
+0200 (Mon, 10 May 2010) | 1 line
Closed #3413. No review.
........
r21891 | rytz | 2010-05-10 19:16:02 +0200 (Mon, 10 May 2010) | 1 line
close #3415. relates to r21680. review by milessabin. ........ r21897
| odersky | 2010-05-11 11:34:56 +0200 (Tue, 11 May 2010) | 1 line
Closes #t3363. Review by extempore.
........
r21898 | odersky | 2010-05-11 11:35:30 +0200 (Tue, 11 May 2010) | 1 line
Corrected sizeHints for scanLeft/Right
........
r21901 | milessabin | 2010-05-11 14:42:21 +0200 (Tue, 11 May 2010) | 1 line
Fix from Mirko Stocker and unit test for #3416. Review by plocinic.
........ r21908 | rytz | 2010-05-12 09:19:48 +0200 (Wed, 12 May 2010) |
1 line
new msil.jar to make msil build. noreview.
........
24 files changed, 115 insertions, 20 deletions
diff --git a/lib/msil.jar.desired.sha1 b/lib/msil.jar.desired.sha1 index cfdfc0b26e..a5722deadd 100644 --- a/lib/msil.jar.desired.sha1 +++ b/lib/msil.jar.desired.sha1 @@ -1 +1 @@ -009cec9efeb8f9b9287e49da1c4b69e1a629b299 ?msil.jar +682f60e7a3315c8dc3e7a39c10ba8069f0b0fca4 ?msil.jar diff --git a/lib/scala-compiler.jar.desired.sha1 b/lib/scala-compiler.jar.desired.sha1 index 557c1516f7..300fd3b8b2 100644 --- a/lib/scala-compiler.jar.desired.sha1 +++ b/lib/scala-compiler.jar.desired.sha1 @@ -1 +1 @@ -f090cf58e9797f7486e7b40371e9db5f7abb4ab1 ?scala-compiler.jar +003012ffac418126c8808ecefad56e9bd2f889bf ?scala-compiler.jar diff --git a/lib/scala-library.jar.desired.sha1 b/lib/scala-library.jar.desired.sha1 index 299ae07601..f91699b2af 100644 --- a/lib/scala-library.jar.desired.sha1 +++ b/lib/scala-library.jar.desired.sha1 @@ -1 +1 @@ -1ed76e39f609982b354442d5f7ccfcf376b7b396 ?scala-library.jar +d251aca11b739698c3c04319be5ad88825dc1732 ?scala-library.jar diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index 497cfc398b..43e515d31e 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -1906,13 +1906,19 @@ self => */ def importClause(): List[Tree] = { val offset = accept(IMPORT) - commaSeparated(importExpr(offset)) + commaSeparated(importExpr()) match { + case Nil => Nil + case t :: rest => + // The first import should start at the position of the keyword. + t.setPos(t.pos.withStart(offset)) + t :: rest + } } /** ImportExpr ::= StableId `.' (Id | `_' | ImportSelectors) * XXX: Hook for IDE */ - def importExpr(importOffset: Int): Tree = { + def importExpr(): Tree = { val start = in.offset var t: Tree = null if (in.token == THIS) { @@ -1956,7 +1962,7 @@ self => Import(t, List(ImportSelector(name, nameOffset, name, nameOffset))) } } - atPos(importOffset, start) { loop() } + atPos(start) { loop() } } /** ImportSelectors ::= `{' {ImportSelector `,'} (ImportSelector | `_') `}' diff --git a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala index 92dbc97965..fe46e22654 100644 --- a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala +++ b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala @@ -541,7 +541,7 @@ trait JavaParsers extends JavaScanners { if (parentToken == AT && in.token == DEFAULT) { val annot = atPos(pos) { - New(rootId(nme.AnnotationDefaultATTR.toTypeName), List(List())) + New(Select(scalaDot(newTermName("runtime")), nme.AnnotationDefaultATTR.toTypeName), List(List())) } mods1 = Modifiers(mods1.flags, mods1.privateWithin, annot :: mods1.annotations, mods1.positions) skipTo(SEMI) diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala index 8f1ece5b9e..dc59587c4a 100644 --- a/src/compiler/scala/tools/nsc/symtab/Types.scala +++ b/src/compiler/scala/tools/nsc/symtab/Types.scala @@ -1179,18 +1179,19 @@ trait Types extends reflect.generic.Types { self: SymbolTable => if (!isValidForBaseClasses(period)) { if (parents.exists(_.exists(_.isInstanceOf[TypeVar]))) { // rename type vars to fresh type params, take base type sequence of - // resulting type, and rename back allthe entries in thats sequence + // resulting type, and rename back all the entries in that sequence var tvs = Set[TypeVar]() for (p <- parents) for (t <- p) t match { case tv: TypeVar => tvs += tv case _ => } - val varToParamMap = (Map[Type, Symbol]() /: tvs)((m, tv) => m + (tv -> tv.origin.typeSymbol.cloneSymbol)) - val paramToVarMap = Map[Symbol, Type]() ++ (varToParamMap map { case (t, tsym) => (tsym -> t) }) + val varToParamMap: Map[Type, Symbol] = tvs map (tv => tv -> tv.origin.typeSymbol.cloneSymbol) toMap + val paramToVarMap = varToParamMap map (_.swap) + val varToParam = new TypeMap { - def apply(tp: Type): Type = tp match { - case tv: TypeVar => varToParamMap(tp).tpe + def apply(tp: Type) = varToParamMap get tp match { + case Some(sym) => sym.tpe case _ => mapOver(tp) } } diff --git a/src/compiler/scala/tools/nsc/transform/Mixin.scala b/src/compiler/scala/tools/nsc/transform/Mixin.scala index 85f71cabc9..18c4a74950 100644 --- a/src/compiler/scala/tools/nsc/transform/Mixin.scala +++ b/src/compiler/scala/tools/nsc/transform/Mixin.scala @@ -738,7 +738,7 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL { val res = (settings.checkInit.value && sym.isGetter && !sym.isInitializedToDefault - && !sym.hasFlag(PARAMACCESSOR) + && !sym.hasFlag(PARAMACCESSOR | SPECIALIZED) && !sym.accessed.hasFlag(PRESUPER) && !sym.isOuterAccessor) diff --git a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala index 6945b5e497..c2e5e474a9 100644 --- a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala +++ b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala @@ -374,7 +374,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { val specializedInfoType: Type = { val (_, unspecParams) = splitParams(clazz.info.typeParams) oldClassTParams = unspecParams - newClassTParams = cloneSymbols(unspecParams, cls) + newClassTParams = cloneSymbols(unspecParams, cls) map subst(env) def applyContext(tpe: Type) = subst(env, tpe).subst(unspecParams, newClassTParams map (_.tpe)) @@ -408,6 +408,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { if (newClassTParams.isEmpty) infoType else PolyType(newClassTParams, infoType) } + log("specializedClass " + cls + ": " + specializedInfoType) atPhase(phase.next)(cls.setInfo(specializedInfoType)) val fullEnv = outerEnv ++ env diff --git a/src/library/scala/MathCommon.scala b/src/library/scala/MathCommon.scala index 480f7e1913..9b4727b7c7 100644 --- a/src/library/scala/MathCommon.scala +++ b/src/library/scala/MathCommon.scala @@ -13,7 +13,7 @@ package scala /** Common code between the deprecated scala.Math object and * the scala.math package object. */ -private[scala] trait MathCommon { +private[scala] class MathCommon { /** The <code>double</code> value that is closer than any other to * <code>e</code>, the base of the natural logarithms. */ diff --git a/src/library/scala/Tuple2.scala b/src/library/scala/Tuple2.scala index 5dec39a79b..fb685096a3 100644 --- a/src/library/scala/Tuple2.scala +++ b/src/library/scala/Tuple2.scala @@ -12,7 +12,7 @@ package scala -import scala.collection.{TraversableLike, IterableLike} +import scala.collection.{TraversableLike, IterableLike, IndexedSeqLike} import scala.collection.generic.CanBuildFrom @@ -55,8 +55,8 @@ case class Tuple2[@specialized(Int, Long, Double) +T1, @specialized(Int, Long, D class Zipped[+Repr1, +El1, +Repr2, +El2](coll1: TraversableLike[El1, Repr1], coll2: IterableLike[El2, Repr2]) { // coll2: IterableLike for filter def map[B, To](f: (El1, El2) => B)(implicit cbf: CanBuildFrom[Repr1, B, To]): To = { val b = cbf(coll1.repr) + b.sizeHint(coll1) val elems2 = coll2.iterator - for(el1 <- coll1) if(elems2.hasNext) b += f(el1, elems2.next) diff --git a/src/library/scala/collection/IterableLike.scala b/src/library/scala/collection/IterableLike.scala index 0efc756b10..06909961ce 100644 --- a/src/library/scala/collection/IterableLike.scala +++ b/src/library/scala/collection/IterableLike.scala @@ -104,6 +104,7 @@ self => override /*TraversableLike*/ def take(n: Int): Repr = { val b = newBuilder + b.sizeHintBounded(n, this) var i = 0 val it = iterator while (i < n && it.hasNext) { @@ -115,6 +116,7 @@ self => override /*TraversableLike*/ def slice(from: Int, until: Int): Repr = { val b = newBuilder + b.sizeHintBounded(until - from, this) var i = from val it = iterator drop from while (i < until && it.hasNext) { @@ -176,6 +178,7 @@ self => */ def takeRight(n: Int): Repr = { val b = newBuilder + b.sizeHintBounded(n, this) val lead = this.iterator drop n var go = false for (x <- this) { @@ -195,6 +198,7 @@ self => */ def dropRight(n: Int): Repr = { val b = newBuilder + if (n >= 0) b.sizeHint(this, -n) val lead = iterator drop n val it = iterator while (lead.hasNext) { diff --git a/src/library/scala/collection/SeqLike.scala b/src/library/scala/collection/SeqLike.scala index d80539d0b0..2774536886 100644 --- a/src/library/scala/collection/SeqLike.scala +++ b/src/library/scala/collection/SeqLike.scala @@ -378,6 +378,7 @@ trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] { self => for (x <- this) xs = x :: xs val b = newBuilder + b.sizeHint(this) for (x <- xs) b += x b.result @@ -827,6 +828,7 @@ trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] { self => } java.util.Arrays.sort(arr.array, ord.asInstanceOf[Ordering[Object]]) val b = newBuilder + b.sizeHint(this) for (x <- arr) b += x b.result } diff --git a/src/library/scala/collection/TraversableLike.scala b/src/library/scala/collection/TraversableLike.scala index 4c8d34622e..fd6c000827 100644 --- a/src/library/scala/collection/TraversableLike.scala +++ b/src/library/scala/collection/TraversableLike.scala @@ -179,6 +179,7 @@ trait TraversableLike[+A, +Repr] extends HasNewBuilder[A, Repr] with Traversable */ def ++[B >: A, That](that: TraversableOnce[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = { val b = bf(repr) + if (that.isInstanceOf[IndexedSeqLike[_, _]]) b.sizeHint(this, that.size) b ++= thisCollection b ++= that b.result @@ -200,6 +201,7 @@ trait TraversableLike[+A, +Repr] extends HasNewBuilder[A, Repr] with Traversable */ def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That = { val b = bf(repr) + b.sizeHint(this) for (x <- this) b += f(x) b.result } @@ -428,6 +430,7 @@ trait TraversableLike[+A, +Repr] extends HasNewBuilder[A, Repr] with Traversable */ def scanLeft[B, That](z: B)(op: (B, A) => B)(implicit bf: CanBuildFrom[Repr, B, That]): That = { val b = bf(repr) + b.sizeHint(this, 1) var acc = z b += acc for (x <- this) { acc = op(acc, x); b += acc } @@ -448,6 +451,7 @@ trait TraversableLike[+A, +Repr] extends HasNewBuilder[A, Repr] with Traversable */ def scanRight[B, That](z: B)(op: (A, B) => B)(implicit bf: CanBuildFrom[Repr, B, That]): That = { val b = bf(repr) + b.sizeHint(this, 1) var acc = z b += acc for (x <- reversed) { acc = op(x, acc); b += acc } @@ -516,6 +520,7 @@ trait TraversableLike[+A, +Repr] extends HasNewBuilder[A, Repr] with Traversable var lst = head var follow = false val b = newBuilder + b.sizeHint(this, -1) for (x <- this) { if (follow) b += lst else follow = true @@ -532,6 +537,7 @@ trait TraversableLike[+A, +Repr] extends HasNewBuilder[A, Repr] with Traversable */ def take(n: Int): Repr = { val b = newBuilder + b.sizeHintBounded(n, this) var i = 0 breakable { for (x <- this) { @@ -551,6 +557,7 @@ trait TraversableLike[+A, +Repr] extends HasNewBuilder[A, Repr] with Traversable */ def drop(n: Int): Repr = { val b = newBuilder + if (n >= 0) b.sizeHint(this, -n) var i = 0 for (x <- this) { if (i >= n) b += x @@ -572,6 +579,7 @@ trait TraversableLike[+A, +Repr] extends HasNewBuilder[A, Repr] with Traversable */ def slice(from: Int, until: Int): Repr = { val b = newBuilder + b.sizeHintBounded(until - from, this) var i = 0 breakable { for (x <- this) { @@ -648,6 +656,8 @@ trait TraversableLike[+A, +Repr] extends HasNewBuilder[A, Repr] with Traversable */ def splitAt(n: Int): (Repr, Repr) = { val l, r = newBuilder + l.sizeHintBounded(n, this) + if (n >= 0) r.sizeHint(this, -n) var i = 0 for (x <- this) { (if (i < n) l else r) += x diff --git a/src/library/scala/collection/generic/MutableMapFactory.scala b/src/library/scala/collection/generic/MutableMapFactory.scala index 2fdb827d05..76ffc9faeb 100644 --- a/src/library/scala/collection/generic/MutableMapFactory.scala +++ b/src/library/scala/collection/generic/MutableMapFactory.scala @@ -12,12 +12,19 @@ package scala.collection package generic -import mutable.MapBuilder +import mutable.Builder -/** A template for companion objects of `immutable.Map` and subclasses thereof. +/** A template for companion objects of `mutable.Map` and subclasses thereof. * @author Martin Odersky * @version 2.8 * @since 2.8 */ abstract class MutableMapFactory[CC[A, B] <: mutable.Map[A, B] with mutable.MapLike[A, B, CC[A, B]]] - extends MapFactory[CC] + extends MapFactory[CC] { + + /** The default builder for $Coll objects. + * @tparam A the type of the keys + * @tparam B the type of the associated values + */ + override def newBuilder[A, B]: Builder[(A, B), CC[A, B]] = empty[A, B] +} diff --git a/src/library/scala/collection/mutable/Builder.scala b/src/library/scala/collection/mutable/Builder.scala index a930c29948..0c8bb79f83 100644 --- a/src/library/scala/collection/mutable/Builder.scala +++ b/src/library/scala/collection/mutable/Builder.scala @@ -52,6 +52,42 @@ trait Builder[-Elem, +To] extends Growable[Elem] { */ def sizeHint(size: Int) {} + /** Gives a hint that one expects the `result` of this builder + * to have the same size as the given collection, plus some delta. This will + * provide a hint only if the collection is known to have a cheap + * `size` method. Currently this is assumed ot be the case if and only if + * the collection is of type `IndexedSeqLike`. + * Some builder classes + * will optimize their representation based on the hint. However, + * builder implementations are still required to work correctly even if the hint is + * wrong, i.e. a different number of elements is added. + * + * @param coll the collection which serves as a hint for the result's size. + * @param delta a correction to add to the `coll.size` to produce the size hint. + */ + def sizeHint(coll: TraversableLike[_, _], delta: Int = 0) { + if (coll.isInstanceOf[IndexedSeqLike[_,_]]) { + sizeHint(coll.size + delta) + } + } + + /** Gives a hint how many elements are expected to be added + * when the next `result` is called, together with an upper bound + * given by the size of some other collection. Some builder classes + * will optimize their representation based on the hint. However, + * builder implementations are still required to work correctly even if the hint is + * wrong, i.e. a different number of elements is added. + * + * @param size the hint how many elements will be added. + * @param boundingColl the bounding collection. If it is + * an IndexedSeqLike, then sizes larger + * than collection's size are reduced. + */ + def sizeHintBounded(size: Int, boundingColl: TraversableLike[_, _]) { + if (boundingColl.isInstanceOf[IndexedSeqLike[_,_]]) + sizeHint(size min boundingColl.size) + } + /** Creates a new builder by applying a transformation function to * the results of this builder. * @param f the transformation function. diff --git a/test/files/jvm/t3415/Hello.java b/test/files/jvm/t3415/Hello.java new file mode 100644 index 0000000000..ae7206453b --- /dev/null +++ b/test/files/jvm/t3415/Hello.java @@ -0,0 +1,3 @@ +public @interface Hello { + String msg() default "hoi"; +} diff --git a/test/files/jvm/t3415/HelloWorld.scala b/test/files/jvm/t3415/HelloWorld.scala new file mode 100644 index 0000000000..53bf55e444 --- /dev/null +++ b/test/files/jvm/t3415/HelloWorld.scala @@ -0,0 +1,4 @@ +object Test extends Application { + @Hello + def foo() { } +} diff --git a/test/files/pos/t3363.scala b/test/files/pos/t3363.scala new file mode 100755 index 0000000000..bae54084ea --- /dev/null +++ b/test/files/pos/t3363.scala @@ -0,0 +1,18 @@ +object TestCase { + + //now matter if you put (abstract) class or trait it will fail in all cases + trait MapOps[T] + + //if fs was reduced to List (generic type with one parameter) then the code compiles + //if you inherit from MapOps[T] instead of MapOps[F] then code compiles fine + implicit def map2ops[T,F](fs: Map[T,F]) = new MapOps[F] { + //if you remove this line, then code compiles + lazy val m: Manifest[T] = error("just something to make it compile") + def is(xs: List[T]) = List(xs) + } + + def main(args: Array[String]) { + println(Map(1 -> "2") is List(2)) + } + + } diff --git a/test/files/positions/Overlap7.scala b/test/files/positions/Overlap7.scala new file mode 100644 index 0000000000..b3dc0d10e2 --- /dev/null +++ b/test/files/positions/Overlap7.scala @@ -0,0 +1,3 @@ +import java.lang.String, java.lang.Object + +class Overlap7 diff --git a/test/files/scalacheck/array.scala b/test/pending/scalacheck/array.scala index 03c0217180..03c0217180 100644 --- a/test/files/scalacheck/array.scala +++ b/test/pending/scalacheck/array.scala diff --git a/test/files/scalacheck/eqeq.scala b/test/pending/scalacheck/eqeq.scala index 60fe63c207..60fe63c207 100644 --- a/test/files/scalacheck/eqeq.scala +++ b/test/pending/scalacheck/eqeq.scala diff --git a/test/files/scalacheck/list.scala b/test/pending/scalacheck/list.scala index 1caf35e872..1caf35e872 100644 --- a/test/files/scalacheck/list.scala +++ b/test/pending/scalacheck/list.scala diff --git a/test/files/scalacheck/range.scala b/test/pending/scalacheck/range.scala index faa1f5d479..faa1f5d479 100644 --- a/test/files/scalacheck/range.scala +++ b/test/pending/scalacheck/range.scala diff --git a/test/files/scalacheck/scan.scala b/test/pending/scalacheck/scan.scala index e9b25ce3df..e9b25ce3df 100644 --- a/test/files/scalacheck/scan.scala +++ b/test/pending/scalacheck/scan.scala |