@@ -1144,8 +1144,8 @@ object Serializers {
1144
1144
* (throw qual.field[null]) = rhs --> qual.field[null] = rhs
1145
1145
*/
1146
1146
lhs0 match {
1147
- case Throw ( sel : Select ) if sel.tpe == NullType => sel
1148
- case _ => lhs0
1147
+ case UnaryOp ( UnaryOp . Throw , sel : Select ) if sel.tpe == NullType => sel
1148
+ case _ => lhs0
1149
1149
}
1150
1150
} else {
1151
1151
lhs0
@@ -1175,13 +1175,6 @@ object Serializers {
1175
1175
case TagTryFinally =>
1176
1176
TryFinally (readTree(), readTree())
1177
1177
1178
- case TagThrow =>
1179
- val expr = readTree()
1180
- val patchedExpr =
1181
- if (hacks.use8) throwArgumentHack8(expr)
1182
- else expr
1183
- Throw (patchedExpr)
1184
-
1185
1178
case TagMatch =>
1186
1179
Match (readTree(), List .fill(readInt()) {
1187
1180
(readTrees().map(_.asInstanceOf [MatchableLiteral ]), readTree())
@@ -1212,7 +1205,7 @@ object Serializers {
1212
1205
/* Note [Nothing FieldDef rewrite]
1213
1206
* qual.field[nothing] --> throw qual.field[null]
1214
1207
*/
1215
- Throw ( Select (qualifier, field)(NullType ))
1208
+ UnaryOp ( UnaryOp . Throw , Select (qualifier, field)(NullType ))
1216
1209
} else {
1217
1210
Select (qualifier, field)(tpe)
1218
1211
}
@@ -1251,6 +1244,36 @@ object Serializers {
1251
1244
case TagUnaryOp => UnaryOp (readByte(), readTree())
1252
1245
case TagBinaryOp => BinaryOp (readByte(), readTree(), readTree())
1253
1246
1247
+ case TagArrayLength | TagGetClass | TagClone | TagIdentityHashCode |
1248
+ TagWrapAsThrowable | TagUnwrapFromThrowable | TagThrow =>
1249
+ if (false /* !hacks.use17*/ ) { // scalastyle:ignore
1250
+ throw new IOException (
1251
+ s " Illegal legacy node $tag found in class ${enclosingClassName.nameString}" )
1252
+ }
1253
+
1254
+ val lhs = readTree()
1255
+ def checkNotNullLhs : Tree = UnaryOp (UnaryOp .CheckNotNull , lhs)
1256
+
1257
+ (tag : @ switch) match {
1258
+ case TagArrayLength =>
1259
+ UnaryOp (UnaryOp .Array_length , checkNotNullLhs)
1260
+ case TagGetClass =>
1261
+ UnaryOp (UnaryOp .GetClass , checkNotNullLhs)
1262
+ case TagClone =>
1263
+ UnaryOp (UnaryOp .Clone , checkNotNullLhs)
1264
+ case TagIdentityHashCode =>
1265
+ UnaryOp (UnaryOp .IdentityHashCode , lhs)
1266
+ case TagWrapAsThrowable =>
1267
+ UnaryOp (UnaryOp .WrapAsThrowable , lhs)
1268
+ case TagUnwrapFromThrowable =>
1269
+ UnaryOp (UnaryOp .UnwrapFromThrowable , checkNotNullLhs)
1270
+ case TagThrow =>
1271
+ val patchedLhs =
1272
+ if (hacks.use8) throwArgumentHack8(lhs)
1273
+ else lhs
1274
+ UnaryOp (UnaryOp .Throw , patchedLhs)
1275
+ }
1276
+
1254
1277
case TagNewArray =>
1255
1278
val arrayTypeRef = readArrayTypeRef()
1256
1279
val lengths = readTrees()
@@ -1284,7 +1307,6 @@ object Serializers {
1284
1307
}
1285
1308
1286
1309
case TagArrayValue => ArrayValue (readArrayTypeRef(), readTrees())
1287
- case TagArrayLength => ArrayLength (readTree())
1288
1310
case TagArraySelect => ArraySelect (readTree(), readTree())(readType())
1289
1311
case TagRecordValue => RecordValue (readType().asInstanceOf [RecordType ], readTrees())
1290
1312
@@ -1304,14 +1326,6 @@ object Serializers {
1304
1326
IsInstanceOf (expr, testType)
1305
1327
1306
1328
case TagAsInstanceOf => AsInstanceOf (readTree(), readType())
1307
- case TagGetClass => GetClass (readTree())
1308
- case TagClone => Clone (readTree())
1309
- case TagIdentityHashCode => IdentityHashCode (readTree())
1310
-
1311
- case TagWrapAsThrowable =>
1312
- WrapAsThrowable (readTree())
1313
- case TagUnwrapFromThrowable =>
1314
- UnwrapFromThrowable (readTree())
1315
1329
1316
1330
case TagJSNew => JSNew (readTree(), readTreeOrJSSpreads())
1317
1331
case TagJSPrivateSelect => JSPrivateSelect (readTree(), readFieldIdent())
@@ -1464,10 +1478,13 @@ object Serializers {
1464
1478
* `runtime.package$.unwrapJavaScriptException(x)`.
1465
1479
*/
1466
1480
private def throwArgumentHack8 (expr : Tree )(implicit pos : Position ): Tree = {
1481
+ def unwrapFromThrowable (t : Tree ): Tree =
1482
+ UnaryOp (UnaryOp .UnwrapFromThrowable , t)
1483
+
1467
1484
expr.tpe match {
1468
1485
case NullType =>
1469
1486
// Evaluate the expression then definitely run into an NPE UB
1470
- UnwrapFromThrowable (expr)
1487
+ unwrapFromThrowable (expr)
1471
1488
1472
1489
case ClassType (_, _) =>
1473
1490
expr match {
@@ -1478,7 +1495,7 @@ object Serializers {
1478
1495
/* Common case (explicit re-throw of the form `throw th`) where we don't need the IIFE.
1479
1496
* if (expr === null) unwrapFromThrowable(null) else expr
1480
1497
*/
1481
- If (BinaryOp (BinaryOp .=== , expr, Null ()), UnwrapFromThrowable (Null ()), expr)(AnyType )
1498
+ If (BinaryOp (BinaryOp .=== , expr, Null ()), unwrapFromThrowable (Null ()), expr)(AnyType )
1482
1499
case _ =>
1483
1500
/* General case where we need to avoid evaluating `expr` twice.
1484
1501
* ((x) => if (x === null) unwrapFromThrowable(null) else x)(expr)
@@ -1487,7 +1504,7 @@ object Serializers {
1487
1504
val xParamDef = ParamDef (x, OriginalName .NoOriginalName , AnyType , mutable = false )
1488
1505
val xRef = xParamDef.ref
1489
1506
val closure = Closure (arrow = true , Nil , List (xParamDef), None , {
1490
- If (BinaryOp (BinaryOp .=== , xRef, Null ()), UnwrapFromThrowable (Null ()), xRef)(AnyType )
1507
+ If (BinaryOp (BinaryOp .=== , xRef, Null ()), unwrapFromThrowable (Null ()), xRef)(AnyType )
1491
1508
}, Nil )
1492
1509
JSFunctionApply (closure, List (expr))
1493
1510
}
@@ -1683,6 +1700,12 @@ object Serializers {
1683
1700
VarDef (LocalIdent (LocalName (name)), NoOriginalName , vtpe, mutable, rhs)
1684
1701
}
1685
1702
1703
+ def arrayLength (t : Tree )(implicit pos : Position ): Tree =
1704
+ UnaryOp (UnaryOp .Array_length , t)
1705
+
1706
+ def getClass (t : Tree )(implicit pos : Position ): Tree =
1707
+ UnaryOp (UnaryOp .GetClass , t)
1708
+
1686
1709
val jlClassRef = ClassRef (ClassClass )
1687
1710
val intArrayTypeRef = ArrayTypeRef (IntRef , 1 )
1688
1711
val objectRef = ClassRef (ObjectClass )
@@ -1740,7 +1763,7 @@ object Serializers {
1740
1763
length,
1741
1764
result,
1742
1765
innerOffset,
1743
- If (BinaryOp (BinaryOp .Int_< , innerOffset.ref, ArrayLength (dimensions.ref)), {
1766
+ If (BinaryOp (BinaryOp .Int_< , innerOffset.ref, arrayLength (dimensions.ref)), {
1744
1767
Block (
1745
1768
result2,
1746
1769
innerComponentType,
@@ -1810,11 +1833,11 @@ object Serializers {
1810
1833
Block (
1811
1834
outermostComponentType,
1812
1835
i,
1813
- While (BinaryOp (BinaryOp .Int_!= , i.ref, ArrayLength (lengthsParam.ref)), {
1836
+ While (BinaryOp (BinaryOp .Int_!= , i.ref, arrayLength (lengthsParam.ref)), {
1814
1837
Block (
1815
1838
Assign (
1816
1839
outermostComponentType.ref,
1817
- GetClass (Apply (EAF , This ()(ClassType (ReflectArrayModClass , nullable = false )),
1840
+ getClass (Apply (EAF , This ()(ClassType (ReflectArrayModClass , nullable = false )),
1818
1841
MethodIdent (newInstanceSingleName),
1819
1842
List (outermostComponentType.ref, IntLiteral (0 )))(AnyType ))
1820
1843
),
@@ -1944,7 +1967,7 @@ object Serializers {
1944
1967
*/
1945
1968
assert(args.size == 1 )
1946
1969
1947
- val patchedBody = Some (IdentityHashCode ( args(0 ).ref))
1970
+ val patchedBody = Some (UnaryOp ( UnaryOp . IdentityHashCode , args(0 ).ref))
1948
1971
val patchedOptimizerHints = OptimizerHints .empty.withInline(true )
1949
1972
1950
1973
MethodDef (flags, name, originalName, args, resultType, patchedBody)(
@@ -1969,11 +1992,12 @@ object Serializers {
1969
1992
1970
1993
val patchedBody = Some {
1971
1994
If (IsInstanceOf (thisValue, cloneableClassType.toNonNullable),
1972
- Clone (AsInstanceOf (thisValue, cloneableClassType)),
1973
- Throw (New (
1974
- HackNames .CloneNotSupportedExceptionClass ,
1975
- MethodIdent (NoArgConstructorName ),
1976
- Nil )))(cloneableClassType)
1995
+ UnaryOp (UnaryOp .Clone , AsInstanceOf (thisValue, cloneableClassType)),
1996
+ UnaryOp (UnaryOp .Throw ,
1997
+ New (
1998
+ HackNames .CloneNotSupportedExceptionClass ,
1999
+ MethodIdent (NoArgConstructorName ),
2000
+ Nil )))(cloneableClassType)
1977
2001
}
1978
2002
val patchedOptimizerHints = OptimizerHints .empty.withInline(true )
1979
2003
0 commit comments