Skip to content

Adds Tree#typeSymbol and used in a gazillion places. #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/ast/NodePrinters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/ast/TreeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 _ =>
}
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/scala/tools/nsc/transform/CleanUp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
Expand Down
38 changes: 19 additions & 19 deletions src/compiler/scala/tools/nsc/transform/Erasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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))
Expand All @@ -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 _ =>
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand All @@ -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 =
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -1141,15 +1141,15 @@ 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)
case BooleanClass => If(qual, LIT(true.##), LIT(false.##))
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) {
Expand All @@ -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])
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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))
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/transform/LambdaLift.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/scala/tools/nsc/transform/Mixin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/scala/tools/nsc/transform/PostErasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/transform/TailCalls.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/scala/tools/nsc/transform/UnCurry.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 _ =>
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
Loading