Skip to content

Commit e2eb053

Browse files
Devirtualize Tree.tpe
1 parent 8233f89 commit e2eb053

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
@@ -754,7 +754,6 @@ object Trees {
754754
}
755755

756756
trait WithoutTypeOrPos[-T >: Untyped] extends Tree[T] {
757-
override def tpe: T @uncheckedVariance = NoType.asInstanceOf[T]
758757
override def withTypeUnchecked(tpe: Type) = this.asInstanceOf[ThisTree[Type]]
759758
override def pos = NoPosition
760759
override def setPos(pos: Position) = {}
@@ -767,6 +766,8 @@ object Trees {
767766
*/
768767
case class Thicket[-T >: Untyped](trees: List[Tree[T]])
769768
extends Tree[T] with WithoutTypeOrPos[T] {
769+
myTpe = NoType.asInstanceOf[T]
770+
770771
type ThisTree[-T >: Untyped] = Thicket[T]
771772
override def isEmpty: Boolean = trees.isEmpty
772773
override def toList: List[Tree[T]] = flatten(trees)
@@ -785,6 +786,7 @@ object Trees {
785786

786787
class EmptyValDef[T >: Untyped] extends ValDef[T](
787788
nme.WILDCARD, genericEmptyTree[T], genericEmptyTree[T]) with WithoutTypeOrPos[T] {
789+
myTpe = NoType.asInstanceOf[T]
788790
override def isEmpty: Boolean = true
789791
setMods(untpd.Modifiers(PrivateLocal))
790792
}

0 commit comments

Comments
 (0)