summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-01-07 19:07:01 +0000
committerPaul Phillips <paulp@improving.org>2011-01-07 19:07:01 +0000
commit32e7c243272d7aaae6c662aa3e1716dae61e1117 (patch)
treeec61af7fab062994641da341d5aea4c8aaf67fa3 /src/compiler/scala/tools
parent148736c3df1fa6463b4b2658c01bcf452a52c224 (diff)
downloadscala-32e7c243272d7aaae6c662aa3e1716dae61e1117.tar.gz
scala-32e7c243272d7aaae6c662aa3e1716dae61e1117.tar.bz2
scala-32e7c243272d7aaae6c662aa3e1716dae61e1117.zip
Great moments in code reuse:
def isRootOrEmptyPackageClass(s: Symbol) = s.isRoot || s.isEmptyPackageClass def isRootOrEmpty = (this == EmptyPackageClass) || (this == RootClass) def isEffectiveRoot = isRoot || isEmptyPackageClass // last one actually not quite identical def isUnqualified(n: Name) = n match { case nme.ROOT | nme.EMPTY_PACKAGE_NAME => true ; case _ => false } I was responsible for at least half of these. Now it's only isEffectiveRoot. Also, I have always found it warty that we have to specify Nothing and Any as upper bounds. I gave the TypeBounds companion object a few obvious methods: def empty: TypeBounds = apply(NothingClass.tpe, AnyClass.tpe) def upper(hi: Type): TypeBounds = apply(NothingClass.tpe, hi) def lower(lo: Type): TypeBounds = apply(lo, AnyClass.tpe) It's a lovable patch. No review.
Diffstat (limited to 'src/compiler/scala/tools')
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreeGen.scala30
-rw-r--r--src/compiler/scala/tools/nsc/ast/Trees.scala2
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Definitions.scala15
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Symbols.scala7
-rw-r--r--src/compiler/scala/tools/nsc/symtab/TypeDebugging.scala2
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Types.scala29
-rw-r--r--src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala11
-rw-r--r--src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala2
-rw-r--r--src/compiler/scala/tools/nsc/transform/OverridingPairs.scala19
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Implicits.scala4
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Infer.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Namers.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala5
-rw-r--r--src/compiler/scala/tools/nsc/util/HashSet.scala20
15 files changed, 68 insertions, 84 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreeGen.scala b/src/compiler/scala/tools/nsc/ast/TreeGen.scala
index 55dfb07c54..978f1e8374 100644
--- a/src/compiler/scala/tools/nsc/ast/TreeGen.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreeGen.scala
@@ -28,8 +28,6 @@ abstract class TreeGen {
def productConstr = scalaDot(tpnme.Product)
def serializableConstr = scalaDot(tpnme.Serializable)
- private def isRootOrEmptyPackageClass(s: Symbol) = s.isRoot || s.isEmptyPackageClass
-
def scalaFunctionConstr(argtpes: List[Tree], restpe: Tree, abstractFun: Boolean = false): Tree = {
val cls = if (abstractFun)
mkAttributedRef(AbstractFunctionClass(argtpes.length))
@@ -55,7 +53,7 @@ abstract class TreeGen {
case NoPrefix =>
EmptyTree
case ThisType(clazz) =>
- if (isRootOrEmptyPackageClass(clazz)) EmptyTree
+ if (clazz.isEffectiveRoot) EmptyTree
else mkAttributedThis(clazz)
case SingleType(pre, sym) =>
val qual = mkAttributedStableRef(pre, sym)
@@ -107,9 +105,9 @@ abstract class TreeGen {
def mkAttributedRef(pre: Type, sym: Symbol): Tree = {
val qual = mkAttributedQualifier(pre)
qual match {
- case EmptyTree => mkAttributedIdent(sym)
- case This(clazz) if isRootOrEmptyPackageClass(qual.symbol) => mkAttributedIdent(sym)
- case _ => mkAttributedSelect(qual, sym)
+ case EmptyTree => mkAttributedIdent(sym)
+ case This(clazz) if qual.symbol.isEffectiveRoot => mkAttributedIdent(sym)
+ case _ => mkAttributedSelect(qual, sym)
}
}
@@ -159,24 +157,20 @@ abstract class TreeGen {
Ident(sym.name) setSymbol sym setType sym.tpe
def mkAttributedSelect(qual: Tree, sym: Symbol): Tree = {
- def tpe = qual.tpe
-
- def isUnqualified(n: Name) = n match { case nme.ROOT | nme.EMPTY_PACKAGE_NAME => true ; case _ => false }
- def hasUnqualifiedName(s: Symbol) = s != null && isUnqualified(s.name.toTermName)
- def isInPkgObject(s: Symbol) = s != null && s.owner.isPackageObjectClass && s.owner.owner == tpe.typeSymbol
-
- if (hasUnqualifiedName(qual.symbol))
+ // Tests involving the repl fail without the .isEmptyPackage condition.
+ if (qual.symbol != null && (qual.symbol.isEffectiveRoot || qual.symbol.isEmptyPackage))
mkAttributedIdent(sym)
else {
- val pkgQualifier =
- if (!isInPkgObject(sym)) qual else {
+ val pkgQualifier =
+ if (sym != null && sym.owner.isPackageObjectClass && sym.owner.owner == qual.tpe.typeSymbol) {
val obj = sym.owner.sourceModule
- Select(qual, nme.PACKAGEkw) setSymbol obj setType singleType(tpe, obj)
+ Select(qual, nme.PACKAGEkw) setSymbol obj setType singleType(qual.tpe, obj)
}
- val tree = Select(pkgQualifier, sym)
+ else qual
+ val tree = Select(pkgQualifier, sym)
if (pkgQualifier.tpe == null) tree
- else tree setType (tpe memberType sym)
+ else tree setType (qual.tpe memberType sym)
}
}
diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala
index ecba1c23da..25c053c36d 100644
--- a/src/compiler/scala/tools/nsc/ast/Trees.scala
+++ b/src/compiler/scala/tools/nsc/ast/Trees.scala
@@ -1122,7 +1122,7 @@ trait Trees extends reflect.generic.Trees { self: SymbolTable =>
}
private class ResetLocalAttrsTraverser extends ResetAttrsTraverser {
- private val erasedSyms = new HashSet[Symbol](8)
+ private val erasedSyms = HashSet[Symbol](8)
override protected def isLocal(sym: Symbol) = erasedSyms(sym)
override protected def resetDef(tree: Tree) {
erasedSyms addEntry tree.symbol
diff --git a/src/compiler/scala/tools/nsc/symtab/Definitions.scala b/src/compiler/scala/tools/nsc/symtab/Definitions.scala
index fb2ee22615..0eb58e3ad2 100644
--- a/src/compiler/scala/tools/nsc/symtab/Definitions.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Definitions.scala
@@ -6,7 +6,8 @@
package scala.tools.nsc
package symtab
-import scala.collection.mutable.{HashMap, HashSet}
+import scala.collection.{ mutable, immutable }
+import scala.collection.mutable.{ HashMap }
import scala.tools.nsc.util.NoPosition
import Flags._
import PartialFunction._
@@ -16,6 +17,7 @@ trait Definitions extends reflect.generic.StandardDefinitions {
self: SymbolTable =>
object definitions extends AbsDefinitions {
+ private var isInitialized = false
def isDefinitionsInitialized = isInitialized
// symbols related to packages
@@ -620,14 +622,13 @@ trait Definitions extends reflect.generic.StandardDefinitions {
newMethod(owner, name).setInfo(PolyType(List(),restpe))
private def newTypeParam(owner: Symbol, index: Int): Symbol =
- owner.newTypeParameter(NoPosition, newTypeName("T" + index))
- .setInfo(TypeBounds(NothingClass.typeConstructor, AnyClass.typeConstructor))
+ owner.newTypeParameter(NoPosition, newTypeName("T" + index)) setInfo TypeBounds.empty
val boxedClass = new HashMap[Symbol, Symbol]
val boxedModule = new HashMap[Symbol, Symbol]
val unboxMethod = new HashMap[Symbol, Symbol] // Type -> Method
val boxMethod = new HashMap[Symbol, Symbol] // Type -> Method
- val primitiveCompanions = new HashSet[Symbol] // AnyVal -> Companion
+ val primitiveCompanions = new mutable.HashSet[Symbol] // AnyVal -> Companion
/** Maps a companion object like scala.Int to scala.runtime.Int. */
lazy val runtimeCompanions = (primitiveCompanions map { sym =>
sym -> getModule("scala.runtime." + sym.name)
@@ -855,11 +856,8 @@ trait Definitions extends reflect.generic.StandardDefinitions {
// }
// }
- private var isInitialized = false
-
def init {
if (isInitialized) return
- isInitialized = true
EmptyPackageClass.setInfo(ClassInfoType(Nil, new Scope, EmptyPackageClass))
EmptyPackage.setInfo(EmptyPackageClass.tpe)
@@ -889,7 +887,7 @@ trait Definitions extends reflect.generic.StandardDefinitions {
Object_== = newMethod(ObjectClass, nme.EQ, anyrefparam, booltype) setFlag FINAL
Object_!= = newMethod(ObjectClass, nme.NE, anyrefparam, booltype) setFlag FINAL
Object_eq = newMethod(ObjectClass, nme.eq, anyrefparam, booltype) setFlag FINAL
- Object_ne = newMethod(ObjectClass, "ne", anyrefparam, booltype) setFlag FINAL
+ Object_ne = newMethod(ObjectClass, nme.ne, anyrefparam, booltype) setFlag FINAL
Object_synchronized = newPolyMethodCon(
ObjectClass, nme.synchronized_,
tparam => msym => MethodType(msym.newSyntheticValueParams(List(tparam.typeConstructor)), tparam.typeConstructor)) setFlag FINAL
@@ -966,6 +964,7 @@ trait Definitions extends reflect.generic.StandardDefinitions {
newMethod(StringClass, "replace", List(charType, charType), stringType)
newMethod(StringClass, "toCharArray", List(), arrayType(charType))
}
+ isInitialized = true
} //init
var nbScalaCallers: Int = 0
diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
index 7f810c9333..4eae44c1d0 100644
--- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
@@ -373,7 +373,6 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable =>
final def needsFlatClasses: Boolean = phase.flatClasses && rawowner != NoSymbol && !rawowner.isPackageClass
// not printed as prefixes
- final def isRootOrEmpty = (this == EmptyPackageClass) || (this == RootClass)
final def isPredefModule = this == PredefModule
final def isScalaPackage = (this == ScalaPackage) || (isPackageObject && owner == ScalaPackageClass)
final def isScalaPackageClass = skipPackageObject == ScalaPackageClass
@@ -386,7 +385,7 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable =>
* unpleasantries like Predef.String, $iw.$iw.Foo and <empty>.Bippy.
*/
final def printWithoutPrefix = !settings.debug.value && (
- isScalaPackageClass || isPredefModule || isRootOrEmpty || isAnonOrRefinementClass || isInterpreterWrapper
+ isScalaPackageClass || isPredefModule || isEffectiveRoot || isAnonOrRefinementClass || isInterpreterWrapper
)
/** Is symbol a monomorphic type?
@@ -947,11 +946,11 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable =>
*/
def existentialBound: Type =
if (this.isClass)
- polyType(this.typeParams, TypeBounds(NothingClass.tpe, this.classBound))
+ polyType(this.typeParams, TypeBounds.upper(this.classBound))
else if (this.isAbstractType)
this.info
else if (this.isTerm)
- TypeBounds(NothingClass.tpe, intersectionType(List(this.tpe, SingletonClass.tpe)))
+ TypeBounds.upper(intersectionType(List(this.tpe, SingletonClass.tpe)))
else
abort("unexpected alias type: "+this)
diff --git a/src/compiler/scala/tools/nsc/symtab/TypeDebugging.scala b/src/compiler/scala/tools/nsc/symtab/TypeDebugging.scala
index f822c9ff24..79f3f4569c 100644
--- a/src/compiler/scala/tools/nsc/symtab/TypeDebugging.scala
+++ b/src/compiler/scala/tools/nsc/symtab/TypeDebugging.scala
@@ -14,7 +14,7 @@ trait TypeDebugging {
// @M toString that is safe during debugging (does not normalize, ...)
object TypeDebugStrings {
object str {
- def brackets(xs: List[_]): String = xs.mkString("[", ", ", "]")
+ def brackets(xs: List[_]): String = if (xs.isEmpty) "" else xs.mkString("[", ", ", "]")
def tparams(tparams: List[Type]): String = brackets(tparams map debug)
def parents(ps: List[Type]): String = (ps map debug).mkString(" with ")
def refine(defs: Scope): String = defs.toList.mkString("{", " ;\n ", "}")
diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala
index 9345d9d26e..ef45834ab7 100644
--- a/src/compiler/scala/tools/nsc/symtab/Types.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Types.scala
@@ -1220,7 +1220,7 @@ trait Types extends reflect.generic.Types { self: SymbolTable =>
override def bounds: TypeBounds = this
def containsType(that: Type) = that match {
case TypeBounds(_, _) => that <:< this
- case _ => lo <:< that && that <:< hi
+ case _ => lo <:< that && that <:< hi
}
// override def isNullable: Boolean = NullClass.tpe <:< lo;
override def safeToString = ">: " + lo + " <: " + hi
@@ -1228,6 +1228,10 @@ trait Types extends reflect.generic.Types { self: SymbolTable =>
}
object TypeBounds extends TypeBoundsExtractor {
+ def empty: TypeBounds = apply(NothingClass.tpe, AnyClass.tpe)
+ def upper(hi: Type): TypeBounds = apply(NothingClass.tpe, hi)
+ def lower(lo: Type): TypeBounds = apply(lo, AnyClass.tpe)
+
def apply(lo: Type, hi: Type): TypeBounds =
unique(new TypeBounds(lo, hi) with UniqueType)
}
@@ -2848,13 +2852,13 @@ A type's typeSymbol should never be inspected directly.
// Hash consing --------------------------------------------------------------
private val initialUniquesCapacity = 4096
- private var uniques: util.HashSet[AnyRef] = _
+ private var uniques: util.HashSet[Type] = _
private var uniqueRunId = NoRunId
- private def unique[T <: AnyRef](tp: T): T = {
+ private def unique[T <: Type](tp: T): T = {
incCounter(rawTypeCount)
if (uniqueRunId != currentRunId) {
- uniques = new util.HashSet("uniques", initialUniquesCapacity)
+ uniques = util.HashSet[Type]("uniques", initialUniquesCapacity)
uniqueRunId = currentRunId
}
(uniques findEntryOrUpdate tp).asInstanceOf[T]
@@ -2862,6 +2866,12 @@ A type's typeSymbol should never be inspected directly.
// Helper Classes ---------------------------------------------------------
+ /** @PP: Unable to see why these apparently constant types should need vals
+ * in every TypeConstraint, I lifted them out.
+ */
+ private lazy val numericLoBound = IntClass.tpe
+ private lazy val numericHiBound = intersectionType(List(ByteClass.tpe, CharClass.tpe), ScalaPackageClass)
+
/** A class expressing upper and lower bounds constraints of type variables,
* as well as their instantiations.
*/
@@ -2877,13 +2887,6 @@ A type's typeSymbol should never be inspected directly.
def loBounds: List[Type] = if (numlo == NoType) lobounds else numlo :: lobounds
def hiBounds: List[Type] = if (numhi == NoType) hibounds else numhi :: hibounds
- /** @PP: Would it be possible to get a comment explaining what role these are serving?
- * In particular, why is numericHiBound being calculated this way given that all the
- * arguments are constant?
- */
- private val numericLoBound = IntClass.tpe
- private val numericHiBound = intersectionType(List(ByteClass.tpe, CharClass.tpe), ScalaPackageClass)
-
def addLoBound(tp: Type, isNumericBound: Boolean = false) {
if (isNumericBound && isNumericValueType(tp)) {
if (numlo == NoType || isNumericSubType(numlo, tp))
@@ -3233,7 +3236,7 @@ A type's typeSymbol should never be inspected directly.
}
def singletonBounds(hi: Type) = {
- TypeBounds(NothingClass.tpe, intersectionType(List(hi, SingletonClass.tpe)))
+ TypeBounds.upper(intersectionType(List(hi, SingletonClass.tpe)))
}
/** A map to compute the asSeenFrom method */
@@ -5243,7 +5246,7 @@ A type's typeSymbol should never be inspected directly.
val symbounds = symtypes filter isTypeBound
var result: Type =
if (symbounds.isEmpty)
- TypeBounds(NothingClass.tpe, AnyClass.tpe)
+ TypeBounds.empty
else glbBounds(symbounds)
for (t <- symtypes if !isTypeBound(t))
if (result.bounds containsType t) result = t
diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
index 6d7d75984c..253ebb708d 100644
--- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
+++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
@@ -741,12 +741,9 @@ abstract class ClassfileParser {
case variance @ ('+' | '-' | '*') =>
index += 1
val bounds = variance match {
- case '+' => TypeBounds(definitions.NothingClass.tpe,
- sig2type(tparams, skiptvs))
- case '-' => TypeBounds(sig2type(tparams, skiptvs),
- definitions.AnyClass.tpe)
- case '*' => TypeBounds(definitions.NothingClass.tpe,
- definitions.AnyClass.tpe)
+ case '+' => TypeBounds.upper(sig2type(tparams, skiptvs))
+ case '-' => TypeBounds.lower(sig2type(tparams, skiptvs))
+ case '*' => TypeBounds.empty
}
val newtparam = sym.newExistential(sym.pos, newTypeName("?"+i)) setInfo bounds
existentials += newtparam
@@ -824,7 +821,7 @@ abstract class ClassfileParser {
if (sig(index) != ':') // guard against empty class bound
ts += objToAny(sig2type(tparams, skiptvs))
}
- TypeBounds(definitions.NothingClass.tpe, intersectionType(ts.toList, sym))
+ TypeBounds.upper(intersectionType(ts.toList, sym))
}
var tparams = classTParams
diff --git a/src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala b/src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala
index 3489b3cb65..3f5fc6fdcb 100644
--- a/src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala
+++ b/src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala
@@ -83,7 +83,7 @@ abstract class TypeParser {
for (cnstrnt <- tvarCILDef.Constraints) {
ts += getCLRType(cnstrnt) // TODO we're definitely not at or after erasure, no need to call objToAny, right?
}
- TypeBounds(definitions.NothingClass.tpe, intersectionType(ts.toList, clazz))
+ TypeBounds.upper(intersectionType(ts.toList, clazz))
// TODO variance???
}
diff --git a/src/compiler/scala/tools/nsc/transform/OverridingPairs.scala b/src/compiler/scala/tools/nsc/transform/OverridingPairs.scala
index 6721280801..52779385ce 100644
--- a/src/compiler/scala/tools/nsc/transform/OverridingPairs.scala
+++ b/src/compiler/scala/tools/nsc/transform/OverridingPairs.scala
@@ -146,25 +146,16 @@ abstract class OverridingPairs {
/** Do `sym1` and `sym2` have a common subclass in `parents`?
* In that case we do not follow their overriding pairs
*/
- private def hasCommonParentAsSubclass(sym1: Symbol, sym2: Symbol) = {
- index get sym1.owner match {
- case Some(index1) =>
- index get sym2.owner match {
- case Some(index2) =>
- intersectionContainsElementLeq(subParents(index1), subParents(index2), index1 min index2)
- case None =>
- false
- }
- case None =>
- false
- }
- }
+ private def hasCommonParentAsSubclass(sym1: Symbol, sym2: Symbol) = (
+ for (index1 <- index get sym1.owner ; index2 <- index get sym2.owner) yield
+ intersectionContainsElementLeq(subParents(index1), subParents(index2), index1 min index2)
+ ).exists(_ == true)
/** The scope entries that have already been visited as overridden
* (maybe excluded because of hasCommonParentAsSubclass).
* These will not appear as overriding
*/
- private val visited = new HashSet[ScopeEntry]("visited", 64)
+ private val visited = HashSet[ScopeEntry]("visited", 64)
/** The current entry candidate for overriding
*/
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
index 0aeea8174a..171ff70e40 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
@@ -459,7 +459,7 @@ trait Contexts { self: Analyzer =>
}
def pushTypeBounds(sym: Symbol) {
- savedTypeBounds = (sym, sym.info) :: savedTypeBounds
+ savedTypeBounds ::= ((sym, sym.info))
}
def restoreTypeBounds(tp: Type): Type = {
diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
index 3a84bdc9e4..6a708a873c 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
@@ -698,7 +698,7 @@ trait Implicits {
*/
def applicableInfos(iss: Infoss, isLocal: Boolean): Map[ImplicitInfo, SearchResult] = {
val start = startCounter(subtypeAppInfos)
- val computation = new ImplicitComputation(iss, if (isLocal) new util.HashSet[Name](512) else null) { }
+ val computation = new ImplicitComputation(iss, if (isLocal) util.HashSet[Name](512) else null) { }
val applicable = computation.findAll()
stopCounter(subtypeAppInfos, start)
@@ -716,7 +716,7 @@ trait Implicits {
*/
def searchImplicit(implicitInfoss: Infoss, isLocal: Boolean): SearchResult =
if (implicitInfoss.forall(_.isEmpty)) SearchFailure
- else new ImplicitComputation(implicitInfoss, if (isLocal) new util.HashSet[Name](512) else null) findBest()
+ else new ImplicitComputation(implicitInfoss, if (isLocal) util.HashSet[Name](128) else null) findBest()
/** The parts of a type is the smallest set of types that contains
* - the type itself
diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
index 20136d49b9..84c770b553 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
@@ -431,7 +431,7 @@ trait Infer {
}
val tp1 = tp map {
case WildcardType =>
- addTypeParam(TypeBounds(NothingClass.tpe, AnyClass.tpe))
+ addTypeParam(TypeBounds.empty)
case BoundedWildcardType(bounds) =>
addTypeParam(bounds)
case t => t
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
index 4bebc0fddc..9f83e2a749 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
@@ -1061,7 +1061,7 @@ trait Namers { self: Analyzer =>
val tparamSyms = typer.reenterTypeParams(tparams) //@M make tparams available in scope (just for this abstypedef)
val tp = typer.typedType(rhs).tpe match {
case TypeBounds(lt, rt) if (lt.isError || rt.isError) =>
- TypeBounds(NothingClass.tpe, AnyClass.tpe)
+ TypeBounds.empty
case tp @ TypeBounds(lt, rt) if (tpsym hasFlag JAVA) =>
TypeBounds(lt, objToAny(rt))
case tp =>
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 2099278fe3..bcb2767e6f 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -3002,8 +3002,7 @@ trait Typers extends Modes {
if (isFullyDefined(pt))
context.owner.newAliasType(tree.pos, name) setInfo pt
else
- context.owner.newAbstractType(tree.pos, name) setInfo
- TypeBounds(NothingClass.tpe, AnyClass.tpe)
+ context.owner.newAbstractType(tree.pos, name) setInfo TypeBounds.empty
val rawInfo = vble.rawInfo
vble = if (vble.name == tpnme.WILDCARD) context.scope.enter(vble)
else namer.enterInScope(vble)
@@ -3895,7 +3894,7 @@ trait Typers extends Modes {
def subArrayType(pt: Type) =
if (isValueClass(pt.typeSymbol) || !isFullyDefined(pt)) arrayType(pt)
else {
- val tparam = context.owner freshExistential "" setInfo TypeBounds(NothingClass.tpe, pt)
+ val tparam = context.owner freshExistential "" setInfo TypeBounds.upper(pt)
ExistentialType(List(tparam), arrayType(tparam.tpe))
}
val (expr1, baseClass) = expr0.tpe.typeSymbol match {
diff --git a/src/compiler/scala/tools/nsc/util/HashSet.scala b/src/compiler/scala/tools/nsc/util/HashSet.scala
index 72d51343e2..0bb5636d86 100644
--- a/src/compiler/scala/tools/nsc/util/HashSet.scala
+++ b/src/compiler/scala/tools/nsc/util/HashSet.scala
@@ -6,14 +6,18 @@
package scala.tools.nsc
package util
-class HashSet[T >: Null <: AnyRef](val label: String, initialCapacity: Int) extends Set[T] {
- def this(initialCapacity: Int) = this("No Label", initialCapacity)
- def this(label: String) = this(label, 16)
- def this() = this(16)
+object HashSet {
+ def apply[T >: Null <: AnyRef](): HashSet[T] = this(16)
+ def apply[T >: Null <: AnyRef](label: String): HashSet[T] = this(label, 16)
+ def apply[T >: Null <: AnyRef](initialCapacity: Int): HashSet[T] = this("No Label", initialCapacity)
+ def apply[T >: Null <: AnyRef](label: String, initialCapacity: Int): HashSet[T] =
+ new HashSet[T](label, initialCapacity)
+}
+class HashSet[T >: Null <: AnyRef](val label: String, initialCapacity: Int) extends Set[T] {
private var used = 0
private var table = new Array[AnyRef](initialCapacity)
- // System.err.println("Created: " + this)
+ private def index(x: Int): Int = math.abs(x % table.length)
def size: Int = used
def clear() {
@@ -21,8 +25,6 @@ class HashSet[T >: Null <: AnyRef](val label: String, initialCapacity: Int) exte
table = new Array[AnyRef](initialCapacity)
}
- private def index(x: Int): Int = math.abs(x % table.length)
-
def findEntryOrUpdate(x: T): T = {
var h = index(x.##)
var entry = table(h)
@@ -42,7 +44,7 @@ class HashSet[T >: Null <: AnyRef](val label: String, initialCapacity: Int) exte
def findEntry(x: T): T = {
var h = index(x.##)
var entry = table(h)
- while ((entry ne null) && entry != x) {
+ while ((entry ne null) && x != entry) {
h = index(h + 1)
entry = table(h)
}
@@ -53,7 +55,7 @@ class HashSet[T >: Null <: AnyRef](val label: String, initialCapacity: Int) exte
var h = index(x.##)
var entry = table(h)
while (entry ne null) {
- if (entry == x) return
+ if (x == entry) return
h = index(h + 1)
entry = table(h)
}