Skip to content

Commit 68e5486

Browse files
committed
Replace phantomTop by general top type.
1 parent 6857a6d commit 68e5486

File tree

4 files changed

+28
-22
lines changed

4 files changed

+28
-22
lines changed

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -990,16 +990,6 @@ class Definitions {
990990
def isPhantomAssume(sym: Symbol)(implicit ctx: Context): Boolean =
991991
sym.name == nme.assume_ && (sym.owner eq PhantomClass)
992992

993-
def topOf(tp: Type)(implicit ctx: Context): Type = tp.phantomTopClass match {
994-
case top: ClassInfo => top.prefix.select(tpnme.Any)
995-
case _ => defn.AnyType
996-
}
997-
998-
def bottomOf(tp: Type)(implicit ctx: Context): Type = tp.phantomTopClass match {
999-
case top: ClassInfo => top.prefix.select(tpnme.Nothing)
1000-
case _ => defn.NothingType
1001-
}
1002-
1003993
lazy val ErasedPhantomClass = ctx.requiredClass("dotty.runtime.ErasedPhantom")
1004994
def ErasedPhantomType = ErasedPhantomClass.typeRef
1005995

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
559559
}
560560
if (tp1.symbol eq NothingClass) tp2.isValueTypeOrLambda && !isPhantom(tp2)
561561
else if (tp1.symbol eq NullClass) isNullable(tp2) && !isPhantom(tp2)
562-
else if (defn.isPhantomNothingClass(tp1.symbol)) tp2.isValueTypeOrLambda && (tp1.phantomTopClass == tp2.phantomTopClass)
562+
else if (defn.isPhantomNothingClass(tp1.symbol)) tp2.isValueTypeOrLambda && (tp1.topType == tp2.topType)
563563
else false
564564
}
565565
case tp1: SingletonType =>

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

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,31 @@ object Types {
175175
loop(this)
176176
}
177177

178-
final def isPhantom(implicit ctx: Context): Boolean = phantomTopClass.exists
178+
/** Is phantom if upper bounded by XYZ.Any where XYZ extends scala.Phantom */
179+
final def isPhantom(implicit ctx: Context): Boolean = isPhantomClass(topType.classSymbol)
179180

180-
final def phantomTopClass(implicit ctx: Context): Type = this match {
181-
case tp: ClassInfo if isPhantomClass(tp.classSymbol) => tp
182-
case tp: TypeProxy => tp.superType.phantomTopClass
183-
case tp: AndOrType => tp.tp1.phantomTopClass
184-
case _ => NoType
181+
/** Returns the top type of the lattice
182+
* - XYX.Any if XYZ extends scala.Phantom and this type is upper bounded XYZ.Any
183+
* - scala.Any otherwise
184+
*/
185+
final def topType(implicit ctx: Context): TypeRef = this match {
186+
case tp: ClassInfo if isPhantomClass(tp.classSymbol) => tp.prefix.select(tpnme.Any).asInstanceOf[TypeRef]
187+
case tp: TypeProxy => tp.superType.topType
188+
case tp: AndOrType => tp.tp1.topType
189+
case _ => defn.AnyType
190+
}
191+
192+
/** Returns the bottom type of the lattice
193+
* - XYZ.Nothing if XYZ extends scala.Phantom and this type is upper bounded XYZ.Any
194+
* - scala.Nothing otherwise
195+
*/
196+
final def bottomType(implicit ctx: Context): Type = topType match {
197+
case top: TypeRef if top.prefix.termSymbol ne defn.ScalaPackageVal =>
198+
top.prefix.select(tpnme.Nothing)
199+
case _ => defn.NothingType
185200
}
186201

202+
/** If the symbol is of the class scala.Phantom.Any or scala.Phantom.Nothing */
187203
private def isPhantomClass(sym: Symbol)(implicit ctx: Context): Boolean =
188204
sym.isClass && (sym.owner eq defn.PhantomClass)
189205

@@ -3287,8 +3303,8 @@ object Types {
32873303
/** Type bounds >: lo <: hi */
32883304
abstract case class TypeBounds(lo: Type, hi: Type) extends CachedProxyType with TypeType {
32893305

3290-
assert(lo.isInstanceOf[TermType])
3291-
assert(hi.isInstanceOf[TermType])
3306+
assert(lo.isInstanceOf[TermType], lo)
3307+
assert(hi.isInstanceOf[TermType], hi)
32923308

32933309
def variance: Int = 0
32943310

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,8 +1136,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
11361136
val lo1 = typed(lo)
11371137
val hi1 = typed(hi)
11381138

1139-
val lo2 = if (!lo1.isEmpty) lo1 else typed(untpd.TypeTree(defn.bottomOf(hi1.typeOpt)))
1140-
val hi2 = if (!hi1.isEmpty) hi1 else typed(untpd.TypeTree(defn.topOf(lo1.typeOpt)))
1139+
val lo2 = if (!lo1.isEmpty) lo1 else typed(untpd.TypeTree(hi1.typeOpt.bottomType))
1140+
val hi2 = if (!hi1.isEmpty) hi1 else typed(untpd.TypeTree(lo1.typeOpt.topType))
11411141

11421142
val tree1 = assignType(cpy.TypeBoundsTree(tree)(lo2, hi2), lo2, hi2)
11431143
if (ctx.mode.is(Mode.Pattern)) {
@@ -1685,7 +1685,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
16851685
case untpd.InfixOp(left, op, right) =>
16861686
checkedTops2(left, right, PhantomCrossedMixedBounds(left, right), tree.pos)
16871687
case EmptyTree => Set.empty
1688-
case _ => Set(defn.topOf(tree.typeOpt))
1688+
case _ => Set(tree.typeOpt.topType)
16891689
}
16901690
}
16911691
checkedTops(tree)

0 commit comments

Comments
 (0)