From c6a9a395fab09db6340161905232511e79000494 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Mon, 26 Nov 2012 23:29:34 +0100 Subject: [PATCH] Adds Tree#typeSymbol and uses it in a gazillion places. --- .../scala/tools/nsc/ast/NodePrinters.scala | 2 +- .../scala/tools/nsc/ast/TreeGen.scala | 2 +- .../tools/nsc/backend/icode/GenICode.scala | 10 ++--- .../nsc/interactive/ScratchPadMaker.scala | 2 +- .../scala/tools/nsc/transform/CleanUp.scala | 4 +- .../scala/tools/nsc/transform/Erasure.scala | 38 +++++++++---------- .../tools/nsc/transform/ExplicitOuter.scala | 4 +- .../tools/nsc/transform/LambdaLift.scala | 2 +- .../scala/tools/nsc/transform/Mixin.scala | 4 +- .../tools/nsc/transform/PostErasure.scala | 8 ++-- .../tools/nsc/transform/SpecializeTypes.scala | 2 +- .../scala/tools/nsc/transform/TailCalls.scala | 2 +- .../scala/tools/nsc/transform/UnCurry.scala | 8 ++-- .../tools/nsc/typechecker/ContextErrors.scala | 6 +-- .../tools/nsc/typechecker/Duplicators.scala | 4 +- .../scala/tools/nsc/typechecker/Macros.scala | 2 +- .../tools/nsc/typechecker/RefChecks.scala | 4 +- .../nsc/typechecker/TypeDiagnostics.scala | 2 +- .../scala/tools/nsc/typechecker/Typers.scala | 37 +++++++++--------- .../selectivecps/SelectiveCPSTransform.scala | 2 +- .../plugin/scala/tools/detach/Detach.scala | 10 ++--- .../scala/reflect/internal/Printers.scala | 4 +- .../scala/reflect/internal/TreeGen.scala | 2 +- .../scala/reflect/internal/Trees.scala | 2 + 24 files changed, 82 insertions(+), 81 deletions(-) diff --git a/src/compiler/scala/tools/nsc/ast/NodePrinters.scala b/src/compiler/scala/tools/nsc/ast/NodePrinters.scala index deea4de707a6..eee1d6a313ae 100644 --- a/src/compiler/scala/tools/nsc/ast/NodePrinters.scala +++ b/src/compiler/scala/tools/nsc/ast/NodePrinters.scala @@ -304,7 +304,7 @@ abstract class NodePrinters { case x: RefTree => showRefTree(x) case x => showPosition(x) + x } - else showName(newTypeName(p.tpe.typeSymbol.fullName)) + else showName(newTypeName(p.typeSymbol.fullName)) } printLine(ps0 mkString ", ", "parents") traverse(self) diff --git a/src/compiler/scala/tools/nsc/ast/TreeGen.scala b/src/compiler/scala/tools/nsc/ast/TreeGen.scala index 53d35791b647..c8572984dcc0 100644 --- a/src/compiler/scala/tools/nsc/ast/TreeGen.scala +++ b/src/compiler/scala/tools/nsc/ast/TreeGen.scala @@ -111,7 +111,7 @@ abstract class TreeGen extends scala.reflect.internal.TreeGen with TreeDSL { def dropSyntheticCatchAll(cases: List[CaseDef]): List[CaseDef] = if (!opt.virtPatmat) cases else cases filter { - case CaseDef(pat, EmptyTree, Throw(Apply(Select(New(exTpt), nme.CONSTRUCTOR), _))) if (treeInfo.isWildcardArg(pat) && (exTpt.tpe.typeSymbol eq MatchErrorClass)) => false + case CaseDef(pat, EmptyTree, Throw(Apply(Select(New(exTpt), nme.CONSTRUCTOR), _))) if (treeInfo.isWildcardArg(pat) && (exTpt.typeSymbol eq MatchErrorClass)) => false case CaseDef(pat, guard, body) => true } } diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala index ea4e8475f932..d953986e51c1 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala @@ -192,7 +192,7 @@ abstract class GenICode extends SubComponent { val thrownKind = toTypeKind(expr.tpe) val ctx1 = genLoad(expr, ctx, thrownKind) - ctx1.bb.emit(THROW(expr.tpe.typeSymbol), expr.pos) + ctx1.bb.emit(THROW(expr.typeSymbol), expr.pos) ctx1.bb.enterIgnoreMode (ctx1, NothingReference) @@ -407,7 +407,7 @@ abstract class GenICode extends SubComponent { }) pat match { - case Typed(Ident(nme.WILDCARD), tpt) => genWildcardHandler(tpt.tpe.typeSymbol) + case Typed(Ident(nme.WILDCARD), tpt) => genWildcardHandler(tpt.typeSymbol) case Ident(nme.WILDCARD) => genWildcardHandler(ThrowableClass) case Bind(_, _) => val exception = ctx.method addLocal new Local(pat.symbol, toTypeKind(pat.symbol.tpe), false) // the exception will be loaded and stored into this local @@ -947,8 +947,8 @@ abstract class GenICode extends SubComponent { } else { cm setHostClass qualSym - if (qual.tpe.typeSymbol != qualSym) - log(s"Precisified host class for $sym from ${qual.tpe.typeSymbol.fullName} to ${qualSym.fullName}") + if (qual.typeSymbol != qualSym) + log(s"Precisified host class for $sym from ${qual.typeSymbol.fullName} to ${qualSym.fullName}") } case _ => } @@ -1590,7 +1590,7 @@ abstract class GenICode extends SubComponent { * not using the rich equality is possible (their own equals method will do ok.)*/ def mustUseAnyComparator: Boolean = { def areSameFinals = l.tpe.isFinalType && r.tpe.isFinalType && (l.tpe =:= r.tpe) - !areSameFinals && isMaybeBoxed(l.tpe.typeSymbol) && isMaybeBoxed(r.tpe.typeSymbol) + !areSameFinals && isMaybeBoxed(l.typeSymbol) && isMaybeBoxed(r.typeSymbol) } if (mustUseAnyComparator) { diff --git a/src/compiler/scala/tools/nsc/interactive/ScratchPadMaker.scala b/src/compiler/scala/tools/nsc/interactive/ScratchPadMaker.scala index 7f0265bf4f78..2d1926e06ecc 100644 --- a/src/compiler/scala/tools/nsc/interactive/ScratchPadMaker.scala +++ b/src/compiler/scala/tools/nsc/interactive/ScratchPadMaker.scala @@ -99,7 +99,7 @@ trait ScratchPadMaker { self: Global => case _ => if (stat.isTerm) { addSkip(stat) - if (stat.tpe.typeSymbol == UnitClass) { + if (stat.typeSymbol == UnitClass) { addSandbox(stat) } else { val resName = nextRes() diff --git a/src/compiler/scala/tools/nsc/transform/CleanUp.scala b/src/compiler/scala/tools/nsc/transform/CleanUp.scala index 0c9cb31d5853..fc7cf7eba038 100644 --- a/src/compiler/scala/tools/nsc/transform/CleanUp.scala +++ b/src/compiler/scala/tools/nsc/transform/CleanUp.scala @@ -70,7 +70,7 @@ abstract class CleanUp extends Transform with ast.TreeDSL { } def shouldRewriteTry(tree: Try) = { - val sym = tree.tpe.typeSymbol + val sym = tree.typeSymbol forMSIL && (sym != UnitClass) && (sym != NothingClass) } @@ -324,7 +324,7 @@ abstract class CleanUp extends Transform with ast.TreeDSL { } /* Some info about the argument at the call site. */ - val qualSym = qual.tpe.typeSymbol + val qualSym = qual.typeSymbol val args = qual1() :: params def isDefinitelyArray = (qualSym == ArrayClass) def isMaybeArray = (qualSym == ObjectClass) || isDefinitelyArray diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala index bba5fd4e5e76..569c2073404b 100644 --- a/src/compiler/scala/tools/nsc/transform/Erasure.scala +++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala @@ -357,7 +357,7 @@ abstract class Erasure extends AddInterfaces /** An extractor object for unboxed expressions (maybe subsumed by posterasure?) */ object Unboxed { def unapply(tree: Tree): Option[Tree] = tree match { - case Apply(fn, List(arg)) if isUnbox(fn.symbol) && safeToRemoveUnbox(arg.tpe.typeSymbol) => + case Apply(fn, List(arg)) if isUnbox(fn.symbol) && safeToRemoveUnbox(arg.typeSymbol) => Some(arg) case Apply( TypeApply( @@ -369,8 +369,8 @@ abstract class Erasure extends AddInterfaces List(tpt)), List()) if cast.symbol == Object_asInstanceOf && - tpt.tpe.typeSymbol.isDerivedValueClass && - sel.symbol == tpt.tpe.typeSymbol.derivedValueClassUnbox => + tpt.typeSymbol.isDerivedValueClass && + sel.symbol == tpt.typeSymbol.derivedValueClassUnbox => Some(arg) case _ => None @@ -380,7 +380,7 @@ abstract class Erasure extends AddInterfaces /** An extractor object for boxed expressions (maybe subsumed by posterasure?) */ object Boxed { def unapply(tree: Tree): Option[Tree] = tree match { - case Apply(Select(New(tpt), nme.CONSTRUCTOR), List(arg)) if (tpt.tpe.typeSymbol.isDerivedValueClass) => + case Apply(Select(New(tpt), nme.CONSTRUCTOR), List(arg)) if (tpt.typeSymbol.isDerivedValueClass) => Some(arg) case LabelDef(name, params, Boxed(rhs)) => Some(treeCopy.LabelDef(tree, name, params, rhs) setType rhs.tpe) @@ -573,13 +573,13 @@ abstract class Erasure extends AddInterfaces case ErasedValueType(tref) => val clazz = tref.sym tree match { - case Unboxed(arg) if arg.tpe.typeSymbol == clazz => + case Unboxed(arg) if arg.typeSymbol == clazz => log("shortcircuiting unbox -> box "+arg); arg case _ => New(clazz, cast(tree, underlyingOfValueClass(clazz))) } case _ => - tree.tpe.typeSymbol match { + tree.typeSymbol match { case UnitClass => if (treeInfo isExprSafeToInline tree) REF(BoxedUnit_UNIT) else BLOCK(tree, REF(BoxedUnit_UNIT)) @@ -593,7 +593,7 @@ abstract class Erasure extends AddInterfaces * This is important for specialization: calls to the super constructor should not box/unbox specialized * fields (see TupleX). (ID) */ - case Apply(boxFun, List(arg)) if isUnbox(tree.symbol) && safeToRemoveUnbox(arg.tpe.typeSymbol) => + case Apply(boxFun, List(arg)) if isUnbox(tree.symbol) && safeToRemoveUnbox(arg.typeSymbol) => log(s"boxing an unbox: ${tree.symbol} -> ${arg.tpe}") arg case _ => @@ -637,7 +637,7 @@ abstract class Erasure extends AddInterfaces log("not boxed: "+tree) lazy val underlying = underlyingOfValueClass(clazz) val tree0 = - if (tree.tpe.typeSymbol == NullClass && + if (tree.typeSymbol == NullClass && isPrimitiveValueClass(underlying.typeSymbol)) { // convert `null` directly to underlying type, as going // via the unboxed type would yield a NPE (see SI-5866) @@ -668,7 +668,7 @@ abstract class Erasure extends AddInterfaces // See SI-4731 for one example of how this occurs. log("Attempted to cast to Unit: " + tree) tree.duplicate setType pt - } else if (tree.tpe != null && tree.tpe.typeSymbol == ArrayClass && pt.typeSymbol == ArrayClass) { + } else if (tree.typeSymbol == ArrayClass && pt.typeSymbol == ArrayClass) { // See SI-2386 for one example of when this might be necessary. val needsExtraCast = isPrimitiveValueType(tree.tpe.typeArgs.head) && !isPrimitiveValueType(pt.typeArgs.head) val tree1 = if (needsExtraCast) gen.mkRuntimeCall(nme.toObjectArray, List(tree)) else tree @@ -724,9 +724,9 @@ abstract class Erasure extends AddInterfaces case Apply(TypeApply(sel @ Select(qual, name), List(targ)), List()) if tree.symbol == Any_asInstanceOf => val qual1 = typedQualifier(qual, NOmode, ObjectClass.tpe) // need to have an expected type, see #3037 - val qualClass = qual1.tpe.typeSymbol + val qualClass = qual1.typeSymbol /* - val targClass = targ.tpe.typeSymbol + val targClass = targ.typeSymbol if (isNumericValueClass(qualClass) && isNumericValueClass(targClass)) // convert numeric type casts @@ -792,7 +792,7 @@ abstract class Erasure extends AddInterfaces assert(qual1.symbol.isStable, qual1.symbol); val applied = Apply(qual1, List()) setPos qual1.pos setType qual1.tpe.resultType adaptMember(selectFrom(applied)) - } else if (!(qual1.isInstanceOf[Super] || (qual1.tpe.typeSymbol isSubClass tree.symbol.owner))) { + } else if (!(qual1.isInstanceOf[Super] || (qual1.typeSymbol isSubClass tree.symbol.owner))) { assert(tree.symbol.owner != ArrayClass) selectFrom(cast(qual1, tree.symbol.owner.tpe)) } else { @@ -1024,8 +1024,8 @@ abstract class Erasure extends AddInterfaces case TypeApply(Select(qual, _), List(targ)) => if (qual.tpe <:< targ.tpe) atPos(tree.pos) { Typed(qual, TypeTree(targ.tpe)) } - else if (isNumericValueClass(qual.tpe.typeSymbol) && isNumericValueClass(targ.tpe.typeSymbol)) - atPos(tree.pos)(numericConversion(qual, targ.tpe.typeSymbol)) + else if (isNumericValueClass(qual.typeSymbol) && isNumericValueClass(targ.typeSymbol)) + atPos(tree.pos)(numericConversion(qual, targ.typeSymbol)) else tree } @@ -1035,7 +1035,7 @@ abstract class Erasure extends AddInterfaces def preEraseIsInstanceOf = { fn match { case TypeApply(sel @ Select(qual, name), List(targ)) => - if (qual.tpe != null && isPrimitiveValueClass(qual.tpe.typeSymbol) && targ.tpe != null && targ.tpe <:< AnyRefClass.tpe) + if (isPrimitiveValueClass(qual.typeSymbol) && targ.tpe != null && targ.tpe <:< AnyRefClass.tpe) unit.error(sel.pos, "isInstanceOf cannot test if value types are references.") def mkIsInstanceOf(q: () => Tree)(tp: Type): Tree = @@ -1112,7 +1112,7 @@ abstract class Erasure extends AddInterfaces val args = tree.args if (fn.symbol.owner == ArrayClass) { // Have to also catch calls to abstract types which are bounded by Array. - if (unboundedGenericArrayLevel(qual.tpe.widen) == 1 || qual.tpe.typeSymbol.isAbstractType) { + if (unboundedGenericArrayLevel(qual.tpe.widen) == 1 || qual.typeSymbol.isAbstractType) { // convert calls to apply/update/length on generic arrays to // calls of ScalaRunTime.array_xxx method calls global.typer.typedPos(tree.pos) { @@ -1141,7 +1141,7 @@ abstract class Erasure extends AddInterfaces // erasure the ScalaRunTime.hash overload goes from Unit => Int to BoxedUnit => Int. // This must be because some earlier transformation is being skipped on ##, but so // far I don't know what. For null we now define null.## == 0. - qual.tpe.typeSymbol match { + qual.typeSymbol match { case UnitClass | NullClass => LIT(0) case IntClass => qual case s @ (ShortClass | ByteClass | CharClass) => numericConversion(qual, s) @@ -1149,7 +1149,7 @@ abstract class Erasure extends AddInterfaces case _ => global.typer.typed(gen.mkRuntimeCall(nme.hash_, List(qual))) } - } else if (isPrimitiveValueClass(qual.tpe.typeSymbol)) { + } else if (isPrimitiveValueClass(qual.typeSymbol)) { // Rewrite 5.getClass to ScalaRunTime.anyValClass(5) global.typer.typed(gen.mkRuntimeCall(nme.anyValClass, List(qual, typer.resolveClassTag(tree.pos, qual.tpe.widen)))) } else if (fn.symbol == AnyVal_getClass) { @@ -1158,7 +1158,7 @@ abstract class Erasure extends AddInterfaces tree } } else qual match { - case New(tpt) if name == nme.CONSTRUCTOR && tpt.tpe.typeSymbol.isDerivedValueClass => + case New(tpt) if name == nme.CONSTRUCTOR && tpt.typeSymbol.isDerivedValueClass => // println("inject derived: "+arg+" "+tpt.tpe) val List(arg) = args val attachment = new TypeRefAttachment(tree.tpe.asInstanceOf[TypeRef]) diff --git a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala index 1003d417f6cd..38390af0ded5 100644 --- a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala +++ b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala @@ -220,7 +220,7 @@ abstract class ExplicitOuter extends InfoTransform * take outer field instead of accessor */ private def outerSelect(base: Tree): Tree = { - val outerAcc = outerAccessor(base.tpe.typeSymbol.toInterface) + val outerAcc = outerAccessor(base.typeSymbol.toInterface) val currentClass = this.currentClass //todo: !!! if this line is removed, we get a build failure that protected$currentClass need an override modifier // outerFld is the $outer field of the current class, if the reference can // use it (i.e. reference is allowed to be of the form this.$outer), @@ -547,7 +547,7 @@ abstract class ExplicitOuter extends InfoTransform // println("(base, acc)= "+(base, acc)) val outerSelect = localTyper typed Apply(Select(base, acc), Nil) // achieves the same as: localTyper typed atPos(tree.pos)(outerPath(base, base.tpe.typeSymbol, outerFor.outerClass)) - // println("(b, tpsym, outerForI, outerFor, outerClass)= "+ (base, base.tpe.typeSymbol, outerFor, sel.symbol.owner, outerFor.outerClass)) + // println("(b, tpsym, outerForI, outerFor, outerClass)= "+ (base, base.typeSymbol, outerFor, sel.symbol.owner, outerFor.outerClass)) // println("outerSelect = "+ outerSelect) return transform(treeCopy.Apply(tree, treeCopy.Select(eqsel, outerSelect, eq), args)) } diff --git a/src/compiler/scala/tools/nsc/transform/LambdaLift.scala b/src/compiler/scala/tools/nsc/transform/LambdaLift.scala index 4a23e65ad20a..98d762a65073 100644 --- a/src/compiler/scala/tools/nsc/transform/LambdaLift.scala +++ b/src/compiler/scala/tools/nsc/transform/LambdaLift.scala @@ -478,7 +478,7 @@ abstract class LambdaLift extends InfoTransform { atPos(tree.pos) { val tp = tree.tpe val elemTree = typer typed Select(tree1 setType sym.tpe, nme.elem) - if (elemTree.tpe.typeSymbol != tp.typeSymbol) gen.mkAttributedCast(elemTree, tp) else elemTree + if (elemTree.typeSymbol != tp.typeSymbol) gen.mkAttributedCast(elemTree, tp) else elemTree } else tree1 case Block(stats, expr0) => diff --git a/src/compiler/scala/tools/nsc/transform/Mixin.scala b/src/compiler/scala/tools/nsc/transform/Mixin.scala index 64bb98e2c5f6..a62064db7dca 100644 --- a/src/compiler/scala/tools/nsc/transform/Mixin.scala +++ b/src/compiler/scala/tools/nsc/transform/Mixin.scala @@ -550,7 +550,7 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL { tree } case Apply(tapp @ TypeApply(fn, List(arg)), List()) => - if (arg.tpe.typeSymbol.isImplClass) { + if (arg.typeSymbol.isImplClass) { val ifacetpe = toInterface(arg.tpe) arg.tpe = ifacetpe tapp.tpe = MethodType(List(), ifacetpe) @@ -1136,7 +1136,7 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL { // change every node type that refers to an implementation class to its // corresponding interface, unless the node's symbol is an implementation class. - if (tree.tpe.typeSymbol.isImplClass && ((sym eq null) || !sym.isImplClass)) + if (tree.typeSymbol.isImplClass && ((sym eq null) || !sym.isImplClass)) tree.tpe = toInterface(tree.tpe) tree match { diff --git a/src/compiler/scala/tools/nsc/transform/PostErasure.scala b/src/compiler/scala/tools/nsc/transform/PostErasure.scala index 3ef32caa2c02..db284e713ca1 100644 --- a/src/compiler/scala/tools/nsc/transform/PostErasure.scala +++ b/src/compiler/scala/tools/nsc/transform/PostErasure.scala @@ -40,8 +40,8 @@ trait PostErasure extends InfoTransform with TypingTransformers { Apply(Select(New(tpt), nme.CONSTRUCTOR), List(arg)), acc), List()) if atPhase(currentRun.erasurePhase) { - tpt.tpe.typeSymbol.isDerivedValueClass && - sel.symbol == tpt.tpe.typeSymbol.derivedValueClassUnbox + tpt.typeSymbol.isDerivedValueClass && + sel.symbol == tpt.typeSymbol.derivedValueClassUnbox } => if (settings.debug.value) log("Removing "+tree+" -> "+arg) arg @@ -51,9 +51,9 @@ trait PostErasure extends InfoTransform with TypingTransformers { cmp), List(Apply(Select(New(tpt2), nme.CONSTRUCTOR), List(arg2)))) if atPhase(currentRun.erasurePhase) { - tpt1.tpe.typeSymbol.isDerivedValueClass && + tpt1.typeSymbol.isDerivedValueClass && (sel.symbol == Object_== || sel.symbol == Object_!=) && - tpt2.tpe.typeSymbol == tpt1.tpe.typeSymbol + tpt2.typeSymbol == tpt1.typeSymbol } => val result = Apply(Select(arg1, cmp) setPos sel.pos, List(arg2)) setPos tree.pos log("shortcircuiting equality "+tree+" -> "+result) diff --git a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala index 2f79472cfb95..71c0145bfd23 100644 --- a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala +++ b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala @@ -1407,7 +1407,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { def transformNew = { debuglog("Attempting to specialize new %s(%s)".format(tpt, args.mkString(", "))) val found = findSpec(tpt.tpe) - if (found.typeSymbol ne tpt.tpe.typeSymbol) { + if (found.typeSymbol ne tpt.typeSymbol) { // the ctor can be specialized debuglog("** instantiated specialized type: " + found) reportError { diff --git a/src/compiler/scala/tools/nsc/transform/TailCalls.scala b/src/compiler/scala/tools/nsc/transform/TailCalls.scala index 95cb052fdaa5..043008bd7430 100644 --- a/src/compiler/scala/tools/nsc/transform/TailCalls.scala +++ b/src/compiler/scala/tools/nsc/transform/TailCalls.scala @@ -199,7 +199,7 @@ abstract class TailCalls extends Transform { def receiverIsSuper = ctx.enclosingType.widen <:< receiver.tpe.widen def isRecursiveCall = (ctx.method eq fun.symbol) && ctx.tailPos def transformArgs = noTailTransforms(args) - def matchesTypeArgs = ctx.tparams sameElements (targs map (_.tpe.typeSymbol)) + def matchesTypeArgs = ctx.tparams sameElements (targs map (_.typeSymbol)) /** Records failure reason in Context for reporting. * Position is unchanged (by default, the method definition.) diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala index 529009a05815..8366ece36f78 100644 --- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala +++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala @@ -235,7 +235,7 @@ abstract class UnCurry extends InfoTransform deEta(fun) match { // nullary or parameterless case fun1 if fun1 ne fun => fun1 - case _ if fun.tpe.typeSymbol == PartialFunctionClass => + case _ if fun.typeSymbol == PartialFunctionClass => // only get here when running under -Xoldpatmat synthPartialFunction(fun) case _ => @@ -446,10 +446,10 @@ abstract class UnCurry extends InfoTransform if (treeInfo isWildcardStarArgList args) { val Typed(tree, _) = args.last if (isJava) - if (tree.tpe.typeSymbol == ArrayClass) tree + if (tree.typeSymbol == ArrayClass) tree else sequenceToArray(tree) else - if (tree.tpe.typeSymbol isSubClass SeqClass) tree + if (tree.typeSymbol isSubClass SeqClass) tree else arrayToSequence(tree, varargsElemType) } else { @@ -484,7 +484,7 @@ abstract class UnCurry extends InfoTransform arg match { // don't add a thunk for by-name argument if argument already is an application of // a Function0. We can then remove the application and use the existing Function0. - case Apply(Select(recv, nme.apply), Nil) if recv.tpe.typeSymbol isSubClass FunctionClass(0) => + case Apply(Select(recv, nme.apply), Nil) if recv.typeSymbol isSubClass FunctionClass(0) => recv case _ => newFunction0(arg) diff --git a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala index 9e9b8b995bb2..1a5a1f3e765b 100644 --- a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala @@ -298,7 +298,7 @@ trait ContextErrors { //typedSelect def NotAMemberError(sel: Tree, qual: Tree, name: Name) = { def errMsg = { - val owner = qual.tpe.typeSymbol + val owner = qual.typeSymbol val target = qual.tpe.widen def targetKindString = if (owner.isTypeParameterOrSkolem) "type parameter " else "" def nameString = decodeWithKind(name, owner) @@ -921,7 +921,7 @@ trait ContextErrors { def PatternTypeIncompatibleWithPtError2(pat: Tree, pt1: Type, pt: Type) = { def errMsg = { - val sym = pat.tpe.typeSymbol + val sym = pat.typeSymbol val clazz = sym.companionClass val addendum = ( if (sym.isModuleClass && clazz.isCaseClass && (clazz isSubClass pt1.typeSymbol)) { @@ -1044,7 +1044,7 @@ trait ContextErrors { issueNormalTypeError(tree, "Implementation restriction: case classes cannot have more than " + definitions.MaxFunctionArity + " parameters.") def InheritsItselfError(tree: Tree) = - issueNormalTypeError(tree, tree.tpe.typeSymbol+" inherits itself") + issueNormalTypeError(tree, tree.typeSymbol+" inherits itself") def MissingParameterOrValTypeError(vparam: Tree) = issueNormalTypeError(vparam, "missing parameter type") diff --git a/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala b/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala index df753ba53c72..24e149fab911 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala @@ -242,7 +242,7 @@ abstract class Duplicators extends Analyzer { tree match { case ttree @ TypeTree() => - // log("fixing tpe: " + tree.tpe + " with sym: " + tree.tpe.typeSymbol) + // log("fixing tpe: " + tree.tpe + " with sym: " + tree.typeSymbol) ttree.tpe = fixType(ttree.tpe) ttree @@ -266,7 +266,7 @@ abstract class Duplicators extends Analyzer { super.typed(ddef, mode, pt) case vdef @ ValDef(mods, name, tpt, rhs) => - // log("vdef fixing tpe: " + tree.tpe + " with sym: " + tree.tpe.typeSymbol + " and " + invalidSyms) + // log("vdef fixing tpe: " + tree.tpe + " with sym: " + tree.typeSymbol + " and " + invalidSyms) //if (mods.hasFlag(Flags.LAZY)) vdef.symbol.resetFlag(Flags.MUTABLE) // Martin to Iulian: lazy vars can now appear because they are no longer boxed; Please check that deleting this statement is OK. vdef.tpt.tpe = fixType(vdef.tpt.tpe) vdef.tpe = null diff --git a/src/compiler/scala/tools/nsc/typechecker/Macros.scala b/src/compiler/scala/tools/nsc/typechecker/Macros.scala index bcc37e8b378e..aa7dcb7b0153 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Macros.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Macros.scala @@ -613,7 +613,7 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces { val binding = loadMacroImplBinding(macroDef) macroTraceVerbose("binding: ")(binding) val tags = binding.signature filter (_ != -1) map (paramPos => { - val targ = binding.targs(paramPos).tpe.typeSymbol + val targ = binding.targs(paramPos).typeSymbol val tpe = if (targ.isTypeParameterOrSkolem) { if (targ.owner == macroDef) { // doesn't work when macro def is compiled separately from its usages diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index ee7805cb3d67..6877f014c058 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -1341,7 +1341,7 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans } private def isIrrefutable(pat: Tree, seltpe: Type): Boolean = pat match { case Apply(_, args) => - val clazz = pat.tpe.typeSymbol + val clazz = pat.typeSymbol clazz == seltpe.typeSymbol && clazz.isCaseClass && (args corresponds clazz.primaryConstructor.tpe.asSeenFrom(seltpe, clazz).paramTypes)(isIrrefutable) @@ -1703,7 +1703,7 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans transformIf(x) case New(tpt) => - enterReference(tree.pos, tpt.tpe.typeSymbol) + enterReference(tree.pos, tpt.typeSymbol) tree case Typed(_, Ident(tpnme.WILDCARD_STAR)) if !isRepeatedParamArg(tree) => diff --git a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala index 4233bde77005..8d7c0b729a7f 100644 --- a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala +++ b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala @@ -433,7 +433,7 @@ trait TypeDiagnostics { (expr != Object_synchronized) && !(expr.isLabel && treeInfo.isSynthCaseSymbol(expr)) // it's okay to jump to matchEnd (or another case) with an argument of type nothing - private def treeOK(tree: Tree) = tree.tpe != null && tree.tpe.typeSymbol == NothingClass + private def treeOK(tree: Tree) = tree.typeSymbol == NothingClass def updateExpr(fn: Tree) = { if (fn.symbol != null && fn.symbol.isMethod && !fn.symbol.isConstructor) diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index a2aca45e8f9a..c64d90f3e350 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -920,8 +920,8 @@ trait Typers extends Modes with Adaptations with Tags { // @M: don't check tree.tpe.symbol.typeParams. check tree.tpe.typeParams!!! // (e.g., m[Int] --> tree.tpe.symbol.typeParams.length == 1, tree.tpe.typeParams.length == 0!) !sameLength(tree.tpe.typeParams, pt.typeParams) && - !(tree.tpe.typeSymbol == AnyClass || - tree.tpe.typeSymbol == NothingClass || + !(tree.typeSymbol == AnyClass || + tree.typeSymbol == NothingClass || pt == WildcardType)) { // Check that the actual kind arity (tree.symbol.typeParams.length) conforms to the expected // kind-arity (pt.typeParams.length). Full checks are done in checkKindBounds in Infer. @@ -1492,17 +1492,17 @@ trait Typers extends Modes with Adaptations with Tags { val clazz = context.owner // Normalize supertype and mixins so that supertype is always a class, not a trait. var supertpt = typedTypeConstructor(templ.parents.head) - val firstParent = supertpt.tpe.typeSymbol + val firstParent = supertpt.typeSymbol var mixins = templ.parents.tail map typedType // If first parent is a trait, make it first mixin and add its superclass as first parent - while ((supertpt.tpe.typeSymbol ne null) && supertpt.tpe.typeSymbol.initialize.isTrait) { + while ((supertpt.typeSymbol ne null) && supertpt.typeSymbol.initialize.isTrait) { val supertpt1 = typedType(supertpt) if (!supertpt1.isErrorTyped) { mixins = supertpt1 :: mixins supertpt = TypeTree(supertpt1.tpe.firstParent) setPos supertpt.pos.focus } } - if (supertpt.tpe.typeSymbol == AnyClass && firstParent.isTrait) + if (supertpt.typeSymbol == AnyClass && firstParent.isTrait) supertpt.tpe = AnyRefClass.tpe // Determine @@ -1627,7 +1627,7 @@ trait Typers extends Modes with Adaptations with Tags { def validateParentClass(parent: Tree, superclazz: Symbol) = if (!parent.isErrorTyped) { - val psym = parent.tpe.typeSymbol.initialize + val psym = parent.typeSymbol.initialize checkStablePrefixClassType(parent) @@ -1670,14 +1670,14 @@ trait Typers extends Modes with Adaptations with Tags { if (settings.explaintypes.value) explainTypes(selfType, parent.tpe.typeOfThis) } - if (parents exists (p => p != parent && p.tpe.typeSymbol == psym && !psym.isError)) + if (parents exists (p => p != parent && p.typeSymbol == psym && !psym.isError)) pending += ParentInheritedTwiceError(parent, psym) validateDynamicParent(psym) } if (!parents.isEmpty && parents.forall(!_.isErrorTyped)) { - val superclazz = parents.head.tpe.typeSymbol + val superclazz = parents.head.typeSymbol for (p <- parents) validateParentClass(p, superclazz) } @@ -2097,7 +2097,7 @@ trait Typers extends Modes with Adaptations with Tags { silent(_.typedTypeConstructor(stringParser(repl).typ())) match { case SilentResultValue(tpt) => val alias = enclClass.newAliasType(name.toTypeName, useCase.pos) - val tparams = cloneSymbolsAtOwner(tpt.tpe.typeSymbol.typeParams, alias) + val tparams = cloneSymbolsAtOwner(tpt.typeSymbol.typeParams, alias) val newInfo = genPolyType(tparams, appliedType(tpt.tpe, tparams map (_.tpe))) alias setInfo newInfo context.scope.enter(alias) @@ -2177,7 +2177,7 @@ trait Typers extends Modes with Adaptations with Tags { checkSelfConstructorArgs(ddef, meth.owner) } - if (tpt1.tpe.typeSymbol != NothingClass && !context.returnsSeen && rhs1.tpe.typeSymbol != NothingClass) + if (tpt1.typeSymbol != NothingClass && !context.returnsSeen && rhs1.typeSymbol != NothingClass) rhs1 = checkDead(rhs1) if (!isPastTyper && meth.owner.isClass && @@ -3771,7 +3771,7 @@ trait Typers extends Modes with Adaptations with Tags { // Ident's type is already over an existential. // (If the type is already over an existential, // then remap the type, not the core symbol.) - if (!arg.tpe.typeSymbol.hasFlag(EXISTENTIAL)) + if (!arg.typeSymbol.hasFlag(EXISTENTIAL)) addIfLocal(arg.symbol, arg.tpe) case _ => () } @@ -4256,11 +4256,11 @@ trait Typers extends Modes with Adaptations with Tags { context.enclMethod.returnsSeen = true val expr1: Tree = typed(expr, EXPRmode | BYVALmode | RETmode, restpt.tpe) // Warn about returning a value if no value can be returned. - if (restpt.tpe.typeSymbol == UnitClass) { + if (restpt.typeSymbol == UnitClass) { // The typing in expr1 says expr is Unit (it has already been coerced if // it is non-Unit) so we have to retype it. Fortunately it won't come up much // unless the warning is legitimate. - if (typed(expr).tpe.typeSymbol != UnitClass) + if (typed(expr).typeSymbol != UnitClass) unit.warning(tree.pos, "enclosing method " + name + " has result type Unit: return value discarded") } treeCopy.Return(tree, checkDead(expr1)).setSymbol(enclMethod.owner) @@ -4517,8 +4517,7 @@ trait Typers extends Modes with Adaptations with Tags { case _ => normalTypedApply(tree, fun, args) match { case Apply(Select(New(tpt), name), args) - if (tpt.tpe != null && - tpt.tpe.typeSymbol == ArrayClass && + if (tpt.typeSymbol == ArrayClass && args.length == 1 && erasure.GenericArray.unapply(tpt.tpe).isDefined) => // !!! todo simplify by using extractor // convert new Array[T](len) to evidence[ClassTag[T]].newArray(len) @@ -4591,9 +4590,9 @@ trait Typers extends Modes with Adaptations with Tags { val clazz = qual1 match { case This(_) => qual1.symbol - case _ => qual1.tpe.typeSymbol + case _ => qual1.typeSymbol } - //println(clazz+"/"+qual1.tpe.typeSymbol+"/"+qual1) + //println(clazz+"/"+qual1.typeSymbol+"/"+qual1) def findMixinSuper(site: Type): Type = { var ps = site.parents filter (_.typeSymbol.name == mix) @@ -4693,7 +4692,7 @@ trait Typers extends Modes with Adaptations with Tags { if (!qual.tpe.widen.isErroneous) { if ((mode & QUALmode) != 0) { - val lastTry = rootMirror.missingHook(qual.tpe.typeSymbol, name) + val lastTry = rootMirror.missingHook(qual.typeSymbol, name) if (lastTry != NoSymbol) return typed1(tree setSymbol lastTry, mode, pt) } NotAMemberError(tree, qual, name) @@ -5241,7 +5240,7 @@ trait Typers extends Modes with Adaptations with Tags { newExistentialType(List(tparam), arrayType(tparam.tpe)) } - val (exprAdapted, baseClass) = exprTyped.tpe.typeSymbol match { + val (exprAdapted, baseClass) = exprTyped.typeSymbol match { case ArrayClass => (adapt(exprTyped, onlyStickyModes(mode), subArrayType(pt)), ArrayClass) case _ => (adapt(exprTyped, onlyStickyModes(mode), seqType(pt)), SeqClass) } diff --git a/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala b/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala index 4482bf2b7c91..da99cffa754f 100644 --- a/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala +++ b/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala @@ -320,7 +320,7 @@ abstract class SelectiveCPSTransform extends PluginComponent with var methodName = nme.map if (body1.tpe != null) { - if (body1.tpe.typeSymbol == Context) + if (body1.typeSymbol == Context) methodName = nme.flatMap } else diff --git a/src/detach/plugin/scala/tools/detach/Detach.scala b/src/detach/plugin/scala/tools/detach/Detach.scala index f9a3d80da42c..7322e5147498 100644 --- a/src/detach/plugin/scala/tools/detach/Detach.scala +++ b/src/detach/plugin/scala/tools/detach/Detach.scala @@ -388,7 +388,7 @@ abstract class Detach extends PluginComponent println("\nTreeAccessorSubstituter: Assign1\n\tqual1="+qual1+", sel.tpe="+lhs.tpe+ "\n\tqual1.tpe="+qual1.tpe+", name1="+name1+ "\n\tqual.tpe="+qual.tpe+", tree.tpe="+tree.tpe)//debug - val iface = toInterface(qual.tpe.typeSymbol) + val iface = toInterface(qual.typeSymbol) val sym = iface.tpe.decls lookup nme.getterToSetter(name) atPos(tree.pos)(Apply( Select(super.transform(qual), sym) setType lhs.tpe, @@ -468,7 +468,7 @@ abstract class Detach extends PluginComponent ", qual.tpe="+qual.tpe+", name="+name)//debug val sym = qual.symbol val qual1 = gen.mkAttributedSelect(gen.mkAttributedThis(sym.owner), sym) - val iface = toInterface(qual.tpe.typeSymbol) + val iface = toInterface(qual.typeSymbol) val sym1 = iface.tpe.decls lookup name val fun = gen.mkAttributedSelect(qual1, sym1) Apply(fun, List()) setType tree.tpe @@ -488,9 +488,9 @@ abstract class Detach extends PluginComponent if (currentOwner.enclClass isNestedIn clazz) apply else removeAccessors(qual) val name1 = - (if (tsym isSubClass qual1.tpe.typeSymbol) "" + (if (tsym isSubClass qual1.typeSymbol) "" else tsym.fullName('$')+"$")+sym.name - val iface = toInterface(qual1.tpe.typeSymbol) + val iface = toInterface(qual1.typeSymbol) val sym1 = iface.tpe.decls lookup name1 gen.mkAttributedSelect(qual1, sym1) case None => @@ -955,7 +955,7 @@ abstract class Detach extends PluginComponent private def mkClosureApply(tree: Tree): Tree = { val apply @ Apply(fun, args) = detachedClosureApply(tree) assert(fun.symbol.isConstructor, fun.symbol+" is not a constructor")//debug - val clazz = apply.tpe.typeSymbol + val clazz = apply.typeSymbol val thiz = capturedThisClass(clazz) val cdef = mkClosureDef(clazz) val uid = localTyper typed { diff --git a/src/reflect/scala/reflect/internal/Printers.scala b/src/reflect/scala/reflect/internal/Printers.scala index 80d247c0ea4d..e9eb65539d9e 100644 --- a/src/reflect/scala/reflect/internal/Printers.scala +++ b/src/reflect/scala/reflect/internal/Printers.scala @@ -392,8 +392,8 @@ trait Printers extends api.Printers { self: SymbolTable => if ((tree.tpe eq null) || (doPrintPositions && tt.original != null)) { if (tt.original != null) print("") else print("") - } else if ((tree.tpe.typeSymbol ne null) && tree.tpe.typeSymbol.isAnonymousClass) { - print(tree.tpe.typeSymbol.toString) + } else if ((tree.typeSymbol ne null) && tree.typeSymbol.isAnonymousClass) { + print(tree.typeSymbol.toString) } else { print(tree.tpe.toString) } diff --git a/src/reflect/scala/reflect/internal/TreeGen.scala b/src/reflect/scala/reflect/internal/TreeGen.scala index ebf099857356..c4fd314e453d 100644 --- a/src/reflect/scala/reflect/internal/TreeGen.scala +++ b/src/reflect/scala/reflect/internal/TreeGen.scala @@ -173,7 +173,7 @@ abstract class TreeGen extends macros.TreeBuilder { mkAttributedIdent(sym) else { val pkgQualifier = - if (sym != null && sym.owner.isPackageObjectClass && sym.effectiveOwner == qual.tpe.typeSymbol) { + if (sym != null && sym.owner.isPackageObjectClass && sym.effectiveOwner == qual.typeSymbol) { val obj = sym.owner.sourceModule Select(qual, nme.PACKAGE) setSymbol obj setType singleType(qual.tpe, obj) } diff --git a/src/reflect/scala/reflect/internal/Trees.scala b/src/reflect/scala/reflect/internal/Trees.scala index b2158de9ec47..b214f732b0e0 100644 --- a/src/reflect/scala/reflect/internal/Trees.scala +++ b/src/reflect/scala/reflect/internal/Trees.scala @@ -27,6 +27,8 @@ trait Trees extends api.Trees { self: SymbolTable => def tpe_=(t: Type) = rawtpe = t def setType(tp: Type): this.type = { rawtpe = tp; this } def defineType(tp: Type): this.type = setType(tp) + /** @return the type symbol of this `Tree`'s tpe, or `NoSymbol` if this tree is untyped. */ + final def typeSymbol: Symbol = if (tpe == null) NoSymbol else tpe.typeSymbol def symbol: Symbol = null //!!!OPT!!! symbol is about 3% of hot compile times -- megamorphic dispatch? def symbol_=(sym: Symbol) { throw new UnsupportedOperationException("symbol_= inapplicable for " + this) }