Skip to content

Commit d78fefb

Browse files
Devirtualize Tree.tpe
1 parent f25a60f commit d78fefb

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ object Trees {
7878
/** The type constructor at the root of the tree */
7979
type ThisTree[T >: Untyped] <: Tree[T]
8080

81-
private[this] var myTpe: T = _
81+
protected var myTpe: T @uncheckedVariance = _
8282

8383
/** Destructively set the type of the tree. This should be called only when it is known that
8484
* it is safe under sharing to do so. One use-case is in the withType method below
@@ -91,7 +91,7 @@ object Trees {
9191
/** The type of the tree. In case of an untyped tree,
9292
* an UnAssignedTypeException is thrown. (Overridden by empty trees)
9393
*/
94-
def tpe: T @uncheckedVariance = {
94+
final def tpe: T @uncheckedVariance = {
9595
if (myTpe == null)
9696
throw new UnAssignedTypeException(this)
9797
myTpe
@@ -722,7 +722,6 @@ object Trees {
722722
}
723723

724724
trait WithoutTypeOrPos[-T >: Untyped] extends Tree[T] {
725-
override def tpe: T @uncheckedVariance = NoType.asInstanceOf[T]
726725
override def withTypeUnchecked(tpe: Type) = this.asInstanceOf[ThisTree[Type]]
727726
override def pos = NoPosition
728727
override def setPos(pos: Position) = {}
@@ -735,6 +734,8 @@ object Trees {
735734
*/
736735
case class Thicket[-T >: Untyped](trees: List[Tree[T]])
737736
extends Tree[T] with WithoutTypeOrPos[T] {
737+
myTpe = NoType.asInstanceOf[T]
738+
738739
type ThisTree[-T >: Untyped] = Thicket[T]
739740
override def isEmpty: Boolean = trees.isEmpty
740741
override def toList: List[Tree[T]] = flatten(trees)
@@ -753,6 +754,7 @@ object Trees {
753754

754755
class EmptyValDef[T >: Untyped] extends ValDef[T](
755756
nme.WILDCARD, genericEmptyTree[T], genericEmptyTree[T]) with WithoutTypeOrPos[T] {
757+
myTpe = NoType.asInstanceOf[T]
756758
override def isEmpty: Boolean = true
757759
setMods(untpd.Modifiers(PrivateLocal))
758760
}

0 commit comments

Comments
 (0)