Skip to content

Commit 2981ae7

Browse files
committed
Simplify TypeComparer
1 parent 6a21e5f commit 2981ae7

File tree

4 files changed

+9
-39
lines changed

4 files changed

+9
-39
lines changed

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

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
6868
private var myInstance: TypeComparer = this
6969
def currentInstance: TypeComparer = myInstance
7070

71-
/** All capturing types in the original `tp1` enclosing the currently
72-
* compared type.
73-
*/
74-
private var enclosingCapturing1: List[AnnotatedType] = Nil
75-
7671
/** Is a subtype check in progress? In that case we may not
7772
* permanently instantiate type variables, because the corresponding
7873
* constraint might still be retracted and the instantiation should
@@ -553,11 +548,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
553548
if tp1.isBoxedCapturing && !parent1.isBoxedCapturing
554549
then tp2.unboxed
555550
else tp2
556-
try
557-
enclosingCapturing1 = tp1 :: enclosingCapturing1
558-
recur(parent1, tp2a)
559-
finally
560-
enclosingCapturing1 = enclosingCapturing1.tail
551+
recur(parent1, tp2a)
561552
else thirdTry
562553
compareCapturing
563554
case tp1: AnnotatedType if !tp1.isRefining =>
@@ -685,7 +676,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
685676

686677
if defn.isFunctionType(tp2) then
687678
if tp2.derivesFrom(defn.PolyFunctionClass) then
688-
return isSubInfo(tp1.ccMember(nme.apply).info, tp2.refinedInfo)
679+
return isSubInfo(tp1.member(nme.apply).info, tp2.refinedInfo)
689680
else
690681
tp1w.widenDealias match
691682
case tp1: RefinedType =>
@@ -2038,7 +2029,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
20382029
* rebase both itself and the member info of `tp` on a freshly created skolem type.
20392030
*/
20402031
def hasMatchingMember(name: Name, tp1: Type, tp2: RefinedType): Boolean =
2041-
trace(i"hasMatchingMember($tp1 . $name :? ${tp2.refinedInfo}), mbr: ${tp1.ccMember(name).info}", subtyping) {
2032+
trace(i"hasMatchingMember($tp1 . $name :? ${tp2.refinedInfo}), mbr: ${tp1.member(name).info}", subtyping) {
20422033

20432034
// If the member is an abstract type and the prefix is a path, compare the member itself
20442035
// instead of its bounds. This case is needed situations like:
@@ -2119,30 +2110,9 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
21192110
|| (tp1.isStable && m.symbol.isStableMember && isSubType(TermRef(tp1, m.symbol), tp2.refinedInfo))
21202111
end qualifies
21212112

2122-
tp1.ccMember(name).hasAltWithInline(qualifies)
2113+
tp1.member(name).hasAltWithInline(qualifies)
21232114
}
21242115

2125-
extension (qual: Type)
2126-
/** Add all directly enclosing capture sets to `qual` and select `name` on the
2127-
* resulting type. A capture set is directly enclosing if there is an enclosing
2128-
* capturing type with the set and all types between `qual` and that type
2129-
* are RefinedTypes or CapturingTypes.
2130-
*/
2131-
def ccMember(name: Name): Denotation =
2132-
def isEnclosing(tp: Type): Boolean = tp match
2133-
case RefinedType(parent, _, _) => isEnclosing(parent)
2134-
case CapturingType(parent, _) => isEnclosing(parent)
2135-
case _ => tp eq qual
2136-
2137-
def addCaptures(tp: Type, encls: List[AnnotatedType]): Type = encls match
2138-
case (ct @ CapturingType(parent, refs)) :: encls1 if isEnclosing(parent) =>
2139-
addCaptures(CapturingType(tp, refs, ct.isBoxedCapturing), encls1)
2140-
case _ =>
2141-
tp
2142-
2143-
addCaptures(qual, enclosingCapturing1).member(name)
2144-
end ccMember
2145-
21462116
final def ensureStableSingleton(tp: Type): SingletonType = tp.stripTypeVar match {
21472117
case tp: SingletonType if tp.isStable => tp
21482118
case tp: ValueType => SkolemType(tp)
@@ -3418,7 +3388,7 @@ class ExplainingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
34183388
}
34193389

34203390
override def hasMatchingMember(name: Name, tp1: Type, tp2: RefinedType): Boolean =
3421-
traceIndented(s"hasMatchingMember(${show(tp1)} . $name, ${show(tp2.refinedInfo)}), member = ${show(tp1.ccMember(name).info)}") {
3391+
traceIndented(s"hasMatchingMember(${show(tp1)} . $name, ${show(tp2.refinedInfo)}), member = ${show(tp1.member(name).info)}") {
34223392
super.hasMatchingMember(name, tp1, tp2)
34233393
}
34243394

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import typer.ForceDegree
1919
import typer.Inferencing._
2020
import typer.IfBottom
2121
import reporting.TestingReporter
22-
import cc.{CapturingType, derivedCapturingType, CaptureSet, isBoxed, isBoxedCapturing, isLevelOwner, localRoot}
22+
import cc.{CapturingType, derivedCapturingType, CaptureSet, isBoxed, isBoxedCapturing}
2323
import CaptureSet.{CompareResult, IdempotentCaptRefMap, IdentityCaptRefMap}
2424

2525
import scala.annotation.internal.sharable
@@ -99,8 +99,8 @@ object TypeOps:
9999
tp match {
100100
case tp: NamedType =>
101101
val sym = tp.symbol
102-
if sym.isStatic && !sym.maybeOwner.seesOpaques then tp
103-
else if tp.prefix `eq` NoPrefix then tp
102+
if sym.isStatic && !sym.maybeOwner.seesOpaques || (tp.prefix `eq` NoPrefix)
103+
then tp
104104
else derivedSelect(tp, atVariance(variance max 0)(this(tp.prefix)))
105105
case tp: LambdaType =>
106106
mapOverLambda(tp) // special cased common case

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2931,6 +2931,7 @@ object Types {
29312931
name == nme.CAPTURE_ROOT && symbol == defn.captureRoot
29322932

29332933
def localRootOwner(using Context): Symbol =
2934+
// TODO Try to make local class roots be NonMembers owned directly by the class
29342935
val owner = symbol.maybeOwner
29352936
def normOwner = if owner.isLocalDummy then owner.owner else owner
29362937
if name == nme.LOCAL_CAPTURE_ROOT then normOwner

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import config.SourceVersion.{`3.0`, `future`}
2020
import config.Printers.refcheck
2121
import reporting._
2222
import Constants.Constant
23-
import cc.{localRoot, isCaptureChecking, isLevelOwner}
2423

2524
object RefChecks {
2625
import tpd._

0 commit comments

Comments
 (0)