Permalink
Browse files

dual mode (generics or not) version of compiler...

dual mode (generics or not) version of compiler and libraries
  • Loading branch information...
1 parent e5d6f33 commit 2ed9387915c9b813907c811ff889a056333d2ded @odersky odersky committed Dec 19, 2007
Showing with 160 additions and 138 deletions.
  1. +1 −1 lib/scala-compiler.jar.desired.sha1
  2. +1 −1 lib/scala-library-src.jar.desired.sha1
  3. +1 −1 lib/scala-library.jar.desired.sha1
  4. +1 −1 src/compiler/scala/tools/nsc/Global.scala
  5. +3 −3 src/compiler/scala/tools/nsc/plugins/Plugin.scala
  6. +23 −7 src/compiler/scala/tools/nsc/symtab/Types.scala
  7. +17 −11 src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
  8. +3 −3 src/compiler/scala/tools/nsc/typechecker/Namers.scala
  9. +4 −4 src/compiler/scala/tools/nsc/typechecker/Typers.scala
  10. +1 −1 src/dbc/scala/dbc/Vendor.scala
  11. +2 −2 src/library/scala/Predef.scala
  12. +2 −2 src/library/scala/collection/jcl/ArrayList.scala
  13. +2 −2 src/library/scala/collection/jcl/BufferWrapper.scala
  14. +4 −2 src/library/scala/collection/jcl/CollectionWrapper.scala
  15. +2 −2 src/library/scala/collection/jcl/HashMap.scala
  16. +2 −2 src/library/scala/collection/jcl/HashSet.scala
  17. +2 −2 src/library/scala/collection/jcl/IdentityHashMap.scala
  18. +1 −1 src/library/scala/collection/jcl/IterableWrapper.scala
  19. +2 −2 src/library/scala/collection/jcl/LinkedHashMap.scala
  20. +2 −2 src/library/scala/collection/jcl/LinkedHashSet.scala
  21. +2 −2 src/library/scala/collection/jcl/LinkedList.scala
  22. +2 −2 src/library/scala/collection/jcl/MapWrapper.scala
  23. +1 −1 src/library/scala/collection/jcl/MutableIterator.scala
  24. +2 −4 src/library/scala/collection/jcl/Ranged.scala
  25. +1 −1 src/library/scala/collection/jcl/SetWrapper.scala
  26. +1 −1 src/library/scala/collection/jcl/SortedMapWrapper.scala
  27. +1 −1 src/library/scala/collection/jcl/SortedSetWrapper.scala
  28. +1 −1 src/library/scala/collection/jcl/TreeMap.scala
  29. +1 −1 src/library/scala/collection/jcl/TreeSet.scala
  30. +2 −2 src/library/scala/collection/jcl/WeakHashMap.scala
  31. +1 −1 src/library/scala/collection/mutable/JavaMapAdaptor.scala
  32. +1 −1 src/library/scala/collection/mutable/JavaSetAdaptor.scala
  33. +4 −4 src/library/scala/collection/mutable/LinkedHashSet.scala
  34. +2 −2 src/library/scala/compat/Platform.scala
  35. +18 −15 src/library/scala/mobile/Code.scala
  36. +1 −1 src/library/scala/mobile/Location.scala
  37. +2 −1 src/library/scala/ref/PhantomReference.scala
  38. +3 −3 src/library/scala/ref/ReferenceQueue.scala
  39. +1 −1 src/library/scala/ref/ReferenceWrapper.scala
  40. +1 −1 src/library/scala/ref/SoftReference.scala
  41. +1 −1 src/library/scala/ref/WeakReference.scala
  42. +2 −2 src/library/scala/runtime/BoxedAnyArray.scala
  43. +1 −1 src/library/scala/runtime/BoxedArray.scala
  44. +1 −1 src/library/scala/runtime/BoxedBooleanArray.scala
  45. +1 −1 src/library/scala/runtime/BoxedByteArray.scala
  46. +1 −1 src/library/scala/runtime/BoxedCharArray.scala
  47. +1 −1 src/library/scala/runtime/BoxedDoubleArray.scala
  48. +1 −1 src/library/scala/runtime/BoxedFloatArray.scala
  49. +1 −1 src/library/scala/runtime/BoxedIntArray.scala
  50. +1 −1 src/library/scala/runtime/BoxedLongArray.scala
  51. +1 −1 src/library/scala/runtime/BoxedObjectArray.scala
  52. +1 −1 src/library/scala/runtime/BoxedShortArray.scala
  53. +1 −1 src/library/scala/runtime/Nothing$.scala
  54. +1 −1 src/library/scala/runtime/Null$.scala
  55. +1 −1 src/library/scala/runtime/RichInt.scala
  56. +15 −19 src/library/scala/runtime/ScalaRunTime.scala
  57. +1 −1 src/library/scala/runtime/StringAdd.scala
  58. +1 −1 src/library/scala/throws.scala
  59. +2 −2 src/library/scala/util/DynamicVariable.scala
  60. +1 −1 test/files/run/classof.scala
