diff options
author | Paul Phillips <paulp@improving.org> | 2012-04-09 10:12:03 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-04-09 19:43:38 -0700 |
commit | c456bebbcddae490a2ab2860855e936adb60539e (patch) | |
tree | 977cded8b50c1efa7e12bc2aee55d62fa91641d7 /src/compiler | |
parent | 54496744806e9617d8ab745122080c48f60c64e7 (diff) | |
download | scala-c456bebbcddae490a2ab2860855e936adb60539e.tar.gz scala-c456bebbcddae490a2ab2860855e936adb60539e.tar.bz2 scala-c456bebbcddae490a2ab2860855e936adb60539e.zip |
Less laborious type application.
And eliminating redundancy. Reduced gratuitous usage of typeConstructor
on symbols which don't have type parameters.
Diffstat (limited to 'src/compiler')
19 files changed, 98 insertions, 115 deletions
diff --git a/src/compiler/scala/reflect/internal/Definitions.scala b/src/compiler/scala/reflect/internal/Definitions.scala index 4fd98ad7b3..6ef6751720 100644 --- a/src/compiler/scala/reflect/internal/Definitions.scala +++ b/src/compiler/scala/reflect/internal/Definitions.scala @@ -198,14 +198,14 @@ trait Definitions extends reflect.api.StandardDefinitions { lazy val JavaLangEnumClass = getRequiredClass("java.lang.Enum") // convenient one-argument parameter lists - lazy val anyparam = List(AnyClass.typeConstructor) + lazy val anyparam = List(AnyClass.tpe) lazy val anyvalparam = List(AnyValClass.typeConstructor) lazy val anyrefparam = List(AnyRefClass.typeConstructor) // private parameter conveniences - private def booltype = BooleanClass.typeConstructor - private def inttype = IntClass.typeConstructor - private def stringtype = StringClass.typeConstructor + private def booltype = BooleanClass.tpe + private def inttype = IntClass.tpe + private def stringtype = StringClass.tpe // Java types def javaTypeName(jclazz: Class[_]): TypeName = newTypeName(jclazz.getName) @@ -249,7 +249,7 @@ trait Definitions extends reflect.api.StandardDefinitions { // top types lazy val AnyClass = enterNewClass(ScalaPackageClass, tpnme.Any, Nil, ABSTRACT) - lazy val AnyRefClass = newAlias(ScalaPackageClass, tpnme.AnyRef, ObjectClass.typeConstructor) + lazy val AnyRefClass = newAlias(ScalaPackageClass, tpnme.AnyRef, ObjectClass.tpe) lazy val ObjectClass = getClass(sn.Object) // Note: this is not the type alias AnyRef, it's a companion-like @@ -376,10 +376,10 @@ trait Definitions extends reflect.api.StandardDefinitions { lazy val RemoteInterfaceClass = getRequiredClass("java.rmi.Remote") lazy val RemoteExceptionClass = getRequiredClass("java.rmi.RemoteException") - lazy val ByNameParamClass = specialPolyClass(tpnme.BYNAME_PARAM_CLASS_NAME, COVARIANT)(_ => AnyClass.typeConstructor) - lazy val EqualsPatternClass = specialPolyClass(tpnme.EQUALS_PATTERN_NAME, 0L)(_ => AnyClass.typeConstructor) - lazy val JavaRepeatedParamClass = specialPolyClass(tpnme.JAVA_REPEATED_PARAM_CLASS_NAME, COVARIANT)(tparam => arrayType(tparam.typeConstructor)) - lazy val RepeatedParamClass = specialPolyClass(tpnme.REPEATED_PARAM_CLASS_NAME, COVARIANT)(tparam => seqType(tparam.typeConstructor)) + lazy val ByNameParamClass = specialPolyClass(tpnme.BYNAME_PARAM_CLASS_NAME, COVARIANT)(_ => AnyClass.tpe) + lazy val EqualsPatternClass = specialPolyClass(tpnme.EQUALS_PATTERN_NAME, 0L)(_ => AnyClass.tpe) + lazy val JavaRepeatedParamClass = specialPolyClass(tpnme.JAVA_REPEATED_PARAM_CLASS_NAME, COVARIANT)(tparam => arrayType(tparam.tpe)) + lazy val RepeatedParamClass = specialPolyClass(tpnme.REPEATED_PARAM_CLASS_NAME, COVARIANT)(tparam => seqType(tparam.tpe)) def isByNameParamType(tp: Type) = tp.typeSymbol == ByNameParamClass def isScalaRepeatedParamType(tp: Type) = tp.typeSymbol == RepeatedParamClass @@ -467,7 +467,6 @@ trait Definitions extends reflect.api.StandardDefinitions { lazy val OptionClass: Symbol = getRequiredClass("scala.Option") lazy val SomeClass: Symbol = getRequiredClass("scala.Some") lazy val NoneModule: Symbol = getRequiredModule("scala.None") - lazy val SomeModule: Symbol = getRequiredModule("scala.Some") /** Note: don't use this manifest/type function for anything important, * as it is incomplete. Would love to have things like existential types @@ -480,7 +479,7 @@ trait Definitions extends reflect.api.StandardDefinitions { val args = m.typeArguments if ((sym eq NoSymbol) || args.isEmpty) sym.tpe - else appliedType(sym.typeConstructor, args map manifestToType) + else appliedType(sym, args map manifestToType: _*) case _ => NoType } @@ -511,21 +510,21 @@ trait Definitions extends reflect.api.StandardDefinitions { def hasJavaMainMethod(path: String): Boolean = hasJavaMainMethod(getModuleIfDefined(path)) - def isOptionType(tp: Type) = cond(tp.normalize) { case TypeRef(_, OptionClass, List(_)) => true } - def isSomeType(tp: Type) = cond(tp.normalize) { case TypeRef(_, SomeClass, List(_)) => true } - def isNoneType(tp: Type) = cond(tp.normalize) { case TypeRef(_, NoneModule, List(_)) => true } + def isOptionType(tp: Type) = tp.typeSymbol isSubClass OptionClass + def isSomeType(tp: Type) = tp.typeSymbol eq SomeClass + def isNoneType(tp: Type) = tp.typeSymbol eq NoneModule - def optionType(tp: Type) = typeRef(NoPrefix, OptionClass, List(tp)) - def someType(tp: Type) = typeRef(NoPrefix, SomeClass, List(tp)) - def symbolType = typeRef(SymbolClass.typeConstructor.prefix, SymbolClass, List()) - def longType = typeRef(LongClass.typeConstructor.prefix, LongClass, List()) - - // Product, Tuple, Function + // Product, Tuple, Function, AbstractFunction private def mkArityArray(name: String, arity: Int, countFrom: Int = 1): Array[Symbol] = { val list = countFrom to arity map (i => getRequiredClass("scala." + name + i)) if (countFrom == 0) list.toArray else (NoSymbol +: list).toArray } + private def aritySpecificType(symbolArray: Array[Symbol], args: List[Type], others: Type*): Type = { + val arity = args.length + if (arity >= symbolArray.length) NoType + else appliedType(symbolArray(arity), args ++ others: _*) + } val MaxTupleArity, MaxProductArity, MaxFunctionArity = 22 /** The maximal dimensions of a generic array creation. @@ -533,11 +532,17 @@ trait Definitions extends reflect.api.StandardDefinitions { * nested array. More is not allowed. */ val MaxArrayDims = 5 - lazy val TupleClass = mkArityArray("Tuple", MaxTupleArity) - lazy val ProductClass = mkArityArray("Product", MaxProductArity) - lazy val FunctionClass = mkArityArray("Function", MaxFunctionArity, 0) + lazy val ProductClass = { val arr = mkArityArray("Product", MaxProductArity) ; arr(0) = UnitClass ; arr } + lazy val TupleClass = mkArityArray("Tuple", MaxTupleArity) + lazy val FunctionClass = mkArityArray("Function", MaxFunctionArity, 0) lazy val AbstractFunctionClass = mkArityArray("runtime.AbstractFunction", MaxFunctionArity, 0) - lazy val isProductNClass = ProductClass.toSet + + /** Creators for TupleN, ProductN, FunctionN. */ + def tupleType(elems: List[Type]) = aritySpecificType(TupleClass, elems) + def productType(elems: List[Type]) = aritySpecificType(ProductClass, elems) + def functionType(formals: List[Type], restpe: Type) = aritySpecificType(FunctionClass, formals, restpe) + def abstractFunctionType(formals: List[Type], restpe: Type) = aritySpecificType(AbstractFunctionClass, formals, restpe) + def wrapArrayMethodName(elemtp: Type): TermName = elemtp.typeSymbol match { case ByteClass => nme.wrapByteArray case ShortClass => nme.wrapShortArray @@ -554,10 +559,11 @@ trait Definitions extends reflect.api.StandardDefinitions { } @deprecated("Use isTupleType", "2.10.0") - def isTupleTypeOrSubtype(tp: Type): Boolean = isTupleType(tp) + def isTupleTypeOrSubtype(tp: Type) = isTupleType(tp) def tupleField(n: Int, j: Int) = getMember(TupleClass(n), nme.productAccessorName(j)) def isTupleSymbol(sym: Symbol) = TupleClass contains unspecializedSymbol(sym) + def isProductNClass(sym: Symbol) = ProductClass contains sym def unspecializedSymbol(sym: Symbol): Symbol = { if (sym hasFlag SPECIALIZED) { @@ -594,14 +600,6 @@ trait Definitions extends reflect.api.StandardDefinitions { } def isTupleType(tp: Type) = isTupleTypeDirect(tp.normalize) - def tupleType(elems: List[Type]) = { - val len = elems.length - if (len <= MaxTupleArity) { - val sym = TupleClass(len) - typeRef(sym.typeConstructor.prefix, sym, elems) - } else NoType - } - lazy val ProductRootClass: Symbol = getRequiredClass("scala.Product") def Product_productArity = getMember(ProductRootClass, nme.productArity) def Product_productElement = getMember(ProductRootClass, nme.productElement) @@ -616,18 +614,6 @@ trait Definitions extends reflect.api.StandardDefinitions { /** returns true if this type is exactly ProductN[T1,...,Tn], not some subclass */ def isExactProductType(tp: Type): Boolean = isProductNClass(tp.typeSymbol) - def productType(elems: List[Type]) = { - if (elems.isEmpty) UnitClass.tpe - else { - val len = elems.length - if (len <= MaxProductArity) { - val sym = ProductClass(len) - typeRef(sym.typeConstructor.prefix, sym, elems) - } - else NoType - } - } - /** if tpe <: ProductN[T1,...,TN], returns List(T1,...,TN) else Nil */ def getProductArgs(tpe: Type): List[Type] = tpe.baseClasses find isProductNClass match { case Some(x) => tpe.baseType(x).typeArgs @@ -640,21 +626,10 @@ trait Definitions extends reflect.api.StandardDefinitions { } def functionApply(n: Int) = getMember(FunctionClass(n), nme.apply) - def functionType(formals: List[Type], restpe: Type) = { - val len = formals.length - if (len <= MaxFunctionArity) { - val sym = FunctionClass(len) - typeRef(sym.typeConstructor.prefix, sym, formals :+ restpe) - } else NoType - } - def abstractFunctionForFunctionType(tp: Type) = tp.normalize match { - case tr @ TypeRef(_, _, args) if isFunctionType(tr) => - val sym = AbstractFunctionClass(args.length - 1) - typeRef(sym.typeConstructor.prefix, sym, args) - case _ => - NoType - } + def abstractFunctionForFunctionType(tp: Type) = + if (isFunctionType(tp)) abstractFunctionType(tp.typeArgs.init, tp.typeArgs.last) + else NoType def isFunctionType(tp: Type): Boolean = tp.normalize match { case TypeRef(_, sym, args) if args.nonEmpty => @@ -671,17 +646,21 @@ trait Definitions extends reflect.api.StandardDefinitions { case _ => NoType } - def seqType(arg: Type) = appliedType(SeqClass.typeConstructor, List(arg)) - def arrayType(arg: Type) = appliedType(ArrayClass.typeConstructor, List(arg)) - def byNameType(arg: Type) = appliedType(ByNameParamClass.typeConstructor, List(arg)) - def iteratorOfType(tp: Type) = appliedType(IteratorClass.typeConstructor, List(tp)) + def arrayType(arg: Type) = appliedType(ArrayClass, arg) + def byNameType(arg: Type) = appliedType(ByNameParamClass, arg) + def iteratorOfType(tp: Type) = appliedType(IteratorClass, tp) + def javaRepeatedType(arg: Type) = appliedType(JavaRepeatedParamClass, arg) + def optionType(tp: Type) = appliedType(OptionClass, tp) + def scalaRepeatedType(arg: Type) = appliedType(RepeatedParamClass, arg) + def seqType(arg: Type) = appliedType(SeqClass, arg) + def someType(tp: Type) = appliedType(SomeClass, tp) - lazy val StringArray = arrayType(StringClass.tpe) + def StringArray = arrayType(StringClass.tpe) lazy val ObjectArray = arrayType(ObjectClass.tpe) def ClassType(arg: Type) = if (phase.erasedTypes || forMSIL) ClassClass.tpe - else appliedType(ClassClass.typeConstructor, List(arg)) + else appliedType(ClassClass, arg) def vmClassType(arg: Type): Type = ClassType(arg) def vmSignature(sym: Symbol, info: Type): String = signature(info) // !!! @@ -940,7 +919,7 @@ trait Definitions extends reflect.api.StandardDefinitions { ) lazy val AnnotationDefaultAttr: Symbol = { - val attr = enterNewClass(RuntimePackageClass, tpnme.AnnotationDefaultATTR, List(AnnotationClass.typeConstructor)) + val attr = enterNewClass(RuntimePackageClass, tpnme.AnnotationDefaultATTR, List(AnnotationClass.tpe)) // This attribute needs a constructor so that modifiers in parsed Java code make sense attr.info.decls enter attr.newClassConstructor(NoPosition) attr @@ -1085,10 +1064,10 @@ trait Definitions extends reflect.api.StandardDefinitions { private lazy val boxedValueClassesSet = boxedClass.values.toSet + BoxedUnitClass /** Is symbol a value class? */ - def isPrimitiveValueClass(sym: Symbol) = scalaValueClassesSet(sym) + def isPrimitiveValueClass(sym: Symbol) = ScalaValueClasses contains sym def isNonUnitValueClass(sym: Symbol) = isPrimitiveValueClass(sym) && (sym != UnitClass) def isSpecializableClass(sym: Symbol) = isPrimitiveValueClass(sym) || (sym == AnyRefClass) - def isScalaValueType(tp: Type) = scalaValueClassesSet(tp.typeSymbol) + def isScalaValueType(tp: Type) = ScalaValueClasses contains tp.typeSymbol /** Is symbol a boxed value class, e.g. java.lang.Integer? */ def isBoxedValueClass(sym: Symbol) = boxedValueClassesSet(sym) diff --git a/src/compiler/scala/reflect/internal/SymbolTable.scala b/src/compiler/scala/reflect/internal/SymbolTable.scala index daaf0dff26..83a24dce68 100644 --- a/src/compiler/scala/reflect/internal/SymbolTable.scala +++ b/src/compiler/scala/reflect/internal/SymbolTable.scala @@ -220,7 +220,7 @@ abstract class SymbolTable extends api.Universe def arrayToRepeated(tp: Type): Type = tp match { case MethodType(params, rtpe) => val formals = tp.paramTypes - assert(formals.last.typeSymbol == definitions.ArrayClass) + assert(formals.last.typeSymbol == definitions.ArrayClass, formals) val method = params.last.owner val elemtp = formals.last.typeArgs.head match { case RefinedType(List(t1, t2), _) if (t1.typeSymbol.isAbstractType && t2.typeSymbol == definitions.ObjectClass) => @@ -228,8 +228,7 @@ abstract class SymbolTable extends api.Universe case t => t } - val newParams = method.newSyntheticValueParams( - formals.init :+ appliedType(definitions.JavaRepeatedParamClass.typeConstructor, List(elemtp))) + val newParams = method.newSyntheticValueParams(formals.init :+ definitions.javaRepeatedType(elemtp)) MethodType(newParams, rtpe) case PolyType(tparams, rtpe) => PolyType(tparams, arrayToRepeated(rtpe)) diff --git a/src/compiler/scala/reflect/internal/Types.scala b/src/compiler/scala/reflect/internal/Types.scala index 786b680ff8..575d84eab4 100644 --- a/src/compiler/scala/reflect/internal/Types.scala +++ b/src/compiler/scala/reflect/internal/Types.scala @@ -3332,6 +3332,10 @@ trait Types extends api.Types { self: SymbolTable => case _ => abort(debugString(tycon)) } + /** Very convenient. */ + def appliedType(tyconSym: Symbol, args: Type*): Type = + appliedType(tyconSym.typeConstructor, args.toList) + /** A creator for existential types where the type arguments, * rather than being applied directly, are interpreted as the * upper bounds of unknown types. For instance if the type argument @@ -6555,6 +6559,16 @@ trait Types extends api.Types { self: SymbolTable => try { explainSwitch = true; op } finally { explainSwitch = s } } + def isUnboundedGeneric(tp: Type) = tp match { + case t @ TypeRef(_, sym, _) => sym.isAbstractType && !(t <:< AnyRefClass.tpe) + case _ => false + } + def isBoundedGeneric(tp: Type) = tp match { + case TypeRef(_, sym, _) if sym.isAbstractType => (tp <:< AnyRefClass.tpe) + case TypeRef(_, sym, _) => !isPrimitiveValueClass(sym) + case _ => false + } + def objToAny(tp: Type): Type = if (!phase.erasedTypes && tp.typeSymbol == ObjectClass) AnyClass.tpe else tp diff --git a/src/compiler/scala/reflect/internal/transform/Erasure.scala b/src/compiler/scala/reflect/internal/transform/Erasure.scala index e87de8db80..1b323f839b 100644 --- a/src/compiler/scala/reflect/internal/transform/Erasure.scala +++ b/src/compiler/scala/reflect/internal/transform/Erasure.scala @@ -69,6 +69,9 @@ trait Erasure { clazz.firstParamAccessor.tpe.resultType abstract class ErasureMap extends TypeMap { + private lazy val ObjectArray = arrayType(ObjectClass.tpe) + private lazy val ErasedObject = erasedTypeRef(ObjectClass) + def mergeParents(parents: List[Type]): Type def eraseNormalClassRef(pre: Type, clazz: Symbol): Type = @@ -87,7 +90,7 @@ trait Erasure { if (unboundedGenericArrayLevel(tp) == 1) ObjectClass.tpe else if (args.head.typeSymbol.isBottomClass) ObjectArray else typeRef(apply(pre), sym, args map applyInArray) - else if (sym == AnyClass || sym == AnyValClass || sym == SingletonClass || sym == NotNullClass) erasedTypeRef(ObjectClass) + else if (sym == AnyClass || sym == AnyValClass || sym == SingletonClass || sym == NotNullClass) ErasedObject else if (sym == UnitClass) erasedTypeRef(BoxedUnitClass) else if (sym.isRefinementClass) apply(mergeParents(tp.parents)) else if (sym.isDerivedValueClass) eraseDerivedValueClassRef(sym) @@ -111,7 +114,7 @@ trait Erasure { case ClassInfoType(parents, decls, clazz) => ClassInfoType( if (clazz == ObjectClass || isPrimitiveValueClass(clazz)) Nil - else if (clazz == ArrayClass) List(erasedTypeRef(ObjectClass)) + else if (clazz == ArrayClass) List(ErasedObject) else removeLaterObjects(parents map this), decls, clazz) case _ => diff --git a/src/compiler/scala/reflect/internal/transform/UnCurry.scala b/src/compiler/scala/reflect/internal/transform/UnCurry.scala index fd6d4e177d..0c1640ceb9 100644 --- a/src/compiler/scala/reflect/internal/transform/UnCurry.scala +++ b/src/compiler/scala/reflect/internal/transform/UnCurry.scala @@ -12,14 +12,8 @@ trait UnCurry { private def expandAlias(tp: Type): Type = if (!tp.isHigherKinded) tp.normalize else tp - private def isUnboundedGeneric(tp: Type) = tp match { - case t @ TypeRef(_, sym, _) => sym.isAbstractType && !(t <:< AnyRefClass.tpe) - case _ => false - } - val uncurry: TypeMap = new TypeMap { def apply(tp0: Type): Type = { - // tp0.typeSymbolDirect.initialize val tp = expandAlias(tp0) tp match { case MethodType(params, MethodType(params1, restpe)) => @@ -31,13 +25,13 @@ trait UnCurry { apply(MethodType(h.cloneSymbol.resetFlag(IMPLICIT) :: t, restpe)) case NullaryMethodType(restpe) => apply(MethodType(List(), restpe)) - case TypeRef(pre, ByNameParamClass, List(arg)) => + case TypeRef(pre, ByNameParamClass, arg :: Nil) => apply(functionType(List(), arg)) - case TypeRef(pre, RepeatedParamClass, args) => - apply(appliedType(SeqClass.typeConstructor, args)) - case TypeRef(pre, JavaRepeatedParamClass, args) => + case TypeRef(pre, RepeatedParamClass, arg :: Nil) => + apply(seqType(arg)) + case TypeRef(pre, JavaRepeatedParamClass, arg :: Nil) => apply(arrayType( - if (isUnboundedGeneric(args.head)) ObjectClass.tpe else args.head)) + if (isUnboundedGeneric(arg)) ObjectClass.tpe else arg)) case _ => expandAlias(mapOver(tp)) } diff --git a/src/compiler/scala/tools/nsc/ast/TreeDSL.scala b/src/compiler/scala/tools/nsc/ast/TreeDSL.scala index 8703de4e18..2b75925d9a 100644 --- a/src/compiler/scala/tools/nsc/ast/TreeDSL.scala +++ b/src/compiler/scala/tools/nsc/ast/TreeDSL.scala @@ -292,7 +292,7 @@ trait TreeDSL { def TRY(tree: Tree) = new TryStart(tree, Nil, EmptyTree) def BLOCK(xs: Tree*) = Block(xs.init.toList, xs.last) def NOT(tree: Tree) = Select(tree, Boolean_not) - def SOME(xs: Tree*) = Apply(SomeModule, makeTupleTerm(xs.toList, true)) + def SOME(xs: Tree*) = Apply(SomeClass.companionSymbol, makeTupleTerm(xs.toList, true)) /** Typed trees from symbols. */ def THIS(sym: Symbol) = gen.mkAttributedThis(sym) diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index fa2fc54ac0..e7e3eaabf5 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -249,7 +249,7 @@ self => final val InBlock = 1 final val InTemplate = 2 - lazy val ScalaValueClassNames: Set[Name] = definitions.scalaValueClassesSet map (_.name) + lazy val ScalaValueClassNames = tpnme.AnyVal :: definitions.ScalaValueClasses.map(_.name) import nme.raw @@ -2743,9 +2743,8 @@ self => val tstart0 = if (body.isEmpty && in.lastOffset < tstart) in.lastOffset else tstart atPos(tstart0) { - // [Martin to Paul: This needs to be refined. We should only include the 9 primitive classes, - // not any other value classes that happen to be defined in the Scala package. - if (inScalaRootPackage && (name == tpnme.AnyVal || (ScalaValueClassNames contains name))) + // Exclude only the 9 primitives plus AnyVal. + if (inScalaRootPackage && ScalaValueClassNames.contains(name)) Template(parents0, self, anyvalConstructor :: body) else Template(anyrefParents, self, constrMods, vparamss, argss, body, o2p(tstart)) diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala index 8e568eca79..ec303d76ee 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala @@ -1533,7 +1533,7 @@ abstract class GenICode extends SubComponent { */ def genEqEqPrimitive(l: Tree, r: Tree, ctx: Context)(thenCtx: Context, elseCtx: Context): Unit = { def getTempLocal = ctx.method.lookupLocal(nme.EQEQ_LOCAL_VAR) getOrElse { - ctx.makeLocal(l.pos, AnyRefClass.typeConstructor, nme.EQEQ_LOCAL_VAR) + ctx.makeLocal(l.pos, AnyRefClass.tpe, nme.EQEQ_LOCAL_VAR) } /** True if the equality comparison is between values that require the use of the rich equality diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala index 18dc4aa56c..be1e466f4e 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala @@ -1022,7 +1022,7 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with serialVUID foreach { value => import Flags._, definitions._ val fieldName = "serialVersionUID" - val fieldSymbol = clasz.symbol.newValue(newTermName(fieldName), NoPosition, STATIC | FINAL) setInfo longType + val fieldSymbol = clasz.symbol.newValue(newTermName(fieldName), NoPosition, STATIC | FINAL) setInfo LongClass.tpe clasz addField new IField(fieldSymbol) lastBlock emit CONSTANT(Constant(value)) lastBlock emit STORE_FIELD(fieldSymbol, true) diff --git a/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala b/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala index 702d643fb4..670c9bbb3b 100644 --- a/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala +++ b/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala @@ -474,7 +474,7 @@ class ModelFactory(val global: Global, val settings: doc.Settings) { if (bSym == definitions.Object_synchronized) { val cSymInfo = (bSym.info: @unchecked) match { case PolyType(ts, MethodType(List(bp), mt)) => - val cp = bp.cloneSymbol.setInfo(appliedType(definitions.ByNameParamClass.typeConstructor, List(bp.info))) + val cp = bp.cloneSymbol.setInfo(definitions.byNameType(bp.info)) PolyType(ts, MethodType(List(cp), mt)) } bSym.cloneSymbol.setInfo(cSymInfo) diff --git a/src/compiler/scala/tools/nsc/interpreter/ReplVals.scala b/src/compiler/scala/tools/nsc/interpreter/ReplVals.scala index a68392f0fb..c5d04b17c9 100644 --- a/src/compiler/scala/tools/nsc/interpreter/ReplVals.scala +++ b/src/compiler/scala/tools/nsc/interpreter/ReplVals.scala @@ -63,11 +63,11 @@ object ReplVals { class AppliedTypeFromManifests(sym: Symbol) { def apply[M](implicit m1: Manifest[M]): Type = if (sym eq NoSymbol) NoType - else appliedType(sym.typeConstructor, List(m1) map (x => manifestToType(x).asInstanceOf[Type])) + else appliedType(sym, manifestToType(m1).asInstanceOf[Type]) def apply[M1, M2](implicit m1: Manifest[M1], m2: Manifest[M2]): Type = if (sym eq NoSymbol) NoType - else appliedType(sym.typeConstructor, List(m1, m2) map (x => manifestToType(x).asInstanceOf[Type])) + else appliedType(sym, manifestToType(m1).asInstanceOf[Type], manifestToType(m2).asInstanceOf[Type]) } (sym: Symbol) => new AppliedTypeFromManifests(sym) diff --git a/src/compiler/scala/tools/nsc/matching/Patterns.scala b/src/compiler/scala/tools/nsc/matching/Patterns.scala index 4f6a4c8dc0..bbe22ca314 100644 --- a/src/compiler/scala/tools/nsc/matching/Patterns.scala +++ b/src/compiler/scala/tools/nsc/matching/Patterns.scala @@ -187,9 +187,9 @@ trait Patterns extends ast.TreeDSL { // As yet I can't testify this is doing any good relative to using // tpt.tpe, but it doesn't seem to hurt either. private lazy val packedType = global.typer.computeType(tpt, tpt.tpe) - private lazy val consRef = appliedType(ConsClass.typeConstructor, List(packedType)) - private lazy val listRef = appliedType(ListClass.typeConstructor, List(packedType)) - private lazy val seqRef = appliedType(SeqClass.typeConstructor, List(packedType)) + private lazy val consRef = appliedType(ConsClass, packedType) + private lazy val listRef = appliedType(ListClass, packedType) + private lazy val seqRef = appliedType(SeqClass, packedType) private def thisSeqRef = { val tc = (tree.tpe baseType SeqClass).typeConstructor diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala index 9dee441527..3d3cea75d6 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala @@ -776,7 +776,8 @@ abstract class ClassfileParser { // with arrays of primitive types. if (elemtp.typeSymbol.isAbstractType && !(elemtp <:< definitions.ObjectClass.tpe)) elemtp = intersectionType(List(elemtp, definitions.ObjectClass.tpe)) - appliedType(definitions.ArrayClass.tpe, List(elemtp)) + + definitions.arrayType(elemtp) case '(' => // we need a method symbol. given in line 486 by calling getType(methodSym, ..) assert(sym ne null, sig) diff --git a/src/compiler/scala/tools/nsc/transform/LambdaLift.scala b/src/compiler/scala/tools/nsc/transform/LambdaLift.scala index 36571ceb7f..f6dc8fbfb0 100644 --- a/src/compiler/scala/tools/nsc/transform/LambdaLift.scala +++ b/src/compiler/scala/tools/nsc/transform/LambdaLift.scala @@ -27,7 +27,7 @@ abstract class LambdaLift extends InfoTransform { def refType(valueRef: Map[Symbol, Symbol], objectRefClass: Symbol) = if (isPrimitiveValueClass(symClass) && symClass != UnitClass) valueRef(symClass).tpe else if (erasedTypes) objectRefClass.tpe - else appliedType(objectRefClass.typeConstructor, List(tpe)) + else appliedType(objectRefClass, tpe) if (sym.hasAnnotation(VolatileAttr)) refType(volatileRefClass, VolatileObjectRefClass) else refType(refClass, ObjectRefClass) } else tpe diff --git a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala index 30decd4854..12d2513756 100644 --- a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala +++ b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala @@ -67,8 +67,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { import definitions.{ RootClass, BooleanClass, UnitClass, ArrayClass, ScalaValueClasses, isPrimitiveValueClass, isScalaValueType, - SpecializedClass, RepeatedParamClass, JavaRepeatedParamClass, - AnyRefClass, ObjectClass, AnyRefModule, + SpecializedClass, AnyRefClass, ObjectClass, AnyRefModule, GroupOfSpecializable, uncheckedVarianceClass, ScalaInlineClass } @@ -126,11 +125,6 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { isBoundedGeneric(tp) //(tp <:< AnyRefClass.tpe) } - private def isBoundedGeneric(tp: Type) = tp match { - case TypeRef(_, sym, _) if sym.isAbstractType => (tp <:< AnyRefClass.tpe) - case TypeRef(_, sym, _) => !isPrimitiveValueClass(sym) - case _ => false - } object TypeEnv { /** Return a new type environment binding specialized type parameters of sym to diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala index 7fc472df2f..f90d3d45fe 100644 --- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala +++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala @@ -126,7 +126,7 @@ abstract class UnCurry extends InfoTransform /** The type of a non-local return expression with given argument type */ private def nonLocalReturnExceptionType(argtype: Type) = - appliedType(NonLocalReturnControlClass.typeConstructor, List(argtype)) + appliedType(NonLocalReturnControlClass, argtype) /** A hashmap from method symbols to non-local return keys */ private val nonLocalReturnKeys = perRunCaches.newMap[Symbol, Symbol]() @@ -244,7 +244,7 @@ abstract class UnCurry extends InfoTransform def parents = if (isFunctionType(fun.tpe)) List(abstractFunctionForFunctionType(fun.tpe), SerializableClass.tpe) - else if (isPartial) List(appliedType(AbstractPartialFunctionClass.typeConstructor, targs), SerializableClass.tpe) + else if (isPartial) List(appliedType(AbstractPartialFunctionClass, targs: _*), SerializableClass.tpe) else List(ObjectClass.tpe, fun.tpe, SerializableClass.tpe) val anonClass = owner newAnonymousFunctionClass(fun.pos, inConstructorFlag) addAnnotation serialVersionUIDAnnotation diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala index 7d1198a4a2..75440a1136 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -1107,7 +1107,7 @@ trait Implicits { /** Re-wraps a type in a manifest before calling inferImplicit on the result */ def findManifest(tp: Type, manifestClass: Symbol = if (full) FullManifestClass else PartialManifestClass) = - inferImplicit(tree, appliedType(manifestClass.typeConstructor, List(tp)), true, false, context).tree + inferImplicit(tree, appliedType(manifestClass, tp), true, false, context).tree def findSubManifest(tp: Type) = findManifest(tp, if (full) FullManifestClass else OptManifestClass) def mot(tp0: Type, from: List[Symbol], to: List[Type]): SearchResult = { diff --git a/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala b/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala index 82ffc3fd9e..3d8c2ea564 100644 --- a/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala +++ b/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala @@ -37,7 +37,7 @@ trait MethodSynthesis { require(container.owner.isPackageClass, "Container must be a top-level class in a package: " + container) require(tparams.size == args.size, "Arguments must match type constructor arity: " + tparams + ", " + args) - typeRef(container.typeConstructor.prefix, container, args map (_.tpe)) + appliedType(container, args map (_.tpe): _*) } def companionType[T](implicit m: M[T]) = diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 76e1d40af9..f558e0afc7 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -186,7 +186,7 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { } val result = wrapImplicit(from) if (result != EmptyTree) result - else wrapImplicit(appliedType(ByNameParamClass.typeConstructor, List(from))) + else wrapImplicit(byNameType(from)) } } @@ -2166,8 +2166,8 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { def translateMatch(selector1: Tree, selectorTp: Type, casesAdapted: List[CaseDef], ownType: Type, doTranslation: Boolean, matchFailGen: Option[Tree => Tree] = None) = { def repeatedToSeq(tp: Type): Type = (tp baseType RepeatedParamClass) match { - case TypeRef(_, RepeatedParamClass, args) => appliedType(SeqClass.typeConstructor, args) - case _ => tp + case TypeRef(_, RepeatedParamClass, arg :: Nil) => seqType(arg) + case _ => tp } if (!doTranslation) { // a switch @@ -2240,7 +2240,7 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { val (selector1, selectorTp, casesAdapted, resTp, doTranslation) = methodBodyTyper.prepareTranslateMatch(selector, cases, mode, ptRes) val methFormals = paramSyms map (_.tpe) - val parents = List(appliedType(AbstractFunctionClass(arity).typeConstructor, methFormals :+ resTp), SerializableClass.tpe) + val parents = List(abstractFunctionType(methFormals, resTp), SerializableClass.tpe) anonClass setInfo ClassInfoType(parents, newScope, anonClass) methodSym setInfoAndEnter MethodType(paramSyms, resTp) @@ -3555,7 +3555,7 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { treeCopy.ArrayValue(tree, elemtpt1, elems1) .setType( (if (isFullyDefined(pt) && !phase.erasedTypes) pt - else appliedType(ArrayClass.typeConstructor, List(elemtpt1.tpe))).notNull) + else arrayType(elemtpt1.tpe)).notNull) } def typedAssign(lhs: Tree, rhs: Tree): Tree = { |