Skip to content

Commit 3aaac8d

Browse files
committed
Remove scala.Phantom
1 parent b567b8d commit 3aaac8d

File tree

127 files changed

+54
-1933
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+54
-1933
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,6 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
442442
else if (tpw isRef defn.DoubleClass) Literal(Constant(0d))
443443
else if (tpw isRef defn.ByteClass) Literal(Constant(0.toByte))
444444
else if (tpw isRef defn.ShortClass) Literal(Constant(0.toShort))
445-
else if (tpw.isPhantom) Literal(Constant(null)).withType(tpw)
446445
else Literal(Constant(null)).select(defn.Any_asInstanceOf).appliedToType(tpe)
447446
}
448447

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

+1-20
Original file line numberDiff line numberDiff line change
@@ -1161,8 +1161,7 @@ class Definitions {
11611161
NullClass,
11621162
NothingClass,
11631163
SingletonClass,
1164-
EqualsPatternClass,
1165-
PhantomClass)
1164+
EqualsPatternClass)
11661165

11671166
lazy val syntheticCoreClasses = syntheticScalaClasses ++ List(
11681167
EmptyPackageVal,
@@ -1191,22 +1190,4 @@ class Definitions {
11911190
}
11921191
}
11931192

1194-
// ----- Phantoms ---------------------------------------------------------
1195-
1196-
lazy val PhantomClass: ClassSymbol = {
1197-
val cls = completeClass(enterCompleteClassSymbol(ScalaPackageClass, tpnme.Phantom, NoInitsTrait, List(AnyType)))
1198-
1199-
val any = enterCompleteClassSymbol(cls, tpnme.Any, Protected | Final | NoInitsTrait, Nil)
1200-
val nothing = enterCompleteClassSymbol(cls, tpnme.Nothing, Protected | Final | NoInitsTrait, List(any.typeRef))
1201-
enterMethod(cls, nme.assume_, ExprType(nothing.typeRef), Protected | Final | Method | Unused)
1202-
1203-
cls
1204-
}
1205-
lazy val Phantom_AnyClass = PhantomClass.unforcedDecls.find(_.name eq tpnme.Any).asClass
1206-
lazy val Phantom_NothingClass = PhantomClass.unforcedDecls.find(_.name eq tpnme.Nothing).asClass
1207-
1208-
/** If the symbol is of the class scala.Phantom.Any or scala.Phantom.Nothing */
1209-
def isPhantomTerminalClass(sym: Symbol) = (sym eq Phantom_AnyClass) || (sym eq Phantom_NothingClass)
1210-
1211-
lazy val ErasedPhantomType: TypeRef = ctx.requiredClassRef("dotty.runtime.ErasedPhantom")
12121193
}

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