@@ -1 +1 @@
-c37ea17a89c5e64bdefd80a28532c8d982c11299 ?scala-compiler.jar
+5ca5f465ee0cf5e17e2f51b256a7fe813d5be005 ?scala-compiler.jar
@@ -1 +1 @@
-f1634e7f5c1f6f7ed4e6a3eb872ff6b08ca9233b ?scala-library-src.jar
+98df69d742b3323810c37fb9c36328c9bed50245 ?scala-library-src.jar
@@ -1 +1 @@
-1207e6fab978eeb71eff6bdc9d523db3cad63c3c ?scala-library.jar
+93774afad0ec5a940628a89348e097050bb25467 ?scala-library.jar
@@ -169,7 +169,7 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
}
try {
val clazz = Class.forName(settings.sourceReader.value)
- val ccon = clazz.getConstructor(Array[Class](classOf[java.nio.charset.CharsetDecoder]))
+ val ccon = clazz.getConstructor(Array[Class[T] forSome { type T }](classOf[java.nio.charset.CharsetDecoder]))
ccon.newInstance(Array[AnyRef] (charset.newDecoder())).asInstanceOf[SourceReader];
//new SourceReader(charset.newDecoder())
} catch {
@@ -100,7 +100,7 @@ object Plugin {
* if the jar file has no plugin in it or if the plugin
* is badly formed.
*/
- def loadFrom(jarfile: File, loader: ClassLoader): Option[Class] = {
+ def loadFrom(jarfile: File, loader: ClassLoader): Option[Class[_]] = {
val pluginInfo = loadDescription(jarfile).get
try {
@@ -120,7 +120,7 @@ object Plugin {
*/
def loadAllFrom(jars: List[File],
dirs: List[File],
- ignoring: List[String]): List[Class] =
+ ignoring: List[String]): List[Class[_]] =
{
val alljars = new ListBuffer[File]
@@ -143,7 +143,7 @@ object Plugin {
/** Instantiate a plugin class, given the class and
* the compiler it is to be used in.
*/
- def instantiate(clazz: Class, global: Global): Plugin = {
+ def instantiate(clazz: Class[_], global: Global): Plugin = {
val constructor = clazz.getConstructor(Array(classOf[Global]))
constructor.newInstance(Array(global)).asInstanceOf[Plugin]
}
@@ -1659,6 +1659,7 @@ A type's typeSymbol should never be inspected directly.
{
override protected def rewrap(newtp: Type) = existentialAbstraction(quantified, newtp)
+ override def isTrivial = false
override def isStable: Boolean = false
override def bounds = TypeBounds(maybeRewrap(underlying.bounds.lo), maybeRewrap(underlying.bounds.hi))
override def parents = underlying.parents map maybeRewrap
@@ -2037,7 +2038,7 @@ A type's typeSymbol should never be inspected directly.
/** A creator for type parameterizations
* If tparams is empty, simply returns result type
*/
- def parameterizedType(tparams: List[Symbol], tpe: Type): Type =
+ def polyType(tparams: List[Symbol], tpe: Type): Type =
if (tparams.isEmpty) tpe
else
PolyType(tparams, tpe match {
@@ -2462,10 +2463,17 @@ A type's typeSymbol should never be inspected directly.
private val emptySymMap = scala.collection.immutable.Map[Symbol, Symbol]()
private val emptySymCount = scala.collection.immutable.Map[Symbol, Int]()
- private def makeExistential(suffix: String, owner: Symbol, lo: Type, hi: Type) =
+ /** Make an existential variable.
+ * @param suffix A suffix to be appended to the freshly generated name
+ * It's ususally "", except for type variables abstracting
+ * over values, where it is ".type".
+ * @param owner The owner of the variable
+ * @param bounds The variable's bounds
+ */
+ def makeExistential(suffix: String, owner: Symbol, bounds: TypeBounds): Symbol =
recycle(
owner.newAbstractType(owner.pos, newTypeName(freshTypeName()+suffix)).setFlag(EXISTENTIAL)
- ).setInfo(TypeBounds(lo, hi))
+ ).setInfo(bounds)
/** A map to compute the asSeenFrom method */
class AsSeenFromMap(pre: Type, clazz: Symbol) extends TypeMap {
@@ -2507,7 +2515,8 @@ A type's typeSymbol should never be inspected directly.
def stabilize(pre: Type, clazz: Symbol): Type = {
capturedPre get clazz match {
case None =>
- val qvar = makeExistential(".type", clazz, AllClass.tpe, intersectionType(List(pre, SingletonClass.tpe)))
+ val qvar = makeExistential(".type", clazz,
+ mkTypeBounds(AllClass.tpe, intersectionType(List(pre, SingletonClass.tpe))))
capturedPre += (clazz -> qvar)
capturedParams = qvar :: capturedParams
qvar
@@ -2586,7 +2595,7 @@ A type's typeSymbol should never be inspected directly.
"something is wrong (wrong class file?): "+basesym+
" with type parameters "+
basesym.typeParams.map(_.name).mkString("[",",","]")+
- " gets applied to arguments "+baseargs.mkString("(",",",")")+", phase = "+phase)
+ " gets applied to arguments "+baseargs.mkString("[",",","]")+", phase = "+phase)
instParam(basesym.typeParams, baseargs);
case ExistentialType(tparams, qtpe) =>
capturedParams = capturedParams union tparams
@@ -3180,7 +3189,14 @@ A type's typeSymbol should never be inspected directly.
!(List.map3(args1, args2, sym1.typeParams) {
(arg1, arg2, tparam) =>
//if (tparam.variance == 0 && !(arg1 =:= arg2)) Console.println("inconsistent: "+arg1+"!="+arg2)//DEBUG
- tparam.variance != 0 || arg1 =:= arg2
+ if (tparam.variance == 0) arg1 =:= arg2
+ else if (arg1.isInstanceOf[TypeVar])
+ // if left-hand argument is a typevar, make it compatible with variance
+ // this is for more precise pattern matching
+ // todo: work this in the spec of this method
+ // also: think what happens if there are embedded typevars?
+ if (tparam.variance < 0) arg1 <:< arg2 else arg2 <:< arg1
+ else true
} contains false)
case (et: ExistentialType, _) =>
et.withTypeVars(isConsistent(_, tp2))
@@ -4090,7 +4106,7 @@ A type's typeSymbol should never be inspected directly.
if (l <:< g) l
else {
val owner = commonOwner(as)
- val qvar = makeExistential("", commonOwner(as), g, l)
+ val qvar = makeExistential("", commonOwner(as), mkTypeBounds(g, l))
capturedParams += qvar
qvar.tpe
}
@@ -470,11 +470,10 @@ abstract class ClassfileParser {
case VOID_TAG => definitions.UnitClass.tpe
case BOOL_TAG => definitions.BooleanClass.tpe
case 'L' => {
- val classSym = classNameToSymbol(subName(c => ((c == ';') || (c == '<'))))
+ val classSym = classNameToSymbol(subName(c => c == ';' || c == '<'))
assert(!classSym.hasFlag(OVERLOADED), classSym.alternatives)
val existentials = new ListBuffer[Symbol]()
val tpe: Type = if (sig(index) == '<') {
- assert(sym != null)
accept('<')
val xs = new ListBuffer[Type]()
while (sig(index) != '>') {
@@ -489,13 +488,11 @@ abstract class ClassfileParser {
case '*' => mkTypeBounds(definitions.AllClass.tpe,
definitions.AnyClass.tpe)
}
- val name = fresh.newName("T_" + sym.name)
- val newtparam = sym.newTypeParameter(NoPosition, name)
+ val newtparam = makeExistential("", sym, bounds)
existentials += newtparam
- newtparam.setInfo(bounds)
xs += newtparam.tpe
-
- case _ => xs += sig2type(tparams)
+ case _ =>
+ xs += sig2type(tparams)
}
}
accept('>')
@@ -571,7 +568,7 @@ abstract class ClassfileParser {
}
ClassInfoType(parents.toList, instanceDefs, sym)
}
- parameterizedType(newTParams.toList, tpe)
+ polyType(newTParams.toList, tpe)
} // polySigToType
@@ -592,8 +589,8 @@ abstract class ClassfileParser {
val sig = pool.getExternalName(in.nextChar)
val newType = sigToType(sym, sig)
sym.setInfo(newType)
- if (settings.debug.value)
- global.inform("" + sym + "; signatire = " + sig + " type = " + newType)
+// if (settings.debug.value)
+ println("" + sym + "; signature = " + sig + " type = " + newType)
hasMeta = true
} else
in.skip(attrLen)
@@ -731,7 +728,8 @@ abstract class ClassfileParser {
pool.getClassSymbol(outerIndex) == sym) {
val innerAlias = getOwner(jflags)
.newAliasType(NoPosition, pool.getName(nameIndex).toTypeName)
- .setInfo(pool.getClassSymbol(innerIndex).tpe)
+ .setFlag(JAVA)
+ .setInfo(new LazyAliasType(pool.getClassSymbol(innerIndex)))
getScope(jflags).enter(innerAlias)
if ((jflags & JAVA_ACC_STATIC) != 0) {
@@ -746,6 +744,14 @@ abstract class ClassfileParser {
for (i <- 0 until attrCount) parseAttribute()
}
+ class LazyAliasType(alias: Symbol) extends LazyType {
+ override def complete(sym: Symbol) {
+ alias.initialize
+ val tparams1 = cloneSymbols(alias.typeParams)
+ sym.setInfo(polyType(tparams1, alias.tpe.substSym(alias.typeParams, tparams1)))
+ }
+ }
+
def skipAttributes() {
val attrCount = in.nextChar
for (i <- 0 until attrCount) {
@@ -522,7 +522,7 @@ trait Namers { self: Analyzer =>
}
private def classSig(tparams: List[TypeDef], impl: Template): Type =
- parameterizedType(typer.reenterTypeParams(tparams), templateSig(impl))
+ polyType(typer.reenterTypeParams(tparams), templateSig(impl))
private def methodSig(tparams: List[TypeDef], vparamss: List[List[ValDef]],
tpt: Tree, rhs: Tree): Type = {
@@ -613,7 +613,7 @@ trait Namers { self: Analyzer =>
}
def thisMethodType(restpe: Type) =
- parameterizedType(
+ polyType(
tparamSyms,
if (vparamSymss.isEmpty) PolyType(List(), restpe)
else checkDependencies((vparamSymss :\ restpe) (makeMethodType)))
@@ -739,7 +739,7 @@ trait Namers { self: Analyzer =>
if (tpsym.owner.isRefinementClass && // only needed in refinements
!tpsym.allOverriddenSymbols.forall{verifyOverriding(_)})
ErrorType
- else parameterizedType(tparamSyms, tp)
+ else polyType(tparamSyms, tp)
}
def typeSig(tree: Tree): Type = {
@@ -1890,7 +1890,7 @@ trait Typers { self: Analyzer =>
protected def existentialBound(sym: Symbol): Type =
if (sym.isClass)
- parameterizedType(sym.typeParams, mkTypeBounds(AllClass.tpe, sym.classBound))
+ polyType(sym.typeParams, mkTypeBounds(AllClass.tpe, sym.classBound))
else if (sym.isAbstractType)
sym.info
else if (sym.isTerm)
@@ -2340,7 +2340,7 @@ trait Typers { self: Analyzer =>
// of the type arguments as we don't know which alternative to choose... here we do
val args1 = map2Conserve(args, tparams) {
//@M! the polytype denotes the expected kind
- (arg, tparam) => typedHigherKindedType(arg, parameterizedType(tparam.typeParams, AnyClass.tpe))
+ (arg, tparam) => typedHigherKindedType(arg, polyType(tparam.typeParams, AnyClass.tpe))
}
typedTypeApply(fun, args1)
case SingleType(_, _) =>
@@ -2829,7 +2829,7 @@ trait Typers { self: Analyzer =>
// if symbol hasn't been fully loaded, can't check kind-arity
else map2Conserve(args, tparams) {
(arg, tparam) =>
- typedHigherKindedType(arg, parameterizedType(tparam.typeParams, AnyClass.tpe))
+ typedHigherKindedType(arg, polyType(tparam.typeParams, AnyClass.tpe))
//@M! the polytype denotes the expected kind
}
val argtypes = args1 map (_.tpe)
@@ -3020,7 +3020,7 @@ trait Typers { self: Analyzer =>
// @M maybe the well-kindedness check should be done when checking the type arguments conform to the type parameters' bounds?
val args1 = if(args.length == tparams.length) map2Conserve(args, tparams) {
//@M! the polytype denotes the expected kind
- (arg, tparam) => typedHigherKindedType(arg, parameterizedType(tparam.typeParams, AnyClass.tpe))
+ (arg, tparam) => typedHigherKindedType(arg, polyType(tparam.typeParams, AnyClass.tpe))
} else {
//@M this branch is correctly hit for an overloaded polymorphic type. It also has to handle erroneous cases.
// Until the right alternative for an overloaded method is known, be very liberal,
@@ -19,7 +19,7 @@ import java.sql.{Connection, Driver};
*/
abstract class Vendor {
- def nativeDriverClass: Class;
+ def nativeDriverClass: Class[Driver];
def uri: java.net.URI;
def user: String;
def pass: String;
@@ -21,7 +21,7 @@ object Predef {
// classOf dummy ------------------------------------------------------
/** Return the runtime representation of a class type. */
- def classOf[T]: Class = null
+ def classOf[T]: Class[T] = null
// aliases ------------------------------------------------------------
@@ -46,7 +46,7 @@ object Predef {
type String = java.lang.String
type StringBuilder = compat.StringBuilder
- type Class = java.lang.Class
+ type Class[T] = java.lang.Class[T]
type Runnable = java.lang.Runnable
type Throwable = java.lang.Throwable
@@ -14,6 +14,6 @@ package scala.collection.jcl;
*
* @author Sean McDirmid
*/
-class ArrayList[A](override val underlying : java.util.ArrayList) extends BufferWrapper[A] {
- def this() = this(new java.util.ArrayList);
+class ArrayList[A](override val underlying : java.util.ArrayList[A]) extends BufferWrapper[A] {
+ def this() = this(new java.util.ArrayList[A]);
}
@@ -15,7 +15,7 @@ package scala.collection.jcl;
* @author Sean McDirmid
*/
trait BufferWrapper[A] extends Buffer[A] with CollectionWrapper[A] {
- def underlying : java.util.List;
+ def underlying : java.util.List[A];
override def elements : BufferIterator[Int,A] = new IteratorWrapper(underlying.listIterator);
override def remove(idx : Int) = underlying.remove(idx).asInstanceOf[A];
override def add(a : A) = underlying.add(a);
@@ -40,7 +40,7 @@ trait BufferWrapper[A] extends Buffer[A] with CollectionWrapper[A] {
}
override def elements = super[BufferWrapper].elements;
}
- class IteratorWrapper(underlying : java.util.ListIterator) extends MutableIterator.Wrapper[A](underlying) with BufferIterator[Int,A] {
+ class IteratorWrapper(underlying : java.util.ListIterator[A]) extends MutableIterator.Wrapper[A](underlying) with BufferIterator[Int,A] {
def add(a : A) = underlying.add(a);
def set(a : A) = underlying.set(a);
def hasPrevious = underlying.hasPrevious;
@@ -18,13 +18,15 @@ trait CollectionWrapper[A] extends Collection[A] with IterableWrapper[A] {
/** Override to specify the collection being accessed through this wrapper.
** Collection operations are then routed through the wrapped Java collection.
**/
- def underlying : java.util.Collection;
+ def underlying : java.util.Collection[A];
override def has(a : A) = underlying.contains(a);
override def elements : MutableIterator[A] = super.elements;
override def size = underlying.size;
override def hasAll(that : Iterable[A]) = that match {
- case that : CollectionWrapper[_] => underlying.containsAll(that.underlying);
+ case that : CollectionWrapper[_] =>
+ val u = underlying;
+ u.containsAll(that.underlying);
case _ => super.hasAll(that);
}
override def add(a : A) = underlying.add(a);
@@ -14,6 +14,6 @@ package scala.collection.jcl;
*
* @author Sean McDirmid
*/
-class HashMap[K,E](override val underlying: java.util.HashMap) extends MapWrapper[K,E] {
- def this() = this(new java.util.HashMap);
+class HashMap[K,E](override val underlying: java.util.HashMap[K,E]) extends MapWrapper[K,E] {
+ def this() = this(new java.util.HashMap[K,E]);
}
@@ -14,7 +14,7 @@ package scala.collection.jcl;
*
* @author Sean McDirmid
*/
-class HashSet[A](override val underlying: java.util.HashSet) extends SetWrapper[A] {
+class HashSet[A](override val underlying: java.util.HashSet[A]) extends SetWrapper[A] {
/** Creates an underlying Java hash set. */
- def this() = this(new java.util.HashSet);
+ def this() = this(new java.util.HashSet[A]);
}
@@ -17,6 +17,6 @@ package scala.collection.jcl;
*
* @author Sean McDirmid
*/
-class IdentityHashMap[K,E](override val underlying : java.util.IdentityHashMap) extends MapWrapper[K,E] {
- def this() = this(new java.util.IdentityHashMap);
+class IdentityHashMap[K,E](override val underlying : java.util.IdentityHashMap[K,E]) extends MapWrapper[K,E] {
+ def this() = this(new java.util.IdentityHashMap[K,E]);
}
@@ -15,7 +15,7 @@ package scala.collection.jcl;
* @author Sean McDirmid
*/
trait IterableWrapper[A] extends MutableIterable[A] {
- def underlying: java.util.Collection;
+ def underlying: java.util.Collection[A];
override def remove(a: A) = underlying.remove(a);
override def removeAll(that: Iterable[A]) = that match {
case that: IterableWrapper[_] => underlying.removeAll(that.underlying);
@@ -15,6 +15,6 @@ package scala.collection.jcl;
*
* @author Sean McDirmid
*/
-class LinkedHashMap[K,E](override val underlying: java.util.LinkedHashMap) extends MapWrapper[K,E] {
- def this() = this(new java.util.LinkedHashMap);
+class LinkedHashMap[K,E](override val underlying: java.util.LinkedHashMap[K,E]) extends MapWrapper[K,E] {
+ def this() = this(new java.util.LinkedHashMap[K,E]);
}
@@ -15,6 +15,6 @@ package scala.collection.jcl;
*
* @author Sean McDirmid
*/
-class LinkedHashSet[A](override val underlying: java.util.LinkedHashSet) extends SetWrapper[A] {
- def this() = this(new java.util.LinkedHashSet);
+class LinkedHashSet[A](override val underlying: java.util.LinkedHashSet[A]) extends SetWrapper[A] {
+ def this() = this(new java.util.LinkedHashSet[A]);
}
Oops, something went wrong.

0 comments on commit 2ed9387

Please sign in to comment.