Skip to content

Commit 36ff9d4

Browse files
Devirtualize Tree.tpe
1 parent 790337f commit 36ff9d4

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
@@ -727,7 +727,6 @@ object Trees {
727727
}
728728

729729
trait WithoutTypeOrPos[-T >: Untyped] extends Tree[T] {
730-
override def tpe: T @uncheckedVariance = NoType.asInstanceOf[T]
731730
override def withTypeUnchecked(tpe: Type) = this.asInstanceOf[ThisTree[Type]]
732731
override def pos = NoPosition
733732
override def setPos(pos: Position) = {}
@@ -740,6 +739,8 @@ object Trees {
740739
*/
741740
case class Thicket[-T >: Untyped](trees: List[Tree[T]])
742741
extends Tree[T] with WithoutTypeOrPos[T] {
742+
myTpe = NoType.asInstanceOf[T]
743+
743744
type ThisTree[-T >: Untyped] = Thicket[T]
744745
override def isEmpty: Boolean = trees.isEmpty
745746
override def toList: List[Tree[T]] = flatten(trees)
@@ -758,6 +759,7 @@ object Trees {
758759

759760
class EmptyValDef[T >: Untyped] extends ValDef[T](
760761
nme.WILDCARD, genericEmptyTree[T], genericEmptyTree[T]) with WithoutTypeOrPos[T] {
762+
myTpe = NoType.asInstanceOf[T]
761763
override def isEmpty: Boolean = true
762764
setMods(untpd.Modifiers(PrivateLocal))
763765
}

0 commit comments

Comments
 (0)