Skip to content

Commit d4da0b1

Browse files
committed
Remove PhantomTypeErasure and integrate into Erasure.
1 parent 44f9952 commit d4da0b1

File tree

7 files changed

+19
-78
lines changed

7 files changed

+19
-78
lines changed

compiler/src/dotty/tools/dotc/Compiler.scala

-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import typer.{FrontEnd, Typer, ImportInfo, RefChecks}
1111
import reporting.{Reporter, ConsoleReporter}
1212
import Phases.Phase
1313
import transform._
14-
import transform.phantom._
1514
import util.FreshNameCreator
1615
import transform.TreeTransforms.{TreeTransform, TreeTransformer}
1716
import core.DenotTransformers.DenotTransformer
@@ -75,7 +74,6 @@ class Compiler {
7574
new ResolveSuper, // Implement super accessors and add forwarders to trait methods
7675
new PrimitiveForwarders, // Add forwarders to trait methods that have a mismatch between generic and primitives
7776
new ArrayConstructors), // Intercept creation of (non-generic) arrays and intrinsify.
78-
List(new PhantomTypeErasure), // Erases phantom types to ErasedPhantom
7977
List(new Erasure), // Rewrite types to JVM model, erasing all type parameters, abstract types and refinements.
8078
List(new ElimErasedValueType, // Expand erased value types to their underlying implmementation types
8179
new VCElideAllocations, // Peep-hole optimization to eliminate unnecessary value class allocations

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -1017,8 +1017,6 @@ class Definitions {
10171017
sym.name == nme.assume_ && (sym.owner eq PhantomClass)
10181018

10191019
lazy val ErasedPhantomClass = ctx.requiredClass("dotty.runtime.ErasedPhantom")
1020-
def ErasedPhantomType = ErasedPhantomClass.typeRef
1020+
def ErasedPhantomType(implicit ctx: Context) = ErasedPhantomClass.typeRef
10211021

1022-
lazy val ErasedPhantomLatticeClass = ctx.requiredClass("dotty.runtime.ErasedPhantomLattice")
1023-
def ErasedPhantomLatticeType = ErasedPhantomLatticeClass.typeRef
10241022
}

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -364,6 +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 (defn.isPhantomAnyClass(tp.symbol) || defn.isPhantomNothingClass(tp.symbol)) defn.ErasedPhantomType
367368
else eraseNormalClassRef(tp)
368369
case tp: RefinedType =>
369370
val parent = tp.parent
@@ -400,8 +401,8 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean
400401
else classParents.mapConserve(eraseTypeRef) match {
401402
case tr :: trs1 =>
402403
assert(!tr.classSymbol.is(Trait), cls)
403-
val tr1 = if (cls is Trait) defn.ObjectType else tr
404-
tr1 :: trs1.filterNot(_ isRef defn.ObjectClass)
404+
val tr1 = if (cls.is(Trait) || (tr.symbol eq defn.PhantomClass)) defn.ObjectType else tr
405+
tr1 :: trs1.filterNot(x => x.isRef(defn.ObjectClass) || x.isRef(defn.PhantomClass))
405406
case nil => nil
406407
}
407408
val erasedDecls = decls.filteredScope(sym => !sym.isType || sym.isClass)
@@ -504,6 +505,8 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean
504505
}
505506
if (defn.isSyntheticFunctionClass(sym))
506507
sigName(defn.erasedFunctionType(sym))
508+
else if (defn.isPhantomAnyClass(tp.symbol) || defn.isPhantomNothingClass(tp.symbol))
509+
sigName(defn.ErasedPhantomType)
507510
else
508511
normalizeClass(sym.asClass).fullName.asTypeName
509512
case defn.ArrayOf(elem) =>

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,8 @@ object Erasure extends TypeTestsCasts{
433433
override def typedTypeApply(tree: untpd.TypeApply, pt: Type)(implicit ctx: Context) = {
434434
val ntree = interceptTypeApply(tree.asInstanceOf[TypeApply])(ctx.withPhase(ctx.erasurePhase))
435435

436-
ntree match {
436+
if (defn.isPhantomAssume(tree.fun.symbol)) Literal(Constant(null)).withType(defn.ErasedPhantomType)
437+
else ntree match {
437438
case TypeApply(fun, args) =>
438439
val fun1 = typedExpr(fun, WildcardType)
439440
fun1.tpe.widen match {

compiler/src/dotty/tools/dotc/transform/phantom/PhantomTypeErasure.scala

-56
This file was deleted.

library/src/dotty/runtime/ErasedPhantomLattice.scala

-3
This file was deleted.

tests/neg/phantom-overload.scala

+11-11
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
class phantomOverload {
33
import Boo._
44
import Boo2._
5+
/* TODO
6+
def foo1(): A = nothing
7+
def foo1(): B = nothing
8+
def foo1(): C = nothing
9+
def foo1(): N = nothing
510
6-
def foo1(): A = nothing // error
7-
def foo1(): B = nothing // error
8-
def foo1(): C = nothing // error
9-
def foo1(): N = nothing // error
10-
11-
def foo2(x: A) = ??? // error
12-
def foo2(x: A) = ??? // error
13-
def foo2(x: B) = ??? // error
14-
def foo2(x: C) = ??? // error
15-
def foo2(x: N) = ??? // error
16-
11+
def foo2(x: A) = ???
12+
def foo2(x: A) = ???
13+
def foo2(x: B) = ???
14+
def foo2(x: C) = ???
15+
def foo2(x: N) = ???
16+
*/
1717
}
1818

1919
object Boo extends Phantom {

0 commit comments

Comments
 (0)