Skip to content

Commit f130c72

Browse files
committed
Drop UnsafeNonvariant
It's no longer needed.
1 parent 31d9a83 commit f130c72

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
@@ -258,16 +258,6 @@ object Types {
258258
def isRepeatedParam(implicit ctx: Context): Boolean =
259259
typeSymbol eq defn.RepeatedParamClass
260260

261-
/** Does this type carry an UnsafeNonvariant annotation? */
262-
final def isUnsafeNonvariant(implicit ctx: Context): Boolean = this match {
263-
case AnnotatedType(_, annot) => annot.symbol == defn.UnsafeNonvariantAnnot
264-
case _ => false
265-
}
266-
267-
/** Does this type have an UnsafeNonvariant annotation on one of its parts? */
268-
final def hasUnsafeNonvariant(implicit ctx: Context): Boolean =
269-
new HasUnsafeNonAccumulator().apply(false, this)
270-
271261
/** Is this the type of a method that has a repeated parameter type as
272262
* last parameter type?
273263
*/
@@ -4178,10 +4168,6 @@ object Types {
41784168
def apply(x: Unit, tp: Type): Unit = foldOver(p(tp), tp)
41794169
}
41804170

4181-
class HasUnsafeNonAccumulator(implicit ctx: Context) extends TypeAccumulator[Boolean] {
4182-
def apply(x: Boolean, tp: Type) = x || tp.isUnsafeNonvariant || foldOver(x, tp)
4183-
}
4184-
41854171
class NamedPartsAccumulator(p: NamedType => Boolean, excludeLowerBounds: Boolean = false)
41864172
(implicit ctx: Context) extends TypeAccumulator[mutable.Set[NamedType]] {
41874173
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
@@ -387,27 +387,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
387387
}
388388

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

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

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

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

0 commit comments

Comments
 (0)