diff options
author | Martin Odersky <odersky@gmail.com> | 2010-01-19 16:44:20 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2010-01-19 16:44:20 +0000 |
commit | c4cacc0edfdf6f3f13afce16ec59ca2b7a25c82b (patch) | |
tree | a36b058b4b400cb6863becae5fd07c4fb46a90eb /src/compiler/scala/tools | |
parent | 6e0b81844bc7b63a971359a9550b1d68c0f63d52 (diff) | |
download | scala-c4cacc0edfdf6f3f13afce16ec59ca2b7a25c82b.tar.gz scala-c4cacc0edfdf6f3f13afce16ec59ca2b7a25c82b.tar.bz2 scala-c4cacc0edfdf6f3f13afce16ec59ca2b7a25c82b.zip |
more performance improvements; eliminated mk......
more performance improvements; eliminated mk...Type function in Types.
Diffstat (limited to 'src/compiler/scala/tools')
13 files changed, 194 insertions, 149 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Definitions.scala b/src/compiler/scala/tools/nsc/symtab/Definitions.scala index 155f5332d8..0371526b40 100644 --- a/src/compiler/scala/tools/nsc/symtab/Definitions.scala +++ b/src/compiler/scala/tools/nsc/symtab/Definitions.scala @@ -574,7 +574,7 @@ trait Definitions { private def newTypeParam(owner: Symbol, index: Int): Symbol = owner.newTypeParameter(NoPosition, "T" + index) - .setInfo(mkTypeBounds(NothingClass.typeConstructor, AnyClass.typeConstructor)) + .setInfo(TypeBounds(NothingClass.typeConstructor, AnyClass.typeConstructor)) val boxedClass = new HashMap[Symbol, Symbol] val boxedModule = new HashMap[Symbol, Symbol] @@ -691,7 +691,7 @@ trait Definitions { def addModuleMethod(clazz: Symbol, name: Name, value: Any) { val owner = clazz.linkedClassOfClass - newParameterlessMethod(owner, name, mkConstantType(Constant(value))) + newParameterlessMethod(owner, name, ConstantType(Constant(value))) } addModuleMethod(ByteClass, "MinValue", java.lang.Byte.MIN_VALUE) addModuleMethod(ByteClass, "MaxValue", java.lang.Byte.MAX_VALUE) diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala index 5ee7409cc7..c427aac848 100644 --- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala +++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala @@ -171,7 +171,7 @@ trait Symbols { final def newLocalDummy(pos: Position) = newValue(pos, nme.LOCAL(this)).setInfo(NoType) final def newMethod(pos: Position, name: Name) = - newValue(pos, name).setFlag(METHOD) + new MethodSymbol(this, pos, name).setFlag(METHOD) final def newLabel(pos: Position, name: Name) = newMethod(pos, name).setFlag(LABEL) final def newConstructor(pos: Position) = @@ -978,11 +978,11 @@ trait Symbols { */ def existentialBound: Type = if (this.isClass) - polyType(this.typeParams, mkTypeBounds(NothingClass.tpe, this.classBound)) + polyType(this.typeParams, TypeBounds(NothingClass.tpe, this.classBound)) else if (this.isAbstractType) this.info else if (this.isTerm) - mkTypeBounds(NothingClass.tpe, intersectionType(List(this.tpe, SingletonClass.tpe))) + TypeBounds(NothingClass.tpe, intersectionType(List(this.tpe, SingletonClass.tpe))) else throw new Error("unexpected alias type: "+this) @@ -1672,11 +1672,13 @@ trait Symbols { protected var referenced: Symbol = NoSymbol protected var defGetter: Symbol = NoSymbol - def cloneSymbolImpl(owner: Symbol): Symbol = { - val clone = new TermSymbol(owner, pos, name) - clone.referenced = referenced - clone.defGetter = defGetter - clone + def cloneSymbolImpl(owner: Symbol): Symbol = + new TermSymbol(owner, pos, name).copyAttrsFrom(this) + + def copyAttrsFrom(original: TermSymbol): this.type = { + referenced = original.referenced + defGetter = original.defGetter + this } private val validAliasFlags = SUPERACCESSOR | PARAMACCESSOR | MIXEDIN | SPECIALIZED @@ -1774,10 +1776,33 @@ trait Symbols { flatname } else rawname - override def cloneSymbolImpl(owner: Symbol): Symbol = { - val clone = new ModuleSymbol(owner, pos, name) - clone.referenced = referenced - clone + override def cloneSymbolImpl(owner: Symbol): Symbol = + new ModuleSymbol(owner, pos, name).copyAttrsFrom(this) + } + + /** A class for method symbols */ + class MethodSymbol(initOwner: Symbol, initPos: Position, initName: Name) + extends TermSymbol(initOwner, initPos, initName) { + + private var mtpePeriod = NoPeriod + private var mtpePre: Type = _ + private var mtpeResult: Type = _ + + override def cloneSymbolImpl(owner: Symbol): Symbol = + new MethodSymbol(owner, pos, name).copyAttrsFrom(this) + + def typeAsMemberOf(pre: Type): Type = { + if (mtpePeriod == currentPeriod) { + if (mtpePre eq pre) return mtpeResult + } else if (isValid(mtpePeriod)) { + mtpePeriod = currentPeriod + if (mtpePre eq pre) return mtpeResult + } + val res = pre.computeMemberType(this) + mtpePeriod = currentPeriod + mtpePre = pre + mtpeResult = res + res } } @@ -1977,7 +2002,7 @@ trait Symbols { val period = thisTypePeriod if (period != currentPeriod) { thisTypePeriod = currentPeriod - if (!isValid(period)) thisTypeCache = mkThisType(this) + if (!isValid(period)) thisTypeCache = ThisType(this) } thisTypeCache } diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala index 37ae9f35fe..c1f4115a88 100644 --- a/src/compiler/scala/tools/nsc/symtab/Types.scala +++ b/src/compiler/scala/tools/nsc/symtab/Types.scala @@ -319,7 +319,7 @@ trait Types { * for a reference denoting an abstract type, its bounds, * for all other types, a TypeBounds type all of whose bounds are this type. */ - def bounds: TypeBounds = mkTypeBounds(this, this) + def bounds: TypeBounds = TypeBounds(this, this) /** For a class or intersection type, its parents. * For a TypeBounds type, the parents of its hi bound. @@ -508,14 +508,18 @@ trait Types { } /** The type of `sym', seen as a member of this type. */ - def memberType(sym: Symbol): Type = { - //@M don't prematurely instantiate higher-kinded types, they will be instantiated by transform, typedTypeApply, etc. when really necessary - sym.tpeHK match { - case ov @ OverloadedType(pre, alts) => - OverloadedType(this, alts) - case tp => - tp.asSeenFrom(this, sym.owner) - } + def memberType(sym: Symbol): Type = sym match { + case meth: MethodSymbol => + meth.typeAsMemberOf(this) + case _ => + computeMemberType(sym) + } + + def computeMemberType(sym: Symbol): Type = sym.tpeHK match { //@M don't prematurely instantiate higher-kinded types, they will be instantiated by transform, typedTypeApply, etc. when really necessary + case OverloadedType(_, alts) => + OverloadedType(this, alts) + case tp => + tp.asSeenFrom(this, sym.owner) } /** Substitute types `to' for occurrences of references to @@ -959,7 +963,7 @@ trait Types { override def safeToString: String = prefixString + "type" /* override def typeOfThis: Type = typeSymbol.typeOfThis - override def bounds: TypeBounds = mkTypeBounds(this, this) + override def bounds: TypeBounds = TypeBounds(this, this) override def prefix: Type = NoType override def typeArgs: List[Type] = List() override def typeParams: List[Symbol] = List() @@ -1016,9 +1020,15 @@ trait Types { override def kind = "NoPrefixType" } + def ThisType(sym: Symbol) = { + if (!phase.erasedTypes) unique(new ThisType(sym) with UniqueType) + else if (sym.isImplClass) sym.typeOfThis + else sym.tpe + } + /** A class for this-types of the form <sym>.this.type */ - case class ThisType(sym: Symbol) extends SingletonType { + abstract case class ThisType(sym: Symbol) extends SingletonType { //assert(sym.isClass && !sym.isModuleClass || sym.isRoot, sym) override def isTrivial: Boolean = sym.isPackageClass override def isNotNull = true @@ -1092,8 +1102,23 @@ trait Types { else pre.prefixString + sym.nameString + "." override def kind = "SingleType" } - - case class SuperType(thistpe: Type, supertpe: Type) extends SingletonType { +/* + object SingleType { + def apply(pre: Type, sym: Symbol): Type = { + if (phase.erasedTypes) + sym.tpe.resultType + else if (sym.isRootPackage) + ThisType(RootClass) + else { + var sym1 = rebind(pre, sym) + val pre1 = removeSuper(pre, sym1) + if (pre1 ne pre) sym1 = rebind(pre1, sym1) + unique(new SingleType(pre1, sym1) with UniqueType) + } + } + } +*/ + abstract case class SuperType(thistpe: Type, supertpe: Type) extends SingletonType { override val isTrivial: Boolean = thistpe.isTrivial && supertpe.isTrivial override def isNotNull = true; override def typeSymbol = thistpe.typeSymbol @@ -1107,9 +1132,13 @@ trait Types { override def kind = "SuperType" } + def SuperType(thistp: Type, supertp: Type): Type = + if (phase.erasedTypes) supertp + else unique(new SuperType(thistp, supertp) with UniqueType) + /** A class for the bounds of abstract types and type parameters */ - case class TypeBounds(lo: Type, hi: Type) extends SubType { + abstract case class TypeBounds(lo: Type, hi: Type) extends SubType { def supertype = hi override val isTrivial: Boolean = lo.isTrivial && hi.isTrivial override def bounds: TypeBounds = this @@ -1122,6 +1151,9 @@ trait Types { override def kind = "TypeBoundsType" } + def TypeBounds(lo: Type, hi: Type): TypeBounds = + unique(new TypeBounds(lo, hi) with UniqueType) + /** A common base class for intersection types and class types */ abstract class CompoundType extends Type { @@ -1461,7 +1493,7 @@ trait Types { * * @param value ... */ - case class ConstantType(value: Constant) extends SingletonType { + abstract case class ConstantType(value: Constant) extends SingletonType { override def underlying: Type = value.tpe assert(underlying.typeSymbol != UnitClass) override def isTrivial: Boolean = true @@ -1474,6 +1506,16 @@ trait Types { override def kind = "ConstantType" } + def ConstantType(value: Constant) = { + class UniqueConstantType extends ConstantType(value) with UniqueType { + /** Save the type of 'value'. For Java enums, it depends on finding the linked class, + * which might not be found after 'flatten'. */ + private lazy val _tpe: Type = value.tpe + override def underlying: Type = _tpe + } + unique(new UniqueConstantType) + } + /** A class for named types of the form * `<prefix>.<sym.name>[args]' * Cannot be created directly; one should always use `typeRef' @@ -2225,7 +2267,7 @@ A type's typeSymbol should never be inspected directly. override def bounds: TypeBounds = { val oftp = underlying.bounds oftp match { - case TypeBounds(lo, hi) if ((lo eq this) && (hi eq this)) => mkTypeBounds(this,this) + case TypeBounds(lo, hi) if ((lo eq this) && (hi eq this)) => TypeBounds(this,this) case _ => oftp } } @@ -2298,19 +2340,12 @@ A type's typeSymbol should never be inspected directly. tp } - /** The canonical creator for this-types */ - def mkThisType(sym: Symbol): Type = { - if (!phase.erasedTypes) unique(new ThisType(sym) with UniqueType) - else if (sym.isImplClass) sym.typeOfThis - else sym.tpe - } - /** The canonical creator for single-types */ def singleType(pre: Type, sym: Symbol): Type = { if (phase.erasedTypes) sym.tpe.resultType else if (sym.isRootPackage) - mkThisType(RootClass) + ThisType(RootClass) else { var sym1 = rebind(pre, sym) val pre1 = removeSuper(pre, sym1) @@ -2319,18 +2354,6 @@ A type's typeSymbol should never be inspected directly. } } - /** The canonical creator for super-types */ - def mkSuperType(thistp: Type, supertp: Type): Type = - if (phase.erasedTypes) supertp - else { - unique(new SuperType(thistp, supertp) with UniqueType) - } - - /** The canonical creator for type bounds */ - def mkTypeBounds(lo: Type, hi: Type): TypeBounds = { - unique(new TypeBounds(lo, hi) with UniqueType) - } - def refinementOfClass(clazz: Symbol, parents: List[Type], decls: Scope) = { class RefinementOfClass extends RefinedType(parents, decls) { override def typeSymbol: Symbol = clazz @@ -2338,8 +2361,6 @@ A type's typeSymbol should never be inspected directly. new RefinementOfClass } - - /** the canonical creator for a refined type with a given scope */ def refinedType(parents: List[Type], owner: Symbol, decls: Scope, pos : Position): Type = { if (phase.erasedTypes) @@ -2376,17 +2397,6 @@ A type's typeSymbol should never be inspected directly. result } - /** the canonical creator for a constant type */ - def mkConstantType(value: Constant): ConstantType = { - class UniqueConstantType extends ConstantType(value) with UniqueType { - /** Save the type of 'value'. For Java enums, it depends on finding the linked class, - * which might not be found after 'flatten'. */ - private lazy val _tpe: Type = value.tpe - override def underlying: Type = _tpe - } - unique(new UniqueConstantType) - } - /** The canonical creator for typerefs * todo: see how we can clean this up a bit */ @@ -2771,14 +2781,14 @@ A type's typeSymbol should never be inspected directly. val thistp1 = this(thistp) val supertp1 = this(supertp) if ((thistp1 eq thistp) && (supertp1 eq supertp)) tp - else mkSuperType(thistp1, supertp1) + else SuperType(thistp1, supertp1) case TypeBounds(lo, hi) => variance = -variance val lo1 = this(lo) variance = -variance val hi1 = this(hi) if ((lo1 eq lo) && (hi1 eq hi)) tp - else mkTypeBounds(lo1, hi1) + else TypeBounds(lo1, hi1) case BoundedWildcardType(bounds) => val bounds1 = this(bounds) if (bounds1 eq bounds) tp @@ -2964,7 +2974,7 @@ A type's typeSymbol should never be inspected directly. // note: it's important to write the two tests in this order, // as only typeParams forces the classfile to be read. See #400 private def isRawIfWithoutArgs(sym: Symbol) = - !sym.typeParams.isEmpty && sym.hasFlag(JAVA) + sym.isClass && !sym.typeParams.isEmpty && sym.hasFlag(JAVA) def isRaw(sym: Symbol, args: List[Type]) = !phase.erasedTypes && isRawIfWithoutArgs(sym) && args.isEmpty @@ -2994,7 +3004,7 @@ A type's typeSymbol should never be inspected directly. } def singletonBounds(hi: Type) = { - mkTypeBounds(NothingClass.tpe, intersectionType(List(hi, SingletonClass.tpe))) + TypeBounds(NothingClass.tpe, intersectionType(List(hi, SingletonClass.tpe))) } /** A map to compute the asSeenFrom method */ @@ -3552,7 +3562,7 @@ A type's typeSymbol should never be inspected directly. def apply(tp: Type): Type = tp match { case ThisType(sym) if (sym.isModuleClass) => val sym1 = adaptToNewRun(sym.owner.thisType, sym) - if (sym1 == sym) tp else mkThisType(sym1) + if (sym1 == sym) tp else ThisType(sym1) case SingleType(pre, sym) => if (sym.isPackage) tp else { @@ -4074,12 +4084,12 @@ A type's typeSymbol should never be inspected directly. else try { pendingSubTypes += p - isSubType0(tp1, tp2, depth) + isSubType2(tp1, tp2, depth) } finally { pendingSubTypes -= p } } else { - isSubType0(tp1, tp2, depth) + isSubType2(tp1, tp2, depth) } } } finally { @@ -4171,10 +4181,6 @@ A type's typeSymbol should never be inspected directly. isSubArgs(tps1.tail, tps2.tail, tparams.tail) ) - def isSubType0(tp1: Type, tp2: Type, depth: Int): Boolean = { - isSubType2(tp1, tp2, depth) - } - def differentOrNone(tp1: Type, tp2: Type) = if (tp1 eq tp2) NoType else tp1 /** Does type `tp1' conform to `tp2'? @@ -4196,7 +4202,7 @@ A type's typeSymbol should never be inspected directly. * - bind TypeVars on the right, if lhs is not Annotated nor BoundedWildcard * - handle common cases for first-kind TypeRefs on both sides as a fast path. */ - def firstTry = tp2 match { + def firstTry = { incCounter(ctr1); tp2 match { // fast path: two typerefs, none of them HK case tr2: TypeRef => tp1 match { @@ -4231,14 +4237,14 @@ A type's typeSymbol should never be inspected directly. } case _ => secondTry - } + }} /** Second try, on the left: * - unwrap AnnotatedTypes, BoundedWildcardTypes, * - bind typevars, * - handle existential types by skolemization. */ - def secondTry = tp1 match { + def secondTry = { incCounter(ctr2); tp1 match { case AnnotatedType(_, _, _) => tp1.withoutAnnotations <:< tp2.withoutAnnotations && annotationsConform(tp1, tp2) case BoundedWildcardType(bounds) => @@ -4254,26 +4260,32 @@ A type's typeSymbol should never be inspected directly. } case _ => thirdTry - } + }} def thirdTryRef(tp1: Type, tp2: TypeRef): Boolean = { + incCounter(ctr3); val sym2 = tp2.sym - if (sym2.isAliasType) { - isSubType(tp1.normalize, tp2.normalize, depth) - } else if (sym2.isAbstractType) { - val tp2a = tp2.bounds.lo -// isDifferentTypeConstructor(tp2a, tp2.pre, sym2) && tp1 <:< tp2a || fourthTry - isDifferentTypeConstructor(tp2, tp2a) && tp1 <:< tp2a || fourthTry - } else if (sym2 == NotNullClass) { - tp1.isNotNull - } else if (sym2 == SingletonClass) { - tp1.isStable - } else if (isRaw(sym2, tp2.args)) { - isSubType(tp1, rawToExistential(tp2), depth) - } else if (sym2.isRefinementClass) { - isSubType(tp1, sym2.info, depth) - } else { - fourthTry + sym2 match { + case _: ClassSymbol => + if (sym2 == NotNullClass) + tp1.isNotNull + else if (sym2 == SingletonClass) + tp1.isStable + else if (isRaw(sym2, tp2.args)) + isSubType(tp1, rawToExistential(tp2), depth) + else if (sym2.name == nme.REFINE_CLASS_NAME.toTypeName) + isSubType(tp1, sym2.info, depth) + else + fourthTry + case _: TypeSymbol => + if (sym2 hasFlag DEFERRED) { + val tp2a = tp2.bounds.lo + isDifferentTypeConstructor(tp2, tp2a) && tp1 <:< tp2a || fourthTry + } else { + isSubType(tp1.normalize, tp2.normalize, depth) + } + case _ => + fourthTry } } @@ -4282,7 +4294,7 @@ A type's typeSymbol should never be inspected directly. * - handle typerefs, existentials, and notnull types. * - handle left+right method types, polytypes, typebounds */ - def thirdTry = tp2 match { + def thirdTry = { incCounter(ctr3); tp2 match { case tr2: TypeRef => thirdTryRef(tp1, tr2) case rt2: RefinedType => @@ -4321,34 +4333,39 @@ A type's typeSymbol should never be inspected directly. } case _ => fourthTry - } + }} /** Fourth try, on the left: * - handle typerefs, refined types, notnull and singleton types. */ - def fourthTry = tp1 match { + def fourthTry = { incCounter(ctr4); tp1 match { case tr1 @ TypeRef(_, sym1, _) => - if (sym1.isAliasType) { - isSubType(tp1.normalize, tp2.normalize, depth) - } else if (sym1.isAbstractType) { - val tp1a = tp1.bounds.hi - isDifferentTypeConstructor(tp1, tp1a) && tp1a <:< tp2 - } else if (sym1 == NothingClass) { - true - } else if (sym1 == NullClass) { - tp2 match { - case TypeRef(_, sym2, _) => - sym2.isClass && (sym2 isNonBottomSubClass ObjectClass) && - !(tp2.normalize.typeSymbol isNonBottomSubClass NotNullClass) - case _ => - isSingleType(tp2) && tp1 <:< tp2.widen - } - } else if (isRaw(sym1, tr1.args)) { - isSubType(rawToExistential(tp1), tp2, depth) - } else if (sym1.isRefinementClass) { - isSubType(sym1.info, tp2, depth) - } else { - false + sym1 match { + case _: ClassSymbol => + if (sym1 == NothingClass) + true + else if (sym1 == NullClass) + tp2 match { + case TypeRef(_, sym2, _) => + sym2.isClass && (sym2 isNonBottomSubClass ObjectClass) && + !(tp2.normalize.typeSymbol isNonBottomSubClass NotNullClass) + case _ => + isSingleType(tp2) && tp1 <:< tp2.widen + } + else if (isRaw(sym1, tr1.args)) + isSubType(rawToExistential(tp1), tp2, depth) + else + sym1.name == nme.REFINE_CLASS_NAME.toTypeName && + isSubType(sym1.info, tp2, depth) + case _: TypeSymbol => + if (sym1 hasFlag DEFERRED) { + val tp1a = tp1.bounds.hi + isDifferentTypeConstructor(tp1, tp1a) && tp1a <:< tp2 + } else { + isSubType(tp1.normalize, tp2.normalize, depth) + } + case _ => + false } case RefinedType(parents1, _) => parents1 exists (_ <:< tp2) @@ -4356,7 +4373,7 @@ A type's typeSymbol should never be inspected directly. tp1.underlying <:< tp2 case _ => false - } + }} firstTry } @@ -4763,7 +4780,7 @@ A type's typeSymbol should never be inspected directly. case ts @ MethodType(params, _) :: rest => MethodType(params, lub0(matchingRestypes(ts, params map (_.tpe)))) case ts @ TypeBounds(_, _) :: rest => - mkTypeBounds(glb(ts map (_.bounds.lo), depth), lub(ts map (_.bounds.hi), depth)) + TypeBounds(glb(ts map (_.bounds.lo), depth), lub(ts map (_.bounds.hi), depth)) case ts0 => val (ts, tparams) = stripExistentialsAndTypeVars(ts0) val bts: List[BaseTypeSeq] = ts map (_.baseTypeSeq) @@ -4792,7 +4809,7 @@ A type's typeSymbol should never be inspected directly. proto.cloneSymbol(lubRefined.typeSymbol).setInfo(symtypes.head) else { def lubBounds(bnds: List[TypeBounds]): TypeBounds = - mkTypeBounds(glb(bnds map (_.lo), decr(depth)), lub(bnds map (_.hi), decr(depth))) + TypeBounds(glb(bnds map (_.lo), decr(depth)), lub(bnds map (_.hi), decr(depth))) lubRefined.typeSymbol.newAbstractType(proto.pos, proto.name) .setInfo(lubBounds(symtypes map (_.bounds))) } @@ -4863,7 +4880,7 @@ A type's typeSymbol should never be inspected directly. case ts @ MethodType(params, _) :: rest => MethodType(params, glb0(matchingRestypes(ts, params map (_.tpe)))) case ts @ TypeBounds(_, _) :: rest => - mkTypeBounds(lub(ts map (_.bounds.lo), depth), glb(ts map (_.bounds.hi), depth)) + TypeBounds(lub(ts map (_.bounds.lo), depth), glb(ts map (_.bounds.hi), depth)) case ts0 => try { val (ts, tparams) = stripExistentialsAndTypeVars(ts0) @@ -4903,13 +4920,13 @@ A type's typeSymbol should never be inspected directly. def glbBounds(bnds: List[Type]): TypeBounds = { val lo = lub(bnds map (_.bounds.lo), decr(depth)) val hi = glb(bnds map (_.bounds.hi), decr(depth)) - if (lo <:< hi) mkTypeBounds(lo, hi) + if (lo <:< hi) TypeBounds(lo, hi) else throw GlbFailure } val symbounds = symtypes filter isTypeBound var result: Type = if (symbounds.isEmpty) - mkTypeBounds(NothingClass.tpe, AnyClass.tpe) + TypeBounds(NothingClass.tpe, AnyClass.tpe) else glbBounds(symbounds) for (t <- symtypes if !isTypeBound(t)) if (result.bounds containsType t) result = t @@ -4996,7 +5013,7 @@ A type's typeSymbol should never be inspected directly. else { // Martin: I removed this, because incomplete. Not sure there is a good way to fix it. For the moment we // just err on the conservative side, i.e. with a bound that is too high. // if(!(tparam.info.bounds contains tparam)){ //@M can't deal with f-bounds, see #2251 - val qvar = commonOwner(as) freshExistential "" setInfo mkTypeBounds(g, l) + val qvar = commonOwner(as) freshExistential "" setInfo TypeBounds(g, l) capturedParams += qvar qvar.tpe } diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala index 5c4679625b..d248567a16 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala @@ -508,7 +508,7 @@ abstract class ClassfileParser { val info = pool.getType(in.nextChar) val sym = getOwner(jflags) .newValue(NoPosition, name).setFlag(sflags) - sym.setInfo(if ((jflags & JAVA_ACC_ENUM) == 0) info else mkConstantType(Constant(sym))) + sym.setInfo(if ((jflags & JAVA_ACC_ENUM) == 0) info else ConstantType(Constant(sym))) setPrivateWithin(sym, jflags) parseAttributes(sym, info) getScope(jflags).enter(sym) @@ -620,12 +620,12 @@ abstract class ClassfileParser { case variance @ ('+' | '-' | '*') => index += 1 val bounds = variance match { - case '+' => mkTypeBounds(definitions.NothingClass.tpe, - sig2type(tparams, skiptvs)) - case '-' => mkTypeBounds(sig2type(tparams, skiptvs), - definitions.AnyClass.tpe) - case '*' => mkTypeBounds(definitions.NothingClass.tpe, - definitions.AnyClass.tpe) + case '+' => TypeBounds(definitions.NothingClass.tpe, + sig2type(tparams, skiptvs)) + case '-' => TypeBounds(sig2type(tparams, skiptvs), + definitions.AnyClass.tpe) + case '*' => TypeBounds(definitions.NothingClass.tpe, + definitions.AnyClass.tpe) } val newtparam = sym.newExistential(sym.pos, "?"+i) setInfo bounds existentials += newtparam @@ -702,7 +702,7 @@ abstract class ClassfileParser { if (sig(index) != ':') // guard against empty class bound ts += objToAny(sig2type(tparams, skiptvs)) } - mkTypeBounds(definitions.NothingClass.tpe, intersectionType(ts.toList, sym)) + TypeBounds(definitions.NothingClass.tpe, intersectionType(ts.toList, sym)) } var tparams = classTParams @@ -781,7 +781,7 @@ abstract class ClassfileParser { case nme.ConstantValueATTR => val c = pool.getConstant(in.nextChar) val c1 = convertTo(c, symtype) - if (c1 ne null) sym.setInfo(mkConstantType(c1)) + if (c1 ne null) sym.setInfo(ConstantType(c1)) else println("failure to convert " + c + " to " + symtype); //debug case nme.ScalaSignatureATTR => unpickler.unpickle(in.buf, in.bp, clazz, staticModule, in.file.toString()) diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/MetaParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/MetaParser.scala index bd20c2dabf..58322cdd85 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/MetaParser.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/MetaParser.scala @@ -78,7 +78,7 @@ abstract class MetaParser{ val hi = if (token == "<") { nextToken(); parseType() } else definitions.AnyClass.tpe - sym.setInfo(mkTypeBounds(lo, hi)) + sym.setInfo(TypeBounds(lo, hi)) locals enter sym; sym } diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/UnPickler.scala b/src/compiler/scala/tools/nsc/symtab/classfile/UnPickler.scala index 05ffba925a..8258878376 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/UnPickler.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/UnPickler.scala @@ -245,6 +245,7 @@ abstract class UnPickler { } case VALsym => sym = if (name == moduleRoot.name && owner == moduleRoot.owner) moduleRoot.resetFlag(MODULE) + else if ((flags & METHOD) != 0) owner.newMethod(NoPosition, name) else owner.newValue(NoPosition, name) sym.defaultGetter = defaultGetter case _ => @@ -274,7 +275,7 @@ abstract class UnPickler { case NOPREFIXtpe => NoPrefix case THIStpe => - mkThisType(readSymbolRef()) + ThisType(readSymbolRef()) case SINGLEtpe => singleType(readTypeRef(), readSymbolRef()) case SUPERtpe => @@ -282,14 +283,14 @@ abstract class UnPickler { val supertpe = readTypeRef() SuperType(thistpe, supertpe) case CONSTANTtpe => - mkConstantType(readConstantRef()) + ConstantType(readConstantRef()) case TYPEREFtpe => val pre = readTypeRef() val sym = readSymbolRef() var args = until(end, readTypeRef) rawTypeRef(pre, sym, args) case TYPEBOUNDStpe => - mkTypeBounds(readTypeRef(), readTypeRef()) + TypeBounds(readTypeRef(), readTypeRef()) case REFINEDtpe => val clazz = readSymbolRef() /* diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala index 7722939aaf..1e0c661f0f 100644 --- a/src/compiler/scala/tools/nsc/transform/Erasure.scala +++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala @@ -374,7 +374,7 @@ abstract class Erasure extends AddInterfaces with typechecker.Analyzer with ast. else if (sym == Object_isInstanceOf || sym == ArrayClass) PolyType(sym.info.typeParams, erasure(sym.info.resultType)) else if (sym.isAbstractType) - mkTypeBounds(WildcardType, WildcardType) + TypeBounds(WildcardType, WildcardType) else if (sym.isTerm && sym.owner == ArrayClass) { if (sym.isClassConstructor) tp match { diff --git a/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala b/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala index 0317a3302c..e827b28331 100644 --- a/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala +++ b/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala @@ -42,7 +42,7 @@ abstract class ConstantFolder { private def fold(tree: Tree, compX: => Constant): Tree = try { val x = compX - if ((x ne null) && x.tag != UnitTag) tree setType mkConstantType(x) + if ((x ne null) && x.tag != UnitTag) tree setType ConstantType(x) else tree } catch { case _: ArithmeticException => tree // the code will crash at runtime, diff --git a/src/compiler/scala/tools/nsc/typechecker/DeVirtualize.scala b/src/compiler/scala/tools/nsc/typechecker/DeVirtualize.scala index aead82283d..97a1d81323 100644 --- a/src/compiler/scala/tools/nsc/typechecker/DeVirtualize.scala +++ b/src/compiler/scala/tools/nsc/typechecker/DeVirtualize.scala @@ -252,7 +252,7 @@ abstract class DeVirtualize extends InfoTransform with TypingTransformers { val parents2 = addOverriddenVirtuals(clazz) map { c => typeRef(clazz.owner.thisType, c, typeParams map (_.tpe)) } - mkTypeBounds(NothingClass.tpe, intersectionType(parents1 ::: parents2)) + TypeBounds(NothingClass.tpe, intersectionType(parents1 ::: parents2)) } } } diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala index 0539b4ee17..c8e2afad3d 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -173,7 +173,7 @@ self: Analyzer => object HasMethodMatching { def apply(name: Name, argtpes: List[Type], restpe: Type): Type = { def templateArgType(argtpe: Type) = - new BoundedWildcardType(mkTypeBounds(argtpe, AnyClass.tpe)) + new BoundedWildcardType(TypeBounds(argtpe, AnyClass.tpe)) val dummyMethod = new TermSymbol(NoSymbol, NoPosition, "typer$dummy") val mtpe = MethodType(dummyMethod.newSyntheticValueParams(argtpes map templateArgType), restpe) memberWildcardType(name, mtpe) diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index 621b6dce11..4d1b3c83fe 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -1418,7 +1418,7 @@ trait Infer { if (lo <:< hi) { if (!((lo <:< tparam.info.bounds.lo) && (tparam.info.bounds.hi <:< hi))) { context.nextEnclosing(_.tree.isInstanceOf[CaseDef]).pushTypeBounds(tparam) - tparam setInfo mkTypeBounds(lo, hi) + tparam setInfo TypeBounds(lo, hi) if (settings.debug.value) log("new bounds of " + tparam + " = " + tparam.info) } else { if (settings.debug.value) log("redundant: "+tparam+" "+tparam.info+"/"+lo+" "+hi) diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 1d6f1bddac..3fd1c2f36b 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -2507,7 +2507,7 @@ trait Typers { self: Analyzer => //Console.println(" contains?"+sym.tpe.decls.lookup(fun.symbol.name)); if(sym != fun.symbol.owner && (sym.isPackageClass||sym.isModuleClass) /*(1)*/ ) { // (1) see 'files/pos/unapplyVal.scala' if(fun.symbol.owner.isClass) { - mkThisType(fun.symbol.owner) + ThisType(fun.symbol.owner) } else { //Console.println("2 ThisType("+fun.symbol.owner+")") NoPrefix // see 'files/run/unapplyComplex.scala' @@ -3046,7 +3046,7 @@ trait Typers { self: Analyzer => context.owner.newAliasType(tree.pos, name) setInfo pt else context.owner.newAbstractType(tree.pos, name) setInfo - mkTypeBounds(NothingClass.tpe, AnyClass.tpe) + TypeBounds(NothingClass.tpe, AnyClass.tpe) val rawInfo = vble.rawInfo vble = if (vble.name == nme.WILDCARD.toTypeName) context.scope.enter(vble) else namer.enterInScope(vble) @@ -3439,7 +3439,7 @@ trait Typers { self: Analyzer => } else { findMixinSuper(clazz.info) } - tree setSymbol clazz setType mkSuperType(clazz.thisType, owntype) + tree setSymbol clazz setType SuperType(clazz.thisType, owntype) } } @@ -4007,7 +4007,7 @@ trait Typers { self: Analyzer => case Literal(value) => tree setType ( if (value.tag == UnitTag) UnitClass.tpe - else mkConstantType(value)) + else ConstantType(value)) case SingletonTypeTree(ref) => val ref1 = checkStable( @@ -4028,7 +4028,7 @@ trait Typers { self: Analyzer => case TypeBoundsTree(lo, hi) => val lo1 = typedType(lo, mode) val hi1 = typedType(hi, mode) - treeCopy.TypeBoundsTree(tree, lo1, hi1) setType mkTypeBounds(lo1.tpe, hi1.tpe) + treeCopy.TypeBoundsTree(tree, lo1, hi1) setType TypeBounds(lo1.tpe, hi1.tpe) case etpt @ ExistentialTypeTree(_, _) => newTyper(context.makeNewScope(tree, context.owner)).typedExistentialTypeTree(etpt, mode) diff --git a/src/compiler/scala/tools/nsc/util/Statistics.scala b/src/compiler/scala/tools/nsc/util/Statistics.scala index 188f2fcdb2..37f70ddbaf 100644 --- a/src/compiler/scala/tools/nsc/util/Statistics.scala +++ b/src/compiler/scala/tools/nsc/util/Statistics.scala @@ -168,6 +168,7 @@ object Statistics { val ctr1 = new Counter val ctr2 = new Counter val ctr3 = new Counter + val ctr4 = new Counter val counter1: SubCounter = new SubCounter(subtypeCount) val counter2: SubCounter = new SubCounter(subtypeCount) val timer1: Timer = new Timer @@ -268,6 +269,7 @@ abstract class Statistics { if (ctr1 != null) inform("#ctr1 : " + ctr1) if (ctr2 != null) inform("#ctr2 : " + ctr2) if (ctr3 != null) inform("#ctr3 : " + ctr3) + if (ctr4 != null) inform("#ctr4 : " + ctr4) if (counter1 != null) inform("#counter1 : " + counter1) if (counter2 != null) inform("#counter2 : " + counter2) if (timer1 != null) inform("#timer1 : " + timer1) |