Skip to content

Commit 76f341c

Browse files
committed
Edit more files
1 parent bc48797 commit 76f341c

File tree

7 files changed

+33
-18
lines changed

7 files changed

+33
-18
lines changed

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

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

5+
import scala.language.{unsafeNulls => _}
6+
57
import core._
68
import ast.{Trees, tpd, untpd, desugar}
79
import util.Spans._
@@ -197,7 +199,7 @@ object Applications {
197199
}
198200
}
199201

200-
def wrapDefs(defs: mutable.ListBuffer[Tree], tree: Tree)(using Context): Tree =
202+
def wrapDefs(defs: mutable.ListBuffer[Tree] | Null, tree: Tree)(using Context): Tree =
201203
if (defs != null && defs.nonEmpty) tpd.Block(defs.toList, tree) else tree
202204

203205
/** Find reference to default parameter getter for parameter #n in current
@@ -730,7 +732,7 @@ trait Applications extends Compatibility {
730732
type TypedArg = Tree
731733
def isVarArg(arg: Trees.Tree[T]): Boolean = untpd.isWildcardStarArg(arg)
732734
private var typedArgBuf = new mutable.ListBuffer[Tree]
733-
private var liftedDefs: mutable.ListBuffer[Tree] = null
735+
private var liftedDefs: mutable.ListBuffer[Tree] | Null = null
734736
private var myNormalizedFun: Tree = fun
735737
init()
736738

@@ -769,7 +771,7 @@ trait Applications extends Compatibility {
769771
override def liftFun(): Unit =
770772
if (liftedDefs == null) {
771773
liftedDefs = new mutable.ListBuffer[Tree]
772-
myNormalizedFun = lifter.liftApp(liftedDefs, myNormalizedFun)
774+
myNormalizedFun = lifter.liftApp(liftedDefs.uncheckedNN, myNormalizedFun)
773775
}
774776

775777
/** The index of the first difference between lists of trees `xs` and `ys`
@@ -835,7 +837,7 @@ trait Applications extends Compatibility {
835837
scala.util.Sorting.stableSort[(Tree, Int), Int](
836838
argDefBuf.zip(impureArgIndices), (arg, idx) => originalIndex(idx)).map(_._1)
837839
}
838-
liftedDefs ++= orderedArgDefs
840+
liftedDefs.nn ++= orderedArgDefs
839841
end if
840842
if (sameSeq(typedArgs, args)) // trick to cut down on tree copying
841843
typedArgs = args.asInstanceOf[List[Tree]]

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

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

5+
import scala.language.{unsafeNulls => _}
6+
57
import core._
68
import ast._
79
import Contexts._

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

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

4+
import scala.language.{unsafeNulls => _}
5+
46
import java.lang.ArithmeticException
57

68
import ast._
@@ -74,7 +76,7 @@ object ConstFold:
7476
private def withFoldedType(c: Constant | Null): T =
7577
if c == null then tree else tree.withType(ConstantType(c)).asInstanceOf[T]
7678

77-
private def foldUnop(op: Name, x: Constant): Constant = (op, x.tag) match {
79+
private def foldUnop(op: Name, x: Constant): Constant | Null = (op, x.tag) match {
7880
case (nme.UNARY_!, BooleanTag) => Constant(!x.booleanValue)
7981

8082
case (nme.UNARY_~ , IntTag ) => Constant(~x.intValue)
@@ -96,7 +98,7 @@ object ConstFold:
9698
/** These are local helpers to keep foldBinop from overly taxing the
9799
* optimizer.
98100
*/
99-
private def foldBooleanOp(op: Name, x: Constant, y: Constant): Constant = op match {
101+
private def foldBooleanOp(op: Name, x: Constant, y: Constant): Constant | Null = op match {
100102
case nme.ZOR => Constant(x.booleanValue | y.booleanValue)
101103
case nme.OR => Constant(x.booleanValue | y.booleanValue)
102104
case nme.XOR => Constant(x.booleanValue ^ y.booleanValue)
@@ -106,7 +108,7 @@ object ConstFold:
106108
case nme.NE => Constant(x.booleanValue != y.booleanValue)
107109
case _ => null
108110
}
109-
private def foldSubrangeOp(op: Name, x: Constant, y: Constant): Constant = op match {
111+
private def foldSubrangeOp(op: Name, x: Constant, y: Constant): Constant | Null = op match {
110112
case nme.OR => Constant(x.intValue | y.intValue)
111113
case nme.XOR => Constant(x.intValue ^ y.intValue)
112114
case nme.AND => Constant(x.intValue & y.intValue)
@@ -126,7 +128,7 @@ object ConstFold:
126128
case nme.MOD => Constant(x.intValue % y.intValue)
127129
case _ => null
128130
}
129-
private def foldLongOp(op: Name, x: Constant, y: Constant): Constant = op match {
131+
private def foldLongOp(op: Name, x: Constant, y: Constant): Constant | Null = op match {
130132
case nme.OR => Constant(x.longValue | y.longValue)
131133
case nme.XOR => Constant(x.longValue ^ y.longValue)
132134
case nme.AND => Constant(x.longValue & y.longValue)
@@ -146,7 +148,7 @@ object ConstFold:
146148
case nme.MOD => Constant(x.longValue % y.longValue)
147149
case _ => null
148150
}
149-
private def foldFloatOp(op: Name, x: Constant, y: Constant): Constant = op match {
151+
private def foldFloatOp(op: Name, x: Constant, y: Constant): Constant | Null = op match {
150152
case nme.EQ => Constant(x.floatValue == y.floatValue)
151153
case nme.NE => Constant(x.floatValue != y.floatValue)
152154
case nme.LT => Constant(x.floatValue < y.floatValue)
@@ -160,7 +162,7 @@ object ConstFold:
160162
case nme.MOD => Constant(x.floatValue % y.floatValue)
161163
case _ => null
162164
}
163-
private def foldDoubleOp(op: Name, x: Constant, y: Constant): Constant = op match {
165+
private def foldDoubleOp(op: Name, x: Constant, y: Constant): Constant | Null = op match {
164166
case nme.EQ => Constant(x.doubleValue == y.doubleValue)
165167
case nme.NE => Constant(x.doubleValue != y.doubleValue)
166168
case nme.LT => Constant(x.doubleValue < y.doubleValue)
@@ -174,21 +176,21 @@ object ConstFold:
174176
case nme.MOD => Constant(x.doubleValue % y.doubleValue)
175177
case _ => null
176178
}
177-
private def foldStringOp(op: Name, x: Constant, y: Constant): Constant = op match {
179+
private def foldStringOp(op: Name, x: Constant, y: Constant): Constant | Null = op match {
178180
case nme.ADD => Constant(x.stringValue + y.stringValue)
179181
case nme.EQ => Constant(x.stringValue == y.stringValue)
180182
case nme.NE => Constant(x.stringValue != y.stringValue)
181183
case _ => null
182184
}
183185

184-
private def foldNullOp(op: Name, x: Constant, y: Constant): Constant =
186+
private def foldNullOp(op: Name, x: Constant, y: Constant): Constant | Null=
185187
assert(x.tag == NullTag || y.tag == NullTag)
186188
op match
187189
case nme.EQ => Constant(x.tag == y.tag)
188190
case nme.NE => Constant(x.tag != y.tag)
189191
case _ => null
190192

191-
private def foldBinop(op: Name, x: Constant, y: Constant): Constant =
193+
private def foldBinop(op: Name, x: Constant, y: Constant): Constant | Null =
192194
val optag =
193195
if (x.tag == y.tag) x.tag
194196
else if (x.isNumeric && y.isNumeric) math.max(x.tag, y.tag)

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

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

5+
import scala.language.{unsafeNulls => _}
6+
57
import core._
68
import ast._
79
import ast.Trees._

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

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

4+
import scala.language.{unsafeNulls => _}
5+
46
object GenericHashMap:
57

68
/** The number of elements up to which dense packing is used.
@@ -23,17 +25,18 @@ object GenericHashMap:
2325
* However, a table of size up to DenseLimit will be re-sized only
2426
* once the number of elements reaches the table's size.
2527
*/
28+
// TODO: Key be anyref?
2629
abstract class GenericHashMap[Key, Value]
2730
(initialCapacity: Int, capacityMultiple: Int) extends MutableMap[Key, Value]:
2831
import GenericHashMap.DenseLimit
2932

3033
protected var used: Int = _
3134
protected var limit: Int = _
32-
protected var table: Array[AnyRef] = _
35+
protected var table: Array[AnyRef | Null] = _
3336
clear()
3437

3538
private def allocate(capacity: Int) =
36-
table = new Array[AnyRef](capacity * 2)
39+
table = new Array[AnyRef | Null](capacity * 2)
3740
limit = if capacity <= DenseLimit then capacity - 1 else capacity / capacityMultiple
3841

3942
private def roundToPower(n: Int) =
@@ -145,14 +148,14 @@ abstract class GenericHashMap[Key, Value]
145148
setKey(idx, key)
146149
setValue(idx, value)
147150

148-
def copyFrom(oldTable: Array[AnyRef]): Unit =
151+
def copyFrom(oldTable: Array[AnyRef | Null]): Unit =
149152
if isDense then
150153
Array.copy(oldTable, 0, table, 0, oldTable.length)
151154
else
152155
var idx = 0
153156
while idx < oldTable.length do
154-
val key = oldTable(idx).asInstanceOf[Key]
155-
if key != null then addOld(key, oldTable(idx + 1).asInstanceOf[Value])
157+
val key: Key | Null = oldTable(idx).asInstanceOf[Key | Null]
158+
if key != null then addOld(key.uncheckedNN, oldTable(idx + 1).asInstanceOf[Value])
156159
idx += 2
157160

158161
protected def growTable(): Unit =

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

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

4+
import scala.language.{unsafeNulls => _}
5+
46
/** A common class for lightweight mutable maps.
57
*/
68
abstract class MutableMap[Key, Value] extends ReadOnlyMap[Key, Value]:

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

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

4+
import scala.language.{unsafeNulls => _}
5+
46
/** A class for the reading part of mutable or immutable maps.
57
*/
68
abstract class ReadOnlyMap[Key, Value]:

0 commit comments

Comments
 (0)