@@ -1139,8 +1139,8 @@ object Serializers {
1139
1139
* (throw qual.field[null]) = rhs --> qual.field[null] = rhs
1140
1140
*/
1141
1141
lhs0 match {
1142
- case Throw ( sel : Select ) if sel.tpe == NullType => sel
1143
- case _ => lhs0
1142
+ case UnaryOp ( UnaryOp . Throw , sel : Select ) if sel.tpe == NullType => sel
1143
+ case _ => lhs0
1144
1144
}
1145
1145
} else {
1146
1146
lhs0
@@ -1170,13 +1170,6 @@ object Serializers {
1170
1170
case TagTryFinally =>
1171
1171
TryFinally (readTree(), readTree())
1172
1172
1173
- case TagThrow =>
1174
- val expr = readTree()
1175
- val patchedExpr =
1176
- if (hacks.use8) throwArgumentHack8(expr)
1177
- else expr
1178
- Throw (patchedExpr)
1179
-
1180
1173
case TagMatch =>
1181
1174
Match (readTree(), List .fill(readInt()) {
1182
1175
(readTrees().map(_.asInstanceOf [MatchableLiteral ]), readTree())
@@ -1207,7 +1200,7 @@ object Serializers {
1207
1200
/* Note [Nothing FieldDef rewrite]
1208
1201
* qual.field[nothing] --> throw qual.field[null]
1209
1202
*/
1210
- Throw ( Select (qualifier, field)(NullType ))
1203
+ UnaryOp ( UnaryOp . Throw , Select (qualifier, field)(NullType ))
1211
1204
} else {
1212
1205
Select (qualifier, field)(tpe)
1213
1206
}
@@ -1246,6 +1239,36 @@ object Serializers {
1246
1239
case TagUnaryOp => UnaryOp (readByte(), readTree())
1247
1240
case TagBinaryOp => BinaryOp (readByte(), readTree(), readTree())
1248
1241
1242
+ case TagArrayLength | TagGetClass | TagClone | TagIdentityHashCode |
1243
+ TagWrapAsThrowable | TagUnwrapFromThrowable | TagThrow =>
1244
+ if (false /* !hacks.use17*/ ) { // scalastyle:ignore
1245
+ throw new IOException (
1246
+ s " Illegal legacy node $tag found in class ${enclosingClassName.nameString}" )
1247
+ }
1248
+
1249
+ val lhs = readTree()
1250
+ def checkNotNullLhs : Tree = UnaryOp (UnaryOp .CheckNotNull , lhs)
1251
+
1252
+ (tag : @ switch) match {
1253
+ case TagArrayLength =>
1254
+ UnaryOp (UnaryOp .Array_length , checkNotNullLhs)
1255
+ case TagGetClass =>
1256
+ UnaryOp (UnaryOp .GetClass , checkNotNullLhs)
1257
+ case TagClone =>
1258
+ UnaryOp (UnaryOp .Clone , checkNotNullLhs)
1259
+ case TagIdentityHashCode =>
1260
+ UnaryOp (UnaryOp .IdentityHashCode , lhs)
1261
+ case TagWrapAsThrowable =>
1262
+ UnaryOp (UnaryOp .WrapAsThrowable , lhs)
1263
+ case TagUnwrapFromThrowable =>
1264
+ UnaryOp (UnaryOp .UnwrapFromThrowable , checkNotNullLhs)
1265
+ case TagThrow =>
1266
+ val patchedLhs =
1267
+ if (hacks.use8) throwArgumentHack8(lhs)
1268
+ else lhs
1269
+ UnaryOp (UnaryOp .Throw , patchedLhs)
1270
+ }
1271
+
1249
1272
case TagNewArray =>
1250
1273
val arrayTypeRef = readArrayTypeRef()
1251
1274
val lengths = readTrees()
@@ -1279,7 +1302,6 @@ object Serializers {
1279
1302
}
1280
1303
1281
1304
case TagArrayValue => ArrayValue (readArrayTypeRef(), readTrees())
1282
- case TagArrayLength => ArrayLength (readTree())
1283
1305
case TagArraySelect => ArraySelect (readTree(), readTree())(readType())
1284
1306
case TagRecordValue => RecordValue (readType().asInstanceOf [RecordType ], readTrees())
1285
1307
@@ -1299,14 +1321,6 @@ object Serializers {
1299
1321
IsInstanceOf (expr, testType)
1300
1322
1301
1323
case TagAsInstanceOf => AsInstanceOf (readTree(), readType())
1302
- case TagGetClass => GetClass (readTree())
1303
- case TagClone => Clone (readTree())
1304
- case TagIdentityHashCode => IdentityHashCode (readTree())
1305
-
1306
- case TagWrapAsThrowable =>
1307
- WrapAsThrowable (readTree())
1308
- case TagUnwrapFromThrowable =>
1309
- UnwrapFromThrowable (readTree())
1310
1324
1311
1325
case TagJSNew => JSNew (readTree(), readTreeOrJSSpreads())
1312
1326
case TagJSPrivateSelect => JSPrivateSelect (readTree(), readFieldIdent())
@@ -1462,10 +1476,13 @@ object Serializers {
1462
1476
* `runtime.package$.unwrapJavaScriptException(x)`.
1463
1477
*/
1464
1478
private def throwArgumentHack8 (expr : Tree )(implicit pos : Position ): Tree = {
1479
+ def unwrapFromThrowable (t : Tree ): Tree =
1480
+ UnaryOp (UnaryOp .UnwrapFromThrowable , t)
1481
+
1465
1482
expr.tpe match {
1466
1483
case NullType =>
1467
1484
// Evaluate the expression then definitely run into an NPE UB
1468
- UnwrapFromThrowable (expr)
1485
+ unwrapFromThrowable (expr)
1469
1486
1470
1487
case ClassType (_, _) =>
1471
1488
expr match {
@@ -1476,7 +1493,7 @@ object Serializers {
1476
1493
/* Common case (explicit re-throw of the form `throw th`) where we don't need the IIFE.
1477
1494
* if (expr === null) unwrapFromThrowable(null) else expr
1478
1495
*/
1479
- If (BinaryOp (BinaryOp .=== , expr, Null ()), UnwrapFromThrowable (Null ()), expr)(AnyType )
1496
+ If (BinaryOp (BinaryOp .=== , expr, Null ()), unwrapFromThrowable (Null ()), expr)(AnyType )
1480
1497
case _ =>
1481
1498
/* General case where we need to avoid evaluating `expr` twice.
1482
1499
* ((x) => if (x === null) unwrapFromThrowable(null) else x)(expr)
@@ -1485,7 +1502,7 @@ object Serializers {
1485
1502
val xParamDef = ParamDef (x, OriginalName .NoOriginalName , AnyType , mutable = false )
1486
1503
val xRef = xParamDef.ref
1487
1504
val closure = Closure (arrow = true , Nil , List (xParamDef), None , {
1488
- If (BinaryOp (BinaryOp .=== , xRef, Null ()), UnwrapFromThrowable (Null ()), xRef)(AnyType )
1505
+ If (BinaryOp (BinaryOp .=== , xRef, Null ()), unwrapFromThrowable (Null ()), xRef)(AnyType )
1489
1506
}, Nil )
1490
1507
JSFunctionApply (closure, List (expr))
1491
1508
}
@@ -1681,6 +1698,12 @@ object Serializers {
1681
1698
VarDef (LocalIdent (LocalName (name)), NoOriginalName , vtpe, mutable, rhs)
1682
1699
}
1683
1700
1701
+ def arrayLength (t : Tree )(implicit pos : Position ): Tree =
1702
+ UnaryOp (UnaryOp .Array_length , t)
1703
+
1704
+ def getClass (t : Tree )(implicit pos : Position ): Tree =
1705
+ UnaryOp (UnaryOp .GetClass , t)
1706
+
1684
1707
val jlClassRef = ClassRef (ClassClass )
1685
1708
val intArrayTypeRef = ArrayTypeRef (IntRef , 1 )
1686
1709
val objectRef = ClassRef (ObjectClass )
@@ -1738,7 +1761,7 @@ object Serializers {
1738
1761
length,
1739
1762
result,
1740
1763
innerOffset,
1741
- If (BinaryOp (BinaryOp .Int_< , innerOffset.ref, ArrayLength (dimensions.ref)), {
1764
+ If (BinaryOp (BinaryOp .Int_< , innerOffset.ref, arrayLength (dimensions.ref)), {
1742
1765
Block (
1743
1766
result2,
1744
1767
innerComponentType,
@@ -1808,11 +1831,11 @@ object Serializers {
1808
1831
Block (
1809
1832
outermostComponentType,
1810
1833
i,
1811
- While (BinaryOp (BinaryOp .Int_!= , i.ref, ArrayLength (lengthsParam.ref)), {
1834
+ While (BinaryOp (BinaryOp .Int_!= , i.ref, arrayLength (lengthsParam.ref)), {
1812
1835
Block (
1813
1836
Assign (
1814
1837
outermostComponentType.ref,
1815
- GetClass (Apply (EAF , This ()(ClassType (ReflectArrayModClass , nullable = false )),
1838
+ getClass (Apply (EAF , This ()(ClassType (ReflectArrayModClass , nullable = false )),
1816
1839
MethodIdent (newInstanceSingleName),
1817
1840
List (outermostComponentType.ref, IntLiteral (0 )))(AnyType ))
1818
1841
),
@@ -1942,7 +1965,7 @@ object Serializers {
1942
1965
*/
1943
1966
assert(args.size == 1 )
1944
1967
1945
- val patchedBody = Some (IdentityHashCode ( args(0 ).ref))
1968
+ val patchedBody = Some (UnaryOp ( UnaryOp . IdentityHashCode , args(0 ).ref))
1946
1969
val patchedOptimizerHints = OptimizerHints .empty.withInline(true )
1947
1970
1948
1971
MethodDef (flags, name, originalName, args, resultType, patchedBody)(
@@ -1967,11 +1990,13 @@ object Serializers {
1967
1990
1968
1991
val patchedBody = Some {
1969
1992
If (IsInstanceOf (thisValue, cloneableClassType.toNonNullable),
1970
- Clone (AsInstanceOf (thisValue, cloneableClassType)),
1971
- Throw (New (
1972
- HackNames .CloneNotSupportedExceptionClass ,
1973
- MethodIdent (NoArgConstructorName ),
1974
- Nil )))(cloneableClassType)
1993
+ UnaryOp (UnaryOp .Clone ,
1994
+ UnaryOp (UnaryOp .CheckNotNull , AsInstanceOf (thisValue, cloneableClassType))),
1995
+ UnaryOp (UnaryOp .Throw ,
1996
+ New (
1997
+ HackNames .CloneNotSupportedExceptionClass ,
1998
+ MethodIdent (NoArgConstructorName ),
1999
+ Nil )))(cloneableClassType)
1975
2000
}
1976
2001
val patchedOptimizerHints = OptimizerHints .empty.withInline(true )
1977
2002
0 commit comments