Skip to content

Commit aa39739

Browse files
committed
Update comments
1 parent 1958707 commit aa39739

16 files changed

+31
-45
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,7 @@ object desugar {
12871287
val ts = tree.trees
12881288
val arity = ts.length
12891289
assert(arity <= Definitions.MaxTupleArity)
1290-
def tupleTypeRef = defn.TupleType(arity)
1290+
def tupleTypeRef = defn.TupleType(arity).nn
12911291
if (arity == 0)
12921292
if (ctx.mode is Mode.Type) TypeTree(defn.UnitType) else unitLiteral
12931293
else if (ctx.mode is Mode.Type) AppliedTypeTree(ref(tupleTypeRef), ts)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
14681468
def tupleTypeTree(elems: List[Tree])(using Context): Tree = {
14691469
val arity = elems.length
14701470
if arity <= Definitions.MaxTupleArity then
1471-
val tupleTp: TypeRef | Null = defn.TupleType(arity)
1471+
val tupleTp = defn.TupleType(arity)
14721472
if tupleTp != null then
14731473
AppliedTypeTree(TypeTree(tupleTp), elems)
14741474
else nestedPairsTypeTree(elems)

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ object Annotations {
164164
object LazyBodyAnnotation {
165165
def apply(bodyFn: Context ?=> Tree): LazyBodyAnnotation =
166166
new LazyBodyAnnotation:
167-
protected var myTree: Tree | (Context ?=> Tree) = ctx ?=> bodyFn(using ctx)
167+
protected var myTree: Tree | (Context ?=> Tree) | Null = ctx ?=> bodyFn(using ctx)
168168
}
169169

170170
object Annotation {
@@ -195,15 +195,15 @@ object Annotations {
195195
/** Create an annotation where the tree is computed lazily. */
196196
def deferred(sym: Symbol)(treeFn: Context ?=> Tree)(using Context): Annotation =
197197
new LazyAnnotation {
198-
protected var myTree: Tree | (Context ?=> Tree) = ctx ?=> treeFn(using ctx)
199-
protected var mySym: Symbol | (Context ?=> Symbol) = sym
198+
protected var myTree: Tree | (Context ?=> Tree) | Null = ctx ?=> treeFn(using ctx)
199+
protected var mySym: Symbol | (Context ?=> Symbol) | Null = sym
200200
}
201201

202202
/** Create an annotation where the symbol and the tree are computed lazily. */
203203
def deferredSymAndTree(symFn: Context ?=> Symbol)(treeFn: Context ?=> Tree)(using Context): Annotation =
204204
new LazyAnnotation {
205-
protected var mySym: Symbol | (Context ?=> Symbol) = ctx ?=> symFn(using ctx)
206-
protected var myTree: Tree | (Context ?=> Tree) = ctx ?=> treeFn(using ctx)
205+
protected var mySym: Symbol | (Context ?=> Symbol) | Null = ctx ?=> symFn(using ctx)
206+
protected var myTree: Tree | (Context ?=> Tree) | Null = ctx ?=> treeFn(using ctx)
207207
}
208208

209209
/** Extractor for child annotations */

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ trait ConstraintHandling {
604604
val e = constraint.entry(param)
605605
if (e.exists) e.bounds
606606
else {
607-
// TODO
607+
// TODO: should we change the type of paramInfos to nullable?
608608
val pinfos: List[param.binder.PInfo] | Null = param.binder.paramInfos
609609
if (pinfos != null) pinfos(param.paramNum) // pinfos == null happens in pos/i536.scala
610610
else TypeBounds.empty
@@ -679,7 +679,6 @@ trait ConstraintHandling {
679679
if (!fromBelow) variance = -1
680680
def apply(t: Type): Type = t match {
681681
case t @ TypeParamRef(tl: TypeLambda, n) if comparedTypeLambdas contains tl =>
682-
// TODO: do we need to check null here?
683682
val bounds = tl.paramInfos(n)
684683
range(bounds.lo, bounds.hi)
685684
case _ =>

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,14 @@ object Contexts {
271271
/** Either the current scope, or, if the current context owner is a class,
272272
* the declarations of the current class.
273273
*/
274+
// TODO: Should we change its type to nullable?
275+
// We can see its value can be null in nestingLevel below.
274276
def effectiveScope(using Context): Scope =
275-
// TODO
276277
val co: Symbol | Null = owner
277278
if co != null && co.isClass then co.asClass.unforcedDecls
278279
else scope
279280

280281
def nestingLevel: Int =
281-
// TODO
282282
val sc: Scope | Null = effectiveScope
283283
if sc != null then sc.nestingLevel else 0
284284

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ class Definitions {
180180
private def enterT1ParameterlessMethod(cls: ClassSymbol, name: TermName, resultTypeFn: PolyType => Type, flags: FlagSet) =
181181
enterPolyMethod(cls, name, 1, resultTypeFn, flags)
182182

183-
private def mkArityArray(name: String, arity: Int, countFrom: Int): Array[TypeRef] = {
184-
val arr = new Array[TypeRef](arity + 1)
183+
private def mkArityArray(name: String, arity: Int, countFrom: Int): Array[TypeRef | Null] = {
184+
val arr = new Array[TypeRef | Null](arity + 1)
185185
for (i <- countFrom to arity) arr(i) = requiredClassRef(name + i)
186186
arr
187187
}
@@ -1260,7 +1260,7 @@ class Definitions {
12601260

12611261
@tu lazy val untestableClasses: Set[Symbol] = Set(NothingClass, NullClass, SingletonClass)
12621262

1263-
@tu lazy val AbstractFunctionType: Array[TypeRef] = mkArityArray("scala.runtime.AbstractFunction", MaxImplementedFunctionArity, 0)
1263+
@tu lazy val AbstractFunctionType: Array[TypeRef] = mkArityArray("scala.runtime.AbstractFunction", MaxImplementedFunctionArity, 0).asInstanceOf[Array[TypeRef]]
12641264
val AbstractFunctionClassPerRun: PerRun[Array[Symbol]] = new PerRun(AbstractFunctionType.map(_.symbol.asClass))
12651265
def AbstractFunctionClass(n: Int)(using Context): Symbol = AbstractFunctionClassPerRun()(using ctx)(n)
12661266

@@ -1283,7 +1283,7 @@ class Definitions {
12831283
.withDefaultValue(holderImpl("LazyRef"))
12841284
})
12851285

1286-
@tu lazy val TupleType: Array[TypeRef] = mkArityArray("scala.Tuple", MaxTupleArity, 1)
1286+
@tu lazy val TupleType: Array[TypeRef | Null] = mkArityArray("scala.Tuple", MaxTupleArity, 1)
12871287

12881288
private class FunType(prefix: String):
12891289
private var classRefs: Array[TypeRef | Null] = new Array(22)
@@ -1497,15 +1497,15 @@ class Definitions {
14971497
def isTupleNType(tp: Type)(using Context): Boolean = {
14981498
val arity = tp.dealias.argInfos.length
14991499
arity <= MaxTupleArity && {
1500-
val tupletp: TypeRef | Null = TupleType(arity)
1500+
val tupletp = TupleType(arity)
15011501
tupletp != null && tp.isRef(tupletp.symbol)
15021502
}
15031503
}
15041504

15051505
def tupleType(elems: List[Type]): Type = {
15061506
val arity = elems.length
15071507
if 0 < arity && arity <= MaxTupleArity then
1508-
val tupletp: TypeRef | Null = TupleType(arity)
1508+
val tupletp = TupleType(arity)
15091509
if tupletp != null then tupletp.appliedTo(elems)
15101510
else TypeOps.nestedPairs(elems)
15111511
else TypeOps.nestedPairs(elems)

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ object TypeErasure {
132132
*/
133133
abstract case class ErasedValueType(tycon: TypeRef, erasedUnderlying: Type)
134134
extends CachedGroundType with ValueType {
135-
override def computeHash(bs: Hashable.Binders): Int = doHash(bs, tycon, erasedUnderlying)
135+
override def computeHash(bs: Hashable.Binders | Null): Int = doHash(bs, tycon, erasedUnderlying)
136136
}
137137

138138
final class CachedErasedValueType(tycon: TypeRef, erasedUnderlying: Type)
@@ -690,7 +690,7 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
690690
private def erasePair(tp: Type)(using Context): Type = {
691691
val arity = tp.tupleArity
692692
if (arity < 0) defn.ProductClass.typeRef
693-
else if (arity <= Definitions.MaxTupleArity) defn.TupleType(arity)
693+
else if (arity <= Definitions.MaxTupleArity) defn.TupleType(arity).nn
694694
else defn.TupleXXLClass.typeRef
695695
}
696696

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

-1
Original file line numberDiff line numberDiff line change
@@ -3919,7 +3919,6 @@ object Types {
39193919
&& {
39203920
val bs1 = new BinderPairs(this, that, bs)
39213921
// `paramInfos` and `resType` might still be uninstantiated at this point
3922-
// TODO:
39233922
(paramInfos: List[TypeBounds] | Null) != null && (resType: Type | Null) != null &&
39243923
paramInfos.equalElements(that.paramInfos, bs1) &&
39253924
resType.equals(that.resType, bs1)

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,8 @@ class PatternMatcher extends MiniPhase {
4646
case rt => tree.tpe
4747
val translated = new Translator(matchType, this).translateMatch(tree)
4848

49-
val engineCtx =
50-
if tree.hasAttachment(Nullables.UnsafeNullsMatch)
51-
then ctx.retractMode(Mode.SafeNulls) else ctx
52-
5349
// check exhaustivity and unreachability
54-
val engine = new patmat.SpaceEngine()(using engineCtx)
50+
val engine = new patmat.SpaceEngine
5551
engine.checkExhaustivity(tree)
5652
engine.checkRedundancy(tree)
5753

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class TupleOptimizations extends MiniPhase with IdentityDenotTransformer {
195195
private def knownTupleFromElements(tpes: List[Type], elements: List[Tree])(using Context) = {
196196
val size = elements.size
197197
assert(0 < size && size <= MaxTupleArity)
198-
val tupleModule = defn.TupleType(size).classSymbol.companionModule
198+
val tupleModule = defn.TupleType(size).nn.classSymbol.companionModule
199199
ref(tupleModule).select(nme.apply).appliedToTypes(tpes).appliedToTermArgs(elements)
200200
}
201201

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ object Implicits:
274274
* @param companionRefs the companion objects in the implicit scope.
275275
*/
276276
class OfTypeImplicits(tp: Type, override val companionRefs: TermRefSet)(initctx: Context) extends ImplicitRefs(initctx) {
277-
// TODO: do we need this assert?
277+
// TODO: why do we need this assert?
278278
assert((initctx.typer: Typer | Null) != null)
279279
implicits.println(i"implicit scope of type $tp = ${companionRefs.showAsList}%, %")
280280
@threadUnsafe lazy val refs: List[ImplicitRef] = {
@@ -1864,9 +1864,10 @@ sealed class TermRefSet(using Context):
18641864
if !that.isEmpty then that.foreach(+=)
18651865

18661866
def foreach[U](f: TermRef => U): Unit =
1867-
// TODO: do we need to check sym == null?
18681867
def handle(sym: TermSymbol | Null, prefixes: Type | List[Type] | Null): Unit =
1869-
prefixes match
1868+
// We cannot use `.nn` here due to inference issue.
1869+
val prefixes0: Type | List[Type] = prefixes.uncheckedNN
1870+
prefixes0 match
18701871
case prefix: Type => f(TermRef(prefix, sym.uncheckedNN))
18711872
case prefixes: List[Type] => prefixes.foreach(pre => f(TermRef(pre, sym.uncheckedNN)))
18721873
elems.forEach(handle)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ class ImportInfo(symf: Context ?=> Symbol,
224224
case None =>
225225
var c = ctx.outer
226226
while c.importInfo eq ctx.importInfo do c = c.outer
227-
// TODO
227+
// TODO: Do we need to change importInfo to nullable?
228228
((c.importInfo: ImportInfo | Null) != null) && c.importInfo.featureImported(feature)(using c)
229229
)
230230
featureCache(feature).nn

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

-7
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ import ast.Trees.mods
2222
object Nullables:
2323
import ast.tpd._
2424

25-
/** An attachment that represents a match tree is created under Unsafe Nulls.
26-
* This is used to pass Unsafe Nulls information to PatternMatcher Phase,
27-
* so we don't get Match case Unreachable Warning when using `case null => ???`
28-
* on non-nullable type.
29-
*/
30-
val UnsafeNullsMatch = Property.StickyKey[Unit]
31-
3225
inline def unsafeNullsEnabled(using Context): Boolean =
3326
ctx.explicitNulls && !ctx.mode.is(Mode.SafeNulls)
3427

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ object ProtoTypes {
137137
override def deepenProto(using Context): Type = ignored
138138
override def deepenProtoTrans(using Context): Type = ignored.deepenProtoTrans
139139

140-
override def computeHash(bs: Hashable.Binders): Int = doHash(bs, ignored)
140+
override def computeHash(bs: Hashable.Binders | Null): Int = doHash(bs, ignored)
141141

142142
override def eql(that: Type): Boolean = that match
143143
case that: IgnoredProto => ignored eq that.ignored
@@ -221,7 +221,7 @@ object ProtoTypes {
221221
override def deepenProtoTrans(using Context): SelectionProto =
222222
derivedSelectionProto(name, memberProto.deepenProtoTrans, compat)
223223

224-
override def computeHash(bs: Hashable.Binders): Int = {
224+
override def computeHash(bs: Hashable.Binders | Null): Int = {
225225
val delta = (if (compat eq NoViewsAllowed) 1 else 0) | (if (privateOK) 2 else 0)
226226
addDelta(doHash(bs, name, memberProto), delta)
227227
}
@@ -585,7 +585,7 @@ object ProtoTypes {
585585
}
586586

587587
class CachedViewProto(argType: Type, resultType: Type) extends ViewProto(argType, resultType) {
588-
override def computeHash(bs: Hashable.Binders): Int = doHash(bs, argType, resultType)
588+
override def computeHash(bs: Hashable.Binders | Null): Int = doHash(bs, argType, resultType)
589589
override def eql(that: Type): Boolean = that match
590590
case that: ViewProto => (argType eq that.argType) && (resType eq that.resType)
591591
case _ => false

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
328328
(prevPrec.ordinal < prec.ordinal || prevPrec == prec && (prevCtx.scope eq ctx.scope))
329329

330330
@tailrec def loop(lastCtx: Context)(using Context): Type =
331+
// Can ctx.scope actually be null?
331332
if ((ctx.scope: Scope | Null) == null) previous
332333
else {
333334
var result: Type = NoType
@@ -1501,7 +1502,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
15011502
}
15021503

15031504
def typedMatch(tree: untpd.Match, pt: Type)(using Context): Tree =
1504-
val tree1 = tree.selector match {
1505+
tree.selector match {
15051506
case EmptyTree =>
15061507
if (tree.isInline) {
15071508
checkInInlineContext("summonFrom", tree.srcPos)
@@ -1603,9 +1604,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
16031604
result
16041605
}
16051606
}
1606-
if Nullables.unsafeNullsEnabled && ctx.phase == Phases.typerPhase then
1607-
tree1.putAttachment(Nullables.UnsafeNullsMatch, ())
1608-
tree1
16091607

16101608
/** Special typing of Match tree when the expected type is a MatchType,
16111609
* and the patterns of the Match tree and the MatchType correspond.

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -2702,7 +2702,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
27022702
def FunctionClass(arity: Int, isImplicit: Boolean = false, isErased: Boolean = false): Symbol =
27032703
dotc.core.Symbols.defn.FunctionClass(arity, isImplicit, isErased)
27042704
def TupleClass(arity: Int): Symbol =
2705-
dotc.core.Symbols.defn.TupleType(arity).classSymbol.asClass
2705+
dotc.core.Symbols.defn.TupleType(arity).nn.classSymbol.asClass
27062706
def isTupleClass(sym: Symbol): Boolean =
27072707
dotc.core.Symbols.defn.isTupleClass(sym)
27082708
def ScalaPrimitiveValueClasses: List[Symbol] =

0 commit comments

Comments
 (0)