Skip to content

Commit 9bd3c16

Browse files
committed
Replace phantomTop by general top type.
1 parent 4954a54 commit 9bd3c16

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
@@ -989,16 +989,6 @@ class Definitions {
989989
def isPhantomAssume(sym: Symbol)(implicit ctx: Context): Boolean =
990990
sym.name == nme.assume_ && (sym.owner eq PhantomClass)
991991

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

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

@@ -3258,8 +3274,8 @@ object Types {
32583274
/** Type bounds >: lo <: hi */
32593275
abstract case class TypeBounds(lo: Type, hi: Type) extends CachedProxyType with TypeType {
32603276

3261-
assert(lo.isInstanceOf[TermType])
3262-
assert(hi.isInstanceOf[TermType])
3277+
assert(lo.isInstanceOf[TermType], lo)
3278+
assert(hi.isInstanceOf[TermType], hi)
32633279

32643280
def variance: Int = 0
32653281

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

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

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

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

0 commit comments

Comments
 (0)