Skip to content

Commit dbc4592

Browse files
committed
Make matches against Symbol and ClassSymbol @unchecked.
1 parent e499246 commit dbc4592

30 files changed

+64
-64
lines changed

compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class TreeTypeMap(
5050
private val mapOwnerThis = new TypeMap {
5151
private def mapPrefix(from: List[Symbol], to: List[Symbol], tp: Type): Type = from match {
5252
case Nil => tp
53-
case (cls: ClassSymbol) :: from1 => mapPrefix(from1, to.tail, tp.substThis(cls, to.head.thisType))
53+
case (cls: ClassSymbol @unchecked) :: from1 => mapPrefix(from1, to.tail, tp.substThis(cls, to.head.thisType))
5454
case _ :: from1 => mapPrefix(from1, to.tail, tp)
5555
}
5656
def apply(tp: Type): Type = tp match {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ object Annotations {
6767
// seems to be enough to ensure this (note that after erasure, `ctx.typer`
6868
// will be the Erasure typer, but that doesn't seem to affect the annotation
6969
// trees we create, so we leave it as is)
70-
case sym: Symbol if sym.defRunId != parentCtx.runId =>
70+
case sym: Symbol @unchecked if sym.defRunId != parentCtx.runId =>
7171
mySym = sym.denot.current.symbol
7272
case _ =>
7373
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ object ContextOps:
1818
*/
1919
def enter(sym: Symbol): Symbol = inContext(ctx) {
2020
ctx.owner match
21-
case cls: ClassSymbol => cls.classDenot.enter(sym)
21+
case cls: ClassSymbol @unchecked => cls.classDenot.enter(sym)
2222
case _ => ctx.scope.openForMutations.enter(sym)
2323
sym
2424
}
@@ -63,7 +63,7 @@ object ContextOps:
6363
def inClassContext(selfInfo: TypeOrSymbol): Context = inContext(ctx) {
6464
val localCtx: Context = ctx.fresh.setNewScope
6565
selfInfo match {
66-
case sym: Symbol if sym.exists && sym.name != nme.WILDCARD => localCtx.scope.openForMutations.enter(sym)
66+
case sym: Symbol @unchecked if sym.exists && sym.name != nme.WILDCARD => localCtx.scope.openForMutations.enter(sym)
6767
case _ =>
6868
}
6969
localCtx

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ final class ProperGadtConstraint private(
249249

250250
private def externalize(param: TypeParamRef)(using Context): Type =
251251
reverseMapping(param) match {
252-
case sym: Symbol => sym.typeRef
252+
case sym: Symbol @unchecked => sym.typeRef
253253
case null => param
254254
}
255255

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ object SymDenotations {
10141014
case ClassInfo(_, _, _, _, selfType) =>
10151015
def sourceOfSelf(tp: TypeOrSymbol): Symbol = (tp: @unchecked) match {
10161016
case tp: TermRef => tp.symbol
1017-
case tp: Symbol => sourceOfSelf(tp.info)
1017+
case tp: Symbol @unchecked => sourceOfSelf(tp.info)
10181018
case tp: RefinedType => sourceOfSelf(tp.parent)
10191019
}
10201020
sourceOfSelf(selfType)
@@ -1748,7 +1748,7 @@ object SymDenotations {
17481748
*/
17491749
def givenSelfType(using Context): Type = classInfo.selfInfo match {
17501750
case tp: Type => tp
1751-
case self: Symbol => self.info
1751+
case self: Symbol @unchecked => self.info
17521752
}
17531753

17541754
// ------ class-specific operations -----------------------------------
@@ -1804,7 +1804,7 @@ object SymDenotations {
18041804
def traverse(parents: List[Type]): Unit = parents match {
18051805
case p :: parents1 =>
18061806
p.classSymbol match {
1807-
case pcls: ClassSymbol => builder.addAll(pcls.baseClasses)
1807+
case pcls: ClassSymbol @unchecked => builder.addAll(pcls.baseClasses)
18081808
case _ => assert(isRefinementClass || p.isError || ctx.mode.is(Mode.Interactive), s"$this has non-class parent: $p")
18091809
}
18101810
traverse(parents1)

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ object Symbols {
333333
if ctx.phaseId != phase.next.id then
334334
atPhase(phase.next)(enteredAfter(phase))
335335
else this.owner match {
336-
case owner: ClassSymbol =>
336+
case owner: ClassSymbol @unchecked =>
337337
if (owner.is(Package)) {
338338
denot.validFor |= InitialPeriod
339339
if (this.is(Module)) this.moduleClass.validFor |= InitialPeriod
@@ -405,7 +405,7 @@ object Symbols {
405405
valid(denot.owner.source) match {
406406
case NoSource =>
407407
this match {
408-
case cls: ClassSymbol => valid(cls.sourceOfClass)
408+
case cls: ClassSymbol @unchecked => valid(cls.sourceOfClass)
409409
case _ if denot.is(Module) => valid(denot.moduleClass.source)
410410
case _ => NoSource
411411
}
@@ -419,7 +419,7 @@ object Symbols {
419419
*
420420
* @see enclosingSourceSymbols
421421
*/
422-
final def sourceSymbol(using Context): Symbol =
422+
final def sourceSymbol(using Context): SymbolImpl =
423423
if (!denot.exists)
424424
this
425425
else if (denot.is(ModuleVal))
@@ -948,15 +948,15 @@ object Symbols {
948948
*/
949949
object TermSymbols:
950950
def unapply(xs: List[Symbol])(using Context): Option[List[TermSymbol]] = xs match
951-
case (x: Symbol) :: _ if x.isType => None
951+
case (x: Symbol @unchecked) :: _ if x.isType => None
952952
case _ => Some(xs.asInstanceOf[List[TermSymbol]])
953953

954954
/** Matches lists of type symbols, excluding the empty list.
955955
* All symbols in the list are assumed to be of the same kind.
956956
*/
957957
object TypeSymbols:
958958
def unapply(xs: List[Symbol])(using Context): Option[List[TypeSymbol]] = xs match
959-
case (x: Symbol) :: _ if x.isType => Some(xs.asInstanceOf[List[TypeSymbol]])
959+
case (x: Symbol @unchecked) :: _ if x.isType => Some(xs.asInstanceOf[List[TypeSymbol]])
960960
case _ => None
961961

962962
// ----- Locating predefined symbols ----------------------------------------
@@ -971,7 +971,7 @@ object Symbols {
971971
def requiredClass(path: PreName)(using Context): ClassSymbol = {
972972
val name = path.toTypeName
973973
staticRef(name).requiredSymbol("class", name)(_.isClass) match {
974-
case cls: ClassSymbol => cls
974+
case cls: ClassSymbol @unchecked => cls
975975
case sym => defn.AnyClass
976976
}
977977
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ class TypeApplications(val self: Type) extends AnyVal {
211211

212212
/** If `self` is a generic class, its type parameter symbols, otherwise Nil */
213213
final def typeParamSymbols(using Context): List[TypeSymbol] = typeParams match {
214-
case tparams @ (_: Symbol) :: _ =>
215-
assert(tparams.forall(_.isInstanceOf[Symbol]))
214+
case tparams @ (_: Symbol @unchecked) :: _ =>
215+
assert(tparams.forall(_.isInstanceOf[Symbol @unchecked]))
216216
tparams.asInstanceOf[List[TypeSymbol]]
217217
// Note: Two successive calls to typeParams can yield different results here because
218218
// of different completion status. I.e. the first call might produce some symbols,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
14371437
* paths is less intrusive than skolemization.
14381438
*/
14391439
def compareCaptured(arg1: TypeBounds, arg2: Type) = tparam match {
1440-
case tparam: Symbol =>
1440+
case tparam: Symbol @unchecked =>
14411441
if (leftRoot.isStable || (ctx.isAfterTyper || ctx.mode.is(Mode.TypevarsMissContext))
14421442
&& leftRoot.member(tparam.name).exists) {
14431443
val captured = TypeRef(leftRoot, tparam)
@@ -1462,7 +1462,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
14621462
val arg1norm = arg1 match {
14631463
case arg1: TypeBounds =>
14641464
tparam match {
1465-
case tparam: Symbol => arg1 & paramBounds(tparam)
1465+
case tparam: Symbol @unchecked => arg1 & paramBounds(tparam)
14661466
case _ => arg1 // This case can only arise when a hk-type is illegally instantiated with a wildcard
14671467
}
14681468
case _ => arg1

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,7 +2029,7 @@ object Types {
20292029

20302030
private def computeName: Name = designator match {
20312031
case name: Name => name
2032-
case sym: Symbol => sym.originDenotation.name
2032+
case sym: Symbol @unchecked => sym.originDenotation.name
20332033
}
20342034

20352035
/** The signature computed from the last known denotation with `sigFromDenot`,
@@ -2073,7 +2073,7 @@ object Types {
20732073

20742074
private def computeSymbol(using Context): Symbol =
20752075
designator match {
2076-
case sym: Symbol =>
2076+
case sym: Symbol @unchecked =>
20772077
if (sym.isValidInCurrentRun) sym else denot.symbol
20782078
case name =>
20792079
(if (denotationIsCurrent) lastDenotation else denot).symbol
@@ -2095,7 +2095,7 @@ object Types {
20952095
* Normally, it's better to use `symbol`, not `currentSymbol`.
20962096
*/
20972097
final def currentSymbol(using Context): Symbol = designator match {
2098-
case sym: Symbol => sym
2098+
case sym: Symbol @unchecked => sym
20992099
case _ => if (denotationIsCurrent) lastDenotation.symbol else NoSymbol
21002100
}
21012101

@@ -2141,7 +2141,7 @@ object Types {
21412141
val sym = lastSymbol
21422142
val allowPrivate = sym == null || (sym == NoSymbol) || sym.lastKnownDenotation.flagsUNSAFE.is(Private)
21432143
finish(memberDenot(name, allowPrivate))
2144-
case sym: Symbol =>
2144+
case sym: Symbol @unchecked =>
21452145
val symd = sym.lastKnownDenotation
21462146
if (symd.validFor.runId != ctx.runId && !stillValid(symd))
21472147
finish(memberDenot(symd.initial.name, allowPrivate = false))
@@ -2252,7 +2252,7 @@ object Types {
22522252
lastSymbol = denot.symbol
22532253
checkedPeriod = if (prefix.isProvisional) Nowhere else ctx.period
22542254
designator match {
2255-
case sym: Symbol if designator ne lastSymbol =>
2255+
case sym: Symbol @unchecked if designator ne lastSymbol =>
22562256
designator = lastSymbol.asInstanceOf[Designator{ type ThisName = self.ThisName }]
22572257
case _ =>
22582258
}
@@ -2302,7 +2302,7 @@ object Types {
23022302

23032303
/** Is this a reference to a class or object member? */
23042304
def isMemberRef(using Context): Boolean = designator match {
2305-
case sym: Symbol => infoDependsOnPrefix(sym, prefix)
2305+
case sym: Symbol @unchecked => infoDependsOnPrefix(sym, prefix)
23062306
case _ => true
23072307
}
23082308

@@ -2462,7 +2462,7 @@ object Types {
24622462
val adapted = withSym(denot.symbol)
24632463
val result =
24642464
if (adapted.eq(this)
2465-
|| designator.isInstanceOf[Symbol]
2465+
|| designator.isInstanceOf[Symbol @unchecked]
24662466
|| !adapted.denotationIsCurrent
24672467
|| adapted.info.eq(denot.info))
24682468
adapted
@@ -2488,7 +2488,7 @@ object Types {
24882488
if (prefix eq this.prefix) this
24892489
else if (lastDenotation == null) NamedType(prefix, designator)
24902490
else designator match {
2491-
case sym: Symbol =>
2491+
case sym: Symbol @unchecked =>
24922492
if (infoDependsOnPrefix(sym, prefix) && !prefix.isArgPrefixOf(sym)) {
24932493
val candidate = reload()
24942494
val falseOverride = sym.isClass && candidate.symbol.exists && candidate.symbol != symbol
@@ -2615,12 +2615,12 @@ object Types {
26152615
}
26162616

26172617
final class CachedTermRef(prefix: Type, designator: Designator, hc: Int) extends TermRef(prefix, designator) {
2618-
assert((prefix ne NoPrefix) || designator.isInstanceOf[Symbol])
2618+
assert((prefix ne NoPrefix) || designator.isInstanceOf[Symbol @unchecked])
26192619
myHash = hc
26202620
}
26212621

26222622
final class CachedTypeRef(prefix: Type, designator: Designator, hc: Int) extends TypeRef(prefix, designator) {
2623-
assert((prefix ne NoPrefix) || designator.isInstanceOf[Symbol])
2623+
assert((prefix ne NoPrefix) || designator.isInstanceOf[Symbol @unchecked])
26242624
myHash = hc
26252625
}
26262626

@@ -2647,7 +2647,7 @@ object Types {
26472647

26482648
object NamedType {
26492649
def isType(desig: Designator)(using Context): Boolean = desig match {
2650-
case sym: Symbol => sym.isType
2650+
case sym: Symbol @unchecked => sym.isType
26512651
case name: Name => name.isTypeName
26522652
}
26532653
def apply(prefix: Type, designator: Designator)(using Context): NamedType =
@@ -2693,7 +2693,7 @@ object Types {
26932693
*/
26942694
abstract case class ThisType(tref: TypeRef) extends CachedProxyType with SingletonType {
26952695
def cls(using Context): ClassSymbol = tref.stableInRunSymbol match {
2696-
case cls: ClassSymbol => cls
2696+
case cls: ClassSymbol @unchecked => cls
26972697
case _ if ctx.mode.is(Mode.Interactive) => defn.AnyClass // was observed to happen in IDE mode
26982698
}
26992699

@@ -3840,7 +3840,7 @@ object Types {
38403840
else
38413841
super.fromParams(params, tp)
38423842
def isOpaqueAlias = params match
3843-
case (param: Symbol) :: _ => param.owner.is(Opaque)
3843+
case (param: Symbol @unchecked) :: _ => param.owner.is(Opaque)
38443844
case _ => false
38453845
bounds match {
38463846
case bounds: MatchAlias =>
@@ -4604,7 +4604,7 @@ object Types {
46044604
case self: Type =>
46054605
cinfo.derivedClassInfo(
46064606
selfInfo = refineSelfType(self.orElse(defn.AnyType)))
4607-
case self: Symbol =>
4607+
case self: Symbol @unchecked =>
46084608
self.info = refineSelfType(self.info)
46094609
cinfo
46104610
else cinfo

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ object Variances {
141141
*/
142142
def variancesConform(tparams1: List[TypeParamInfo], tparams2: List[TypeParamInfo])(using Context): Boolean =
143143
val needsDetailedCheck = tparams2 match
144-
case (_: Symbol) :: _ => true
144+
case (_: Symbol @unchecked) :: _ => true
145145
case LambdaParam(tl: HKTypeLambda, _) :: _ => tl.isDeclaredVarianceLambda
146146
case _ => false
147147
if needsDetailedCheck then tparams1.corresponds(tparams2)(varianceConforms)

0 commit comments

Comments
 (0)