Skip to content

Commit a26a309

Browse files
committed
Drop UnsafeNonvariant
It's no longer needed.
1 parent 91ee02f commit a26a309

File tree

5 files changed

+9
-61
lines changed

5 files changed

+9
-61
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,8 +657,6 @@ class Definitions {
657657
def UncheckedStableAnnot(implicit ctx: Context) = UncheckedStableAnnotType.symbol.asClass
658658
lazy val UncheckedVarianceAnnotType = ctx.requiredClassRef("scala.annotation.unchecked.uncheckedVariance")
659659
def UncheckedVarianceAnnot(implicit ctx: Context) = UncheckedVarianceAnnotType.symbol.asClass
660-
lazy val UnsafeNonvariantAnnotType = ctx.requiredClassRef("scala.annotation.internal.UnsafeNonvariant")
661-
def UnsafeNonvariantAnnot(implicit ctx: Context) = UnsafeNonvariantAnnotType.symbol.asClass
662660
lazy val VolatileAnnotType = ctx.requiredClassRef("scala.volatile")
663661
def VolatileAnnot(implicit ctx: Context) = VolatileAnnotType.symbol.asClass
664662
lazy val FieldMetaAnnotType = ctx.requiredClassRef("scala.annotation.meta.field")

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

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,14 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
5151

5252
/*>|>*/ ctx.conditionalTraceIndented(TypeOps.track, s"asSeen ${tp.show} from (${pre.show}, ${cls.show})", show = true) /*<|<*/ { // !!! DEBUG
5353
tp match {
54-
case tp: NamedType =>
55-
val sym = tp.symbol
56-
if (sym.isStatic) tp
54+
case tp: NamedType => // inlined for performance; TODO: factor out into inline method
55+
if (tp.symbol.isStatic) tp
5756
else {
58-
val pre1 = apply(tp.prefix)
59-
if (pre1.isUnsafeNonvariant) {
60-
val safeCtx = ctx.withProperty(TypeOps.findMemberLimit, Some(()))
61-
pre1.member(tp.name)(safeCtx).info match {
62-
case TypeAlias(alias) =>
63-
// try to follow aliases of this will avoid skolemization.
64-
return alias
65-
case _ =>
66-
}
67-
}
68-
derivedSelect(tp, pre1)
57+
val saved = variance
58+
variance = variance max 0
59+
val prefix1 = this(tp.prefix)
60+
variance = saved
61+
derivedSelect(tp, prefix1)
6962
}
7063
case tp: ThisType =>
7164
toPrefix(pre, cls, tp.cls)

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -255,16 +255,6 @@ object Types {
255255
def isRepeatedParam(implicit ctx: Context): Boolean =
256256
typeSymbol eq defn.RepeatedParamClass
257257

258-
/** Does this type carry an UnsafeNonvariant annotation? */
259-
final def isUnsafeNonvariant(implicit ctx: Context): Boolean = this match {
260-
case AnnotatedType(_, annot) => annot.symbol == defn.UnsafeNonvariantAnnot
261-
case _ => false
262-
}
263-
264-
/** Does this type have an UnsafeNonvariant annotation on one of its parts? */
265-
final def hasUnsafeNonvariant(implicit ctx: Context): Boolean =
266-
new HasUnsafeNonAccumulator().apply(false, this)
267-
268258
/** Is this the type of a method that has a repeated parameter type as
269259
* last parameter type?
270260
*/
@@ -4175,10 +4165,6 @@ object Types {
41754165
def apply(x: Unit, tp: Type): Unit = foldOver(p(tp), tp)
41764166
}
41774167

4178-
class HasUnsafeNonAccumulator(implicit ctx: Context) extends TypeAccumulator[Boolean] {
4179-
def apply(x: Boolean, tp: Type) = x || tp.isUnsafeNonvariant || foldOver(x, tp)
4180-
}
4181-
41824168
class NamedPartsAccumulator(p: NamedType => Boolean, excludeLowerBounds: Boolean = false)
41834169
(implicit ctx: Context) extends TypeAccumulator[mutable.Set[NamedType]] {
41844170
override def stopAtStatic = false

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

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -386,27 +386,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
386386
}
387387

388388
private def typedSelect(tree: untpd.Select, pt: Type, qual: Tree)(implicit ctx: Context): Select =
389-
healNonvariant(
390-
checkValue(assignType(cpy.Select(tree)(qual, tree.name), qual), pt),
391-
pt)
392-
393-
/** Let `tree = p.n` where `p: T`. If tree's type is an unsafe instantiation
394-
* (see TypeOps#asSeenFrom for how this can happen), rewrite the prefix `p`
395-
* to `(p: <unknown skolem of type T>)` and try again with the new (stable)
396-
* prefix. If the result has another unsafe instantiation, raise an error.
397-
*/
398-
private def healNonvariant[T <: Tree](tree: T, pt: Type)(implicit ctx: Context): T =
399-
if (ctx.unsafeNonvariant == ctx.runId && tree.tpe.widen.hasUnsafeNonvariant)
400-
tree match {
401-
case tree @ Select(qual, _) if !qual.tpe.isStable =>
402-
val alt = typedSelect(tree, pt, Typed(qual, TypeTree(SkolemType(qual.tpe.widen))))
403-
typr.println(i"healed type: ${tree.tpe} --> $alt")
404-
alt.asInstanceOf[T]
405-
case _ =>
406-
ctx.error(ex"unsafe instantiation of type ${tree.tpe}", tree.pos)
407-
tree
408-
}
409-
else tree
389+
checkValue(assignType(cpy.Select(tree)(qual, tree.name), qual), pt)
410390

411391
def typedSelect(tree: untpd.Select, pt: Type)(implicit ctx: Context): Tree = track("typedSelect") {
412392
def typeSelectOnTerm(implicit ctx: Context): Tree = {
@@ -616,8 +596,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
616596
case lhsCore: RefTree if setter.exists =>
617597
val setterTypeRaw = pre.select(setterName, setter)
618598
val setterType = ensureAccessible(setterTypeRaw, isSuperSelection(lhsCore), tree.pos)
619-
val lhs2 = healNonvariant(
620-
untpd.rename(lhsCore, setterName).withType(setterType), WildcardType)
599+
val lhs2 = untpd.rename(lhsCore, setterName).withType(setterType)
621600
typedUnadapted(untpd.Apply(untpd.TypedSplice(lhs2), tree.rhs :: Nil))
622601
case _ =>
623602
reassignmentToVal

library/src/scala/annotation/internal/UnsafeNonvariant.scala

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

0 commit comments

Comments
 (0)