Skip to content

Commit ba6e0e5

Browse files
committed
Revert all the changes that added NonNull.
1 parent 434204f commit ba6e0e5

File tree

5 files changed

+30
-65
lines changed

5 files changed

+30
-65
lines changed

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

+5-19
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,10 @@ class Definitions {
249249
*/
250250
@tu lazy val AnyClass: ClassSymbol = completeClass(enterCompleteClassSymbol(ScalaPackageClass, tpnme.Any, Abstract, Nil), ensureCtor = false)
251251
def AnyType: TypeRef = AnyClass.typeRef
252-
@tu lazy val AnyValClass: ClassSymbol = completeClass(
253-
enterCompleteClassSymbol(ScalaPackageClass, tpnme.AnyVal, Abstract,
254-
List(AnyClass.typeRef, NotNullClass.typeRef)))
252+
@tu lazy val AnyValClass: ClassSymbol = completeClass(enterCompleteClassSymbol(ScalaPackageClass, tpnme.AnyVal, Abstract, List(AnyClass.typeRef)))
255253
def AnyValType: TypeRef = AnyValClass.typeRef
256254

257-
@tu lazy val Any_== : TermSymbol = enterMethod(AnyClass, nme.EQ, methOfAny(BooleanType), Final)
255+
@tu lazy val Any_== : TermSymbol = enterMethod(AnyClass, nme.EQ, methOfAny(BooleanType), Final)
258256
@tu lazy val Any_!= : TermSymbol = enterMethod(AnyClass, nme.NE, methOfAny(BooleanType), Final)
259257
@tu lazy val Any_equals: TermSymbol = enterMethod(AnyClass, nme.equals_, methOfAny(BooleanType))
260258
@tu lazy val Any_hashCode: TermSymbol = enterMethod(AnyClass, nme.hashCode_, MethodType(Nil, IntType))
@@ -263,8 +261,6 @@ class Definitions {
263261
@tu lazy val Any_isInstanceOf: TermSymbol = enterT1ParameterlessMethod(AnyClass, nme.isInstanceOf_, _ => BooleanType, Final)
264262
@tu lazy val Any_asInstanceOf: TermSymbol = enterT1ParameterlessMethod(AnyClass, nme.asInstanceOf_, _.paramRefs(0), Final)
265263
@tu lazy val Any_typeTest: TermSymbol = enterT1ParameterlessMethod(AnyClass, nme.isInstanceOfPM, _ => BooleanType, Final | Synthetic | Artifact)
266-
@tu lazy val Any_notNull: TermSymbol = newSymbol(AnyClass, nme.NOT_NULL, Method | Final | Erased | Artifact| StableRealizable,
267-
AndType(AnyClass.thisType, NotNullClass.typeRef)).entered
268264
@tu lazy val Any_typeCast: TermSymbol = enterT1ParameterlessMethod(AnyClass, nme.asInstanceOfPM, _.paramRefs(0), Final | Synthetic | Artifact | StableRealizable)
269265
// generated by pattern matcher, eliminated by erasure
270266

@@ -276,16 +272,13 @@ class Definitions {
276272
Final,
277273
bounds = TypeBounds.lower(AnyClass.thisType))
278274

279-
private def AnyMethods: List[TermSymbol] = List(Any_==, Any_!=, Any_equals, Any_hashCode,
280-
Any_toString, Any_##, Any_getClass, Any_isInstanceOf, Any_asInstanceOf, Any_typeTest, Any_typeCast, Any_notNull)
281-
282-
def isAny_notNull(sym: Symbol)(given Context) = sym.name == nme.NOT_NULL && sym == Any_notNull
275+
def AnyMethods: List[TermSymbol] = List(Any_==, Any_!=, Any_equals, Any_hashCode,
276+
Any_toString, Any_##, Any_getClass, Any_isInstanceOf, Any_asInstanceOf, Any_typeTest, Any_typeCast)
283277

284278
@tu lazy val ObjectClass: ClassSymbol = {
285279
val cls = ctx.requiredClass("java.lang.Object")
286280
assert(!cls.isCompleted, "race for completing java.lang.Object")
287-
cls.info = ClassInfo(cls.owner.thisType, cls,
288-
List(AnyClass.typeRef, NotNullClass.typeRef), newScope)
281+
cls.info = ClassInfo(cls.owner.thisType, cls, AnyClass.typeRef :: Nil, newScope)
289282
cls.setFlag(NoInits | JavaDefined)
290283

291284
// The companion object doesn't really exist, so it needs to be marked as
@@ -410,11 +403,6 @@ class Definitions {
410403
List(AnyClass.typeRef), EmptyScope)
411404
@tu lazy val SingletonType: TypeRef = SingletonClass.typeRef
412405

413-
@tu lazy val NotNullClass: ClassSymbol =
414-
enterCompleteClassSymbol(
415-
ScalaPackageClass, tpnme.NotNull, PureInterfaceCreationFlags,
416-
List(AnyClass.typeRef), EmptyScope)
417-
418406
@tu lazy val CollectionSeqType: TypeRef = ctx.requiredClassRef("scala.collection.Seq")
419407
@tu lazy val SeqType: TypeRef = ctx.requiredClassRef("scala.collection.immutable.Seq")
420408
def SeqClass(given Context): ClassSymbol = SeqType.symbol.asClass
@@ -1302,7 +1290,6 @@ class Definitions {
13021290
.updated(AnyClass, ObjectClass)
13031291
.updated(AnyValClass, ObjectClass)
13041292
.updated(SingletonClass, ObjectClass)
1305-
.updated(NotNullClass, ObjectClass)
13061293
.updated(TupleClass, ObjectClass)
13071294
.updated(NonEmptyTupleClass, ProductClass)
13081295

@@ -1319,7 +1306,6 @@ class Definitions {
13191306
ByNameParamClass2x,
13201307
AnyValClass,
13211308
NullClass,
1322-
NotNullClass,
13231309
NothingClass,
13241310
SingletonClass)
13251311

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

+25-42
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
6262
private var myAnyKindClass: ClassSymbol = null
6363
private var myNothingClass: ClassSymbol = null
6464
private var myNullClass: ClassSymbol = null
65-
private var myNotNullClass: ClassSymbol = null
6665
private var myObjectClass: ClassSymbol = null
6766
private var myAnyType: TypeRef = null
6867
private var myAnyKindType: TypeRef = null
@@ -84,10 +83,6 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
8483
if (myNullClass == null) myNullClass = defn.NullClass
8584
myNullClass
8685
}
87-
def NotNullClass: ClassSymbol =
88-
if myNotNullClass == null then myNotNullClass = defn.NotNullClass
89-
myNotNullClass
90-
9186
def ObjectClass: ClassSymbol = {
9287
if (myObjectClass == null) myObjectClass = defn.ObjectClass
9388
myObjectClass
@@ -775,15 +770,6 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
775770
if (tp2a ne tp2) // Follow the alias; this might avoid truncating the search space in the either below
776771
return recur(tp1, tp2a)
777772

778-
if tp11.isRef(NotNullClass)
779-
tp12.widen match
780-
case OrNull(tp12a) if recur(tp12a, tp2) => return true
781-
case _ =>
782-
if tp12.isRef(NotNullClass)
783-
tp11.widen match
784-
case OrNull(tp11a) if recur(tp11a, tp2) => return true
785-
case _ =>
786-
787773
// Rewrite (T111 | T112) & T12 <: T2 to (T111 & T12) <: T2 and (T112 | T12) <: T2
788774
// and analogously for T11 & (T121 | T122) & T12 <: T2
789775
// `&' types to the left of <: are problematic, because
@@ -1056,7 +1042,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
10561042
*/
10571043
def isNewSubType(tp1: Type): Boolean =
10581044
if (isCovered(tp1) && isCovered(tp2))
1059-
//println(i"useless subtype: $tp1 <:< $tp2")
1045+
//println(s"useless subtype: $tp1 <:< $tp2")
10601046
false
10611047
else isSubType(tp1, tp2, approx.addLow)
10621048

@@ -1547,11 +1533,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
15471533
* combiners are AppliedTypes, RefinedTypes, RecTypes, And/Or-Types or AnnotatedTypes.
15481534
*/
15491535
private def isCovered(tp: Type): Boolean = tp.dealiasKeepRefiningAnnots.stripTypeVar match {
1550-
case tp: TypeRef =>
1551-
tp.symbol.isClass
1552-
&& tp.symbol != NothingClass
1553-
&& tp.symbol != NullClass
1554-
&& tp.symbol != NotNullClass
1536+
case tp: TypeRef => tp.symbol.isClass && tp.symbol != NothingClass && tp.symbol != NullClass
15551537
case tp: AppliedType => isCovered(tp.tycon)
15561538
case tp: RefinedOrRecType => isCovered(tp.parent)
15571539
case tp: AndType => isCovered(tp.tp1) && isCovered(tp.tp2)
@@ -1719,27 +1701,28 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
17191701
tp11 & tp2 | tp12 & tp2
17201702
case _ =>
17211703
val tp1a = dropIfSuper(tp1, tp2)
1722-
if (tp1a ne tp1) return glb(tp1a, tp2)
1723-
val tp2a = dropIfSuper(tp2, tp1)
1724-
if (tp2a ne tp2) return glb(tp1, tp2a)
1725-
tp1 match
1726-
case tp1: ConstantType =>
1727-
tp2 match
1728-
case tp2: ConstantType =>
1729-
// Make use of the fact that the intersection of two constant types
1730-
// types which are not subtypes of each other is known to be empty.
1731-
// Note: The same does not apply to singleton types in general.
1732-
// E.g. we could have a pattern match against `x.type & y.type`
1733-
// which might succeed if `x` and `y` happen to be the same ref
1734-
// at run time. It would not work to replace that with `Nothing`.
1735-
// However, maybe we can still apply the replacement to
1736-
// types which are not explicitly written.
1737-
return NothingType
1738-
case _ =>
1739-
case _ =>
1740-
if tp1.isRef(NotNullClass) && tp2.isNull then return NothingType
1741-
if tp2.isRef(NotNullClass) && tp1.isNull then return NothingType
1742-
andType(tp1, tp2)
1704+
if (tp1a ne tp1) glb(tp1a, tp2)
1705+
else {
1706+
val tp2a = dropIfSuper(tp2, tp1)
1707+
if (tp2a ne tp2) glb(tp1, tp2a)
1708+
else tp1 match {
1709+
case tp1: ConstantType =>
1710+
tp2 match {
1711+
case tp2: ConstantType =>
1712+
// Make use of the fact that the intersection of two constant types
1713+
// types which are not subtypes of each other is known to be empty.
1714+
// Note: The same does not apply to singleton types in general.
1715+
// E.g. we could have a pattern match against `x.type & y.type`
1716+
// which might succeed if `x` and `y` happen to be the same ref
1717+
// at run time. It would not work to replace that with `Nothing`.
1718+
// However, maybe we can still apply the replacement to
1719+
// types which are not explicitly written.
1720+
NothingType
1721+
case _ => andType(tp1, tp2)
1722+
}
1723+
case _ => andType(tp1, tp2)
1724+
}
1725+
}
17431726
}
17441727
}
17451728
}
@@ -1855,7 +1838,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
18551838
else if (!tp2.exists) tp1
18561839
else tp.derivedAndType(tp1, tp2)
18571840

1858-
/** If some (&-operand of) `tp` is a supertype of `sub` replace it with `NoType`.
1841+
/** If some (&-operand of) this type is a supertype of `sub` replace it with `NoType`.
18591842
*/
18601843
private def dropIfSuper(tp: Type, sub: Type): Type =
18611844
if (isSubTypeWhenFrozen(sub, tp)) NoType

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

-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ object TypeErasure {
197197
else if (sym.isAbstractType) TypeAlias(WildcardType)
198198
else if (sym.isConstructor) outer.addParam(sym.owner.asClass, erase(tp)(erasureCtx))
199199
else if (sym.is(Label)) erase.eraseResult(sym.info)(erasureCtx)
200-
else if sym.is(Erased) && defn.isAny_notNull(sym) then NoType // Q: Should we delete all erased symbols that way?
201200
else erase.eraseInfo(tp, sym)(erasureCtx) match {
202201
case einfo: MethodType =>
203202
if (sym.isGetter && einfo.resultType.isRef(defn.UnitClass))

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

-2
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,6 @@ object Erasure {
426426
* e.m -> e.[]m if `m` is an array operation other than `clone`.
427427
*/
428428
override def typedSelect(tree: untpd.Select, pt: Type)(implicit ctx: Context): Tree = {
429-
if defn.isAny_notNull(tree.symbol) then return typed(tree.qualifier, pt)
430-
431429
val qual1 = typed(tree.qualifier, AnySelectionProto)
432430

433431
def mapOwner(sym: Symbol): Symbol = {

tests/run-macros/i6518.check

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
##
33
$asInstanceOf$
44
$isInstanceOf$
5-
$nn
65
==
76
andThen
87
apply

0 commit comments

Comments
 (0)