Skip to content

Commit 41bf2eb

Browse files
committed
Clean code
1 parent 2987afe commit 41bf2eb

File tree

11 files changed

+49
-49
lines changed

11 files changed

+49
-49
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -823,9 +823,8 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
823823
* tree must be reachable from come tree stored in an enclosing context.
824824
*/
825825
def definingStats(sym: Symbol)(using Context): List[Tree] =
826-
val unit = ctx.compilationUnit
827-
if (!sym.span.exists || (ctx eq NoContext) || (unit eq NoCompilationUnit)) Nil
828-
else defPath(sym, unit.tpdTree) match {
826+
if (!sym.span.exists || (ctx eq NoContext) || (ctx.compilationUnit eq NoCompilationUnit)) Nil
827+
else defPath(sym, ctx.compilationUnit.tpdTree) match {
829828
case defn :: encl :: _ =>
830829
def verify(stats: List[Tree]) =
831830
if (stats exists (definedSym(_) == sym)) stats else Nil

compiler/src/dotty/tools/dotc/config/Feature.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import util.{SrcPos, NoSourcePosition}
1010
import SourceVersion._
1111
import reporting.Message
1212
import NameKinds.QualifiedName
13-
import typer.ImportInfo
1413

1514
object Feature:
1615

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ object Contexts {
270270
* the declarations of the current class.
271271
*/
272272
def effectiveScope(using Context): Scope =
273-
val co: Symbol | Null = owner
274-
if co != null && co.isClass then co.asClass.unforcedDecls
273+
val myOwner: Symbol | Null = owner
274+
if myOwner != null && myOwner.isClass then myOwner.asClass.unforcedDecls
275275
else scope
276276

277277
def nestingLevel: Int = effectiveScope.nestingLevel

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +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`
54+
// TODO: investigate why flow typing is not working on `es`
5555
if (es != null && (es.nn(idx) eq entry)) current
5656
else {
5757
val result =

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ class TypeError(msg: String) extends Exception(msg) {
1818
def this() = this("")
1919
final def toMessage(using Context): Message =
2020
withMode(Mode.Printing)(produceMessage)
21-
def produceMessage(using Context): Message =
22-
val msg: String = super.getMessage.uncheckedNN
23-
msg
21+
def produceMessage(using Context): Message = super.getMessage.nn
2422
override def getMessage: String = super.getMessage.nn
2523
}
2624

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4511,8 +4511,8 @@ object Types {
45114511
def paramName: binder.ThisName = binder.paramNames(paramNum)
45124512

45134513
override def underlying(using Context): Type = {
4514+
// TODO: update paramInfos's type to nullable
45144515
val infos: List[Type] | Null = binder.paramInfos
4515-
// TODO
45164516
if (infos == null) NoType // this can happen if the referenced generic type is not initialized yet
45174517
else infos(paramNum)
45184518
}

compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ class InteractiveDriver(val settings: List[String]) extends Driver {
164164

165165
run.compileSources(List(source))
166166
run.printSummary()
167-
val ctxrun = ctx.run.nn
168-
val unit = if ctxrun.units.nonEmpty then ctxrun.units.head else ctxrun.suspendedUnits.head
167+
val ctxRun = ctx.run.nn
168+
val unit = if ctxRun.units.nonEmpty then ctxRun.units.head else ctxRun.suspendedUnits.head
169169
val t = unit.tpdTree
170170
cleanup(t)
171171
myOpenedTrees(uri) = topLevelTrees(t, source)

compiler/src/dotty/tools/dotc/reporting/StoreReporter.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ class StoreReporter(outer: Reporter | Null = Reporter.NoReporter, fromTyperState
2424
def doReport(dia: Diagnostic)(using Context): Unit = {
2525
typr.println(s">>>> StoredError: ${dia.message}") // !!! DEBUG
2626
if (infos == null) infos = new mutable.ListBuffer
27-
infos.nn += dia
27+
infos.uncheckedNN += dia
2828
}
2929

3030
override def hasUnreportedErrors: Boolean =
31-
outer != null && infos != null && infos.nn.exists(_.isInstanceOf[Error])
31+
outer != null && infos != null && infos.uncheckedNN.exists(_.isInstanceOf[Error])
3232

3333
override def hasStickyErrors: Boolean =
34-
infos != null && infos.nn.exists(_.isInstanceOf[StickyError])
34+
infos != null && infos.uncheckedNN.exists(_.isInstanceOf[StickyError])
3535

3636
override def removeBufferedMessages(using Context): List[Diagnostic] =
37-
if (infos != null) try infos.nn.toList finally infos = null
37+
if (infos != null) try infos.uncheckedNN.toList finally infos = null
3838
else Nil
3939

4040
override def pendingMessages(using Context): List[Diagnostic] =
41-
if (infos != null) infos.nn.toList else Nil
41+
if (infos != null) infos.uncheckedNN.toList else Nil
4242

4343
override def errorsReported: Boolean = hasErrors || (outer != null && outer.errorsReported)
4444

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +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`
386+
// TODO: investigate why flow typing is not working on `targ`
387387
if ctx.reporter.hasUnreportedErrors then
388388
if hasInnerErrors(targ.nn) then
389389
state.errorArgs += arg

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

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -163,40 +163,46 @@ abstract class WeakHashSet[A <: AnyRef](initialCapacity: Int = 8, loadFactor: Do
163163
elem
164164
}
165165

166-
def put(elem: A): A = {
167-
Stats.record(statsItem("put"))
168-
removeStaleEntries()
169-
val h = hash(elem)
170-
val bucket = index(h)
171-
val oldHead = table(bucket)
166+
// TODO: remove the `case null` when we can enable explicit nulls in regular compiling,
167+
// since the type `A <: AnyRef` of `elem` can ensure the value is not null.
168+
def put(elem: A): A = (elem: A | Null) match {
169+
case null => throw new NullPointerException("WeakHashSet cannot hold nulls")
170+
case _ =>
171+
Stats.record(statsItem("put"))
172+
removeStaleEntries()
173+
val h = hash(elem)
174+
val bucket = index(h)
175+
val oldHead = table(bucket)
172176

173-
@tailrec
174-
def linkedListLoop(entry: Entry[A] | Null): A = entry match {
175-
case null => addEntryAt(bucket, elem, h, oldHead)
176-
case _ =>
177-
val entryElem = entry.get
178-
if entryElem != null && isEqual(elem, entryElem) then entryElem.uncheckedNN
179-
else linkedListLoop(entry.tail)
180-
}
177+
@tailrec
178+
def linkedListLoop(entry: Entry[A] | Null): A = entry match {
179+
case null => addEntryAt(bucket, elem, h, oldHead)
180+
case _ =>
181+
val entryElem = entry.get
182+
if entryElem != null && isEqual(elem, entryElem) then entryElem.uncheckedNN
183+
else linkedListLoop(entry.tail)
184+
}
181185

182-
linkedListLoop(oldHead)
186+
linkedListLoop(oldHead)
183187
}
184188

185189
def +=(elem: A): Unit = put(elem)
186190

187-
def -=(elem: A): Unit = {
188-
Stats.record(statsItem("-="))
189-
removeStaleEntries()
190-
val bucket = index(hash(elem))
191+
def -=(elem: A): Unit = (elem: A | Null) match {
192+
case null =>
193+
case _ =>
194+
Stats.record(statsItem("-="))
195+
removeStaleEntries()
196+
val bucket = index(hash(elem))
191197

192-
@tailrec
193-
def linkedListLoop(prevEntry: Entry[A] | Null, entry: Entry[A] | Null): Unit =
194-
if entry != null then
195-
val entryElem = entry.get
196-
if entryElem != null && isEqual(elem, entryElem) then remove(bucket, prevEntry, entry)
197-
else linkedListLoop(entry, entry.tail)
198+
@tailrec
199+
def linkedListLoop(prevEntry: Entry[A] | Null, entry: Entry[A] | Null): Unit =
200+
if entry != null then
201+
val entryElem = entry.get
202+
if entryElem != null && isEqual(elem, entryElem) then remove(bucket, prevEntry, entry)
203+
else linkedListLoop(entry, entry.tail)
198204

199-
linkedListLoop(null, table(bucket))
205+
linkedListLoop(null, table(bucket))
200206
}
201207

202208
def clear(): Unit = {
@@ -255,14 +261,13 @@ abstract class WeakHashSet[A <: AnyRef](initialCapacity: Int = 8, loadFactor: Do
255261
}
256262

257263
def next(): A =
258-
if (lookaheadelement == null)
264+
if lookaheadelement == null then
259265
throw new IndexOutOfBoundsException("next on an empty iterator")
260-
else {
266+
else
261267
val result = lookaheadelement.nn
262268
lookaheadelement = null
263269
entry = entry.nn.tail
264270
result
265-
}
266271
}
267272
}
268273

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import dotty.tools.dotc.core.NameKinds
1414
import dotty.tools.dotc.core.StdNames._
1515
import dotty.tools.dotc.quoted.reflect._
1616
import dotty.tools.dotc.core.Decorators._
17-
import dotty.tools.dotc.CompilationUnit
1817
import dotty.tools.dotc.NoCompilationUnit
1918

2019
import dotty.tools.dotc.quoted.{MacroExpansion, PickledQuotes}

0 commit comments

Comments
 (0)