Skip to content

Commit b9e76d6

Browse files
committed
Avoid redundant generation of static this proxies
We don't need a thos proxy if the target is a statioc object, unless that object sees opaque aliases. This allows to simplify the registerType logic, and avoided some spurious proxy generations, for instance in run-macros/i5119
1 parent df412c6 commit b9e76d6

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2546,7 +2546,7 @@ object SymDenotations {
25462546
}
25472547

25482548
private[SymDenotations] def stillValidInOwner(denot: SymDenotation)(using Context): Boolean = try
2549-
val owner = denot.owner.denot
2549+
val owner = denot.maybeOwner.denot
25502550
stillValid(owner)
25512551
&& (
25522552
!owner.isClass

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
642642
inlineCallPrefix.tpe == tpe && ctx.owner.isContainedIn(tpe.cls)
643643
|| tpe.cls.isContainedIn(inlinedMethod)
644644
|| tpe.cls.is(Package)
645+
|| tpe.cls.isStaticOwner && !(tpe.cls.seesOpaques && ctx.owner.isContainedIn(tpe.cls))
645646

646647
/** Very similar to TreeInfo.isPureExpr, but with the following inliner-only exceptions:
647648
* - synthetic case class apply methods, when the case class constructor is empty, are
@@ -742,18 +743,9 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
742743

743744
private val registerTypes = new TypeTraverser:
744745
override def stopAt = StopAt.Package
745-
// Only register ThisType prefixes that see opaques. No need to register the others
746-
// since they are static prefixes.
747-
def registerStaticPrefix(t: Type): Unit = t match
748-
case t: ThisType if t.cls.seesOpaques => registerType(t)
749-
case t: NamedType => registerStaticPrefix(t.prefix)
750-
case _ =>
751-
override def traverse(t: Type) = t match
752-
case t: NamedType if t.currentSymbol.isStatic =>
753-
registerStaticPrefix(t.prefix)
754-
case t =>
755-
registerType(t)
756-
traverseChildren(t)
746+
override def traverse(t: Type) =
747+
registerType(t)
748+
traverseChildren(t)
757749

758750
/** Register type of leaf node */
759751
private def registerLeaf(tree: Tree): Unit = tree match

0 commit comments

Comments
 (0)