-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ object StdNames {
241241
final val SourceFileATTR: N = "SourceFile"
242242
final val SyntheticATTR: N = "Synthetic"
243243

244-
final val Phantom: N = "Phantom"
245244

246245
// ----- Term names -----------------------------------------
247246

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ object SymDenotations {
667667

668668
/** Is this symbol a class references to which that are supertypes of null? */
669669
final def isNullableClass(implicit ctx: Context): Boolean =
670-
isClass && !isValueClass && !(this is ModuleClass) && symbol != defn.NothingClass && !defn.isPhantomTerminalClass(symbol)
670+
isClass && !isValueClass && !(this is ModuleClass) && symbol != defn.NothingClass
671671

672672
/** Is this definition accessible as a member of tree with type `pre`?
673673
* @param pre The type of the tree from which the selection is made

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

+3-9
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
5050
private[this] var myAnyClass: ClassSymbol = null
5151
private[this] var myNothingClass: ClassSymbol = null
5252
private[this] var myNullClass: ClassSymbol = null
53-
private[this] var myPhantomNothingClass: ClassSymbol = null
5453
private[this] var myObjectClass: ClassSymbol = null
5554
private[this] var myAnyType: TypeRef = null
5655
private[this] var myNothingType: TypeRef = null
@@ -67,10 +66,6 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
6766
if (myNullClass == null) myNullClass = defn.NullClass
6867
myNullClass
6968
}
70-
def PhantomNothingClass = {
71-
if (myPhantomNothingClass == null) myPhantomNothingClass = defn.Phantom_NothingClass
72-
myPhantomNothingClass
73-
}
7469
def ObjectClass = {
7570
if (myObjectClass == null) myObjectClass = defn.ObjectClass
7671
myObjectClass
@@ -287,7 +282,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
287282
if (recur(info1.alias, tp2)) return true
288283
if (tp1.prefix.isStable) return false
289284
case _ =>
290-
if (tp1 eq NothingType) return tp1 == tp2.bottomType
285+
if (tp1 eq NothingType) return true
291286
}
292287
thirdTry
293288
case tp1: TypeParamRef =>
@@ -586,9 +581,8 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
586581
case _ => false
587582
}
588583
val sym1 = tp1.symbol
589-
(sym1 eq NothingClass) && tp2.isValueTypeOrLambda && !tp2.isPhantom ||
590-
(sym1 eq NullClass) && isNullable(tp2) ||
591-
(sym1 eq PhantomNothingClass) && tp1.topType == tp2.topType
584+
(sym1 eq NothingClass) && tp2.isValueTypeOrLambda ||
585+
(sym1 eq NullClass) && isNullable(tp2)
592586
}
593587
case tp1 @ AppliedType(tycon1, args1) =>
594588
compareAppliedType1(tp1, tycon1, args1)

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

-2
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,6 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean
380380
else if (semiEraseVCs && isDerivedValueClass(sym)) eraseDerivedValueClassRef(tp)
381381
else if (sym == defn.ArrayClass) apply(tp.appliedTo(TypeBounds.empty)) // i966 shows that we can hit a raw Array type.
382382
else if (defn.isSyntheticFunctionClass(sym)) defn.erasedFunctionType(sym)
383-
else if (defn.isPhantomTerminalClass(sym)) defn.ErasedPhantomType
384-
else if (sym eq defn.PhantomClass) defn.ObjectType // To erase the definitions of Phantom.{assume, Any, Nothing}
385383
else eraseNormalClassRef(tp)
386384
case tp: AppliedType =>
387385
if (tp.tycon.isRef(defn.ArrayClass)) eraseArray(tp)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
4242
case pre: SuperType => toPrefix(pre.thistpe, cls, thiscls)
4343
case _ =>
4444
if (thiscls.derivesFrom(cls) && pre.baseType(thiscls).exists)
45-
if (variance <= 0 && !isLegalPrefix(pre)) range(pre.bottomType, pre)
45+
if (variance <= 0 && !isLegalPrefix(pre)) range(defn.NothingType, pre)
4646
else pre
4747
else if ((pre.termSymbol is Package) && !(thiscls is Package))
4848
toPrefix(pre.select(nme.PACKAGE), cls, thiscls)

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

+6-47
Original file line numberDiff line numberDiff line change
@@ -193,59 +193,18 @@ object Types {
193193
}
194194
}
195195

196-
/** Returns true if the type is a phantom type
197-
* - true if XYZ extends scala.Phantom and this type is upper bounded XYZ.Any
198-
* - false otherwise
199-
*/
200-
final def isPhantom(implicit ctx: Context): Boolean = phantomLatticeType.exists
201-
202-
/** Returns the top type of the lattice
203-
* - XYX.Any if XYZ extends scala.Phantom and this type is upper bounded XYZ.Any
204-
* - scala.Any otherwise
205-
*/
206-
final def topType(implicit ctx: Context): Type = {
207-
val lattice = phantomLatticeType
208-
if (lattice.exists) lattice.select(tpnme.Any)
209-
else defn.AnyType
210-
}
211-
212-
/** Returns the bottom type of the lattice
213-
* - XYZ.Nothing if XYZ extends scala.Phantom and this type is upper bounded XYZ.Any
214-
* - scala.Nothing otherwise
215-
*/
216-
final def bottomType(implicit ctx: Context): Type = {
217-
val lattice = phantomLatticeType
218-
if (lattice.exists) lattice.select(tpnme.Nothing)
219-
else defn.NothingType
220-
}
221-
222196
/** Is this type exactly Nothing (no vars, aliases, refinements etc allowed)? */
223197
def isBottomType(implicit ctx: Context): Boolean = this match {
224-
case tp: TypeRef =>
225-
val sym = tp.symbol
226-
(sym eq defn.NothingClass) || (sym eq defn.Phantom_NothingClass)
198+
case tp: TypeRef => tp.symbol eq defn.NothingClass
227199
case _ => false
228200
}
229201

230202
/** Is this type exactly Any (no vars, aliases, refinements etc allowed)? */
231203
def isTopType(implicit ctx: Context): Boolean = this match {
232-
case tp: TypeRef =>
233-
val sym = tp.symbol
234-
(sym eq defn.AnyClass) || (sym eq defn.Phantom_AnyClass)
204+
case tp: TypeRef => tp.symbol eq defn.AnyClass
235205
case _ => false
236206
}
237207

238-
/** Returns the type of the phantom lattice (i.e. the prefix of the phantom type)
239-
* - XYZ if XYZ extends scala.Phantom and this type is upper bounded XYZ.Any
240-
* - NoType otherwise
241-
*/
242-
private final def phantomLatticeType(implicit ctx: Context): Type = widen match {
243-
case tp: ClassInfo if defn.isPhantomTerminalClass(tp.classSymbol) => tp.prefix
244-
case tp: TypeProxy => tp.underlying.phantomLatticeType
245-
case tp: AndOrType => tp.tp1.phantomLatticeType
246-
case _ => NoType
247-
}
248-
249208
/** Is this type a (possibly aliased) singleton type? */
250209
def isSingleton(implicit ctx: Context) = dealias.isInstanceOf[SingletonType]
251210

@@ -2860,7 +2819,7 @@ object Types {
28602819
val dropDependencies = new ApproximatingTypeMap {
28612820
def apply(tp: Type) = tp match {
28622821
case tp @ TermParamRef(thisLambdaType, _) =>
2863-
range(tp.bottomType, atVariance(1)(apply(tp.underlying)))
2822+
range(defn.NothingType, atVariance(1)(apply(tp.underlying)))
28642823
case _ => mapOver(tp)
28652824
}
28662825
}
@@ -4177,7 +4136,7 @@ object Types {
41774136
case Range(infoLo: TypeBounds, infoHi: TypeBounds) =>
41784137
assert(variance == 0)
41794138
if (!infoLo.isAlias && !infoHi.isAlias) propagate(infoLo, infoHi)
4180-
else range(tp.bottomType, tp.parent)
4139+
else range(defn.NothingType, tp.parent)
41814140
case Range(infoLo, infoHi) =>
41824141
propagate(infoLo, infoHi)
41834142
case _ =>
@@ -4209,7 +4168,7 @@ object Types {
42094168
else tp.derivedTypeBounds(lo, hi)
42104169

42114170
override protected def derivedSuperType(tp: SuperType, thistp: Type, supertp: Type) =
4212-
if (isRange(thistp) || isRange(supertp)) range(thistp.bottomType, thistp.topType)
4171+
if (isRange(thistp) || isRange(supertp)) range(defn.NothingType, defn.AnyType)
42134172
else tp.derivedSuperType(thistp, supertp)
42144173

42154174
override protected def derivedAppliedType(tp: AppliedType, tycon: Type, args: List[Type]): Type =
@@ -4246,7 +4205,7 @@ object Types {
42464205
if (distributeArgs(args, tp.typeParams))
42474206
range(tp.derivedAppliedType(tycon, loBuf.toList),
42484207
tp.derivedAppliedType(tycon, hiBuf.toList))
4249-
else range(tp.bottomType, tp.topType)
4208+
else range(defn.NothingType, defn.AnyType)
42504209
// TODO: can we give a better bound than `topType`?
42514210
}
42524211
}

compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala

+1-3
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,6 @@ object GenericSignatures {
212212
else
213213
jsig(unboxedSeen, toplevel, primitiveOK)
214214
}
215-
else if (tp.isPhantom)
216-
jsig(defn.ErasedPhantomType)
217215
else if (sym.isClass)
218216
classSig
219217
else
@@ -242,7 +240,7 @@ object GenericSignatures {
242240
// unused method parameters do not make it to the bytecode.
243241
def effectiveParamInfoss(t: Type)(implicit ctx: Context): List[List[Type]] = t match {
244242
case t: MethodType if t.isUnusedMethod => effectiveParamInfoss(t.resType)
245-
case t: MethodType => t.paramInfos.filterNot(_.isPhantom) :: effectiveParamInfoss(t.resType)
243+
case t: MethodType => t.paramInfos :: effectiveParamInfoss(t.resType)
246244
case _ => Nil
247245
}
248246
val params = effectiveParamInfoss(mtpe).flatten

compiler/src/dotty/tools/dotc/transform/PhantomArgLift.scala

-69
This file was deleted.

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

-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ object ErrorReporting {
121121
val expected1 = dropJavaMethod(expected)
122122
if ((found1 eq found) != (expected eq expected1) && (found1 <:< expected1))
123123
"\n(Note that Scala's and Java's representation of this type differs)"
124-
else if (found.topType != expected.topType)
125-
"\n(Note that the types are in different universes, see Phantom types)"
126124
else if (ctx.settings.explainTypes.value)
127125
"\n" + ctx.typerState.show + "\n" + TypeComparer.explained((found <:< expected)(_))
128126
else

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ class Namer { typer: Typer =>
11201120
val deskolemize = new ApproximatingTypeMap {
11211121
def apply(tp: Type) = /*trace(i"deskolemize($tp) at $variance", show = true)*/ {
11221122
tp match {
1123-
case tp: SkolemType => range(tp.bottomType, atVariance(1)(apply(tp.info)))
1123+
case tp: SkolemType => range(defn.NothingType, atVariance(1)(apply(tp.info)))
11241124
case _ => mapOver(tp)
11251125
}
11261126
}

0 commit comments

Comments
 (0)