Skip to content

Commit 91cb4a0

Browse files
committed
Add others
1 parent 8f9afe1 commit 91cb4a0

14 files changed

+100
-75
lines changed

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package dotty.tools
22
package dotc
33
package core
44

5+
import scala.language.{unsafeNulls => _}
6+
57
import Periods._
68
import Contexts._
79
import dotty.tools.backend.jvm.GenBCode
@@ -13,7 +15,7 @@ import scala.collection.mutable.ListBuffer
1315
import dotty.tools.dotc.transform.MegaPhase._
1416
import dotty.tools.dotc.transform._
1517
import Periods._
16-
import parsing.{ Parser}
18+
import parsing.Parser
1719
import typer.{TyperPhase, RefChecks}
1820
import typer.ImportInfo.withRootImports
1921
import ast.tpd
@@ -341,7 +343,7 @@ object Phases {
341343
def initContext(ctx: FreshContext): Unit = ()
342344

343345
private var myPeriod: Period = Periods.InvalidPeriod
344-
private var myBase: ContextBase = null
346+
private var myBase: ContextBase = _
345347
private var myErasedTypes = false
346348
private var myFlatClasses = false
347349
private var myRefChecked = false

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

+59-57
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ package dotty.tools
77
package dotc
88
package core
99

10+
import scala.language.{unsafeNulls => _}
11+
1012
import Symbols._
1113
import Types.{TermRef, NoPrefix}
1214
import Flags._
@@ -50,11 +52,11 @@ object Scopes {
5052

5153
/** the next entry in the hash bucket
5254
*/
53-
var tail: ScopeEntry = null
55+
var tail: ScopeEntry | Null = null
5456

5557
/** the preceding entry in this scope
5658
*/
57-
var prev: ScopeEntry = null
59+
var prev: ScopeEntry | Null = null
5860

5961
override def toString: String = sym.toString
6062
}
@@ -88,7 +90,7 @@ object Scopes {
8890
def iterator(using Context): Iterator[Symbol] = toList.iterator
8991

9092
/** Is the scope empty? */
91-
def isEmpty: Boolean = lastEntry eq null
93+
def isEmpty: Boolean = lastEntry == null
9294

9395
/** Applies a function f to all Symbols of this Scope. */
9496
def foreach[U](f: Symbol => U)(using Context): Unit = toList.foreach(f)
@@ -98,7 +100,7 @@ object Scopes {
98100
ensureComplete()
99101
var syms: List[Symbol] = Nil
100102
var e = lastEntry
101-
while ((e ne null) && e.owner == this) {
103+
while ((e != null) && e.owner == this) {
102104
val sym = e.sym
103105
if (p(sym)) syms = sym :: syms
104106
e = e.prev
@@ -122,20 +124,20 @@ object Scopes {
122124
def lookupEntry(name: Name)(using Context): ScopeEntry | Null
123125

124126
/** Lookup next entry with same name as this one */
125-
def lookupNextEntry(entry: ScopeEntry)(using Context): ScopeEntry
127+
def lookupNextEntry(entry: ScopeEntry)(using Context): ScopeEntry | Null
126128

127129
/** Lookup a symbol */
128130
final def lookup(name: Name)(using Context): Symbol = {
129131
val e = lookupEntry(name)
130-
if (e eq null) NoSymbol else e.sym
132+
if (e == null) NoSymbol else e.sym
131133
}
132134

133135
/** Returns an iterator yielding every symbol with given name in this scope.
134136
*/
135137
final def lookupAll(name: Name)(using Context): Iterator[Symbol] = new Iterator[Symbol] {
136138
var e = lookupEntry(name)
137-
def hasNext: Boolean = e ne null
138-
def next(): Symbol = { val r = e.sym; e = lookupNextEntry(e); r }
139+
def hasNext: Boolean = e != null
140+
def next(): Symbol = { val r = e.uncheckedNN.sym; e = lookupNextEntry(e.uncheckedNN); r }
139141
}
140142

141143
/** Does this scope contain a reference to `sym` when looking up `name`? */
@@ -163,13 +165,13 @@ object Scopes {
163165
* a copy with the matching symbols.
164166
*/
165167
final def filteredScope(p: Symbol => Boolean)(using Context): Scope = {
166-
var result: MutableScope = null
168+
var result: MutableScope | Null = null
167169
for (sym <- iterator)
168170
if (!p(sym)) {
169171
if (result == null) result = cloneScope
170-
result.unlink(sym)
172+
result.nn.unlink(sym)
171173
}
172-
if (result == null) this else result
174+
if (result == null) this else result.nn
173175
}
174176

175177
def implicitDecls(using Context): List[TermRef] = Nil
@@ -193,7 +195,7 @@ object Scopes {
193195
* This is necessary because when run from reflection every scope needs to have a
194196
* SynchronizedScope as mixin.
195197
*/
196-
class MutableScope protected[Scopes](initElems: ScopeEntry, initSize: Int, val nestingLevel: Int)
198+
class MutableScope protected[Scopes](initElems: ScopeEntry | Null, initSize: Int, val nestingLevel: Int)
197199
extends Scope {
198200

199201
/** Scope shares elements with `base` */
@@ -213,14 +215,14 @@ object Scopes {
213215

214216
/** the hash table
215217
*/
216-
private var hashTable: Array[ScopeEntry] = null
218+
private var hashTable: Array[ScopeEntry | Null] | Null = null
217219

218220
/** a cache for all elements, to be used by symbol iterator.
219221
*/
220-
private var elemsCache: List[Symbol] = null
222+
private var elemsCache: List[Symbol] | Null = null
221223

222224
/** The synthesizer to be used, or `null` if no synthesis is done on this scope */
223-
private var synthesize: SymbolSynthesizer = null
225+
private var synthesize: SymbolSynthesizer | Null = null
224226

225227
/** Use specified synthesize for this scope */
226228
def useSynthesizer(s: SymbolSynthesizer): Unit = synthesize = s
@@ -232,7 +234,7 @@ object Scopes {
232234
def cloneScope(using Context): MutableScope = {
233235
val entries = new mutable.ArrayBuffer[ScopeEntry]
234236
var e = lastEntry
235-
while ((e ne null) && e.owner == this) {
237+
while ((e != null) && e.owner == this) {
236238
entries += e
237239
e = e.prev
238240
}
@@ -247,21 +249,21 @@ object Scopes {
247249

248250
/** create and enter a scope entry with given name and symbol */
249251
protected def newScopeEntry(name: Name, sym: Symbol)(using Context): ScopeEntry = {
250-
ensureCapacity(if (hashTable ne null) hashTable.length else MinHashedScopeSize)
252+
ensureCapacity(if (hashTable != null) hashTable.uncheckedNN.length else MinHashedScopeSize)
251253
val e = new ScopeEntry(name, sym, this)
252254
e.prev = lastEntry
253255
lastEntry = e
254-
if (hashTable ne null) enterInHash(e)
256+
if (hashTable != null) enterInHash(e)
255257
size += 1
256258
elemsCache = null
257259
e
258260
}
259261

260262
private def enterInHash(e: ScopeEntry)(using Context): Unit = {
261-
val idx = e.name.hashCode & (hashTable.length - 1)
262-
e.tail = hashTable(idx)
263+
val idx = e.name.hashCode & (hashTable.nn.length - 1)
264+
e.tail = hashTable.nn(idx)
263265
assert(e.tail != e)
264-
hashTable(idx) = e
266+
hashTable.nn(idx) = e
265267
}
266268

267269
/** enter a symbol in this scope. */
@@ -289,21 +291,21 @@ object Scopes {
289291
private def createHash(tableSize: Int)(using Context): Unit =
290292
if (size > tableSize * FillFactor) createHash(tableSize * 2)
291293
else {
292-
hashTable = new Array[ScopeEntry](tableSize)
294+
hashTable = new Array[ScopeEntry | Null](tableSize)
293295
enterAllInHash(lastEntry)
294296
// checkConsistent() // DEBUG
295297
}
296298

297-
private def enterAllInHash(e: ScopeEntry, n: Int = 0)(using Context): Unit =
298-
if (e ne null)
299+
private def enterAllInHash(e: ScopeEntry | Null, n: Int = 0)(using Context): Unit =
300+
if (e != null)
299301
if (n < MaxRecursions) {
300302
enterAllInHash(e.prev, n + 1)
301303
enterInHash(e)
302304
}
303305
else {
304306
var entries: List[ScopeEntry] = List()
305-
var ee = e
306-
while (ee ne null) {
307+
var ee: ScopeEntry | Null = e
308+
while (ee != null) {
307309
entries = ee :: entries
308310
ee = ee.prev
309311
}
@@ -315,18 +317,18 @@ object Scopes {
315317
if (lastEntry == e)
316318
lastEntry = e.prev
317319
else {
318-
var e1 = lastEntry
319-
while (e1.prev != e) e1 = e1.prev
320+
var e1 = lastEntry.nn
321+
while (e1.prev != e) e1 = e1.prev.nn
320322
e1.prev = e.prev
321323
}
322-
if (hashTable ne null) {
323-
val index = e.name.hashCode & (hashTable.length - 1)
324-
var e1 = hashTable(index)
324+
if (hashTable != null) {
325+
val index = e.name.hashCode & (hashTable.nn.length - 1)
326+
var e1 = hashTable.nn(index)
325327
if (e1 == e)
326-
hashTable(index) = e.tail
328+
hashTable.nn(index) = e.tail
327329
else {
328-
while (e1.tail != e) e1 = e1.tail
329-
e1.tail = e.tail
330+
while (e1.nn.tail != e) e1 = e1.nn.tail
331+
e1.nn.tail = e.tail
330332
}
331333
}
332334
elemsCache = null
@@ -340,7 +342,7 @@ object Scopes {
340342
/** remove symbol from this scope if it is present under the given name */
341343
final def unlink(sym: Symbol, name: Name)(using Context): Unit = {
342344
var e = lookupEntry(name)
343-
while (e ne null) {
345+
while (e != null) {
344346
if (e.sym == sym) unlink(e)
345347
e = lookupNextEntry(e)
346348
}
@@ -352,7 +354,7 @@ object Scopes {
352354
final def replace(prev: Symbol, replacement: Symbol)(using Context): Unit = {
353355
require(prev.name == replacement.name)
354356
var e = lookupEntry(prev.name)
355-
while (e ne null) {
357+
while (e != null) {
356358
if (e.sym == prev) e.sym = replacement
357359
e = lookupNextEntry(e)
358360
}
@@ -362,55 +364,55 @@ object Scopes {
362364
/** Lookup a symbol entry matching given name.
363365
*/
364366
override def lookupEntry(name: Name)(using Context): ScopeEntry | Null = {
365-
var e: ScopeEntry = null
366-
if (hashTable ne null) {
367-
e = hashTable(name.hashCode & (hashTable.length - 1))
368-
while ((e ne null) && e.name != name)
367+
var e: ScopeEntry | Null = null
368+
if (hashTable != null) {
369+
e = hashTable.nn(name.hashCode & (hashTable.nn.length - 1))
370+
while ((e != null) && e.name != name)
369371
e = e.tail
370372
}
371373
else {
372374
e = lastEntry
373-
while ((e ne null) && e.name != name)
375+
while ((e != null) && e.name != name)
374376
e = e.prev
375377
}
376-
if ((e eq null) && (synthesize != null)) {
377-
val sym = synthesize(name)
378+
if ((e == null) && (synthesize != null)) {
379+
val sym = synthesize.uncheckedNN(name)
378380
if (sym.exists) newScopeEntry(sym.name, sym) else e
379381
}
380382
else e
381383
}
382384

383385
/** lookup next entry with same name as this one */
384-
override final def lookupNextEntry(entry: ScopeEntry)(using Context): ScopeEntry = {
385-
var e = entry
386-
if (hashTable ne null)
387-
while ({ e = e.tail ; (e ne null) && e.name != entry.name }) ()
386+
override final def lookupNextEntry(entry: ScopeEntry)(using Context): ScopeEntry | Null = {
387+
var e: ScopeEntry | Null = entry
388+
if (hashTable != null)
389+
while ({ e = e.nn.tail ; (e != null) && e.uncheckedNN.name != entry.name }) ()
388390
else
389-
while ({ e = e.prev ; (e ne null) && e.name != entry.name }) ()
391+
while ({ e = e.nn.prev ; (e != null) && e.uncheckedNN.name != entry.name }) ()
390392
e
391393
}
392394

393395
/** Returns all symbols as a list in the order they were entered in this scope.
394396
* Does _not_ include the elements of inherited scopes.
395397
*/
396398
override final def toList(using Context): List[Symbol] = {
397-
if (elemsCache eq null) {
399+
if (elemsCache == null) {
398400
ensureComplete()
399401
elemsCache = Nil
400402
var e = lastEntry
401-
while ((e ne null) && e.owner == this) {
402-
elemsCache = e.sym :: elemsCache
403+
while ((e != null) && e.owner == this) {
404+
elemsCache = e.sym :: elemsCache.nn
403405
e = e.prev
404406
}
405407
}
406-
elemsCache
408+
elemsCache.nn
407409
}
408410

409411
override def implicitDecls(using Context): List[TermRef] = {
410412
ensureComplete()
411413
var irefs = new mutable.ListBuffer[TermRef]
412414
var e = lastEntry
413-
while (e ne null) {
415+
while (e != null) {
414416
if (e.sym.isOneOf(GivenOrImplicitVal)) {
415417
val d = e.sym.denot
416418
irefs += TermRef(NoPrefix, d.symbol.asTerm).withDenot(d)
@@ -433,7 +435,7 @@ object Scopes {
433435
while (e != null) {
434436
var e1 = lookupEntry(e.name)
435437
while (e1 != e && e1 != null) e1 = lookupNextEntry(e1)
436-
assert(e1 == e, s"PANIC: Entry ${e.name} is badly linked")
438+
assert(e1 == e, s"PANIC: Entry ${e.nn.name} is badly linked")
437439
e = e.prev
438440
}
439441
}
@@ -463,12 +465,12 @@ object Scopes {
463465
/** The empty scope (immutable).
464466
*/
465467
object EmptyScope extends Scope {
466-
override private[dotc] def lastEntry: ScopeEntry = null
468+
override private[dotc] def lastEntry: ScopeEntry | Null = null
467469
override def size: Int = 0
468470
override def nestingLevel: Int = 0
469471
override def toList(using Context): List[Symbol] = Nil
470472
override def cloneScope(using Context): MutableScope = unsupported("cloneScope")
471-
override def lookupEntry(name: Name)(using Context): ScopeEntry = null
472-
override def lookupNextEntry(entry: ScopeEntry)(using Context): ScopeEntry = null
473+
override def lookupEntry(name: Name)(using Context): ScopeEntry | Null = null
474+
override def lookupNextEntry(entry: ScopeEntry)(using Context): ScopeEntry | Null = null
473475
}
474476
}

compiler/src/dotty/tools/dotc/rewrites/Rewrites.scala

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package dotty.tools.dotc
22
package rewrites
33

4+
import scala.language.{unsafeNulls => _}
5+
46
import util.{SourceFile, Spans}
57
import Spans.Span
68
import core.Contexts._

0 commit comments

Comments
 (0)