Skip to content

Commit 7a68ebb

Browse files
committed
Fix according to review comments
1 parent 164ce87 commit 7a68ebb

File tree

11 files changed

+35
-39
lines changed

11 files changed

+35
-39
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Src
181181
case _: XMLBlock =>
182182
// FIXME: Trees generated by the XML parser do not satisfy `checkPos`
183183
case _: WildcardFunction
184-
if lastPositioned != null && lastPositioned.isInstanceOf[ValDef] && !p.isInstanceOf[ValDef] =>
184+
if lastPositioned.isInstanceOf[ValDef] && !p.isInstanceOf[ValDef] =>
185185
// ignore transition from last wildcard parameter to body
186186
case _ =>
187187
assert(!lastSpan.exists || !p.span.exists || lastSpan.end <= p.span.start,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,13 @@ object Names {
182182
private var derivedNames: LinearMap[NameInfo, DerivedName] = LinearMap.empty
183183

184184
private def add(info: NameInfo): TermName = synchronized {
185-
derivedNames.lookup(info) match
185+
val dnOpt = derivedNames.lookup(info)
186+
dnOpt match
186187
case null =>
187188
val derivedName = new DerivedName(this, info)
188189
derivedNames = derivedNames.updated(info, derivedName)
189190
derivedName
190-
case derivedName: DerivedName =>
191-
derivedName
191+
case _ => dnOpt
192192
}
193193

194194
private def rewrap(underlying: TermName) =

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ object OrderingConstraint {
5151
def update(prev: OrderingConstraint, current: OrderingConstraint,
5252
poly: TypeLambda, idx: Int, entry: T)(using Context): OrderingConstraint = {
5353
var es = entries(current, poly)
54+
// TODO: invest why flow typing is not working on `es`
5455
if (es != null && (es.nn(idx) eq entry)) current
5556
else {
5657
val result =
@@ -567,12 +568,12 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
567568
boundsMap.foreachBinding { (poly, entries) =>
568569
for (i <- 0 until paramCount(entries))
569570
typeVar(entries, i) match {
570-
case tv: TypeVar if !tv.inst.exists && isBounds(entries(i)) => myUninstVars.nn += tv
571+
case tv: TypeVar if !tv.inst.exists && isBounds(entries(i)) => myUninstVars.uncheckedNN += tv
571572
case _ =>
572573
}
573574
}
574575
}
575-
myUninstVars.nn
576+
myUninstVars.uncheckedNN
576577
}
577578

578579
// ---------- Checking -----------------------------------------------

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ object Scopes {
134134
final def lookupAll(name: Name)(using Context): Iterator[Symbol] = new Iterator[Symbol] {
135135
var e = lookupEntry(name)
136136
def hasNext: Boolean = e != null
137-
def next(): Symbol = { val r = e.uncheckedNN.sym; e = lookupNextEntry(e.uncheckedNN); r }
137+
def next(): Symbol = { val r = e.nn.sym; e = lookupNextEntry(e.uncheckedNN); r }
138138
}
139139

140140
/** Does this scope contain a reference to `sym` when looking up `name`? */
@@ -168,7 +168,8 @@ object Scopes {
168168
if (result == null) result = cloneScope
169169
result.nn.unlink(sym)
170170
}
171-
if (result == null) this else result.nn
171+
// TODO: improve flow typing to handle this case
172+
if (result == null) this else result.uncheckedNN
172173
}
173174

174175
def implicitDecls(using Context): List[TermRef] = Nil

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

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ object Symbols {
8686
ctx.settings.YcheckInit.value // initialization check
8787

8888
/** The last denotation of this symbol */
89-
private var lastDenot: SymDenotation | Null = _
89+
private var lastDenot: SymDenotation = _
9090
private var checkedPeriod: Period = Nowhere
9191

9292
private[core] def invalidateDenotCache(): Unit = { checkedPeriod = Nowhere }
@@ -101,9 +101,8 @@ object Symbols {
101101
/** The current denotation of this symbol */
102102
final def denot(using Context): SymDenotation = {
103103
util.Stats.record("Symbol.denot")
104-
val lastd = lastDenot.nn
105-
if (checkedPeriod == ctx.period) lastd
106-
else computeDenot(lastd)
104+
if (checkedPeriod == ctx.period) lastDenot
105+
else computeDenot(lastDenot)
107106
}
108107

109108
private def computeDenot(lastd: SymDenotation)(using Context): SymDenotation = {
@@ -123,14 +122,14 @@ object Symbols {
123122

124123
/** The original denotation of this symbol, without forcing anything */
125124
final def originDenotation: SymDenotation =
126-
lastDenot.nn.initial
125+
lastDenot.initial
127126

128127
/** The last known denotation of this symbol, without going through `current` */
129128
final def lastKnownDenotation: SymDenotation =
130-
lastDenot.nn
129+
lastDenot
131130

132131
private[core] def defRunId: RunId =
133-
if (lastDenot == null) NoRunId else lastDenot.nn.validFor.runId
132+
lastDenot.validFor.runId
134133

135134
private inline def associatedFileMatches(inline filter: AbstractFile => Boolean)(using Context): Boolean =
136135
try
@@ -153,18 +152,17 @@ object Symbols {
153152

154153
/** Is symbol valid in current run? */
155154
final def isValidInCurrentRun(using Context): Boolean =
156-
val d = lastDenot.nn
157-
(d.validFor.runId == ctx.runId || stillValid(d)) &&
158-
(d.symbol eq this)
155+
(lastDenot.validFor.runId == ctx.runId || stillValid(lastDenot)) &&
156+
(lastDenot.symbol eq this)
159157
// the last condition is needed because under ctx.staleOK overwritten
160158
// members keep denotations pointing to the new symbol, so the validity
161159
// periods check out OK. But once a package member is overridden it is not longer
162160
// valid. If the option would be removed, the check would be no longer needed.
163161

164162
final def isTerm(using Context): Boolean =
165-
(if (defRunId == ctx.runId) lastDenot.nn else denot).isTerm
163+
(if (defRunId == ctx.runId) lastDenot else denot).isTerm
166164
final def isType(using Context): Boolean =
167-
(if (defRunId == ctx.runId) lastDenot.nn else denot).isType
165+
(if (defRunId == ctx.runId) lastDenot else denot).isType
168166
final def asTerm(using Context): TermSymbol = {
169167
assert(isTerm, s"asTerm called on not-a-Term $this" );
170168
asInstanceOf[TermSymbol]
@@ -181,10 +179,8 @@ object Symbols {
181179
* conservatively returns `false` if symbol does not yet have a denotation, or denotation
182180
* is a class that is not yet read.
183181
*/
184-
final def isPrivate(using Context): Boolean = {
185-
val d = lastDenot
186-
d != null && d.flagsUNSAFE.is(Private)
187-
}
182+
final def isPrivate(using Context): Boolean =
183+
lastDenot.flagsUNSAFE.is(Private)
188184

189185
/** Is the symbol a pattern bound symbol?
190186
*/
@@ -193,14 +189,14 @@ object Symbols {
193189

194190
/** The symbol's signature if it is completed or a method, NotAMethod otherwise. */
195191
final def signature(using Context): Signature =
196-
if (lastDenot != null && (lastDenot.uncheckedNN.isCompleted || lastDenot.uncheckedNN.is(Method)))
192+
if lastDenot.uncheckedNN.isCompleted || lastDenot.uncheckedNN.is(Method) then
197193
denot.signature
198194
else
199195
Signature.NotAMethod
200196

201197
/** Special cased here, because it may be used on naked symbols in substituters */
202198
final def isStatic(using Context): Boolean =
203-
lastDenot != null && lastDenot.uncheckedNN.initial.isStatic
199+
lastDenot.initial.isStatic
204200

205201
/** This symbol entered into owner's scope (owner must be a class). */
206202
final def entered(using Context): this.type = {
@@ -268,7 +264,7 @@ object Symbols {
268264
* Overridden in ClassSymbol
269265
*/
270266
def associatedFile(using Context): AbstractFile | Null =
271-
if (lastDenot == null) null else lastDenot.uncheckedNN.topLevelClass.associatedFile
267+
lastDenot.topLevelClass.associatedFile
272268

273269
/** The class file from which this class was generated, null if not applicable. */
274270
final def binaryFile(using Context): AbstractFile | Null = {
@@ -356,8 +352,7 @@ object Symbols {
356352
protected def prefixString: String = "Symbol"
357353

358354
override def toString: String =
359-
if (lastDenot == null) s"Naked$prefixString#$id"
360-
else lastDenot.nn.toString // + "#" + id // !!! DEBUG
355+
lastDenot.toString // + "#" + id // !!! DEBUG
361356

362357
def toText(printer: Printer): Text = printer.toText(this)
363358

compiler/src/dotty/tools/dotc/transform/sjs/PrepJSInterop.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,8 @@ class PrepJSInterop extends MacroTransform with IdentityDenotTransformer { thisP
544544
val dotIndex = pathName.indexOf('.')
545545
val globalRef =
546546
if (dotIndex < 0) pathName
547-
else pathName.substring(0, dotIndex)
548-
checkGlobalRefName(globalRef.nn)
547+
else pathName.substring(0, dotIndex).nn
548+
checkGlobalRefName(globalRef)
549549
}
550550

551551
checkAndGetJSNativeLoadingSpecAnnotOf(pos, sym) match {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ object Implicits:
364364
if (monitored) record(s"check eligible refs in irefCtx", refs.length)
365365
val ownEligible = filterMatching(tp)
366366
if isOuterMost then ownEligible
367-
else combineEligibles(ownEligible, outerImplicits.uncheckedNN.eligible(tp))
367+
else combineEligibles(ownEligible, outerImplicits.nn.eligible(tp))
368368
}
369369

370370
override def isAccessible(ref: TermRef)(using Context): Boolean =
@@ -381,7 +381,7 @@ object Implicits:
381381
def exclude(root: Symbol): ContextualImplicits =
382382
if (this == NoContext.implicits) this
383383
else {
384-
val outerExcluded = outerImplicits.uncheckedNN exclude root
384+
val outerExcluded = outerImplicits.nn exclude root
385385
if (irefCtx.importInfo.nn.site.termSymbol == root) outerExcluded
386386
else if (outerExcluded eqn outerImplicits) this
387387
else new ContextualImplicits(refs, outerExcluded, isImport)(irefCtx)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ class Namer { typer: Typer =>
539539
if (fromTempl.derived.nonEmpty) {
540540
if (modTempl.derived.nonEmpty)
541541
report.error(em"a class and its companion cannot both have `derives` clauses", mdef.srcPos)
542+
// `res` is inside a closure, so the flow-typing doesn't work here.
542543
res.uncheckedNN.putAttachment(desugar.DerivingCompanion, fromTempl.srcPos.startPos)
543544
}
544545
res.uncheckedNN

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ object ProtoTypes {
383383
targ = arg.withType(WildcardType)
384384
case _ =>
385385
targ = typerFn(arg)
386+
// TODO: invest why flow typing is not working on `targ`
386387
if ctx.reporter.hasUnreportedErrors then
387388
if hasInnerErrors(targ.nn) then
388389
state.errorArgs += arg

compiler/src/dotty/tools/dotc/util/HashSet.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class HashSet[T](initialCapacity: Int = 8, capacityMultiple: Int = 2) extends Mu
8989
e = entryAt(idx)
9090
null
9191

92-
/** Add entry at `x` at index `idx` */
92+
/** Add entry at `x` at index `idx` */
9393
protected def addEntryAt(idx: Int, x: T): T =
9494
Stats.record(statsItem("addEntryAt"))
9595
setEntry(idx, x)
@@ -102,6 +102,7 @@ class HashSet[T](initialCapacity: Int = 8, capacityMultiple: Int = 2) extends Mu
102102
var idx = firstIndex(x)
103103
var e: T | Null = entryAt(idx)
104104
while e != null do
105+
// TODO: remove uncheckedNN when explicit-nulls is enabled for regule compiling
105106
if isEqual(e.uncheckedNN, x) then return e.uncheckedNN
106107
idx = nextIndex(idx)
107108
e = entryAt(idx)

compiler/src/dotty/tools/package.scala

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,7 @@ package object tools {
3939
/** Nullable eq and ne. */
4040
extension [T <: AnyRef](x: T | Null)
4141
inline def eqn (y: T | Null) =
42-
if x != null then
43-
if y != null then
44-
x eq y
45-
else false
46-
else y == null
42+
x.asInstanceOf[AnyRef] eq y.asInstanceOf[AnyRef]
4743

4844
inline def nen(y: T | Null): Boolean = !eqn(y)
4945

0 commit comments

Comments
 (0)