Skip to content

Commit 2384348

Browse files
committed
Remove ErasedPhantom class and use Unit.
1 parent 11420cf commit 2384348

File tree

7 files changed

+12
-27
lines changed

7 files changed

+12
-27
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ class Definitions {
979979
lazy val PhantomNothingClass = PhantomClass.unforcedDecls.find(_.name eq tpnme.Nothing).asClass
980980
lazy val PhantomAssume = PhantomClass.unforcedDecls.find(_.name eq nme.assume_)
981981

982-
lazy val ErasedPhantomClass = ctx.requiredClass("dotty.runtime.ErasedPhantom")
983-
def ErasedPhantomType(implicit ctx: Context) = ErasedPhantomClass.typeRef
982+
/** If the symbol is of the class scala.Phantom.Any or scala.Phantom.Nothing */
983+
def isPhantomClass(sym: Symbol) = (sym eq PhantomAnyClass) || (sym eq PhantomNothingClass)
984984

985985
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -652,10 +652,8 @@ object SymDenotations {
652652
}
653653

654654
/** Is this symbol a class references to which that are supertypes of null? */
655-
final def isNullableClass(implicit ctx: Context): Boolean = {
656-
isClass && !isValueClass && !(this is ModuleClass) &&
657-
symbol != defn.NothingClass && symbol != defn.PhantomAnyClass && symbol != defn.PhantomNothingClass
658-
}
655+
final def isNullableClass(implicit ctx: Context): Boolean =
656+
isClass && !isValueClass && !(this is ModuleClass) && symbol != defn.NothingClass && !defn.isPhantomClass(symbol)
659657

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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean
364364
else if (semiEraseVCs && isDerivedValueClass(sym)) eraseDerivedValueClassRef(tp)
365365
else if (sym == defn.ArrayClass) apply(tp.appliedTo(TypeBounds.empty)) // i966 shows that we can hit a raw Array type.
366366
else if (defn.isSyntheticFunctionClass(sym)) defn.erasedFunctionType(sym)
367-
else if ((tp.symbol eq defn.PhantomAnyClass) || (tp.symbol eq defn.PhantomNothingClass)) defn.ErasedPhantomType
367+
else if (defn.isPhantomClass(tp.symbol)) defn.BoxedUnitType
368368
else eraseNormalClassRef(tp)
369369
case tp: RefinedType =>
370370
val parent = tp.parent
@@ -507,8 +507,8 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean
507507
}
508508
if (defn.isSyntheticFunctionClass(sym))
509509
sigName(defn.erasedFunctionType(sym))
510-
else if ((tp.symbol eq defn.PhantomAnyClass) || (tp.symbol eq defn.PhantomNothingClass))
511-
sigName(defn.ErasedPhantomType)
510+
else if (defn.isPhantomClass(tp.symbol))
511+
sigName(defn.BoxedUnitType)
512512
else
513513
normalizeClass(sym.asClass).fullName.asTypeName
514514
case defn.ArrayOf(elem) =>

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,12 @@ object Types {
200200
* - NoType otherwise
201201
*/
202202
final def phantomLatticeType(implicit ctx: Context): Type = widen match {
203-
case tp: ClassInfo if isPhantomClass(tp.classSymbol) => tp.prefix
203+
case tp: ClassInfo if defn.isPhantomClass(tp.classSymbol) => tp.prefix
204204
case tp: TypeProxy if tp.superType ne this => tp.superType.phantomLatticeType
205205
case tp: AndOrType => tp.tp1.phantomLatticeType
206206
case _ => NoType
207207
}
208208

209-
/** If the symbol is of the class scala.Phantom.Any or scala.Phantom.Nothing */
210-
private def isPhantomClass(sym: Symbol)(implicit ctx: Context): Boolean =
211-
(sym eq defn.PhantomAnyClass) || (sym eq defn.PhantomNothingClass)
212-
213209
/** Is this type guaranteed not to have `null` as a value?
214210
* For the moment this is only true for modules, but it could
215211
* be refined later.

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -454,14 +454,9 @@ object Erasure extends TypeTestsCasts{
454454
val Apply(fun, args) = tree
455455
if (fun.symbol == defn.dummyApply)
456456
typedUnadapted(args.head, pt)
457-
else if (fun.symbol eq defn.PhantomAssume) {
458-
/* All phantom types are erased to `ErasedPhantom` (an un-instantiable final abstract class),
459-
* hence the only valid term for a `ErasedPhantom` is `null`.
460-
* As `Phantom.assume` is the only way to instantiate phantoms, all runtime values of
461-
* phantom type become `null` (no instantiation overhead).
462-
*/
463-
Literal(Constant(null)).withType(defn.ErasedPhantomType)
464-
} else typedExpr(fun, FunProto(args, pt, this)) match {
457+
else if (fun.symbol eq defn.PhantomAssume)
458+
ref(defn.BoxedUnit_UNIT)
459+
else typedExpr(fun, FunProto(args, pt, this)) match {
465460
case fun1: Apply => // arguments passed in prototype were already passed
466461
fun1
467462
case fun1 =>

library/src/dotty/runtime/ErasedPhantom.scala

Lines changed: 0 additions & 3 deletions
This file was deleted.

library/src/scala/Phantom.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ trait Phantom {
77
88
protected final abstract class Nothing extends Any
99
10-
protected final def assume: this.Nothing =
11-
null.asInstanceOf[this.Nothing] // This implementation matches the erased implementation
10+
protected final def assume: this.Nothing
1211
}
1312
*/

0 commit comments

Comments
 (0)