Skip to content

Commit

Permalink
Update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
noti0na1 committed Feb 2, 2022
1 parent 1958707 commit aa39739
Show file tree
Hide file tree
Showing 16 changed files with 31 additions and 45 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,7 @@ object desugar {
val ts = tree.trees
val arity = ts.length
assert(arity <= Definitions.MaxTupleArity)
def tupleTypeRef = defn.TupleType(arity)
def tupleTypeRef = defn.TupleType(arity).nn
if (arity == 0)
if (ctx.mode is Mode.Type) TypeTree(defn.UnitType) else unitLiteral
else if (ctx.mode is Mode.Type) AppliedTypeTree(ref(tupleTypeRef), ts)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
def tupleTypeTree(elems: List[Tree])(using Context): Tree = {
val arity = elems.length
if arity <= Definitions.MaxTupleArity then
val tupleTp: TypeRef | Null = defn.TupleType(arity)
val tupleTp = defn.TupleType(arity)
if tupleTp != null then
AppliedTypeTree(TypeTree(tupleTp), elems)
else nestedPairsTypeTree(elems)
Expand Down
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/dotc/core/Annotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ object Annotations {
object LazyBodyAnnotation {
def apply(bodyFn: Context ?=> Tree): LazyBodyAnnotation =
new LazyBodyAnnotation:
protected var myTree: Tree | (Context ?=> Tree) = ctx ?=> bodyFn(using ctx)
protected var myTree: Tree | (Context ?=> Tree) | Null = ctx ?=> bodyFn(using ctx)
}

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

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

/** Extractor for child annotations */
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ trait ConstraintHandling {
val e = constraint.entry(param)
if (e.exists) e.bounds
else {
// TODO
// TODO: should we change the type of paramInfos to nullable?
val pinfos: List[param.binder.PInfo] | Null = param.binder.paramInfos
if (pinfos != null) pinfos(param.paramNum) // pinfos == null happens in pos/i536.scala
else TypeBounds.empty
Expand Down Expand Up @@ -679,7 +679,6 @@ trait ConstraintHandling {
if (!fromBelow) variance = -1
def apply(t: Type): Type = t match {
case t @ TypeParamRef(tl: TypeLambda, n) if comparedTypeLambdas contains tl =>
// TODO: do we need to check null here?
val bounds = tl.paramInfos(n)
range(bounds.lo, bounds.hi)
case _ =>
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,14 @@ object Contexts {
/** Either the current scope, or, if the current context owner is a class,
* the declarations of the current class.
*/
// TODO: Should we change its type to nullable?
// We can see its value can be null in nestingLevel below.
def effectiveScope(using Context): Scope =
// TODO
val co: Symbol | Null = owner
if co != null && co.isClass then co.asClass.unforcedDecls
else scope

def nestingLevel: Int =
// TODO
val sc: Scope | Null = effectiveScope
if sc != null then sc.nestingLevel else 0

Expand Down
12 changes: 6 additions & 6 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ class Definitions {
private def enterT1ParameterlessMethod(cls: ClassSymbol, name: TermName, resultTypeFn: PolyType => Type, flags: FlagSet) =
enterPolyMethod(cls, name, 1, resultTypeFn, flags)

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

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

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

Expand All @@ -1283,7 +1283,7 @@ class Definitions {
.withDefaultValue(holderImpl("LazyRef"))
})

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

private class FunType(prefix: String):
private var classRefs: Array[TypeRef | Null] = new Array(22)
Expand Down Expand Up @@ -1497,15 +1497,15 @@ class Definitions {
def isTupleNType(tp: Type)(using Context): Boolean = {
val arity = tp.dealias.argInfos.length
arity <= MaxTupleArity && {
val tupletp: TypeRef | Null = TupleType(arity)
val tupletp = TupleType(arity)
tupletp != null && tp.isRef(tupletp.symbol)
}
}

def tupleType(elems: List[Type]): Type = {
val arity = elems.length
if 0 < arity && arity <= MaxTupleArity then
val tupletp: TypeRef | Null = TupleType(arity)
val tupletp = TupleType(arity)
if tupletp != null then tupletp.appliedTo(elems)
else TypeOps.nestedPairs(elems)
else TypeOps.nestedPairs(elems)
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/TypeErasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ object TypeErasure {
*/
abstract case class ErasedValueType(tycon: TypeRef, erasedUnderlying: Type)
extends CachedGroundType with ValueType {
override def computeHash(bs: Hashable.Binders): Int = doHash(bs, tycon, erasedUnderlying)
override def computeHash(bs: Hashable.Binders | Null): Int = doHash(bs, tycon, erasedUnderlying)
}

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

Expand Down
1 change: 0 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3919,7 +3919,6 @@ object Types {
&& {
val bs1 = new BinderPairs(this, that, bs)
// `paramInfos` and `resType` might still be uninstantiated at this point
// TODO:
(paramInfos: List[TypeBounds] | Null) != null && (resType: Type | Null) != null &&
paramInfos.equalElements(that.paramInfos, bs1) &&
resType.equals(that.resType, bs1)
Expand Down
6 changes: 1 addition & 5 deletions compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,8 @@ class PatternMatcher extends MiniPhase {
case rt => tree.tpe
val translated = new Translator(matchType, this).translateMatch(tree)

val engineCtx =
if tree.hasAttachment(Nullables.UnsafeNullsMatch)
then ctx.retractMode(Mode.SafeNulls) else ctx

// check exhaustivity and unreachability
val engine = new patmat.SpaceEngine()(using engineCtx)
val engine = new patmat.SpaceEngine
engine.checkExhaustivity(tree)
engine.checkRedundancy(tree)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class TupleOptimizations extends MiniPhase with IdentityDenotTransformer {
private def knownTupleFromElements(tpes: List[Type], elements: List[Tree])(using Context) = {
val size = elements.size
assert(0 < size && size <= MaxTupleArity)
val tupleModule = defn.TupleType(size).classSymbol.companionModule
val tupleModule = defn.TupleType(size).nn.classSymbol.companionModule
ref(tupleModule).select(nme.apply).appliedToTypes(tpes).appliedToTermArgs(elements)
}

Expand Down
7 changes: 4 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ object Implicits:
* @param companionRefs the companion objects in the implicit scope.
*/
class OfTypeImplicits(tp: Type, override val companionRefs: TermRefSet)(initctx: Context) extends ImplicitRefs(initctx) {
// TODO: do we need this assert?
// TODO: why do we need this assert?
assert((initctx.typer: Typer | Null) != null)
implicits.println(i"implicit scope of type $tp = ${companionRefs.showAsList}%, %")
@threadUnsafe lazy val refs: List[ImplicitRef] = {
Expand Down Expand Up @@ -1864,9 +1864,10 @@ sealed class TermRefSet(using Context):
if !that.isEmpty then that.foreach(+=)

def foreach[U](f: TermRef => U): Unit =
// TODO: do we need to check sym == null?
def handle(sym: TermSymbol | Null, prefixes: Type | List[Type] | Null): Unit =
prefixes match
// We cannot use `.nn` here due to inference issue.
val prefixes0: Type | List[Type] = prefixes.uncheckedNN
prefixes0 match
case prefix: Type => f(TermRef(prefix, sym.uncheckedNN))
case prefixes: List[Type] => prefixes.foreach(pre => f(TermRef(pre, sym.uncheckedNN)))
elems.forEach(handle)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/ImportInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class ImportInfo(symf: Context ?=> Symbol,
case None =>
var c = ctx.outer
while c.importInfo eq ctx.importInfo do c = c.outer
// TODO
// TODO: Do we need to change importInfo to nullable?
((c.importInfo: ImportInfo | Null) != null) && c.importInfo.featureImported(feature)(using c)
)
featureCache(feature).nn
Expand Down
7 changes: 0 additions & 7 deletions compiler/src/dotty/tools/dotc/typer/Nullables.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ import ast.Trees.mods
object Nullables:
import ast.tpd._

/** An attachment that represents a match tree is created under Unsafe Nulls.
* This is used to pass Unsafe Nulls information to PatternMatcher Phase,
* so we don't get Match case Unreachable Warning when using `case null => ???`
* on non-nullable type.
*/
val UnsafeNullsMatch = Property.StickyKey[Unit]

inline def unsafeNullsEnabled(using Context): Boolean =
ctx.explicitNulls && !ctx.mode.is(Mode.SafeNulls)

Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ object ProtoTypes {
override def deepenProto(using Context): Type = ignored
override def deepenProtoTrans(using Context): Type = ignored.deepenProtoTrans

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

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

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

class CachedViewProto(argType: Type, resultType: Type) extends ViewProto(argType, resultType) {
override def computeHash(bs: Hashable.Binders): Int = doHash(bs, argType, resultType)
override def computeHash(bs: Hashable.Binders | Null): Int = doHash(bs, argType, resultType)
override def eql(that: Type): Boolean = that match
case that: ViewProto => (argType eq that.argType) && (resType eq that.resType)
case _ => false
Expand Down
6 changes: 2 additions & 4 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
(prevPrec.ordinal < prec.ordinal || prevPrec == prec && (prevCtx.scope eq ctx.scope))

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

def typedMatch(tree: untpd.Match, pt: Type)(using Context): Tree =
val tree1 = tree.selector match {
tree.selector match {
case EmptyTree =>
if (tree.isInline) {
checkInInlineContext("summonFrom", tree.srcPos)
Expand Down Expand Up @@ -1603,9 +1604,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
result
}
}
if Nullables.unsafeNullsEnabled && ctx.phase == Phases.typerPhase then
tree1.putAttachment(Nullables.UnsafeNullsMatch, ())
tree1

/** Special typing of Match tree when the expected type is a MatchType,
* and the patterns of the Match tree and the MatchType correspond.
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2702,7 +2702,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
def FunctionClass(arity: Int, isImplicit: Boolean = false, isErased: Boolean = false): Symbol =
dotc.core.Symbols.defn.FunctionClass(arity, isImplicit, isErased)
def TupleClass(arity: Int): Symbol =
dotc.core.Symbols.defn.TupleType(arity).classSymbol.asClass
dotc.core.Symbols.defn.TupleType(arity).nn.classSymbol.asClass
def isTupleClass(sym: Symbol): Boolean =
dotc.core.Symbols.defn.isTupleClass(sym)
def ScalaPrimitiveValueClasses: List[Symbol] =
Expand Down

0 comments on commit aa39739

Please sign in to comment.